Completed
Push — release-2.1 ( 277d24...7ab63c )
by Colin
09:43
created
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -155,12 +158,13 @@  discard block
 block discarded – undo
155 158
 				'data' => array(
156 159
 					'function' => function($news)
157 160
 					{
158
-						if (is_numeric($news['id']))
159
-							return '
161
+						if (is_numeric($news['id'])) {
162
+													return '
160 163
 								<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
161 164
 								<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
162
-						else
163
-							return $news['unparsed'];
165
+						} else {
166
+													return $news['unparsed'];
167
+						}
164 168
 					},
165 169
 					'class' => 'half_table',
166 170
 				),
@@ -186,10 +190,11 @@  discard block
 block discarded – undo
186 190
 				'data' => array(
187 191
 					'function' => function($news)
188 192
 					{
189
-						if (is_numeric($news['id']))
190
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
191
-						else
192
-							return '';
193
+						if (is_numeric($news['id'])) {
194
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
195
+						} else {
196
+													return '';
197
+						}
193 198
 					},
194 199
 					'class' => 'centercol icon',
195 200
 				),
@@ -283,12 +288,13 @@  discard block
 block discarded – undo
283 288
 
284 289
 	$admin_current_news = array();
285 290
 	// Ready the current news.
286
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
287
-		$admin_current_news[$id] = array(
291
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
292
+			$admin_current_news[$id] = array(
288 293
 			'id' => $id,
289 294
 			'unparsed' => un_preparsecode($line),
290 295
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
291 296
 		);
297
+	}
292 298
 
293 299
 	$admin_current_news['last'] = array(
294 300
 		'id' => 'last',
@@ -355,10 +361,11 @@  discard block
 block discarded – undo
355 361
 			'member_count' => 0,
356 362
 		);
357 363
 
358
-		if ($row['min_posts'] == -1)
359
-			$normalGroups[$row['id_group']] = $row['id_group'];
360
-		else
361
-			$postGroups[$row['id_group']] = $row['id_group'];
364
+		if ($row['min_posts'] == -1) {
365
+					$normalGroups[$row['id_group']] = $row['id_group'];
366
+		} else {
367
+					$postGroups[$row['id_group']] = $row['id_group'];
368
+		}
362 369
 	}
363 370
 	$smcFunc['db_free_result']($request);
364 371
 
@@ -374,8 +381,9 @@  discard block
 block discarded – undo
374 381
 				'post_group_list' => $postGroups,
375 382
 			)
376 383
 		);
377
-		while ($row = $smcFunc['db_fetch_assoc']($query))
378
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
384
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
385
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
386
+		}
379 387
 		$smcFunc['db_free_result']($query);
380 388
 	}
381 389
 
@@ -391,8 +399,9 @@  discard block
 block discarded – undo
391 399
 				'normal_group_list' => $normalGroups,
392 400
 			)
393 401
 		);
394
-		while ($row = $smcFunc['db_fetch_assoc']($query))
395
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
402
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
403
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
404
+		}
396 405
 		$smcFunc['db_free_result']($query);
397 406
 
398 407
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -409,8 +418,9 @@  discard block
 block discarded – undo
409 418
 				'blank_string' => '',
410 419
 			)
411 420
 		);
412
-		while ($row = $smcFunc['db_fetch_assoc']($query))
413
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
421
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
422
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
423
+		}
414 424
 		$smcFunc['db_free_result']($query);
415 425
 	}
416 426
 
@@ -461,10 +471,11 @@  discard block
 block discarded – undo
461 471
 	{
462 472
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
463 473
 
464
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
465
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
466
-		elseif (!empty($_REQUEST['xml']))
467
-			continue;
474
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
475
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
476
+		} elseif (!empty($_REQUEST['xml'])) {
477
+					continue;
478
+		}
468 479
 
469 480
 		preparsecode($context[$key]);
470 481
 		if ($html)
@@ -543,10 +554,12 @@  discard block
 block discarded – undo
543 554
 
544 555
 	// Start by finding any members!
545 556
 	$toClean = array();
546
-	if (!empty($_POST['members']))
547
-		$toClean[] = 'members';
548
-	if (!empty($_POST['exclude_members']))
549
-		$toClean[] = 'exclude_members';
557
+	if (!empty($_POST['members'])) {
558
+			$toClean[] = 'members';
559
+	}
560
+	if (!empty($_POST['exclude_members'])) {
561
+			$toClean[] = 'exclude_members';
562
+	}
550 563
 	if (!empty($toClean))
551 564
 	{
552 565
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -558,11 +571,13 @@  discard block
 block discarded – undo
558 571
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
559 572
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
560 573
 
561
-			foreach ($_POST[$type] as $index => $member)
562
-				if (strlen(trim($member)) > 0)
574
+			foreach ($_POST[$type] as $index => $member) {
575
+							if (strlen(trim($member)) > 0)
563 576
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
564
-				else
565
-					unset($_POST[$type][$index]);
577
+			}
578
+				else {
579
+									unset($_POST[$type][$index]);
580
+				}
566 581
 
567 582
 			// Find the members
568 583
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -572,16 +587,18 @@  discard block
 block discarded – undo
572 587
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
573 588
 	{
574 589
 		$members = array();
575
-		foreach ($_POST['member_list'] as $member_id)
576
-			$members[] = (int) $member_id;
590
+		foreach ($_POST['member_list'] as $member_id) {
591
+					$members[] = (int) $member_id;
592
+		}
577 593
 		$_POST['members'] = implode(',', $members);
578 594
 	}
579 595
 
580 596
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
581 597
 	{
582 598
 		$members = array();
583
-		foreach ($_POST['exclude_member_list'] as $member_id)
584
-			$members[] = (int) $member_id;
599
+		foreach ($_POST['exclude_member_list'] as $member_id) {
600
+					$members[] = (int) $member_id;
601
+		}
585 602
 		$_POST['exclude_members'] = implode(',', $members);
586 603
 	}
587 604
 
@@ -605,8 +622,9 @@  discard block
 block discarded – undo
605 622
 			'current_time' => time(),
606 623
 		)
607 624
 	);
608
-	while ($row = $smcFunc['db_fetch_assoc']($request))
609
-		$context['recipients']['exclude_members'][] = $row['id_member'];
625
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
626
+			$context['recipients']['exclude_members'][] = $row['id_member'];
627
+	}
610 628
 	$smcFunc['db_free_result']($request);
611 629
 
612 630
 	$request = $smcFunc['db_query']('', '
@@ -641,8 +659,9 @@  discard block
 block discarded – undo
641 659
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
642 660
 			$condition_array_params
643 661
 		);
644
-		while ($row = $smcFunc['db_fetch_assoc']($request))
645
-			$context['recipients']['exclude_members'][] = $row['id_member'];
662
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
663
+					$context['recipients']['exclude_members'][] = $row['id_member'];
664
+		}
646 665
 		$smcFunc['db_free_result']($request);
647 666
 	}
648 667
 
@@ -660,10 +679,11 @@  discard block
 block discarded – undo
660 679
 		);
661 680
 		while ($row = $smcFunc['db_fetch_assoc']($request))
662 681
 		{
663
-			if (in_array(3, $context['recipients']))
664
-				$context['recipients']['exclude_members'][] = $row['identifier'];
665
-			else
666
-				$context['recipients']['members'][] = $row['identifier'];
682
+			if (in_array(3, $context['recipients'])) {
683
+							$context['recipients']['exclude_members'][] = $row['identifier'];
684
+			} else {
685
+							$context['recipients']['members'][] = $row['identifier'];
686
+			}
667 687
 		}
668 688
 		$smcFunc['db_free_result']($request);
669 689
 	}
@@ -710,8 +730,9 @@  discard block
 block discarded – undo
710 730
 	$num_at_once = 1000;
711 731
 
712 732
 	// If by PM's I suggest we half the above number.
713
-	if (!empty($_POST['send_pm']))
714
-		$num_at_once /= 2;
733
+	if (!empty($_POST['send_pm'])) {
734
+			$num_at_once /= 2;
735
+	}
715 736
 
716 737
 	checkSession();
717 738
 
@@ -734,8 +755,7 @@  discard block
 block discarded – undo
734 755
 		);
735 756
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
736 757
 		$smcFunc['db_free_result']($request);
737
-	}
738
-	else
758
+	} else
739 759
 	{
740 760
 		$context['total_members'] = (int) $_REQUEST['total_members'];
741 761
 	}
@@ -753,32 +773,35 @@  discard block
 block discarded – undo
753 773
 	if (!empty($_POST['exclude_members']))
754 774
 	{
755 775
 		$members = explode(',', $_POST['exclude_members']);
756
-		foreach ($members as $member)
757
-			if ($member >= $context['start'])
776
+		foreach ($members as $member) {
777
+					if ($member >= $context['start'])
758 778
 				$context['recipients']['exclude_members'][] = (int) $member;
779
+		}
759 780
 	}
760 781
 
761 782
 	// What about members we *must* do?
762 783
 	if (!empty($_POST['members']))
763 784
 	{
764 785
 		$members = explode(',', $_POST['members']);
765
-		foreach ($members as $member)
766
-			if ($member >= $context['start'])
786
+		foreach ($members as $member) {
787
+					if ($member >= $context['start'])
767 788
 				$context['recipients']['members'][] = (int) $member;
789
+		}
768 790
 	}
769 791
 	// Cleaning groups is simple - although deal with both checkbox and commas.
770 792
 	if (isset($_POST['groups']))
771 793
 	{
772 794
 		if (is_array($_POST['groups']))
773 795
 		{
774
-			foreach ($_POST['groups'] as $group => $dummy)
775
-				$context['recipients']['groups'][] = (int) $group;
776
-		}
777
-		else
796
+			foreach ($_POST['groups'] as $group => $dummy) {
797
+							$context['recipients']['groups'][] = (int) $group;
798
+			}
799
+		} else
778 800
 		{
779 801
 			$groups = explode(',', $_POST['groups']);
780
-			foreach ($groups as $group)
781
-				$context['recipients']['groups'][] = (int) $group;
802
+			foreach ($groups as $group) {
803
+							$context['recipients']['groups'][] = (int) $group;
804
+			}
782 805
 		}
783 806
 	}
784 807
 	// Same for excluded groups
@@ -786,15 +809,17 @@  discard block
 block discarded – undo
786 809
 	{
787 810
 		if (is_array($_POST['exclude_groups']))
788 811
 		{
789
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
790
-				$context['recipients']['exclude_groups'][] = (int) $group;
812
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
813
+							$context['recipients']['exclude_groups'][] = (int) $group;
814
+			}
791 815
 		}
792 816
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
793 817
 		elseif ($_POST['exclude_groups'] != '')
794 818
 		{
795 819
 			$groups = explode(',', $_POST['exclude_groups']);
796
-			foreach ($groups as $group)
797
-				$context['recipients']['exclude_groups'][] = (int) $group;
820
+			foreach ($groups as $group) {
821
+							$context['recipients']['exclude_groups'][] = (int) $group;
822
+			}
798 823
 		}
799 824
 	}
800 825
 	// Finally - emails!
@@ -804,14 +829,16 @@  discard block
 block discarded – undo
804 829
 		foreach ($addressed as $curmem)
805 830
 		{
806 831
 			$curmem = trim($curmem);
807
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
808
-				$context['recipients']['emails'][$curmem] = $curmem;
832
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
833
+							$context['recipients']['emails'][$curmem] = $curmem;
834
+			}
809 835
 		}
810 836
 	}
811 837
 
812 838
 	// If we're only cleaning drop out here.
813
-	if ($clean_only)
814
-		return;
839
+	if ($clean_only) {
840
+			return;
841
+	}
815 842
 
816 843
 	require_once($sourcedir . '/Subs-Post.php');
817 844
 
@@ -827,16 +854,18 @@  discard block
 block discarded – undo
827 854
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
828 855
 	{
829 856
 		// Prepare the message for HTML.
830
-		if (!empty($_POST['parse_html']))
831
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
857
+		if (!empty($_POST['parse_html'])) {
858
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
859
+		}
832 860
 
833 861
 		// This is here to prevent spam filters from tagging this as spam.
834 862
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
835 863
 		{
836
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
837
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
838
-			else
839
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
864
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
865
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
866
+			} else {
867
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
868
+			}
840 869
 		}
841 870
 	}
842 871
 
@@ -890,15 +919,17 @@  discard block
 block discarded – undo
890 919
 	foreach ($context['recipients']['emails'] as $k => $email)
891 920
 	{
892 921
 		// Done as many as we can?
893
-		if ($i >= $num_at_once)
894
-			break;
922
+		if ($i >= $num_at_once) {
923
+					break;
924
+		}
895 925
 
896 926
 		// Don't sent it twice!
897 927
 		unset($context['recipients']['emails'][$k]);
898 928
 
899 929
 		// Dammit - can't PM emails!
900
-		if ($context['send_pm'])
901
-			continue;
930
+		if ($context['send_pm']) {
931
+					continue;
932
+		}
902 933
 
903 934
 		$to_member = array(
904 935
 			$email,
@@ -932,8 +963,9 @@  discard block
 block discarded – undo
932 963
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
933 964
 				}
934 965
 			}
935
-			if (!empty($queryBuild))
936
-			$sendQuery .= implode(' OR ', $queryBuild);
966
+			if (!empty($queryBuild)) {
967
+						$sendQuery .= implode(' OR ', $queryBuild);
968
+			}
937 969
 		}
938 970
 		if (!empty($context['recipients']['members']))
939 971
 		{
@@ -952,8 +984,9 @@  discard block
 block discarded – undo
952 984
 		}
953 985
 
954 986
 		// Anything to exclude?
955
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
956
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
987
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
988
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
989
+		}
957 990
 		if (!empty($context['recipients']['exclude_members']))
958 991
 		{
959 992
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -989,21 +1022,24 @@  discard block
 block discarded – undo
989 1022
 		foreach ($rows as $row)
990 1023
 		{
991 1024
 			// Force them to have it?
992
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
993
-				continue;
1025
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1026
+							continue;
1027
+			}
994 1028
 
995 1029
 			// What groups are we looking at here?
996
-			if (empty($row['additional_groups']))
997
-				$groups = array($row['id_group'], $row['id_post_group']);
998
-			else
999
-				$groups = array_merge(
1030
+			if (empty($row['additional_groups'])) {
1031
+							$groups = array($row['id_group'], $row['id_post_group']);
1032
+			} else {
1033
+							$groups = array_merge(
1000 1034
 					array($row['id_group'], $row['id_post_group']),
1001 1035
 					explode(',', $row['additional_groups'])
1002 1036
 				);
1037
+			}
1003 1038
 
1004 1039
 			// Excluded groups?
1005
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1006
-				continue;
1040
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1041
+							continue;
1042
+			}
1007 1043
 
1008 1044
 			// We might need this
1009 1045
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1026,10 +1062,11 @@  discard block
 block discarded – undo
1026 1062
 				), $_POST['subject']);
1027 1063
 
1028 1064
 			// Send the actual email - or a PM!
1029
-			if (!$context['send_pm'])
1030
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1031
-			else
1032
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1065
+			if (!$context['send_pm']) {
1066
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1067
+			} else {
1068
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1069
+			}
1033 1070
 		}
1034 1071
 	}
1035 1072
 
@@ -1079,8 +1116,9 @@  discard block
 block discarded – undo
1079 1116
 
1080 1117
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1081 1118
 
1082
-	if ($return_config)
1083
-		return $config_vars;
1119
+	if ($return_config) {
1120
+			return $config_vars;
1121
+	}
1084 1122
 
1085 1123
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1086 1124
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5495,7 +5495,6 @@  discard block
 block discarded – undo
5495 5495
 
5496 5496
 /**
5497 5497
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5498
-
5499 5498
  * @param string $file The file/dir full path.
5500 5499
  * @param int $value Not needed, added for legacy reasons.
5501 5500
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5535,7 +5534,6 @@  discard block
 block discarded – undo
5535 5534
 
5536 5535
 /**
5537 5536
  * Wrapper function for json_decode() with error handling.
5538
-
5539 5537
  * @param string $json The string to decode.
5540 5538
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5541 5539
  * @param bool $logIt To specify if the error will be logged if theres any.
@@ -6029,7 +6027,7 @@  discard block
 block discarded – undo
6029 6027
 		$params = stream_context_get_params($stream);
6030 6028
 		$result = isset($params["options"]["ssl"]["peer_certificate"]) ? true : false;
6031 6029
 	}
6032
-    return $result;
6030
+	return $result;
6033 6031
 }
6034 6032
 
6035 6033
 /**
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
  * - caches the formatting data from the setting for optimization.
694 694
  *
695 695
  * @param float $number A number
696
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
696
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
697 697
  * @return string A formatted number
698 698
  */
699 699
 function comma_format($number, $override_decimal_count = false)
@@ -5869,7 +5869,7 @@  discard block
 block discarded – undo
5869 5869
  * It assumes the data is already a string.
5870 5870
  * @param string $data The data to print
5871 5871
  * @param string $type The content type. Defaults to Json.
5872
- * @return void
5872
+ * @return false|null
5873 5873
  */
5874 5874
 function smf_serverResponse($data = '', $type = 'content-type: application/json')
