Completed
Push — release-2.1 ( cfdc59...af3d3b )
by Jeremy
12:06 queued 05:35
created
Sources/ManageBans.php 1 patch
Braces   +257 added lines, -207 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
  * Ban center. The main entrance point for all ban center functions.
@@ -120,10 +121,11 @@  discard block
 block discarded – undo
120 121
 	}
121 122
 
122 123
 	// Create a date string so we don't overload them with date info.
123
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
124
-		$context['ban_time_format'] = $user_info['time_format'];
125
-	else
126
-		$context['ban_time_format'] = $matches[0];
124
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
125
+			$context['ban_time_format'] = $user_info['time_format'];
126
+	} else {
127
+			$context['ban_time_format'] = $matches[0];
128
+	}
127 129
 
128 130
 	$listOptions = array(
129 131
 		'id' => 'ban_list',
@@ -201,16 +203,19 @@  discard block
 block discarded – undo
201 203
 					'function' => function($rowData) use ($txt)
202 204
 					{
203 205
 						// This ban never expires...whahaha.
204
-						if ($rowData['expire_time'] === null)
205
-							return $txt['never'];
206
+						if ($rowData['expire_time'] === null) {
207
+													return $txt['never'];
208
+						}
206 209
 
207 210
 						// This ban has already expired.
208
-						elseif ($rowData['expire_time'] < time())
209
-							return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
211
+						elseif ($rowData['expire_time'] < time()) {
212
+													return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
213
+						}
210 214
 
211 215
 						// Still need to wait a few days for this ban to expire.
212
-						else
213
-							return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
216
+						else {
217
+													return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
218
+						}
214 219
 					},
215 220
 				),
216 221
 				'sort' => array(
@@ -320,8 +325,9 @@  discard block
 block discarded – undo
320 325
 		)
321 326
 	);
322 327
 	$bans = array();
323
-	while ($row = $smcFunc['db_fetch_assoc']($request))
324
-		$bans[] = $row;
328
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
329
+			$bans[] = $row;
330
+	}
325 331
 
326 332
 	$smcFunc['db_free_result']($request);
327 333
 
@@ -363,8 +369,9 @@  discard block
 block discarded – undo
363 369
 {
364 370
 	global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir;
365 371
 
366
-	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
367
-		BanEdit2();
372
+	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) {
373
+			BanEdit2();
374
+	}
368 375
 
369 376
 	$ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
370 377
 
@@ -373,11 +380,10 @@  discard block
 block discarded – undo
373 380
 	createToken('admin-bet');
374 381
 	$context['form_url'] = $scripturl . '?action=admin;area=ban;sa=edit';
375 382
 
376
-	if (!empty($context['ban_errors']))
377
-		foreach ($context['ban_errors'] as $error)
383
+	if (!empty($context['ban_errors'])) {
384
+			foreach ($context['ban_errors'] as $error)
378 385
 			$context['error_messages'][$error] = $txt[$error];
379
-
380
-	else
386
+	} else
381 387
 	{
382 388
 		// If we're editing an existing ban, get it from the database.
383 389
 		if (!empty($ban_group_id))
@@ -413,12 +419,13 @@  discard block
 block discarded – undo
413 419
 						'data' => array(
414 420
 							'function' => function($ban_item) use ($txt)
415 421
 							{
416
-								if (in_array($ban_item['type'], array('ip', 'hostname', 'email')))
417
-									return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
418
-								elseif ($ban_item['type'] == 'user')
419
-									return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
420
-								else
421
-									return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
422
+								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) {
423
+																	return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
424
+								} elseif ($ban_item['type'] == 'user') {
425
+																	return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
426
+								} else {
427
+																	return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
428
+								}
422 429
 							},
423 430
 							'style' => 'text-align: left;',
424 431
 						),
@@ -556,8 +563,9 @@  discard block
 block discarded – undo
556 563
 					$context['ban']['from_user'] = true;
557 564
 
558 565
 					// Would be nice if we could also ban the hostname.
559
-					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup']))
560
-						$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
566
+					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) {
567
+											$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
568
+					}
561 569
 
562 570
 					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
563 571
 				}
@@ -625,8 +633,9 @@  discard block
 block discarded – undo
625 633
 			'items_per_page' => $items_per_page,
626 634
 		)
627 635
 	);
628
-	if ($smcFunc['db_num_rows']($request) == 0)
629
-		fatal_lang_error('ban_not_found', false);
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			fatal_lang_error('ban_not_found', false);
638
+	}
630 639
 
631 640
 	while ($row = $smcFunc['db_fetch_assoc']($request))
632 641
 	{
@@ -663,18 +672,15 @@  discard block
 block discarded – undo
663 672
 			{
664 673
 				$ban_items[$row['id_ban']]['type'] = 'ip';
665 674
 				$ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);
666
-			}
667
-			elseif (!empty($row['hostname']))
675
+			} elseif (!empty($row['hostname']))
668 676
 			{
669 677
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
670 678
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
671
-			}
672
-			elseif (!empty($row['email_address']))
679
+			} elseif (!empty($row['email_address']))
673 680
 			{
674 681
 				$ban_items[$row['id_ban']]['type'] = 'email';
675 682
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
676
-			}
677
-			elseif (!empty($row['id_member']))
683
+			} elseif (!empty($row['id_member']))
678 684
 			{
679 685
 				$ban_items[$row['id_ban']]['type'] = 'user';
680 686
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -740,9 +746,10 @@  discard block
 block discarded – undo
740 746
 	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError');
741 747
 
742 748
 	$return = array();
743
-	foreach ($search_list as $key => $callable)
744
-		if (is_callable($callable))
749
+	foreach ($search_list as $key => $callable) {
750
+			if (is_callable($callable))
745 751
 			$return[$key] = call_user_func($callable, $member_id);
752
+	}
746 753
 
747 754
 	return $return;
748 755
 }
@@ -767,8 +774,9 @@  discard block
 block discarded – undo
767 774
 			'current_user' => $member_id,
768 775
 		)
769 776
 	);
770
-	while ($row = $smcFunc['db_fetch_assoc']($request))
771
-		$message_ips[] = inet_dtop($row['poster_ip']);
777
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
778
+			$message_ips[] = inet_dtop($row['poster_ip']);
779
+	}
772 780
 	$smcFunc['db_free_result']($request);
773 781
 
774 782
 	return $message_ips;
@@ -793,8 +801,9 @@  discard block
 block discarded – undo
793 801
 			'current_user' => $member_id,
794 802
 		)
795 803
 	);
796
-	while ($row = $smcFunc['db_fetch_assoc']($request))
797
-	    $error_ips[] = inet_dtop($row['ip']);
804
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
805
+		    $error_ips[] = inet_dtop($row['ip']);
806
+	}
798 807
 	$smcFunc['db_free_result']($request);
799 808
 
800 809
 	return $error_ips;
@@ -835,11 +844,13 @@  discard block
 block discarded – undo
835 844
 		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
836 845
 
837 846
 		// Adding a new ban group
838
-		if (empty($_REQUEST['bg']))
839
-			$ban_group_id = insertBanGroup($ban_info);
847
+		if (empty($_REQUEST['bg'])) {
848
+					$ban_group_id = insertBanGroup($ban_info);
849
+		}
840 850
 		// Editing an existing ban group
841
-		else
842
-			$ban_group_id = updateBanGroup($ban_info);
851
+		else {
852
+					$ban_group_id = updateBanGroup($ban_info);
853
+		}
843 854
 
844 855
 		if (is_numeric($ban_group_id))
845 856
 		{
@@ -850,9 +861,10 @@  discard block
 block discarded – undo
850 861
 		$context['ban'] = $ban_info;
851 862
 	}
852 863
 
853
-	if (isset($_POST['ban_suggestions']))
854
-		// @TODO: is $_REQUEST['bi'] ever set?
864
+	if (isset($_POST['ban_suggestions'])) {
865
+			// @TODO: is $_REQUEST['bi'] ever set?
855 866
 		$saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
867
+	}
856 868
 
857 869
 	// Something went wrong somewhere... Oh well, let's go back.
858 870
 	if (!empty($context['ban_errors']))
@@ -862,8 +874,9 @@  discard block
 block discarded – undo
862 874
 		$context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
863 875
 
864 876
 		// Not strictly necessary, but it's nice
865
-		if (!empty($context['ban_suggestions']['member']['id']))
866
-			$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
877
+		if (!empty($context['ban_suggestions']['member']['id'])) {
878
+					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
879
+		}
867 880
 		return BanEdit();
868 881
 	}
869 882
 	$context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();
@@ -910,10 +923,11 @@  discard block
 block discarded – undo
910 923
 
911 924
 	foreach ($suggestions as $key => $value)
912 925
 	{
913
-		if (is_array($value))
914
-			$triggers[$key] = $value;
915
-		else
916
-			$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
926
+		if (is_array($value)) {
927
+					$triggers[$key] = $value;
928
+		} else {
929
+					$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
930
+		}
917 931
 	}
918 932
 
919 933
 	$ban_triggers = validateTriggers($triggers);
@@ -921,16 +935,18 @@  discard block
 block discarded – undo
921 935
 	// Time to save!
922 936
 	if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))
923 937
 	{
924
-		if (empty($ban_id))
925
-			addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
926
-		else
927
-			updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
938
+		if (empty($ban_id)) {
939
+					addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
940
+		} else {
941
+					updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
942
+		}
943
+	}
944
+	if (!empty($context['ban_errors'])) {
945
+			return $triggers;
946
+	} else {
947
+			return false;
948
+	}
928 949
 	}
929
-	if (!empty($context['ban_errors']))
930
-		return $triggers;
931
-	else
932
-		return false;
933
-}
934 950
 
935 951
 /**
936 952
  * This function removes a bunch of triggers based on ids
@@ -944,14 +960,17 @@  discard block
 block discarded – undo
944 960
 {
945 961
 	global $smcFunc, $scripturl;
946 962
 
947
-	if ($group_id !== false)
948
-		$group_id = (int) $group_id;
963
+	if ($group_id !== false) {
964
+			$group_id = (int) $group_id;
965
+	}
949 966
 
950
-	if (empty($group_id) && empty($items_ids))
951
-		return false;
967
+	if (empty($group_id) && empty($items_ids)) {
968
+			return false;
969
+	}
952 970
 
953
-	if (!is_array($items_ids))
954
-		$items_ids = array($items_ids);
971
+	if (!is_array($items_ids)) {
972
+			$items_ids = array($items_ids);
973
+	}
955 974
 
956 975
 	$log_info = array();
957 976
 	$ban_items = array();
@@ -989,8 +1008,7 @@  discard block
 block discarded – undo
989 1008
 					'bantype' => ($is_range ? 'ip_range' : 'main_ip'),
990 1009
 					'value' => $ban_items[$row['id_ban']]['ip'],
991 1010
 				);
992
-			}
993
-			elseif (!empty($row['hostname']))
1011
+			} elseif (!empty($row['hostname']))
994 1012
 			{
995 1013
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
996 1014
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
@@ -998,8 +1016,7 @@  discard block
 block discarded – undo
998 1016
 					'bantype' => 'hostname',
999 1017
 					'value' => $row['hostname'],
1000 1018
 				);
1001
-			}
1002
-			elseif (!empty($row['email_address']))
1019
+			} elseif (!empty($row['email_address']))
1003 1020
 			{
1004 1021
 				$ban_items[$row['id_ban']]['type'] = 'email';
1005 1022
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
@@ -1007,8 +1024,7 @@  discard block
 block discarded – undo
1007 1024
 					'bantype' => 'email',
1008 1025
 					'value' => $ban_items[$row['id_ban']]['email'],
1009 1026
 				);
1010
-			}
1011
-			elseif (!empty($row['id_member']))
1027
+			} elseif (!empty($row['id_member']))
1012 1028
 			{
1013 1029
 				$ban_items[$row['id_ban']]['type'] = 'user';
1014 1030
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -1041,8 +1057,7 @@  discard block
 block discarded – undo
1041 1057
 				'ban_group' => $group_id,
1042 1058
 			)
1043 1059
 		);
1044
-	}
1045
-	elseif (!empty($items_ids))
1060
+	} elseif (!empty($items_ids))
1046 1061
 	{
1047 1062
 		$smcFunc['db_query']('', '
1048 1063
 			DELETE FROM {db_prefix}ban_items
@@ -1067,13 +1082,15 @@  discard block
 block discarded – undo
1067 1082
 {
1068 1083
 	global $smcFunc;
1069 1084
 
1070
-	if (!is_array($group_ids))
1071
-		$group_ids = array($group_ids);
1085
+	if (!is_array($group_ids)) {
1086
+			$group_ids = array($group_ids);
1087
+	}
1072 1088
 
1073 1089
 	$group_ids = array_unique($group_ids);
1074 1090
 
1075
-	if (empty($group_ids))
1076
-		return false;
1091
+	if (empty($group_ids)) {
1092
+			return false;
1093
+	}
1077 1094
 
1078 1095
 	$smcFunc['db_query']('', '
1079 1096
 		DELETE FROM {db_prefix}ban_groups
@@ -1097,21 +1114,23 @@  discard block
 block discarded – undo
1097 1114
 {
1098 1115
 	global $smcFunc;
1099 1116
 
1100
-	if (empty($ids))
1101
-		$smcFunc['db_query']('truncate_table', '
1117
+	if (empty($ids)) {
1118
+			$smcFunc['db_query']('truncate_table', '
1102 1119
 			TRUNCATE {db_prefix}log_banned',
1103 1120
 			array(
1104 1121
 			)
1105 1122
 		);
1106
-	else
1123
+	} else
1107 1124
 	{
1108
-		if (!is_array($ids))
1109
-			$ids = array($ids);
1125
+		if (!is_array($ids)) {
1126
+					$ids = array($ids);
1127
+		}
1110 1128
 
1111 1129
 		$ids = array_unique($ids);
1112 1130
 
1113
-		if (empty($ids))
1114
-			return false;
1131
+		if (empty($ids)) {
1132
+					return false;
1133
+		}
1115 1134
 
1116 1135
 		$smcFunc['db_query']('', '
1117 1136
 			DELETE FROM {db_prefix}log_banned
@@ -1137,8 +1156,9 @@  discard block
 block discarded – undo
1137 1156
 {
1138 1157
 	global $context, $smcFunc;
1139 1158
 
1140
-	if (empty($triggers))
1141
-		$context['ban_erros'][] = 'ban_empty_triggers';
1159
+	if (empty($triggers)) {
1160
+			$context['ban_erros'][] = 'ban_empty_triggers';
1161
+	}
1142 1162
 
1143 1163
 	$ban_triggers = array();
1144 1164
 	$log_info = array();
@@ -1147,39 +1167,39 @@  discard block
 block discarded – undo
1147 1167
 	{
1148 1168
 		if (!empty($value))
1149 1169
 		{
1150
-			if ($key == 'member')
1151
-				continue;
1170
+			if ($key == 'member') {
1171
+							continue;
1172
+			}
1152 1173
 
1153 1174
 			if ($key == 'main_ip')
1154 1175
 			{
1155 1176
 				$value = trim($value);
1156 1177
 				$ip_parts = ip2range($value);
1157
-				if (!checkExistingTriggerIP($ip_parts, $value))
1158
-					$context['ban_erros'][] = 'invalid_ip';
1159
-				else
1178
+				if (!checkExistingTriggerIP($ip_parts, $value)) {
1179
+									$context['ban_erros'][] = 'invalid_ip';
1180
+				} else
1160 1181
 				{
1161 1182
 					$ban_triggers['main_ip'] = array(
1162 1183
 						'ip_low' => $ip_parts['low'],
1163 1184
 						'ip_high' => $ip_parts['high']
1164 1185
 					);
1165 1186
 				}
1166
-			}
1167
-			elseif ($key == 'hostname')
1187
+			} elseif ($key == 'hostname')
1168 1188
 			{
1169
-				if (preg_match('/[^\w.\-*]/', $value) == 1)
1170
-					$context['ban_erros'][] = 'invalid_hostname';
1171
-				else
1189
+				if (preg_match('/[^\w.\-*]/', $value) == 1) {
1190
+									$context['ban_erros'][] = 'invalid_hostname';
1191
+				} else
1172 1192
 				{
1173 1193
 					// Replace the * wildcard by a MySQL wildcard %.
1174 1194
 					$value = substr(str_replace('*', '%', $value), 0, 255);
1175 1195
 
1176 1196
 					$ban_triggers['hostname']['hostname'] = $value;
1177 1197
 				}
1178
-			}
1179
-			elseif ($key == 'email')
1198
+			} elseif ($key == 'email')
1180 1199
 			{
1181
-				if (preg_match('/[^\w.\-\+*@]/', $value) == 1)
1182
-					$context['ban_erros'][] = 'invalid_email';
1200
+				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) {
1201
+									$context['ban_erros'][] = 'invalid_email';
1202
+				}
1183 1203
 
1184 1204
 				// Check the user is not banning an admin.
1185 1205
 				$request = $smcFunc['db_query']('', '
@@ -1193,15 +1213,15 @@  discard block
 block discarded – undo
1193 1213
 						'email' => $value,
1194 1214
 					)
1195 1215
 				);
1196
-				if ($smcFunc['db_num_rows']($request) != 0)
1197
-					$context['ban_erros'][] = 'no_ban_admin';
1216
+				if ($smcFunc['db_num_rows']($request) != 0) {
1217
+									$context['ban_erros'][] = 'no_ban_admin';
1218
+				}
1198 1219
 				$smcFunc['db_free_result']($request);
1199 1220
 
1200 1221
 				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255);
1201 1222
 
1202 1223
 				$ban_triggers['email']['email_address'] = $value;
1203
-			}
1204
-			elseif ($key == 'user')
1224
+			} elseif ($key == 'user')
1205 1225
 			{
1206 1226
 				$user = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES));
1207 1227
 
@@ -1215,8 +1235,9 @@  discard block
 block discarded – undo
1215 1235
 						'username' => $user,
1216 1236
 					)
1217 1237
 				);
1218
-				if ($smcFunc['db_num_rows']($request) == 0)
1219
-					$context['ban_erros'][] = 'invalid_username';
1238
+				if ($smcFunc['db_num_rows']($request) == 0) {
1239
+									$context['ban_erros'][] = 'invalid_username';
1240
+				}
1220 1241
 				list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);
1221 1242
 				$smcFunc['db_free_result']($request);
1222 1243
 
@@ -1224,25 +1245,25 @@  discard block
 block discarded – undo
1224 1245
 				{
1225 1246
 					unset($value);
1226 1247
 					$context['ban_erros'][] = 'no_ban_admin';
1248
+				} else {
1249
+									$ban_triggers['user']['id_member'] = $value;
1227 1250
 				}
1228
-				else
1229
-					$ban_triggers['user']['id_member'] = $value;
1230
-			}
1231
-			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1251
+			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1232 1252
 			{
1233 1253
 				// Special case, those two are arrays themselves
1234 1254
 				$values = array_unique($value);
1235 1255
 				// Don't add the main IP again.
1236
-				if (isset($triggers['main_ip']))
1237
-					$values = array_diff($values, array($triggers['main_ip']));
1256
+				if (isset($triggers['main_ip'])) {
1257
+									$values = array_diff($values, array($triggers['main_ip']));
1258
+				}
1238 1259
 				unset($value);
1239 1260
 				foreach ($values as $val)
1240 1261
 				{
1241 1262
 					$val = trim($val);
1242 1263
 					$ip_parts = ip2range($val);
1243
-					if (!checkExistingTriggerIP($ip_parts, $val))
1244
-						$context['ban_erros'][] = 'invalid_ip';
1245
-					else
1264
+					if (!checkExistingTriggerIP($ip_parts, $val)) {
1265
+											$context['ban_erros'][] = 'invalid_ip';
1266
+					} else
1246 1267
 					{
1247 1268
 						$ban_triggers[$key][] = array(
1248 1269
 							'ip_low' => $ip_parts['low'],
@@ -1255,15 +1276,16 @@  discard block
 block discarded – undo
1255 1276
 						);
1256 1277
 					}
1257 1278
 				}
1279
+			} else {
1280
+							$context['ban_erros'][] = 'no_bantype_selected';
1258 1281
 			}
1259
-			else
1260
-				$context['ban_erros'][] = 'no_bantype_selected';
1261 1282
 
1262
-			if (isset($value) && !is_array($value))
1263
-				$log_info[] = array(
1283
+			if (isset($value) && !is_array($value)) {
1284
+							$log_info[] = array(
1264 1285
 					'value' => $value,
1265 1286
 					'bantype' => $key,
1266 1287
 				);
1288
+			}
1267 1289
 		}
1268 1290
 	}
1269 1291
 	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info);
@@ -1283,8 +1305,9 @@  discard block
 block discarded – undo
1283 1305
 {
1284 1306
 	global $smcFunc, $context;
1285 1307
 
1286
-	if (empty($group_id))
1287
-		$context['ban_errors'][] = 'ban_id_empty';
1308
+	if (empty($group_id)) {
1309
+			$context['ban_errors'][] = 'ban_id_empty';
1310
+	}
1288 1311
 
1289 1312
 	// Preset all values that are required.
1290 1313
 	$values = array(
@@ -1309,18 +1332,21 @@  discard block
 block discarded – undo
1309 1332
 	foreach ($triggers as $key => $trigger)
1310 1333
 	{
1311 1334
 		// Exceptions, exceptions, exceptions...always exceptions... :P
1312
-		if (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1313
-			foreach ($trigger as $real_trigger)
1335
+		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) {
1336
+					foreach ($trigger as $real_trigger)
1314 1337
 				$insertTriggers[] = array_merge($values, $real_trigger);
1315
-		else
1316
-			$insertTriggers[] = array_merge($values, $trigger);
1338
+		} else {
1339
+					$insertTriggers[] = array_merge($values, $trigger);
1340
+		}
1317 1341
 	}
1318 1342
 
1319
-	if (empty($insertTriggers))
1320
-		$context['ban_errors'][] = 'ban_no_triggers';
1343
+	if (empty($insertTriggers)) {
1344
+			$context['ban_errors'][] = 'ban_no_triggers';
1345
+	}
1321 1346
 
1322
-	if (!empty($context['ban_errors']))
1323
-		return false;
1347
+	if (!empty($context['ban_errors'])) {
1348
+			return false;
1349
+	}
1324 1350
 
1325 1351
 	$smcFunc['db_insert']('',
1326 1352
 		'{db_prefix}ban_items',
@@ -1348,15 +1374,19 @@  discard block
 block discarded – undo
1348 1374
 {
1349 1375
 	global $smcFunc, $context;
1350 1376
 
1351
-	if (empty($ban_item))
1352
-		$context['ban_errors'][] = 'ban_ban_item_empty';
1353
-	if (empty($group_id))
1354
-		$context['ban_errors'][] = 'ban_id_empty';
1355
-	if (empty($trigger))
1356
-		$context['ban_errors'][] = 'ban_no_triggers';
1377
+	if (empty($ban_item)) {
1378
+			$context['ban_errors'][] = 'ban_ban_item_empty';
1379
+	}
1380
+	if (empty($group_id)) {
1381
+			$context['ban_errors'][] = 'ban_id_empty';
1382
+	}
1383
+	if (empty($trigger)) {
1384
+			$context['ban_errors'][] = 'ban_no_triggers';
1385
+	}
1357 1386
 
1358
-	if (!empty($context['ban_errors']))
1359
-		return;
1387
+	if (!empty($context['ban_errors'])) {
1388
+			return;
1389
+	}
1360 1390
 
1361 1391
 	// Preset all values that are required.
1362 1392
 	$values = array(
@@ -1397,8 +1427,9 @@  discard block
 block discarded – undo
1397 1427
  */