5875 5875
 {
@@ -6351,7 +6351,7 @@  discard block
 block discarded – undo
6351 6351
  *
6352 6352
  * @param string $iri The IRI to test.
6353 6353
  * @param int $flags Optional flags to pass to filter_var()
6354
- * @return string|bool Either the original IRI, or false if the IRI was invalid.
6354
+ * @return string|false Either the original IRI, or false if the IRI was invalid.
6355 6355
  */
6356 6356
 function validate_iri($iri, $flags = null)
6357 6357
 {
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 			{
387 387
 				$val = 'CASE ';
388 388
 				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
389
+					$val .= 'WHEN id_member = ' . $v . ' THEN ' . count(fetch_alerts($v, false, 0, array(), false)) . ' ';
390 390
 				$val = $val . ' END';
391 391
 				$type = 'raw';
392 392
 			}
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 	static $non_twelve_hour, $locale_cache;
740 740
 	static $unsupportedFormats, $finalizedFormats;
741 741
 
742
-	$unsupportedFormatsWindows = array('z','Z');
742
+	$unsupportedFormatsWindows = array('z', 'Z');
743 743
 
744 744
 	// Ensure required values are set
745 745
 	$user_info['time_offset'] = !empty($user_info['time_offset']) ? $user_info['time_offset'] : 0;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
825 825
 		if (empty($unsupportedFormats))
826 826
 		{
827
-			foreach($strftimeFormatSubstitutions as $format => $substitution)
827
+			foreach ($strftimeFormatSubstitutions as $format => $substitution)
828 828
 			{
829 829
 				// Avoid a crashing bug with PHP 7 on certain versions of Windows
830 830
 				if ($context['server']['is_windows'] && in_array($format, $unsupportedFormatsWindows))
@@ -1196,7 +1196,7 @@  discard block
 block discarded – undo
1196 1196
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1197 1197
 				),
1198 1198
 				'content' => '$1',
1199
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1199
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1200 1200
 				{
1201 1201
 					$returnContext = '';
1202 1202
 
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 						}
1232 1232
 
1233 1233
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1234
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1234
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>';
1235 1235
 						else
1236 1236
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1237 1237
 					}
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 				'type' => 'unparsed_content',
1261 1261
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1262 1262
 				// @todo Maybe this can be simplified?
1263
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1263
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1264 1264
 				{
1265 1265
 					if (!isset($disabled['code']))
1266 1266
 					{
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 				'type' => 'unparsed_equals_content',
1298 1298
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1299 1299
 				// @todo Maybe this can be simplified?
1300
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1300
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1301 1301
 				{
1302 1302
 					if (!isset($disabled['code']))
1303 1303
 					{
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 				'type' => 'unparsed_content',
1342 1342
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1343 1343
 				// @todo Should this respect guest_hideContacts?
1344
-				'validate' => function (&$tag, &$data, $disabled)
1344
+				'validate' => function(&$tag, &$data, $disabled)
1345 1345
 				{
1346 1346
 					$data = strtr($data, array('<br>' => ''));
1347 1347
 				},
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
 				'type' => 'unparsed_commas_content',
1361 1361
 				'test' => '\d+,\d+\]',
1362 1362
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1363
-				'validate' => function (&$tag, &$data, $disabled)
1363
+				'validate' => function(&$tag, &$data, $disabled)
1364 1364
 				{
1365 1365
 					if (isset($disabled['url']))
1366 1366
 						$tag['content'] = '$1';
@@ -1376,7 +1376,7 @@  discard block
 block discarded – undo
1376 1376
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1377 1377
 				'before' => '<div $1>',
1378 1378
 				'after' => '</div>',
1379
-				'validate' => function (&$tag, &$data, $disabled)
1379
+				'validate' => function(&$tag, &$data, $disabled)
1380 1380
 				{
1381 1381
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1382 1382
 
@@ -1425,7 +1425,7 @@  discard block
 block discarded – undo
1425 1425
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1426 1426
 				),
1427 1427
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1428
-				'validate' => function (&$tag, &$data, $disabled)
1428
+				'validate' => function(&$tag, &$data, $disabled)
1429 1429
 				{
1430 1430
 					global $image_proxy_enabled, $user_info;
1431 1431
 
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
 				'tag' => 'img',
1452 1452
 				'type' => 'unparsed_content',
1453 1453
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1454
-				'validate' => function (&$tag, &$data, $disabled)
1454
+				'validate' => function(&$tag, &$data, $disabled)
1455 1455
 				{
1456 1456
 					global $image_proxy_enabled, $user_info;
1457 1457
 
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
 				'tag' => 'iurl',
1478 1478
 				'type' => 'unparsed_content',
1479 1479
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1480
-				'validate' => function (&$tag, &$data, $disabled)
1480
+				'validate' => function(&$tag, &$data, $disabled)
1481 1481
 				{
1482 1482
 					$data = strtr($data, array('<br>' => ''));
1483 1483
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
 				'quoted' => 'optional',
1492 1492
 				'before' => '<a href="$1" class="bbc_link">',
1493 1493
 				'after' => '</a>',
1494
-				'validate' => function (&$tag, &$data, $disabled)
1494
+				'validate' => function(&$tag, &$data, $disabled)
1495 1495
 				{
1496 1496
 					if (substr($data, 0, 1) == '#')
1497 1497
 						$data = '#post_' . substr($data, 1);
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 				'tag' => 'php',
1578 1578
 				'type' => 'unparsed_content',
1579 1579
 				'content' => '<span class="phpcode">$1</span>',
1580
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1580
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1581 1581
 				{
1582 1582
 					if (!isset($disabled['php']))
1583 1583
 					{
@@ -1675,7 +1675,7 @@  discard block
 block discarded – undo
1675 1675
 				'test' => '[1-7]\]',
1676 1676
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1677 1677
 				'after' => '</span>',
1678
-				'validate' => function (&$tag, &$data, $disabled)
1678
+				'validate' => function(&$tag, &$data, $disabled)
1679 1679
 				{
1680 1680
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1681 1681
 					$data = $sizes[$data] . 'em';
@@ -1713,7 +1713,7 @@  discard block
 block discarded – undo
1713 1713
 				'tag' => 'time',
1714 1714
 				'type' => 'unparsed_content',
1715 1715
 				'content' => '$1',
1716
-				'validate' => function (&$tag, &$data, $disabled)
1716
+				'validate' => function(&$tag, &$data, $disabled)
1717 1717
 				{
1718 1718
 					if (is_numeric($data))
1719 1719
 						$data = timeformat($data);
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 				'tag' => 'url',
1742 1742
 				'type' => 'unparsed_content',
1743 1743
 				'content' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>',
1744
-				'validate' => function (&$tag, &$data, $disabled)
1744
+				'validate' => function(&$tag, &$data, $disabled)
1745 1745
 				{
1746 1746
 					$data = strtr($data, array('<br>' => ''));
1747 1747
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1755,7 +1755,7 @@  discard block
 block discarded – undo
1755 1755
 				'quoted' => 'optional',
1756 1756
 				'before' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">',
1757 1757
 				'after' => '</a>',
1758
-				'validate' => function (&$tag, &$data, $disabled)
1758
+				'validate' => function(&$tag, &$data, $disabled)
1759 1759
 				{
1760 1760
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1761 1761
 					if (empty($scheme))
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
 		{
1788 1788
 			if (isset($temp_bbc))
1789 1789
 				$bbc_codes = $temp_bbc;
1790
-			usort($codes, function ($a, $b) {
1790
+			usort($codes, function($a, $b) {
1791 1791
 				return strcmp($a['tag'], $b['tag']);
1792 1792
 			});
1793 1793
 			return $codes;
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
 										# a run of Unicode domain name characters and a dot
2004 2004
 										[\p{L}\p{M}\p{N}\-.:@]+\.
2005 2005
 										# and then a TLD valid in the DNS or the reserved "local" TLD
2006
-										(?:'. $modSettings['tld_regex'] .'|local)
2006
+										(?:'. $modSettings['tld_regex'] . '|local)
2007 2007
 									)
2008 2008
 									# followed by a non-domain character or end of line
2009 2009
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -2071,7 +2071,7 @@  discard block
 block discarded – undo
2071 2071
 						)?
2072 2072
 						';
2073 2073
 
2074
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
2074
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
2075 2075
 							$url = array_shift($matches);
2076 2076
 
2077 2077
 							// If this isn't a clean URL, bail out
@@ -2096,7 +2096,7 @@  discard block
 block discarded – undo
2096 2096
 								$fullUrl = $url;
2097 2097
 
2098 2098
 							// Make sure that $fullUrl really is valid
2099
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2099
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '') . $fullUrl) === false)
2100 2100
 								return $url;
2101 2101
 
2102 2102
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
@@ -2160,7 +2160,7 @@  discard block
 block discarded – undo
2160 2160
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2161 2161
 
2162 2162
 			// A closing tag that doesn't match any open tags? Skip it.
2163
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2163
+			if (!in_array($look_for, array_map(function($code) {return $code['tag']; }, $open_tags)))
2164 2164
 				continue;
2165 2165
 
2166 2166
 			$to_close = array();
@@ -2830,7 +2830,7 @@  discard block
 block discarded – undo
2830 2830
 			{
2831 2831
 				$exts = array('svg', 'png', 'gif', 'jpg');
2832 2832
 				$fname = pathinfo($smileysto[$i], PATHINFO_FILENAME);
2833
-				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2833
+				$alt_images = glob($smileys_dir . $fname . '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2834 2834
 				if (!empty($alt_images))
2835 2835
 				{
2836 2836
 					foreach ($exts as $ext)
@@ -2846,7 +2846,7 @@  discard block
 block discarded – undo
2846 2846
 			}
2847 2847
 
2848 2848
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2849
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2849
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2850 2850
 
2851 2851
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2852 2852
 
@@ -2863,7 +2863,7 @@  discard block
 block discarded – undo
2863 2863
 
2864 2864
 	// Replace away!
2865 2865
 	$message = preg_replace_callback($smileyPregSearch,
2866
-		function ($matches) use ($smileyPregReplacements)
2866
+		function($matches) use ($smileyPregReplacements)
2867 2867
 		{
2868 2868
 			return $smileyPregReplacements[$matches[1]];
2869 2869
 		}, $message);
@@ -2960,13 +2960,13 @@  discard block
 block discarded – undo
2960 2960
 	{
2961 2961
 		if (defined('SID') && SID != '')
2962 2962
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2963
-				function ($m) use ($scripturl)
2963
+				function($m) use ($scripturl)
2964 2964
 				{
2965
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2965
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2966 2966
 				}, $setLocation);
2967 2967
 		else
2968 2968
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2969
-				function ($m) use ($scripturl)
2969
+				function($m) use ($scripturl)
2970 2970
 				{
2971 2971
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2972 2972
 				}, $setLocation);
@@ -3287,7 +3287,7 @@  discard block
 block discarded – undo
3287 3287
 
3288 3288
 	// Add a generic "Are you sure?" confirmation message.
3289 3289
 	addInlineJavaScript('
3290
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3290
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3291 3291
 
3292 3292
 	// Now add the capping code for avatars.
3293 3293
 	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
@@ -3753,7 +3753,7 @@  discard block
 block discarded – undo
3753 3753
 	if (!empty($normal))
3754 3754
 		foreach ($normal as $nf)
3755 3755
 			echo '
3756
-	<link rel="stylesheet" href="', $nf ,'">';
3756
+	<link rel="stylesheet" href="', $nf, '">';
3757 3757
 
3758 3758
 	if ($db_show_debug === true)
3759 3759
 	{
@@ -3769,7 +3769,7 @@  discard block
 block discarded – undo
3769 3769
 	<style>';
3770 3770
 
3771 3771
 		foreach ($context['css_header'] as $css)
3772
-			echo $css .'
3772
+			echo $css . '
3773 3773
 	';
3774 3774
 
3775 3775
 		echo'
@@ -3813,7 +3813,7 @@  discard block
 block discarded – undo
3813 3813
 
3814 3814
 
3815 3815
 	// No namespaces, sorry!
3816
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3816
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3817 3817
 
3818 3818
 	// Temp path.
3819 3819
 	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
@@ -3993,7 +3993,7 @@  discard block
 block discarded – undo
3993 3993
 	else
3994 3994
 		$path = $modSettings['attachmentUploadDir'];
3995 3995
 
3996
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3996
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3997 3997
 }
3998 3998
 
3999 3999
 /**
@@ -4037,10 +4037,10 @@  discard block
 block discarded – undo
4037 4037
 		$valid_low = isValidIP($ip_parts[0]);
4038 4038
 		$valid_high = isValidIP($ip_parts[1]);
4039 4039
 		$count = 0;
4040
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
4040
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
4041 4041
 		$max = ($mode == ':' ? 'ffff' : '255');
4042 4042
 		$min = 0;
4043
-		if(!$valid_low)
4043
+		if (!$valid_low)
4044 4044
 		{
4045 4045
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
4046 4046
 			$valid_low = isValidIP($ip_parts[0]);
@@ -4054,7 +4054,7 @@  discard block
 block discarded – undo
4054 4054
 		}
4055 4055
 
4056 4056
 		$count = 0;
4057
-		if(!$valid_high)
4057
+		if (!$valid_high)
4058 4058
 		{
4059 4059
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
4060 4060
 			$valid_high = isValidIP($ip_parts[1]);
@@ -4067,7 +4067,7 @@  discard block
 block discarded – undo
4067 4067
 			}
4068 4068
 		}
4069 4069
 
4070
-		if($valid_high && $valid_low)
4070
+		if ($valid_high && $valid_low)
4071 4071
 		{
4072 4072
 			$ip_array['low'] = $ip_parts[0];
4073 4073
 			$ip_array['high'] = $ip_parts[1];
@@ -4248,7 +4248,7 @@  discard block
 block discarded – undo
4248 4248
 		addInlineJavaScript('
4249 4249
 	var user_menus = new smc_PopupMenu();
4250 4250
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4251
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4251
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4252 4252
 		if ($context['allow_pm'])
4253 4253
 			addInlineJavaScript('
4254 4254
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4884,7 +4884,7 @@  discard block
 block discarded – undo
4884 4884
 		// No? try a fallback to $sourcedir
4885 4885
 		else
4886 4886
 		{
4887
-			$absPath = $sourcedir .'/'. $file;
4887
+			$absPath = $sourcedir . '/' . $file;
4888 4888
 
4889 4889
 			if (file_exists($absPath))
4890 4890
 				require_once($absPath);
@@ -5151,15 +5151,15 @@  discard block
 block discarded – undo
5151 5151
 
5152 5152
 	// UTF-8 occurences of MS special characters
5153 5153
 	$findchars_utf8 = array(
5154
-		"\xe2\x80\x9a",	// single low-9 quotation mark
5155
-		"\xe2\x80\x9e",	// double low-9 quotation mark
5156
-		"\xe2\x80\xa6",	// horizontal ellipsis
5157
-		"\xe2\x80\x98",	// left single curly quote
5158
-		"\xe2\x80\x99",	// right single curly quote
5159
-		"\xe2\x80\x9c",	// left double curly quote
5160
-		"\xe2\x80\x9d",	// right double curly quote
5161
-		"\xe2\x80\x93",	// en dash
5162
-		"\xe2\x80\x94",	// em dash
5154
+		"\xe2\x80\x9a", // single low-9 quotation mark
5155
+		"\xe2\x80\x9e", // double low-9 quotation mark
5156
+		"\xe2\x80\xa6", // horizontal ellipsis
5157
+		"\xe2\x80\x98", // left single curly quote
5158
+		"\xe2\x80\x99", // right single curly quote
5159
+		"\xe2\x80\x9c", // left double curly quote
5160
+		"\xe2\x80\x9d", // right double curly quote
5161
+		"\xe2\x80\x93", // en dash
5162
+		"\xe2\x80\x94", // em dash
5163 5163
 	);
5164 5164
 
5165 5165
 	// windows 1252 / iso equivalents
@@ -5177,15 +5177,15 @@  discard block
 block discarded – undo
5177 5177
 
5178 5178
 	// safe replacements
5179 5179
 	$replacechars = array(
5180
-		',',	// &sbquo;
5181
-		',,',	// &bdquo;
5182
-		'...',	// &hellip;
5183
-		"'",	// &lsquo;
5184
-		"'",	// &rsquo;
5185
-		'"',	// &ldquo;
5186
-		'"',	// &rdquo;
5187
-		'-',	// &ndash;
5188
-		'--',	// &mdash;
5180
+		',', // &sbquo;
5181
+		',,', // &bdquo;
5182
+		'...', // &hellip;
5183
+		"'", // &lsquo;
5184
+		"'", // &rsquo;
5185
+		'"', // &ldquo;
5186
+		'"', // &rdquo;
5187
+		'-', // &ndash;
5188
+		'--', // &mdash;
5189 5189
 	);
5190 5190
 
5191 5191
 	if ($context['utf8'])
@@ -5505,7 +5505,7 @@  discard block
 block discarded – undo
5505 5505
  */
5506 5506
 function inet_dtop($bin)
5507 5507
 {
5508
-	if(empty($bin))
5508
+	if (empty($bin))
5509 5509
 		return '';
5510 5510
 
5511 5511
 	global $db_type;
@@ -5536,28 +5536,28 @@  discard block
 block discarded – undo
5536 5536
  */
5537 5537
 function _safe_serialize($value)
5538 5538
 {
5539
-	if(is_null($value))
5539
+	if (is_null($value))
5540 5540
 		return 'N;';
5541 5541
 
5542
-	if(is_bool($value))
5543
-		return 'b:'. (int) $value .';';
5542
+	if (is_bool($value))
5543
+		return 'b:' . (int) $value . ';';
5544 5544
 
5545
-	if(is_int($value))
5546
-		return 'i:'. $value .';';
5545
+	if (is_int($value))
5546
+		return 'i:' . $value . ';';
5547 5547
 
5548
-	if(is_float($value))
5549
-		return 'd:'. str_replace(',', '.', $value) .';';
5548
+	if (is_float($value))
5549
+		return 'd:' . str_replace(',', '.', $value) . ';';
5550 5550
 
5551
-	if(is_string($value))
5552
-		return 's:'. strlen($value) .':"'. $value .'";';
5551
+	if (is_string($value))
5552
+		return 's:' . strlen($value) . ':"' . $value . '";';
5553 5553
 
5554
-	if(is_array($value))
5554
+	if (is_array($value))
5555 5555
 	{
5556 5556
 		$out = '';
5557
-		foreach($value as $k => $v)
5557
+		foreach ($value as $k => $v)
5558 5558
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5559 5559
 
5560
-		return 'a:'. count($value) .':{'. $out .'}';
5560
+		return 'a:' . count($value) . ':{' . $out . '}';
5561 5561
 	}
5562 5562
 
5563 5563
 	// safe_serialize cannot serialize resources or objects.
@@ -5599,7 +5599,7 @@  discard block
 block discarded – undo
5599 5599
 function _safe_unserialize($str)
5600 5600
 {
5601 5601
 	// Input  is not a string.
5602
-	if(empty($str) || !is_string($str))
5602
+	if (empty($str) || !is_string($str))
5603 5603
 		return false;
5604 5604
 
5605 5605
 	$stack = array();
@@ -5613,40 +5613,40 @@  discard block
 block discarded – undo
5613 5613
 	 *   3 - in array, expecting value or another array
5614 5614
 	 */
5615 5615
 	$state = 0;
5616
-	while($state != 1)
5616
+	while ($state != 1)
5617 5617
 	{
5618 5618
 		$type = isset($str[0]) ? $str[0] : '';
5619
-		if($type == '}')
5619
+		if ($type == '}')
5620 5620
 			$str = substr($str, 1);
5621 5621
 
5622
-		else if($type == 'N' && $str[1] == ';')
5622
+		else if ($type == 'N' && $str[1] == ';')
5623 5623
 		{
5624 5624
 			$value = null;
5625 5625
 			$str = substr($str, 2);
5626 5626
 		}
5627
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5627
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5628 5628
 		{
5629 5629
 			$value = $matches[1] == '1' ? true : false;
5630 5630
 			$str = substr($str, 4);
5631 5631
 		}
5632
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5632
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5633 5633
 		{
5634
-			$value = (int)$matches[1];
5634
+			$value = (int) $matches[1];
5635 5635
 			$str = $matches[2];
5636 5636
 		}
5637
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5637
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5638 5638
 		{
5639
-			$value = (float)$matches[1];
5639
+			$value = (float) $matches[1];
5640 5640
 			$str = $matches[3];
5641 5641
 		}
5642
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5642
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5643 5643
 		{
5644
-			$value = substr($matches[2], 0, (int)$matches[1]);
5645
-			$str = substr($matches[2], (int)$matches[1] + 2);
5644
+			$value = substr($matches[2], 0, (int) $matches[1]);
5645
+			$str = substr($matches[2], (int) $matches[1] + 2);
5646 5646
 		}
5647
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5647
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5648 5648
 		{
5649
-			$expectedLength = (int)$matches[1];
5649
+			$expectedLength = (int) $matches[1];
5650 5650
 			$str = $matches[2];
5651 5651
 		}
5652 5652
 
@@ -5654,10 +5654,10 @@  discard block
 block discarded – undo
5654 5654
 		else
5655 5655
 			return false;
5656 5656
 
5657
-		switch($state)
5657
+		switch ($state)
5658 5658
 		{
5659 5659
 			case 3: // In array, expecting value or another array.
5660
-				if($type == 'a')
5660
+				if ($type == 'a')
5661 5661
 				{
5662 5662
 					$stack[] = &$list;
5663 5663
 					$list[$key] = array();
@@ -5666,7 +5666,7 @@  discard block
 block discarded – undo
5666 5666
 					$state = 2;
5667 5667
 					break;
5668 5668
 				}
5669
-				if($type != '}')
5669
+				if ($type != '}')
5670 5670
 				{
5671 5671
 					$list[$key] = $value;
5672 5672
 					$state = 2;
@@ -5677,29 +5677,29 @@  discard block
 block discarded – undo
5677 5677
 				return false;
5678 5678
 
5679 5679
 			case 2: // in array, expecting end of array or a key
5680
-				if($type == '}')
5680
+				if ($type == '}')
5681 5681
 				{
5682 5682
 					// Array size is less than expected.
5683
-					if(count($list) < end($expected))
5683
+					if (count($list) < end($expected))
5684 5684
 						return false;
5685 5685
 
5686 5686
 					unset($list);
5687
-					$list = &$stack[count($stack)-1];
5687
+					$list = &$stack[count($stack) - 1];
5688 5688
 					array_pop($stack);
5689 5689
 
5690 5690
 					// Go to terminal state if we're at the end of the root array.
5691 5691
 					array_pop($expected);
5692 5692
 
5693
-					if(count($expected) == 0)
5693
+					if (count($expected) == 0)
5694 5694
 						$state = 1;
5695 5695
 
5696 5696
 					break;
5697 5697
 				}
5698 5698
 
5699
-				if($type == 'i' || $type == 's')
5699
+				if ($type == 'i' || $type == 's')
5700 5700
 				{
5701 5701
 					// Array size exceeds expected length.
5702
-					if(count($list) >= end($expected))
5702
+					if (count($list) >= end($expected))
5703 5703
 						return false;
5704 5704
 
5705 5705
 					$key = $value;
@@ -5712,7 +5712,7 @@  discard block
 block discarded – undo
5712 5712
 
5713 5713
 			// Expecting array or value.
5714 5714
 			case 0:
5715
-				if($type == 'a')
5715
+				if ($type == 'a')
5716 5716
 				{
5717 5717
 					$data = array();
5718 5718
 					$list = &$data;
@@ -5721,7 +5721,7 @@  discard block
 block discarded – undo
5721 5721
 					break;
5722 5722
 				}
5723 5723
 
5724
-				if($type != '}')
5724
+				if ($type != '}')
5725 5725
 				{
5726 5726
 					$data = $value;
5727 5727
 					$state = 1;
@@ -5734,7 +5734,7 @@  discard block
 block discarded – undo
5734 5734
 	}
5735 5735
 
5736 5736
 	// Trailing data in input.
5737
-	if(!empty($str))
5737
+	if (!empty($str))
5738 5738
 		return false;
5739 5739
 
5740 5740
 	return $data;
@@ -5788,7 +5788,7 @@  discard block
 block discarded – undo
5788 5788
 	// Set different modes.
5789 5789
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5790 5790
 
5791
-	foreach($chmodValues as $val)
5791
+	foreach ($chmodValues as $val)
5792 5792
 	{
5793 5793
 		// If it's writable, break out of the loop.
5794 5794
 		if (is_writable($file))
@@ -5823,13 +5823,13 @@  discard block
 block discarded – undo
5823 5823
 	$returnArray = @json_decode($json, $returnAsArray);
5824 5824
 
5825 5825
 	// PHP 5.3 so no json_last_error_msg()
5826
-	switch(json_last_error())
5826
+	switch (json_last_error())
5827 5827
 	{
5828 5828
 		case JSON_ERROR_NONE:
5829 5829
 			$jsonError = false;
5830 5830
 			break;
5831 5831
 		case JSON_ERROR_DEPTH:
5832
-			$jsonError =  'JSON_ERROR_DEPTH';
5832
+			$jsonError = 'JSON_ERROR_DEPTH';
5833 5833
 			break;
5834 5834
 		case JSON_ERROR_STATE_MISMATCH:
5835 5835
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5857,10 +5857,10 @@  discard block
 block discarded – undo
5857 5857
 		loadLanguage('Errors');
5858 5858
 
5859 5859
 		if (!empty($jsonDebug))
5860
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5860
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5861 5861
 
5862 5862
 		else
5863
-			log_error($txt['json_'. $jsonError], 'critical');
5863
+			log_error($txt['json_' . $jsonError], 'critical');
5864 5864
 
5865 5865
 		// Everyone expects an array.
5866 5866
 		return array();
@@ -5977,7 +5977,7 @@  discard block
 block discarded – undo
5977 5977
 		// Convert Punycode to Unicode
5978 5978
 		require_once($sourcedir . '/Class-Punycode.php');
5979 5979
 		$Punycode = new Punycode();
5980
-		$tlds = array_map(function ($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
5980
+		$tlds = array_map(function($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
5981 5981
 	}
5982 5982
 	// Otherwise, use the 2012 list of gTLDs and ccTLDs for now and schedule a background update
5983 5983
 	else
@@ -6071,7 +6071,7 @@  discard block
 block discarded – undo
6071 6071
 	}
6072 6072
 
6073 6073
 	// This recursive function creates the index array from the strings
6074
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6074
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6075 6075
 	{
6076 6076
 		static $depth = 0;
6077 6077
 		$depth++;
@@ -6098,7 +6098,7 @@  discard block
 block discarded – undo
6098 6098
 	};
6099 6099
 
6100 6100
 	// This recursive function turns the index array into a regular expression
6101
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
6101
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
6102 6102
 	{
6103 6103
 		static $depth = 0;
6104 6104
 		$depth++;
@@ -6122,11 +6122,11 @@  discard block
 block discarded – undo
6122 6122
 
6123 6123
 				if (count(array_keys($value)) == 1)
6124 6124
 				{
6125
-					$new_key_array = explode('(?'.'>', $sub_regex);
6125
+					$new_key_array = explode('(?' . '>', $sub_regex);
6126 6126
 					$new_key .= $new_key_array[0];
6127 6127
 				}
6128 6128
 				else
6129
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6129
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
6130 6130
 			}
6131 6131
 
6132 6132
 			if ($depth > 1)
@@ -6169,10 +6169,10 @@  discard block
 block discarded – undo
6169 6169
 	{
6170 6170
 		$regex = array();
6171 6171
 		while (!empty($index))
6172
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6172
+			$regex[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6173 6173
 	}
6174 6174
 	else
6175
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6175
+		$regex = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6176 6176
 
6177 6177
 	// Restore PHP's internal character encoding to whatever it was originally
6178 6178
 	if (!empty($current_encoding))
@@ -6396,7 +6396,7 @@  discard block
 block discarded – undo
6396 6396
 function sanitize_iri($iri)
6397 6397
 {
6398 6398
 	// Encode any non-ASCII characters (but not space or control characters of any sort)
6399
-	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function ($matches) {
6399
+	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function($matches) {
6400 6400
 		return rawurlencode($matches[0]);
6401 6401
 	}, $iri);
6402 6402
 
@@ -6438,7 +6438,7 @@  discard block
 block discarded – undo
6438 6438
 	$unescaped = array(
6439 6439
 		'%21'=>'!', '%23'=>'#', '%24'=>'$', '%26'=>'&',
6440 6440
 		'%27'=>"'", '%28'=>'(', '%29'=>')', '%2A'=>'*',
6441
-		'%2B'=>'+', '%2C'=>',',	'%2F'=>'/', '%3A'=>':',
6441
+		'%2B'=>'+', '%2C'=>',', '%2F'=>'/', '%3A'=>':',
6442 6442
 		'%3B'=>';', '%3D'=>'=', '%3F'=>'?', '%40'=>'@',
6443 6443
 	);
6444 6444
 	$iri = strtr(rawurlencode($iri), $unescaped);
Please login to merge, or discard this patch.
Braces   +1460 added lines, -1083 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
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -385,18 +394,17 @@  discard block
 block discarded – undo
385 394
 			if (is_array($members))
386 395
 			{
387 396
 				$val = 'CASE ';
388
-				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
397
+				foreach ($members as $k => $v) {
398
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				}
390 400
 				$val = $val . ' END';
391 401
 				$type = 'raw';
392
-			}
393
-			else
402
+			} else
394 403
 			{
395 404
 				$blub = fetch_alerts($members, false, 0, array(), false);
396 405
 				$val = count($blub);
397 406
 			}
398
-		}
399
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
407
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
400 408
 		{
401 409
 			$val = $var . ' ' . $val . ' 1';
402 410
 			$type = 'raw';
@@ -407,8 +415,9 @@  discard block
 block discarded – undo
407 415
 		{
408 416
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
409 417
 			{
410
-				if ($match[1] != '+ ')
411
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
418
+				if ($match[1] != '+ ') {
419
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				}
412 421
 				$type = 'raw';
413 422
 			}
414 423
 		}
@@ -429,8 +438,9 @@  discard block
 block discarded – undo
429 438
 	// Clear any caching?
430 439
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
431 440
 	{
432
-		if (!is_array($members))
433
-			$members = array($members);
441
+		if (!is_array($members)) {
442
+					$members = array($members);
443
+		}
434 444
 
435 445
 		foreach ($members as $member)
436 446
 		{
@@ -463,29 +473,32 @@  discard block
 block discarded – undo
463 473
 {
464 474
 	global $modSettings, $smcFunc;
465 475
 
466
-	if (empty($changeArray) || !is_array($changeArray))
467
-		return;
476
+	if (empty($changeArray) || !is_array($changeArray)) {
477
+			return;
478
+	}
468 479
 
469 480
 	$toRemove = array();
470 481
 
471 482
 	// Go check if there is any setting to be removed.
472
-	foreach ($changeArray as $k => $v)
473
-		if ($v === null)
483
+	foreach ($changeArray as $k => $v) {
484
+			if ($v === null)
474 485
 		{
475 486
 			// Found some, remove them from the original array and add them to ours.
476 487
 			unset($changeArray[$k]);
488
+	}
477 489
 			$toRemove[] = $k;
478 490
 		}
479 491
 
480 492
 	// Proceed with the deletion.
481
-	if (!empty($toRemove))
482
-		$smcFunc['db_query']('', '
493
+	if (!empty($toRemove)) {
494
+			$smcFunc['db_query']('', '
483 495
 			DELETE FROM {db_prefix}settings
484 496
 			WHERE variable IN ({array_string:remove})',
485 497
 			array(
486 498
 				'remove' => $toRemove,
487 499
 			)
488 500
 		);
501
+	}
489 502
 
490 503
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
491 504
 	if ($update)
@@ -514,19 +527,22 @@  discard block
 block discarded – undo
514 527
 	foreach ($changeArray as $variable => $value)
515 528
 	{
516 529
 		// Don't bother if it's already like that ;).
517
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
518
-			continue;
530
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
531
+					continue;
532
+		}
519 533
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
520
-		elseif (!isset($modSettings[$variable]) && empty($value))
521
-			continue;
534
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
535
+					continue;
536
+		}
522 537
 
523 538
 		$replaceArray[] = array($variable, $value);
524 539
 
525 540
 		$modSettings[$variable] = $value;
526 541
 	}
527 542
 
528
-	if (empty($replaceArray))
529
-		return;
543
+	if (empty($replaceArray)) {
544
+			return;
545
+	}
530 546
 
531 547
 	$smcFunc['db_insert']('replace',
532 548
 		'{db_prefix}settings',
@@ -572,14 +588,17 @@  discard block
 block discarded – undo
572 588
 	$start_invalid = $start < 0;
573 589
 
574 590
 	// Make sure $start is a proper variable - not less than 0.
575
-	if ($start_invalid)
576
-		$start = 0;
591
+	if ($start_invalid) {
592
+			$start = 0;
593
+	}
577 594
 	// Not greater than the upper bound.
578
-	elseif ($start >= $max_value)
579
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
595
+	elseif ($start >= $max_value) {
596
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	}
580 598
 	// And it has to be a multiple of $num_per_page!
581
-	else
582
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
599
+	else {
600
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	}
583 602
 
584 603
 	$context['current_page'] = $start / $num_per_page;
585 604
 
@@ -609,77 +628,87 @@  discard block
 block discarded – undo
609 628
 
610 629
 		// Show all the pages.
611 630
 		$display_page = 1;
612
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
613
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
632
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		}
614 634
 
615 635
 		// Show the right arrow.
616 636
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
617
-		if ($start != $counter - $max_value && !$start_invalid)
618
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
619
-	}
620
-	else
637
+		if ($start != $counter - $max_value && !$start_invalid) {
638
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
639
+		}
640
+	} else
621 641
 	{
622 642
 		// If they didn't enter an odd value, pretend they did.
623 643
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
624 644
 
625 645
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
626
-		if (!empty($start) && $show_prevnext)
627
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-		else
629
-			$pageindex .= '';
646
+		if (!empty($start) && $show_prevnext) {
647
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
648
+		} else {
649
+					$pageindex .= '';
650
+		}
630 651
 
631 652
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
632
-		if ($start > $num_per_page * $PageContiguous)
633
-			$pageindex .= sprintf($base_link, 0, '1');
653
+		if ($start > $num_per_page * $PageContiguous) {
654
+					$pageindex .= sprintf($base_link, 0, '1');
655
+		}
634 656
 
635 657
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
636
-		if ($start > $num_per_page * ($PageContiguous + 1))
637
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
658
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
659
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
638 660
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
639 661
 				'{FIRST_PAGE}' => $num_per_page,
640 662
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
641 663
 				'{PER_PAGE}' => $num_per_page,
642 664
 			));
665
+		}
643 666
 
644 667
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
645
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
646
-			if ($start >= $num_per_page * $nCont)
668
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
669
+					if ($start >= $num_per_page * $nCont)
647 670
 			{
648 671
 				$tmpStart = $start - $num_per_page * $nCont;
672
+		}
649 673
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
650 674
 			}
651 675
 
652 676
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
653
-		if (!$start_invalid)
654
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
655
-		else
656
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
677
+		if (!$start_invalid) {
678
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
679
+		} else {
680
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
681
+		}
657 682
 
658 683
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
659 684
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
660
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
661
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
685
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
686
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
662 687
 			{
663 688
 				$tmpStart = $start + $num_per_page * $nCont;
689
+		}
664 690
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
665 691
 			}
666 692
 
667 693
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
668
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
669
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
694
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
695
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
670 696
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
671 697
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
672 698
 				'{LAST_PAGE}' => $tmpMaxPages,
673 699
 				'{PER_PAGE}' => $num_per_page,
674 700
 			));
701
+		}
675 702
 
676 703
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
677
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
678
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
704
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
705
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		}
679 707
 
680 708
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
681
-		if ($start != $tmpMaxPages && $show_prevnext)
682
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
709
+		if ($start != $tmpMaxPages && $show_prevnext) {
710
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		}
683 712
 	}
684 713
 	$pageindex .= $settings['page_index']['extra_after'];
685 714
 
@@ -705,8 +734,9 @@  discard block
 block discarded – undo
705 734
 	if ($decimal_separator === null)
706 735
 	{
707 736
 		// Not set for whatever reason?
708
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
709
-			return $number;
737
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
738
+					return $number;
739
+		}
710 740
 
711 741
 		// Cache these each load...
712 742
 		$thousands_separator = $matches[1];
@@ -747,17 +777,20 @@  discard block
 block discarded – undo
747 777
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
748 778
 
749 779
 	// Offset the time.
750
-	if (!$offset_type)
751
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
780
+	if (!$offset_type) {
781
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	}
752 783
 	// Just the forum offset?
753
-	elseif ($offset_type == 'forum')
754
-		$time = $log_time + $modSettings['time_offset'] * 3600;
755
-	else
756
-		$time = $log_time;
784
+	elseif ($offset_type == 'forum') {
785
+			$time = $log_time + $modSettings['time_offset'] * 3600;
786
+	} else {
787
+			$time = $log_time;
788
+	}
757 789
 
758 790
 	// We can't have a negative date (on Windows, at least.)
759
-	if ($log_time < 0)
760
-		$log_time = 0;
791
+	if ($log_time < 0) {
792
+			$log_time = 0;
793
+	}
761 794
 
762 795
 	// Today and Yesterday?
763 796
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -774,24 +807,27 @@  discard block
 block discarded – undo
774 807
 		{
775 808
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
776 809
 			$today_fmt = $h . ':%M' . $s . ' %p';
810
+		} else {
811
+					$today_fmt = '%H:%M' . $s;
777 812
 		}
778
-		else
779
-			$today_fmt = '%H:%M' . $s;
780 813
 
781 814
 		// Same day of the year, same year.... Today!
782
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
783
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
816
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		}
784 818
 
785 819
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
786
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
787
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
820
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
821
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		}
788 823
 	}
789 824
 
790 825
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
791 826
 
792 827
 	// Use the cached formats if available
793
-	if (is_null($finalizedFormats))
794
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
828
+	if (is_null($finalizedFormats)) {
829
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	}
795 831
 
796 832
 	// Make a supported version for this format if we don't already have one
797 833
 	if (empty($finalizedFormats[$str]))
@@ -820,8 +856,9 @@  discard block
 block discarded – undo
820 856
 		);
821 857
 
822 858
 		// No need to do this part again if we already did it once
823
-		if (is_null($unsupportedFormats))
824
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
859
+		if (is_null($unsupportedFormats)) {
860
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		}
825 862
 		if (empty($unsupportedFormats))
826 863
 		{
827 864
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -837,20 +874,23 @@  discard block
 block discarded – undo
837 874
 
838 875
 				// Windows will return false for unsupported formats
839 876
 				// Other operating systems return the format string as a literal
840
-				if ($value === false || $value === $format)
841
-					$unsupportedFormats[] = $format;
877
+				if ($value === false || $value === $format) {
878
+									$unsupportedFormats[] = $format;
879
+				}
842 880
 			}
843 881
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
844 882
 		}
845 883
 
846 884
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
847
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
848
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
885
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
886
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		}
849 888
 
850 889
 		// Substitute unsupported formats with supported ones
851
-		if (!empty($unsupportedFormats))
852
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
890
+		if (!empty($unsupportedFormats)) {
891
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
853 892
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
893
+		}
854 894
 
855 895
 		// Remember this so we don't need to do it again
856 896
 		$finalizedFormats[$str] = $timeformat;
@@ -859,33 +899,39 @@  discard block
 block discarded – undo
859 899
 
860 900
 	$str = $finalizedFormats[$str];
861 901
 
862
-	if (!isset($locale_cache))
863
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
902
+	if (!isset($locale_cache)) {
903
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	}
864 905
 
865 906
 	if ($locale_cache !== false)
866 907
 	{
867 908
 		// Check if another process changed the locale
868
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
869
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
909
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
910
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		}
870 912
 
871
-		if (!isset($non_twelve_hour))
872
-			$non_twelve_hour = trim(strftime('%p')) === '';
873
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
874
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
913
+		if (!isset($non_twelve_hour)) {
914
+					$non_twelve_hour = trim(strftime('%p')) === '';
915
+		}
916
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
917
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
918
+		}
875 919
 
876
-		foreach (array('%a', '%A', '%b', '%B') as $token)
877
-			if (strpos($str, $token) !== false)
920
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
921
+					if (strpos($str, $token) !== false)
878 922
 				$str = str_replace($token, strftime($token, $time), $str);
879
-	}
880
-	else
923
+		}
924
+	} else
881 925
 	{
882 926
 		// Do-it-yourself time localization.  Fun.
883
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
884
-			if (strpos($str, $token) !== false)
927
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
928
+					if (strpos($str, $token) !== false)
885 929
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
930
+		}
886 931
 
887
-		if (strpos($str, '%p') !== false)
888
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
932
+		if (strpos($str, '%p') !== false) {
933
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		}
889 935
 	}
890 936
 
891 937
 	// Format the time and then restore any literal percent characters
@@ -908,16 +954,19 @@  discard block
 block discarded – undo
908 954
 	static $translation = array();
909 955
 
910 956
 	// Determine the character set... Default to UTF-8
911
-	if (empty($context['character_set']))
912
-		$charset = 'UTF-8';
957
+	if (empty($context['character_set'])) {
958
+			$charset = 'UTF-8';
959
+	}
913 960
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
914
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
915
-		$charset = 'ISO-8859-1';
916
-	else
917
-		$charset = $context['character_set'];
961
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
962
+			$charset = 'ISO-8859-1';
963
+	} else {
964
+			$charset = $context['character_set'];
965
+	}
918 966
 
919
-	if (empty($translation))
920
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
967
+	if (empty($translation)) {
968
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	}
921 970
 
922 971
 	return strtr($string, $translation);
923 972
 }
@@ -939,8 +988,9 @@  discard block
 block discarded – undo
939 988
 	global $smcFunc;
940 989
 
941 990
 	// It was already short enough!
942
-	if ($smcFunc['strlen']($subject) <= $len)
943
-		return $subject;
991
+	if ($smcFunc['strlen']($subject) <= $len) {
992
+			return $subject;
993
+	}
944 994
 
945 995
 	// Shorten it by the length it was too long, and strip off junk from the end.
946 996
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -959,10 +1009,11 @@  discard block
 block discarded – undo
959 1009
 {
960 1010
 	global $user_info, $modSettings;
961 1011
 
962
-	if ($timestamp === null)
963
-		$timestamp = time();
964
-	elseif ($timestamp == 0)
965
-		return 0;
1012
+	if ($timestamp === null) {
1013
+			$timestamp = time();
1014
+	} elseif ($timestamp == 0) {
1015
+			return 0;
1016
+	}
966 1017
 
967 1018
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
968 1019
 }
@@ -991,8 +1042,9 @@  discard block
 block discarded – undo
991 1042
 		$array[$i] = $array[$j];
992 1043
 		$array[$j] = $temp;
993 1044
 
994
-		for ($i = 1; $p[$i] == 0; $i++)
995
-			$p[$i] = 1;
1045
+		for ($i = 1; $p[$i] == 0; $i++) {
1046
+					$p[$i] = 1;
1047
+		}
996 1048
 
997 1049
 		$orders[] = $array;
998 1050
 	}
@@ -1024,12 +1076,14 @@  discard block
 block discarded – undo
1024 1076
 	static $disabled;
1025 1077
 
1026 1078
 	// Don't waste cycles
1027
-	if ($message === '')
1028
-		return '';
1079
+	if ($message === '') {
1080
+			return '';
1081
+	}
1029 1082
 
1030 1083
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1031
-	if (!isset($context['utf8']))
1032
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1084
+	if (!isset($context['utf8'])) {
1085
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	}
1033 1087
 
1034 1088
 	// Clean up any cut/paste issues we may have
1035 1089
 	$message = sanitizeMSCutPaste($message);
@@ -1041,13 +1095,15 @@  discard block
 block discarded – undo
1041 1095
 		return $message;
1042 1096
 	}
1043 1097
 
1044
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1045
-		$smileys = (bool) $smileys;
1098
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1099
+			$smileys = (bool) $smileys;
1100
+	}
1046 1101
 
1047 1102
 	if (empty($modSettings['enableBBC']) && $message !== false)
1048 1103
 	{
1049
-		if ($smileys === true)
1050
-			parsesmileys($message);
1104
+		if ($smileys === true) {
1105
+					parsesmileys($message);
1106
+		}
1051 1107
 
1052 1108
 		return $message;
1053 1109
 	}
@@ -1060,8 +1116,9 @@  discard block
 block discarded – undo
1060 1116
 	}
1061 1117
 
1062 1118
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1063
-	if (!empty($modSettings['autoLinkUrls']))
1064
-		set_tld_regex();
1119
+	if (!empty($modSettings['autoLinkUrls'])) {
1120
+			set_tld_regex();
1121
+	}
1065 1122
 
1066 1123
 	// Allow mods access before entering the main parse_bbc loop
1067 1124
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1075,12 +1132,14 @@  discard block
 block discarded – undo
1075 1132
 
1076 1133
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1077 1134
 
1078
-			foreach ($temp as $tag)
1079
-				$disabled[trim($tag)] = true;
1135
+			foreach ($temp as $tag) {
1136
+							$disabled[trim($tag)] = true;
1137
+			}
1080 1138
 		}
1081 1139
 
1082
-		if (empty($modSettings['enableEmbeddedFlash']))
1083
-			$disabled['flash'] = true;
1140
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1141
+					$disabled['flash'] = true;
1142
+		}
1084 1143
 
1085 1144
 		/* The following bbc are formatted as an array, with keys as follows:
1086 1145
 
@@ -1201,8 +1260,9 @@  discard block
 block discarded – undo
1201 1260
 					$returnContext = '';
1202 1261
 
1203 1262
 					// BBC or the entire attachments feature is disabled
1204
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1205
-						return $data;
1263
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1264
+											return $data;
1265
+					}
1206 1266
 
1207 1267
 					// Save the attach ID.
1208 1268
 					$attachID = $data;
@@ -1213,8 +1273,9 @@  discard block
 block discarded – undo
1213 1273
 					$currentAttachment = parseAttachBBC($attachID);
1214 1274
 
1215 1275
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1216
-					if (is_string($currentAttachment))
1217
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1276
+					if (is_string($currentAttachment)) {
1277
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1278
+					}
1218 1279
 
1219 1280
 					if (!empty($currentAttachment['is_image']))
1220 1281
 					{
@@ -1230,15 +1291,17 @@  discard block
 block discarded – undo
1230 1291
 							$height = ' height="' . $currentAttachment['height'] . '"';
1231 1292
 						}
1232 1293
 
1233
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1234
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1235
-						else
1236
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1294
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1295
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1296
+						} else {
1297
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1298
+						}
1237 1299
 					}
1238 1300
 
1239 1301
 					// No image. Show a link.
1240
-					else
1241
-						$returnContext .= $currentAttachment['link'];
1302
+					else {
1303
+											$returnContext .= $currentAttachment['link'];
1304
+					}
1242 1305
 
1243 1306
 					// Gotta append what we just did.
1244 1307
 					$data = $returnContext;
@@ -1269,8 +1332,9 @@  discard block
 block discarded – undo
1269 1332
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1270 1333
 						{
1271 1334
 							// Do PHP code coloring?
1272
-							if ($php_parts[$php_i] != '&lt;?php')
1273
-								continue;
1335
+							if ($php_parts[$php_i] != '&lt;?php') {
1336
+															continue;
1337
+							}
1274 1338
 
1275 1339
 							$php_string = '';
1276 1340
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1286,8 +1350,9 @@  discard block
 block discarded – undo
1286 1350
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1287 1351
 
1288 1352
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1289
-						if ($context['browser']['is_opera'])
1290
-							$data .= '&nbsp;';
1353
+						if ($context['browser']['is_opera']) {
1354
+													$data .= '&nbsp;';
1355
+						}
1291 1356
 					}
1292 1357
 				},
1293 1358
 				'block_level' => true,
@@ -1306,8 +1371,9 @@  discard block
 block discarded – undo
1306 1371
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1307 1372
 						{
1308 1373
 							// Do PHP code coloring?
1309
-							if ($php_parts[$php_i] != '&lt;?php')
1310
-								continue;
1374
+							if ($php_parts[$php_i] != '&lt;?php') {
1375
+															continue;
1376
+							}
1311 1377
 
1312 1378
 							$php_string = '';
1313 1379
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1323,8 +1389,9 @@  discard block
 block discarded – undo
1323 1389
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1324 1390
 
1325 1391
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1326
-						if ($context['browser']['is_opera'])
1327
-							$data[0] .= '&nbsp;';
1392
+						if ($context['browser']['is_opera']) {
1393
+													$data[0] .= '&nbsp;';
1394
+						}
1328 1395
 					}
1329 1396
 				},
1330 1397
 				'block_level' => true,
@@ -1362,11 +1429,13 @@  discard block
 block discarded – undo
1362 1429
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1363 1430
 				'validate' => function (&$tag, &$data, $disabled)
1364 1431
 				{
1365
-					if (isset($disabled['url']))
1366
-						$tag['content'] = '$1';
1432
+					if (isset($disabled['url'])) {
1433
+											$tag['content'] = '$1';
1434
+					}
1367 1435
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1368
-					if (empty($scheme))
1369
-						$data[0] = '//' . ltrim($data[0], ':/');
1436
+					if (empty($scheme)) {
1437
+											$data[0] = '//' . ltrim($data[0], ':/');
1438
+					}
1370 1439
 				},
1371 1440
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1372 1441
 			),
@@ -1380,10 +1449,11 @@  discard block
 block discarded – undo
1380 1449
 				{
1381 1450
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1382 1451
 
1383
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1384
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1385
-					else
1386
-						$css = '';
1452
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1453
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1454
+					} else {
1455
+											$css = '';
1456
+					}
1387 1457
 
1388 1458
 					$data = $class . $css;
1389 1459
 				},
@@ -1433,17 +1503,20 @@  discard block
 block discarded – undo
1433 1503
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1434 1504
 					if ($image_proxy_enabled)
1435 1505
 					{
1436
-						if (!empty($user_info['possibly_robot']))
1437
-							return;
1506
+						if (!empty($user_info['possibly_robot'])) {
1507
+													return;
1508
+						}
1438 1509
 
1439
-						if (empty($scheme))
1440
-							$data = 'http://' . ltrim($data, ':/');
1510
+						if (empty($scheme)) {
1511
+													$data = 'http://' . ltrim($data, ':/');
1512
+						}
1441 1513
 
1442
-						if ($scheme != 'https')
1443
-							$data = get_proxied_url($data);
1514
+						if ($scheme != 'https') {
1515
+													$data = get_proxied_url($data);
1516
+						}
1517
+					} elseif (empty($scheme)) {
1518
+											$data = '//' . ltrim($data, ':/');
1444 1519
 					}
1445
-					elseif (empty($scheme))
1446
-						$data = '//' . ltrim($data, ':/');
1447 1520
 				},
1448 1521
 				'disabled_content' => '($1)',
1449 1522
 			),
@@ -1459,17 +1532,20 @@  discard block
 block discarded – undo
1459 1532
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1460 1533
 					if ($image_proxy_enabled)
1461 1534
 					{
1462
-						if (!empty($user_info['possibly_robot']))
1463
-							return;
1535
+						if (!empty($user_info['possibly_robot'])) {
1536
+													return;
1537
+						}
1464 1538
 
1465
-						if (empty($scheme))
1466
-							$data = 'http://' . ltrim($data, ':/');
1539
+						if (empty($scheme)) {
1540
+													$data = 'http://' . ltrim($data, ':/');
1541
+						}
1467 1542
 
1468
-						if ($scheme != 'https')
1469
-							$data = get_proxied_url($data);
1543
+						if ($scheme != 'https') {
1544
+													$data = get_proxied_url($data);
1545
+						}
1546
+					} elseif (empty($scheme)) {
1547
+											$data = '//' . ltrim($data, ':/');
1470 1548
 					}
1471
-					elseif (empty($scheme))
1472
-						$data = '//' . ltrim($data, ':/');
1473 1549
 				},
1474 1550
 				'disabled_content' => '($1)',
1475 1551
 			),
@@ -1481,8 +1557,9 @@  discard block
 block discarded – undo
1481 1557
 				{
1482 1558
 					$data = strtr($data, array('<br>' => ''));
1483 1559
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1484
-					if (empty($scheme))
1485
-						$data = '//' . ltrim($data, ':/');
1560
+					if (empty($scheme)) {
1561
+											$data = '//' . ltrim($data, ':/');
1562
+					}
1486 1563
 				},
1487 1564
 			),
1488 1565
 			array(
@@ -1493,13 +1570,14 @@  discard block
 block discarded – undo
1493 1570
 				'after' => '</a>',
1494 1571
 				'validate' => function (&$tag, &$data, $disabled)
1495 1572
 				{
1496
-					if (substr($data, 0, 1) == '#')
1497
-						$data = '#post_' . substr($data, 1);
1498
-					else
1573
+					if (substr($data, 0, 1) == '#') {
1574
+											$data = '#post_' . substr($data, 1);
1575
+					} else
1499 1576
 					{
1500 1577
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1501
-						if (empty($scheme))
1502
-							$data = '//' . ltrim($data, ':/');
1578
+						if (empty($scheme)) {
1579
+													$data = '//' . ltrim($data, ':/');
1580
+						}
1503 1581
 					}
1504 1582
 				},
1505 1583
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1583,8 +1661,9 @@  discard block
 block discarded – undo
1583 1661
 					{
1584 1662
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1585 1663
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1586
-						if ($add_begin)
1587
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1664
+						if ($add_begin) {
1665
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1666
+						}
1588 1667
 					}
1589 1668
 				},
1590 1669
 				'block_level' => false,
@@ -1715,10 +1794,11 @@  discard block
 block discarded – undo
1715 1794
 				'content' => '$1',
1716 1795
 				'validate' => function (&$tag, &$data, $disabled)
1717 1796
 				{
1718
-					if (is_numeric($data))
1719
-						$data = timeformat($data);
1720
-					else
1721
-						$tag['content'] = '[time]$1[/time]';
1797
+					if (is_numeric($data)) {
1798
+											$data = timeformat($data);
1799
+					} else {
1800
+											$tag['content'] = '[time]$1[/time]';
1801
+					}
1722 1802
 				},
1723 1803
 			),
1724 1804
 			array(
@@ -1745,8 +1825,9 @@  discard block
 block discarded – undo
1745 1825
 				{
1746 1826
 					$data = strtr($data, array('<br>' => ''));
1747 1827
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1748
-					if (empty($scheme))
1749
-						$data = '//' . ltrim($data, ':/');
1828
+					if (empty($scheme)) {
1829
+											$data = '//' . ltrim($data, ':/');
1830
+					}
1750 1831
 				},
1751 1832
 			),
1752 1833
 			array(
@@ -1758,8 +1839,9 @@  discard block
 block discarded – undo
1758 1839
 				'validate' => function (&$tag, &$data, $disabled)
1759 1840
 				{
1760 1841
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1761
-					if (empty($scheme))
1762
-						$data = '//' . ltrim($data, ':/');
1842
+					if (empty($scheme)) {
1843
+											$data = '//' . ltrim($data, ':/');
1844
+					}
1763 1845
 				},
1764 1846
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1765 1847
 				'disabled_after' => ' ($1)',
@@ -1785,8 +1867,9 @@  discard block
 block discarded – undo
1785 1867
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1786 1868
 		if ($message === false)
1787 1869
 		{
1788
-			if (isset($temp_bbc))
1789
-				$bbc_codes = $temp_bbc;
1870
+			if (isset($temp_bbc)) {
1871
+							$bbc_codes = $temp_bbc;
1872
+			}
1790 1873
 			usort($codes, function ($a, $b) {
1791 1874
 				return strcmp($a['tag'], $b['tag']);
1792 1875
 			});
@@ -1806,8 +1889,9 @@  discard block
 block discarded – undo
1806 1889
 		);
1807 1890
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1808 1891
 		{
1809
-			foreach ($itemcodes as $c => $dummy)
1810
-				$bbc_codes[$c] = array();
1892
+			foreach ($itemcodes as $c => $dummy) {
1893
+							$bbc_codes[$c] = array();
1894
+			}
1811 1895
 		}
1812 1896
 
1813 1897
 		// Shhhh!
@@ -1828,12 +1912,14 @@  discard block
 block discarded – undo
1828 1912
 		foreach ($codes as $code)
1829 1913
 		{
1830 1914
 			// Make it easier to process parameters later
1831
-			if (!empty($code['parameters']))
1832
-				ksort($code['parameters'], SORT_STRING);
1915
+			if (!empty($code['parameters'])) {
1916
+							ksort($code['parameters'], SORT_STRING);
1917
+			}
1833 1918
 
1834 1919
 			// If we are not doing every tag only do ones we are interested in.
1835
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1836
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1920
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1921
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1922
+			}
1837 1923
 		}
1838 1924
 		$codes = null;
1839 1925
 	}
@@ -1844,8 +1930,9 @@  discard block
 block discarded – undo
1844 1930
 		// It's likely this will change if the message is modified.
1845 1931
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1846 1932
 
1847
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1848
-			return $temp;
1933
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1934
+					return $temp;
1935
+		}
1849 1936
 
1850 1937
 		$cache_t = microtime();
1851 1938
 	}
@@ -1877,8 +1964,9 @@  discard block
 block discarded – undo
1877 1964
 		$disabled['flash'] = true;
1878 1965
 
1879 1966
 		// @todo Change maybe?
1880
-		if (!isset($_GET['images']))
1881
-			$disabled['img'] = true;
1967
+		if (!isset($_GET['images'])) {
1968
+					$disabled['img'] = true;
1969
+		}
1882 1970
 
1883 1971
 		// @todo Interface/setting to add more?
1884 1972
 	}
@@ -1889,8 +1977,9 @@  discard block
 block discarded – undo
1889 1977
 	$alltags = array();
1890 1978
 	foreach ($bbc_codes as $section)
1891 1979
 	{
1892
-		foreach ($section as $code)
1893
-			$alltags[] = $code['tag'];
1980
+		foreach ($section as $code) {
1981
+					$alltags[] = $code['tag'];
1982
+		}
1894 1983
 	}
1895 1984
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
1896 1985
 
@@ -1902,8 +1991,9 @@  discard block
 block discarded – undo
1902 1991
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1903 1992
 
1904 1993
 		// Failsafe.
1905
-		if ($pos === false || $last_pos > $pos)
1906
-			$pos = strlen($message) + 1;
1994
+		if ($pos === false || $last_pos > $pos) {
1995
+					$pos = strlen($message) + 1;
1996
+		}
1907 1997
 
1908 1998
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1909 1999
 		if ($last_pos < $pos - 1)
@@ -1921,8 +2011,9 @@  discard block
 block discarded – undo
1921 2011
 
1922 2012
 				// <br> should be empty.
1923 2013
 				$empty_tags = array('br', 'hr');
1924
-				foreach ($empty_tags as $tag)
1925
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2014
+				foreach ($empty_tags as $tag) {
2015
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2016
+				}
1926 2017
 
1927 2018
 				// b, u, i, s, pre... basic tags.
1928 2019
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1931,8 +2022,9 @@  discard block
 block discarded – undo
1931 2022
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1932 2023
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1933 2024
 
1934
-					if ($diff > 0)
1935
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2025
+					if ($diff > 0) {
2026
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2027
+					}
1936 2028
 				}
1937 2029
 
1938 2030
 				// Do <img ...> - with security... action= -> action-.
@@ -1945,8 +2037,9 @@  discard block
 block discarded – undo
1945 2037
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1946 2038
 
1947 2039
 						// Remove action= from the URL - no funny business, now.
1948
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1949
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2040
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2041
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2042
+						}
1950 2043
 
1951 2044
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1952 2045
 					}
@@ -1961,16 +2054,18 @@  discard block
 block discarded – undo
1961 2054
 				$no_autolink_area = false;
1962 2055
 				if (!empty($open_tags))
1963 2056
 				{
1964
-					foreach ($open_tags as $open_tag)
1965
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2057
+					foreach ($open_tags as $open_tag) {
2058
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1966 2059
 							$no_autolink_area = true;
2060
+					}
1967 2061
 				}
1968 2062
 
1969 2063
 				// Don't go backwards.
1970 2064
 				// @todo Don't think is the real solution....
1971 2065
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1972
-				if ($pos < $lastAutoPos)
1973
-					$no_autolink_area = true;
2066
+				if ($pos < $lastAutoPos) {
2067
+									$no_autolink_area = true;
2068
+				}
1974 2069
 				$lastAutoPos = $pos;
1975 2070
 
1976 2071
 				if (!$no_autolink_area)
@@ -2075,29 +2170,33 @@  discard block
 block discarded – undo
2075 2170
 							$url = array_shift($matches);
2076 2171
 
2077 2172
 							// If this isn't a clean URL, bail out
2078
-							if ($url != sanitize_iri($url))
2079
-								return $url;
2173
+							if ($url != sanitize_iri($url)) {
2174
+															return $url;
2175
+							}
2080 2176
 
2081 2177
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2082 2178
 
2083 2179
 							if ($scheme == 'mailto')
2084 2180
 							{
2085 2181
 								$email_address = str_replace('mailto:', '', $url);
2086
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2087
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2088
-								else
2089
-									return $url;
2182
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2183
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2184
+								} else {
2185
+																	return $url;
2186
+								}
2090 2187
 							}
2091 2188
 
2092 2189
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2093
-							if (empty($scheme))
2094
-								$fullUrl = '//' . ltrim($url, ':/');
2095
-							else
2096
-								$fullUrl = $url;
2190
+							if (empty($scheme)) {
2191
+															$fullUrl = '//' . ltrim($url, ':/');
2192
+							} else {
2193
+															$fullUrl = $url;
2194
+							}
2097 2195
 
2098 2196
 							// Make sure that $fullUrl really is valid
2099
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2100
-								return $url;
2197
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2198
+															return $url;
2199
+							}
2101 2200
 
2102 2201
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2103 2202
 						}, $data);
@@ -2146,22 +2245,25 @@  discard block
 block discarded – undo
2146 2245
 		}
2147 2246
 
2148 2247
 		// Are we there yet?  Are we there yet?
2149
-		if ($pos >= strlen($message) - 1)
2150
-			break;
2248
+		if ($pos >= strlen($message) - 1) {
2249
+					break;
2250
+		}
2151 2251
 
2152 2252
 		$tags = strtolower($message[$pos + 1]);
2153 2253
 
2154 2254
 		if ($tags == '/' && !empty($open_tags))
2155 2255
 		{
2156 2256
 			$pos2 = strpos($message, ']', $pos + 1);
2157
-			if ($pos2 == $pos + 2)
2158
-				continue;
2257
+			if ($pos2 == $pos + 2) {
2258
+							continue;
2259
+			}
2159 2260
 
2160 2261
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2161 2262
 
2162 2263
 			// A closing tag that doesn't match any open tags? Skip it.
2163
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2164
-				continue;
2264
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2265
+							continue;
2266
+			}
2165 2267
 
2166 2268
 			$to_close = array();
2167 2269
 			$block_level = null;
@@ -2169,8 +2271,9 @@  discard block
 block discarded – undo
2169 2271
 			do
2170 2272
 			{
2171 2273
 				$tag = array_pop($open_tags);
2172
-				if (!$tag)
2173
-					break;
2274
+				if (!$tag) {
2275
+									break;
2276
+				}
2174 2277
 
2175 2278
 				if (!empty($tag['block_level']))
2176 2279
 				{
@@ -2184,10 +2287,11 @@  discard block
 block discarded – undo
2184 2287
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2185 2288
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2186 2289
 					{
2187
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2188
-							if ($temp['tag'] == $look_for)
2290
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2291
+													if ($temp['tag'] == $look_for)
2189 2292
 							{
2190 2293
 								$block_level = !empty($temp['block_level']);
2294
+						}
2191 2295
 								break;
2192 2296
 							}
2193 2297
 					}
@@ -2209,15 +2313,15 @@  discard block
 block discarded – undo
2209 2313
 			{
2210 2314
 				$open_tags = $to_close;
2211 2315
 				continue;
2212
-			}
2213
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2316
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2214 2317
 			{
2215 2318
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2216 2319
 				{
2217
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2218
-						if ($temp['tag'] == $look_for)
2320
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2321
+											if ($temp['tag'] == $look_for)
2219 2322
 						{
2220 2323
 							$block_level = !empty($temp['block_level']);
2324
+					}
2221 2325
 							break;
2222 2326
 						}
2223 2327
 				}
@@ -2225,8 +2329,9 @@  discard block
 block discarded – undo
2225 2329
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2226 2330
 				if (!$block_level)
2227 2331
 				{
2228
-					foreach ($to_close as $tag)
2229
-						array_push($open_tags, $tag);
2332
+					foreach ($to_close as $tag) {
2333
+											array_push($open_tags, $tag);
2334
+					}
2230 2335
 					continue;
2231 2336
 				}
2232 2337
 			}
@@ -2239,14 +2344,17 @@  discard block
 block discarded – undo
2239 2344
 
2240 2345
 				// See the comment at the end of the big loop - just eating whitespace ;).
2241 2346
 				$whitespace_regex = '';
2242
-				if (!empty($tag['block_level']))
2243
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2347
+				if (!empty($tag['block_level'])) {
2348
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2349
+				}
2244 2350
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2245
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2246
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2351
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2352
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2353
+				}
2247 2354
 
2248
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2249
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2355
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2356
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2357
+				}
2250 2358
 			}
2251 2359
 
2252 2360
 			if (!empty($to_close))
@@ -2259,8 +2367,9 @@  discard block
 block discarded – undo
2259 2367
 		}
2260 2368
 
2261 2369
 		// No tags for this character, so just keep going (fastest possible course.)
2262
-		if (!isset($bbc_codes[$tags]))
2263
-			continue;
2370
+		if (!isset($bbc_codes[$tags])) {
2371
+					continue;
2372
+		}
2264 2373
 
2265 2374
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2266 2375
 		$tag = null;
@@ -2269,48 +2378,57 @@  discard block
 block discarded – undo
2269 2378
 			$pt_strlen = strlen($possible['tag']);
2270 2379
 
2271 2380
 			// Not a match?
2272
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2273
-				continue;
2381
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2382
+							continue;
2383
+			}
2274 2384
 
2275 2385
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2276 2386
 
2277 2387
 			// A tag is the last char maybe
2278
-			if ($next_c == '')
2279
-				break;
2388
+			if ($next_c == '') {
2389
+							break;
2390
+			}
2280 2391
 
2281 2392
 			// A test validation?
2282
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2283
-				continue;
2393
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2394
+							continue;
2395
+			}
2284 2396
 			// Do we want parameters?
2285 2397
 			elseif (!empty($possible['parameters']))
2286 2398
 			{
2287
-				if ($next_c != ' ')
2288
-					continue;
2289
-			}
2290
-			elseif (isset($possible['type']))
2399
+				if ($next_c != ' ') {
2400
+									continue;
2401
+				}
2402
+			} elseif (isset($possible['type']))
2291 2403
 			{
2292 2404
 				// Do we need an equal sign?
2293
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2294
-					continue;
2405
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2406
+									continue;
2407
+				}
2295 2408
 				// Maybe we just want a /...
2296
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2297
-					continue;
2409
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2410
+									continue;
2411
+				}
2298 2412
 				// An immediate ]?
2299
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2300
-					continue;
2413
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2414
+									continue;
2415
+				}
2301 2416
 			}
2302 2417
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2303
-			elseif ($next_c != ']')
2304
-				continue;
2418
+			elseif ($next_c != ']') {
2419
+							continue;
2420
+			}
2305 2421
 
2306 2422
 			// Check allowed tree?
2307
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2308
-				continue;
2309
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2310
-				continue;
2423
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2424
+							continue;
2425
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2426
+							continue;
2427
+			}
2311 2428
 			// If this is in the list of disallowed child tags, don't parse it.
2312
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2313
-				continue;
2429
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2430
+							continue;
2431
+			}
2314 2432
 
2315 2433
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2316 2434
 
@@ -2322,8 +2440,9 @@  discard block
 block discarded – undo
2322 2440
 				foreach ($open_tags as $open_quote)
2323 2441
 				{
2324 2442
 					// Every parent quote this quote has flips the styling
2325
-					if ($open_quote['tag'] == 'quote')
2326
-						$quote_alt = !$quote_alt;
2443
+					if ($open_quote['tag'] == 'quote') {
2444
+											$quote_alt = !$quote_alt;
2445
+					}
2327 2446
 				}
2328 2447
 				// Add a class to the quote to style alternating blockquotes
2329 2448
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2334,8 +2453,9 @@  discard block
 block discarded – undo
2334 2453
 			{
2335 2454
 				// Build a regular expression for each parameter for the current tag.
2336 2455
 				$preg = array();
2337
-				foreach ($possible['parameters'] as $p => $info)
2338
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2456
+				foreach ($possible['parameters'] as $p => $info) {
2457
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2458
+				}
2339 2459
 
2340 2460
 				// Extract the string that potentially holds our parameters.
2341 2461
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2354,24 +2474,27 @@  discard block
 block discarded – undo
2354 2474
 
2355 2475
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2356 2476
 
2357
-					if ($match)
2358
-						$blob_counter = count($blobs) + 1;
2477
+					if ($match) {
2478
+											$blob_counter = count($blobs) + 1;
2479
+					}
2359 2480
 				}
2360 2481
 
2361 2482
 				// Didn't match our parameter list, try the next possible.
2362
-				if (!$match)
2363
-					continue;
2483
+				if (!$match) {
2484
+									continue;
2485
+				}
2364 2486
 
2365 2487
 				$params = array();
2366 2488
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2367 2489
 				{
2368 2490
 					$key = strtok(ltrim($matches[$i]), '=');
2369
-					if (isset($possible['parameters'][$key]['value']))
2370
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2371
-					elseif (isset($possible['parameters'][$key]['validate']))
2372
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2373
-					else
2374
-						$params['{' . $key . '}'] = $matches[$i + 1];
2491
+					if (isset($possible['parameters'][$key]['value'])) {
2492
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2493
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2494
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2495
+					} else {
2496
+											$params['{' . $key . '}'] = $matches[$i + 1];
2497
+					}
2375 2498
 
2376 2499
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2377 2500
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2379,23 +2502,26 @@  discard block
 block discarded – undo
2379 2502
 
2380 2503
 				foreach ($possible['parameters'] as $p => $info)
2381 2504
 				{
2382
-					if (!isset($params['{' . $p . '}']))
2383
-						$params['{' . $p . '}'] = '';
2505
+					if (!isset($params['{' . $p . '}'])) {
2506
+											$params['{' . $p . '}'] = '';
2507
+					}
2384 2508
 				}
2385 2509
 
2386 2510
 				$tag = $possible;
2387 2511
 
2388 2512
 				// Put the parameters into the string.
2389
-				if (isset($tag['before']))
2390
-					$tag['before'] = strtr($tag['before'], $params);
2391
-				if (isset($tag['after']))
2392
-					$tag['after'] = strtr($tag['after'], $params);
2393
-				if (isset($tag['content']))
2394
-					$tag['content'] = strtr($tag['content'], $params);
2513
+				if (isset($tag['before'])) {
2514
+									$tag['before'] = strtr($tag['before'], $params);
2515
+				}
2516
+				if (isset($tag['after'])) {
2517
+									$tag['after'] = strtr($tag['after'], $params);
2518
+				}
2519
+				if (isset($tag['content'])) {
2520
+									$tag['content'] = strtr($tag['content'], $params);
2521
+				}
2395 2522
 
2396 2523
 				$pos1 += strlen($given_param_string);
2397
-			}
2398
-			else
2524
+			} else
2399 2525
 			{
2400 2526
 				$tag = $possible;
2401 2527
 				$params = array();
@@ -2406,8 +2532,9 @@  discard block
 block discarded – undo
2406 2532
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2407 2533
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2408 2534
 		{
2409
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2410
-				continue;
2535
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2536
+							continue;
2537
+			}
2411 2538
 
2412 2539
 			$tag = $itemcodes[$message[$pos + 1]];
2413 2540
 
@@ -2428,9 +2555,9 @@  discard block
 block discarded – undo
2428 2555
 			{
2429 2556
 				array_pop($open_tags);
2430 2557
 				$code = '</li>';
2558
+			} else {
2559
+							$code = '';
2431 2560
 			}
2432
-			else
2433
-				$code = '';
2434 2561
 
2435 2562
 			// Now we open a new tag.
2436 2563
 			$open_tags[] = array(
@@ -2477,12 +2604,14 @@  discard block
 block discarded – undo
2477 2604
 		}
2478 2605
 
2479 2606
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2480
-		if ($tag === null)
2481
-			continue;
2607
+		if ($tag === null) {
2608
+					continue;
2609
+		}
2482 2610
 
2483 2611
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2484
-		if (isset($inside['disallow_children']))
2485
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2612
+		if (isset($inside['disallow_children'])) {
2613
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2614
+		}
2486 2615
 
2487 2616
 		// Is this tag disabled?
2488 2617
 		if (isset($disabled[$tag['tag']]))
@@ -2492,14 +2621,13 @@  discard block
 block discarded – undo
2492 2621
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2493 2622
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2494 2623
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2495
-			}
2496
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2624
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2497 2625
 			{
2498 2626
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2499 2627
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2628
+			} else {
2629
+							$tag['content'] = $tag['disabled_content'];
2500 2630
 			}
2501
-			else
2502
-				$tag['content'] = $tag['disabled_content'];
2503 2631
 		}
2504 2632
 
2505 2633
 		// we use this a lot
@@ -2509,8 +2637,9 @@  discard block
 block discarded – undo
2509 2637
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2510 2638
 		{
2511 2639
 			$n = count($open_tags) - 1;
2512
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2513
-				$n--;
2640
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2641
+							$n--;
2642
+			}
2514 2643
 
2515 2644
 			// Close all the non block level tags so this tag isn't surrounded by them.
2516 2645
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2522,12 +2651,15 @@  discard block
 block discarded – undo
2522 2651
 
2523 2652
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2524 2653
 				$whitespace_regex = '';
2525
-				if (!empty($tag['block_level']))
2526
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2527
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2528
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2529
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2530
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2654
+				if (!empty($tag['block_level'])) {
2655
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2656
+				}
2657
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2658
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2659
+				}
2660
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2661
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2662
+				}
2531 2663
 
2532 2664
 				array_pop($open_tags);
2533 2665
 			}
@@ -2548,16 +2680,19 @@  discard block
 block discarded – undo
2548 2680
 		elseif ($tag['type'] == 'unparsed_content')
2549 2681
 		{
2550 2682
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2551
-			if ($pos2 === false)
2552
-				continue;
2683
+			if ($pos2 === false) {
2684
+							continue;
2685
+			}
2553 2686
 
2554 2687
 			$data = substr($message, $pos1, $pos2 - $pos1);
2555 2688
 
2556
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2557
-				$data = substr($data, 4);
2689
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2690
+							$data = substr($data, 4);
2691
+			}
2558 2692
 
2559
-			if (isset($tag['validate']))
2560
-				$tag['validate']($tag, $data, $disabled, $params);
2693
+			if (isset($tag['validate'])) {
2694
+							$tag['validate']($tag, $data, $disabled, $params);
2695
+			}
2561 2696
 
2562 2697
 			$code = strtr($tag['content'], array('$1' => $data));
2563 2698
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2572,34 +2707,40 @@  discard block
 block discarded – undo
2572 2707
 			if (isset($tag['quoted']))
2573 2708
 			{
2574 2709
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2575
-				if ($tag['quoted'] != 'optional' && !$quoted)
2576
-					continue;
2710
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2711
+									continue;
2712
+				}
2577 2713
 
2578
-				if ($quoted)
2579
-					$pos1 += 6;
2714
+				if ($quoted) {
2715
+									$pos1 += 6;
2716
+				}
2717
+			} else {
2718
+							$quoted = false;
2580 2719
 			}
2581
-			else
2582
-				$quoted = false;
2583 2720
 
2584 2721
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2585
-			if ($pos2 === false)
2586
-				continue;
2722
+			if ($pos2 === false) {
2723
+							continue;
2724
+			}
2587 2725
 
2588 2726
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2589
-			if ($pos3 === false)
2590
-				continue;
2727
+			if ($pos3 === false) {
2728
+							continue;
2729
+			}
2591 2730
 
2592 2731
 			$data = array(
2593 2732
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2594 2733
 				substr($message, $pos1, $pos2 - $pos1)
2595 2734
 			);
2596 2735
 
2597
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2598
-				$data[0] = substr($data[0], 4);
2736
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2737
+							$data[0] = substr($data[0], 4);
2738
+			}
2599 2739
 
2600 2740
 			// Validation for my parking, please!
2601
-			if (isset($tag['validate']))
2602
-				$tag['validate']($tag, $data, $disabled, $params);
2741
+			if (isset($tag['validate'])) {
2742
+							$tag['validate']($tag, $data, $disabled, $params);
2743
+			}
2603 2744
 
2604 2745
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2605 2746
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2616,23 +2757,27 @@  discard block
 block discarded – undo
2616 2757
 		elseif ($tag['type'] == 'unparsed_commas_content')
2617 2758
 		{
2618 2759
 			$pos2 = strpos($message, ']', $pos1);
2619
-			if ($pos2 === false)
2620
-				continue;
2760
+			if ($pos2 === false) {
2761
+							continue;
2762
+			}
2621 2763
 
2622 2764
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2623
-			if ($pos3 === false)
2624
-				continue;
2765
+			if ($pos3 === false) {
2766
+							continue;
2767
+			}
2625 2768
 
2626 2769
 			// We want $1 to be the content, and the rest to be csv.
2627 2770
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2628 2771
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2629 2772
 
2630
-			if (isset($tag['validate']))
2631
-				$tag['validate']($tag, $data, $disabled, $params);
2773
+			if (isset($tag['validate'])) {
2774
+							$tag['validate']($tag, $data, $disabled, $params);
2775
+			}
2632 2776
 
2633 2777
 			$code = $tag['content'];
2634
-			foreach ($data as $k => $d)
2635
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2778
+			foreach ($data as $k => $d) {
2779
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2780
+			}
2636 2781
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2637 2782
 			$pos += strlen($code) - 1 + 2;
2638 2783
 		}
@@ -2640,24 +2785,28 @@  discard block
 block discarded – undo
2640 2785
 		elseif ($tag['type'] == 'unparsed_commas')
2641 2786
 		{
2642 2787
 			$pos2 = strpos($message, ']', $pos1);
2643
-			if ($pos2 === false)
2644
-				continue;
2788
+			if ($pos2 === false) {
2789
+							continue;
2790
+			}
2645 2791
 
2646 2792
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2647 2793
 
2648
-			if (isset($tag['validate']))
2649
-				$tag['validate']($tag, $data, $disabled, $params);
2794
+			if (isset($tag['validate'])) {
2795
+							$tag['validate']($tag, $data, $disabled, $params);
2796
+			}
2650 2797
 
2651 2798
 			// Fix after, for disabled code mainly.
2652
-			foreach ($data as $k => $d)
2653
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2799
+			foreach ($data as $k => $d) {
2800
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2801
+			}
2654 2802
 
2655 2803
 			$open_tags[] = $tag;
2656 2804
 
2657 2805
 			// Replace them out, $1, $2, $3, $4, etc.
2658 2806
 			$code = $tag['before'];
2659
-			foreach ($data as $k => $d)
2660
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2807
+			foreach ($data as $k => $d) {
2808
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2809
+			}
2661 2810
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2662 2811
 			$pos += strlen($code) - 1 + 2;
2663 2812
 		}
@@ -2668,28 +2817,33 @@  discard block
 block discarded – undo
2668 2817
 			if (isset($tag['quoted']))
2669 2818
 			{
2670 2819
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2671
-				if ($tag['quoted'] != 'optional' && !$quoted)
2672
-					continue;
2820
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2821
+									continue;
2822
+				}
2673 2823
 
2674
-				if ($quoted)
2675
-					$pos1 += 6;
2824
+				if ($quoted) {
2825
+									$pos1 += 6;
2826
+				}
2827
+			} else {
2828
+							$quoted = false;
2676 2829
 			}
2677
-			else
2678
-				$quoted = false;
2679 2830
 
2680 2831
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2681
-			if ($pos2 === false)
2682
-				continue;
2832
+			if ($pos2 === false) {
2833
+							continue;
2834
+			}
2683 2835
 
2684 2836
 			$data = substr($message, $pos1, $pos2 - $pos1);
2685 2837
 
2686 2838
 			// Validation for my parking, please!
2687
-			if (isset($tag['validate']))
2688
-				$tag['validate']($tag, $data, $disabled, $params);
2839
+			if (isset($tag['validate'])) {
2840
+							$tag['validate']($tag, $data, $disabled, $params);
2841
+			}
2689 2842
 
2690 2843
 			// For parsed content, we must recurse to avoid security problems.
2691
-			if ($tag['type'] != 'unparsed_equals')
2692
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2844
+			if ($tag['type'] != 'unparsed_equals') {
2845
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2846
+			}
2693 2847
 
2694 2848
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2695 2849
 
@@ -2701,34 +2855,40 @@  discard block
 block discarded – undo
2701 2855
 		}
2702 2856
 
2703 2857
 		// If this is block level, eat any breaks after it.
2704
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2705
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2858
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2859
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2860
+		}
2706 2861
 
2707 2862
 		// Are we trimming outside this tag?
2708
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2709
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2863
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2864
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2865
+		}
2710 2866
 	}
2711 2867
 
2712 2868
 	// Close any remaining tags.
2713
-	while ($tag = array_pop($open_tags))
2714
-		$message .= "\n" . $tag['after'] . "\n";
2869
+	while ($tag = array_pop($open_tags)) {
2870
+			$message .= "\n" . $tag['after'] . "\n";
2871
+	}
2715 2872
 
2716 2873
 	// Parse the smileys within the parts where it can be done safely.
2717 2874
 	if ($smileys === true)
2718 2875
 	{
2719 2876
 		$message_parts = explode("\n", $message);
2720
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2721
-			parsesmileys($message_parts[$i]);
2877
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2878
+					parsesmileys($message_parts[$i]);
2879
+		}
2722 2880
 
2723 2881
 		$message = implode('', $message_parts);
2724 2882
 	}
2725 2883
 
2726 2884
 	// No smileys, just get rid of the markers.
2727
-	else
2728
-		$message = strtr($message, array("\n" => ''));
2885
+	else {
2886
+			$message = strtr($message, array("\n" => ''));
2887
+	}
2729 2888
 
2730
-	if ($message !== '' && $message[0] === ' ')
2731
-		$message = '&nbsp;' . substr($message, 1);
2889
+	if ($message !== '' && $message[0] === ' ') {
2890
+			$message = '&nbsp;' . substr($message, 1);
2891
+	}
2732 2892
 
2733 2893
 	// Cleanup whitespace.
2734 2894
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2737,15 +2897,16 @@  discard block
 block discarded – undo
2737 2897
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2738 2898
 
2739 2899
 	// Cache the output if it took some time...
2740
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2741
-		cache_put_data($cache_key, $message, 240);
2900
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2901
+			cache_put_data($cache_key, $message, 240);
2902
+	}
2742 2903
 
2743 2904
 	// If this was a force parse revert if needed.
2744 2905
 	if (!empty($parse_tags))
2745 2906
 	{
2746
-		if (empty($temp_bbc))
2747
-			$bbc_codes = array();
2748
-		else
2907
+		if (empty($temp_bbc)) {
2908
+					$bbc_codes = array();
2909
+		} else
2749 2910
 		{
2750 2911
 			$bbc_codes = $temp_bbc;
2751 2912
 			unset($temp_bbc);
@@ -2772,8 +2933,9 @@  discard block
 block discarded – undo
2772 2933
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2773 2934
 
2774 2935
 	// No smiley set at all?!
2775
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2776
-		return;
2936
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2937
+			return;
2938
+	}
2777 2939
 
2778 2940
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2779 2941
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2787,8 +2949,7 @@  discard block
 block discarded – undo
2787 2949
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2788 2950
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2789 2951
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2790
-		}
2791
-		else
2952
+		} else
2792 2953
 		{
2793 2954
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2794 2955
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2812,9 +2973,9 @@  discard block
 block discarded – undo
2812 2973
 				$smcFunc['db_free_result']($result);
2813 2974
 
2814 2975
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2976
+			} else {
2977
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2815 2978
 			}
2816
-			else
2817
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2818 2979
 		}
2819 2980
 
2820 2981
 		// The non-breaking-space is a complex thing...
@@ -2836,16 +2997,18 @@  discard block
 block discarded – undo
2836 2997
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2837 2998
 				if (!empty($alt_images))
2838 2999
 				{
2839
-					foreach ($exts as $ext)
2840
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3000
+					foreach ($exts as $ext) {
3001
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2841 3002
 						{
2842 3003
 							$smileysto[$i] = $fname . '.' . $ext;
3004
+					}
2843 3005
 							break;
2844 3006
 						}
2845 3007
 				}
2846 3008
 				// If we have no image, just leave the text version in place
2847
-				else
2848
-					continue;
3009
+				else {
3010
+									continue;
3011
+				}
2849 3012
 			}
2850 3013
 
2851 3014
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -2913,12 +3076,14 @@  discard block
 block discarded – undo
2913 3076
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
2914 3077
 
2915 3078
 	// Only use the proxy if enabled and necessary
2916
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
2917
-		return $url;
3079
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3080
+			return $url;
3081
+	}
2918 3082
 
2919 3083
 	// We don't need to proxy our own resources
2920
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
2921
-		return strtr($url, array('http://' => 'https://'));
3084
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3085
+			return strtr($url, array('http://' => 'https://'));
3086
+	}
2922 3087
 
2923 3088
 	// By default, use SMF's own image proxy script
2924 3089
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -2943,35 +3108,41 @@  discard block
 block discarded – undo
2943 3108
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2944 3109
 
2945 3110
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2946
-	if (!empty($context['flush_mail']))
2947
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3111
+	if (!empty($context['flush_mail'])) {
3112
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2948 3113
 		AddMailQueue(true);
3114
+	}
2949 3115
 
2950 3116
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2951 3117
 
2952
-	if ($add)
2953
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3118
+	if ($add) {
3119
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3120
+	}
2954 3121
 
2955 3122
 	// Put the session ID in.
2956
-	if (defined('SID') && SID != '')
2957
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3123
+	if (defined('SID') && SID != '') {
3124
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3125
+	}
2958 3126
 	// Keep that debug in their for template debugging!
2959
-	elseif (isset($_GET['debug']))
2960
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3127
+	elseif (isset($_GET['debug'])) {
3128
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3129
+	}
2961 3130
 
2962 3131
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2963 3132
 	{
2964
-		if (defined('SID') && SID != '')
2965
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3133
+		if (defined('SID') && SID != '') {
3134
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2966 3135
 				function ($m) use ($scripturl)
2967 3136
 				{
2968 3137
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3138
+		}
2969 3139
 				}, $setLocation);
2970
-		else
2971
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3140
+		else {
3141
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2972 3142
 				function ($m) use ($scripturl)
2973 3143
 				{
2974 3144
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3145
+		}
2975 3146
 				}, $setLocation);
2976 3147
 	}
2977 3148
 
@@ -2982,8 +3153,9 @@  discard block
 block discarded – undo
2982 3153
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2983 3154
 
2984 3155
 	// Debugging.
2985
-	if (isset($db_show_debug) && $db_show_debug === true)
2986
-		$_SESSION['debug_redirect'] = $db_cache;
3156
+	if (isset($db_show_debug) && $db_show_debug === true) {
3157
+			$_SESSION['debug_redirect'] = $db_cache;
3158
+	}
2987 3159
 
2988 3160
 	obExit(false);
2989 3161
 }
@@ -3002,51 +3174,60 @@  discard block
 block discarded – undo
3002 3174
 
3003 3175
 	// Attempt to prevent a recursive loop.
3004 3176
 	++$level;
3005
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3006
-		exit;
3007
-	if ($from_fatal_error)
3008
-		$has_fatal_error = true;
3177
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3178
+			exit;
3179
+	}
3180
+	if ($from_fatal_error) {
3181
+			$has_fatal_error = true;
3182
+	}
3009 3183
 
3010 3184
 	// Clear out the stat cache.
3011 3185
 	trackStats();
3012 3186
 
3013 3187
 	// If we have mail to send, send it.
3014
-	if (!empty($context['flush_mail']))
3015
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3188
+	if (!empty($context['flush_mail'])) {
3189
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3016 3190
 		AddMailQueue(true);
3191
+	}
3017 3192
 
3018 3193
 	$do_header = $header === null ? !$header_done : $header;
3019
-	if ($do_footer === null)
3020
-		$do_footer = $do_header;
3194
+	if ($do_footer === null) {
3195
+			$do_footer = $do_header;
3196
+	}
3021 3197
 
3022 3198
 	// Has the template/header been done yet?
3023 3199
 	if ($do_header)
3024 3200
 	{
3025 3201
 		// Was the page title set last minute? Also update the HTML safe one.
3026
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3027
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3202
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3203
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3204
+		}
3028 3205
 
3029 3206
 		// Start up the session URL fixer.
3030 3207
 		ob_start('ob_sessrewrite');
3031 3208
 
3032
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3033
-			$buffers = explode(',', $settings['output_buffers']);
3034
-		elseif (!empty($settings['output_buffers']))
3035
-			$buffers = $settings['output_buffers'];
3036
-		else
3037
-			$buffers = array();
3209
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3210
+					$buffers = explode(',', $settings['output_buffers']);
3211
+		} elseif (!empty($settings['output_buffers'])) {
3212
+					$buffers = $settings['output_buffers'];
3213
+		} else {
3214
+					$buffers = array();
3215
+		}
3038 3216
 
3039
-		if (isset($modSettings['integrate_buffer']))
3040
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3217
+		if (isset($modSettings['integrate_buffer'])) {
3218
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3219
+		}
3041 3220
 
3042
-		if (!empty($buffers))
3043
-			foreach ($buffers as $function)
3221
+		if (!empty($buffers)) {
3222
+					foreach ($buffers as $function)
3044 3223
 			{
3045 3224
 				$call = call_helper($function, true);
3225
+		}
3046 3226
 
3047 3227
 				// Is it valid?
3048
-				if (!empty($call))
3049
-					ob_start($call);
3228
+				if (!empty($call)) {
3229
+									ob_start($call);
3230
+				}
3050 3231
 			}
3051 3232
 
3052 3233
 		// Display the screen in the logical order.
@@ -3058,8 +3239,9 @@  discard block
 block discarded – undo
3058 3239
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3059 3240
 
3060 3241
 		// Anything special to put out?
3061
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3062
-			echo $context['insert_after_template'];
3242
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3243
+					echo $context['insert_after_template'];
3244
+		}
3063 3245
 
3064 3246
 		// Just so we don't get caught in an endless loop of errors from the footer...
3065 3247
 		if (!$footer_done)
@@ -3068,14 +3250,16 @@  discard block
 block discarded – undo
3068 3250
 			template_footer();
3069 3251
 
3070 3252
 			// (since this is just debugging... it's okay that it's after </html>.)
3071
-			if (!isset($_REQUEST['xml']))
3072
-				displayDebug();
3253
+			if (!isset($_REQUEST['xml'])) {
3254
+							displayDebug();
3255
+			}
3073 3256
 		}
3074 3257
 	}
3075 3258
 
3076 3259
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3077
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3078
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3260
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3261
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3262
+	}
3079 3263
 
3080 3264
 	// For session check verification.... don't switch browsers...
3081 3265
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3084,9 +3268,10 @@  discard block
 block discarded – undo
3084 3268
 	call_integration_hook('integrate_exit', array($do_footer));
3085 3269
 
3086 3270
 	// Don't exit if we're coming from index.php; that will pass through normally.
3087
-	if (!$from_index)
3088
-		exit;
3089
-}
3271
+	if (!$from_index) {
3272
+			exit;
3273
+	}
3274
+	}
3090 3275
 
3091 3276
 /**
3092 3277
  * Get the size of a specified image with better error handling.
@@ -3105,8 +3290,9 @@  discard block
 block discarded – undo
3105 3290
 	$url = str_replace(' ', '%20', $url);
3106 3291
 
3107 3292
 	// Can we pull this from the cache... please please?
3108
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3109
-		return $temp;
3293
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3294
+			return $temp;
3295
+	}
3110 3296
 	$t = microtime();
3111 3297
 
3112 3298
 	// Get the host to pester...
@@ -3116,12 +3302,10 @@  discard block
 block discarded – undo
3116 3302
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3117 3303
 	{
3118 3304
 		return false;
3119
-	}
3120
-	elseif (!isset($match[1]))
3305
+	} elseif (!isset($match[1]))
3121 3306
 	{
3122 3307
 		$size = @getimagesize($url);
3123
-	}
3124
-	else
3308
+	} else
3125 3309
 	{
3126 3310
 		// Try to connect to the server... give it half a second.
3127 3311
 		$temp = 0;
@@ -3158,12 +3342,14 @@  discard block
 block discarded – undo
3158 3342
 	}
3159 3343
 
3160 3344
 	// If we didn't get it, we failed.
3161
-	if (!isset($size))
3162
-		$size = false;
3345
+	if (!isset($size)) {
3346
+			$size = false;
3347
+	}
3163 3348
 
3164 3349
 	// If this took a long time, we may never have to do it again, but then again we might...
3165
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3166
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3350
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3351
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3352
+	}
3167 3353
 
3168 3354
 	// Didn't work.
3169 3355
 	return $size;
@@ -3181,8 +3367,9 @@  discard block
 block discarded – undo
3181 3367
 
3182 3368
 	// Under SSI this function can be called more then once.  That can cause some problems.
3183 3369
 	//   So only run the function once unless we are forced to run it again.
3184
-	if ($loaded && !$forceload)
3185
-		return;
3370
+	if ($loaded && !$forceload) {
3371
+			return;
3372
+	}
3186 3373
 
3187 3374
 	$loaded = true;
3188 3375
 
@@ -3194,14 +3381,16 @@  discard block
 block discarded – undo
3194 3381
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3195 3382
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3196 3383
 	{
3197
-		if (trim($context['news_lines'][$i]) == '')
3198
-			continue;
3384
+		if (trim($context['news_lines'][$i]) == '') {
3385
+					continue;
3386
+		}
3199 3387
 
3200 3388
 		// Clean it up for presentation ;).
3201 3389
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3202 3390
 	}
3203
-	if (!empty($context['news_lines']))
3204
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3391
+	if (!empty($context['news_lines'])) {
3392
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3393
+	}
3205 3394
 
3206 3395
 	if (!$user_info['is_guest'])
3207 3396
 	{
@@ -3210,40 +3399,48 @@  discard block
 block discarded – undo
3210 3399
 		$context['user']['alerts'] = &$user_info['alerts'];
3211 3400
 
3212 3401
 		// Personal message popup...
3213
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3214
-			$context['user']['popup_messages'] = true;
3215
-		else
3216
-			$context['user']['popup_messages'] = false;
3402
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3403
+					$context['user']['popup_messages'] = true;
3404
+		} else {
3405
+					$context['user']['popup_messages'] = false;
3406
+		}
3217 3407
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3218 3408
 
3219
-		if (allowedTo('moderate_forum'))
3220
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3409
+		if (allowedTo('moderate_forum')) {
3410
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3411
+		}
3221 3412
 
3222 3413
 		$context['user']['avatar'] = array();
3223 3414
 
3224 3415
 		// Check for gravatar first since we might be forcing them...
3225 3416
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3226 3417
 		{
3227
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3228
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3229
-			else
3230
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3418
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3419
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3420
+			} else {
3421
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3422
+			}
3231 3423
 		}
3232 3424
 		// Uploaded?
3233
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3234
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3425
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3426
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3427
+		}
3235 3428
 		// Full URL?
3236
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3237
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3429
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3430
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3431
+		}
3238 3432
 		// Otherwise we assume it's server stored.
3239
-		elseif ($user_info['avatar']['url'] != '')
3240
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3433
+		elseif ($user_info['avatar']['url'] != '') {
3434
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3435
+		}
3241 3436
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3242
-		else
3243
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3437
+		else {
3438
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3439
+		}
3244 3440
 
3245
-		if (!empty($context['user']['avatar']))
3246
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3441
+		if (!empty($context['user']['avatar'])) {
3442
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3443
+		}
3247 3444
 
3248 3445
 		// Figure out how long they've been logged in.
3249 3446
 		$context['user']['total_time_logged_in'] = array(
@@ -3251,8 +3448,7 @@  discard block
 block discarded – undo
3251 3448
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3252 3449
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3253 3450
 		);
3254
-	}
3255
-	else
3451
+	} else
3256 3452
 	{
3257 3453
 		$context['user']['messages'] = 0;
3258 3454
 		$context['user']['unread_messages'] = 0;
@@ -3260,12 +3456,14 @@  discard block
 block discarded – undo
3260 3456
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3261 3457
 		$context['user']['popup_messages'] = false;
3262 3458
 
3263
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3264
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3459
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3460
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3461
+		}
3265 3462
 
3266 3463
 		// If we've upgraded recently, go easy on the passwords.
3267
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3268
-			$context['disable_login_hashing'] = true;
3464
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3465
+					$context['disable_login_hashing'] = true;
3466
+		}
3269 3467
 	}
3270 3468
 
3271 3469
 	// Setup the main menu items.
@@ -3278,8 +3476,8 @@  discard block
 block discarded – undo
3278 3476
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3279 3477
 
3280 3478
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3281
-	if ($context['show_pm_popup'])
3282
-		addInlineJavaScript('
3479
+	if ($context['show_pm_popup']) {
3480
+			addInlineJavaScript('
3283 3481
 		jQuery(document).ready(function($) {
3284 3482
 			new smc_Popup({
3285 3483
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3287,24 +3485,28 @@  discard block
 block discarded – undo
3287 3485
 				icon_class: \'generic_icons mail_new\'
3288 3486
 			});
3289 3487
 		});');
3488
+	}
3290 3489
 
3291 3490
 	// Add a generic "Are you sure?" confirmation message.
3292 3491
 	addInlineJavaScript('
3293 3492
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3294 3493
 
3295 3494
 	// Now add the capping code for avatars.
3296
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3297
-		addInlineCss('
3495
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3496
+			addInlineCss('
3298 3497
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3498
+	}
3299 3499
 
3300 3500
 	// Add max image limits
3301
-	if (!empty($modSettings['max_image_width']))
3302
-		addInlineCss('
3501
+	if (!empty($modSettings['max_image_width'])) {
3502
+			addInlineCss('
3303 3503
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3504
+	}
3304 3505
 
3305
-	if (!empty($modSettings['max_image_height']))
3306
-		addInlineCss('
3506
+	if (!empty($modSettings['max_image_height'])) {
3507
+			addInlineCss('
3307 3508
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3509
+	}
3308 3510
 
3309 3511
 	// This looks weird, but it's because BoardIndex.php references the variable.
3310 3512
 	$context['common_stats']['latest_member'] = array(
@@ -3321,11 +3523,13 @@  discard block
 block discarded – undo
3321 3523
 	);
3322 3524
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3323 3525
 
3324
-	if (empty($settings['theme_version']))
3325
-		addJavaScriptVar('smf_scripturl', $scripturl);
3526
+	if (empty($settings['theme_version'])) {
3527
+			addJavaScriptVar('smf_scripturl', $scripturl);
3528
+	}
3326 3529
 
3327
-	if (!isset($context['page_title']))
3328
-		$context['page_title'] = '';
3530
+	if (!isset($context['page_title'])) {
3531
+			$context['page_title'] = '';
3532
+	}
3329 3533
 
3330 3534
 	// Set some specific vars.
3331 3535
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3335,21 +3539,23 @@  discard block
 block discarded – undo
3335 3539
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3336 3540
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3337 3541
 
3338
-	if (!empty($context['meta_keywords']))
3339
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3542
+	if (!empty($context['meta_keywords'])) {
3543
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3544
+	}
3340 3545
 
3341
-	if (!empty($context['canonical_url']))
3342
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3546
+	if (!empty($context['canonical_url'])) {
3547
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3548
+	}
3343 3549
 
3344
-	if (!empty($settings['og_image']))
3345
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3550
+	if (!empty($settings['og_image'])) {
3551
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3552
+	}
3346 3553
 
3347 3554
 	if (!empty($context['meta_description']))
3348 3555
 	{
3349 3556
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3350 3557
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3351
-	}
3352
-	else
3558
+	} else
3353 3559
 	{
3354 3560
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3355 3561
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3374,8 +3580,9 @@  discard block
 block discarded – undo
3374 3580
 	$memory_needed = memoryReturnBytes($needed);
3375 3581
 
3376 3582
 	// should we account for how much is currently being used?
3377
-	if ($in_use)
3378
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3583
+	if ($in_use) {
3584
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3585
+	}
3379 3586
 
3380 3587
 	// if more is needed, request it
3381 3588
 	if ($memory_current < $memory_needed)
@@ -3398,8 +3605,9 @@  discard block
 block discarded – undo
3398 3605
  */
3399 3606
 function memoryReturnBytes($val)
3400 3607
 {
3401
-	if (is_integer($val))
3402
-		return $val;
3608
+	if (is_integer($val)) {
3609
+			return $val;
3610
+	}
3403 3611
 
3404 3612
 	// Separate the number from the designator
3405 3613
 	$val = trim($val);
@@ -3435,10 +3643,11 @@  discard block
 block discarded – undo
3435 3643
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3436 3644
 
3437 3645
 		// Are we debugging the template/html content?
3438
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3439
-			header('content-type: application/xhtml+xml');
3440
-		elseif (!isset($_REQUEST['xml']))
3441
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3646
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3647
+					header('content-type: application/xhtml+xml');
3648
+		} elseif (!isset($_REQUEST['xml'])) {
3649
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3650
+		}
3442 3651
 	}