1398 1428
 function logTriggersUpdates($logs, $new = true, $removal = false)
1399 1429
 {
1400
-	if (empty($logs))
1401
-		return;
1430
+	if (empty($logs)) {
1431
+			return;
1432
+	}
1402 1433
 
1403 1434
 	$log_name_map = array(
1404 1435
 		'main_ip' => 'ip_range',
@@ -1409,14 +1440,15 @@  discard block
 block discarded – undo
1409 1440
 	);
1410 1441
 
1411 1442
 	// Log the addion of the ban entries into the moderation log.
1412
-	foreach ($logs as $log)
1413
-		logAction('ban' . ($removal == true ? 'remove' : ''), array(
1443
+	foreach ($logs as $log) {
1444
+			logAction('ban' . ($removal == true ? 'remove' : ''), array(
1414 1445
 			$log_name_map[$log['bantype']] => $log['value'],
1415 1446
 			'new' => empty($new) ? 0 : 1,
1416 1447
 			'remove' => empty($removal) ? 0 : 1,
1417 1448
 			'type' => $log['bantype'],
1418 1449
 		));
1419
-}
1450
+	}
1451
+	}
1420 1452
 
1421 1453
 /**
1422 1454
  * Updates an existing ban group
@@ -1430,12 +1462,15 @@  discard block
 block discarded – undo
1430 1462
 {
1431 1463
 	global $smcFunc, $context;
1432 1464
 
1433
-	if (empty($ban_info['name']))
1434
-		$context['ban_errors'][] = 'ban_name_empty';
1435
-	if (empty($ban_info['id']))
1436
-		$context['ban_errors'][] = 'ban_id_empty';
1437
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1438
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1465
+	if (empty($ban_info['name'])) {
1466
+			$context['ban_errors'][] = 'ban_name_empty';
1467
+	}
1468
+	if (empty($ban_info['id'])) {
1469
+			$context['ban_errors'][] = 'ban_id_empty';
1470
+	}
1471
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1472
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1473
+	}
1439 1474
 
1440 1475
 	if (!empty($ban_info['id']))
1441 1476
 	{
@@ -1450,8 +1485,9 @@  discard block
 block discarded – undo
1450 1485
 			)
1451 1486
 		);
1452 1487
 
1453
-		if ($smcFunc['db_num_rows']($request) == 0)
1454
-			$context['ban_errors'][] = 'ban_not_found';
1488
+		if ($smcFunc['db_num_rows']($request) == 0) {
1489
+					$context['ban_errors'][] = 'ban_not_found';
1490
+		}
1455 1491
 		$smcFunc['db_free_result']($request);
1456 1492
 	}
1457 1493
 
@@ -1469,13 +1505,15 @@  discard block
 block discarded – undo
1469 1505
 				'new_ban_name' => $ban_info['name'],
1470 1506
 			)
1471 1507
 		);
1472
-		if ($smcFunc['db_num_rows']($request) != 0)
1473
-			$context['ban_errors'][] = 'ban_name_exists';
1508
+		if ($smcFunc['db_num_rows']($request) != 0) {
1509
+					$context['ban_errors'][] = 'ban_name_exists';
1510
+		}
1474 1511
 		$smcFunc['db_free_result']($request);
1475 1512
 	}
1476 1513
 
1477
-	if (!empty($context['ban_errors']))
1478
-		return $ban_info['id'];
1514
+	if (!empty($context['ban_errors'])) {
1515
+			return $ban_info['id'];
1516
+	}
1479 1517
 
1480 1518
 	$smcFunc['db_query']('', '
1481 1519
 		UPDATE {db_prefix}ban_groups
@@ -1519,10 +1557,12 @@  discard block
 block discarded – undo
1519 1557
 {
1520 1558
 	global $smcFunc, $context;
1521 1559
 
1522
-	if (empty($ban_info['name']))
1523
-		$context['ban_errors'][] = 'ban_name_empty';
1524
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1525
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1560
+	if (empty($ban_info['name'])) {
1561
+			$context['ban_errors'][] = 'ban_name_empty';
1562
+	}
1563
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1564
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1565
+	}
1526 1566
 
1527 1567
 	if (!empty($ban_info['name']))
1528 1568
 	{
@@ -1537,13 +1577,15 @@  discard block
 block discarded – undo
1537 1577
 			)
1538 1578
 		);
1539 1579
 
1540
-		if ($smcFunc['db_num_rows']($request) == 1)
1541
-			$context['ban_errors'][] = 'ban_name_exists';
1580
+		if ($smcFunc['db_num_rows']($request) == 1) {
1581
+					$context['ban_errors'][] = 'ban_name_exists';
1582
+		}
1542 1583
 		$smcFunc['db_free_result']($request);
1543 1584
 	}
1544 1585
 
1545
-	if (!empty($context['ban_errors']))
1546
-		return;
1586
+	if (!empty($context['ban_errors'])) {
1587
+			return;
1588
+	}
1547 1589
 
1548 1590
 	// Yes yes, we're ready to add now.
1549 1591
 	$ban_info['id'] = $smcFunc['db_insert']('',
@@ -1560,8 +1602,9 @@  discard block
 block discarded – undo
1560 1602
 		1
1561 1603
 	);
1562 1604
 
1563
-	if (empty($ban_info['id']))
1564
-		$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1605
+	if (empty($ban_info['id'])) {
1606
+			$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1607
+	}
1565 1608
 
1566 1609
 	return $ban_info['id'];
1567 1610
 }
@@ -1586,24 +1629,24 @@  discard block
 block discarded – undo
1586 1629
 	$ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
1587 1630
 	$ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
1588 1631
 
1589
-	if (empty($ban_group))
1590
-		fatal_lang_error('ban_not_found', false);
1632
+	if (empty($ban_group)) {
1633
+			fatal_lang_error('ban_not_found', false);
1634
+	}
1591 1635
 
1592 1636
 	if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))
1593 1637
 	{
1594 1638
 		saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
1595 1639
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1596
-	}
1597
-	elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1640
+	} elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1598 1641
 	{
1599 1642
 		// The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)
1600 1643
 		saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
1601
-		if (!empty($_POST['ban_suggestions']))
1602
-			saveTriggers($_POST['ban_suggestions'], $ban_group);
1644
+		if (!empty($_POST['ban_suggestions'])) {
1645
+					saveTriggers($_POST['ban_suggestions'], $ban_group);
1646
+		}
1603 1647
 
1604 1648
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1605
-	}
1606
-	elseif (isset($_POST['edit_trigger']))
1649
+	} elseif (isset($_POST['edit_trigger']))
1607 1650
 	{
1608 1651
 		removeBanTriggers($ban_id);
1609 1652
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
@@ -1634,8 +1677,7 @@  discard block
 block discarded – undo
1634 1677
 			),
1635 1678
 			'is_new' => true,
1636 1679
 		);
1637
-	}
1638
-	else
1680
+	} else
1639 1681
 	{
1640 1682
 		$request = $smcFunc['db_query']('', '
1641 1683
 			SELECT
@@ -1652,8 +1694,9 @@  discard block
 block discarded – undo
1652 1694
 				'ban_group' => $ban_group,
1653 1695
 			)
1654 1696
 		);
1655
-		if ($smcFunc['db_num_rows']($request) == 0)
1656
-			fatal_lang_error('ban_not_found', false);
1697
+		if ($smcFunc['db_num_rows']($request) == 0) {
1698
+					fatal_lang_error('ban_not_found', false);
1699
+		}
1657 1700
 		$row = $smcFunc['db_fetch_assoc']($request);
1658 1701
 		$smcFunc['db_free_result']($request);
1659 1702
 
@@ -1702,8 +1745,9 @@  discard block
 block discarded – undo
1702 1745
 		removeBanTriggers($_POST['remove']);
1703 1746
 
1704 1747
 		// Rehabilitate some members.
1705
-		if ($_REQUEST['entity'] == 'member')
1706
-			updateBanMembers();
1748
+		if ($_REQUEST['entity'] == 'member') {
1749
+					updateBanMembers();
1750
+		}
1707 1751
 
1708 1752
 		// Make sure the ban cache is refreshed.
1709 1753
 		updateSettings(array('banLastUpdated' => time()));
@@ -1816,8 +1860,7 @@  discard block
 block discarded – undo
1816 1860
 			'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',
1817 1861
 			'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',
1818 1862
 		);
1819
-	}
1820
-	elseif ($context['selected_entity'] === 'hostname')
1863
+	} elseif ($context['selected_entity'] === 'hostname')
1821 1864
 	{
1822 1865
 		$listOptions['columns']['banned_entity']['data'] = array(
1823 1866
 			'function' => function($rowData) use ($smcFunc)
@@ -1829,8 +1872,7 @@  discard block
 block discarded – undo
1829 1872
 			'default' => 'bi.hostname',
1830 1873
 			'reverse' => 'bi.hostname DESC',
1831 1874
 		);
1832
-	}
1833
-	elseif ($context['selected_entity'] === 'email')
1875
+	} elseif ($context['selected_entity'] === 'email')
1834 1876
 	{
1835 1877
 		$listOptions['columns']['banned_entity']['data'] = array(
1836 1878
 			'function' => function($rowData) use ($smcFunc)
@@ -1842,8 +1884,7 @@  discard block
 block discarded – undo
1842 1884
 			'default' => 'bi.email_address',
1843 1885
 			'reverse' => 'bi.email_address DESC',
1844 1886
 		);
1845
-	}
1846
-	elseif ($context['selected_entity'] === 'member')
1887
+	} elseif ($context['selected_entity'] === 'member')
1847 1888
 	{
1848 1889
 		$listOptions['columns']['banned_entity']['data'] = array(
1849 1890
 			'sprintf' => array(
@@ -1907,8 +1948,9 @@  discard block
 block discarded – undo
1907 1948
 		)
1908 1949
 	);
1909 1950
 	$ban_triggers = array();
1910
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1911
-		$ban_triggers[] = $row;
1951
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1952
+			$ban_triggers[] = $row;
1953
+	}
1912 1954
 	$smcFunc['db_free_result']($request);
1913 1955
 
1914 1956
 	return $ban_triggers;
@@ -1964,8 +2006,9 @@  discard block
 block discarded – undo
1964 2006
 		validateToken('admin-bl');
1965 2007
 
1966 2008
 		// 'Delete all entries' button was pressed.
1967
-		if (!empty($_POST['removeAll']))
1968
-			removeBanLogs();
2009
+		if (!empty($_POST['removeAll'])) {
2010
+					removeBanLogs();
2011
+		}
1969 2012
 		// 'Delete selection' button was pressed.
1970 2013
 		else
1971 2014
 		{
@@ -2174,12 +2217,15 @@  discard block
 block discarded – undo
2174 2217
 	$low = inet_dtop($low);
2175 2218
 	$high = inet_dtop($high);
2176 2219
 
2177
-	if ($low == '255.255.255.255') return 'unknown';
2178
-	if ($low == $high)
2179
-	    return $low;
2180
-	else
2181
-	    return $low . '-' . $high;
2182
-}
2220
+	if ($low == '255.255.255.255') {
2221
+		return 'unknown';
2222
+	}
2223
+	if ($low == $high) {
2224
+		    return $low;
2225
+	} else {
2226
+		    return $low . '-' . $high;
2227
+	}
2228
+	}
2183 2229
 
2184 2230
 /**
2185 2231
  * Checks whether a given IP range already exists in the trigger list.
@@ -2255,15 +2301,17 @@  discard block
 block discarded – undo
2255 2301
 	$memberEmailWild = array();
2256 2302
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2257 2303
 	{
2258
-		if ($row['id_member'])
2259
-			$memberIDs[$row['id_member']] = $row['id_member'];
2304
+		if ($row['id_member']) {
2305
+					$memberIDs[$row['id_member']] = $row['id_member'];
2306
+		}
2260 2307
 		if ($row['email_address'])
2261 2308
 		{
2262 2309
 			// Does it have a wildcard - if so we can't do a IN on it.
2263
-			if (strpos($row['email_address'], '%') !== false)
2264
-				$memberEmailWild[$row['email_address']] = $row['email_address'];
2265
-			else
2266
-				$memberEmails[$row['email_address']] = $row['email_address'];
2310
+			if (strpos($row['email_address'], '%') !== false) {
2311
+							$memberEmailWild[$row['email_address']] = $row['email_address'];
2312
+			} else {
2313
+							$memberEmails[$row['email_address']] = $row['email_address'];
2314
+			}
2267 2315
 		}
2268 2316
 	}
2269 2317
 	$smcFunc['db_free_result']($request);
@@ -2314,14 +2362,15 @@  discard block
 block discarded – undo
2314 2362
 	}
2315 2363
 
2316 2364
 	// We welcome our new members in the realm of the banned.
2317
-	if (!empty($newMembers))
2318
-		$smcFunc['db_query']('', '
2365
+	if (!empty($newMembers)) {
2366
+			$smcFunc['db_query']('', '
2319 2367
 			DELETE FROM {db_prefix}log_online
2320 2368
 			WHERE id_member IN ({array_int:new_banned_members})',
2321 2369
 			array(
2322 2370
 				'new_banned_members' => $newMembers,
2323 2371
 			)
2324 2372
 		);
2373
+	}
2325 2374
 
2326 2375
 	// Find members that are wrongfully marked as banned.
2327 2376
 	$request = $smcFunc['db_query']('', '
@@ -2348,9 +2397,10 @@  discard block
 block discarded – undo
2348 2397
 	}
2349 2398
 	$smcFunc['db_free_result']($request);
2350 2399
 
2351
-	if (!empty($updates))
2352
-		foreach ($updates as $newStatus => $members)
2400
+	if (!empty($updates)) {
2401
+			foreach ($updates as $newStatus => $members)
2353 2402
 			updateMemberData($members, array('is_activated' => $newStatus));
2403
+	}
2354 2404
 
2355 2405
 	// Update the latest member and our total members as banning may change them.
2356 2406
 	updateStats('member');
Please login to merge, or discard this patch.
Themes/default/ReportedContent.template.php 1 patch
Braces   +66 added lines, -44 removed lines patch added patch discarded remove patch
@@ -18,11 +18,12 @@  discard block
 block discarded – undo
18 18
 	global $context, $txt, $scripturl;
19 19
 
20 20
 	// Let them know the action was a success.
21
-	if (!empty($context['report_post_action']))
22
-		echo '
21
+	if (!empty($context['report_post_action'])) {
22
+			echo '
23 23
 	<div class="infobox">
24 24
 		', $txt['report_action_' . $context['report_post_action']], '
25 25
 	</div>';
26
+	}
26 27
 
27 28
 	echo '
28 29
 	<form id="reported_posts" action="', $scripturl, '?action=moderate;area=reportedposts;sa=show', $context['view_closed'] ? ';closed' : '', ';start=', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 
53 54
 		// Prepare the comments...
54 55
 		$comments = array();
55
-		foreach ($report['comments'] as $comment)
56
-			$comments[$comment['member']['id']] = $comment['member']['link'];
56
+		foreach ($report['comments'] as $comment) {
57
+					$comments[$comment['member']['id']] = $comment['member']['link'];
58
+		}
57 59
 
58 60
 		echo '
59 61
 				', $txt['mc_reportedp_reported_by'], ': ', implode(', ', $comments), '
@@ -69,18 +71,21 @@  discard block
 block discarded – undo
69 71
 				<li><a href="', $scripturl, '?action=moderate;area=reportedposts;sa=handle;closed=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';', $context['mod-report-closed_token_var'], '=', $context['mod-report-closed_token'], '">', $close_button, '</a></li>';
70 72
 
71 73
 		// Delete message button.
72
-		if (!$report['closed'] && (is_array($context['report_remove_any_boards']) && in_array($report['topic']['id_board'], $context['report_remove_any_boards'])))
73
-			echo '
74
+		if (!$report['closed'] && (is_array($context['report_remove_any_boards']) && in_array($report['topic']['id_board'], $context['report_remove_any_boards']))) {
75
+					echo '
74 76
 				<li><a href="', $scripturl, '?action=deletemsg;topic=', $report['topic']['id'], '.0;msg=', $report['topic']['id_msg'], ';modcenter;', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['mc_reportedp_delete_confirm'], '" class="you_sure">', $delete_button, '</a></li>';
77
+		}
75 78
 
76 79
 		// Ban this user button.
77
-		if (!$report['closed'] && !empty($context['report_manage_bans']))
78
-			echo '
80
+		if (!$report['closed'] && !empty($context['report_manage_bans'])) {
81
+					echo '
79 82
 				<li><a href="', $scripturl, '?action=admin;area=ban;sa=add', (!empty($report['author']['id']) ? ';u=' . $report['author']['id'] : ';msg=' . $report['topic']['id_msg']), ';', $context['session_var'], '=', $context['session_id'], '">', $ban_button, '</a></li>';
83
+		}
80 84
 
81
-		if (!$context['view_closed'])
82
-			echo '
85
+		if (!$context['view_closed']) {
86
+					echo '
83 87
 				<li><input type="checkbox" name="close[]" value="' . $report['id'] . '"></li>';
88
+		}
84 89
 
85 90
 		echo '
86 91
 			</ul>
@@ -88,18 +93,20 @@  discard block
 block discarded – undo
88 93
 	}
89 94
 
90 95
 	// Were none found?
91
-	if (empty($context['reports']))
92
-		echo '
96
+	if (empty($context['reports'])) {
97
+			echo '
93 98
 		<div class="windowbg">
94 99
 			<p class="centertext">', $txt['mc_reportedp_none_found'], '</p>
95 100
 		</div>';
101
+	}
96 102
 
97 103
 	echo '
98 104
 		<div class="pagesection">';
99 105
 
100
-	if (!empty($context['total_reports']) && $context['total_reports'] >= $context['reports_how_many'])
101
-		echo '
106
+	if (!empty($context['total_reports']) && $context['total_reports'] >= $context['reports_how_many']) {
107
+			echo '
102 108
 			<div class="pagelinks floatleft">' . $context['page_index'] . '</div>';
109
+	}
103 110
 
104 111
 	echo '
105 112
 			<div class="floatright">', !$context['view_closed'] ? '
@@ -130,18 +137,20 @@  discard block
 block discarded – undo
130 137
 			<div class="modbox">
131 138
 				<ul>';
132 139
 
133
-	foreach ($context['reported_posts'] as $report)
134
-		echo '
140
+	foreach ($context['reported_posts'] as $report) {
141
+			echo '
135 142
 					<li class="smalltext">
136 143
 						<a href="', $report['report_href'], '">', $report['subject'], '</a> ', $txt['mc_reportedp_by'], ' ', $report['author']['link'], '
137 144
 					</li>';
145
+	}
138 146
 
139 147
 	// Don't have any watched users right now?
140
-	if (empty($context['reported_posts']))
141
-		echo '
148
+	if (empty($context['reported_posts'])) {
149
+			echo '
142 150
 					<li>
143 151
 						<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
144 152
 					</li>';
153
+	}
145 154
 
146 155
 	echo '
147 156
 				</ul>
@@ -189,11 +198,12 @@  discard block
 block discarded – undo
189 198
 	global $context, $scripturl, $txt;
190 199
 
191 200
 	// Let them know the action was a success.
192
-	if (!empty($context['report_post_action']))
193
-		echo '
201
+	if (!empty($context['report_post_action'])) {
202
+			echo '
194 203
 	<div class="infobox">
195 204
 		', $txt['report_action_' . $context['report_post_action']], '
196 205
 	</div>';
206
+	}
197 207
 
198 208
 	echo '
199 209
 	<div id="modcenter">
@@ -229,14 +239,15 @@  discard block
 block discarded – undo
229 239
 				<h3 class="catbg">', $txt['mc_modreport_whoreported_title'], '</h3>
230 240
 			</div>';
231 241
 
232
-	foreach ($context['report']['comments'] as $comment)
233
-		echo '
242
+	foreach ($context['report']['comments'] as $comment) {
243
+			echo '
234 244
 			<div class="windowbg">
235 245
 				<p class="smalltext">
236 246
 					', sprintf($txt['mc_modreport_whoreported_data'], $comment['member']['link'] . (empty($comment['member']['id']) && !empty($comment['member']['ip']) ? ' (' . $comment['member']['ip'] . ')' : ''), $comment['time']), '
237 247
 				</p>
238 248
 				<p>', $comment['message'], '</p>
239 249
 			</div>';
250
+	}
240 251
 
241 252
 	echo '
242 253
 			<br>
@@ -245,11 +256,12 @@  discard block
 block discarded – undo
245 256
 			</div>
246 257
 			<div>';
247 258
 
248
-	if (empty($context['report']['mod_comments']))
249
-		echo '
259
+	if (empty($context['report']['mod_comments'])) {
260
+			echo '
250 261
 				<div class="information">
251 262
 					<p class="centertext">', $txt['mc_modreport_no_mod_comment'], '</p>
252 263
 				</div>';
264
+	}
253 265
 
254 266
 	foreach ($context['report']['mod_comments'] as $comment)
255 267
 	{
@@ -335,18 +347,20 @@  discard block
 block discarded – undo
335 347
 			<div class="modbox">
336 348
 				<ul>';
337 349
 
338
-	foreach ($context['reported_members'] as $report)
339
-		echo '
350
+	foreach ($context['reported_members'] as $report) {
351
+			echo '
340 352
 					<li class="smalltext">
341 353
 						<a href="', $report['report_href'], '">', $report['user_name'], '</a>
342 354
 					</li>';
355
+	}
343 356
 
344 357
 	// Don't have any reported members right now?
345
-	if (empty($context['reported_members']))
346
-		echo '
358
+	if (empty($context['reported_members'])) {
359
+			echo '
347 360
 					<li>
348 361
 						<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
349 362
 					</li>';
363
+	}
350 364
 
351 365
 	echo '
352 366
 				</ul>
@@ -394,11 +408,12 @@  discard block
 block discarded – undo
394 408
 	global $context, $txt, $scripturl;
395 409
 
396 410
 	// Let them know the action was a success.
397
-	if (!empty($context['report_post_action']) && !empty($txt['report_action_' . $context['report_post_action']]))
398
-		echo '
411
+	if (!empty($context['report_post_action']) && !empty($txt['report_action_' . $context['report_post_action']])) {
412
+			echo '
399 413
 	<div class="infobox">
400 414
 		', $txt['report_action_' . $context['report_post_action']], '
401 415
 	</div>';
416
+	}
402 417
 
403 418
 	echo '
404 419
 	<form id="reported_members" action="', $scripturl, '?action=moderate;area=reportedmembers;sa=show', $context['view_closed'] ? ';closed' : '', ';start=', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
@@ -430,8 +445,9 @@  discard block
 block discarded – undo
430 445
 
431 446
 		// Prepare the comments...
432 447
 		$comments = array();
433
-		foreach ($report['comments'] as $comment)
434
-			$comments[$comment['member']['id']] = $comment['member']['link'];
448
+		foreach ($report['comments'] as $comment) {
449
+					$comments[$comment['member']['id']] = $comment['member']['link'];
450
+		}
435 451
 
436 452
 		echo '
437 453
 				', $txt['mc_reportedp_reported_by'], ': ', implode(', ', $comments), '
@@ -443,13 +459,15 @@  discard block
 block discarded – undo
443 459
 				<li><a href="', $scripturl, '?action=moderate;area=reportedmembers;sa=handle;closed=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';', $context['mod-report-closed_token_var'], '=', $context['mod-report-closed_token'], '">', $close_button, '</a></li>';
444 460
 
445 461
 		// Ban this user button.
446
-		if (!$report['closed'] && !empty($context['report_manage_bans']) && !empty($report['user']['id']))
447
-			echo '
462
+		if (!$report['closed'] && !empty($context['report_manage_bans']) && !empty($report['user']['id'])) {
463
+					echo '
448 464
 				<li><a href="', $scripturl, '?action=admin;area=ban;sa=add;u=', $report['user']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $ban_button, '</a></li>';
465
+		}
449 466
 
450
-		if (!$context['view_closed'])
451
-			echo '
467
+		if (!$context['view_closed']) {
468
+					echo '
452 469
 				<li><input type="checkbox" name="close[]" value="' . $report['id'] . '"></li>';
470
+		}
453 471
 
454 472
 			echo '
455 473
 			</ul>
@@ -457,11 +475,12 @@  discard block
 block discarded – undo
457 475
 	}
458 476
 
459 477
 	// Were none found?
460
-	if (empty($context['reports']))
461
-		echo '
478
+	if (empty($context['reports'])) {
479
+			echo '
462 480
 		<div class="windowbg">
463 481
 			<p class="centertext">', $txt['mc_reportedp_none_found'], '</p>
464 482
 		</div>';
483
+	}
465 484
 
466 485
 	echo '
467 486
 		<div class="pagesection">
@@ -482,11 +501,12 @@  discard block
 block discarded – undo
482 501
 	global $context, $scripturl, $txt;
483 502
 
484 503
 	// Let them know the action was a success.
485
-	if (!empty($context['report_post_action']))
486
-		echo '
504
+	if (!empty($context['report_post_action'])) {
505
+			echo '
487 506
 	<div class="infobox">
488 507
 		', $txt['report_action_' . $context['report_post_action']], '
489 508
 	</div>';
509
+	}
490 510
 
491 511
 	echo '
492 512
 	<div id="modcenter">
@@ -519,14 +539,15 @@  discard block
 block discarded – undo
519 539
 				<h3 class="catbg">', $txt['mc_memberreport_whoreported_title'], '</h3>
520 540
 			</div>';
521 541
 
522
-	foreach ($context['report']['comments'] as $comment)
523
-		echo '
542
+	foreach ($context['report']['comments'] as $comment) {
543
+			echo '
524 544
 			<div class="windowbg">
525 545
 				<p class="smalltext">
526 546
 					', sprintf($txt['mc_modreport_whoreported_data'], $comment['member']['link'] . (empty($comment['member']['id']) && !empty($comment['member']['ip']) ? ' (' . $comment['member']['ip'] . ')' : ''), $comment['time']), '
527 547
 				</p>
528 548
 				<p>', $comment['message'], '</p>
529 549
 			</div>';
550
+	}
530 551
 
531 552
 	echo '
532 553
 			<br>
@@ -535,11 +556,12 @@  discard block
 block discarded – undo
535 556
 			</div>
536 557
 			<div>';
537 558
 
538
-	if (empty($context['report']['mod_comments']))
539
-		echo '
559
+	if (empty($context['report']['mod_comments'])) {
560
+			echo '
540 561
 				<div class="information">
541 562
 					<p class="centertext">', $txt['mc_modreport_no_mod_comment'], '</p>
542 563
 				</div>';
564
+	}
543 565
 
544 566
 	foreach ($context['report']['mod_comments'] as $comment)
545 567
 	{
Please login to merge, or discard this patch.
Themes/default/ManageCalendar.template.php 1 patch
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,9 +40,10 @@  discard block
 block discarded – undo
40 40
 							<option value="0000"', $context['holiday']['year'] == '0000' ? ' selected' : '', '>', $txt['every_year'], '</option>';
41 41
 
42 42
 	// Show a list of all the years we allow...
43
-	for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
44
-		echo '
43
+	for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++) {
44
+			echo '
45 45
 							<option value="', $year, '"', $year == $context['holiday']['year'] ? ' selected' : '', '>', $year, '</option>';
46
+	}
46 47
 
47 48
 	echo '
48 49
 						</select>
@@ -50,9 +51,10 @@  discard block
 block discarded – undo
50 51
 						<select name="month" id="month" onchange="generateDays();">';
51 52
 
52 53
 	// There are 12 months per year - ensure that they all get listed.
53
-	for ($month = 1; $month <= 12; $month++)
54
-		echo '
54
+	for ($month = 1; $month <= 12; $month++) {
55
+			echo '
55 56
 							<option value="', $month, '"', $month == $context['holiday']['month'] ? ' selected' : '', '>', $txt['months'][$month], '</option>';
57
+	}
56 58
 
57 59
 	echo '
58 60
 						</select>
@@ -60,23 +62,25 @@  discard block
 block discarded – undo
60 62
 						<select name="day" id="day" onchange="generateDays();">';
61 63
 
62 64
 	// This prints out all the days in the current month - this changes dynamically as we switch months.
63
-	for ($day = 1; $day <= $context['holiday']['last_day']; $day++)
64
-		echo '
65
+	for ($day = 1; $day <= $context['holiday']['last_day']; $day++) {
66
+			echo '
65 67
 							<option value="', $day, '"', $day == $context['holiday']['day'] ? ' selected' : '', '>', $day, '</option>';
68
+	}
66 69
 
67 70
 	echo '
68 71
 						</select>
69 72
 					</dd>
70 73
 				</dl>';
71 74
 
72
-	if ($context['is_new'])
73
-		echo '
75
+	if ($context['is_new']) {
76
+			echo '
74 77
 				<input type="submit" value="', $txt['holidays_button_add'], '" class="button">';
75
-	else
76
-		echo '
78
+	} else {
79
+			echo '
77 80
 				<input type="submit" name="edit" value="', $txt['holidays_button_edit'], '" class="button">
78 81
 				<input type="submit" name="delete" value="', $txt['holidays_button_remove'], '" class="button">
79 82
 				<input type="hidden" name="holiday" value="', $context['holiday']['id'], '">';
83
+	}
80 84
 	echo '
81 85
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
82 86
 			</div><!-- .windowbg -->
Please login to merge, or discard this patch.
Themes/default/MoveTopic.template.php 1 patch
Braces   +32 added lines, -23 removed lines patch added patch discarded remove patch
@@ -37,9 +37,10 @@  discard block
 block discarded – undo
37 37
 		echo '
38 38
 								<optgroup label="', $category['name'], '">';
39 39
 
40
-		foreach ($category['boards'] as $board)
41
-			echo '
40
+		foreach ($category['boards'] as $board) {
41
+					echo '
42 42
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', $board['id'] == $context['current_board'] ? ' disabled' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level']-1) . '=&gt; ' : '', $board['name'], '</option>';
43
+		}
43 44
 		echo '
44 45
 								</optgroup>';
45 46
 	}
@@ -70,9 +71,10 @@  discard block
 block discarded – undo
70 71
 				</div><!-- .move_topic -->
71 72
 			</div><!-- .windowbg -->';
72 73
 
73
-	if ($context['back_to_topic'])
74
-		echo '
74
+	if ($context['back_to_topic']) {
75
+			echo '
75 76
 			<input type="hidden" name="goback" value="1">';
77
+	}
76 78
 
77 79
 	echo '
78 80
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -125,10 +127,10 @@  discard block
 block discarded – undo
125 127
 									<option value="86400">', $txt['two_months'], '</option>
126 128
 								</select>
127 129
 							</dd>';
128
-	}
129
-	else
130
-		echo '
130
+	} else {
131
+			echo '
131 132
 							<input type="hidden" name="redirect_expires" value="0">';
133
+	}
132 134
 
133 135
 	echo '
134 136
 						</dl>
@@ -207,9 +209,10 @@  discard block
 block discarded – undo
207 209
 			echo '
208 210
 							<optgroup label="', $cat['name'], '">';
209 211
 
210
-			foreach ($cat['boards'] as $board)
211
-				echo '
212
+			foreach ($cat['boards'] as $board) {
213
+							echo '
212 214
 								<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
215
+			}
213 216
 
214 217
 			echo '
215 218
 							</optgroup>';
@@ -219,9 +222,9 @@  discard block
 block discarded – undo
219 222
 						<input type="hidden" name="from" value="' . $context['origin_topic'] . '">
220 223
 						<input type="submit" value="', $txt['go'], '" class="button">
221 224
 					</form>';
225
+	} else {
226
+			echo $txt['target_below'];
222 227
 	}
223
-	else
224
-		echo $txt['target_below'];
225 228
 
226 229
 	echo '		</h4>
227 230
 			</div><!-- .title_bar -->
@@ -239,12 +242,13 @@  discard block
 block discarded – undo
239 242
 
240 243
 		$merge_button = create_button('merge', 'merge', '');
241 244
 
242
-		foreach ($context['topics'] as $topic)
243
-			echo '
245
+		foreach ($context['topics'] as $topic) {
246
+					echo '
244 247
 						<li>
245 248
 							<a href="', $scripturl, '?action=mergetopics;sa=options;board=', $context['current_board'], '.0;from=', $context['origin_topic'], ';to=', $topic['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $merge_button, '</a>
246 249
 							<a href="', $scripturl, '?topic=', $topic['id'], '.0" target="_blank" rel="noopener">', $topic['subject'], '</a> ', $txt['started_by'], ' ', $topic['poster']['link'], '
247 250
 						</li>';
251
+		}
248 252
 
249 253
 		echo '
250 254
 					</ul>
@@ -255,9 +259,10 @@  discard block
 block discarded – undo
255 259
 				</div>';
256 260
 	}
257 261
 	// Just a nice "There aren't any topics" message
258
-	else
259
-		echo '
262
+	else {
263
+			echo '
260 264
 				<div class="windowbg">', $txt['topic_alert_none'], '</div>';
265
+	}
261 266
 
262 267
 	echo '
263 268
 				<br>
@@ -307,8 +312,8 @@  discard block
 block discarded – undo
307 312
 				</thead>
308 313
 				<tbody>';
309 314
 
310
-	foreach ($context['topics'] as $topic)
311
-		echo '
315
+	foreach ($context['topics'] as $topic) {
316
+			echo '
312 317
 					<tr class="windowbg">
313 318
 						<td>
314 319
 							<input type="checkbox" name="topics[]" value="' . $topic['id'] . '" checked>
@@ -328,6 +333,7 @@  discard block
 block discarded – undo
328 333
 							<input type="checkbox" name="notifications[]" value="' . $topic['id'] . '" checked>
329 334
 						</td>
330 335
 					</tr>';
336
+	}
331 337
 	echo '
332 338
 				</tbody>
333 339
 			</table>
@@ -337,9 +343,10 @@  discard block
 block discarded – undo
337 343
 					<legend>', $txt['merge_select_subject'], '</legend>
338 344
 					<select name="subject" onchange="this.form.custom_subject.style.display = (this.options[this.selectedIndex].value != 0) ? \'none\': \'\' ;">';
339 345
 
340
-	foreach ($context['topics'] as $topic)
341
-		echo '
346
+	foreach ($context['topics'] as $topic) {
347
+			echo '
342 348
 						<option value="', $topic['id'], '"' . ($topic['selected'] ? ' selected' : '') . '>', $topic['subject'], '</option>';
349
+	}
343 350
 	echo '
344 351
 						<option value="0">', $txt['merge_custom_subject'], ':</option>
345 352
 					</select>
@@ -358,11 +365,12 @@  discard block
 block discarded – undo
358 365
 					<legend>', $txt['merge_select_target_board'], '</legend>
359 366
 					<ul>';
360 367
 
361
-		foreach ($context['boards'] as $board)
362
-			echo '
368
+		foreach ($context['boards'] as $board) {
369
+					echo '
363 370
 						<li>
364 371
 							<input type="radio" name="board" value="' . $board['id'] . '"' . ($board['selected'] ? ' checked' : '') . '> ' . $board['name'] . '
365 372
 						</li>';
373
+		}
366 374
 		echo '
367 375
 					</ul>
368 376
 				</fieldset>';
@@ -374,11 +382,12 @@  discard block
 block discarded – undo
374 382
 					<legend>' . $txt['merge_select_poll'] . '</legend>
375 383
 					<ul>';
376 384
 
377
-		foreach ($context['polls'] as $poll)
378
-			echo '
385
+		foreach ($context['polls'] as $poll) {
386
+					echo '
379 387
 						<li>
380 388
 							<input type="radio" name="poll" value="' . $poll['id'] . '"' . ($poll['selected'] ? ' checked' : '') . '> ' . $poll['question'] . ' (' . $txt['topic'] . ': <a href="' . $scripturl . '?topic=' . $poll['topic']['id'] . '.0" target="_blank" rel="noopener">' . $poll['topic']['subject'] . '</a>)
381 389
 						</li>';
390
+		}
382 391
 		echo '
383 392
 						<li>
384 393
 							<input type="radio" name="poll" value="-1"> (' . $txt['merge_no_poll'] . ')
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +182 added lines, -132 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -170,16 +181,19 @@  discard block
 block discarded – undo
170 181
 		if (in_array('website', $reg_fields))
171 182
 		{
172 183
 			unset($reg_fields['website']);
173
-			if (isset($_POST['website_title']))
174
-				$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
175
-			if (isset($_POST['website_url']))
176
-				$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
184
+			if (isset($_POST['website_title'])) {
185
+							$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
186
+			}
187
+			if (isset($_POST['website_url'])) {
188
+							$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
189
+			}
177 190
 		}
178 191
 
179 192
 		// We might have had some submissions on this front - go check.
180
-		foreach ($reg_fields as $field)
181
-			if (isset($_POST[$field]))
193
+		foreach ($reg_fields as $field) {
194
+					if (isset($_POST[$field]))
182 195
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
196
+		}
183 197
 
184 198
 		// Load all the fields in question.
185 199
 		setupProfileContext($reg_fields);
@@ -196,8 +210,9 @@  discard block
 block discarded – undo
196 210
 		$context['visual_verification_id'] = $verificationOptions['id'];
197 211
 	}
198 212
 	// Otherwise we have nothing to show.
199
-	else
200
-		$context['visual_verification'] = false;
213
+	else {
214
+			$context['visual_verification'] = false;
215
+	}
201 216
 
202 217
 
203 218
 	$context += array(
@@ -208,8 +223,9 @@  discard block
 block discarded – undo
208 223
 
209 224
 	// Were there any errors?
210 225
 	$context['registration_errors'] = array();
211
-	if (!empty($reg_errors))
212
-		$context['registration_errors'] = $reg_errors;
226
+	if (!empty($reg_errors)) {
227
+			$context['registration_errors'] = $reg_errors;
228
+	}
213 229
 
214 230
 	createToken('register');
215 231
 }
@@ -226,27 +242,32 @@  discard block
 block discarded – undo
226 242
 	validateToken('register');
227 243
 
228 244
 	// Check to ensure we're forcing SSL for authentication
229
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
230
-		fatal_lang_error('register_ssl_required');
245
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
246
+			fatal_lang_error('register_ssl_required');
247
+	}
231 248
 
232 249
 	// Start collecting together any errors.
233 250
 	$reg_errors = array();
234 251
 
235 252
 	// You can't register if it's disabled.
236
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
237
-		fatal_lang_error('registration_disabled', false);
253
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
254
+			fatal_lang_error('registration_disabled', false);
255
+	}
238 256
 
239 257
 	// Well, if you don't agree, you can't register.
240
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
241
-		redirectexit();
258
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
259
+			redirectexit();
260
+	}
242 261
 
243 262
 	// Make sure they came from *somewhere*, have a session.
244
-	if (!isset($_SESSION['old_url']))
245
-		redirectexit('action=signup');
263
+	if (!isset($_SESSION['old_url'])) {
264
+			redirectexit('action=signup');
265
+	}
246 266
 
247 267
 	// If we don't require an agreement, we need a extra check for coppa.
248
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
249
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
268
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
269
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
270
+	}
250 271
 	// Are they under age, and under age users are banned?
251 272
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
252 273
 	{
@@ -255,8 +276,9 @@  discard block
 block discarded – undo
255 276
 	}
256 277
 
257 278
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
258
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
259
-		redirectexit('action=signup');
279
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
280
+			redirectexit('action=signup');
281
+	}
260 282
 	// Failing that, check the time on it.
261 283
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
262 284
 	{
@@ -276,8 +298,9 @@  discard block
 block discarded – undo
276 298
 		if (is_array($context['visual_verification']))
277 299
 		{
278 300
 			loadLanguage('Errors');
279
-			foreach ($context['visual_verification'] as $error)
280
-				$reg_errors[] = $txt['error_' . $error];
301
+			foreach ($context['visual_verification'] as $error) {
302
+							$reg_errors[] = $txt['error_' . $error];
303
+			}
281 304
 		}
282 305
 	}
283 306
 
@@ -286,14 +309,16 @@  discard block
 block discarded – undo
286 309
 		if (!is_array($_POST[$key]))
287 310
 		{
288 311
 			// For UTF-8, replace any kind of space with a normal space, and remove any kind of control character (incl. "\n" and "\r"), then trim.
289
-			if ($context['utf8'])
290
-				$_POST[$key] = $smcFunc['htmltrim'](preg_replace(array('~\p{Z}+~u', '~\p{C}+~u'), array(' ', ''), $_POST[$key]));
312
+			if ($context['utf8']) {
313
+							$_POST[$key] = $smcFunc['htmltrim'](preg_replace(array('~\p{Z}+~u', '~\p{C}+~u'), array(' ', ''), $_POST[$key]));
314
+			}
291 315
 			// Otherwise, just remove "\n" and "\r", then trim.
292
-			else
293
-				$_POST[$key] = $smcFunc['htmltrim'](str_replace(array("\n", "\r"), '', $_POST[$key]));
316
+			else {
317
+							$_POST[$key] = $smcFunc['htmltrim'](str_replace(array("\n", "\r"), '', $_POST[$key]));
318
+			}
319
+		} else {
320
+					$_POST[$key] = htmltrim__recursive($_POST[$key]);
294 321
 		}
295
-		else
296
-			$_POST[$key] = htmltrim__recursive($_POST[$key]);
297 322
 	}
298 323
 
299 324
 	// Collect all extra registration fields someone might have filled in.
@@ -328,13 +353,15 @@  discard block
 block discarded – undo
328 353
 			$possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings);
329 354
 
330 355
 			// Make sure their website URL is squeaky clean
331
-			if (isset($_POST['website_url']))
332
-				$_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url']));
356
+			if (isset($_POST['website_url'])) {
357
+							$_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url']));
358
+			}
333 359
 		}
334 360
 	}
335 361
 
336
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
337
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
362
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
363
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
364
+	}
338 365
 
339 366
 	// Needed for isReservedName() and registerMember().
340 367
 	require_once($sourcedir . '/Subs-Members.php');
@@ -343,8 +370,9 @@  discard block
 block discarded – undo
343 370
 	if (isset($_POST['real_name']))
344 371
 	{
345 372
 		// Are you already allowed to edit the displayed name?
346
-		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))
347
-			$canEditDisplayName = true;
373
+		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) {
374
+					$canEditDisplayName = true;
375
+		}
348 376
 
349 377
 		// If you are a guest, will you be allowed to once you register?
350 378
 		else
@@ -363,32 +391,37 @@  discard block
 block discarded – undo
363 391
 		}
364 392
 
365 393
 		// Only set it if you can and if we are sure it is good
366
-		if ($canEditDisplayName && $smcFunc['htmltrim']($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
367
-				$possible_strings[] = 'real_name';
394
+		if ($canEditDisplayName && $smcFunc['htmltrim']($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
395
+						$possible_strings[] = 'real_name';
396
+		}
368 397
 	}
369 398
 
370 399
 	// Handle a string as a birthdate...
371
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
372
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
400
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
401
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
402
+	}
373 403
 	// Or birthdate parts...
374
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
375
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
404
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
405
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
406
+	}
376 407
 
377 408
 	// Validate the passed language file.
378 409
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
379 410
 	{
380 411
 		// Do we have any languages?
381
-		if (empty($context['languages']))
382
-			getLanguages();
412
+		if (empty($context['languages'])) {
413
+					getLanguages();
414
+		}
383 415
 
384 416
 		// Did we find it?
385
-		if (isset($context['languages'][$_POST['lngfile']]))
386
-			$_SESSION['language'] = $_POST['lngfile'];
387
-		else
417
+		if (isset($context['languages'][$_POST['lngfile']])) {
418
+					$_SESSION['language'] = $_POST['lngfile'];
419
+		} else {
420
+					unset($_POST['lngfile']);
421
+		}
422
+	} else {
388 423
 			unset($_POST['lngfile']);
389 424
 	}
390
-	else
391
-		unset($_POST['lngfile']);
392 425
 
393 426
 	// Set the options needed for registration.
394 427
 	$regOptions = array(
@@ -408,22 +441,27 @@  discard block
 block discarded – undo
408 441
 	);
409 442
 
410 443
 	// Include the additional options that might have been filled in.
411
-	foreach ($possible_strings as $var)
412
-		if (isset($_POST[$var]))
444
+	foreach ($possible_strings as $var) {
445
+			if (isset($_POST[$var]))
413 446
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
414
-	foreach ($possible_ints as $var)
415
-		if (isset($_POST[$var]))
447
+	}
448
+	foreach ($possible_ints as $var) {
449
+			if (isset($_POST[$var]))
416 450
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
417
-	foreach ($possible_floats as $var)
418
-		if (isset($_POST[$var]))
451
+	}
452
+	foreach ($possible_floats as $var) {
453
+			if (isset($_POST[$var]))
419 454
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
420
-	foreach ($possible_bools as $var)
421
-		if (isset($_POST[$var]))
455
+	}
456
+	foreach ($possible_bools as $var) {
457
+			if (isset($_POST[$var]))
422 458
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
459
+	}
423 460
 
424 461
 	// Registration options are always default options...
425
-	if (isset($_POST['default_options']))
426
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
462
+	if (isset($_POST['default_options'])) {
463
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
464
+	}
427 465
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
428 466
 
429 467
 	// Make sure they are clean, dammit!
@@ -443,12 +481,14 @@  discard block
 block discarded – undo
443 481
 	while ($row = $smcFunc['db_fetch_assoc']($request))
444 482
 	{
445 483
 		// Don't allow overriding of the theme variables.
446
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
447
-			unset($regOptions['theme_vars'][$row['col_name']]);
484
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
485
+					unset($regOptions['theme_vars'][$row['col_name']]);
486
+		}
448 487
 
449 488
 		// Not actually showing it then?
450
-		if (!$row['show_reg'])
451
-			continue;
489
+		if (!$row['show_reg']) {
490
+					continue;
491
+		}
452 492
 
453 493
 		// Prepare the value!
454 494
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -457,24 +497,27 @@  discard block
 block discarded – undo
457 497
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
458 498
 		{
459 499
 			// Is it too long?
460
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
461
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
500
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
501
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
502
+			}
462 503
 
463 504
 			// Any masks to apply?
464 505
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
465 506
 			{
466
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
467
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
468
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
469
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
470
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
471
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
507
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
508
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
509
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
510
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
511
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
512
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
513
+				}
472 514
 			}
473 515
 		}
474 516
 
475 517
 		// Is this required but not there?
476
-		if (trim($value) == '' && $row['show_reg'] > 1)
477
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
518
+		if (trim($value) == '' && $row['show_reg'] > 1) {
519
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
520
+		}
478 521
 	}
479 522
 	$smcFunc['db_free_result']($request);
480 523
 
@@ -482,8 +525,9 @@  discard block
 block discarded – undo
482 525
 	if (!empty($custom_field_errors))
483 526
 	{
484 527
 		loadLanguage('Errors');
485
-		foreach ($custom_field_errors as $error)
486
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
528
+		foreach ($custom_field_errors as $error) {
529
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
530
+		}
487 531
 	}
488 532
 
489 533
 	// Lets check for other errors before trying to register the member.
@@ -528,8 +572,9 @@  discard block
 block discarded – undo
528 572
 	}
529 573
 
530 574
 	// If COPPA has been selected then things get complicated, setup the template.
531
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
532
-		redirectexit('action=coppa;member=' . $memberID);
575
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
576
+			redirectexit('action=coppa;member=' . $memberID);
577
+	}
533 578
 	// Basic template variable setup.
534 579
 	elseif (!empty($modSettings['registration_method']))
535 580
 	{
@@ -541,8 +586,7 @@  discard block
 block discarded – undo
541 586
 			'sub_template' => 'after',
542 587
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
543 588
 		);
544
-	}
545
-	else
589
+	} else
546 590
 	{
547 591
 		call_integration_hook('integrate_activate', array($regOptions['username']));
548 592
 
@@ -562,16 +606,18 @@  discard block
 block discarded – undo
562 606
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
563 607
 
564 608
 	// Logged in users should not bother to activate their accounts
565
-	if (!empty($user_info['id']))
566
-		redirectexit();
609
+	if (!empty($user_info['id'])) {
610
+			redirectexit();
611
+	}
567 612
 
568 613
 	loadLanguage('Login');
569 614
 	loadTemplate('Login');
570 615
 
571 616
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
572 617
 	{
573
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
574
-			fatal_lang_error('no_access', false);
618
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
619
+					fatal_lang_error('no_access', false);
620
+		}
575 621
 
576 622
 		$context['member_id'] = 0;
577 623
 		$context['sub_template'] = 'resend';
@@ -611,11 +657,13 @@  discard block
 block discarded – undo
611 657
 	// Change their email address? (they probably tried a fake one first :P.)
612 658
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
613 659
 	{
614
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
615
-			fatal_lang_error('no_access', false);
660
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
661
+					fatal_lang_error('no_access', false);
662
+		}
616 663
 
617
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
618
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
664
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
665
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
666
+		}
619 667
 
620 668
 		// Make sure their email isn't banned.
621 669
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -631,8 +679,9 @@  discard block
 block discarded – undo
631 679
 			)
632 680
 		);
633 681
 
634
-		if ($smcFunc['db_num_rows']($request) != 0)
635
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
682
+		if ($smcFunc['db_num_rows']($request) != 0) {
683
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
684
+		}
636 685
 		$smcFunc['db_free_result']($request);
637 686
 
638 687
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -670,9 +719,9 @@  discard block
 block discarded – undo
670 719
 	// Quit if this code is not right.
671 720
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
672 721
 	{
673
-		if (!empty($row['is_activated']))
674
-			fatal_lang_error('already_activated', false);
675
-		elseif ($row['validation_code'] == '')
722
+		if (!empty($row['is_activated'])) {
723
+					fatal_lang_error('already_activated', false);
724
+		} elseif ($row['validation_code'] == '')
676 725
 		{
677 726
 			loadLanguage('Profile');
678 727
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -722,8 +771,9 @@  discard block
 block discarded – undo
722 771
 	loadTemplate('Register');
723 772
 
724 773
 	// No User ID??
725
-	if (!isset($_GET['member']))
726
-		fatal_lang_error('no_access', false);
774
+	if (!isset($_GET['member'])) {
775
+			fatal_lang_error('no_access', false);
776
+	}
727 777
 
728 778
 	// Get the user details...
729 779
 	$request = $smcFunc['db_query']('', '
@@ -736,8 +786,9 @@  discard block
 block discarded – undo
736 786
 			'is_coppa' => 5,
737 787
 		)
738 788
 	);
739
-	if ($smcFunc['db_num_rows']($request) == 0)
740
-		fatal_lang_error('no_access', false);
789
+	if ($smcFunc['db_num_rows']($request) == 0) {
790
+			fatal_lang_error('no_access', false);
791
+	}
741 792
 	list ($username) = $smcFunc['db_fetch_row']($request);
742 793
 	$smcFunc['db_free_result']($request);
743 794
 
@@ -775,8 +826,7 @@  discard block
 block discarded – undo
775 826
 			echo $data;
776 827
 			obExit(false);
777 828
 		}
778
-	}
779
-	else
829
+	} else
780 830
 	{
781 831
 		$context += array(
782 832
 			'page_title' => $txt['coppa_title'],
@@ -829,8 +879,9 @@  discard block
 block discarded – undo
829 879
 	{
830 880
 		require_once($sourcedir . '/Subs-Graphics.php');
831 881
 
832
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
833
-			send_http_status(400);
882
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
883
+					send_http_status(400);
884
+		}
834 885
 
835 886
 		// Otherwise just show a pre-defined letter.
836 887
 		elseif (isset($_REQUEST['letter']))
@@ -848,14 +899,13 @@  discard block
 block discarded – undo
848 899
 			header('content-type: image/gif');
849 900
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
850 901
 		}
851
-	}
852
-
853
-	elseif ($_REQUEST['format'] === '.wav')
902
+	} elseif ($_REQUEST['format'] === '.wav')
854 903
 	{
855 904
 		require_once($sourcedir . '/Subs-Sound.php');
856 905
 
857
-		if (!createWaveFile($code))
858
-			send_http_status(400);
906
+		if (!createWaveFile($code)) {
907
+					send_http_status(400);
908
+		}
859 909
 	}
860 910
 
861 911
 	// We all die one day...
Please login to merge, or discard this patch.
Sources/Subs-Sound.php 1 patch
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(send_http_status(400));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(send_http_status(400));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -42,16 +44,19 @@  discard block
 block discarded – undo
42 44
 	mt_srand(end($tmp));
43 45
 
44 46
 	// Try to see if there's a sound font in the user's language.
45
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
46
-		$sound_language = $user_info['language'];
47
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
48
+			$sound_language = $user_info['language'];
49
+	}
47 50
 
48 51
 	// English should be there.
49
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
50
-		$sound_language = 'english';
52
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
53
+			$sound_language = 'english';
54
+	}
51 55
 
52 56
 	// Guess not...
53
-	else
54
-		return false;
57
+	else {
58
+			return false;
59
+	}
55 60
 
56 61
 	// File names are in lower case so lets make sure that we are only using a lower case string
57 62
 	$word = strtolower($word);
@@ -61,20 +66,25 @@  discard block
 block discarded – undo
61 66
 	for ($i = 0; $i < strlen($word); $i++)
62 67
 	{
63 68
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
64
-		if (strpos($sound_letter, 'data') === false)
65
-			return false;
69
+		if (strpos($sound_letter, 'data') === false) {
70
+					return false;
71
+		}
66 72
 
67 73
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
68 74
 		switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
69 75
 		{
70
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
71
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
72
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
76
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
77
+								for ($k = 0, $m = round(mt_rand(15, 25) / 10);
78
+			}
79
+			$k < $m; $k++) {
80
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
81
+					}
73 82
 			break;
74 83
 
75 84
 			case 1:
76
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
77
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
85
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
86
+									$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
87
+				}
78 88
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
79 89
 			break;
80 90
 
@@ -82,10 +92,12 @@  discard block
 block discarded – undo
82 92
 				$shift = 0;
83 93
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
84 94
 				{
85
-					if (mt_rand(0, 10) === 0)
86
-						$shift += mt_rand(-3, 3);
87
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
88
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
95
+					if (mt_rand(0, 10) === 0) {
96
+											$shift += mt_rand(-3, 3);
97
+					}
98
+					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) {
99
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
100
+					}
89 101
 				}
90 102
 			break;
91 103
 		}
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 1 patch
Braces   +59 added lines, -52 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
  * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count.
@@ -40,11 +41,11 @@  discard block
 block discarded – undo
40 41
 
41 42
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
42 43
 	{
43
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
44
-			$modSettings['enableCompressedOutput'] = 0;
45
-
46
-		else
47
-			ob_start('ob_gzhandler');
44
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
45
+					$modSettings['enableCompressedOutput'] = 0;
46
+		} else {
47
+					ob_start('ob_gzhandler');
48
+		}
48 49
 	}
49 50
 
50 51
 	if (empty($modSettings['enableCompressedOutput']))
@@ -76,8 +77,9 @@  discard block
 block discarded – undo
76 77
 	}
77 78
 
78 79
 	// Use cache when possible.
79
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
80
-		list($file, $thumbFile) = $cache;
80
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
81
+			list($file, $thumbFile) = $cache;
82
+	}
81 83
 
82 84
 	// Get the info from the DB.
83 85
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -85,10 +87,9 @@  discard block
 block discarded – undo
85 87
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
86 88
 		$attachRequest = null;
87 89
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
88
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
89
-			$request = $attachRequest;
90
-
91
-		else
90
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
91
+					$request = $attachRequest;
92
+		} else
92 93
 		{
93 94
 			// Make sure this attachment is on this board and load its info while we are at it.
94 95
 			$request = $smcFunc['db_query']('', '
@@ -181,13 +182,15 @@  discard block
 block discarded – undo
181 182
 		}
182 183
 
183 184
 		// Cache it.
184
-		if (!empty($file) || !empty($thumbFile))
185
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
185
+		if (!empty($file) || !empty($thumbFile)) {
186
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
187
+		}
186 188
 	}
187 189
 
188 190
 	// Replace the normal file with its thumbnail if it has one!
189
-	if (!empty($showThumb) && !empty($thumbFile))
190
-		$file = $thumbFile;
191
+	if (!empty($showThumb) && !empty($thumbFile)) {
192
+			$file = $thumbFile;
193
+	}
191 194
 
192 195
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
193 196
 	if (!file_exists($file['filePath']))
@@ -237,8 +240,8 @@  discard block
 block discarded – undo
237 240
 	}
238 241
 
239 242
 	// Update the download counter (unless it's a thumbnail or resuming an incomplete download).
240
-	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0)
241
-		$smcFunc['db_query']('', '
243
+	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) {
244
+			$smcFunc['db_query']('', '
242 245
 			UPDATE {db_prefix}attachments
243 246
 			SET downloads = downloads + 1
244 247
 			WHERE id_attach = {int:id_attach}',
@@ -246,12 +249,14 @@  discard block
 block discarded – undo
246 249
 				'id_attach' => $attachId,
247 250
 			)
248 251
 		);
252
+	}
249 253
 
250 254
 	// Send the attachment headers.
251 255
 	header('pragma: ');
252 256
 
253
-	if (!isBrowser('gecko'))
254
-		header('content-transfer-encoding: binary');
257
+	if (!isBrowser('gecko')) {
258
+			header('content-transfer-encoding: binary');
259
+	}
255 260
 
256 261
 	header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
257 262
 	header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -260,18 +265,19 @@  discard block
 block discarded – undo
260 265
 	header('etag: ' . $eTag);
261 266
 
262 267
 	// Make sure the mime type warrants an inline display.
263
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
264
-		unset($_REQUEST['image']);
268
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
269
+			unset($_REQUEST['image']);
270
+	}
265 271
 
266 272
 	// Does this have a mime type?
267
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
268
-		header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
269
-
270
-	else
273
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
274
+			header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
275
+	} else
271 276
 	{
272 277
 		header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
273
-		if (isset($_REQUEST['image']))
274
-			unset($_REQUEST['image']);
278
+		if (isset($_REQUEST['image'])) {
279
+					unset($_REQUEST['image']);
280
+		}
275 281
 	}
276 282
 
277 283
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -279,24 +285,22 @@  discard block
 block discarded – undo
279 285
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
280 286
 
281 287
 	// Different browsers like different standards...
282
-	if (isBrowser('firefox'))
283
-		header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
284
-
285
-	elseif (isBrowser('opera'))
286
-		header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
287
-
288
-	elseif (isBrowser('ie'))
289
-		header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
290
-
291
-	else
292
-		header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"');
288
+	if (isBrowser('firefox')) {
289
+			header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
290
+	} elseif (isBrowser('opera')) {
291
+			header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
292
+	} elseif (isBrowser('ie')) {
293
+			header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
294
+	} else {
295
+			header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"');
296
+	}
293 297
 
294 298
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
295
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
296
-		header('cache-control: no-cache');
297
-
298
-	else
299
-		header('cache-control: max-age=' . (525600 * 60) . ', private');
299
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
300
+			header('cache-control: no-cache');
301
+	} else {
302
+			header('cache-control: max-age=' . (525600 * 60) . ', private');
303
+	}
300 304
 
301 305
 	// Multipart and resuming support
302 306
 	if (isset($_SERVER['HTTP_RANGE']))
@@ -304,9 +308,9 @@  discard block
 block discarded – undo
304 308
 		send_http_status(206);
305 309
 		header("content-length: $new_length");
306 310
 		header("content-range: bytes $range-$range_end/$size");
311
+	} else {
312
+			header("content-length: " . $size);
307 313
 	}
308
-	else
309
-		header("content-length: " . $size);
310 314
 
311 315
 
312 316
 	// Try to buy some time...
@@ -315,8 +319,9 @@  discard block
 block discarded – undo
315 319
 	// For multipart/resumable downloads, send the requested chunk(s) of the file
316 320
 	if (isset($_SERVER['HTTP_RANGE']))
317 321
 	{
318
-		while (@ob_get_level() > 0)
319
-			@ob_end_clean();
322
+		while (@ob_get_level() > 0) {
323
+					@ob_end_clean();
324
+		}
320 325
 
321 326
 		// 40 kilobytes is a good-ish amount
322 327
 		$chunksize = 40 * 1024;
@@ -340,8 +345,9 @@  discard block
 block discarded – undo
340 345
 	elseif ($size > 4194304)
341 346
 	{
342 347
 		// Forcibly end any output buffering going on.
343
-		while (@ob_get_level() > 0)
344
-			@ob_end_clean();
348
+		while (@ob_get_level() > 0) {
349
+					@ob_end_clean();
350
+		}
345 351
 
346 352
 		$fp = fopen($file['filePath'], 'rb');
347 353
 		while (!feof($fp))
@@ -353,8 +359,9 @@  discard block
 block discarded – undo
353 359
 	}
354 360
 
355 361
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
356
-	elseif (@readfile($file['filePath']) === null)
357
-		echo file_get_contents($file['filePath']);
362
+	elseif (@readfile($file['filePath']) === null) {
363
+			echo file_get_contents($file['filePath']);
364
+	}
358 365
 
359 366
 	die();
360 367
 }
Please login to merge, or discard this patch.
Sources/Search.php 1 patch
Braces   +420 added lines, -311 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
 // This defines two version types for checking the API's are compatible with this version of SMF.
20 21
 $GLOBALS['search_versions'] = array(
@@ -39,8 +40,9 @@  discard block
 block discarded – undo
39 40
 	global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir;
40 41
 
41 42
 	// Is the load average too high to allow searching just now?
42
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
43
-		fatal_lang_error('loadavg_search_disabled', false);
43
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
44
+			fatal_lang_error('loadavg_search_disabled', false);
45
+	}
44 46
 
45 47
 	loadLanguage('Search');
46 48
 	// Don't load this in XML mode.
@@ -88,23 +90,30 @@  discard block
 block discarded – undo
88 90
 			@list ($k, $v) = explode('|\'|', $data);
89 91
 			$context['search_params'][$k] = $v;
90 92
 		}
91
-		if (isset($context['search_params']['brd']))
92
-			$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
93
+		if (isset($context['search_params']['brd'])) {
94
+					$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
95
+		}
93 96
 	}
94 97
 
95
-	if (isset($_REQUEST['search']))
96
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
98
+	if (isset($_REQUEST['search'])) {
99
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
100
+	}
97 101
 
98
-	if (isset($context['search_params']['search']))
99
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
100
-	if (isset($context['search_params']['userspec']))
101
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
102
-	if (!empty($context['search_params']['searchtype']))
103
-		$context['search_params']['searchtype'] = 2;
104
-	if (!empty($context['search_params']['minage']))
105
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
106
-	if (!empty($context['search_params']['maxage']))
107
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
102
+	if (isset($context['search_params']['search'])) {
103
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
104
+	}
105
+	if (isset($context['search_params']['userspec'])) {
106
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
107
+	}
108
+	if (!empty($context['search_params']['searchtype'])) {
109
+			$context['search_params']['searchtype'] = 2;
110
+	}
111
+	if (!empty($context['search_params']['minage'])) {
112
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
113
+	}
114
+	if (!empty($context['search_params']['maxage'])) {
115
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
116
+	}
108 117
 
109 118
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
110 119
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
@@ -116,11 +125,13 @@  discard block
 block discarded – undo
116 125
 		$context['search_errors']['messages'] = array();
117 126
 		foreach ($context['search_errors'] as $search_error => $dummy)
118 127
 		{
119
-			if ($search_error === 'messages')
120
-				continue;
128
+			if ($search_error === 'messages') {
129
+							continue;
130
+			}
121 131
 
122
-			if ($search_error == 'string_too_long')
123
-				$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
132
+			if ($search_error == 'string_too_long') {
133
+							$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
134
+			}
124 135
 
125 136
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
126 137
 		}
@@ -143,12 +154,13 @@  discard block
 block discarded – undo
143 154
 	while ($row = $smcFunc['db_fetch_assoc']($request))
144 155
 	{
145 156
 		// This category hasn't been set up yet..
146
-		if (!isset($context['categories'][$row['id_cat']]))
147
-			$context['categories'][$row['id_cat']] = array(
157
+		if (!isset($context['categories'][$row['id_cat']])) {
158
+					$context['categories'][$row['id_cat']] = array(
148 159
 				'id' => $row['id_cat'],
149 160
 				'name' => $row['cat_name'],
150 161
 				'boards' => array()
151 162
 			);
163
+		}
152 164
 
153 165
 		// Set this board up, and let the template know when it's a child.  (indent them..)
154 166
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -159,8 +171,9 @@  discard block
 block discarded – undo
159 171
 		);
160 172
 
161 173
 		// If a board wasn't checked that probably should have been ensure the board selection is selected, yo!
162
-		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board']))
163
-			$context['boards_check_all'] = false;
174
+		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) {
175
+					$context['boards_check_all'] = false;
176
+		}
164 177
 	}
165 178
 	$smcFunc['db_free_result']($request);
166 179
 
@@ -182,18 +195,20 @@  discard block
 block discarded – undo
182 195
 	}
183 196
 
184 197
 	$max_boards = ceil(count($temp_boards) / 2);
185
-	if ($max_boards == 1)
186
-		$max_boards = 2;
198
+	if ($max_boards == 1) {
199
+			$max_boards = 2;
200
+	}
187 201
 
188 202
 	// Now, alternate them so they can be shown left and right ;).
189 203
 	$context['board_columns'] = array();
190 204
 	for ($i = 0; $i < $max_boards; $i++)
191 205
 	{
192 206
 		$context['board_columns'][] = $temp_boards[$i];
193
-		if (isset($temp_boards[$i + $max_boards]))
194
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
195
-		else
196
-			$context['board_columns'][] = array();
207
+		if (isset($temp_boards[$i + $max_boards])) {
208
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
209
+		} else {
210
+					$context['board_columns'][] = array();
211
+		}
197 212
 	}
198 213
 
199 214
 	if (!empty($_REQUEST['topic']))
@@ -225,8 +240,9 @@  discard block
 block discarded – undo
225 240
 			)
226 241
 		);
227 242
 
228
-		if ($smcFunc['db_num_rows']($request) == 0)
229
-			fatal_lang_error('topic_gone', false);
243
+		if ($smcFunc['db_num_rows']($request) == 0) {
244
+					fatal_lang_error('topic_gone', false);
245
+		}
230 246
 
231 247
 		list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request);
232 248
 		$smcFunc['db_free_result']($request);
@@ -256,11 +272,13 @@  discard block
 block discarded – undo
256 272
 	global $excludedWords, $participants, $smcFunc;
257 273
 
258 274
 	// if comming from the quick search box, and we want to search on members, well we need to do that ;)
259
-	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members')
260
-		redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
275
+	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') {
276
+			redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
277
+	}
261 278
 
262
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
263
-		fatal_lang_error('loadavg_search_disabled', false);
279
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
280
+			fatal_lang_error('loadavg_search_disabled', false);
281
+	}
264 282
 
265 283
 	// No, no, no... this is a bit hard on the server, so don't you go prefetching it!
266 284
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -307,8 +325,9 @@  discard block
 block discarded – undo
307 325
 	}
308 326
 
309 327
 	// Zero weight.  Weightless :P.
310
-	if (empty($weight_total))
311
-		fatal_lang_error('search_invalid_weights');
328
+	if (empty($weight_total)) {
329
+			fatal_lang_error('search_invalid_weights');
330
+	}
312 331
 
313 332
 	// These vars don't require an interface, they're just here for tweaking.
314 333
 	$recentPercentage = 0.30;
@@ -326,11 +345,13 @@  discard block
 block discarded – undo
326 345
 	$context['search_string_limit'] = 100;
327 346
 
328 347
 	loadLanguage('Search');
329
-	if (!isset($_REQUEST['xml']))
330
-		loadTemplate('Search');
348
+	if (!isset($_REQUEST['xml'])) {
349
+			loadTemplate('Search');
350
+	}
331 351
 	//If we're doing XML we need to use the results template regardless really.
332
-	else
333
-		$context['sub_template'] = 'results';
352
+	else {
353
+			$context['sub_template'] = 'results';
354
+	}
334 355
 
335 356
 	// Are you allowed?
336 357
 	isAllowedTo('search_posts');
@@ -363,34 +384,39 @@  discard block
 block discarded – undo
363 384
 			$search_params[$k] = $v;
364 385
 		}
365 386
 
366
-		if (isset($search_params['brd']))
367
-			$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
387
+		if (isset($search_params['brd'])) {
388
+					$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
389
+		}
368 390
 	}
369 391
 
370 392
 	// Store whether simple search was used (needed if the user wants to do another query).
371
-	if (!isset($search_params['advanced']))
372
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
393
+	if (!isset($search_params['advanced'])) {
394
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
395
+	}
373 396
 
374 397
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
375
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
376
-		$search_params['searchtype'] = 2;
398
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
399
+			$search_params['searchtype'] = 2;
400
+	}
377 401
 
378 402
 	// Minimum age of messages. Default to zero (don't set param in that case).
379
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
380
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
403
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
404
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
405
+	}
381 406
 
382 407
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
383
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999))
384
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
408
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) {
409
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
410
+	}
385 411
 
386 412
 	// Searching a specific topic?
387 413
 	if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic'))
388 414
 	{
389 415
 		$search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : '');
390 416
 		$search_params['show_complete'] = true;
417
+	} elseif (!empty($search_params['topic'])) {
418
+			$search_params['topic'] = (int) $search_params['topic'];
391 419
 	}
392
-	elseif (!empty($search_params['topic']))
393
-		$search_params['topic'] = (int) $search_params['topic'];
394 420
 
395 421
 	if (!empty($search_params['minage']) || !empty($search_params['maxage']))
396 422
 	{
@@ -408,19 +434,21 @@  discard block
 block discarded – undo
408 434
 			)
409 435
 		);
410 436
 		list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request);
411
-		if ($minMsgID < 0 || $maxMsgID < 0)
412
-			$context['search_errors']['no_messages_in_time_frame'] = true;
437
+		if ($minMsgID < 0 || $maxMsgID < 0) {
438
+					$context['search_errors']['no_messages_in_time_frame'] = true;
439
+		}
413 440
 		$smcFunc['db_free_result']($request);
414 441
 	}
415 442
 
416 443
 	// Default the user name to a wildcard matching every user (*).
417
-	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
418
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
444
+	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
445
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
446
+	}
419 447
 
420 448
 	// If there's no specific user, then don't mention it in the main query.
421
-	if (empty($search_params['userspec']))
422
-		$userQuery = '';
423
-	else
449
+	if (empty($search_params['userspec'])) {
450
+			$userQuery = '';
451
+	} else
424 452
 	{
425 453
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
426 454
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -432,19 +460,21 @@  discard block
 block discarded – undo
432 460
 		{
433 461
 			$possible_users[$k] = trim($possible_users[$k]);
434 462
 
435
-			if (strlen($possible_users[$k]) == 0)
436
-				unset($possible_users[$k]);
463
+			if (strlen($possible_users[$k]) == 0) {
464
+							unset($possible_users[$k]);
465
+			}
437 466
 		}
438 467
 
439 468
 		// Create a list of database-escaped search names.
440 469
 		$realNameMatches = array();
441
-		foreach ($possible_users as $possible_user)
442
-			$realNameMatches[] = $smcFunc['db_quote'](
470
+		foreach ($possible_users as $possible_user) {
471
+					$realNameMatches[] = $smcFunc['db_quote'](
443 472
 				'{string:possible_user}',
444 473
 				array(
445 474
 					'possible_user' => $possible_user
446 475
 				)
447 476
 			);
477
+		}
448 478
 
449 479
 		// Retrieve a list of possible members.
450 480
 		$request = $smcFunc['db_query']('', '
@@ -456,9 +486,9 @@  discard block
 block discarded – undo
456 486
 			)
457 487
 		);
458 488
 		// Simply do nothing if there're too many members matching the criteria.
459
-		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
460
-			$userQuery = '';
461
-		elseif ($smcFunc['db_num_rows']($request) == 0)
489
+		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
490
+					$userQuery = '';
491
+		} elseif ($smcFunc['db_num_rows']($request) == 0)
462 492
 		{
463 493
 			$userQuery = $smcFunc['db_quote'](
464 494
 				'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})',
@@ -467,12 +497,12 @@  discard block
 block discarded – undo
467 497
 					'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches),
468 498
 				)
469 499
 			);
470
-		}
471
-		else
500
+		} else
472 501
 		{
473 502
 			$memberlist = array();
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$memberlist[] = $row['id_member'];
503
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
504
+							$memberlist[] = $row['id_member'];
505
+			}
476 506
 			$userQuery = $smcFunc['db_quote'](
477 507
 				'(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))',
478 508
 				array(
@@ -486,22 +516,25 @@  discard block
 block discarded – undo
486 516
 	}
487 517
 
488 518
 	// If the boards were passed by URL (params=), temporarily put them back in $_REQUEST.
489
-	if (!empty($search_params['brd']) && is_array($search_params['brd']))
490
-		$_REQUEST['brd'] = $search_params['brd'];
519
+	if (!empty($search_params['brd']) && is_array($search_params['brd'])) {
520
+			$_REQUEST['brd'] = $search_params['brd'];
521
+	}
491 522
 
492 523
 	// Ensure that brd is an array.
493 524
 	if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board'))
494 525
 	{
495
-		if (!empty($_REQUEST['brd']))
496
-			$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
497
-		else
498
-			$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
526
+		if (!empty($_REQUEST['brd'])) {
527
+					$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
528
+		} else {
529
+					$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
530
+		}
499 531
 	}
500 532
 
501 533
 	// Make sure all boards are integers.
502
-	if (!empty($_REQUEST['brd']))
503
-		foreach ($_REQUEST['brd'] as $id => $brd)
534
+	if (!empty($_REQUEST['brd'])) {
535
+			foreach ($_REQUEST['brd'] as $id => $brd)
504 536
 			$_REQUEST['brd'][$id] = (int) $brd;
537
+	}
505 538
 
506 539
 	// Special case for boards: searching just one topic?
507 540
 	if (!empty($search_params['topic']))
@@ -520,17 +553,18 @@  discard block
 block discarded – undo
520 553
 			)
521 554
 		);
522 555
 
523
-		if ($smcFunc['db_num_rows']($request) == 0)
524
-			fatal_lang_error('topic_gone', false);
556
+		if ($smcFunc['db_num_rows']($request) == 0) {
557
+					fatal_lang_error('topic_gone', false);
558
+		}
525 559
 
526 560
 		$search_params['brd'] = array();
527 561
 		list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request);
528 562
 		$smcFunc['db_free_result']($request);
529 563
 	}
530 564
 	// Select all boards you've selected AND are allowed to see.
531
-	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
532
-		$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
533
-	else
565
+	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) {
566
+			$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
567
+	} else
534 568
 	{
535 569
 		$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
536 570
 		$request = $smcFunc['db_query']('', '
@@ -548,19 +582,22 @@  discard block
 block discarded – undo
548 582
 			)
549 583
 		);
550 584
 		$search_params['brd'] = array();
551
-		while ($row = $smcFunc['db_fetch_assoc']($request))
552
-			$search_params['brd'][] = $row['id_board'];
585
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
586
+					$search_params['brd'][] = $row['id_board'];
587
+		}
553 588
 		$smcFunc['db_free_result']($request);
554 589
 
555 590
 		// This error should pro'bly only happen for hackers.
556
-		if (empty($search_params['brd']))
557
-			$context['search_errors']['no_boards_selected'] = true;
591
+		if (empty($search_params['brd'])) {
592
+					$context['search_errors']['no_boards_selected'] = true;
593
+		}
558 594
 	}
559 595
 
560 596
 	if (count($search_params['brd']) != 0)
561 597
 	{
562
-		foreach ($search_params['brd'] as $k => $v)
563
-			$search_params['brd'][$k] = (int) $v;
598
+		foreach ($search_params['brd'] as $k => $v) {
599
+					$search_params['brd'][$k] = (int) $v;
600
+		}
564 601
 
565 602
 		// If we've selected all boards, this parameter can be left empty.
566 603
 		$request = $smcFunc['db_query']('', '
@@ -574,15 +611,16 @@  discard block
 block discarded – undo
574 611
 		list ($num_boards) = $smcFunc['db_fetch_row']($request);
575 612
 		$smcFunc['db_free_result']($request);
576 613
 
577
-		if (count($search_params['brd']) == $num_boards)
614
+		if (count($search_params['brd']) == $num_boards) {
615
+					$boardQuery = '';
616
+		} elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) {
617
+					$boardQuery = '!= ' . $modSettings['recycle_board'];
618
+		} else {
619
+					$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
620
+		}
621
+	} else {
578 622
 			$boardQuery = '';
579
-		elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd']))
580
-			$boardQuery = '!= ' . $modSettings['recycle_board'];
581
-		else
582
-			$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
583 623
 	}
584
-	else
585
-		$boardQuery = '';
586 624
 
587 625
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
588 626
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
@@ -596,11 +634,13 @@  discard block
 block discarded – undo
596 634
 		'id_msg',
597 635
 	);
598 636
 	call_integration_hook('integrate_search_sort_columns', array(&$sort_columns));
599
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
600
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
637
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
638
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
639
+	}
601 640
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance';
602
-	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies')
603
-		$search_params['sort'] = 'id_msg';
641
+	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') {
642
+			$search_params['sort'] = 'id_msg';
643
+	}
604 644
 
605 645
 	// Sorting direction: descending unless stated otherwise.
606 646
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
@@ -624,17 +664,19 @@  discard block
 block discarded – undo
624 664
 	// What are we searching for?
625 665
 	if (empty($search_params['search']))
626 666
 	{
627
-		if (isset($_GET['search']))
628
-			$search_params['search'] = un_htmlspecialchars($_GET['search']);
629
-		elseif (isset($_POST['search']))
630
-			$search_params['search'] = $_POST['search'];
631
-		else
632
-			$search_params['search'] = '';
667
+		if (isset($_GET['search'])) {
668
+					$search_params['search'] = un_htmlspecialchars($_GET['search']);
669
+		} elseif (isset($_POST['search'])) {
670
+					$search_params['search'] = $_POST['search'];
671
+		} else {
672
+					$search_params['search'] = '';
673
+		}
633 674
 	}
634 675
 
635 676
 	// Nothing??
636
-	if (!isset($search_params['search']) || $search_params['search'] == '')
637
-		$context['search_errors']['invalid_search_string'] = true;
677
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
678
+			$context['search_errors']['invalid_search_string'] = true;
679
+	}
638 680
 	// Too long?
639 681
 	elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit'])
640 682
 	{
@@ -648,8 +690,9 @@  discard block
 block discarded – undo
648 690
 	$stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query));
649 691
 
650 692
 	// This (hidden) setting will do fulltext searching in the most basic way.
651
-	if (!empty($modSettings['search_simple_fulltext']))
652
-		$stripped_query = strtr($stripped_query, array('"' => ''));
693
+	if (!empty($modSettings['search_simple_fulltext'])) {
694
+			$stripped_query = strtr($stripped_query, array('"' => ''));
695
+	}
653 696
 
654 697
 	$no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1;
655 698
 
@@ -672,8 +715,9 @@  discard block
 block discarded – undo
672 715
 	{
673 716
 		if ($word === '-')
674 717
 		{
675
-			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
676
-				$excludedWords[] = $word;
718
+			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
719
+							$excludedWords[] = $word;
720
+			}
677 721
 			unset($phraseArray[$index]);
678 722
 		}
679 723
 	}
@@ -683,8 +727,9 @@  discard block
 block discarded – undo
683 727
 	{
684 728
 		if (strpos(trim($word), '-') === 0)
685 729
 		{
686
-			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
687
-				$excludedWords[] = $word;
730
+			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
731
+							$excludedWords[] = $word;
732
+			}
688 733
 			unset($wordArray[$index]);
689 734
 		}
690 735
 	}
@@ -697,8 +742,9 @@  discard block
 block discarded – undo
697 742
 	foreach ($searchArray as $index => $value)
698 743
 	{
699 744
 		// Skip anything practically empty.
700
-		if (($searchArray[$index] = trim($value, '-_\' ')) === '')
701
-			unset($searchArray[$index]);
745
+		if (($searchArray[$index] = trim($value, '-_\' ')) === '') {
746
+					unset($searchArray[$index]);
747
+		}
702 748
 		// Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing.
703 749
 		elseif (in_array($searchArray[$index], $blacklisted_words))
704 750
 		{
@@ -716,31 +762,37 @@  discard block
 block discarded – undo
716 762
 
717 763
 	// Create an array of replacements for highlighting.
718 764
 	$context['mark'] = array();
719
-	foreach ($searchArray as $word)
720
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
765
+	foreach ($searchArray as $word) {
766
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
767
+	}
721 768
 
722 769
 	// Initialize two arrays storing the words that have to be searched for.
723 770
 	$orParts = array();
724 771
 	$searchWords = array();
725 772
 
726 773
 	// Make sure at least one word is being searched for.
727
-	if (empty($searchArray))
728
-		$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
774
+	if (empty($searchArray)) {
775
+			$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
776
+	}
729 777
 	// All words/sentences must match.
730
-	elseif (empty($search_params['searchtype']))
731
-		$orParts[0] = $searchArray;
778
+	elseif (empty($search_params['searchtype'])) {
779
+			$orParts[0] = $searchArray;
780
+	}
732 781
 	// Any word/sentence must match.
733
-	else
734
-		foreach ($searchArray as $index => $value)
782
+	else {
783
+			foreach ($searchArray as $index => $value)
735 784
 			$orParts[$index] = array($value);
785
+	}
736 786
 
737 787
 	// Don't allow duplicate error messages if one string is too short.
738
-	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string']))
739
-		unset($context['search_errors']['invalid_search_string']);
788
+	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) {
789
+			unset($context['search_errors']['invalid_search_string']);
790
+	}
740 791
 	// Make sure the excluded words are in all or-branches.
741
-	foreach ($orParts as $orIndex => $andParts)
742
-		foreach ($excludedWords as $word)
792
+	foreach ($orParts as $orIndex => $andParts) {
793
+			foreach ($excludedWords as $word)
743 794
 			$orParts[$orIndex][] = $word;
795
+	}
744 796
 
745 797
 	// Determine the or-branches and the fulltext search words.
746 798
 	foreach ($orParts as $orIndex => $andParts)
@@ -754,8 +806,9 @@  discard block
 block discarded – undo
754 806
 		);
755 807
 
756 808
 		// Sort the indexed words (large words -> small words -> excluded words).
757
-		if ($searchAPI->supportsMethod('searchSort'))
758
-			usort($orParts[$orIndex], 'searchSort');
809
+		if ($searchAPI->supportsMethod('searchSort')) {
810
+					usort($orParts[$orIndex], 'searchSort');
811
+		}
759 812
 
760 813
 		foreach ($orParts[$orIndex] as $word)
761 814
 		{
@@ -767,15 +820,17 @@  discard block
 block discarded – undo
767 820
 			if (!$is_excluded || count($subjectWords) === 1)
768 821
 			{
769 822
 				$searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords);
770
-				if ($is_excluded)
771
-					$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
823
+				if ($is_excluded) {
824
+									$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
825
+				}
826
+			} else {
827
+							$excludedPhrases[] = $word;
772 828
 			}
773
-			else
774
-				$excludedPhrases[] = $word;
775 829
 
776 830
 			// Have we got indexes to prepare?
777
-			if ($searchAPI->supportsMethod('prepareIndexes'))
778
-				$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
831
+			if ($searchAPI->supportsMethod('prepareIndexes')) {
832
+							$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
833
+			}
779 834
 		}
780 835
 
781 836
 		// Search_force_index requires all AND parts to have at least one fulltext word.
@@ -783,8 +838,7 @@  discard block
 block discarded – undo
783 838
 		{
784 839
 			$context['search_errors']['query_not_specific_enough'] = true;
785 840
 			break;
786
-		}
787
-		elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
841
+		} elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
788 842
 		{
789 843
 			$context['search_errors']['query_not_specific_enough'] = true;
790 844
 			break;
@@ -812,8 +866,9 @@  discard block
 block discarded – undo
812 866
 		$found_misspelling = false;
813 867
 		foreach ($searchArray as $word)
814 868
 		{
815
-			if (empty($link))
816
-				continue;
869
+			if (empty($link)) {
870
+							continue;
871
+			}
817 872
 
818 873
 			// Don't check phrases.
819 874
 			if (preg_match('~^\w+$~', $word) === 0)
@@ -828,8 +883,7 @@  discard block
 block discarded – undo
828 883
 				$did_you_mean['search'][] = $word;
829 884
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
830 885
 				continue;
831
-			}
832
-			elseif (spell_check($link, $word))
886
+			} elseif (spell_check($link, $word))
833 887
 			{
834 888
 				$did_you_mean['search'][] = $word;
835 889
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -840,11 +894,13 @@  discard block
 block discarded – undo
840 894
 			foreach ($suggestions as $i => $s)
841 895
 			{
842 896
 				// Search is case insensitive.
843
-				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word))
844
-					unset($suggestions[$i]);
897
+				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) {
898
+									unset($suggestions[$i]);
899
+				}
845 900
 				// Plus, don't suggest something the user thinks is rude!
846
-				elseif ($suggestions[$i] != censorText($s))
847
-					unset($suggestions[$i]);
901
+				elseif ($suggestions[$i] != censorText($s)) {
902
+									unset($suggestions[$i]);
903
+				}
848 904
 			}
849 905
 
850 906
 			// Anything found?  If so, correct it!
@@ -854,8 +910,7 @@  discard block
 block discarded – undo
854 910
 				$did_you_mean['search'][] = $suggestions[0];
855 911
 				$did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>';
856 912
 				$found_misspelling = true;
857
-			}
858
-			else
913
+			} else
859 914
 			{
860 915
 				$did_you_mean['search'][] = $word;
861 916
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -872,8 +927,7 @@  discard block
 block discarded – undo
872 927
 				{
873 928
 					$temp_excluded['search'][] = '-"' . $word . '"';
874 929
 					$temp_excluded['display'][] = '-&quot;' . $smcFunc['htmlspecialchars']($word) . '&quot;';
875
-				}
876
-				else
930
+				} else
877 931
 				{
878 932
 					$temp_excluded['search'][] = '-' . $word;
879 933
 					$temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word);
@@ -885,11 +939,13 @@  discard block
 block discarded – undo
885 939
 
886 940
 			$temp_params = $search_params;
887 941
 			$temp_params['search'] = implode(' ', $did_you_mean['search']);
888
-			if (isset($temp_params['brd']))
889
-				$temp_params['brd'] = implode(',', $temp_params['brd']);
942
+			if (isset($temp_params['brd'])) {
943
+							$temp_params['brd'] = implode(',', $temp_params['brd']);
944
+			}
890 945
 			$context['params'] = array();
891
-			foreach ($temp_params as $k => $v)
892
-				$context['did_you_mean_params'][] = $k . '|\'|' . $v;
946
+			foreach ($temp_params as $k => $v) {
947
+							$context['did_you_mean_params'][] = $k . '|\'|' . $v;
948
+			}
893 949
 			$context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params']));
894 950
 			$context['did_you_mean'] = implode(' ', $did_you_mean['display']);
895 951
 		}
@@ -897,18 +953,20 @@  discard block
 block discarded – undo
897 953
 
898 954
 	// Let the user adjust the search query, should they wish?
899 955
 	$context['search_params'] = $search_params;
900
-	if (isset($context['search_params']['search']))
901
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
902
-	if (isset($context['search_params']['userspec']))
903
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
956
+	if (isset($context['search_params']['search'])) {
957
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
958
+	}
959
+	if (isset($context['search_params']['userspec'])) {
960
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
961
+	}
904 962
 
905 963
 	// Do we have captcha enabled?
906 964
 	if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']))
907 965
 	{
908 966
 		// If we come from another search box tone down the error...
909
-		if (!isset($_REQUEST['search_vv']))
910
-			$context['search_errors']['need_verification_code'] = true;
911
-		else
967
+		if (!isset($_REQUEST['search_vv'])) {
968
+					$context['search_errors']['need_verification_code'] = true;
969
+		} else
912 970
 		{
913 971
 			require_once($sourcedir . '/Subs-Editor.php');
914 972
 			$verificationOptions = array(
@@ -918,12 +976,14 @@  discard block
 block discarded – undo
918 976
 
919 977
 			if (is_array($context['require_verification']))
920 978
 			{
921
-				foreach ($context['require_verification'] as $error)
922
-					$context['search_errors'][$error] = true;
979
+				foreach ($context['require_verification'] as $error) {
980
+									$context['search_errors'][$error] = true;
981
+				}
923 982
 			}
924 983
 			// Don't keep asking for it - they've proven themselves worthy.
925
-			else
926
-				$_SESSION['ss_vv_passed'] = true;
984
+			else {
985
+							$_SESSION['ss_vv_passed'] = true;
986
+			}
927 987
 		}
928 988
 	}
929 989
 
@@ -931,19 +991,22 @@  discard block
 block discarded – undo
931 991
 
932 992
 	// All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below.
933 993
 	$temp_params = $search_params;
934
-	if (isset($temp_params['brd']))
935
-		$temp_params['brd'] = implode(',', $temp_params['brd']);
994
+	if (isset($temp_params['brd'])) {
995
+			$temp_params['brd'] = implode(',', $temp_params['brd']);
996
+	}
936 997
 	$context['params'] = array();
937
-	foreach ($temp_params as $k => $v)
938
-		$context['params'][] = $k . '|\'|' . $v;
998
+	foreach ($temp_params as $k => $v) {
999
+			$context['params'][] = $k . '|\'|' . $v;
1000
+	}
939 1001
 
940 1002
 	if (!empty($context['params']))
941 1003
 	{
942 1004
 		// Due to old IE's 2083 character limit, we have to compress long search strings
943 1005
 		$params = @gzcompress(implode('|"|', $context['params']));
944 1006
 		// Gzcompress failed, use try non-gz
945
-		if (empty($params))
946
-			$params = implode('|"|', $context['params']);
1007
+		if (empty($params)) {
1008
+					$params = implode('|"|', $context['params']);
1009
+		}
947 1010
 		// Base64 encode, then replace +/= with uri safe ones that can be reverted
948 1011
 		$context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params));
949 1012
 	}
@@ -969,8 +1032,9 @@  discard block
 block discarded – undo
969 1032
 	}
970 1033
 
971 1034
 	// Spam me not, Spam-a-lot?
972
-	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])
973
-		spamProtection('search');
1035
+	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) {
1036
+			spamProtection('search');
1037
+	}
974 1038
 	// Store the last search string to allow pages of results to be browsed.
975 1039
 	$_SESSION['last_ss'] = $search_params['search'];
976 1040
 
@@ -1007,8 +1071,9 @@  discard block
 block discarded – undo
1007 1071
 				)
1008 1072
 			);
1009 1073
 
1010
-			if ($smcFunc['db_num_rows']($request) === 0)
1011
-				$update_cache = true;	
1074
+			if ($smcFunc['db_num_rows']($request) === 0) {
1075
+							$update_cache = true;
1076
+			}
1012 1077
 		}
1013 1078
 
1014 1079
 		if ($update_cache)
@@ -1047,8 +1112,9 @@  discard block
 block discarded – undo
1047 1112
 						'where' => array(),
1048 1113
 					);
1049 1114
 
1050
-					if ($modSettings['postmod_active'])
1051
-						$subject_query['where'][] = 't.approved = {int:is_approved}';
1115
+					if ($modSettings['postmod_active']) {
1116
+											$subject_query['where'][] = 't.approved = {int:is_approved}';
1117
+					}
1052 1118
 
1053 1119
 					$numTables = 0;
1054 1120
 					$prev_join = 0;
@@ -1060,8 +1126,7 @@  discard block
 block discarded – undo
1060 1126
 						{
1061 1127
 							$subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)';
1062 1128
 							$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1063
-						}
1064
-						else
1129
+						} else
1065 1130
 						{
1066 1131
 							$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1067 1132
 							$subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}');
@@ -1079,14 +1144,18 @@  discard block
 block discarded – undo
1079 1144
 						}
1080 1145
 						$subject_query['where'][] = $userQuery;
1081 1146
 					}
1082
-					if (!empty($search_params['topic']))
1083
-						$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1084
-					if (!empty($minMsgID))
1085
-						$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1086
-					if (!empty($maxMsgID))
1087
-						$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1088
-					if (!empty($boardQuery))
1089
-						$subject_query['where'][] = 't.id_board ' . $boardQuery;
1147
+					if (!empty($search_params['topic'])) {
1148
+											$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1149
+					}
1150
+					if (!empty($minMsgID)) {
1151
+											$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1152
+					}
1153
+					if (!empty($maxMsgID)) {
1154
+											$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1155
+					}
1156
+					if (!empty($boardQuery)) {
1157
+											$subject_query['where'][] = 't.id_board ' . $boardQuery;
1158
+					}
1090 1159
 					if (!empty($excludedPhrases))
1091 1160
 					{
1092 1161
 						if ($subject_query['from'] != '{db_prefix}messages AS m')
@@ -1106,8 +1175,9 @@  discard block
 block discarded – undo
1106 1175
 					foreach ($weight_factors as $type => $value)
1107 1176
 					{
1108 1177
 						$relevance .= $weight[$type];
1109
-						if (!empty($value['results']))
1110
-							$relevance .= ' * ' . $value['results'];
1178
+						if (!empty($value['results'])) {
1179
+													$relevance .= ' * ' . $value['results'];
1180
+						}
1111 1181
 						$relevance .= ' + ';
1112 1182
 					}
1113 1183
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1145,20 +1215,23 @@  discard block
 block discarded – undo
1145 1215
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1146 1216
 						{
1147 1217
 							// No duplicates!
1148
-							if (isset($inserts[$row[1]]))
1149
-								continue;
1218
+							if (isset($inserts[$row[1]])) {
1219
+															continue;
1220
+							}
1150 1221
 
1151
-							foreach ($row as $key => $value)
1152
-								$inserts[$row[1]][] = (int) $row[$key];
1222
+							foreach ($row as $key => $value) {
1223
+															$inserts[$row[1]][] = (int) $row[$key];
1224
+							}
1153 1225
 						}
1154 1226
 						$smcFunc['db_free_result']($ignoreRequest);
1155 1227
 						$numSubjectResults = count($inserts);
1228
+					} else {
1229
+											$numSubjectResults += $smcFunc['db_affected_rows']();
1156 1230
 					}
1157
-					else
1158
-						$numSubjectResults += $smcFunc['db_affected_rows']();
1159 1231
 
1160
-					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1161
-						break;
1232
+					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1233
+											break;
1234
+					}
1162 1235
 				}
1163 1236
 
1164 1237
 				// If there's data to be inserted for non-IGNORE databases do it here!
@@ -1173,8 +1246,7 @@  discard block
 block discarded – undo
1173 1246
 				}
1174 1247
 
1175 1248
 				$_SESSION['search_cache']['num_results'] = $numSubjectResults;
1176
-			}
1177
-			else
1249
+			} else
1178 1250
 			{
1179 1251
 				$main_query = array(
1180 1252
 					'select' => array(
@@ -1206,8 +1278,7 @@  discard block
 block discarded – undo
1206 1278
 					$main_query['weights'] = $weight_factors;
1207 1279
 
1208 1280
 					$main_query['group_by'][] = 't.id_topic';
1209
-				}
1210
-				else
1281
+				} else
1211 1282
 				{
1212 1283
 					// This is outrageous!
1213 1284
 					$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';
@@ -1228,8 +1299,9 @@  discard block
 block discarded – undo
1228 1299
 						$main_query['where'][] = 't.id_topic = {int:topic}';
1229 1300
 						$main_query['parameters']['topic'] = $search_params['topic'];
1230 1301
 					}
1231
-					if (!empty($search_params['show_complete']))
1232
-						$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1302
+					if (!empty($search_params['show_complete'])) {
1303
+											$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1304
+					}
1233 1305
 				}
1234 1306
 
1235 1307
 				// *** Get the subject results.
@@ -1254,14 +1326,15 @@  discard block
 block discarded – undo
1254 1326
 					) !== false;
1255 1327
 
1256 1328
 					// Clean up some previous cache.
1257
-					if (!$createTemporary)
1258
-						$smcFunc['db_search_query']('delete_log_search_topics', '
1329
+					if (!$createTemporary) {
1330
+											$smcFunc['db_search_query']('delete_log_search_topics', '
1259 1331
 							DELETE FROM {db_prefix}log_search_topics
1260 1332
 							WHERE id_search = {int:search_id}',
1261 1333
 							array(
1262 1334
 								'search_id' => $_SESSION['search_cache']['id_search'],
1263 1335
 							)
1264 1336
 						);
1337
+					}
1265 1338
 
1266 1339
 					foreach ($searchWords as $orIndex => $words)
1267 1340
 					{
@@ -1293,8 +1366,7 @@  discard block
 block discarded – undo
1293 1366
 								$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1294 1367
 								$subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}';
1295 1368
 								$subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]';
1296
-							}
1297
-							else
1369
+							} else
1298 1370
 							{
1299 1371
 								$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1300 1372
 								$subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}';
@@ -1349,8 +1421,9 @@  discard block
 block discarded – undo
1349 1421
 						call_integration_hook('integrate_subject_search_query', array(&$subject_query));
1350 1422
 
1351 1423
 						// Nothing to search for?
1352
-						if (empty($subject_query['where']))
1353
-							continue;
1424
+						if (empty($subject_query['where'])) {
1425
+													continue;
1426
+						}
1354 1427
 
1355 1428
 						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( '
1356 1429
 							INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics
@@ -1373,19 +1446,21 @@  discard block
 block discarded – undo
1373 1446
 							{
1374 1447
 								$ind = $createTemporary ? 0 : 1;
1375 1448
 								// No duplicates!
1376
-								if (isset($inserts[$row[$ind]]))
1377
-									continue;
1449
+								if (isset($inserts[$row[$ind]])) {
1450
+																	continue;
1451
+								}
1378 1452
 
1379 1453
 								$inserts[$row[$ind]] = $row;
1380 1454
 							}
1381 1455
 							$smcFunc['db_free_result']($ignoreRequest);
1382 1456
 							$numSubjectResults = count($inserts);
1457
+						} else {
1458
+													$numSubjectResults += $smcFunc['db_affected_rows']();
1383 1459
 						}
1384
-						else
1385
-							$numSubjectResults += $smcFunc['db_affected_rows']();
1386 1460
 
1387
-						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1388
-							break;
1461
+						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1462
+													break;
1463
+						}
1389 1464
 					}
1390 1465
 
1391 1466
 					// Got some non-MySQL data to plonk in?
@@ -1403,8 +1478,9 @@  discard block
 block discarded – undo
1403 1478
 					{
1404 1479
 						$main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END';
1405 1480
 						$main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)';
1406
-						if (!$createTemporary)
1407
-							$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1481
+						if (!$createTemporary) {
1482
+													$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1483
+						}
1408 1484
 					}
1409 1485
 				}
1410 1486
 
@@ -1430,14 +1506,15 @@  discard block
 block discarded – undo
1430 1506
 					) !== false;
1431 1507
 
1432 1508
 					// Clear, all clear!
1433
-					if (!$createTemporary)
1434
-						$smcFunc['db_search_query']('delete_log_search_messages', '
1509
+					if (!$createTemporary) {
1510
+											$smcFunc['db_search_query']('delete_log_search_messages', '
1435 1511
 							DELETE FROM {db_prefix}log_search_messages
1436 1512
 							WHERE id_search = {int:id_search}',
1437 1513
 							array(
1438 1514
 								'id_search' => $_SESSION['search_cache']['id_search'],
1439 1515
 							)
1440 1516
 						);
1517
+					}
1441 1518
 
1442 1519
 					foreach ($searchWords as $orIndex => $words)
1443 1520
 					{
@@ -1471,19 +1548,21 @@  discard block
 block discarded – undo
1471 1548
 								while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1472 1549
 								{
1473 1550
 									// No duplicates!
1474
-									if (isset($inserts[$row[0]]))
1475
-										continue;
1551
+									if (isset($inserts[$row[0]])) {
1552
+																			continue;
1553
+									}
1476 1554
 
1477 1555
 									$inserts[$row[0]] = $row;
1478 1556
 								}
1479 1557
 								$smcFunc['db_free_result']($ignoreRequest);
1480 1558
 								$indexedResults = count($inserts);
1559
+							} else {
1560
+															$indexedResults += $smcFunc['db_affected_rows']();
1481 1561
 							}
1482
-							else
1483
-								$indexedResults += $smcFunc['db_affected_rows']();
1484 1562
 
1485
-							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults)
1486
-								break;
1563
+							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) {
1564
+															break;
1565
+							}
1487 1566
 						}
1488 1567
 					}
1489 1568
 
@@ -1503,8 +1582,7 @@  discard block
 block discarded – undo
1503 1582
 						$context['search_errors']['query_not_specific_enough'] = true;
1504 1583
 						$_REQUEST['params'] = $context['params'];
1505 1584
 						return PlushSearch1();
1506
-					}
1507
-					elseif (!empty($indexedResults))
1585
+					} elseif (!empty($indexedResults))
1508 1586
 					{
1509 1587
 						$main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)';
1510 1588
 						if (!$createTemporary)
@@ -1526,15 +1604,18 @@  discard block
 block discarded – undo
1526 1604
 						foreach ($words['all_words'] as $regularWord)
1527 1605
 						{
1528 1606
 							$where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1529
-							if (in_array($regularWord, $excludedWords))
1530
-								$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1607
+							if (in_array($regularWord, $excludedWords)) {
1608
+															$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1609
+							}
1531 1610
 							$main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
1532 1611
 						}
1533
-						if (!empty($where))
1534
-							$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1612
+						if (!empty($where)) {
1613
+													$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1614
+						}
1615
+					}
1616
+					if (!empty($orWhere)) {
1617
+											$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1535 1618
 					}
1536
-					if (!empty($orWhere))
1537
-						$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1538 1619
 
1539 1620
 					if (!empty($userQuery))
1540 1621
 					{
@@ -1572,8 +1653,9 @@  discard block
 block discarded – undo
1572 1653
 					foreach ($main_query['weights'] as $type => $value)
1573 1654
 					{
1574 1655
 						$relevance .= $weight[$type];
1575
-						if (!empty($value['search']))
1576
-							$relevance .= ' * ' . $value['search'];
1656
+						if (!empty($value['search'])) {
1657
+													$relevance .= ' * ' . $value['search'];
1658
+						}
1577 1659
 						$relevance .= ' + ';
1578 1660
 						$new_weight_total += $weight[$type];
1579 1661
 					}
@@ -1604,11 +1686,13 @@  discard block
 block discarded – undo
1604 1686
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1605 1687
 						{
1606 1688
 							// No duplicates!
1607
-							if (isset($inserts[$row[2]]))
1608
-								continue;
1689
+							if (isset($inserts[$row[2]])) {
1690
+															continue;
1691
+							}
1609 1692
 
1610
-							foreach ($row as $key => $value)
1611
-								$inserts[$row[2]][] = (int) $row[$key];
1693
+							foreach ($row as $key => $value) {
1694
+															$inserts[$row[2]][] = (int) $row[$key];
1695
+							}
1612 1696
 						}
1613 1697
 						$smcFunc['db_free_result']($ignoreRequest);
1614 1698
 
@@ -1616,8 +1700,9 @@  discard block
 block discarded – undo
1616 1700
 						if (!empty($inserts))
1617 1701
 						{
1618 1702
 							$query_columns = array();
1619
-							foreach ($main_query['select'] as $k => $v)
1620
-								$query_columns[$k] = 'int';
1703
+							foreach ($main_query['select'] as $k => $v) {
1704
+															$query_columns[$k] = 'int';
1705
+							}
1621 1706
 
1622 1707
 							$smcFunc['db_insert']('',
1623 1708
 								'{db_prefix}log_search_results',
@@ -1627,21 +1712,23 @@  discard block
 block discarded – undo
1627 1712
 							);
1628 1713
 						}
1629 1714
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1715
+					} else {
1716
+											$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1630 1717
 					}
1631
-					else
1632
-						$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1633 1718
 				}
1634 1719
 
1635 1720
 				// Insert subject-only matches.
1636 1721
 				if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0)
1637 1722
 				{
1638 1723
 					$relevance = '1000 * (';
1639
-					foreach ($weight_factors as $type => $value)
1640
-						if (isset($value['results']))
1724
+					foreach ($weight_factors as $type => $value) {
1725
+											if (isset($value['results']))
1641 1726
 						{
1642 1727
 							$relevance .= $weight[$type];
1643
-							if (!empty($value['results']))
1644
-								$relevance .= ' * ' . $value['results'];
1728
+					}
1729
+							if (!empty($value['results'])) {
1730
+															$relevance .= ' * ' . $value['results'];
1731
+							}
1645 1732
 							$relevance .= ' + ';
1646 1733
 						}
1647 1734
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1675,8 +1762,9 @@  discard block
 block discarded – undo
1675 1762
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1676 1763
 						{
1677 1764
 							// No duplicates!
1678
-							if (isset($usedIDs[$row[1]]))
1679
-								continue;
1765
+							if (isset($usedIDs[$row[1]])) {
1766
+															continue;
1767
+							}
1680 1768
 
1681 1769
 							$usedIDs[$row[1]] = true;
1682 1770
 							$inserts[] = $row;
@@ -1694,12 +1782,12 @@  discard block
 block discarded – undo
1694 1782
 							);
1695 1783
 						}
1696 1784
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1785
+					} else {
1786
+											$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1697 1787
 					}
1698
-					else
1699
-						$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1788
+				} elseif ($_SESSION['search_cache']['num_results'] == -1) {
1789
+									$_SESSION['search_cache']['num_results'] = 0;
1700 1790
 				}
1701
-				elseif ($_SESSION['search_cache']['num_results'] == -1)
1702
-					$_SESSION['search_cache']['num_results'] = 0;
1703 1791
 			}
1704 1792
 		}
1705 1793
 
@@ -1769,14 +1857,16 @@  discard block
 block discarded – undo
1769 1857
 			)
1770 1858
 		);
1771 1859
 		$posters = array();
1772
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1773
-			$posters[] = $row['id_member'];
1860
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1861
+					$posters[] = $row['id_member'];
1862
+		}
1774 1863
 		$smcFunc['db_free_result']($request);
1775 1864
 
1776 1865
 		call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters));
1777 1866
 
1778
-		if (!empty($posters))
1779
-			loadMemberData(array_unique($posters));
1867
+		if (!empty($posters)) {
1868
+					loadMemberData(array_unique($posters));
1869
+		}
1780 1870
 
1781 1871
 		// Get the messages out for the callback - select enough that it can be made to look just like Display.
1782 1872
 		$messages_request = $smcFunc['db_query']('', '
@@ -1809,8 +1899,9 @@  discard block
 block discarded – undo
1809 1899
 		);
1810 1900
 
1811 1901
 		// If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore.
1812
-		if ($smcFunc['db_num_rows']($messages_request) == 0)
1813
-			$context['topics'] = array();
1902
+		if ($smcFunc['db_num_rows']($messages_request) == 0) {
1903
+					$context['topics'] = array();
1904
+		}
1814 1905
 
1815 1906
 		// If we want to know who participated in what then load this now.
1816 1907
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
@@ -1828,8 +1919,9 @@  discard block
 block discarded – undo
1828 1919
 					'limit' => count($participants),
1829 1920
 				)
1830 1921
 			);
1831
-			while ($row = $smcFunc['db_fetch_assoc']($result))
1832
-				$participants[$row['id_topic']] = true;
1922
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
1923
+							$participants[$row['id_topic']] = true;
1924
+			}
1833 1925
 			$smcFunc['db_free_result']($result);
1834 1926
 		}
1835 1927
 	}
@@ -1838,15 +1930,17 @@  discard block
 block discarded – undo
1838 1930
 	$context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false);
1839 1931
 
1840 1932
 	// Consider the search complete!
1841
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1842
-		cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1933
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1934
+			cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1935
+	}
1843 1936
 
1844 1937
 	$context['key_words'] = &$searchArray;
1845 1938
 
1846 1939
 	// Setup the default topic icons... for checking they exist and the like!
1847 1940
 	$context['icon_sources'] = array();
1848
-	foreach ($context['stable_icons'] as $icon)
1849
-		$context['icon_sources'][$icon] = 'images_url';
1941
+	foreach ($context['stable_icons'] as $icon) {
1942
+			$context['icon_sources'][$icon] = 'images_url';
1943
+	}
1850 1944
 
1851 1945
 	$context['sub_template'] = 'results';
1852 1946
 	$context['page_title'] = $txt['search_results'];
@@ -1877,26 +1971,31 @@  discard block
 block discarded – undo
1877 1971
 	global $boards_can, $participants, $smcFunc;
1878 1972
 	static $recycle_board = null;
1879 1973
 
1880
-	if ($recycle_board === null)
1881
-		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1974
+	if ($recycle_board === null) {
1975
+			$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1976
+	}
1882 1977
 
1883 1978
 	// Remember which message this is.  (ie. reply #83)
1884 1979
 	static $counter = null;
1885
-	if ($counter == null || $reset)
1886
-		$counter = $_REQUEST['start'] + 1;
1980
+	if ($counter == null || $reset) {
1981
+			$counter = $_REQUEST['start'] + 1;
1982
+	}
1887 1983
 
1888 1984
 	// If the query returned false, bail.
1889
-	if ($messages_request == false)
1890
-		return false;
1985
+	if ($messages_request == false) {
1986
+			return false;
1987
+	}
1891 1988
 
1892 1989
 	// Start from the beginning...
1893
-	if ($reset)
1894
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1990
+	if ($reset) {
1991
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1992
+	}
1895 1993
 
1896 1994
 	// Attempt to get the next message.
1897 1995
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1898
-	if (!$message)
1899
-		return false;
1996
+	if (!$message) {
1997
+			return false;
1998
+	}
1900 1999
 
1901 2000
 	// Can't have an empty subject can we?
1902 2001
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1935,9 +2034,9 @@  discard block
 block discarded – undo
1935 2034
 
1936 2035
 		if ($smcFunc['strlen']($message['body']) > $charLimit)
1937 2036
 		{
1938
-			if (empty($context['key_words']))
1939
-				$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
1940
-			else
2037
+			if (empty($context['key_words'])) {
2038
+							$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
2039
+			} else
1941 2040
 			{
1942 2041
 				$matchString = '';
1943 2042
 				$force_partial_word = false;
@@ -1946,18 +2045,20 @@  discard block
 block discarded – undo
1946 2045
 					$keyword = un_htmlspecialchars($keyword);
1947 2046
 					$keyword = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
1948 2047
 
1949
-					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0)
1950
-						$force_partial_word = true;
2048
+					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) {
2049
+											$force_partial_word = true;
2050
+					}
1951 2051
 					$matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|';
1952 2052
 				}
1953 2053
 				$matchString = un_htmlspecialchars(substr($matchString, 0, -1));
1954 2054
 
1955 2055
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br>' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
1956 2056
 
1957
-				if (empty($modSettings['search_method']) || $force_partial_word)
1958
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
1959
-				else
1960
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2057
+				if (empty($modSettings['search_method']) || $force_partial_word) {
2058
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2059
+				} else {
2060
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2061
+				}
1961 2062
 
1962 2063
 				$message['body'] = '';
1963 2064
 				foreach ($matches[0] as $index => $match)
@@ -1970,8 +2071,7 @@  discard block
 block discarded – undo
1970 2071
 			// Re-fix the international characters.
1971 2072
 			$message['body'] = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']);
1972 2073
 		}
1973
-	}
1974
-	else
2074
+	} else
1975 2075
 	{
1976 2076
 		// Run BBC interpreter on the message.
1977 2077
 		$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
@@ -1990,21 +2090,26 @@  discard block
 block discarded – undo
1990 2090
 	// Sadly, we need to check the icon ain't broke.
1991 2091
 	if (!empty($modSettings['messageIconChecks_enable']))
1992 2092
 	{
1993
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1994
-			$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1995
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1996
-			$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1997
-		if (!isset($context['icon_sources'][$message['icon']]))
1998
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1999
-	}
2000
-	else
2093
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2094
+					$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
2095
+		}
2096
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2097
+					$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
2098
+		}
2099
+		if (!isset($context['icon_sources'][$message['icon']])) {
2100
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
2101
+		}
2102
+	} else
2001 2103
 	{
2002
-		if (!isset($context['icon_sources'][$message['first_icon']]))
2003
-			$context['icon_sources'][$message['first_icon']] = 'images_url';
2004
-		if (!isset($context['icon_sources'][$message['last_icon']]))
2005
-			$context['icon_sources'][$message['last_icon']] = 'images_url';
2006
-		if (!isset($context['icon_sources'][$message['icon']]))
2007
-			$context['icon_sources'][$message['icon']] = 'images_url';
2104
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2105
+					$context['icon_sources'][$message['first_icon']] = 'images_url';
2106
+		}
2107
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2108
+					$context['icon_sources'][$message['last_icon']] = 'images_url';
2109
+		}
2110
+		if (!isset($context['icon_sources'][$message['icon']])) {
2111
+					$context['icon_sources'][$message['icon']] = 'images_url';
2112
+		}
2008 2113
 	}
2009 2114
 
2010 2115
 	// Do we have quote tag enabled?
@@ -2014,12 +2119,14 @@  discard block
 block discarded – undo
2014 2119
 	$colorClass = 'windowbg';
2015 2120
 
2016 2121
 	// Sticky topics should get a different color, too.
2017
-	if ($message['is_sticky'])
2018
-		$colorClass .= ' sticky';
2122
+	if ($message['is_sticky']) {
2123
+			$colorClass .= ' sticky';
2124
+	}
2019 2125
 
2020 2126
 	// Locked topics get special treatment as well.
2021
-	if ($message['locked'])
2022
-		$colorClass .= ' locked';
2127
+	if ($message['locked']) {
2128
+			$colorClass .= ' locked';
2129
+	}
2023 2130
 
2024 2131
 	$output = array_merge($context['topics'][$message['id_msg']], array(
2025 2132
 		'id' => $message['id_topic'],
@@ -2113,8 +2220,9 @@  discard block
 block discarded – undo
2113 2220
 		$query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\''));
2114 2221
 
2115 2222
 		// Highlighting empty strings would make a terrible mess...
2116
-		if (strlen($query) == 0)
2117
-			continue;
2223
+		if (strlen($query) == 0) {
2224
+					continue;
2225
+		}
2118 2226
 
2119 2227
 		$body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m)
2120 2228
 		{
@@ -2167,8 +2275,9 @@  discard block
 block discarded – undo
2167 2275
 
2168 2276
 	// Load up the search API we are going to use.
2169 2277
 	$modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index'];
2170
-	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'))
2171
-		fatal_lang_error('search_api_missing');
2278
+	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) {
2279
+			fatal_lang_error('search_api_missing');
2280
+	}
2172 2281
 	require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php');
2173 2282
 
2174 2283
 	// Create an instance of the search API and check it is valid for this version of SMF.
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +268 added lines, -196 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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -65,13 +66,16 @@  discard block
 block discarded – undo
65 66
 			'db_native_replace'			=> 'smf_db_native_replace',
66 67
 			'db_cte_support'			=> 'smf_db_cte_support',
67 68
 		);
69
+	}
68 70
 
69
-	if (!empty($db_options['persist']))
70
-		$db_server = 'p:' . $db_server;
71
+	if (!empty($db_options['persist'])) {
72
+			$db_server = 'p:' . $db_server;
73
+	}
71 74
 
72 75
 	// We are not going to make it very far without these.
73
-	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect'))
74
-		display_db_error();
76
+	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) {
77
+			display_db_error();
78
+	}
75 79
 
76 80
 	$connection = mysqli_init();
77 81
 
@@ -81,29 +85,33 @@  discard block
 block discarded – undo
81 85
 
82 86
 	if ($connection)
83 87
 	{
84
-		if (!empty($db_options['port']))
85
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
86
-		else
87
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
88
+		if (!empty($db_options['port'])) {
89
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
90
+		} else {
91
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
92
+		}
88 93
 	}
89 94
 
90 95
 	// Something's wrong, show an error if its fatal (which we assume it is)
91 96
 	if ($success === false)
92 97
 	{
93
-		if (!empty($db_options['non_fatal']))
94
-			return null;
95
-		else
96
-			display_db_error();
98
+		if (!empty($db_options['non_fatal'])) {
99
+					return null;
100
+		} else {
101
+					display_db_error();
102
+		}
97 103
 	}
98 104
 
99 105
 	// Select the database, unless told not to
100
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
101
-		display_db_error();
106
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
107
+			display_db_error();
108
+	}
102 109
 
103 110
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
104 111
 
105
-	if (!empty($db_options['db_mb4']))
106
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
112
+	if (!empty($db_options['db_mb4'])) {
113
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
114
+	}
107 115
 
108 116
 	return $connection;
109 117
 }
@@ -174,34 +182,42 @@  discard block
 block discarded – undo
174 182
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
175 183
 
176 184
 	list ($values, $connection) = $db_callback;
177
-	if (!is_object($connection))
178
-		display_db_error();
185
+	if (!is_object($connection)) {
186
+			display_db_error();
187
+	}
179 188
 
180
-	if ($matches[1] === 'db_prefix')
181
-		return $db_prefix;
189
+	if ($matches[1] === 'db_prefix') {
190
+			return $db_prefix;
191
+	}
182 192
 
183
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
184
-		return $user_info[$matches[1]];
193
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
194
+			return $user_info[$matches[1]];
195
+	}
185 196
 
186
-	if ($matches[1] === 'empty')
187
-		return '\'\'';
197
+	if ($matches[1] === 'empty') {
198
+			return '\'\'';
199
+	}
188 200
 
189
-	if (!isset($matches[2]))
190
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
201
+	if (!isset($matches[2])) {
202
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
203
+	}
191 204
 
192
-	if ($matches[1] === 'literal')
193
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
205
+	if ($matches[1] === 'literal') {
206
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
207
+	}
194 208
 
195
-	if (!isset($values[$matches[2]]))
196
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
209
+	if (!isset($values[$matches[2]])) {
210
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
211
+	}
197 212
 
198 213
 	$replacement = $values[$matches[2]];
199 214
 
200 215
 	switch ($matches[1])
201 216
 	{
202 217
 		case 'int':
203
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
204
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
219
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+			}
205 221
 			return (string) (int) $replacement;
206 222
 		break;
207 223
 
@@ -213,65 +229,73 @@  discard block
 block discarded – undo
213 229
 		case 'array_int':
214 230
 			if (is_array($replacement))
215 231
 			{
216
-				if (empty($replacement))
217
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+				if (empty($replacement)) {
233
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+				}
218 235
 
219 236
 				foreach ($replacement as $key => $value)
220 237
 				{
221
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
222
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
238
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
239
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+					}
223 241
 
224 242
 					$replacement[$key] = (string) (int) $value;
225 243
 				}
226 244
 
227 245
 				return implode(', ', $replacement);
246
+			} else {
247
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228 248
 			}
229
-			else
230
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231 249
 
232 250
 		break;
233 251
 
234 252
 		case 'array_string':
235 253
 			if (is_array($replacement))
236 254
 			{
237
-				if (empty($replacement))
238
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+				if (empty($replacement)) {
256
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+				}
239 258
 
240
-				foreach ($replacement as $key => $value)
241
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
259
+				foreach ($replacement as $key => $value) {
260
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
261
+				}
242 262
 
243 263
 				return implode(', ', $replacement);
264
+			} else {
265
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244 266
 			}
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247 267
 		break;
248 268
 
249 269
 		case 'date':
250
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
251
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
271
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
272
+			} else {
273
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+			}
254 275
 		break;
255 276
 
256 277
 		case 'time':
257
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
258
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
259
-			else
260
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
279
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
280
+			} else {
281
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			}
261 283
 		break;
262 284
 
263 285
 		case 'datetime':
264
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
265
-				return 'str_to_date('.
286
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
287
+							return 'str_to_date('.
266 288
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
267 289
 					',\'%Y-%m-%d %h:%i:%s\')';
268
-			else
269
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
290
+			} else {
291
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
292
+			}
270 293
 		break;
271 294
 
272 295
 		case 'float':
273
-			if (!is_numeric($replacement))
274
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
296
+			if (!is_numeric($replacement)) {
297
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298
+			}
275 299
 			return (string) (float) $replacement;
276 300
 		break;
277 301
 
@@ -285,32 +309,37 @@  discard block
 block discarded – undo
285 309
 		break;
286 310
 
287 311
 		case 'inet':
288
-			if ($replacement == 'null' || $replacement == '')
289
-				return 'null';
290
-			if (!isValidIP($replacement))
291
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+			if ($replacement == 'null' || $replacement == '') {
313
+							return 'null';
314
+			}
315
+			if (!isValidIP($replacement)) {
316
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
317
+			}
292 318
 			//we don't use the native support of mysql > 5.6.2
293 319
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
294 320
 
295 321
 		case 'array_inet':
296 322
 			if (is_array($replacement))
297 323
 			{
298
-				if (empty($replacement))
299
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
324
+				if (empty($replacement)) {
325
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
326
+				}
300 327
 
301 328
 				foreach ($replacement as $key => $value)
302 329
 				{
303
-					if ($replacement == 'null' || $replacement == '')
304
-						$replacement[$key] = 'null';
305
-					if (!isValidIP($value))
306
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
330
+					if ($replacement == 'null' || $replacement == '') {
331
+											$replacement[$key] = 'null';
332
+					}
333
+					if (!isValidIP($value)) {
334
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
335
+					}
307 336
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
308 337
 				}
309 338
 
310 339
 				return implode(', ', $replacement);
340
+			} else {
341
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
311 342
 			}
312
-			else
313
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314 343
 		break;
315 344
 
316 345
 		default:
@@ -381,18 +410,20 @@  discard block
 block discarded – undo
381 410
 	// One more query....
382 411
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
383 412
 
384
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
385
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
413
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
414
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
415
+	}
386 416
 
387 417
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
388 418
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
389 419
 	{
390 420
 		// Add before LIMIT
391
-		if ($pos = strpos($db_string, 'LIMIT '))
392
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
393
-		else
394
-			// Append it.
421
+		if ($pos = strpos($db_string, 'LIMIT ')) {
422
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
423
+		} else {
424
+					// Append it.
395 425
 			$db_string .= "\n\t\t\tORDER BY null";
426
+		}
396 427
 	}
397 428
 
398 429
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -418,17 +449,18 @@  discard block
 block discarded – undo
418 449
 		while (true)
419 450
 		{
420 451
 			$pos = strpos($db_string_1, '\'', $pos + 1);
421
-			if ($pos === false)
422
-				break;
452
+			if ($pos === false) {
453
+							break;
454
+			}
423 455
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
424 456
 
425 457
 			while (true)
426 458
 			{
427 459
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
428 460
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
429
-				if ($pos1 === false)
430
-					break;
431
-				elseif ($pos2 === false || $pos2 > $pos1)
461
+				if ($pos1 === false) {
462
+									break;
463
+				} elseif ($pos2 === false || $pos2 > $pos1)
432 464
 				{
433 465
 					$pos = $pos1;
434 466
 					break;
@@ -444,16 +476,19 @@  discard block
 block discarded – undo
444 476
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
445 477
 
446 478
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
447
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
448
-			$fail = true;
479
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
480
+					$fail = true;
481
+		}
449 482
 		// Trying to change passwords, slow us down, or something?
450
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
451
-			$fail = true;
452
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
453
-			$fail = true;
483
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
484
+					$fail = true;
485
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
486
+					$fail = true;
487
+		}
454 488
 
455
-		if (!empty($fail) && function_exists('log_error'))
456
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
489
+		if (!empty($fail) && function_exists('log_error')) {
490
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
491
+		}
457 492
 	}
458 493
 
459 494
 	// Debugging.
@@ -463,8 +498,9 @@  discard block
 block discarded – undo
463 498
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
464 499
 
465 500
 		// Initialize $db_cache if not already initialized.
466
-		if (!isset($db_cache))
467
-			$db_cache = array();
501
+		if (!isset($db_cache)) {
502
+					$db_cache = array();
503
+		}
468 504
 
469 505
 		if (!empty($_SESSION['debug_redirect']))
470 506
 		{
@@ -480,17 +516,20 @@  discard block
 block discarded – undo
480 516
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
481 517
 	}
482 518
 
483
-	if (empty($db_unbuffered))
484
-		$ret = @mysqli_query($connection, $db_string);
485
-	else
486
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
519
+	if (empty($db_unbuffered)) {
520
+			$ret = @mysqli_query($connection, $db_string);
521
+	} else {
522
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
523
+	}
487 524
 
488
-	if ($ret === false && empty($db_values['db_error_skip']))
489
-		$ret = smf_db_error($db_string, $connection);
525
+	if ($ret === false && empty($db_values['db_error_skip'])) {
526
+			$ret = smf_db_error($db_string, $connection);
527
+	}
490 528
 
491 529
 	// Debugging.
492
-	if (isset($db_show_debug) && $db_show_debug === true)
493
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
530
+	if (isset($db_show_debug) && $db_show_debug === true) {
531
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
532
+	}
494 533
 
495 534
 	return $ret;
496 535
 }
@@ -537,12 +576,13 @@  discard block
 block discarded – undo
537 576
 	// Decide which connection to use
538 577
 	$connection = $connection === null ? $db_connection : $connection;
539 578
 
540
-	if ($type == 'begin')
541
-		return @mysqli_query($connection, 'BEGIN');
542
-	elseif ($type == 'rollback')
543
-		return @mysqli_query($connection, 'ROLLBACK');
544
-	elseif ($type == 'commit')
545
-		return @mysqli_query($connection, 'COMMIT');
579
+	if ($type == 'begin') {
580
+			return @mysqli_query($connection, 'BEGIN');
581
+	} elseif ($type == 'rollback') {
582
+			return @mysqli_query($connection, 'ROLLBACK');
583
+	} elseif ($type == 'commit') {
584
+			return @mysqli_query($connection, 'COMMIT');
585
+	}
546 586
 
547 587
 	return false;
548 588
 }
@@ -580,8 +620,9 @@  discard block
 block discarded – undo
580 620
 	//    1213: Deadlock found.
581 621
 
582 622
 	// Log the error.
583
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
584
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
623
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
624
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
625
+	}
585 626
 
586 627
 	// Database error auto fixing ;).
587 628
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -590,8 +631,9 @@  discard block
 block discarded – undo
590 631
 		$old_cache = @$modSettings['cache_enable'];
591 632
 		$modSettings['cache_enable'] = '1';
592 633
 
593
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
594
-			$db_last_error = max(@$db_last_error, $temp);
634
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
635
+					$db_last_error = max(@$db_last_error, $temp);
636
+		}
595 637
 
596 638
 		if (@$db_last_error < time() - 3600 * 24 * 3)
597 639
 		{
@@ -607,8 +649,9 @@  discard block
 block discarded – undo
607 649
 					foreach ($tables as $table)
608 650
 					{
609 651
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
610
-						if (trim($table) != '')
611
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
652
+						if (trim($table) != '') {
653
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
654
+						}
612 655
 					}
613 656
 				}
614 657
 
@@ -617,8 +660,9 @@  discard block
 block discarded – undo
617 660
 			// Table crashed.  Let's try to fix it.
618 661
 			elseif ($query_errno == 1016)
619 662
 			{
620
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
621
-					$fix_tables = array('`' . $match[1] . '`');
663
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
664
+									$fix_tables = array('`' . $match[1] . '`');
665
+				}
622 666
 			}
623 667
 			// Indexes crashed.  Should be easy to fix!
624 668
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -637,13 +681,15 @@  discard block
 block discarded – undo
637 681
 
638 682
 			// Make a note of the REPAIR...
639 683
 			cache_put_data('db_last_error', time(), 600);
640
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
641
-				updateSettingsFile(array('db_last_error' => time()));
684
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
685
+							updateSettingsFile(array('db_last_error' => time()));
686
+			}
642 687
 
643 688
 			// Attempt to find and repair the broken table.
644
-			foreach ($fix_tables as $table)
645
-				$smcFunc['db_query']('', "
689
+			foreach ($fix_tables as $table) {
690
+							$smcFunc['db_query']('', "
646 691
 					REPAIR TABLE $table", false, false);
692
+			}
647 693
 
648 694
 			// And send off an email!
649 695
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -652,11 +698,12 @@  discard block
 block discarded – undo
652 698
 
653 699
 			// Try the query again...?
654 700
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
655
-			if ($ret !== false)
656
-				return $ret;
701
+			if ($ret !== false) {
702
+							return $ret;
703
+			}
704
+		} else {
705
+					$modSettings['cache_enable'] = $old_cache;
657 706
 		}
658
-		else
659
-			$modSettings['cache_enable'] = $old_cache;
660 707
 
661 708
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
662 709
 		if (in_array($query_errno, array(1205, 1213)))
@@ -669,24 +716,27 @@  discard block
 block discarded – undo
669 716
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
670 717
 
671 718
 					$new_errno = mysqli_errno($db_connection);
672
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
673
-						break;
719
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
720
+											break;
721
+					}
674 722
 				}
675 723
 
676 724
 				// If it failed again, shucks to be you... we're not trying it over and over.
677
-				if ($ret !== false)
678
-					return $ret;
725
+				if ($ret !== false) {
726
+									return $ret;
727
+				}
679 728
 			}
680 729
 		}
681 730
 		// Are they out of space, perhaps?
682 731
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
683 732
 		{
684
-			if (!isset($txt))
685
-				$query_error .= ' - check database storage space.';
686
-			else
733
+			if (!isset($txt)) {
734
+							$query_error .= ' - check database storage space.';
735
+			} else
687 736
 			{
688
-				if (!isset($txt['mysql_error_space']))
689
-					loadLanguage('Errors');
737
+				if (!isset($txt['mysql_error_space'])) {
738
+									loadLanguage('Errors');
739
+				}
690 740
 
691 741
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
692 742
 			}
@@ -694,15 +744,17 @@  discard block
 block discarded – undo
694 744
 	}
695 745
 
696 746
 	// Nothing's defined yet... just die with it.
697
-	if (empty($context) || empty($txt))
698
-		die($query_error);
747
+	if (empty($context) || empty($txt)) {
748
+			die($query_error);
749
+	}
699 750
 
700 751
 	// Show an error message, if possible.
701 752
 	$context['error_title'] = $txt['database_error'];
702
-	if (allowedTo('admin_forum'))
703
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
704
-	else
705
-		$context['error_message'] = $txt['try_again'];
753
+	if (allowedTo('admin_forum')) {
754
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
755
+	} else {
756
+			$context['error_message'] = $txt['try_again'];
757
+	}
706 758
 
707 759
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
708 760
 	{
@@ -734,8 +786,9 @@  discard block
 block discarded – undo
734 786
 	$return_var = null;
735 787
 
736 788
 	// With nothing to insert, simply return.
737
-	if (empty($data))
738
-		return;
789
+	if (empty($data)) {
790
+			return;
791
+	}
739 792
 
740 793
 	// Replace the prefix holder with the actual prefix.
741 794
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -745,23 +798,26 @@  discard block
 block discarded – undo
745 798
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
746 799
 	{
747 800
 		$with_returning = true;
748
-		if ($returnmode == 2)
749
-			$return_var = array();
801
+		if ($returnmode == 2) {
802
+					$return_var = array();
803
+		}
750 804
 	}
751 805
 
752 806
 	// Inserting data as a single row can be done as a single array.
753
-	if (!is_array($data[array_rand($data)]))
754
-		$data = array($data);
807
+	if (!is_array($data[array_rand($data)])) {
808
+			$data = array($data);
809
+	}
755 810
 
756 811
 	// Create the mold for a single row insert.
757 812
 	$insertData = '(';
758 813
 	foreach ($columns as $columnName => $type)
759 814
 	{
760 815
 		// Are we restricting the length?
761
-		if (strpos($type, 'string-') !== false)
762
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
763
-		else
764
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
816
+		if (strpos($type, 'string-') !== false) {
817
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
818
+		} else {
819
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
820
+		}
765 821
 	}
766 822
 	$insertData = substr($insertData, 0, -2) . ')';
767 823
 
@@ -770,8 +826,9 @@  discard block
 block discarded – undo
770 826
 
771 827
 	// Here's where the variables are injected to the query.
772 828
 	$insertRows = array();
773
-	foreach ($data as $dataRow)
774
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
829
+	foreach ($data as $dataRow) {
830
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
831
+	}
775 832
 
776 833
 	// Determine the method of insertion.
777 834
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -790,8 +847,7 @@  discard block
 block discarded – undo
790 847
 			),
791 848
 			$connection
792 849
 		);
793
-	}
794
-	else //special way for ignore method with returning
850
+	} else //special way for ignore method with returning
795 851
 	{
796 852
 		$count = count($insertRows);
797 853
 		$ai = 0;
@@ -811,19 +867,21 @@  discard block
 block discarded – undo
811 867
 			);
812 868
 			$new_id = $smcFunc['db_insert_id']();
813 869
 
814
-			if ($last_id != $new_id) //the inserted value was new
870
+			if ($last_id != $new_id) {
871
+				//the inserted value was new
815 872
 			{
816 873
 				$ai = $new_id;
817 874
 			}
818
-			else	// the inserted value already exists we need to find the pk
875
+			} else	// the inserted value already exists we need to find the pk
819 876
 			{
820 877
 				$where_string = '';
821 878
 				$count2 = count($indexed_columns);
822 879
 				for ($x = 0; $x < $count2; $x++)
823 880
 				{
824 881
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
825
-					if (($x + 1) < $count2)
826
-						$where_string += ' AND ';
882
+					if (($x + 1) < $count2) {
883
+											$where_string += ' AND ';
884
+					}
827 885
 				}
828 886
 
829 887
 				$request = $smcFunc['db_query']('','
@@ -839,25 +897,27 @@  discard block
 block discarded – undo
839 897
 				}
840 898
 			}
841 899
 
842
-			if ($returnmode == 1)
843
-				$return_var = $ai;
844
-			else if ($returnmode == 2)
845
-				$return_var[] = $ai;
900
+			if ($returnmode == 1) {
901
+							$return_var = $ai;
902
+			} else if ($returnmode == 2) {
903
+							$return_var[] = $ai;
904
+			}
846 905
 		}
847 906
 	}
848 907
 
849 908
 
850 909
 	if ($with_returning)
851 910
 	{
852
-		if ($returnmode == 1 && empty($return_var))
853
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
854
-		else if ($returnmode == 2 && empty($return_var))
911
+		if ($returnmode == 1 && empty($return_var)) {
912
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
913
+		} else if ($returnmode == 2 && empty($return_var))
855 914
 		{
856 915
 			$return_var = array();
857 916
 			$count = count($insertRows);
858 917
 			$start = smf_db_insert_id($table, $keys[0]);
859
-			for ($i = 0; $i < $count; $i++ )
860
-				$return_var[] = $start + $i;
918
+			for ($i = 0; $i < $count; $i++ ) {
919
+							$return_var[] = $start + $i;
920
+			}
861 921
 		}
862 922
 		return $return_var;
863 923
 	}
@@ -875,8 +935,9 @@  discard block
 block discarded – undo
875 935
  */
876 936
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
877 937
 {
878
-	if (empty($log_message))
879
-		$log_message = $error_message;
938
+	if (empty($log_message)) {
939
+			$log_message = $error_message;
940
+	}
880 941
 
881 942
 	foreach (debug_backtrace() as $step)
882 943
 	{
@@ -895,12 +956,14 @@  discard block
 block discarded – undo
895 956
 	}
896 957
 
897 958
 	// A special case - we want the file and line numbers for debugging.
898
-	if ($error_type == 'return')
899
-		return array($file, $line);
959
+	if ($error_type == 'return') {
960
+			return array($file, $line);
961
+	}
900 962
 
901 963
 	// Is always a critical error.
902
-	if (function_exists('log_error'))
903
-		log_error($log_message, 'critical', $file, $line);
964
+	if (function_exists('log_error')) {
965
+			log_error($log_message, 'critical', $file, $line);
966
+	}
904 967
 
905 968
 	if (function_exists('fatal_error'))
906 969
 	{
@@ -908,12 +971,12 @@  discard block
 block discarded – undo
908 971
 
909 972
 		// Cannot continue...
910 973
 		exit;
974
+	} elseif ($error_type) {
975
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
976
+	} else {
977
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
978
+	}
911 979
 	}
912
-	elseif ($error_type)
913
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
914
-	else
915
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
916
-}
917 980
 