3443 3652
 
3444 3653
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3447,8 +3656,9 @@  discard block
 block discarded – undo
3447 3656
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3448 3657
 	{
3449 3658
 		$position = array_search('body', $context['template_layers']);
3450
-		if ($position === false)
3451
-			$position = array_search('main', $context['template_layers']);
3659
+		if ($position === false) {
3660
+					$position = array_search('main', $context['template_layers']);
3661
+		}
3452 3662
 
3453 3663
 		if ($position !== false)
3454 3664
 		{
@@ -3476,23 +3686,25 @@  discard block
 block discarded – undo
3476 3686
 
3477 3687
 			foreach ($securityFiles as $i => $securityFile)
3478 3688
 			{
3479
-				if (!file_exists($boarddir . '/' . $securityFile))
3480
-					unset($securityFiles[$i]);
3689
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3690
+									unset($securityFiles[$i]);
3691
+				}
3481 3692
 			}
3482 3693
 
3483 3694
 			// We are already checking so many files...just few more doesn't make any difference! :P
3484
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3485
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3486
-
3487
-			else
3488
-				$path = $modSettings['attachmentUploadDir'];
3695
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3696
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3697
+			} else {
3698
+							$path = $modSettings['attachmentUploadDir'];
3699
+			}
3489 3700
 
3490 3701
 			secureDirectory($path, true);
3491 3702
 			secureDirectory($cachedir);
3492 3703
 
3493 3704
 			// If agreement is enabled, at least the english version shall exists
3494
-			if ($modSettings['requireAgreement'])
3495
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3705
+			if ($modSettings['requireAgreement']) {
3706
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3707
+			}
3496 3708
 
3497 3709
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3498 3710
 			{
@@ -3507,18 +3719,21 @@  discard block
 block discarded – undo
3507 3719
 					echo '
3508 3720
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3509 3721
 
3510
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3511
-						echo '
3722
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3723
+											echo '
3512 3724
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3725
+					}
3513 3726
 				}
3514 3727
 
3515
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3516
-					echo '
3728
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3729
+									echo '
3517 3730
 				<strong>', $txt['cache_writable'], '</strong><br>';
3731
+				}
3518 3732
 
3519
-				if (!empty($agreement))
3520
-					echo '
3733
+				if (!empty($agreement)) {
3734
+									echo '
3521 3735
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3736
+				}
3522 3737
 
3523 3738
 				echo '
3524 3739
 			</p>
@@ -3533,16 +3748,18 @@  discard block
 block discarded – undo
3533 3748
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3534 3749
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3535 3750
 
3536
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3537
-				echo '
3751
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3752
+							echo '
3538 3753
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3754
+			}
3539 3755
 
3540
-			if (!empty($_SESSION['ban']['expire_time']))
3541
-				echo '
3756
+			if (!empty($_SESSION['ban']['expire_time'])) {
3757
+							echo '
3542 3758
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3543
-			else
3544
-				echo '
3759
+			} else {
3760
+							echo '
3545 3761
 					<div>', $txt['your_ban_expires_never'], '</div>';
3762
+			}
3546 3763
 
3547 3764
 			echo '
3548 3765
 				</div>';
@@ -3558,8 +3775,9 @@  discard block
 block discarded – undo
3558 3775
 	global $forum_copyright, $software_year, $forum_version;
3559 3776
 
3560 3777
 	// Don't display copyright for things like SSI.
3561
-	if (!isset($forum_version) || !isset($software_year))
3562
-		return;
3778
+	if (!isset($forum_version) || !isset($software_year)) {
3779
+			return;
3780
+	}
3563 3781
 
3564 3782
 	// Put in the version...
3565 3783
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3577,9 +3795,10 @@  discard block
 block discarded – undo
3577 3795
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3578 3796
 	$context['load_queries'] = $db_count;
3579 3797
 
3580
-	foreach (array_reverse($context['template_layers']) as $layer)
3581
-		loadSubTemplate($layer . '_below', true);
3582
-}
3798
+	foreach (array_reverse($context['template_layers']) as $layer) {
3799
+			loadSubTemplate($layer . '_below', true);
3800
+	}
3801
+	}
3583 3802
 
3584 3803
 /**
3585 3804
  * Output the Javascript files
@@ -3613,8 +3832,7 @@  discard block
 block discarded – undo
3613 3832
 			{
3614 3833
 				echo '
3615 3834
 		var ', $key, ';';
3616
-			}
3617
-			else
3835
+			} else
3618 3836
 			{
3619 3837
 				echo '
3620 3838
 		var ', $key, ' = ', $value, ';';
@@ -3633,27 +3851,29 @@  discard block
 block discarded – undo
3633 3851
 		foreach ($context['javascript_files'] as $id => $js_file)
3634 3852
 		{
3635 3853
 			// Last minute call! allow theme authors to disable single files.
3636
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3637
-				continue;
3854
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3855
+							continue;
3856
+			}
3638 3857
 
3639 3858
 			// By default files don't get minimized unless the file explicitly says so!
3640 3859
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3641 3860
 			{
3642
-				if (!empty($js_file['options']['async']))
3643
-					$toMinify['async'][] = $js_file;
3644
-				elseif (!empty($js_file['options']['defer']))
3645
-					$toMinify['defer'][] = $js_file;
3646
-				else
3647
-					$toMinify['standard'][] = $js_file;
3861
+				if (!empty($js_file['options']['async'])) {
3862
+									$toMinify['async'][] = $js_file;
3863
+				} elseif (!empty($js_file['options']['defer'])) {
3864
+									$toMinify['defer'][] = $js_file;
3865
+				} else {
3866
+									$toMinify['standard'][] = $js_file;
3867
+				}
3648 3868
 
3649 3869
 				// Grab a random seed.
3650
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3651
-					$minSeed = $js_file['options']['seed'];
3652
-			}
3653
-
3654
-			else
3655
-				echo '
3870
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3871
+									$minSeed = $js_file['options']['seed'];
3872
+				}
3873
+			} else {
3874
+							echo '
3656 3875
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3876
+			}
3657 3877
 		}
3658 3878
 
3659 3879
 		foreach ($toMinify as $js_files)
@@ -3664,9 +3884,10 @@  discard block
 block discarded – undo
3664 3884
 
3665 3885
 				$minSuccessful = array_keys($result) === array('smf_minified');
3666 3886
 
3667
-				foreach ($result as $minFile)
3668
-					echo '
3887
+				foreach ($result as $minFile) {
3888
+									echo '
3669 3889
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
3890
+				}
3670 3891
 			}
3671 3892
 		}
3672 3893
 	}
@@ -3680,8 +3901,9 @@  discard block
 block discarded – undo
3680 3901
 <script>
3681 3902
 window.addEventListener("DOMContentLoaded", function() {';
3682 3903
 
3683
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3684
-				echo $js_code;
3904
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3905
+							echo $js_code;
3906
+			}
3685 3907
 
3686 3908
 			echo '
3687 3909
 });
@@ -3693,8 +3915,9 @@  discard block
 block discarded – undo
3693 3915
 			echo '
3694 3916
 	<script>';
3695 3917
 
3696
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3697
-				echo $js_code;
3918
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3919
+							echo $js_code;
3920
+			}
3698 3921
 
3699 3922
 			echo '
3700 3923
 	</script>';
@@ -3722,23 +3945,26 @@  discard block
 block discarded – undo
3722 3945
 	foreach ($context['css_files'] as $id => $file)
3723 3946
 	{
3724 3947
 		// Last minute call! allow theme authors to disable single files.
3725
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3726
-			continue;
3948
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3949
+					continue;
3950
+		}
3727 3951
 
3728 3952
 		// Files are minimized unless they explicitly opt out.
3729
-		if (!isset($file['options']['minimize']))
3730
-			$file['options']['minimize'] = true;
3953
+		if (!isset($file['options']['minimize'])) {
3954
+					$file['options']['minimize'] = true;
3955
+		}
3731 3956
 
3732 3957
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3733 3958
 		{
3734 3959
 			$toMinify[] = $file;
3735 3960
 
3736 3961
 			// Grab a random seed.
3737
-			if (!isset($minSeed) && isset($file['options']['seed']))
3738
-				$minSeed = $file['options']['seed'];
3962
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3963
+							$minSeed = $file['options']['seed'];
3964
+			}
3965
+		} else {
3966
+					$normal[] = $file['fileUrl'];
3739 3967
 		}
3740
-		else
3741
-			$normal[] = $file['fileUrl'];
3742 3968
 	}
3743 3969
 
3744 3970
 	if (!empty($toMinify))
@@ -3747,23 +3973,26 @@  discard block
 block discarded – undo
3747 3973
 
3748 3974
 		$minSuccessful = array_keys($result) === array('smf_minified');
3749 3975
 
3750
-		foreach ($result as $minFile)
3751
-			echo '
3976
+		foreach ($result as $minFile) {
3977
+					echo '
3752 3978
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3979
+		}
3753 3980
 	}
3754 3981
 
3755 3982
 	// Print the rest after the minified files.
3756
-	if (!empty($normal))
3757
-		foreach ($normal as $nf)
3983
+	if (!empty($normal)) {
3984
+			foreach ($normal as $nf)
3758 3985
 			echo '
3759 3986
 	<link rel="stylesheet" href="', $nf ,'">';
3987
+	}
3760 3988
 
3761 3989
 	if ($db_show_debug === true)
3762 3990
 	{
3763 3991
 		// Try to keep only what's useful.
3764 3992
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3765
-		foreach ($context['css_files'] as $file)
3766
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3993
+		foreach ($context['css_files'] as $file) {
3994
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3995
+		}
3767 3996
 	}
3768 3997
 
3769 3998
 	if (!empty($context['css_header']))
@@ -3771,9 +4000,10 @@  discard block
 block discarded – undo
3771 4000
 		echo '
3772 4001
 	<style>';
3773 4002
 
3774
-		foreach ($context['css_header'] as $css)
3775
-			echo $css .'
4003
+		foreach ($context['css_header'] as $css) {
4004
+					echo $css .'
3776 4005
 	';
4006
+		}
3777 4007
 
3778 4008
 		echo'
3779 4009
 	</style>';
@@ -3796,8 +4026,9 @@  discard block
 block discarded – undo
3796 4026
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3797 4027
 	$data = is_array($data) ? $data : array();
3798 4028
 
3799
-	if (empty($type) || empty($data))
3800
-		return $data;
4029
+	if (empty($type) || empty($data)) {
4030
+			return $data;
4031
+	}
3801 4032
 
3802 4033
 	// Different pages include different files, so we use a hash to label the different combinations
3803 4034
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3806,13 +4037,14 @@  discard block
 block discarded – undo
3806 4037
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3807 4038
 
3808 4039
 	// Already done?
3809
-	if (!empty($toCache))
3810
-		return array('smf_minified' => array(
4040
+	if (!empty($toCache)) {
4041
+			return array('smf_minified' => array(
3811 4042
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3812 4043
 			'filePath' => $toCache,
3813 4044
 			'fileName' => basename($toCache),
3814 4045
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3815 4046
 		));
4047
+	}
3816 4048
 
3817 4049
 
3818 4050
 	// No namespaces, sorry!
@@ -3842,9 +4074,9 @@  discard block
 block discarded – undo
3842 4074
 
3843 4075
 	foreach ($data as $id => $file)
3844 4076
 	{
3845
-		if (empty($file['filePath']))
3846
-			$toAdd = false;
3847
-		else
4077
+		if (empty($file['filePath'])) {
4078
+					$toAdd = false;
4079
+		} else
3848 4080
 		{
3849 4081
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3850 4082
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3852,12 +4084,14 @@  discard block
 block discarded – undo
3852 4084
 		}
3853 4085
 
3854 4086
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3855
-		if (empty($file['options']['async']))
3856
-			$async = false;
4087
+		if (empty($file['options']['async'])) {
4088
+					$async = false;
4089
+		}
3857 4090
 
3858 4091
 		// A minified script should only be deferred if all its components wanted to be.
3859
-		if (empty($file['options']['defer']))
3860
-			$defer = false;
4092
+		if (empty($file['options']['defer'])) {
4093
+					$defer = false;
4094
+		}
3861 4095
 
3862 4096
 		// The file couldn't be located so it won't be added. Log this error.
3863 4097
 		if (empty($toAdd))
@@ -3923,12 +4157,14 @@  discard block
 block discarded – undo
3923 4157
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
3924 4158
 			{
3925 4159
 				// Remove the cache entry
3926
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
3927
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4160
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4161
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4162
+				}
3928 4163
 
3929 4164
 				// Try to delete the file. Add it to our error list if it fails.
3930
-				if (!@unlink($filename))
3931
-					$not_deleted[] = $filename;
4165
+				if (!@unlink($filename)) {
4166
+									$not_deleted[] = $filename;
4167
+				}
3932 4168
 			}
3933 4169
 		}
3934 4170
 	}
@@ -3960,8 +4196,9 @@  discard block
 block discarded – undo
3960 4196
 	global $modSettings, $smcFunc;
3961 4197
 
3962 4198
 	// Just make up a nice hash...
3963
-	if ($new)
3964
-		return sha1(md5($filename . time()) . mt_rand());
4199
+	if ($new) {
4200
+			return sha1(md5($filename . time()) . mt_rand());
4201
+	}
3965 4202
 
3966 4203
 	// Just make sure that attachment id is only a int
3967 4204
 	$attachment_id = (int) $attachment_id;
@@ -3978,23 +4215,25 @@  discard block
 block discarded – undo
3978 4215
 				'id_attach' => $attachment_id,
3979 4216
 			));
3980 4217
 
3981
-		if ($smcFunc['db_num_rows']($request) === 0)
3982
-			return false;
4218
+		if ($smcFunc['db_num_rows']($request) === 0) {
4219
+					return false;
4220
+		}
3983 4221
 
3984 4222
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3985 4223
 		$smcFunc['db_free_result']($request);
3986 4224
 	}
3987 4225
 
3988 4226
 	// Still no hash? mmm...
3989
-	if (empty($file_hash))
3990
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4227
+	if (empty($file_hash)) {
4228
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4229
+	}
3991 4230
 
3992 4231
 	// Are we using multiple directories?
3993
-	if (is_array($modSettings['attachmentUploadDir']))
3994
-		$path = $modSettings['attachmentUploadDir'][$dir];
3995
-
3996
-	else
3997
-		$path = $modSettings['attachmentUploadDir'];
4232
+	if (is_array($modSettings['attachmentUploadDir'])) {
4233
+			$path = $modSettings['attachmentUploadDir'][$dir];
4234
+	} else {
4235
+			$path = $modSettings['attachmentUploadDir'];
4236
+	}
3998 4237
 
3999 4238
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4000 4239
 }
@@ -4009,8 +4248,9 @@  discard block
 block discarded – undo
4009 4248
 function ip2range($fullip)
4010 4249
 {
4011 4250
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4012
-	if ($fullip == 'unknown')
4013
-		$fullip = '255.255.255.255';
4251
+	if ($fullip == 'unknown') {
4252
+			$fullip = '255.255.255.255';
4253
+	}
4014 4254
 
4015 4255
 	$ip_parts = explode('-', $fullip);
4016 4256
 	$ip_array = array();
@@ -4034,10 +4274,11 @@  discard block
 block discarded – undo
4034 4274
 		$ip_array['low'] = $ip_parts[0];
4035 4275
 		$ip_array['high'] = $ip_parts[1];
4036 4276
 		return $ip_array;
4037
-	}
4038
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4277
+	} elseif (count($ip_parts) == 2) {
4278
+		// if ip 22.22.*-22.22.*
4039 4279
 	{
4040 4280
 		$valid_low = isValidIP($ip_parts[0]);
4281
+	}
4041 4282
 		$valid_high = isValidIP($ip_parts[1]);
4042 4283
 		$count = 0;
4043 4284
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4052,7 +4293,9 @@  discard block
 block discarded – undo
4052 4293
 				$ip_parts[0] .= $mode . $min;
4053 4294
 				$valid_low = isValidIP($ip_parts[0]);
4054 4295
 				$count++;
4055
-				if ($count > 9) break;
4296
+				if ($count > 9) {
4297
+					break;
4298
+				}
4056 4299
 			}
4057 4300
 		}
4058 4301
 
@@ -4066,7 +4309,9 @@  discard block
 block discarded – undo
4066 4309
 				$ip_parts[1] .= $mode . $max;
4067 4310
 				$valid_high = isValidIP($ip_parts[1]);
4068 4311
 				$count++;
4069
-				if ($count > 9) break;
4312
+				if ($count > 9) {
4313
+					break;
4314
+				}
4070 4315
 			}
4071 4316
 		}
4072 4317
 
@@ -4090,46 +4335,54 @@  discard block
 block discarded – undo
4090 4335
 {
4091 4336
 	global $modSettings;
4092 4337
 
4093
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4094
-		return $host;
4338
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4339
+			return $host;
4340
+	}
4095 4341
 	$t = microtime();
4096 4342
 
4097 4343
 	// Try the Linux host command, perhaps?
4098 4344
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4099 4345
 	{
4100
-		if (!isset($modSettings['host_to_dis']))
4101
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4102
-		else
4103
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4346
+		if (!isset($modSettings['host_to_dis'])) {
4347
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4348
+		} else {
4349
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4350
+		}
4104 4351
 
4105 4352
 		// Did host say it didn't find anything?
4106
-		if (strpos($test, 'not found') !== false)
4107
-			$host = '';
4353
+		if (strpos($test, 'not found') !== false) {
4354
+					$host = '';
4355
+		}
4108 4356
 		// Invalid server option?
4109
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4110
-			updateSettings(array('host_to_dis' => 1));
4357
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4358
+					updateSettings(array('host_to_dis' => 1));
4359
+		}
4111 4360
 		// Maybe it found something, after all?
4112
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4113
-			$host = $match[1];
4361
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4362
+					$host = $match[1];
4363
+		}
4114 4364
 	}
4115 4365
 
4116 4366
 	// This is nslookup; usually only Windows, but possibly some Unix?
4117 4367
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4118 4368
 	{
4119 4369
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4120
-		if (strpos($test, 'Non-existent domain') !== false)
4121
-			$host = '';
4122
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4123
-			$host = $match[1];
4370
+		if (strpos($test, 'Non-existent domain') !== false) {
4371
+					$host = '';
4372
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4373
+					$host = $match[1];
4374
+		}
4124 4375
 	}
4125 4376
 
4126 4377
 	// This is the last try :/.
4127
-	if (!isset($host) || $host === false)
4128
-		$host = @gethostbyaddr($ip);
4378
+	if (!isset($host) || $host === false) {
4379
+			$host = @gethostbyaddr($ip);
4380
+	}
4129 4381
 
4130 4382
 	// It took a long time, so let's cache it!
4131
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4132
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4383
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4384
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4385
+	}
4133 4386
 
4134 4387
 	return $host;
4135 4388
 }
@@ -4165,20 +4418,21 @@  discard block
 block discarded – undo
4165 4418
 			{
4166 4419
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4167 4420
 				$total = 0;
4168
-				for ($i = 0; $i < $max_chars; $i++)
4169
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4421
+				for ($i = 0; $i < $max_chars; $i++) {
4422
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4423
+				}
4170 4424
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4171 4425
 			}
4172 4426
 		}
4173 4427
 		return array_unique($returned_ints);
4174
-	}
4175
-	else
4428
+	} else
4176 4429
 	{
4177 4430
 		// Trim characters before and after and add slashes for database insertion.
4178 4431
 		$returned_words = array();
4179
-		foreach ($words as $word)
4180
-			if (($word = trim($word, '-_\'')) !== '')
4432
+		foreach ($words as $word) {
4433
+					if (($word = trim($word, '-_\'')) !== '')
4181 4434
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4435
+		}
4182 4436
 
4183 4437
 		// Filter out all words that occur more than once.
4184 4438
 		return array_unique($returned_words);
@@ -4200,16 +4454,18 @@  discard block
 block discarded – undo
4200 4454
 	global $settings, $txt;
4201 4455
 
4202 4456
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4203
-	if (function_exists('template_create_button') && !$force_use)
4204
-		return template_create_button($name, $alt, $label = '', $custom = '');
4457
+	if (function_exists('template_create_button') && !$force_use) {
4458
+			return template_create_button($name, $alt, $label = '', $custom = '');
4459
+	}
4205 4460
 
4206
-	if (!$settings['use_image_buttons'])
4207
-		return $txt[$alt];
4208
-	elseif (!empty($settings['use_buttons']))
4209
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4210
-	else
4211
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4212
-}
4461
+	if (!$settings['use_image_buttons']) {
4462
+			return $txt[$alt];
4463
+	} elseif (!empty($settings['use_buttons'])) {
4464
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4465
+	} else {
4466
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4467
+	}
4468
+	}
4213 4469
 
4214 4470
 /**
4215 4471
  * Sets up all of the top menu buttons
@@ -4252,9 +4508,10 @@  discard block
 block discarded – undo
4252 4508
 	var user_menus = new smc_PopupMenu();
4253 4509
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4254 4510
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4255
-		if ($context['allow_pm'])
4256
-			addInlineJavaScript('
4511
+		if ($context['allow_pm']) {
4512
+					addInlineJavaScript('
4257 4513
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4514
+		}
4258 4515
 
4259 4516
 		if (!empty($modSettings['enable_ajax_alerts']))
4260 4517
 		{
@@ -4414,88 +4671,96 @@  discard block
 block discarded – undo
4414 4671
 
4415 4672
 		// Now we put the buttons in the context so the theme can use them.
4416 4673
 		$menu_buttons = array();
4417
-		foreach ($buttons as $act => $button)
4418
-			if (!empty($button['show']))
4674
+		foreach ($buttons as $act => $button) {
4675
+					if (!empty($button['show']))
4419 4676
 			{
4420 4677
 				$button['active_button'] = false;
4678
+		}
4421 4679
 
4422 4680
 				// This button needs some action.
4423
-				if (isset($button['action_hook']))
4424
-					$needs_action_hook = true;
4681
+				if (isset($button['action_hook'])) {
4682
+									$needs_action_hook = true;
4683
+				}
4425 4684
 
4426 4685
 				// Make sure the last button truly is the last button.
4427 4686
 				if (!empty($button['is_last']))
4428 4687
 				{
4429
-					if (isset($last_button))
4430
-						unset($menu_buttons[$last_button]['is_last']);
4688
+					if (isset($last_button)) {
4689
+											unset($menu_buttons[$last_button]['is_last']);
4690
+					}
4431 4691
 					$last_button = $act;
4432 4692
 				}
4433 4693
 
4434 4694
 				// Go through the sub buttons if there are any.
4435
-				if (!empty($button['sub_buttons']))
4436
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4695
+				if (!empty($button['sub_buttons'])) {
4696
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4437 4697
 					{
4438 4698
 						if (empty($subbutton['show']))
4439 4699
 							unset($button['sub_buttons'][$key]);
4700
+				}
4440 4701
 
4441 4702
 						// 2nd level sub buttons next...
4442 4703
 						if (!empty($subbutton['sub_buttons']))
4443 4704
 						{
4444 4705
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4445 4706
 							{
4446
-								if (empty($sub_button2['show']))
4447
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4707
+								if (empty($sub_button2['show'])) {
4708
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4709
+								}
4448 4710
 							}
4449 4711
 						}
4450 4712
 					}
4451 4713
 
4452 4714
 				// Does this button have its own icon?
4453
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4454
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4455
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4456
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4457
-				elseif (isset($button['icon']))
4458
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4459
-				else
4460
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4715
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4716
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4717
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4718
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4719
+				} elseif (isset($button['icon'])) {
4720
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4721
+				} else {
4722
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4723
+				}
4461 4724
 
4462 4725
 				$menu_buttons[$act] = $button;
4463 4726
 			}
4464 4727
 
4465
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4466
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4728
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4729
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4730
+		}
4467 4731
 	}
4468 4732
 
4469 4733
 	$context['menu_buttons'] = $menu_buttons;
4470 4734
 
4471 4735
 	// Logging out requires the session id in the url.
4472
-	if (isset($context['menu_buttons']['logout']))
4473
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4736
+	if (isset($context['menu_buttons']['logout'])) {
4737
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4738
+	}
4474 4739
 
4475 4740
 	// Figure out which action we are doing so we can set the active tab.
4476 4741
 	// Default to home.
4477 4742
 	$current_action = 'home';
4478 4743
 
4479
-	if (isset($context['menu_buttons'][$context['current_action']]))
4480
-		$current_action = $context['current_action'];
4481
-	elseif ($context['current_action'] == 'search2')
4482
-		$current_action = 'search';
4483
-	elseif ($context['current_action'] == 'theme')
4484
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4485
-	elseif ($context['current_action'] == 'register2')
4486
-		$current_action = 'register';
4487
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4488
-		$current_action = 'login';
4489
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4490
-		$current_action = 'moderate';
4744
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4745
+			$current_action = $context['current_action'];
4746
+	} elseif ($context['current_action'] == 'search2') {
4747
+			$current_action = 'search';
4748
+	} elseif ($context['current_action'] == 'theme') {
4749
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4750
+	} elseif ($context['current_action'] == 'register2') {
4751
+			$current_action = 'register';
4752
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4753
+			$current_action = 'login';
4754
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4755
+			$current_action = 'moderate';
4756
+	}
4491 4757
 
4492 4758
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4493 4759
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4494 4760
 	{
4495 4761
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4496 4762
 		$context[$current_action] = true;
4497
-	}
4498
-	elseif ($context['current_action'] == 'pm')
4763
+	} elseif ($context['current_action'] == 'pm')
4499 4764
 	{
4500 4765
 		$current_action = 'self_pm';
4501 4766
 		$context['self_pm'] = true;
@@ -4552,12 +4817,14 @@  discard block
 block discarded – undo
4552 4817
 	}
4553 4818
 
4554 4819
 	// Not all actions are simple.
4555
-	if (!empty($needs_action_hook))
4556
-		call_integration_hook('integrate_current_action', array(&$current_action));
4820
+	if (!empty($needs_action_hook)) {
4821
+			call_integration_hook('integrate_current_action', array(&$current_action));
4822
+	}
4557 4823
 
4558
-	if (isset($context['menu_buttons'][$current_action]))
4559
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4560
-}
4824
+	if (isset($context['menu_buttons'][$current_action])) {
4825
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4826
+	}
4827
+	}
4561 4828
 
4562 4829
 /**
4563 4830
  * Generate a random seed and ensure it's stored in settings.
@@ -4581,30 +4848,35 @@  discard block
 block discarded – undo
4581 4848
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4582 4849
 	global $context, $txt;
4583 4850
 
4584
-	if ($db_show_debug === true)
4585
-		$context['debug']['hooks'][] = $hook;
4851
+	if ($db_show_debug === true) {
4852
+			$context['debug']['hooks'][] = $hook;
4853
+	}
4586 4854
 
4587 4855
 	// Need to have some control.
4588
-	if (!isset($context['instances']))
4589
-		$context['instances'] = array();
4856
+	if (!isset($context['instances'])) {
4857
+			$context['instances'] = array();
4858
+	}
4590 4859
 
4591 4860
 	$results = array();
4592
-	if (empty($modSettings[$hook]))
4593
-		return $results;
4861
+	if (empty($modSettings[$hook])) {
4862
+			return $results;
4863
+	}
4594 4864
 
4595 4865
 	$functions = explode(',', $modSettings[$hook]);
4596 4866
 	// Loop through each function.
4597 4867
 	foreach ($functions as $function)
4598 4868
 	{
4599 4869
 		// Hook has been marked as "disabled". Skip it!
4600
-		if (strpos($function, '!') !== false)
4601
-			continue;
4870
+		if (strpos($function, '!') !== false) {
4871
+					continue;
4872
+		}
4602 4873
 
4603 4874
 		$call = call_helper($function, true);
4604 4875
 
4605 4876
 		// Is it valid?
4606
-		if (!empty($call))
4607
-			$results[$function] = call_user_func_array($call, $parameters);
4877
+		if (!empty($call)) {
4878
+					$results[$function] = call_user_func_array($call, $parameters);
4879
+		}
4608 4880
 
4609 4881
 		// Whatever it was suppose to call, it failed :(
4610 4882
 		elseif (!empty($function))
@@ -4620,8 +4892,9 @@  discard block
 block discarded – undo
4620 4892
 			}
4621 4893
 
4622 4894
 			// "Assume" the file resides on $boarddir somewhere...
4623
-			else
4624
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4895
+			else {
4896
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4897
+			}
4625 4898
 		}
4626 4899
 	}
4627 4900
 
@@ -4643,12 +4916,14 @@  discard block
 block discarded – undo
4643 4916
 	global $smcFunc, $modSettings;
4644 4917
 
4645 4918
 	// Any objects?
4646
-	if ($object)
4647
-		$function = $function . '#';
4919
+	if ($object) {
4920
+			$function = $function . '#';
4921
+	}
4648 4922
 
4649 4923
 	// Any files  to load?
4650
-	if (!empty($file) && is_string($file))
4651
-		$function = $file . (!empty($function) ? '|' . $function : '');
4924
+	if (!empty($file) && is_string($file)) {
4925
+			$function = $file . (!empty($function) ? '|' . $function : '');
4926
+	}
4652 4927
 
4653 4928
 	// Get the correct string.
4654 4929
 	$integration_call = $function;
@@ -4670,13 +4945,14 @@  discard block
 block discarded – undo
4670 4945
 		if (!empty($current_functions))
4671 4946
 		{
4672 4947
 			$current_functions = explode(',', $current_functions);
4673
-			if (in_array($integration_call, $current_functions))
4674
-				return;
4948
+			if (in_array($integration_call, $current_functions)) {
4949
+							return;
4950
+			}
4675 4951
 
4676 4952
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4953
+		} else {
4954
+					$permanent_functions = array($integration_call);
4677 4955
 		}
4678
-		else
4679
-			$permanent_functions = array($integration_call);
4680 4956
 
4681 4957
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4682 4958
 	}
@@ -4685,8 +4961,9 @@  discard block
 block discarded – undo
4685 4961
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4686 4962
 
4687 4963
 	// Do nothing, if it's already there.
4688
-	if (in_array($integration_call, $functions))
4689
-		return;
4964
+	if (in_array($integration_call, $functions)) {
4965
+			return;
4966
+	}
4690 4967
 
4691 4968
 	$functions[] = $integration_call;
4692 4969
 	$modSettings[$hook] = implode(',', $functions);
@@ -4709,12 +4986,14 @@  discard block
 block discarded – undo
4709 4986
 	global $smcFunc, $modSettings;
4710 4987
 
4711 4988
 	// Any objects?
4712
-	if ($object)
4713
-		$function = $function . '#';
4989
+	if ($object) {
4990
+			$function = $function . '#';
4991
+	}
4714 4992
 
4715 4993
 	// Any files  to load?
4716
-	if (!empty($file) && is_string($file))
4717
-		$function = $file . '|' . $function;
4994
+	if (!empty($file) && is_string($file)) {
4995
+			$function = $file . '|' . $function;
4996
+	}
4718 4997
 
4719 4998
 	// Get the correct string.
4720 4999
 	$integration_call = $function;
@@ -4735,16 +5014,18 @@  discard block
 block discarded – undo
4735 5014
 	{
4736 5015
 		$current_functions = explode(',', $current_functions);
4737 5016
 
4738
-		if (in_array($integration_call, $current_functions))
4739
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5017
+		if (in_array($integration_call, $current_functions)) {
5018
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5019
+		}
4740 5020
 	}
4741 5021
 
4742 5022
 	// Turn the function list into something usable.
4743 5023
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4744 5024
 
4745 5025
 	// You can only remove it if it's available.
4746
-	if (!in_array($integration_call, $functions))
4747
-		return;
5026
+	if (!in_array($integration_call, $functions)) {
5027
+			return;
5028
+	}
4748 5029
 
4749 5030
 	$functions = array_diff($functions, array($integration_call));
4750 5031
 	$modSettings[$hook] = implode(',', $functions);
@@ -4765,17 +5046,20 @@  discard block
 block discarded – undo
4765 5046
 	global $context, $smcFunc, $txt, $db_show_debug;
4766 5047
 
4767 5048
 	// Really?
4768
-	if (empty($string))
4769
-		return false;
5049
+	if (empty($string)) {
5050
+			return false;
5051
+	}
4770 5052
 
4771 5053
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4772 5054
 	// A closure? should be a callable one.
4773
-	if (is_array($string) || $string instanceof Closure)
4774
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5055
+	if (is_array($string) || $string instanceof Closure) {
5056
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5057
+	}
4775 5058
 
4776 5059
 	// No full objects, sorry! pass a method or a property instead!
4777
-	if (is_object($string))
4778
-		return false;
5060
+	if (is_object($string)) {
5061
+			return false;
5062
+	}
4779 5063
 
4780 5064
 	// Stay vitaminized my friends...
4781 5065
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4784,8 +5068,9 @@  discard block
 block discarded – undo
4784 5068
 	$string = load_file($string);
4785 5069
 
4786 5070
 	// Loaded file failed
4787
-	if (empty($string))
4788
-		return false;
5071
+	if (empty($string)) {
5072
+			return false;
5073
+	}
4789 5074
 
4790 5075
 	// Found a method.
4791 5076
 	if (strpos($string, '::') !== false)
@@ -4806,8 +5091,9 @@  discard block
 block discarded – undo
4806 5091
 				// Add another one to the list.
4807 5092
 				if ($db_show_debug === true)
4808 5093
 				{
4809
-					if (!isset($context['debug']['instances']))
4810
-						$context['debug']['instances'] = array();
5094
+					if (!isset($context['debug']['instances'])) {
5095
+											$context['debug']['instances'] = array();
5096
+					}
4811 5097
 
4812 5098
 					$context['debug']['instances'][$class] = $class;
4813 5099
 				}
@@ -4817,13 +5103,15 @@  discard block
 block discarded – undo
4817 5103
 		}
4818 5104
 
4819 5105
 		// Right then. This is a call to a static method.
4820
-		else
4821
-			$func = array($class, $method);
5106
+		else {
5107
+					$func = array($class, $method);
5108
+		}
4822 5109
 	}
4823 5110
 
4824 5111
 	// Nope! just a plain regular function.
4825
-	else
4826
-		$func = $string;
5112
+	else {
5113
+			$func = $string;
5114
+	}
4827 5115
 
4828 5116
 	// Right, we got what we need, time to do some checks.
4829 5117
 	if (!is_callable($func, false, $callable_name))
@@ -4839,17 +5127,18 @@  discard block
 block discarded – undo
4839 5127
 	else
4840 5128
 	{
4841 5129
 		// What are we gonna do about it?
4842
-		if ($return)
4843
-			return $func;
5130
+		if ($return) {
5131
+					return $func;
5132
+		}
4844 5133
 
4845 5134
 		// If this is a plain function, avoid the heat of calling call_user_func().
4846 5135
 		else
4847 5136
 		{
4848
-			if (is_array($func))
4849
-				call_user_func($func);
4850
-
4851
-			else
4852
-				$func();
5137
+			if (is_array($func)) {
5138
+							call_user_func($func);
5139
+			} else {
5140
+							$func();
5141
+			}
4853 5142
 		}
4854 5143
 	}
4855 5144
 }
@@ -4866,31 +5155,34 @@  discard block
 block discarded – undo
4866 5155
 {
4867 5156
 	global $sourcedir, $txt, $boarddir, $settings;
4868 5157
 
4869
-	if (empty($string))
4870
-		return false;
5158
+	if (empty($string)) {
5159
+			return false;
5160
+	}
4871 5161
 
4872 5162
 	if (strpos($string, '|') !== false)
4873 5163
 	{
4874 5164
 		list ($file, $string) = explode('|', $string);
4875 5165
 
4876 5166
 		// Match the wildcards to their regular vars.
4877
-		if (empty($settings['theme_dir']))
4878
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4879
-
4880
-		else
4881
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5167
+		if (empty($settings['theme_dir'])) {
5168
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5169
+		} else {
5170
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5171
+		}
4882 5172
 
4883 5173
 		// Load the file if it can be loaded.
4884
-		if (file_exists($absPath))
4885
-			require_once($absPath);
5174
+		if (file_exists($absPath)) {
5175
+					require_once($absPath);
5176
+		}
4886 5177
 
4887 5178
 		// No? try a fallback to $sourcedir
4888 5179
 		else
4889 5180
 		{
4890 5181
 			$absPath = $sourcedir .'/'. $file;
4891 5182
 
4892
-			if (file_exists($absPath))
4893
-				require_once($absPath);
5183
+			if (file_exists($absPath)) {
5184
+							require_once($absPath);
5185
+			}
4894 5186
 
4895 5187
 			// Sorry, can't do much for you at this point.
4896 5188
 			else
@@ -4929,8 +5221,9 @@  discard block
 block discarded – undo
4929 5221
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
4930 5222
 
4931 5223
 	// No scheme? No data for you!
4932
-	if (empty($match[1]))
4933
-		return false;
5224
+	if (empty($match[1])) {
5225
+			return false;
5226
+	}
4934 5227
 
4935 5228
 	// An FTP url. We should try connecting and RETRieving it...
4936 5229
 	elseif ($match[1] == 'ftp')
@@ -4940,23 +5233,26 @@  discard block
 block discarded – undo
4940 5233
 
4941 5234
 		// Establish a connection and attempt to enable passive mode.
4942 5235
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
4943
-		if ($ftp->error !== false || !$ftp->passive())
4944
-			return false;
5236
+		if ($ftp->error !== false || !$ftp->passive()) {
5237
+					return false;
5238
+		}
4945 5239
 
4946 5240
 		// I want that one *points*!
4947 5241
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
4948 5242
 
4949 5243
 		// Since passive mode worked (or we would have returned already!) open the connection.
4950 5244
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
4951
-		if (!$fp)
4952
-			return false;
5245
+		if (!$fp) {
5246
+					return false;
5247
+		}
4953 5248
 
4954 5249
 		// The server should now say something in acknowledgement.
4955 5250
 		$ftp->check_response(150);
4956 5251
 
4957 5252
 		$data = '';
4958
-		while (!feof($fp))
4959
-			$data .= fread($fp, 4096);
5253
+		while (!feof($fp)) {
5254
+					$data .= fread($fp, 4096);
5255
+		}
4960 5256
 		fclose($fp);
4961 5257
 
4962 5258
 		// All done, right?  Good.
@@ -4968,8 +5264,9 @@  discard block
 block discarded – undo
4968 5264
 	elseif (isset($match[1]) && $match[1] == 'http')
4969 5265
 	{
4970 5266
 		// First try to use fsockopen, because it is fastest.
4971
-		if ($keep_alive && $match[3] == $keep_alive_dom)
4972
-			$fp = $keep_alive_fp;
5267
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5268
+					$fp = $keep_alive_fp;
5269
+		}
4973 5270
 		if (empty($fp))
4974 5271
 		{
4975 5272
 			// Open the socket on the port we want...
@@ -4989,20 +5286,21 @@  discard block
 block discarded – undo
4989 5286
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
4990 5287
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4991 5288
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4992
-				if ($keep_alive)
4993
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
4994
-				else
4995
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
4996
-			}
4997
-			else
5289
+				if ($keep_alive) {
5290
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5291
+				} else {
5292
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5293
+				}
5294
+			} else
4998 5295
 			{
4999 5296
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5000 5297
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5001 5298
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5002
-				if ($keep_alive)
5003
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5004
-				else
5005
-					fwrite($fp, 'connection: close' . "\r\n");
5299
+				if ($keep_alive) {
5300
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5301
+				} else {
5302
+									fwrite($fp, 'connection: close' . "\r\n");
5303
+				}
5006 5304
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5007 5305
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5008 5306
 				fwrite($fp, $post_data);
@@ -5015,30 +5313,33 @@  discard block
 block discarded – undo
5015 5313
 			{
5016 5314
 				$header = '';
5017 5315
 				$location = '';
5018
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5019
-					if (strpos($header, 'location:') !== false)
5316
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5317
+									if (strpos($header, 'location:') !== false)
5020 5318
 						$location = trim(substr($header, strpos($header, ':') + 1));
5319
+				}
5021 5320
 
5022
-				if (empty($location))
5023
-					return false;
5024
-				else
5321
+				if (empty($location)) {
5322
+									return false;
5323
+				} else
5025 5324
 				{
5026
-					if (!$keep_alive)
5027
-						fclose($fp);
5325
+					if (!$keep_alive) {
5326
+											fclose($fp);
5327
+					}
5028 5328
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5029 5329
 				}
5030 5330
 			}
5031 5331
 
5032 5332
 			// Make sure we get a 200 OK.
5033
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5034
-				return false;
5333
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5334
+							return false;
5335
+			}
5035 5336
 
5036 5337
 			// Skip the headers...
5037 5338
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5038 5339
 			{
5039
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5040
-					$content_length = $match[1];
5041
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5340
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5341
+									$content_length = $match[1];
5342
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5042 5343
 				{
5043 5344
 					$keep_alive_dom = null;
5044 5345
 					$keep_alive = false;
@@ -5050,17 +5351,19 @@  discard block
 block discarded – undo
5050 5351
 			$data = '';
5051 5352
 			if (isset($content_length))
5052 5353
 			{
5053
-				while (!feof($fp) && strlen($data) < $content_length)
5054
-					$data .= fread($fp, $content_length - strlen($data));
5055
-			}
5056
-			else
5354
+				while (!feof($fp) && strlen($data) < $content_length) {
5355
+									$data .= fread($fp, $content_length - strlen($data));
5356
+				}
5357
+			} else
5057 5358
 			{
5058
-				while (!feof($fp))
5059
-					$data .= fread($fp, 4096);
5359
+				while (!feof($fp)) {
5360
+									$data .= fread($fp, 4096);
5361
+				}
5060 5362
 			}
5061 5363
 
5062
-			if (!$keep_alive)
5063
-				fclose($fp);
5364
+			if (!$keep_alive) {
5365
+							fclose($fp);
5366
+			}
5064 5367
 		}
5065 5368
 
5066 5369
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5073,17 +5376,18 @@  discard block
 block discarded – undo
5073 5376
 			$fetch_data->get_url_data($url, $post_data);
5074 5377
 
5075 5378
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5076
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5077
-				$data = $fetch_data->result('body');
5078
-			else
5079
-				return false;
5379
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5380
+							$data = $fetch_data->result('body');
5381
+			} else {
5382
+							return false;
5383
+			}
5080 5384
 		}
5081 5385
 
5082 5386
 		// Neither fsockopen nor curl are available. Well, phooey.
5083
-		else
5084
-			return false;
5085
-	}
5086
-	else
5387
+		else {
5388
+					return false;
5389
+		}
5390
+	} else
5087 5391
 	{
5088 5392
 		// Umm, this shouldn't happen?
5089 5393
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5103,8 +5407,9 @@  discard block
 block discarded – undo
5103 5407
 	global $user_info, $smcFunc;
5104 5408
 
5105 5409
 	// Make sure we have something to work with.
5106
-	if (empty($topic))
5107
-		return array();
5410
+	if (empty($topic)) {
5411
+			return array();
5412
+	}
5108 5413
 
5109 5414
 
5110 5415
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5127,8 +5432,9 @@  discard block
 block discarded – undo
5127 5432
 				'topic' => $topic,
5128 5433
 			)
5129 5434
 		);
5130
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5131
-			$temp[] = (int) $row['content_id'];
5435
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5436
+					$temp[] = (int) $row['content_id'];
5437
+		}
5132 5438
 
5133 5439
 		cache_put_data($cache_key, $temp, $ttl);
5134 5440
 	}
@@ -5149,8 +5455,9 @@  discard block
 block discarded – undo
5149 5455
 {
5150 5456
 	global $context;
5151 5457
 
5152
-	if (empty($string))
5153
-		return $string;
5458
+	if (empty($string)) {
5459
+			return $string;
5460
+	}
5154 5461
 
5155 5462
 	// UTF-8 occurences of MS special characters
5156 5463
 	$findchars_utf8 = array(
@@ -5191,10 +5498,11 @@  discard block
 block discarded – undo
5191 5498
 		'--',	// &mdash;
5192 5499
 	);
5193 5500
 
5194
-	if ($context['utf8'])
5195
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5196
-	else
5197
-		$string = str_replace($findchars_iso, $replacechars, $string);
5501
+	if ($context['utf8']) {
5502
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5503
+	} else {
5504
+			$string = str_replace($findchars_iso, $replacechars, $string);
5505
+	}
5198 5506
 
5199 5507
 	return $string;
5200 5508
 }
@@ -5213,49 +5521,59 @@  discard block
 block discarded – undo
5213 5521
 {
5214 5522
 	global $context;
5215 5523
 
5216
-	if (!isset($matches[2]))
5217
-		return '';
5524
+	if (!isset($matches[2])) {
5525
+			return '';
5526
+	}
5218 5527
 
5219 5528
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5220 5529
 
5221 5530
 	// remove left to right / right to left overrides
5222
-	if ($num === 0x202D || $num === 0x202E)
5223
-		return '';
5531
+	if ($num === 0x202D || $num === 0x202E) {
5532
+			return '';
5533
+	}
5224 5534
 
5225 5535
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5226
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5227
-		return '&#' . $num . ';';
5536
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5537
+			return '&#' . $num . ';';
5538
+	}
5228 5539
 
5229 5540
 	if (empty($context['utf8']))
5230 5541
 	{
5231 5542
 		// no control characters
5232
-		if ($num < 0x20)
5233
-			return '';
5543
+		if ($num < 0x20) {
5544
+					return '';
5545
+		}
5234 5546
 		// text is text
5235
-		elseif ($num < 0x80)
5236
-			return chr($num);
5547
+		elseif ($num < 0x80) {
5548
+					return chr($num);
5549
+		}
5237 5550
 		// all others get html-ised
5238
-		else
5239
-			return '&#' . $matches[2] . ';';
5240
-	}
5241
-	else
5551
+		else {
5552
+					return '&#' . $matches[2] . ';';
5553
+		}
5554
+	} else
5242 5555
 	{
5243 5556
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5244 5557
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5245
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5246
-			return '';
5558
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5559
+					return '';
5560
+		}
5247 5561
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5248
-		elseif ($num < 0x80)
5249
-			return chr($num);
5562
+		elseif ($num < 0x80) {
5563
+					return chr($num);
5564
+		}
5250 5565
 		// <0x800 (2048)
5251
-		elseif ($num < 0x800)
5252
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5566
+		elseif ($num < 0x800) {
5567
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5568
+		}
5253 5569
 		// < 0x10000 (65536)
5254
-		elseif ($num < 0x10000)
5255
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5570
+		elseif ($num < 0x10000) {
5571
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5572
+		}
5256 5573
 		// <= 0x10FFFF (1114111)
5257
-		else
5258
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5574
+		else {
5575
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5576
+		}
5259 5577
 	}
5260 5578
 }
5261 5579
 
@@ -5271,28 +5589,34 @@  discard block
 block discarded – undo
5271 5589
  */