918 981
 /**
919 982
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -930,10 +993,11 @@  discard block
 block discarded – undo
930 993
 		'\\' => '\\\\',
931 994
 	);
932 995
 
933
-	if ($translate_human_wildcards)
934
-		$replacements += array(
996
+	if ($translate_human_wildcards) {
997
+			$replacements += array(
935 998
 			'*' => '%',
936 999
 		);
1000
+	}
937 1001
 
938 1002
 	return strtr($string, $replacements);
939 1003
 }
@@ -947,8 +1011,9 @@  discard block
 block discarded – undo
947 1011
  */
948 1012
 function smf_is_resource($result)
949 1013
 {
950
-	if ($result instanceof mysqli_result)
951
-		return true;
1014
+	if ($result instanceof mysqli_result) {
1015
+			return true;
1016
+	}
952 1017
 
953 1018
 	return false;
954 1019
 }
@@ -977,19 +1042,22 @@  discard block
 block discarded – undo
977 1042
 	static $mysql_error_data_prep;
978 1043
 
979 1044
 	// without database we can't do anything
980
-	if (empty($db_connection))
981
-		return;
1045
+	if (empty($db_connection)) {
1046
+			return;
1047
+	}
982 1048
 
983
-	if (empty($mysql_error_data_prep))
984
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1049
+	if (empty($mysql_error_data_prep)) {
1050
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
985 1051
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
986 1052
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?, ?)'
987 1053
 			);