5272 5590
 function fixchar__callback($matches)
5273 5591
 {
5274
-	if (!isset($matches[1]))
5275
-		return '';
5592
+	if (!isset($matches[1])) {
5593
+			return '';
5594
+	}
5276 5595
 
5277 5596
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5278 5597
 
5279 5598
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5280 5599
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5281
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5282
-		return '';
5600
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5601
+			return '';
5602
+	}
5283 5603
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5284
-	elseif ($num < 0x80)
5285
-		return chr($num);
5604
+	elseif ($num < 0x80) {
5605
+			return chr($num);
5606
+	}
5286 5607
 	// <0x800 (2048)
5287
-	elseif ($num < 0x800)
5288
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5608
+	elseif ($num < 0x800) {
5609
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5610
+	}
5289 5611
 	// < 0x10000 (65536)
5290
-	elseif ($num < 0x10000)
5291
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5612
+	elseif ($num < 0x10000) {
5613
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5614
+	}
5292 5615
 	// <= 0x10FFFF (1114111)
5293
-	else
5294
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5295
-}
5616
+	else {
5617
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5618
+	}
5619
+	}
5296 5620
 
5297 5621
 /**
5298 5622
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5305,17 +5629,19 @@  discard block
 block discarded – undo
5305 5629
  */
5306 5630
 function entity_fix__callback($matches)
5307 5631
 {
5308
-	if (!isset($matches[2]))
5309
-		return '';
5632
+	if (!isset($matches[2])) {
5633
+			return '';
5634
+	}
5310 5635
 
5311 5636
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5312 5637
 
5313 5638
 	// we don't allow control characters, characters out of range, byte markers, etc
5314
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5315
-		return '';
5316
-	else
5317
-		return '&#' . $num . ';';
5318
-}
5639
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5640
+			return '';
5641
+	} else {
5642
+			return '&#' . $num . ';';
5643
+	}
5644
+	}
5319 5645
 
5320 5646
 /**
5321 5647
  * Return a Gravatar URL based on
@@ -5339,18 +5665,23 @@  discard block
 block discarded – undo
5339 5665
 		$ratings = array('G', 'PG', 'R', 'X');
5340 5666
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5341 5667
 		$url_params = array();
5342
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5343
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5344
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5345
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5346
-		if (!empty($modSettings['avatar_max_width_external']))
5347
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5348
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5349
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5668
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5669
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5670
+		}
5671
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5672
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5673
+		}
5674
+		if (!empty($modSettings['avatar_max_width_external'])) {
5675
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5676
+		}
5677
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5678
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5350 5679
 				$size_string = $modSettings['avatar_max_height_external'];
5680
+		}
5351 5681
 
5352
-		if (!empty($size_string))
5353
-			$url_params[] = 's=' . $size_string;
5682
+		if (!empty($size_string)) {
5683
+					$url_params[] = 's=' . $size_string;
5684
+		}
5354 5685
 	}
5355 5686
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5356 5687
 
@@ -5369,22 +5700,26 @@  discard block
 block discarded – undo
5369 5700
 	static $timezones = null, $lastwhen = null;
5370 5701
 
5371 5702
 	// No point doing this over if we already did it once
5372
-	if (!empty($timezones) && $when == $lastwhen)
5373
-		return $timezones;
5374
-	else
5375
-		$lastwhen = $when;
5703
+	if (!empty($timezones) && $when == $lastwhen) {
5704
+			return $timezones;
5705
+	} else {
5706
+			$lastwhen = $when;
5707
+	}
5376 5708
 
5377 5709
 	// Parseable datetime string?
5378
-	if (is_int($timestamp = strtotime($when)))
5379
-		$when = $timestamp;
5710
+	if (is_int($timestamp = strtotime($when))) {
5711
+			$when = $timestamp;
5712
+	}
5380 5713
 
5381 5714
 	// A Unix timestamp?
5382
-	elseif (is_numeric($when))
5383
-		$when = intval($when);
5715
+	elseif (is_numeric($when)) {
5716
+			$when = intval($when);
5717
+	}
5384 5718
 
5385 5719
 	// Invalid value? Just get current Unix timestamp.
5386
-	else
5387
-		$when = time();
5720
+	else {
5721
+			$when = time();
5722
+	}
5388 5723
 
5389 5724
 	// We'll need these too
5390 5725
 	$date_when = date_create('@' . $when);
@@ -5399,8 +5734,9 @@  discard block
 block discarded – undo
5399 5734
 	foreach ($priority_countries as $country)
5400 5735
 	{
5401 5736
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5402
-		if (!empty($country_tzids))
5403
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5737
+		if (!empty($country_tzids)) {
5738
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5739
+		}
5404 5740
 	}
5405 5741
 
5406 5742
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5414,8 +5750,9 @@  discard block
 block discarded – undo
5414 5750
 	foreach ($tzids as $tzid)
5415 5751
 	{
5416 5752
 		// We don't want UTC right now
5417
-		if ($tzid == 'UTC')
5418
-			continue;
5753
+		if ($tzid == 'UTC') {
5754
+					continue;
5755
+		}
5419 5756
 
5420 5757
 		$tz = timezone_open($tzid);
5421 5758
 
@@ -5436,13 +5773,14 @@  discard block
 block discarded – undo
5436 5773
 		}
5437 5774
 
5438 5775
 		// A time zone from a prioritized country?
5439
-		if (in_array($tzid, $priority_tzids))
5440
-			$priority_zones[$tzkey] = true;
5776
+		if (in_array($tzid, $priority_tzids)) {
5777
+					$priority_zones[$tzkey] = true;
5778
+		}
5441 5779
 
5442 5780
 		// Keep track of the location and offset for this tzid
5443
-		if (!empty($txt[$tzid]))
5444
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5445
-		else
5781
+		if (!empty($txt[$tzid])) {
5782
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5783
+		} else
5446 5784
 		{
5447 5785
 			$tzid_parts = explode('/', $tzid);
5448 5786
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5462,23 +5800,27 @@  discard block
 block discarded – undo
5462 5800
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5463 5801
 
5464 5802
 		// Use the custom description, if there is one
5465
-		if (!empty($tztxt[$tzvalue['tzid']]))
5466
-			$desc = $tztxt[$tzvalue['tzid']];
5803
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5804
+					$desc = $tztxt[$tzvalue['tzid']];
5805
+		}
5467 5806
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5468
-		else
5469
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5807
+		else {
5808
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5809
+		}
5470 5810
 
5471 5811
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5472 5812
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5473 5813
 
5474
-		if (isset($priority_zones[$tzkey]))
5475
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5476
-		else
5477
-			$timezones[$tzvalue['tzid']] = $desc;
5814
+		if (isset($priority_zones[$tzkey])) {
5815
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5816
+		} else {
5817
+					$timezones[$tzvalue['tzid']] = $desc;
5818
+		}
5478 5819
 	}
5479 5820
 
5480
-	if (!empty($priority_timezones))
5481
-		$priority_timezones[] = '-----';
5821
+	if (!empty($priority_timezones)) {
5822
+			$priority_timezones[] = '-----';
5823
+	}
5482 5824
 
5483 5825
 	$timezones = array_merge(
5484 5826
 		$priority_timezones,
@@ -5495,8 +5837,9 @@  discard block
 block discarded – undo
5495 5837
  */
5496 5838
 function inet_ptod($ip_address)
5497 5839
 {
5498
-	if (!isValidIP($ip_address))
5499
-		return $ip_address;
5840
+	if (!isValidIP($ip_address)) {
5841
+			return $ip_address;
5842
+	}
5500 5843
 
5501 5844
 	$bin = inet_pton($ip_address);
5502 5845
 	return $bin;
@@ -5508,13 +5851,15 @@  discard block
 block discarded – undo
5508 5851
  */
5509 5852
 function inet_dtop($bin)
5510 5853
 {
5511
-	if(empty($bin))
5512
-		return '';
5854
+	if(empty($bin)) {
5855
+			return '';
5856
+	}
5513 5857
 
5514 5858
 	global $db_type;
5515 5859
 
5516
-	if ($db_type == 'postgresql')
5517
-		return $bin;
5860
+	if ($db_type == 'postgresql') {
5861
+			return $bin;
5862
+	}
5518 5863
 
5519 5864
 	$ip_address = inet_ntop($bin);
5520 5865
 
@@ -5539,26 +5884,32 @@  discard block
 block discarded – undo
5539 5884
  */
5540 5885
 function _safe_serialize($value)
5541 5886
 {
5542
-	if(is_null($value))
5543
-		return 'N;';
5887
+	if(is_null($value)) {
5888
+			return 'N;';
5889
+	}
5544 5890
 
5545
-	if(is_bool($value))
5546
-		return 'b:'. (int) $value .';';
5891
+	if(is_bool($value)) {
5892
+			return 'b:'. (int) $value .';';
5893
+	}
5547 5894
 
5548
-	if(is_int($value))
5549
-		return 'i:'. $value .';';
5895
+	if(is_int($value)) {
5896
+			return 'i:'. $value .';';
5897
+	}
5550 5898
 
5551
-	if(is_float($value))
5552
-		return 'd:'. str_replace(',', '.', $value) .';';
5899
+	if(is_float($value)) {
5900
+			return 'd:'. str_replace(',', '.', $value) .';';
5901
+	}
5553 5902
 
5554
-	if(is_string($value))
5555
-		return 's:'. strlen($value) .':"'. $value .'";';
5903
+	if(is_string($value)) {
5904
+			return 's:'. strlen($value) .':"'. $value .'";';
5905
+	}
5556 5906
 
5557 5907
 	if(is_array($value))
5558 5908
 	{
5559 5909
 		$out = '';
5560
-		foreach($value as $k => $v)
5561
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5910
+		foreach($value as $k => $v) {
5911
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5912
+		}
5562 5913
 
5563 5914
 		return 'a:'. count($value) .':{'. $out .'}';
5564 5915
 	}
@@ -5584,8 +5935,9 @@  discard block
 block discarded – undo
5584 5935
 
5585 5936
 	$out = _safe_serialize($value);
5586 5937
 
5587
-	if (isset($mbIntEnc))
5588
-		mb_internal_encoding($mbIntEnc);
5938
+	if (isset($mbIntEnc)) {
5939
+			mb_internal_encoding($mbIntEnc);
5940
+	}
5589 5941
 
5590 5942
 	return $out;
5591 5943
 }
@@ -5602,8 +5954,9 @@  discard block
 block discarded – undo
5602 5954
 function _safe_unserialize($str)
5603 5955
 {
5604 5956
 	// Input  is not a string.
5605
-	if(empty($str) || !is_string($str))
5606
-		return false;
5957
+	if(empty($str) || !is_string($str)) {
5958
+			return false;
5959
+	}
5607 5960
 
5608 5961
 	$stack = array();
5609 5962
 	$expected = array();
@@ -5619,43 +5972,38 @@  discard block
 block discarded – undo
5619 5972
 	while($state != 1)
5620 5973
 	{
5621 5974
 		$type = isset($str[0]) ? $str[0] : '';
5622
-		if($type == '}')
5623
-			$str = substr($str, 1);
5624
-
5625
-		else if($type == 'N' && $str[1] == ';')
5975
+		if($type == '}') {
5976
+					$str = substr($str, 1);
5977
+		} else if($type == 'N' && $str[1] == ';')
5626 5978
 		{
5627 5979
 			$value = null;
5628 5980
 			$str = substr($str, 2);
5629
-		}
5630
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5981
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5631 5982
 		{
5632 5983
 			$value = $matches[1] == '1' ? true : false;
5633 5984
 			$str = substr($str, 4);
5634
-		}
5635
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5985
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5636 5986
 		{
5637 5987
 			$value = (int)$matches[1];
5638 5988
 			$str = $matches[2];
5639
-		}
5640
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5989
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5641 5990
 		{
5642 5991
 			$value = (float)$matches[1];
5643 5992
 			$str = $matches[3];
5644
-		}
5645
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5993
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5646 5994
 		{
5647 5995
 			$value = substr($matches[2], 0, (int)$matches[1]);
5648 5996
 			$str = substr($matches[2], (int)$matches[1] + 2);
5649
-		}
5650
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5997
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5651 5998
 		{
5652 5999
 			$expectedLength = (int)$matches[1];
5653 6000
 			$str = $matches[2];
5654 6001
 		}
5655 6002
 
5656 6003
 		// Object or unknown/malformed type.
5657
-		else
5658
-			return false;
6004
+		else {
6005
+					return false;
6006
+		}
5659 6007
 
5660 6008
 		switch($state)
5661 6009
 		{
@@ -5683,8 +6031,9 @@  discard block
 block discarded – undo
5683 6031
 				if($type == '}')
5684 6032
 				{
5685 6033
 					// Array size is less than expected.
5686
-					if(count($list) < end($expected))
5687
-						return false;
6034
+					if(count($list) < end($expected)) {
6035
+											return false;
6036
+					}
5688 6037
 
5689 6038
 					unset($list);
5690 6039
 					$list = &$stack[count($stack)-1];
@@ -5693,8 +6042,9 @@  discard block
 block discarded – undo
5693 6042
 					// Go to terminal state if we're at the end of the root array.
5694 6043
 					array_pop($expected);
5695 6044
 
5696
-					if(count($expected) == 0)
5697
-						$state = 1;
6045
+					if(count($expected) == 0) {
6046
+											$state = 1;
6047
+					}
5698 6048
 
5699 6049
 					break;
5700 6050
 				}
@@ -5702,8 +6052,9 @@  discard block
 block discarded – undo
5702 6052
 				if($type == 'i' || $type == 's')
5703 6053
 				{
5704 6054
 					// Array size exceeds expected length.
5705
-					if(count($list) >= end($expected))
5706
-						return false;
6055
+					if(count($list) >= end($expected)) {
6056
+											return false;
6057
+					}
5707 6058
 
5708 6059
 					$key = $value;
5709 6060
 					$state = 3;
@@ -5737,8 +6088,9 @@  discard block
 block discarded – undo
5737 6088
 	}
5738 6089
 
5739 6090
 	// Trailing data in input.
5740
-	if(!empty($str))
5741
-		return false;
6091
+	if(!empty($str)) {
6092
+			return false;
6093
+	}
5742 6094
 
5743 6095
 	return $data;
5744 6096
 }
@@ -5761,8 +6113,9 @@  discard block
 block discarded – undo
5761 6113
 
5762 6114
 	$out = _safe_unserialize($str);
5763 6115
 
5764
-	if (isset($mbIntEnc))
5765
-		mb_internal_encoding($mbIntEnc);
6116
+	if (isset($mbIntEnc)) {
6117
+			mb_internal_encoding($mbIntEnc);
6118
+	}
5766 6119
 
5767 6120
 	return $out;
5768 6121
 }
@@ -5777,12 +6130,14 @@  discard block
 block discarded – undo
5777 6130
 function smf_chmod($file, $value = 0)
5778 6131
 {
5779 6132
 	// No file? no checks!
5780
-	if (empty($file))
5781
-		return false;
6133
+	if (empty($file)) {
6134
+			return false;
6135
+	}
5782 6136
 
5783 6137
 	// Already writable?
5784
-	if (is_writable($file))
5785
-		return true;
6138
+	if (is_writable($file)) {
6139
+			return true;
6140
+	}
5786 6141
 
5787 6142
 	// Do we have a file or a dir?
5788 6143
 	$isDir = is_dir($file);
@@ -5798,10 +6153,9 @@  discard block
 block discarded – undo
5798 6153
 		{
5799 6154
 			$isWritable = true;
5800 6155
 			break;
6156
+		} else {
6157
+					@chmod($file, $val);
5801 6158
 		}
5802
-
5803
-		else
5804
-			@chmod($file, $val);
5805 6159
 	}
5806 6160
 
5807 6161
 	return $isWritable;
@@ -5820,8 +6174,9 @@  discard block
 block discarded – undo
5820 6174
 	global $txt;
5821 6175
 
5822 6176
 	// Come on...
5823
-	if (empty($json) || !is_string($json))
5824
-		return array();
6177
+	if (empty($json) || !is_string($json)) {
6178
+			return array();
6179
+	}
5825 6180
 
5826 6181
 	$returnArray = @json_decode($json, $returnAsArray);
5827 6182
 
@@ -5859,11 +6214,11 @@  discard block
 block discarded – undo
5859 6214
 		$jsonDebug = $jsonDebug[0];
5860 6215
 		loadLanguage('Errors');
5861 6216
 
5862
-		if (!empty($jsonDebug))
5863
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5864
-
5865
-		else
5866
-			log_error($txt['json_'. $jsonError], 'critical');
6217
+		if (!empty($jsonDebug)) {
6218
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6219
+		} else {
6220
+					log_error($txt['json_'. $jsonError], 'critical');
6221
+		}
5867 6222
 
5868 6223
 		// Everyone expects an array.
5869 6224
 		return array();
@@ -5897,8 +6252,9 @@  discard block
 block discarded – undo
5897 6252
 	global $db_show_debug, $modSettings;
5898 6253
 
5899 6254
 	// Defensive programming anyone?
5900
-	if (empty($data))
5901
-		return false;
6255
+	if (empty($data)) {
6256
+			return false;
6257
+	}
5902 6258
 
5903 6259
 	// Don't need extra stuff...
5904 6260
 	$db_show_debug = false;
@@ -5906,11 +6262,11 @@  discard block
 block discarded – undo
5906 6262
 	// Kill anything else.
5907 6263
 	ob_end_clean();
5908 6264
 
5909
-	if (!empty($modSettings['CompressedOutput']))
5910
-		@ob_start('ob_gzhandler');
5911
-
5912
-	else
5913
-		ob_start();
6265
+	if (!empty($modSettings['CompressedOutput'])) {
6266
+			@ob_start('ob_gzhandler');
6267
+	} else {
6268
+			ob_start();
6269
+	}
5914 6270
 
5915 6271
 	// Set the header.
5916 6272
 	header($type);
@@ -5942,8 +6298,9 @@  discard block
 block discarded – undo
5942 6298
 	static $done = false;
5943 6299
 
5944 6300
 	// If we don't need to do anything, don't
5945
-	if (!$update && $done)
5946
-		return;
6301
+	if (!$update && $done) {
6302
+			return;
6303
+	}
5947 6304
 
5948 6305
 	// Should we get a new copy of the official list of TLDs?
5949 6306
 	if ($update)
@@ -5955,8 +6312,9 @@  discard block
 block discarded – undo
5955 6312
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
5956 6313
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
5957 6314
 		// update to see if civilization has been restored.
5958
-		if ($tlds === false)
5959
-			$postapocalypticNightmare = true;
6315
+		if ($tlds === false) {
6316
+					$postapocalypticNightmare = true;
6317
+		}
5960 6318
 	}
5961 6319
 	// If we aren't updating and the regex is valid, we're done
5962 6320
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5971,10 +6329,11 @@  discard block
 block discarded – undo
5971 6329
 		// Clean $tlds and convert it to an array
5972 6330
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5973 6331
 			$line = trim($line);
5974
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5975
-				return false;
5976
-			else
5977
-				return true;
6332
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6333
+							return false;
6334
+			} else {
6335
+							return true;
6336
+			}
5978 6337
 		});
5979 6338
 
5980 6339
 		// Convert Punycode to Unicode
@@ -6066,8 +6425,7 @@  discard block
 block discarded – undo
6066 6425
 
6067 6426
 		$strlen = 'mb_strlen';
6068 6427
 		$substr = 'mb_substr';
6069
-	}
6070
-	else
6428
+	} else
6071 6429
 	{
6072 6430
 		$strlen = $smcFunc['strlen'];
6073 6431
 		$substr = $smcFunc['substr'];
@@ -6081,20 +6439,21 @@  discard block
 block discarded – undo
6081 6439
 
6082 6440
 		$first = $substr($string, 0, 1);
6083 6441
 
6084
-		if (empty($index[$first]))
6085
-			$index[$first] = array();
6442
+		if (empty($index[$first])) {
6443
+					$index[$first] = array();
6444
+		}
6086 6445
 
6087 6446
 		if ($strlen($string) > 1)
6088 6447
 		{
6089 6448
 			// Sanity check on recursion
6090
-			if ($depth > 99)
6091
-				$index[$first][$substr($string, 1)] = '';
6092
-
6093
-			else
6094
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6449
+			if ($depth > 99) {
6450
+							$index[$first][$substr($string, 1)] = '';
6451
+			} else {
6452
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6453
+			}
6454
+		} else {
6455
+					$index[$first][''] = '';
6095 6456
 		}
6096
-		else
6097
-			$index[$first][''] = '';
6098 6457
 
6099 6458
 		$depth--;
6100 6459
 		return $index;
@@ -6117,9 +6476,9 @@  discard block
 block discarded – undo
6117 6476
 			$key_regex = preg_quote($key, $delim);
6118 6477
 			$new_key = $key;
6119 6478
 
6120
-			if (empty($value))
6121
-				$sub_regex = '';
6122
-			else
6479
+			if (empty($value)) {
6480
+							$sub_regex = '';
6481
+			} else
6123 6482
 			{
6124 6483
 				$sub_regex = $index_to_regex($value, $delim);
6125 6484
 
@@ -6127,22 +6486,22 @@  discard block
 block discarded – undo
6127 6486
 				{
6128 6487
 					$new_key_array = explode('(?'.'>', $sub_regex);
6129 6488
 					$new_key .= $new_key_array[0];
6489
+				} else {
6490
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6130 6491
 				}
6131
-				else
6132
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6133 6492
 			}
6134 6493
 
6135
-			if ($depth > 1)
6136
-				$regex[$new_key] = $key_regex . $sub_regex;
6137
-			else
6494
+			if ($depth > 1) {
6495
+							$regex[$new_key] = $key_regex . $sub_regex;
6496
+			} else
6138 6497
 			{
6139 6498
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6140 6499
 				{
6141 6500
 					$regex[$new_key] = $key_regex . $sub_regex;
6142 6501
 					unset($index[$key]);
6502
+				} else {
6503
+									break;
6143 6504
 				}
6144
-				else
6145
-					break;
6146 6505
 			}
6147 6506
 		}
6148 6507
 
@@ -6151,10 +6510,11 @@  discard block
 block discarded – undo
6151 6510
 			$l1 = $strlen($k1);
6152 6511
 			$l2 = $strlen($k2);
6153 6512
 
6154
-			if ($l1 == $l2)
6155
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6156
-			else
6157
-				return $l1 > $l2 ? -1 : 1;
6513
+			if ($l1 == $l2) {
6514
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6515
+			} else {
6516
+							return $l1 > $l2 ? -1 : 1;
6517
+			}
6158 6518
 		});
6159 6519
 
6160 6520
 		$depth--;
@@ -6165,21 +6525,24 @@  discard block
 block discarded – undo
6165 6525
 	$index = array();
6166 6526
 	$regex = '';
6167 6527
 
6168
-	foreach ($strings as $string)
6169
-		$index = $add_string_to_index($string, $index);
6528
+	foreach ($strings as $string) {
6529
+			$index = $add_string_to_index($string, $index);
6530
+	}
6170 6531
 
6171 6532
 	if ($returnArray === true)
6172 6533
 	{
6173 6534
 		$regex = array();
6174
-		while (!empty($index))
6175
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6535
+		while (!empty($index)) {
6536
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6537
+		}
6538
+	} else {
6539
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6176 6540
 	}
6177
-	else
6178
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6179 6541
 
6180 6542
 	// Restore PHP's internal character encoding to whatever it was originally
6181
-	if (!empty($current_encoding))
6182
-		mb_internal_encoding($current_encoding);
6543
+	if (!empty($current_encoding)) {
6544
+			mb_internal_encoding($current_encoding);
6545
+	}
6183 6546
 
6184 6547
 	return $regex;
6185 6548
 }
@@ -6222,13 +6585,15 @@  discard block
 block discarded – undo
6222 6585
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6223 6586
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6224 6587
 	$headers = @get_headers($url);
6225
-	if ($headers === false)
6226
-		return false;
6588
+	if ($headers === false) {
6589
+			return false;
6590
+	}
6227 6591
 
6228 6592
 	// Now to see if it came back https...
6229 6593
 	// First check for a redirect status code in first row (301, 302, 307)
6230
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6231
-		return false;
6594
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6595
+			return false;
6596
+	}
6232 6597
 
6233 6598
 	// Search for the location entry to confirm https
6234 6599
 	$result = false;
@@ -6266,8 +6631,7 @@  discard block
 block discarded – undo
6266 6631
 		$is_admin = $user_info['is_admin'];
6267 6632
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6268 6633
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6269
-	}
6270
-	else
6634
+	} else
6271 6635
 	{
6272 6636
 		$request = $smcFunc['db_query']('', '
6273 6637
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6281,17 +6645,19 @@  discard block
 block discarded – undo
6281 6645
 
6282 6646
 		$row = $smcFunc['db_fetch_assoc']($request);
6283 6647
 
6284
-		if (empty($row['additional_groups']))
6285
-			$groups = array($row['id_group'], $row['id_post_group']);
6286
-		else
6287
-			$groups = array_merge(
6648
+		if (empty($row['additional_groups'])) {
6649
+					$groups = array($row['id_group'], $row['id_post_group']);
6650
+		} else {
6651
+					$groups = array_merge(
6288 6652
 					array($row['id_group'], $row['id_post_group']),
6289 6653
 					explode(',', $row['additional_groups'])
6290 6654
 			);
6655
+		}
6291 6656
 
6292 6657
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6293
-		foreach ($groups as $k => $v)
6294
-			$groups[$k] = (int) $v;
6658
+		foreach ($groups as $k => $v) {
6659
+					$groups[$k] = (int) $v;
6660
+		}
6295 6661
 
6296 6662
 		$is_admin = in_array(1, $groups);
6297 6663
 
@@ -6308,8 +6674,9 @@  discard block
 block discarded – undo
6308 6674
 				'current_member' => $userid,
6309 6675
 			)
6310 6676
 		);
6311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6312
-			$boards_mod[] = $row['id_board'];
6677
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6678
+					$boards_mod[] = $row['id_board'];
6679
+		}
6313 6680
 		$smcFunc['db_free_result']($request);
6314 6681
 
6315 6682
 		// Can any of the groups they're in moderate any of the boards?
@@ -6321,8 +6688,9 @@  discard block
 block discarded – undo
6321 6688
 				'groups' => $groups,
6322 6689
 			)
6323 6690
 		);
6324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6325
-			$boards_mod[] = $row['id_board'];
6691
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6692
+					$boards_mod[] = $row['id_board'];
6693
+		}
6326 6694
 		$smcFunc['db_free_result']($request);
6327 6695
 
6328 6696
 		// Just in case we've got duplicates here...
@@ -6332,21 +6700,25 @@  discard block
 block discarded – undo
6332 6700
 	}
6333 6701
 
6334 6702
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6335
-	if ($is_admin)
6336
-		$query_part['query_see_board'] = '1=1';
6703
+	if ($is_admin) {
6704
+			$query_part['query_see_board'] = '1=1';
6705
+	}
6337 6706
 	// Otherwise just the groups in $user_info['groups'].
6338
-	else
6339
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6707
+	else {
6708
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6709
+	}
6340 6710
 
6341 6711
 	// Build the list of boards they WANT to see.
6342 6712
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6343 6713
 
6344 6714
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6345
-	if (empty($ignoreboards))
6346
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6715
+	if (empty($ignoreboards)) {
6716
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6717
+	}
6347 6718
 	// Ok I guess they don't want to see all the boards
6348
-	else
6349
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6719
+	else {
6720
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6721
+	}
6350 6722
 
6351 6723
 	return $query_part;
6352 6724
 }
@@ -6360,10 +6732,11 @@  discard block
 block discarded – undo
6360 6732
 {
6361 6733
 	$secure = false;
6362 6734
 
6363
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6364
-		$secure = true;
6365
-	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')
6366
-		$secure = true;
6735
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6736
+			$secure = true;
6737
+	} 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') {
6738
+			$secure = true;
6739
+	}
6367 6740
 
6368 6741
 	return $secure;
6369 6742
 }
@@ -6380,11 +6753,12 @@  discard block
 block discarded – undo
6380 6753
 {
6381 6754
 	$url = iri_to_url($iri);
6382 6755
 
6383
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6384
-		return $iri;
6385
-	else
6386
-		return false;
6387
-}
6756
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6757
+			return $iri;
6758
+	} else {
6759
+			return false;
6760
+	}
6761
+	}
6388 6762
 