1054
+	}
988 1055
 
989
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
990
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
991
-	else
992
-		$error_array[2] = null;
1056
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1057
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1058
+	} else {
1059
+			$error_array[2] = null;
1060
+	}
993 1061
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis',
994 1062
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
995 1063
 		$error_array[7], $error_array[8], $error_array[9]);
@@ -1011,8 +1079,9 @@  discard block
 block discarded – undo
1011 1079
 	$count = count($array_values);
1012 1080
 	$then = ($desc ? ' THEN -' : ' THEN ');
1013 1081
 
1014
-	for ($i = 0; $i < $count; $i++)
1015
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1082
+	for ($i = 0; $i < $count; $i++) {
1083
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1084
+	}
1016 1085
 
1017 1086
 	$return .= 'END';
1018 1087
 	return $return;
@@ -1038,17 +1107,20 @@  discard block
 block discarded – undo
1038 1107
 	global $smcFunc;
1039 1108
 	static $return;
1040 1109
 
1041
-	if (isset($return))
1042
-		return $return;
1110
+	if (isset($return)) {
1111
+			return $return;
1112
+	}
1043 1113
 
1044 1114
 	db_extend('extra');
1045 1115
 
1046 1116
 	$version = $smcFunc['db_get_version']();
1047 1117
 
1048
-	if (strpos(strtolower($version), 'mariadb') !== false)
1049
-		$return = version_compare($version, '10.2.2', '>=');
1050
-	else //mysql
1118
+	if (strpos(strtolower($version), 'mariadb') !== false) {
1119
+			$return = version_compare($version, '10.2.2', '>=');
1120
+	} else {
1121
+		//mysql
1051 1122
 		$return = version_compare($version, '8.0.1', '>=');
1123
+	}
1052 1124
 
1053 1125
 	return $return;
1054 1126
 }
Please login to merge, or discard this patch.