6389 6763
 /**
6390 6764
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6427,8 +6801,9 @@  discard block
 block discarded – undo
6427 6801
 
6428 6802
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6429 6803
 
6430
-	if (empty($host))
6431
-		return $iri;
6804
+	if (empty($host)) {
6805
+			return $iri;
6806
+	}
6432 6807
 
6433 6808
 	// Convert the domain using the Punycode algorithm
6434 6809
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6464,8 +6839,9 @@  discard block
 block discarded – undo
6464 6839
 
6465 6840
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6466 6841
 
6467
-	if (empty($host))
6468
-		return $url;
6842
+	if (empty($host)) {
6843
+			return $url;
6844
+	}
6469 6845
 
6470 6846
 	// Decode the domain from Punycode
6471 6847
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6491,8 +6867,9 @@  discard block
 block discarded – undo
6491 6867
 {
6492 6868
 	global $user_info, $modSettings, $smcFunc, $txt;
6493 6869
 
6494
-	if (empty($modSettings['cron_last_checked']))
6495
-		$modSettings['cron_last_checked'] = 0;
6870
+	if (empty($modSettings['cron_last_checked'])) {
6871
+			$modSettings['cron_last_checked'] = 0;
6872
+	}
6496 6873
 
6497 6874
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6498 6875
 	{
@@ -6512,9 +6889,9 @@  discard block
 block discarded – undo
6512 6889
 			loadLanguage('ManageScheduledTasks');
6513 6890
 			log_error($txt['cron_not_working']);
6514 6891
 			updateSettings(array('cron_is_real_cron' => 0));
6892
+		} else {
6893
+					updateSettings(array('cron_last_checked' => time()));
6515 6894
 		}
6516
-		else
6517
-			updateSettings(array('cron_last_checked' => time()));
6518 6895
 	}
6519 6896
 }
6520 6897
 
Please login to merge, or discard this patch.
Themes/default/ModerationCenter.template.php 1 patch
Braces   +59 added lines, -41 removed lines patch added patch discarded remove patch
@@ -54,18 +54,20 @@  discard block
 block discarded – undo
54 54
 		<div class="windowbg2 noup" id="group_requests_panel">
55 55
 			<ul>';
56 56
 
57
-	foreach ($context['group_requests'] as $request)
58
-		echo '
57
+	foreach ($context['group_requests'] as $request) {
58
+			echo '
59 59
 				<li class="smalltext">
60 60
 					<a href="', $request['request_href'], '">', $request['group']['name'], '</a> ', $txt['mc_groupr_by'], ' ', $request['member']['link'], '
61 61
 				</li>';
62
+	}
62 63
 
63 64
 	// Don't have any watched users right now?
64
-	if (empty($context['group_requests']))
65
-		echo '
65
+	if (empty($context['group_requests'])) {
66
+			echo '
66 67
 				<li>
67 68
 					<strong class="smalltext">', $txt['mc_group_requests_none'], '</strong>
68 69
 				</li>';
70
+	}
69 71
 
70 72
 	echo '
71 73
 			</ul>
@@ -121,18 +123,20 @@  discard block
 block discarded – undo
121 123
 		<div class="windowbg2 noup" id="watched_users_panel">
122 124
 			<ul>';
123 125
 
124
-	foreach ($context['watched_users'] as $user)
125
-		echo '
126
+	foreach ($context['watched_users'] as $user) {
127
+			echo '
126 128
 				<li>
127 129
 					<span class="smalltext">', sprintf(!empty($user['last_login']) ? $txt['mc_seen'] : $txt['mc_seen_never'], $user['link'], $user['last_login']), '</span>
128 130
 				</li>';
131
+	}
129 132
 
130 133
 	// Don't have any watched users right now?
131
-	if (empty($context['watched_users']))
132
-		echo '
134
+	if (empty($context['watched_users'])) {
135
+			echo '
133 136
 				<li>
134 137
 					<strong class="smalltext">', $txt['mc_watched_users_none'], '</strong>
135 138
 				</li>';
139
+	}
136 140
 
137 141
 	echo '
138 142
 			</ul>
@@ -188,18 +192,20 @@  discard block
 block discarded – undo
188 192
 		<div class="windowbg2 noup" id="reported_posts_panel">
189 193
 			<ul>';
190 194
 
191
-	foreach ($context['reported_posts'] as $post)
192
-		echo '
195
+	foreach ($context['reported_posts'] as $post) {
196
+			echo '
193 197
 				<li>
194 198
 					<span class="smalltext">', sprintf($txt['mc_post_report'], $post['report_link'], $post['author']['link']), '</span>
195 199
 				</li>';
200
+	}
196 201
 
197 202
 	// Don't have any watched users right now?
198
-	if (empty($context['reported_posts']))
199
-		echo '
203
+	if (empty($context['reported_posts'])) {
204
+			echo '
200 205
 				<li>
201 206
 					<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
202 207
 				</li>';
208
+	}
203 209
 
204 210
 	echo '
205 211
 			</ul>
@@ -255,18 +261,20 @@  discard block
 block discarded – undo
255 261
 		<div class="windowbg2 noup" id="reported_users_panel">
256 262
 			<ul>';
257 263
 
258
-	foreach ($context['reported_users'] as $user)
259
-		echo '
264
+	foreach ($context['reported_users'] as $user) {
265
+			echo '
260 266
 				<li>
261 267
 					<span class="smalltext">', $user['user']['link'], '</span>
262 268
 				</li>';
269
+	}
263 270
 
264 271
 	// Don't have any watched users right now?
265
-	if (empty($context['reported_users']))
266
-		echo '
272
+	if (empty($context['reported_users'])) {
273
+			echo '
267 274
 				<li>
268 275
 					<strong class="smalltext">', $txt['mc_reported_users_none'], '</strong>
269 276
 				</li>';
277
+	}
270 278
 
271 279
 	echo '
272 280
 			</ul>
@@ -313,11 +321,12 @@  discard block
 block discarded – undo
313 321
 	global $context, $txt, $scripturl;
314 322
 
315 323
 	// Let them know the action was a success.
316
-	if (!empty($context['report_post_action']))
317
-		echo '
324
+	if (!empty($context['report_post_action'])) {
325
+			echo '
318 326
 		<div class="infobox">
319 327
 			', $txt['report_action_' . $context['report_post_action']], '
320 328
 		</div>';
329
+	}
321 330
 
322 331
 	echo '
323 332
 		<div id="modnotes">
@@ -333,11 +342,12 @@  discard block
 block discarded – undo
333 342
 					<ul class="moderation_notes">';
334 343
 
335 344
 		// Cycle through the notes.
336
-		foreach ($context['notes'] as $note)
337
-			echo '
345
+		foreach ($context['notes'] as $note) {
346
+					echo '
338 347
 						<li class="smalltext">
339 348
 							', ($note['can_delete'] ? '<a href="' . $note['delete_href'] . ';' . $context['mod-modnote-del_token_var'] . '=' . $context['mod-modnote-del_token'] . '" data-confirm="' . $txt['mc_reportedp_delete_confirm'] . '" class="you_sure"><span class="generic_icons delete"></span></a>' : ''), $note['time'], ' <strong>', $note['author']['link'], ':</strong> ', $note['text'], '
340 349
 						</li>';
350
+		}
341 351
 
342 352
 		echo '
343 353
 					</ul>
@@ -378,18 +388,19 @@  discard block
 block discarded – undo
378 388
 	$remove_button = create_button('delete', 'remove_message', 'remove');
379 389
 
380 390
 	// No posts?
381
-	if (empty($context['unapproved_items']))
382
-		echo '
391
+	if (empty($context['unapproved_items'])) {
392
+			echo '
383 393
 			<div class="windowbg2">
384 394
 				<p class="centertext">
385 395
 					', $txt['mc_unapproved_' . $context['current_view'] . '_none_found'], '
386 396
 				</p>
387 397
 			</div>';
388
-	else
389
-		echo '
398
+	} else {
399
+			echo '
390 400
 			<div class="pagesection floatleft">
391 401
 				', $context['page_index'], '
392 402
 			</div>';
403
+	}
393 404
 
394 405
 	foreach ($context['unapproved_items'] as $item)
395 406
 	{
@@ -408,14 +419,16 @@  discard block
 block discarded – undo
408 419
 				<span class="floatright">
409 420
 					<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';approve=', $item['id'], '">', $approve_button, '</a>';
410 421
 
411
-		if ($item['can_delete'])
412
-			echo '
422
+		if ($item['can_delete']) {
423
+					echo '
413 424
 					', $context['menu_separator'], '
414 425
 					<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';delete=', $item['id'], '">', $remove_button, '</a>';
426
+		}
415 427
 
416
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
417
-			echo '
428
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
429
+					echo '
418 430
 					<input type="checkbox" name="item[]" value="', $item['id'], '" checked> ';
431
+		}
419 432
 
420 433
 		echo '
421 434
 				</span>
@@ -425,8 +438,8 @@  discard block
 block discarded – undo
425 438
 	echo '
426 439
 			<div class="pagesection">';
427 440
 
428
-	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
429
-		echo '
441
+	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
442
+			echo '
430 443
 				<div class="floatright">
431 444
 					<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'', $txt['mc_unapproved_sure'], '\')) submit();">
432 445
 						<option value="0">', $txt['with_selected'], ':</option>
@@ -438,12 +451,14 @@  discard block
 block discarded – undo
438 451
 						<input type="submit" name="mc_go" value="', $txt['go'], '" class="button">
439 452
 					</noscript>
440 453
 				</div>';
454
+	}
441 455
 
442
-	if (!empty($context['unapproved_items']))
443
-		echo '
456
+	if (!empty($context['unapproved_items'])) {
457
+			echo '
444 458
 				<div class="floatleft">
445 459
 					<div class="pagelinks">', $context['page_index'], '</div>
446 460
 				</div>';
461
+	}
447 462
 
448 463
 	echo '
449 464
 			</div><!-- .pagesection -->
@@ -464,8 +479,9 @@  discard block
 block discarded – undo
464 479
 
465 480
 	// We'll have a delete please bob.
466 481
 	// @todo Discuss this with the team and rewrite if required.
467
-	if (empty($delete_button))
468
-		$delete_button = create_button('delete', 'remove_message', 'remove', 'class="centericon"');
482
+	if (empty($delete_button)) {
483
+			$delete_button = create_button('delete', 'remove_message', 'remove', 'class="centericon"');
484
+	}
469 485
 
470 486
 	$output_html = '
471 487
 					<div>
@@ -474,10 +490,11 @@  discard block
 block discarded – undo
474 490
 						</div>
475 491
 						<div class="floatright">';
476 492
 
477
-	if ($post['can_delete'])
478
-		$output_html .= '
493
+	if ($post['can_delete']) {
494
+			$output_html .= '
479 495
 							<a href="' . $scripturl . '?action=moderate;area=userwatch;sa=post;delete=' . $post['id'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['mc_watched_users_delete_post'] . '" class="you_sure">' . $delete_button . '</a>
480 496
 							<input type="checkbox" name="delete[]" value="' . $post['id'] . '">';
497
+	}
481 498
 
482 499
 	$output_html .= '
483 500
 						</div>
@@ -521,12 +538,12 @@  discard block
 block discarded – undo
521 538
 				<input type="submit" name="save" value="', $txt['save'], '" class="button">
522 539
 			</div>
523 540
 		</form>';
524
-	}
525
-	else
526
-		echo '
541
+	} else {
542
+			echo '
527 543
 		<div class="windowbg">
528 544
 			<div class="centertext">', $txt['mc_no_settings'], '</div>
529 545
 		</div>';
546
+	}
530 547
 
531 548
 	echo '
532 549
 	</div><!-- #modcenter -->';
@@ -622,13 +639,14 @@  discard block
 block discarded – undo
622 639
 					</dd>
623 640
 				</dl>';
624 641
 
625
-	if ($context['template_data']['can_edit_personal'])
626
-		echo '
642
+	if ($context['template_data']['can_edit_personal']) {
643
+			echo '
627 644
 				<input type="checkbox" name="make_personal" id="make_personal"', $context['template_data']['personal'] ? ' checked' : '', '>
628 645
 					<label for="make_personal">
629 646
 						<strong>', $txt['mc_warning_template_personal'], '</strong>
630 647
 					</label>
631 648
 					<p class="smalltext">', $txt['mc_warning_template_personal_desc'], '</p>';
649
+	}
632 650
 
633 651
 	echo '
634 652
 				<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button">
Please login to merge, or discard this patch.
Sources/CacheAPI-postgres.php 2 patches
Braces   +28 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * PostgreSQL Cache API class
@@ -49,8 +50,9 @@  discard block
 block discarded – undo
49 50
 
50 51
 		$result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache'));
51 52
 
52
-		if (pg_affected_rows($result) === 0)
53
-			pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');			
53
+		if (pg_affected_rows($result) === 0) {
54
+					pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');
55
+		}
54 56
 	}
55 57
 
56 58
 	/**
@@ -60,14 +62,16 @@  discard block
 block discarded – undo
60 62
 	{
61 63
 		global $smcFunc, $db_connection;
62 64
 
63
-		if ($smcFunc['db_title'] !== 'PostgreSQL')
64
-			return false;
65
+		if ($smcFunc['db_title'] !== 'PostgreSQL') {
66
+					return false;
67
+		}
65 68
 
66 69
 		$result = pg_query($db_connection, 'SHOW server_version_num');
67 70
 		$res = pg_fetch_assoc($result);
68 71
 		
69
-		if ($res['server_version_num'] < 90500)
70
-			return false;
72
+		if ($res['server_version_num'] < 90500) {
73
+					return false;
74
+		}
71 75
 		
72 76
 		return $test ? true : parent::isSupported();
73 77
 	}
@@ -81,13 +85,15 @@  discard block
 block discarded – undo
81 85
 
82 86
 		$ttl = time() - $ttl;
83 87
 		
84
-		if (empty($this->pg_get_data_prep))
85
-			$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
88
+		if (empty($this->pg_get_data_prep)) {
89
+					$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
90
+		}
86 91
 			
87 92
 		$result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl));
88 93
 		
89
-		if (pg_affected_rows($result) === 0)
90
-			return null;
94
+		if (pg_affected_rows($result) === 0) {
95
+					return null;
96
+		}
91 97
 
92 98
 		$res = pg_fetch_assoc($result);
93 99
 
@@ -101,23 +107,26 @@  discard block
 block discarded – undo
101 107
 	{
102 108
 		global  $db_prefix, $db_connection;
103 109
 
104
-		if (!isset($value))
105
-			$value = '';
110
+		if (!isset($value)) {
111
+					$value = '';
112
+		}
106 113
 
107 114
 		$ttl = time() + $ttl;
108 115
 
109
-		if (empty($this->pg_put_data_prep))
110
-			$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
116
+		if (empty($this->pg_put_data_prep)) {
117
+					$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
111 118
 				'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3)
112 119
 				ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl'
113 120
 			);
121
+		}
114 122
 
115 123
 		$result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl));
116 124
 
117
-		if (pg_affected_rows($result) > 0)
118
-			return true;
119
-		else
120
-			return false;
125
+		if (pg_affected_rows($result) > 0) {
126
+					return true;
127
+		} else {
128
+					return false;
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	{
166 166
 		global $db_connection, $db_prefix;
167 167
 		
168
-		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time() );
168
+		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time());
169 169
 	}
170 170
 	
171 171
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	{
190 190
 		global $db_connection, $db_prefix;
191 191
 		
192
-		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM '. $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
192
+		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM ' . $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
193 193
 	}
194 194
 }
195 195
 
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/MessageIndex.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -349,7 +349,7 @@
 block discarded – undo
349 349
 			SELECT
350 350
 				t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
351 351
 				' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from,
352
-				' . ( $enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
352
+				' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
353 353
 				'	: '') . '
354 354
 				t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic,
355 355
 				ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
Please login to merge, or discard this patch.
Braces   +266 added lines, -199 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
  * Show the list of topics in this board, along with any child boards.
@@ -56,8 +57,9 @@  discard block
 block discarded – undo
56 57
 
57 58
 	$context['name'] = $board_info['name'];
58 59
 	$context['description'] = $board_info['description'];
59
-	if (!empty($board_info['description']))
60
-		$context['meta_description'] = strip_tags($board_info['description']);
60
+	if (!empty($board_info['description'])) {
61
+			$context['meta_description'] = strip_tags($board_info['description']);
62
+	}
61 63
 
62 64
 	// How many topics do we have in total?
63 65
 	$board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
@@ -73,12 +75,14 @@  discard block
 block discarded – undo
73 75
 		$session_name = session_name();
74 76
 		foreach ($_GET as $k => $v)
75 77
 		{
76
-			if (!in_array($k, array('board', 'start', $session_name)))
77
-				$context['robot_no_index'] = true;
78
+			if (!in_array($k, array('board', 'start', $session_name))) {
79
+							$context['robot_no_index'] = true;
80
+			}
78 81
 		}
79 82
 	}
80
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
81
-		$context['robot_no_index'] = true;
83
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
84
+			$context['robot_no_index'] = true;
85
+	}
82 86
 
83 87
 	// If we can view unapproved messages and there are some build up a list.
84 88
 	if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts']))
@@ -89,14 +93,16 @@  discard block
 block discarded – undo
89 93
 	}
90 94
 
91 95
 	// We only know these.
92
-	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post')))
93
-		$_REQUEST['sort'] = 'last_post';
96
+	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) {
97
+			$_REQUEST['sort'] = 'last_post';
98
+	}
94 99
 
95 100
 	// Make sure the starting place makes sense and construct the page index.
96
-	if (isset($_REQUEST['sort']))
97
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
101
+	if (isset($_REQUEST['sort'])) {
102
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
105
+	}
100 106
 	$context['start'] = &$_REQUEST['start'];
101 107
 
102 108
 	// Set a canonical URL for this page.
@@ -132,14 +138,16 @@  discard block
 block discarded – undo
132 138
 	$context['link_moderators'] = array();
133 139
 	if (!empty($board_info['moderators']))
134 140
 	{
135
-		foreach ($board_info['moderators'] as $mod)
136
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
141
+		foreach ($board_info['moderators'] as $mod) {
142
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
143
+		}
137 144
 	}
138 145
 	if (!empty($board_info['moderator_groups']))
139 146
 	{
140 147
 		// By default just tack the moderator groups onto the end of the members
141
-		foreach ($board_info['moderator_groups'] as $mod_group)
142
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
148
+		foreach ($board_info['moderator_groups'] as $mod_group) {
149
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
150
+		}
143 151
 	}
144 152
 
145 153
 	// Now we tack the info onto the end of the linktree
@@ -191,20 +199,24 @@  discard block
 block discarded – undo
191 199
 		);
192 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
193 201
 		{
194
-			if (empty($row['id_member']))
195
-				continue;
202
+			if (empty($row['id_member'])) {
203
+							continue;
204
+			}
196 205
 
197
-			if (!empty($row['online_color']))
198
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
199
-			else
200
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
206
+			if (!empty($row['online_color'])) {
207
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
208
+			} else {
209
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
210
+			}
201 211
 
202 212
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
203
-			if ($is_buddy)
204
-				$link = '<strong>' . $link . '</strong>';
213
+			if ($is_buddy) {
214
+							$link = '<strong>' . $link . '</strong>';
215
+			}
205 216
 
206
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
207
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
217
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
218
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
219
+			}
208 220
 			// @todo why are we filling this array of data that are just counted (twice) and discarded? ???
209 221
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
210 222
 				'id' => $row['id_member'],
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 				'hidden' => empty($row['show_online']),
218 230
 			);
219 231
 
220
-			if (empty($row['show_online']))
221
-				$context['view_num_hidden']++;
232
+			if (empty($row['show_online'])) {
233
+							$context['view_num_hidden']++;
234
+			}
222 235
 		}
223 236
 		$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
224 237
 		$smcFunc['db_free_result']($request);
@@ -260,8 +273,9 @@  discard block
 block discarded – undo
260 273
 	// Bring in any changes we want to make before the query.
261 274
 	call_integration_hook('integrate_pre_messageindex', array(&$sort_methods));
262 275
 
263
-	foreach ($sort_methods as $key => $val)
264
-		$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
276
+	foreach ($sort_methods as $key => $val) {
277
+			$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
278
+	}
265 279
 
266 280
 	// Calculate the fastest way to get the topics.
267 281
 	$start = (int) $_REQUEST['start'];
@@ -271,14 +285,15 @@  discard block
 block discarded – undo
271 285
 		$fake_ascending = true;
272 286
 		$context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex'];
273 287
 		$start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex'];
288
+	} else {
289
+			$fake_ascending = false;
274 290
 	}
275
-	else
276
-		$fake_ascending = false;
277 291
 
278 292
 	// Setup the default topic icons...
279 293
 	$context['icon_sources'] = array();
280
-	foreach ($context['stable_icons'] as $icon)
281
-		$context['icon_sources'][$icon] = 'images_url';
294
+	foreach ($context['stable_icons'] as $icon) {
295
+			$context['icon_sources'][$icon] = 'images_url';
296
+	}
282 297
 
283 298
 	$topic_ids = array();
284 299
 	$context['topics'] = array();
@@ -316,8 +331,9 @@  discard block
 block discarded – undo
316 331
 			$message_pre_index_parameters
317 332
 		);
318 333
 		$topic_ids = array();
319
-		while ($row = $smcFunc['db_fetch_assoc']($request))
320
-			$topic_ids[] = $row['id_topic'];
334
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
335
+					$topic_ids[] = $row['id_topic'];
336
+		}
321 337
 	}
322 338
 
323 339
 	// Grab the appropriate topic information...
@@ -340,10 +356,11 @@  discard block
 block discarded – undo
340 356
 		$message_index_wheres = array();
341 357
 		call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters, &$message_index_wheres, &$topic_ids));
342 358
 
343
-		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
344
-			$enableParticipation = true;
345
-		else
346
-			$enableParticipation = false;
359
+		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) {
360
+					$enableParticipation = true;
361
+		} else {
362
+					$enableParticipation = false;
363
+		}
347 364
 
348 365
 		$result = $smcFunc['db_query']('substring', '
349 366
 			SELECT
@@ -382,11 +399,13 @@  discard block
 block discarded – undo
382 399
 		// Begin 'printing' the message index for current board.
383 400
 		while ($row = $smcFunc['db_fetch_assoc']($result))
384 401
 		{
385
-			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
386
-				continue;
402
+			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
403
+							continue;
404
+			}
387 405
 
388
-			if (!$pre_query)
389
-				$topic_ids[] = $row['id_topic'];
406
+			if (!$pre_query) {
407
+							$topic_ids[] = $row['id_topic'];
408
+			}
390 409
 
391 410
 			// Reference the main color class.
392 411
 			$colorClass = 'windowbg';
@@ -396,8 +415,9 @@  discard block
 block discarded – undo
396 415
 			{
397 416
 				// Limit them to $modSettings['preview_characters'] characters
398 417
 				$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
399
-				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
400
-					$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
418
+				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
419
+									$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
420
+				}
401 421
 
402 422
 				// Censor the subject and message preview.
403 423
 				censorText($row['first_subject']);
@@ -408,27 +428,27 @@  discard block
 block discarded – undo
408 428
 				{
409 429
 					$row['last_subject'] = $row['first_subject'];
410 430
 					$row['last_body'] = $row['first_body'];
411
-				}
412
-				else
431
+				} else
413 432
 				{
414 433
 					$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
415
-					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
416
-						$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
434
+					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
435
+											$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
436
+					}
417 437
 
418 438
 					censorText($row['last_subject']);
419 439
 					censorText($row['last_body']);
420 440
 				}
421
-			}
422
-			else
441
+			} else
423 442
 			{
424 443
 				$row['first_body'] = '';
425 444
 				$row['last_body'] = '';
426 445
 				censorText($row['first_subject']);
427 446
 
428
-				if ($row['id_first_msg'] == $row['id_last_msg'])
429
-					$row['last_subject'] = $row['first_subject'];
430
-				else
431
-					censorText($row['last_subject']);
447
+				if ($row['id_first_msg'] == $row['id_last_msg']) {
448
+									$row['last_subject'] = $row['first_subject'];
449
+				} else {
450
+									censorText($row['last_subject']);
451
+				}
432 452
 			}
433 453
 
434 454
 			// Decide how many pages the topic should have.
@@ -439,42 +459,50 @@  discard block
 block discarded – undo
439 459
 				$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
440 460
 
441 461
 				// If we can use all, show all.
442
-				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
443
-					$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
462
+				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) {
463
+									$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
464
+				}
465
+			} else {
466
+							$pages = '';
444 467
 			}
445
-			else
446
-				$pages = '';
447 468
 
448 469
 			// We need to check the topic icons exist...
449 470
 			if (!empty($modSettings['messageIconChecks_enable']))
450 471
 			{
451
-				if (!isset($context['icon_sources'][$row['first_icon']]))
452
-					$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
453
-				if (!isset($context['icon_sources'][$row['last_icon']]))
454
-					$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
455
-			}
456
-			else
472
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
473
+									$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
474
+				}
475
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
476
+									$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
477
+				}
478
+			} else
457 479
 			{
458
-				if (!isset($context['icon_sources'][$row['first_icon']]))
459
-					$context['icon_sources'][$row['first_icon']] = 'images_url';
460
-				if (!isset($context['icon_sources'][$row['last_icon']]))
461
-					$context['icon_sources'][$row['last_icon']] = 'images_url';
480
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
481
+									$context['icon_sources'][$row['first_icon']] = 'images_url';
482
+				}
483
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
484
+									$context['icon_sources'][$row['last_icon']] = 'images_url';
485
+				}
462 486
 			}
463 487
 
464
-			if (!empty($board_info['recycle']))
465
-				$row['first_icon'] = 'recycled';
488
+			if (!empty($board_info['recycle'])) {
489
+							$row['first_icon'] = 'recycled';
490
+			}
466 491
 
467 492
 			// Is this topic pending approval, or does it have any posts pending approval?
468
-			if ($context['can_approve_posts'] && $row['unapproved_posts'])
469
-				$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
493
+			if ($context['can_approve_posts'] && $row['unapproved_posts']) {
494
+							$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
495
+			}
470 496
 
471 497
 			// Sticky topics should get a different color, too.
472
-			if ($row['is_sticky'])
473
-				$colorClass .= ' sticky';
498
+			if ($row['is_sticky']) {
499
+							$colorClass .= ' sticky';
500
+			}
474 501
 
475 502
 			// Locked topics get special treatment as well.
476
-			if ($row['locked'])
477
-				$colorClass .= ' locked';
503
+			if ($row['locked']) {
504
+							$colorClass .= ' locked';
505
+			}
478 506
 
479 507
 			// 'Print' the topic info.
480 508
 			$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -555,8 +583,9 @@  discard block
 block discarded – undo
555 583
 		$smcFunc['db_free_result']($result);
556 584
 
557 585
 		// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
558
-		if ($fake_ascending)
559
-			$context['topics'] = array_reverse($context['topics'], true);
586
+		if ($fake_ascending) {
587
+					$context['topics'] = array_reverse($context['topics'], true);
588
+		}
560 589
 	}
561 590
 
562 591
 	$context['jump_to'] = array(
@@ -579,9 +608,9 @@  discard block
 block discarded – undo
579 608
 		// Can we restore topics?
580 609
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
581 610
 
582
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
583
-			$context['can_move_any'] = true;
584
-		else
611
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
612
+					$context['can_move_any'] = true;
613
+		} else
585 614
 		{
586 615
 			// We'll use this in a minute
587 616
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -608,11 +637,13 @@  discard block
 block discarded – undo
608 637
 		}
609 638
 
610 639
 		// Can we use quick moderation checkboxes?
611
-		if ($options['display_quick_mod'] == 1)
612
-			$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
640
+		if ($options['display_quick_mod'] == 1) {
641
+					$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
642
+		}
613 643
 		// Or the icons?
614
-		else
615
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
644
+		else {
645
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
646
+		}
616 647
 	}
617 648
 
618 649
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -646,13 +677,15 @@  discard block
 block discarded – undo
646 677
 			);
647 678
 
648 679
 			// We've seen all these boards now!
649
-			foreach ($board_info['parent_boards'] as $k => $dummy)
650
-				if (isset($_SESSION['topicseen_cache'][$k]))
680
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
681
+							if (isset($_SESSION['topicseen_cache'][$k]))
651 682
 					unset($_SESSION['topicseen_cache'][$k]);
683
+			}
652 684
 		}
653 685
 
654
-		if (isset($_SESSION['topicseen_cache'][$board]))
655
-			unset($_SESSION['topicseen_cache'][$board]);
686
+		if (isset($_SESSION['topicseen_cache'][$board])) {
687
+					unset($_SESSION['topicseen_cache'][$board]);
688
+		}
656 689
 
657 690
 		$request = $smcFunc['db_query']('', '
658 691
 			SELECT id_topic, id_board, sent
@@ -673,8 +706,9 @@  discard block
 block discarded – undo
673 706
 				$context['is_marked_notify'] = true;
674 707
 				$board_sent = $row['sent'];
675 708
 			}
676
-			if (!empty($row['id_topic']))
677
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
709
+			if (!empty($row['id_topic'])) {
710
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
711
+			}
678 712
 		}
679 713
 		$smcFunc['db_free_result']($request);
680 714
 
@@ -698,8 +732,7 @@  discard block
 block discarded – undo
698 732
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
699 733
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
700 734
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
701
-	}
702
-	else
735
+	} else
703 736
 	{
704 737
 		$context['is_marked_notify'] = false;
705 738
 		$context['board_notification_mode'] = 1;
@@ -712,23 +745,27 @@  discard block
 block discarded – undo
712 745
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
713 746
 
714 747
 	// Don't want to show this forever...
715
-	if ($context['becomesUnapproved'])
716
-		unset($_SESSION['becomesUnapproved']);
748
+	if ($context['becomesUnapproved']) {
749
+			unset($_SESSION['becomesUnapproved']);
750
+	}
717 751
 
718 752
 	// Build the message index button array.
719 753
 	$context['normal_buttons'] = array();
720 754
 
721
-	if ($context['can_post_new'])
722
-		$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
755
+	if ($context['can_post_new']) {
756
+			$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
757
+	}
723 758
 
724
-	if ($context['can_post_poll'])
725
-		$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
759
+	if ($context['can_post_poll']) {
760
+			$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
761
+	}
726 762
 
727
-	if ($context['user']['is_logged'])
728
-		$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
763
+	if ($context['user']['is_logged']) {
764
+			$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
765
+	}
729 766
 
730
-	if ($context['can_mark_notify'])
731
-		$context['normal_buttons']['notify'] = array(
767
+	if ($context['can_mark_notify']) {
768
+			$context['normal_buttons']['notify'] = array(
732 769
 			'lang' => true,
733 770
 			'text' => 'notify_board_' . $context['board_notification_mode'],
734 771
 			'sub_buttons' => array(
@@ -746,6 +783,7 @@  discard block
 block discarded – undo
746 783
 				),
747 784
 			),
748 785
 		);
786
+	}
749 787
 
750 788
 	// Javascript for inline editing.
751 789
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -767,18 +805,21 @@  discard block
 block discarded – undo
767 805
 	checkSession('request');
768 806
 
769 807
 	// Lets go straight to the restore area.
770
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
771
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
808
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
809
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
810
+	}
772 811
 
773
-	if (isset($_SESSION['topicseen_cache']))
774
-		$_SESSION['topicseen_cache'] = array();
812
+	if (isset($_SESSION['topicseen_cache'])) {
813
+			$_SESSION['topicseen_cache'] = array();
814
+	}
775 815
 
776 816
 	// This is going to be needed to send off the notifications and for updateLastMessages().
777 817
 	require_once($sourcedir . '/Subs-Post.php');
778 818
 
779 819
 	// Remember the last board they moved things to.
780
-	if (isset($_REQUEST['move_to']))
781
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
820
+	if (isset($_REQUEST['move_to'])) {
821
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
822
+	}
782 823
 
783 824
 	// Only a few possible actions.
784 825
 	$possibleActions = array();
@@ -798,8 +839,7 @@  discard block
 block discarded – undo
798 839
 		);
799 840
 
800 841
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
801
-	}
802
-	else
842
+	} else
803 843
 	{
804 844
 		/**
805 845
 		 * @todo Ugly. There's no getting around this, is there?
@@ -817,8 +857,7 @@  discard block
 block discarded – undo
817 857
 		if (!empty($board))
818 858
 		{
819 859
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
820
-		}
821
-		else
860
+		} else
822 861
 		{
823 862
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
824 863
 		}
@@ -829,55 +868,67 @@  discard block
 block discarded – undo
829 868
 		}
830 869
 	}
831 870
 
832
-	if (!$user_info['is_guest'])
833
-		$possibleActions[] = 'markread';
834
-	if (!empty($boards_can['make_sticky']))
835
-		$possibleActions[] = 'sticky';
836
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
837
-		$possibleActions[] = 'move';
838
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
839
-		$possibleActions[] = 'remove';
840
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
841
-		$possibleActions[] = 'lock';
842
-	if (!empty($boards_can['merge_any']))
843
-		$possibleActions[] = 'merge';
844
-	if (!empty($boards_can['approve_posts']))
845
-		$possibleActions[] = 'approve';
871
+	if (!$user_info['is_guest']) {
872
+			$possibleActions[] = 'markread';
873
+	}
874
+	if (!empty($boards_can['make_sticky'])) {
875
+			$possibleActions[] = 'sticky';
876
+	}
877
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
878
+			$possibleActions[] = 'move';
879
+	}
880
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
881
+			$possibleActions[] = 'remove';
882
+	}
883
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
884
+			$possibleActions[] = 'lock';
885
+	}
886
+	if (!empty($boards_can['merge_any'])) {
887
+			$possibleActions[] = 'merge';
888
+	}
889
+	if (!empty($boards_can['approve_posts'])) {
890
+			$possibleActions[] = 'approve';
891
+	}
846 892
 
847 893
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
848 894
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
849 895
 	if (!empty($_REQUEST['topics']))
850 896
 	{
851 897
 		// If the action isn't valid, just quit now.
852
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
853
-			redirectexit($redirect_url);
898
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
899
+					redirectexit($redirect_url);
900
+		}
854 901
 
855 902
 		// Merge requires all topics as one parameter and can be done at once.
856 903
 		if ($_REQUEST['qaction'] == 'merge')
857 904
 		{
858 905
 			// Merge requires at least two topics.
859
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
860
-				redirectexit($redirect_url);
906
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
907
+							redirectexit($redirect_url);
908
+			}
861 909
 
862 910
 			require_once($sourcedir . '/SplitTopics.php');
863 911
 			return MergeExecute($_REQUEST['topics']);
864 912
 		}
865 913
 
866 914
 		// Just convert to the other method, to make it easier.
867
-		foreach ($_REQUEST['topics'] as $topic)
868
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
915
+		foreach ($_REQUEST['topics'] as $topic) {
916
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
917
+		}
869 918
 	}
870 919
 
871 920
 	// Weird... how'd you get here?
872
-	if (empty($_REQUEST['actions']))
873
-		redirectexit($redirect_url);
921
+	if (empty($_REQUEST['actions'])) {
922
+			redirectexit($redirect_url);
923
+	}
874 924
 
875 925
 	// Validate each action.
876 926
 	$temp = array();
877 927
 	foreach ($_REQUEST['actions'] as $topic => $action)
878 928
 	{
879
-		if (in_array($action, $possibleActions))
880
-			$temp[(int) $topic] = $action;
929
+		if (in_array($action, $possibleActions)) {
930
+					$temp[(int) $topic] = $action;
931
+		}
881 932
 	}
882 933
 	$_REQUEST['actions'] = $temp;
883 934
 
@@ -898,27 +949,31 @@  discard block
 block discarded – undo
898 949
 		{
899 950
 			if (!empty($board))
900 951
 			{
901
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
902
-					unset($_REQUEST['actions'][$row['id_topic']]);
903
-			}
904
-			else
952
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
953
+									unset($_REQUEST['actions'][$row['id_topic']]);
954
+				}
955
+			} else
905 956
 			{
906 957
 				// Don't allow them to act on unapproved posts they can't see...
907
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
908
-					unset($_REQUEST['actions'][$row['id_topic']]);
958
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
959
+									unset($_REQUEST['actions'][$row['id_topic']]);
960
+				}
909 961
 				// Goodness, this is fun.  We need to validate the action.
910
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
911
-					unset($_REQUEST['actions'][$row['id_topic']]);
912
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
913
-					unset($_REQUEST['actions'][$row['id_topic']]);
914
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
915
-					unset($_REQUEST['actions'][$row['id_topic']]);
962
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
963
+									unset($_REQUEST['actions'][$row['id_topic']]);
964
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) {
965
+									unset($_REQUEST['actions'][$row['id_topic']]);
966
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) {
967
+									unset($_REQUEST['actions'][$row['id_topic']]);
968
+				}
916 969
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
917
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))))
918
-					unset($_REQUEST['actions'][$row['id_topic']]);
970
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) {
971
+									unset($_REQUEST['actions'][$row['id_topic']]);
972
+				}
919 973
 				// If the topic is approved then you need permission to approve the posts within.
920
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))))
921
-					unset($_REQUEST['actions'][$row['id_topic']]);
974
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) {
975
+									unset($_REQUEST['actions'][$row['id_topic']]);
976
+				}
922 977
 			}
923 978
 		}
924 979
 		$smcFunc['db_free_result']($request);
@@ -936,11 +991,11 @@  discard block
 block discarded – undo
936 991
 	{
937 992
 		$topic = (int) $topic;
938 993
 
939
-		if ($action == 'markread')
940
-			$markCache[] = $topic;
941
-		elseif ($action == 'sticky')
942
-			$stickyCache[] = $topic;
943
-		elseif ($action == 'move')
994
+		if ($action == 'markread') {
995
+					$markCache[] = $topic;
996
+		} elseif ($action == 'sticky') {
997
+					$stickyCache[] = $topic;
998
+		} elseif ($action == 'move')
944 999
 		{
945 1000
 			require_once($sourcedir . '/MoveTopic.php');
946 1001
 			moveTopicConcurrence();
@@ -948,23 +1003,25 @@  discard block
 block discarded – undo
948 1003
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
949 1004
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
950 1005
 
951
-			if (empty($moveCache[1][$topic]))
952
-				continue;
1006
+			if (empty($moveCache[1][$topic])) {
1007
+							continue;
1008
+			}
953 1009
 
954 1010
 			$moveCache[0][] = $topic;
1011
+		} elseif ($action == 'remove') {
1012
+					$removeCache[] = $topic;
1013
+		} elseif ($action == 'lock') {
1014
+					$lockCache[] = $topic;
1015
+		} elseif ($action == 'approve') {
1016
+					$approveCache[] = $topic;
955 1017
 		}
956
-		elseif ($action == 'remove')
957
-			$removeCache[] = $topic;
958
-		elseif ($action == 'lock')
959
-			$lockCache[] = $topic;
960
-		elseif ($action == 'approve')
961
-			$approveCache[] = $topic;
962 1018
 	}
963 1019
 
964
-	if (empty($board))
965
-		$affectedBoards = array();
966
-	else
967
-		$affectedBoards = array($board => array(0, 0));
1020
+	if (empty($board)) {
1021
+			$affectedBoards = array();
1022
+	} else {
1023
+			$affectedBoards = array($board => array(0, 0));
1024
+	}
968 1025
 
969 1026
 	// Do all the stickies...
970 1027
 	if (!empty($stickyCache))
@@ -1024,14 +1081,16 @@  discard block
 block discarded – undo
1024 1081
 		{
1025 1082
 			$to = $moveCache[1][$row['id_topic']];
1026 1083
 
1027
-			if (empty($to))
1028
-				continue;
1084
+			if (empty($to)) {
1085
+							continue;
1086
+			}
1029 1087
 
1030 1088
 			// Does this topic's board count the posts or not?
1031 1089
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1032 1090
 
1033
-			if (!isset($moveTos[$to]))
1034
-				$moveTos[$to] = array();
1091
+			if (!isset($moveTos[$to])) {
1092
+							$moveTos[$to] = array();
1093
+			}
1035 1094
 
1036 1095
 			$moveTos[$to][] = $row['id_topic'];
1037 1096
 
@@ -1045,8 +1104,9 @@  discard block
 block discarded – undo
1045 1104
 		require_once($sourcedir . '/MoveTopic.php');
1046 1105
 
1047 1106
 		// Do the actual moves...
1048
-		foreach ($moveTos as $to => $topics)
1049
-			moveTopics($topics, $to);
1107
+		foreach ($moveTos as $to => $topics) {
1108
+					moveTopics($topics, $to);
1109
+		}
1050 1110
 
1051 1111
 		// Does the post counts need to be updated?
1052 1112
 		if (!empty($moveTos))
@@ -1095,20 +1155,23 @@  discard block
 block discarded – undo
1095 1155
 
1096 1156
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1097 1157
 				{
1098
-					if (!isset($members[$row['id_member']]))
1099
-						$members[$row['id_member']] = 0;
1158
+					if (!isset($members[$row['id_member']])) {
1159
+											$members[$row['id_member']] = 0;
1160
+					}
1100 1161
 
1101
-					if ($topicRecounts[$row['id_topic']] === '+')
1102
-						$members[$row['id_member']] += 1;
1103
-					else
1104
-						$members[$row['id_member']] -= 1;
1162
+					if ($topicRecounts[$row['id_topic']] === '+') {
1163
+											$members[$row['id_member']] += 1;
1164
+					} else {
1165
+											$members[$row['id_member']] -= 1;
1166
+					}
1105 1167
 				}
1106 1168
 
1107 1169
 				$smcFunc['db_free_result']($request);
1108 1170
 
1109 1171
 				// And now update them member's post counts
1110
-				foreach ($members as $id_member => $post_adj)
1111
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1172
+				foreach ($members as $id_member => $post_adj) {
1173
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1174
+				}
1112 1175
 			}
1113 1176
 		}
1114 1177
 	}
@@ -1187,8 +1250,9 @@  discard block
 block discarded – undo
1187 1250
 			approveTopics($approveCache);
1188 1251
 
1189 1252
 			// Time for some logging!
1190
-			foreach ($approveCache as $topic)
1191
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1253
+			foreach ($approveCache as $topic) {
1254
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1255
+			}
1192 1256
 		}
1193 1257
 	}
1194 1258
 
@@ -1223,8 +1287,7 @@  discard block
 block discarded – undo
1223 1287
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1224 1288
 			}
1225 1289
 			$smcFunc['db_free_result']($result);
1226
-		}
1227
-		else
1290
+		} else
1228 1291
 		{
1229 1292
 			$result = $smcFunc['db_query']('', '
1230 1293
 				SELECT id_topic, locked, id_board
@@ -1274,13 +1337,15 @@  discard block
 block discarded – undo
1274 1337
 			)
1275 1338
 		);
1276 1339
 		$logged_topics = array();
1277
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1278
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1340
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1341
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1342
+		}
1279 1343
 		$smcFunc['db_free_result']($request);
1280 1344
 
1281 1345
 		$markArray = array();
1282
-		foreach ($markCache as $topic)
1283
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1346
+		foreach ($markCache as $topic) {
1347
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1348
+		}
1284 1349
 
1285 1350
 		$smcFunc['db_insert']('replace',
1286 1351
 			'{db_prefix}log_topics',
@@ -1293,8 +1358,9 @@  discard block
 block discarded – undo
1293 1358
 	foreach ($moveCache as $topic)
1294 1359
 	{
1295 1360
 		// Didn't actually move anything!
1296
-		if (!isset($topic[0]))
1297
-			break;
1361
+		if (!isset($topic[0])) {
1362
+					break;
1363
+		}
1298 1364
 
1299 1365
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1300 1366
 		sendNotifications($topic[0], 'move');
@@ -1316,8 +1382,9 @@  discard block
 block discarded – undo
1316 1382
 		'calendar_updated' => time(),
1317 1383
 	));
1318 1384
 
1319
-	if (!empty($affectedBoards))
1320
-		updateLastMessages(array_keys($affectedBoards));
1385
+	if (!empty($affectedBoards)) {
1386
+			updateLastMessages(array_keys($affectedBoards));
1387
+	}
1321 1388
 
1322 1389
 	redirectexit($redirect_url);
1323 1390
 }
Please login to merge, or discard this patch.
other/install.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1697,8 +1697,7 @@  discard block
 block discarded – undo
1697 1697
 	updateStats('topic');
1698 1698
 
1699 1699
 	// This function is needed to do the updateStats('subject') call.
1700
-	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1701
-		function($string){
1700
+	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1702 1701
 			global $sourcedir;
1703 1702
 			if (function_exists('mb_strtolower'))
1704 1703
 				return mb_strtolower($string, 'UTF-8');
@@ -1767,7 +1766,7 @@  discard block
 block discarded – undo
1767 1766
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1768 1767
 		{
1769 1768
 			// Set the ten lines to nothing.
1770
-			for ($j=0; $j < 10; $j++)
1769
+			for ($j = 0; $j < 10; $j++)
1771 1770
 				$settingsArray[$i++] = '';
1772 1771
 
1773 1772
 			continue;
Please login to merge, or discard this patch.
Braces   +470 added lines, -350 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		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')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} 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') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -313,10 +325,11 @@  discard block
 block discarded – undo
313 325
 	}
314 326
 
315 327
 	// Override the language file?
316
-	if (isset($_GET['lang_file']))
317
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
318
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
319
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
328
+	if (isset($_GET['lang_file'])) {
329
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
331
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
332
+	}
320 333
 
321 334
 	// Make sure it exists, if it doesn't reset it.
322 335
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -325,8 +338,9 @@  discard block
 block discarded – undo
325 338
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
326 339
 
327 340
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
328
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
329
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
341
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
342
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
343
+		}
330 344
 	}
331 345
 
332 346
 	// And now include the actual language file itself.
@@ -343,15 +357,18 @@  discard block
 block discarded – undo
343 357
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
344 358
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
345 359
 
346
-	if (empty($sourcedir))
347
-		$sourcedir = dirname(__FILE__) . '/Sources';
360
+	if (empty($sourcedir)) {
361
+			$sourcedir = dirname(__FILE__) . '/Sources';
362
+	}
348 363
 
349 364
 	// Need this to check whether we need the database password.
350 365
 	require(dirname(__FILE__) . '/Settings.php');
351
-	if (!defined('SMF'))
352
-		define('SMF', 1);
353
-	if (empty($smcFunc))
354
-		$smcFunc = array();
366
+	if (!defined('SMF')) {
367
+			define('SMF', 1);
368
+	}
369
+	if (empty($smcFunc)) {
370
+			$smcFunc = array();
371
+	}
355 372
 
356 373
 	$modSettings['disableQueryCheck'] = true;
357 374
 
@@ -359,8 +376,9 @@  discard block
 block discarded – undo
359 376
 	if (!$db_connection)
360 377
 	{
361 378
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
362
-		if (version_compare(PHP_VERSION, '5', '<'))
363
-			require_once($sourcedir . '/Subs-Compat.php');
379
+		if (version_compare(PHP_VERSION, '5', '<')) {
380
+					require_once($sourcedir . '/Subs-Compat.php');
381
+		}
364 382
 
365 383
 		$db_options = array('persist' => $db_persist);
366 384
 		$port = '';
@@ -371,19 +389,20 @@  discard block
 block discarded – undo
371 389
 			if ($db_type == 'mysql')
372 390
 			{
373 391
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
374
-			}
375
-			elseif ($db_type == 'postgresql')
392
+			} elseif ($db_type == 'postgresql')
376 393
 			{
377 394
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
378 395
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
379 396
 			}
380 397
 		}
381 398
 
382
-		if (!empty($port))
383
-			$db_options['port'] = $port;
399
+		if (!empty($port)) {
400
+					$db_options['port'] = $port;
401
+		}
384 402
 
385
-		if (!$db_connection)
386
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
403
+		if (!$db_connection) {
404
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
405
+		}
387 406
 	}
388 407
 }
389 408
 
@@ -411,8 +430,9 @@  discard block
 block discarded – undo
411 430
 		// @todo REMOVE THIS!!
412 431
 		else
413 432
 		{
414
-			if (function_exists('doStep' . $_GET['step']))
415
-				call_user_func('doStep' . $_GET['step']);
433
+			if (function_exists('doStep' . $_GET['step'])) {
434
+							call_user_func('doStep' . $_GET['step']);
435
+			}
416 436
 		}
417 437
 		// Show the footer.
418 438
 		template_install_below();
@@ -430,8 +450,9 @@  discard block
 block discarded – undo
430 450
 	$incontext['sub_template'] = 'welcome_message';
431 451
 
432 452
 	// Done the submission?
433
-	if (isset($_POST['contbutt']))
434
-		return true;
453
+	if (isset($_POST['contbutt'])) {
454
+			return true;
455
+	}
435 456
 
436 457
 	// See if we think they have already installed it?
437 458
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -439,14 +460,17 @@  discard block
 block discarded – undo
439 460
 		$probably_installed = 0;
440 461
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
441 462
 		{
442
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
443
-				$probably_installed++;
444
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
445
-				$probably_installed++;
463
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
464
+							$probably_installed++;
465
+			}
466
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
467
+							$probably_installed++;
468
+			}
446 469
 		}
447 470
 
448
-		if ($probably_installed == 2)
449
-			$incontext['warning'] = $txt['error_already_installed'];
471
+		if ($probably_installed == 2) {
472
+					$incontext['warning'] = $txt['error_already_installed'];
473
+		}
450 474
 	}
451 475
 
452 476
 	// Is some database support even compiled in?
@@ -461,45 +485,54 @@  discard block
 block discarded – undo
461 485
 				$databases[$key]['supported'] = false;
462 486
 				$notFoundSQLFile = true;
463 487
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
488
+			} else {
489
+							$incontext['supported_databases'][] = $db;
464 490
 			}
465
-			else
466
-				$incontext['supported_databases'][] = $db;
467 491
 		}
468 492
 	}
469 493
 
470 494
 	// Check the PHP version.
471
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
472
-		$error = 'error_php_too_low';
495
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
496
+			$error = 'error_php_too_low';
497
+	}
473 498
 	// Make sure we have a supported database
474
-	elseif (empty($incontext['supported_databases']))
475
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
499
+	elseif (empty($incontext['supported_databases'])) {
500
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
501
+	}
476 502
 	// How about session support?  Some crazy sysadmin remove it?
477
-	elseif (!function_exists('session_start'))
478
-		$error = 'error_session_missing';
503
+	elseif (!function_exists('session_start')) {
504
+			$error = 'error_session_missing';
505
+	}
479 506
 	// Make sure they uploaded all the files.
480
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
481
-		$error = 'error_missing_files';
507
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
508
+			$error = 'error_missing_files';
509
+	}
482 510
 	// Very simple check on the session.save_path for Windows.
483 511
 	// @todo Move this down later if they don't use database-driven sessions?
484
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
485
-		$error = 'error_session_save_path';
512
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
513
+			$error = 'error_session_save_path';
514
+	}
486 515
 
487 516
 	// Since each of the three messages would look the same, anyway...
488
-	if (isset($error))
489
-		$incontext['error'] = $txt[$error];
517
+	if (isset($error)) {
518
+			$incontext['error'] = $txt[$error];
519
+	}
490 520
 
491 521
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
492
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
493
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
522
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
523
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
524
+	}
494 525
 
495 526
 	// Confirm mbstring is loaded...
496
-	if (!extension_loaded('mbstring'))
497
-		$incontext['error'] = $txt['install_no_mbstring'];
527
+	if (!extension_loaded('mbstring')) {
528
+			$incontext['error'] = $txt['install_no_mbstring'];
529
+	}
498 530
 
499 531
 	// Check for https stream support.
500 532
 	$supported_streams = stream_get_wrappers();
501
-	if (!in_array('https', $supported_streams))
502
-		$incontext['warning'] = $txt['install_no_https'];
533
+	if (!in_array('https', $supported_streams)) {
534
+			$incontext['warning'] = $txt['install_no_https'];
535
+	}
503 536
 
504 537
 	return false;
505 538
 }
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 		'Settings_bak.php',
525 558
 	);
526 559
 
527
-	foreach ($incontext['detected_languages'] as $lang => $temp)
528
-		$extra_files[] = 'Themes/default/languages/' . $lang;
560
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
561
+			$extra_files[] = 'Themes/default/languages/' . $lang;
562
+	}
529 563
 
530 564
 	// With mod_security installed, we could attempt to fix it with .htaccess.
531
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
532
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
565
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
566
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
567
+	}
533 568
 
534 569
 	$failed_files = array();
535 570
 
@@ -541,20 +576,23 @@  discard block
 block discarded – undo
541 576
 		foreach ($writable_files as $file)
542 577
 		{
543 578
 			// Some files won't exist, try to address up front
544
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
545
-				@touch(dirname(__FILE__) . '/' . $file);
579
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
580
+							@touch(dirname(__FILE__) . '/' . $file);
581
+			}
546 582
 			// NOW do the writable check...
547 583
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
548 584
 			{
549 585
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
550 586
 
551 587
 				// Well, 755 hopefully worked... if not, try 777.
552
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
553
-					$failed_files[] = $file;
588
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
589
+									$failed_files[] = $file;
590
+				}
554 591
 			}
555 592
 		}
556
-		foreach ($extra_files as $file)
557
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
593
+		foreach ($extra_files as $file) {
594
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
595
+		}
558 596
 	}
559 597
 	// Windows is trickier.  Let's try opening for r+...
560 598
 	else
@@ -564,30 +602,35 @@  discard block
 block discarded – undo
564 602
 		foreach ($writable_files as $file)
565 603
 		{
566 604
 			// Folders can't be opened for write... but the index.php in them can ;)
567
-			if (is_dir(dirname(__FILE__) . '/' . $file))
568
-				$file .= '/index.php';
605
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
606
+							$file .= '/index.php';
607
+			}
569 608
 
570 609
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
571 610
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
572 611
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
573 612
 
574 613
 			// Hmm, okay, try just for write in that case...
575
-			if (!is_resource($fp))
576
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
614
+			if (!is_resource($fp)) {
615
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
616
+			}
577 617
 
578
-			if (!is_resource($fp))
579
-				$failed_files[] = $file;
618
+			if (!is_resource($fp)) {
619
+							$failed_files[] = $file;
620
+			}
580 621
 
581 622
 			@fclose($fp);
582 623
 		}
583
-		foreach ($extra_files as $file)
584
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
624
+		foreach ($extra_files as $file) {
625
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
626
+		}
585 627
 	}
586 628
 
587 629
 	$failure = count($failed_files) >= 1;
588 630
 
589
-	if (!isset($_SERVER))
590
-		return !$failure;
631
+	if (!isset($_SERVER)) {
632
+			return !$failure;
633
+	}
591 634
 
592 635
 	// Put the list into context.
593 636
 	$incontext['failed_files'] = $failed_files;
@@ -635,19 +678,23 @@  discard block
 block discarded – undo
635 678
 
636 679
 		if (!isset($ftp) || $ftp->error !== false)
637 680
 		{
638
-			if (!isset($ftp))
639
-				$ftp = new ftp_connection(null);
681
+			if (!isset($ftp)) {
682
+							$ftp = new ftp_connection(null);
683
+			}
640 684
 			// Save the error so we can mess with listing...
641
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
642
-				$incontext['ftp_errors'][] = $ftp->last_message;
685
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
686
+							$incontext['ftp_errors'][] = $ftp->last_message;
687
+			}
643 688
 
644 689
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
645 690
 
646
-			if (empty($_POST['ftp_path']) && $found_path)
647
-				$_POST['ftp_path'] = $detect_path;
691
+			if (empty($_POST['ftp_path']) && $found_path) {
692
+							$_POST['ftp_path'] = $detect_path;
693
+			}
648 694
 
649
-			if (!isset($_POST['ftp_username']))
650
-				$_POST['ftp_username'] = $username;
695
+			if (!isset($_POST['ftp_username'])) {
696
+							$_POST['ftp_username'] = $username;
697
+			}
651 698
 
652 699
 			// Set the username etc, into context.
653 700
 			$incontext['ftp'] = array(
@@ -659,8 +706,7 @@  discard block
 block discarded – undo
659 706
 			);
660 707
 
661 708
 			return false;
662
-		}
663
-		else
709
+		} else
664 710
 		{
665 711
 			$_SESSION['installer_temp_ftp'] = array(
666 712
 				'server' => $_POST['ftp_server'],
@@ -674,10 +720,12 @@  discard block
 block discarded – undo
674 720
 
675 721
 			foreach ($failed_files as $file)
676 722
 			{
677
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
678
-					$ftp->chmod($file, 0755);
679
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
680
-					$ftp->chmod($file, 0777);
723
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
724
+									$ftp->chmod($file, 0755);
725
+				}
726
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
727
+									$ftp->chmod($file, 0777);
728
+				}
681 729
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
682 730
 				{
683 731
 					$failed_files_updated[] = $file;
@@ -733,15 +781,17 @@  discard block
 block discarded – undo
733 781
 
734 782
 			if (!$foundOne)
735 783
 			{
736
-				if (isset($db['default_host']))
737
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
784
+				if (isset($db['default_host'])) {
785
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
786
+				}
738 787
 				if (isset($db['default_user']))
739 788
 				{
740 789
 					$incontext['db']['user'] = ini_get($db['default_user']);
741 790
 					$incontext['db']['name'] = ini_get($db['default_user']);
742 791
 				}
743
-				if (isset($db['default_password']))
744
-					$incontext['db']['pass'] = ini_get($db['default_password']);
792
+				if (isset($db['default_password'])) {
793
+									$incontext['db']['pass'] = ini_get($db['default_password']);
794
+				}
745 795
 
746 796
 				// For simplicity and less confusion, leave the port blank by default
747 797
 				$incontext['db']['port'] = '';
@@ -760,10 +810,10 @@  discard block
 block discarded – undo
760 810
 		$incontext['db']['server'] = $_POST['db_server'];
761 811
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
762 812
 
763
-		if (!empty($_POST['db_port']))
764
-			$incontext['db']['port'] = $_POST['db_port'];
765
-	}
766
-	else
813
+		if (!empty($_POST['db_port'])) {
814
+					$incontext['db']['port'] = $_POST['db_port'];
815
+		}
816
+	} else
767 817
 	{
768 818
 		$incontext['db']['prefix'] = 'smf_';
769 819
 	}
@@ -799,10 +849,11 @@  discard block
 block discarded – undo
799 849
 		if (!empty($_POST['db_port']))
800 850
 		{
801 851
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
802
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
803
-				$vars['db_port'] = (int) $_POST['db_port'];
804
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
805
-				$vars['db_port'] = (int) $_POST['db_port'];
852
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
853
+							$vars['db_port'] = (int) $_POST['db_port'];
854
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
855
+							$vars['db_port'] = (int) $_POST['db_port'];
856
+			}
806 857
 		}
807 858
 
808 859
 		// God I hope it saved!
@@ -815,8 +866,9 @@  discard block
 block discarded – undo
815 866
 		// Make sure it works.
816 867
 		require(dirname(__FILE__) . '/Settings.php');
817 868
 
818
-		if (empty($sourcedir))
819
-			$sourcedir = dirname(__FILE__) . '/Sources';
869
+		if (empty($sourcedir)) {
870
+					$sourcedir = dirname(__FILE__) . '/Sources';
871
+		}
820 872
 
821 873
 		// Better find the database file!
822 874
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -826,18 +878,21 @@  discard block
 block discarded – undo
826 878
 		}
827 879
 
828 880
 		// Now include it for database functions!
829
-		if (!defined('SMF'))
830
-			define('SMF', 1);
881
+		if (!defined('SMF')) {
882
+					define('SMF', 1);
883
+		}
831 884
 
832 885
 		$modSettings['disableQueryCheck'] = true;
833
-		if (empty($smcFunc))
834
-			$smcFunc = array();
886
+		if (empty($smcFunc)) {
887
+					$smcFunc = array();
888
+		}
835 889
 
836 890
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
837 891
 
838 892
 		// What - running PHP4? The shame!
839
-		if (version_compare(PHP_VERSION, '5', '<'))
840
-			require_once($sourcedir . '/Subs-Compat.php');
893
+		if (version_compare(PHP_VERSION, '5', '<')) {
894
+					require_once($sourcedir . '/Subs-Compat.php');
895
+		}
841 896
 
842 897
 		// Attempt a connection.
843 898
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -925,12 +980,14 @@  discard block
 block discarded – undo
925 980
 	$incontext['page_title'] = $txt['install_settings'];
926 981
 
927 982
 	// Let's see if we got the database type correct.
928
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
929
-		$db_type = $_POST['db_type'];
983
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
984
+			$db_type = $_POST['db_type'];
985
+	}
930 986
 
931 987
 	// Else we'd better be able to get the connection.
932
-	else
933
-		load_database();
988
+	else {
989
+			load_database();
990
+	}
934 991
 
935 992
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
936 993
 
@@ -939,10 +996,11 @@  discard block
 block discarded – undo
939 996
 
940 997
 		$secure = false;
941 998
 
942
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
943
-			$secure = true;
944
-		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')
945
-			$secure = true;
999
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1000
+					$secure = true;
1001
+		} 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') {
1002
+					$secure = true;
1003
+		}
946 1004
 
947 1005
 	// Now, to put what we've learned together... and add a path.
948 1006
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -974,18 +1032,21 @@  discard block
 block discarded – undo
974 1032
 	// Submitting?
975 1033
 	if (isset($_POST['boardurl']))
976 1034
 	{
977
-		if (substr($_POST['boardurl'], -10) == '/index.php')
978
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
979
-		elseif (substr($_POST['boardurl'], -1) == '/')
980
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
981
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
982
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1035
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1036
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1037
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1038
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1039
+		}
1040
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1041
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1042
+		}
983 1043
 
984 1044
 		//Make sure boardurl is aligned with ssl setting
985
-		if (empty($_POST['force_ssl']))
986
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
987
-		else
988
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1045
+		if (empty($_POST['force_ssl'])) {
1046
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1047
+		} else {
1048
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1049
+		}
989 1050
 
990 1051
 		// Save these variables.
991 1052
 		$vars = array(
@@ -1024,10 +1085,10 @@  discard block
 block discarded – undo
1024 1085
 			{
1025 1086
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1026 1087
 				return false;
1027
-			}
1028
-			else
1029
-				// Set the character set here.
1088
+			} else {
1089
+							// Set the character set here.
1030 1090
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1091
+			}
1031 1092
 		}
1032 1093
 
1033 1094
 		// Good, skip on.
@@ -1047,8 +1108,9 @@  discard block
 block discarded – undo
1047 1108
 	$incontext['continue'] = 1;
1048 1109
 
1049 1110
 	// Already done?
1050
-	if (isset($_POST['pop_done']))
1051
-		return true;
1111
+	if (isset($_POST['pop_done'])) {
1112
+			return true;
1113
+	}
1052 1114
 
1053 1115
 	// Reload settings.
1054 1116
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1066,8 +1128,9 @@  discard block
 block discarded – undo
1066 1128
 	$modSettings = array();
1067 1129
 	if ($result !== false)
1068 1130
 	{
1069
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1070
-			$modSettings[$row['variable']] = $row['value'];
1131
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1132
+					$modSettings[$row['variable']] = $row['value'];
1133
+		}
1071 1134
 		$smcFunc['db_free_result']($result);
1072 1135
 
1073 1136
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1080,20 +1143,22 @@  discard block
 block discarded – undo
1080 1143
 	$modSettings['disableQueryCheck'] = true;
1081 1144
 
1082 1145
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1083
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1084
-		$smcFunc['db_query']('', '
1146
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1147
+			$smcFunc['db_query']('', '
1085 1148
 			SET NAMES {string:utf8}',
1086 1149
 			array(
1087 1150
 				'db_error_skip' => true,
1088 1151
 				'utf8' => 'utf8',
1089 1152
 			)
1090 1153
 		);
1154
+	}
1091 1155
 
1092 1156
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1093
-	if (substr(__DIR__, -1) == '\\')
1094
-		$attachdir = __DIR__ . 'attachments';
1095
-	else
1096
-		$attachdir = __DIR__ . '/attachments';
1157
+	if (substr(__DIR__, -1) == '\\') {
1158
+			$attachdir = __DIR__ . 'attachments';
1159
+	} else {
1160
+			$attachdir = __DIR__ . '/attachments';
1161
+	}
1097 1162
 
1098 1163
 	$replaces = array(
1099 1164
 		'{$db_prefix}' => $db_prefix,
@@ -1110,8 +1175,9 @@  discard block
 block discarded – undo
1110 1175
 
1111 1176
 	foreach ($txt as $key => $value)
1112 1177
 	{
1113
-		if (substr($key, 0, 8) == 'default_')
1114
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1178
+		if (substr($key, 0, 8) == 'default_') {
1179
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1180
+		}
1115 1181
 	}
1116 1182
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1117 1183
 
@@ -1126,8 +1192,9 @@  discard block
 block discarded – undo
1126 1192
 
1127 1193
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1128 1194
 		{
1129
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1130
-				$engines[] = $row['Engine'];
1195
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1196
+							$engines[] = $row['Engine'];
1197
+			}
1131 1198
 		}
1132 1199
 
1133 1200
 		// Done with this now
@@ -1151,8 +1218,7 @@  discard block
 block discarded – undo
1151 1218
 			$replaces['START TRANSACTION;'] = '';
1152 1219
 			$replaces['COMMIT;'] = '';
1153 1220
 		}
1154
-	}
1155
-	else
1221
+	} else
1156 1222
 	{
1157 1223
 		$has_innodb = false;
1158 1224
 	}
@@ -1174,21 +1240,24 @@  discard block
 block discarded – undo
1174 1240
 	foreach ($sql_lines as $count => $line)
1175 1241
 	{
1176 1242
 		// No comments allowed!
1177
-		if (substr(trim($line), 0, 1) != '#')
1178
-			$current_statement .= "\n" . rtrim($line);
1243
+		if (substr(trim($line), 0, 1) != '#') {
1244
+					$current_statement .= "\n" . rtrim($line);
1245
+		}
1179 1246
 
1180 1247
 		// Is this the end of the query string?
1181
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1182
-			continue;
1248
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1249
+					continue;
1250
+		}
1183 1251
 
1184 1252
 		// Does this table already exist?  If so, don't insert more data into it!
1185 1253
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1186 1254
 		{
1187 1255
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1188
-			if (!empty($matches[0]))
1189
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1190
-			else
1191
-				$incontext['sql_results']['insert_dups']++;
1256
+			if (!empty($matches[0])) {
1257
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1258
+			} else {
1259
+							$incontext['sql_results']['insert_dups']++;
1260
+			}
1192 1261
 
1193 1262
 			$current_statement = '';
1194 1263
 			continue;
@@ -1197,8 +1266,9 @@  discard block
 block discarded – undo
1197 1266
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1198 1267
 		{
1199 1268
 			// Use the appropriate function based on the DB type
1200
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1201
-				$db_errorno = $db_type . '_errno';
1269
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1270
+							$db_errorno = $db_type . '_errno';
1271
+			}
1202 1272
 
1203 1273
 			// Error 1050: Table already exists!
1204 1274
 			// @todo Needs to be made better!
@@ -1213,18 +1283,18 @@  discard block
 block discarded – undo
1213 1283
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1214 1284
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1215 1285
 			}
1216
-		}
1217
-		else
1286
+		} else
1218 1287
 		{
1219
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1220
-				$incontext['sql_results']['tables']++;
1221
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1288
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1289
+							$incontext['sql_results']['tables']++;
1290
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1222 1291
 			{
1223 1292
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1224
-				if (!empty($matches[0]))
1225
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1226
-				else
1227
-					$incontext['sql_results']['inserts']++;
1293
+				if (!empty($matches[0])) {
1294
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1295
+				} else {
1296
+									$incontext['sql_results']['inserts']++;
1297
+				}
1228 1298
 			}
1229 1299
 		}
1230 1300
 
@@ -1237,15 +1307,17 @@  discard block
 block discarded – undo
1237 1307
 	// Sort out the context for the SQL.
1238 1308
 	foreach ($incontext['sql_results'] as $key => $number)
1239 1309
 	{
1240
-		if ($number == 0)
1241
-			unset($incontext['sql_results'][$key]);
1242
-		else
1243
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1310
+		if ($number == 0) {
1311
+					unset($incontext['sql_results'][$key]);
1312
+		} else {
1313
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1314
+		}
1244 1315
 	}
1245 1316
 
1246 1317
 	// Make sure UTF will be used globally.
1247
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1248
-		$newSettings[] = array('global_character_set', 'UTF-8');
1318
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1319
+			$newSettings[] = array('global_character_set', 'UTF-8');
1320
+	}
1249 1321
 
1250 1322
 	// Auto-detect local & global cookie settings
1251 1323
 	$url_parts = parse_url($boardurl);
@@ -1274,15 +1346,19 @@  discard block
 block discarded – undo
1274 1346
 
1275 1347
 		// Look for subfolder, if found, set localCookie
1276 1348
 		// Checking for len > 1 ensures you don't have just a slash...
1277
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1278
-			$localCookies = '1';
1349
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1350
+					$localCookies = '1';
1351
+		}
1279 1352
 
1280
-		if (isset($globalCookies))
1281
-			$newSettings[] = array('globalCookies', $globalCookies);
1282
-		if (isset($globalCookiesDomain))
1283
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1284
-		if (isset($localCookies))
1285
-			$newSettings[] = array('localCookies', $localCookies);
1353
+		if (isset($globalCookies)) {
1354
+					$newSettings[] = array('globalCookies', $globalCookies);
1355
+		}
1356
+		if (isset($globalCookiesDomain)) {
1357
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1358
+		}
1359
+		if (isset($localCookies)) {
1360
+					$newSettings[] = array('localCookies', $localCookies);
1361
+		}
1286 1362
 	}
1287 1363
 
1288 1364
 	// Are we allowing stat collection?
@@ -1300,16 +1376,17 @@  discard block
 block discarded – undo
1300 1376
 			fwrite($fp, $out);
1301 1377
 
1302 1378
 			$return_data = '';
1303
-			while (!feof($fp))
1304
-				$return_data .= fgets($fp, 128);
1379
+			while (!feof($fp)) {
1380
+							$return_data .= fgets($fp, 128);
1381
+			}
1305 1382
 
1306 1383
 			fclose($fp);
1307 1384
 
1308 1385
 			// Get the unique site ID.
1309 1386
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1310 1387
 
1311
-			if (!empty($ID[1]))
1312
-				$smcFunc['db_insert']('replace',
1388
+			if (!empty($ID[1])) {
1389
+							$smcFunc['db_insert']('replace',
1313 1390
 					$db_prefix . 'settings',
1314 1391
 					array('variable' => 'string', 'value' => 'string'),
1315 1392
 					array(
@@ -1318,11 +1395,12 @@  discard block
 block discarded – undo
1318 1395
 					),
1319 1396
 					array('variable')
1320 1397
 				);
1398
+			}
1321 1399
 		}
1322 1400
 	}
1323 1401
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1324
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1325
-		$smcFunc['db_query']('', '
1402
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1403
+			$smcFunc['db_query']('', '
1326 1404
 			DELETE FROM {db_prefix}settings
1327 1405
 			WHERE variable = {string:enable_sm_stats}',
1328 1406
 			array(
@@ -1330,20 +1408,23 @@  discard block
 block discarded – undo
1330 1408
 				'db_error_skip' => true,
1331 1409
 			)
1332 1410
 		);
1411
+	}
1333 1412
 
1334 1413
 	// Are we enabling SSL?
1335
-	if (!empty($_POST['force_ssl']))
1336
-		$newSettings[] = array('force_ssl', 1);
1414
+	if (!empty($_POST['force_ssl'])) {
1415
+			$newSettings[] = array('force_ssl', 1);
1416
+	}
1337 1417
 
1338 1418
 	// Setting a timezone is required.
1339 1419
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1340 1420
 	{
1341 1421
 		// Get PHP's default timezone, if set
1342 1422
 		$ini_tz = ini_get('date.timezone');
1343
-		if (!empty($ini_tz))
1344
-			$timezone_id = $ini_tz;
1345
-		else
1346
-			$timezone_id = '';
1423
+		if (!empty($ini_tz)) {
1424
+					$timezone_id = $ini_tz;
1425
+		} else {
1426
+					$timezone_id = '';
1427
+		}
1347 1428
 
1348 1429
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1349 1430
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1352,8 +1433,9 @@  discard block
 block discarded – undo
1352 1433
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1353 1434
 		}
1354 1435
 
1355
-		if (date_default_timezone_set($timezone_id))
1356
-			$newSettings[] = array('default_timezone', $timezone_id);
1436
+		if (date_default_timezone_set($timezone_id)) {
1437
+					$newSettings[] = array('default_timezone', $timezone_id);
1438
+		}
1357 1439
 	}
1358 1440
 
1359 1441
 	if (!empty($newSettings))
@@ -1384,16 +1466,18 @@  discard block
 block discarded – undo
1384 1466
 	}
1385 1467
 
1386 1468
 	// MySQL specific stuff
1387
-	if (substr($db_type, 0, 5) != 'mysql')
1388
-		return false;
1469
+	if (substr($db_type, 0, 5) != 'mysql') {
1470
+			return false;
1471
+	}
1389 1472
 
1390 1473
 	// Find database user privileges.
1391 1474
 	$privs = array();
1392 1475
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1393 1476
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1394 1477
 	{
1395
-		if ($row['Privilege'] == 'Alter')
1396
-			$privs[] = $row['Privilege'];
1478
+		if ($row['Privilege'] == 'Alter') {
1479
+					$privs[] = $row['Privilege'];
1480
+		}
1397 1481
 	}
1398 1482
 	$smcFunc['db_free_result']($get_privs);
1399 1483
 
@@ -1423,8 +1507,9 @@  discard block
 block discarded – undo
1423 1507
 	$incontext['continue'] = 1;
1424 1508
 
1425 1509
 	// Skipping?
1426
-	if (!empty($_POST['skip']))
1427
-		return true;
1510
+	if (!empty($_POST['skip'])) {
1511
+			return true;
1512
+	}
1428 1513
 
1429 1514
 	// Need this to check whether we need the database password.
1430 1515
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1441,18 +1526,22 @@  discard block
 block discarded – undo
1441 1526
 	// We need this to properly hash the password for Admin
1442 1527
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1443 1528
 			global $sourcedir;
1444
-			if (function_exists('mb_strtolower'))
1445
-				return mb_strtolower($string, 'UTF-8');
1529
+			if (function_exists('mb_strtolower')) {
1530
+							return mb_strtolower($string, 'UTF-8');
1531
+			}
1446 1532
 			require_once($sourcedir . '/Subs-Charset.php');
1447 1533
 			return utf8_strtolower($string);
1448 1534
 		};
1449 1535
 
1450
-	if (!isset($_POST['username']))
1451
-		$_POST['username'] = '';
1452
-	if (!isset($_POST['email']))
1453
-		$_POST['email'] = '';
1454
-	if (!isset($_POST['server_email']))
1455
-		$_POST['server_email'] = '';
1536
+	if (!isset($_POST['username'])) {
1537
+			$_POST['username'] = '';
1538
+	}
1539
+	if (!isset($_POST['email'])) {
1540
+			$_POST['email'] = '';
1541
+	}
1542
+	if (!isset($_POST['server_email'])) {
1543
+			$_POST['server_email'] = '';
1544
+	}
1456 1545
 
1457 1546
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1458 1547
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1471,8 +1560,9 @@  discard block
 block discarded – undo
1471 1560
 			'admin_group' => 1,
1472 1561
 		)
1473 1562
 	);
1474
-	if ($smcFunc['db_num_rows']($request) != 0)
1475
-		$incontext['skip'] = 1;
1563
+	if ($smcFunc['db_num_rows']($request) != 0) {
1564
+			$incontext['skip'] = 1;
1565
+	}
1476 1566
 	$smcFunc['db_free_result']($request);
1477 1567
 
1478 1568
 	// Trying to create an account?
@@ -1503,8 +1593,9 @@  discard block
 block discarded – undo
1503 1593
 		}
1504 1594
 
1505 1595
 		// Update the webmaster's email?
1506
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1507
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1596
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1597
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1598
+		}
1508 1599
 
1509 1600
 		// Work out whether we're going to have dodgy characters and remove them.
1510 1601
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1527,32 +1618,27 @@  discard block
 block discarded – undo
1527 1618
 			$smcFunc['db_free_result']($result);
1528 1619
 
1529 1620
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1530
-		}
1531
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1621
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1532 1622
 		{
1533 1623
 			// Try the previous step again.
1534 1624
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1535 1625
 			return false;
1536
-		}
1537
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1626
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1538 1627
 		{
1539 1628
 			// Try the previous step again.
1540 1629
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1541 1630
 			return false;
1542
-		}
1543
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1631
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1544 1632
 		{
1545 1633
 			// One step back, this time fill out a proper admin email address.
1546 1634
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1547 1635
 			return false;
1548
-		}
1549
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1636
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1550 1637
 		{
1551 1638
 			// One step back, this time fill out a proper admin email address.
1552 1639
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1553 1640
 			return false;
1554
-		}
1555
-		elseif ($_POST['username'] != '')
1641
+		} elseif ($_POST['username'] != '')
1556 1642
 		{
1557 1643
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1558 1644
 
@@ -1620,17 +1706,19 @@  discard block
 block discarded – undo
1620 1706
 	reloadSettings();
1621 1707
 
1622 1708
 	// Bring a warning over.
1623
-	if (!empty($incontext['account_existed']))
1624
-		$incontext['warning'] = $incontext['account_existed'];
1709
+	if (!empty($incontext['account_existed'])) {
1710
+			$incontext['warning'] = $incontext['account_existed'];
1711
+	}
1625 1712
 
1626
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1627
-		$smcFunc['db_query']('', '
1713
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1714
+			$smcFunc['db_query']('', '
1628 1715
 			SET NAMES {string:db_character_set}',
1629 1716
 			array(
1630 1717
 				'db_character_set' => $db_character_set,
1631 1718
 				'db_error_skip' => true,
1632 1719
 			)
1633 1720
 		);
1721
+	}
1634 1722
 
1635 1723
 	// As track stats is by default enabled let's add some activity.
1636 1724
 	$smcFunc['db_insert']('ignore',
@@ -1651,14 +1739,16 @@  discard block
 block discarded – undo
1651 1739
 	// Only proceed if we can load the data.
1652 1740
 	if ($request)
1653 1741
 	{
1654
-		while ($row = $smcFunc['db_fetch_row']($request))
1655
-			$modSettings[$row[0]] = $row[1];
1742
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1743
+					$modSettings[$row[0]] = $row[1];
1744
+		}
1656 1745
 		$smcFunc['db_free_result']($request);
1657 1746
 	}
1658 1747
 
1659 1748
 	// Automatically log them in ;)
1660
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1661
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1749
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1750
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1751
+	}
1662 1752
 
1663 1753
 	$result = $smcFunc['db_query']('', '
1664 1754
 		SELECT value
@@ -1669,13 +1759,14 @@  discard block
 block discarded – undo
1669 1759
 			'db_error_skip' => true,
1670 1760
 		)
1671 1761
 	);
1672
-	if ($smcFunc['db_num_rows']($result) != 0)
1673
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1762
+	if ($smcFunc['db_num_rows']($result) != 0) {
1763
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1764
+	}
1674 1765
 	$smcFunc['db_free_result']($result);
1675 1766
 
1676
-	if (empty($db_sessions))
1677
-		$_SESSION['admin_time'] = time();
1678
-	else
1767
+	if (empty($db_sessions)) {
1768
+			$_SESSION['admin_time'] = time();
1769
+	} else
1679 1770
 	{
1680 1771
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1681 1772
 
@@ -1699,8 +1790,9 @@  discard block
 block discarded – undo
1699 1790
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1700 1791
 		function($string){
1701 1792
 			global $sourcedir;
1702
-			if (function_exists('mb_strtolower'))
1703
-				return mb_strtolower($string, 'UTF-8');
1793
+			if (function_exists('mb_strtolower')) {
1794
+							return mb_strtolower($string, 'UTF-8');
1795
+			}
1704 1796
 			require_once($sourcedir . '/Subs-Charset.php');
1705 1797
 			return utf8_strtolower($string);
1706 1798
 		};
@@ -1716,8 +1808,9 @@  discard block
 block discarded – undo
1716 1808
 		)
1717 1809
 	);
1718 1810
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1719
-	if ($smcFunc['db_num_rows']($request) > 0)
1720
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1811
+	if ($smcFunc['db_num_rows']($request) > 0) {
1812
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1813
+	}
1721 1814
 	$smcFunc['db_free_result']($request);
1722 1815
 
1723 1816
 	// Now is the perfect time to fetch the SM files.
@@ -1736,8 +1829,9 @@  discard block
 block discarded – undo
1736 1829
 
1737 1830
 	// Check if we need some stupid MySQL fix.
1738 1831
 	$server_version = $smcFunc['db_server_info']();
1739
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1740
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1832
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1833
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1834
+	}
1741 1835
 
1742 1836
 	// Some final context for the template.
1743 1837
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1757,8 +1851,9 @@  discard block
 block discarded – undo
1757 1851
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1758 1852
 
1759 1853
 	// @todo Do we just want to read the file in clean, and split it this way always?
1760
-	if (count($settingsArray) == 1)
1761
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1854
+	if (count($settingsArray) == 1) {
1855
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1856
+	}
1762 1857
 
1763 1858
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1764 1859
 	{
@@ -1766,25 +1861,29 @@  discard block
 block discarded – undo
1766 1861
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1767 1862
 		{
1768 1863
 			// Set the ten lines to nothing.
1769
-			for ($j=0; $j < 10; $j++)
1770
-				$settingsArray[$i++] = '';
1864
+			for ($j=0; $j < 10; $j++) {
1865
+							$settingsArray[$i++] = '';
1866
+			}
1771 1867
 
1772 1868
 			continue;
1773 1869
 		}
1774 1870
 
1775
-		if (trim($settingsArray[$i]) == '?' . '>')
1776
-			$settingsArray[$i] = '';
1871
+		if (trim($settingsArray[$i]) == '?' . '>') {
1872
+					$settingsArray[$i] = '';
1873
+		}
1777 1874
 
1778 1875
 		// Don't trim or bother with it if it's not a variable.
1779
-		if (substr($settingsArray[$i], 0, 1) != '$')
1780
-			continue;
1876
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1877
+					continue;
1878
+		}
1781 1879
 
1782 1880
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1783 1881
 
1784
-		foreach ($vars as $var => $val)
1785
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1882
+		foreach ($vars as $var => $val) {
1883
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1786 1884
 			{
1787 1885
 				$comment = strstr($settingsArray[$i], '#');
1886
+		}
1788 1887
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1789 1888
 				unset($vars[$var]);
1790 1889
 			}
@@ -1794,36 +1893,41 @@  discard block
 block discarded – undo
1794 1893
 	if (!empty($vars))
1795 1894
 	{
1796 1895
 		$settingsArray[$i++] = '';
1797
-		foreach ($vars as $var => $val)
1798
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1896
+		foreach ($vars as $var => $val) {
1897
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1898
+		}
1799 1899
 	}
1800 1900
 
1801 1901
 	// Blank out the file - done to fix a oddity with some servers.
1802 1902
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1803
-	if (!$fp)
1804
-		return false;
1903
+	if (!$fp) {
1904
+			return false;
1905
+	}
1805 1906
 	fclose($fp);
1806 1907
 
1807 1908
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1808 1909
 
1809 1910
 	// Gotta have one of these ;)
1810
-	if (trim($settingsArray[0]) != '<?php')
1811
-		fwrite($fp, "<?php\n");
1911
+	if (trim($settingsArray[0]) != '<?php') {
1912
+			fwrite($fp, "<?php\n");
1913
+	}
1812 1914
 
1813 1915
 	$lines = count($settingsArray);
1814 1916
 	for ($i = 0; $i < $lines - 1; $i++)
1815 1917
 	{
1816 1918
 		// Don't just write a bunch of blank lines.
1817
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1818
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1919
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1920
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1921
+		}
1819 1922
 	}
1820 1923
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1821 1924
 	fclose($fp);
1822 1925
 
1823 1926
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1824 1927
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1825
-	if (function_exists('opcache_invalidate'))
1826
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1928
+	if (function_exists('opcache_invalidate')) {
1929
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1930
+	}
1827 1931
 
1828 1932
 	return true;
1829 1933
 }
@@ -1833,10 +1937,11 @@  discard block
 block discarded – undo
1833 1937
 	global $cachedir;
1834 1938
 
1835 1939
 	// Write out the db_last_error file with the error timestamp
1836
-	if (!empty($cachedir) && is_writable($cachedir))
1837
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1838
-	else
1839
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1940
+	if (!empty($cachedir) && is_writable($cachedir)) {
1941
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1942
+	} else {
1943
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1944
+	}
1840 1945
 
1841 1946
 	return true;
1842 1947
 }
@@ -1853,9 +1958,9 @@  discard block
 block discarded – undo
1853 1958
 	SecFilterScanPOST Off
1854 1959
 </IfModule>';
1855 1960
 
1856
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1857
-		return true;
1858
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1961
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1962
+			return true;
1963
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1859 1964
 	{
1860 1965
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1861 1966
 
@@ -1867,29 +1972,28 @@  discard block
 block discarded – undo
1867 1972
 				fwrite($ht_handle, $htaccess_addition);
1868 1973
 				fclose($ht_handle);
1869 1974
 				return true;
1975
+			} else {
1976
+							return false;
1870 1977
 			}
1871
-			else
1872
-				return false;
1978
+		} else {
1979
+					return true;
1873 1980
 		}
1874
-		else
1875
-			return true;
1876
-	}
1877
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1878
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1879
-	elseif (is_writable(dirname(__FILE__)))
1981
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1982
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1983
+	} elseif (is_writable(dirname(__FILE__)))
1880 1984
 	{
1881 1985
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1882 1986
 		{
1883 1987
 			fwrite($ht_handle, $htaccess_addition);
1884 1988
 			fclose($ht_handle);
1885 1989
 			return true;
1990
+		} else {
1991
+					return false;
1886 1992
 		}
1887
-		else
1993
+	} else {
1888 1994
 			return false;
1889 1995
 	}
1890
-	else
1891
-		return false;
1892
-}
1996
+	}
1893 1997
 
1894 1998
 function template_install_above()
1895 1999
 {
@@ -1927,9 +2031,10 @@  discard block
 block discarded – undo
1927 2031
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1928 2032
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1929 2033
 
1930
-		foreach ($incontext['detected_languages'] as $lang => $name)
1931
-			echo '
2034
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2035
+					echo '
1932 2036
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2037
+		}
1933 2038
 
1934 2039
 		echo '
1935 2040
 								</select>
@@ -1949,9 +2054,10 @@  discard block
 block discarded – undo
1949 2054
 						<h2>', $txt['upgrade_progress'], '</h2>
1950 2055
 						<ul>';
1951 2056
 
1952
-	foreach ($incontext['steps'] as $num => $step)
1953
-		echo '
2057
+	foreach ($incontext['steps'] as $num => $step) {
2058
+			echo '
1954 2059
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2060
+	}
1955 2061
 
1956 2062
 	echo '
1957 2063
 						</ul>
@@ -1976,20 +2082,23 @@  discard block
 block discarded – undo
1976 2082
 		echo '
1977 2083
 								<div class="floatright">';
1978 2084
 
1979
-		if (!empty($incontext['continue']))
1980
-			echo '
2085
+		if (!empty($incontext['continue'])) {
2086
+					echo '
1981 2087
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button" />';
1982
-		if (!empty($incontext['skip']))
1983
-			echo '
2088
+		}
2089
+		if (!empty($incontext['skip'])) {
2090
+					echo '
1984 2091
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button" />';
2092
+		}
1985 2093
 		echo '
1986 2094
 								</div>';
1987 2095
 	}
1988 2096
 
1989 2097
 	// Show the closing form tag and other data only if not in the last step
1990
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1991
-		echo '
2098
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2099
+			echo '
1992 2100
 							</form>';
2101
+	}
1993 2102
 
1994 2103
 	echo '
1995 2104
 						</div>
@@ -2024,13 +2133,15 @@  discard block
 block discarded – undo
2024 2133
 		</div>';
2025 2134
 
2026 2135
 	// Show the warnings, or not.
2027
-	if (template_warning_divs())
2028
-		echo '
2136
+	if (template_warning_divs()) {
2137
+			echo '
2029 2138
 		<h3>', $txt['install_all_lovely'], '</h3>';
2139
+	}
2030 2140
 
2031 2141
 	// Say we want the continue button!
2032
-	if (empty($incontext['error']))
2033
-		$incontext['continue'] = 1;
2142
+	if (empty($incontext['error'])) {
2143
+			$incontext['continue'] = 1;
2144
+	}
2034 2145
 
2035 2146
 	// For the latest version stuff.
2036 2147
 	echo '
@@ -2064,8 +2175,8 @@  discard block
 block discarded – undo
2064 2175
 	global $txt, $incontext;
2065 2176
 
2066 2177
 	// Errors are very serious..
2067
-	if (!empty($incontext['error']))
2068
-		echo '
2178
+	if (!empty($incontext['error'])) {
2179
+			echo '
2069 2180
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2070 2181
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2071 2182
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -2073,9 +2184,10 @@  discard block
 block discarded – undo
2073 2184
 				', $incontext['error'], '
2074 2185
 			</div>
2075 2186
 		</div>';
2187
+	}
2076 2188
 	// A warning message?
2077
-	elseif (!empty($incontext['warning']))
2078
-		echo '
2189
+	elseif (!empty($incontext['warning'])) {
2190
+			echo '
2079 2191
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2080 2192
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2081 2193
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2083,6 +2195,7 @@  discard block
 block discarded – undo
2083 2195
 				', $incontext['warning'], '
2084 2196
 			</div>
2085 2197
 		</div>';
2198
+	}
2086 2199
 
2087 2200
 	return empty($incontext['error']) && empty($incontext['warning']);
2088 2201
 }
@@ -2098,27 +2211,30 @@  discard block
 block discarded – undo
2098 2211
 			<li>', $incontext['failed_files']), '</li>
2099 2212
 		</ul>';
2100 2213
 
2101
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2102
-		echo '
2214
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2215
+			echo '
2103 2216
 		<hr>
2104 2217
 		<p>', $txt['chmod_linux_info'], '</p>
2105 2218
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2219
+	}
2106 2220
 
2107 2221
 	// This is serious!
2108
-	if (!template_warning_divs())
2109
-		return;
2222
+	if (!template_warning_divs()) {
2223
+			return;
2224
+	}
2110 2225
 
2111 2226
 	echo '
2112 2227
 		<hr>
2113 2228
 		<p>', $txt['ftp_setup_info'], '</p>';
2114 2229
 
2115
-	if (!empty($incontext['ftp_errors']))
2116
-		echo '
2230
+	if (!empty($incontext['ftp_errors'])) {
2231
+			echo '
2117 2232
 		<div class="error_message">
2118 2233
 			', $txt['error_ftp_no_connect'], '<br><br>
2119 2234
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2120 2235
 		</div>
2121 2236
 		<br>';
2237
+	}
2122 2238
 
2123 2239
 	echo '
2124 2240
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2178,17 +2294,17 @@  discard block
 block discarded – undo
2178 2294
 				<td>
2179 2295
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2180 2296
 
2181
-	foreach ($incontext['supported_databases'] as $key => $db)
2182
-			echo '
2297
+	foreach ($incontext['supported_databases'] as $key => $db) {
2298
+				echo '
2183 2299
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2300
+	}
2184 2301
 
2185 2302
 	echo '
2186 2303
 					</select>
2187 2304
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2188 2305
 				</td>
2189 2306
 			</tr>';
2190
-	}
2191
-	else
2307
+	} else
2192 2308
 	{
2193 2309
 		echo '
2194 2310
 			<tr style="display: none;">
@@ -2381,9 +2497,10 @@  discard block
 block discarded – undo
2381 2497
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2382 2498
 				<ul>';
2383 2499
 
2384
-		foreach ($incontext['failures'] as $line => $fail)
2385
-			echo '
2500
+		foreach ($incontext['failures'] as $line => $fail) {
2501
+					echo '
2386 2502
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2503
+		}
2387 2504
 
2388 2505
 		echo '
2389 2506
 				</ul>';
@@ -2444,15 +2561,16 @@  discard block
 block discarded – undo
2444 2561
 			</tr>
2445 2562
 		</table>';
2446 2563
 
2447
-	if ($incontext['require_db_confirm'])
2448
-		echo '
2564
+	if ($incontext['require_db_confirm']) {
2565
+			echo '
2449 2566
 		<h2>', $txt['user_settings_database'], '</h2>
2450 2567
 		<p>', $txt['user_settings_database_info'], '</p>
2451 2568
 
2452 2569
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2453 2570
 			<input type="password" name="password3" size="30" />
2454 2571
 		</div>';
2455
-}
2572
+	}
2573
+	}
2456 2574
 
2457 2575
 // Tell them it's done, and to delete.
2458 2576
 function template_delete_install()
@@ -2465,14 +2583,15 @@  discard block
 block discarded – undo
2465 2583
 	template_warning_divs();
2466 2584
 
2467 2585
 	// Install directory still writable?
2468
-	if ($incontext['dir_still_writable'])
2469
-		echo '
2586
+	if ($incontext['dir_still_writable']) {
2587
+			echo '
2470 2588
 		<em>', $txt['still_writable'], '</em><br>
2471 2589
 		<br>';
2590
+	}
2472 2591
 
2473 2592
 	// Don't show the box if it's like 99% sure it won't work :P.
2474
-	if ($incontext['probably_delete_install'])
2475
-		echo '
2593
+	if ($incontext['probably_delete_install']) {
2594
+			echo '
2476 2595
 		<div style="margin: 1ex; font-weight: bold;">
2477 2596
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2478 2597
 		</div>
@@ -2488,6 +2607,7 @@  discard block
 block discarded – undo
2488 2607
 			}
2489 2608
 		</script>
2490 2609
 		<br>';
2610
+	}
2491 2611
 
2492 2612
 	echo '
2493 2613
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
Themes/default/Login.template.php 1 patch
Braces   +35 added lines, -24 removed lines patch added patch discarded remove patch
@@ -28,15 +28,17 @@  discard block
 block discarded – undo
28 28
 				<form class="login" action="', $context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '">';
29 29
 
30 30
 	// Did they make a mistake last time?
31
-	if (!empty($context['login_errors']))
32
-		echo '
31
+	if (!empty($context['login_errors'])) {
32
+			echo '
33 33
 					<div class="errorbox">', implode('<br>', $context['login_errors']), '</div>
34 34
 					<br>';
35
+	}
35 36
 
36 37
 	// Or perhaps there's some special description for this time?
37
-	if (isset($context['description']))
38
-		echo '
38
+	if (isset($context['description'])) {
39
+			echo '
39 40
 					<div class="information">', $context['description'], '</div>';
41
+	}
40 42
 
41 43
 	// Now just get the basic information - username, password, etc.
42 44
 	echo '
@@ -61,10 +63,11 @@  discard block
 block discarded – undo
61 63
 						</dd>';
62 64
 
63 65
 	// If they have deleted their account, give them a chance to change their mind.
64
-	if (isset($context['login_show_undelete']))
65
-		echo '
66
+	if (isset($context['login_show_undelete'])) {
67
+			echo '
66 68
 						<dt class="alert">', $txt['undelete_account'], ':</dt>
67 69
 						<dd><input type="checkbox" name="undelete"></dd>';
70
+	}
68 71
 
69 72
 	echo '
70 73
 					</dl>
@@ -82,8 +85,8 @@  discard block
 block discarded – undo
82 85
 							document.getElementById("', !empty($context['from_ajax']) ? 'ajax_' : '', isset($context['default_username']) && $context['default_username'] != '' ? 'loginpass' : 'loginuser', '").focus();
83 86
 						}, 150);';
84 87
 
85
-	if (!empty($context['from_ajax']))
86
-		echo '
88
+	if (!empty($context['from_ajax'])) {
89
+			echo '
87 90
 						form = $("#frmLogin");
88 91
 						form.submit(function(e) {
89 92
 							e.preventDefault();
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 
117 120
 							return false;
118 121
 						});';
122
+	}
119 123
 
120 124
 	echo '
121 125
 					</script>
122 126
 				</form>';
123 127
 
124 128
 	// It is a long story as to why we have this when we're clearly not going to use it.
125
-	if (!empty($context['from_ajax']))
126
-		echo '
129
+	if (!empty($context['from_ajax'])) {
130
+			echo '
127 131
 				<br>
128 132
 				<a href="javascript:self.close();"></a>';
133
+	}
129 134
 
130 135
 	echo '
131 136
 			</div><!-- .roundframe -->
@@ -148,11 +153,12 @@  discard block
 block discarded – undo
148 153
 			</div>
149 154
 			<div class="roundframe noup">';
150 155
 
151
-	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
152
-		echo '
156
+	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error'])) {
157
+			echo '
153 158
 				<div class="error">
154 159
 					', $txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' : 'backup_') . 'invalid'], '
155 160
 				</div>';
161
+	}
156 162
 
157 163
 	echo '
158 164
 				<form action="', $context['tfa_url'], '" method="post" id="frmTfa">
@@ -181,8 +187,8 @@  discard block
 block discarded – undo
181 187
 				<script>
182 188
 					form = $("#frmTfa");';
183 189
 
184
-	if (!empty($context['from_ajax']))
185
-		echo '
190
+	if (!empty($context['from_ajax'])) {
191
+			echo '
186 192
 					form.submit(function(e) {
187 193
 						// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
188 194
 						if (form.find("input[name=tfa_backup]:first").val().length > 0)
@@ -201,6 +207,7 @@  discard block
 block discarded – undo
201 207
 
202 208
 						return false;
203 209
 					});';
210
+	}
204 211
 
205 212
 	echo '
206 213
 					form.find("input[name=backup]").click(function(e) {
@@ -232,10 +239,11 @@  discard block
 block discarded – undo
232 239
 			<p class="information centertext">
233 240
 				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';
234 241
 
235
-	if ($context['can_register'])
236
-		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
237
-	else
238
-		echo $txt['login_below'];
242
+	if ($context['can_register']) {
243
+			echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
244
+	} else {
245
+			echo $txt['login_below'];
246
+	}
239 247
 
240 248
 	// And now the login information.
241 249
 	echo '
@@ -335,9 +343,10 @@  discard block
 block discarded – undo
335 343
 			</div>
336 344
 			<div class="roundframe centertext noup">';
337 345
 
338
-	if (!empty($context['incorrect_password']))
339
-		echo '
346
+	if (!empty($context['incorrect_password'])) {
347
+			echo '
340 348
 				<div class="error">', $txt['admin_incorrect_password'], '</div>';
349
+	}
341 350
 
342 351
 	echo '
343 352
 				<strong>', $txt['password'], ':</strong>
@@ -378,10 +387,11 @@  discard block
 block discarded – undo
378 387
 				<dl>';
379 388
 
380 389
 	// You didn't even have an ID?
381
-	if (empty($context['member_id']))
382
-		echo '
390
+	if (empty($context['member_id'])) {
391
+			echo '
383 392
 					<dt>', $txt['invalid_activation_username'], ':</dt>
384 393
 					<dd><input type="text" name="user" size="30"></dd>';
394
+	}
385 395
 
386 396
 	echo '
387 397
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
@@ -418,13 +428,14 @@  discard block
 block discarded – undo
418 428
 					<dd><input type="password" name="passwd" size="30"></dd>
419 429
 				</dl>';
420 430
 
421
-	if ($context['can_activate'])
422
-		echo '
431
+	if ($context['can_activate']) {
432
+			echo '
423 433
 				<p>', $txt['invalid_activation_known'], '</p>
424 434
 				<dl>
425 435
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
426 436
 					<dd><input type="text" name="code" size="30"></dd>
427 437
 				</dl>';
438
+	}
428 439
 
429 440
 	echo '
430 441
 				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button"></p>
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 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']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$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']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	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))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	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)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$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'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$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'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.