Completed
Pull Request — release-2.1 (#4995)
by Jeremy
06:49
created
Sources/ManageErrors.php 1 patch
Braces   +52 added lines, -40 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
  * View the forum's error log.
@@ -30,12 +31,14 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
31 32
 
32 33
 	// Viewing contents of a file?
33
-	if (isset($_GET['file']))
34
-		return ViewFile();
34
+	if (isset($_GET['file'])) {
35
+			return ViewFile();
36
+	}
35 37
 	
36 38
 	// Viewing contents of a backtrace?
37
-	if (isset($_GET['backtrace']))
38
-		return ViewBacktrace();
39
+	if (isset($_GET['backtrace'])) {
40
+			return ViewBacktrace();
41
+	}
39 42
 
40 43
 	// Check for the administrative permission to do this.
41 44
 	isAllowedTo('admin_forum');
@@ -89,8 +92,8 @@  discard block
 block discarded – undo
89 92
 	);
90 93
 
91 94
 	// Set up the filtering...
92
-	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
93
-		$filter = array(
95
+	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) {
96
+			$filter = array(
94 97
 			'variable' => $_GET['filter'],
95 98
 			'value' => array(
96 99
 				'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
@@ -98,10 +101,12 @@  discard block
 block discarded – undo
98 101
 			'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
99 102
 			'entity' => $filters[$_GET['filter']]['txt']
100 103
 		);
104
+	}
101 105
 
102 106
 	// Deleting, are we?
103
-	if (isset($_POST['delall']) || isset($_POST['delete']))
104
-		deleteErrors();
107
+	if (isset($_POST['delall']) || isset($_POST['delete'])) {
108
+			deleteErrors();
109
+	}
105 110
 
106 111
 	// Just how many errors are there?
107 112
 	$result = $smcFunc['db_query']('', '
@@ -116,12 +121,14 @@  discard block
 block discarded – undo
116 121
 	$smcFunc['db_free_result']($result);
117 122
 
118 123
 	// If this filter is empty...
119
-	if ($num_errors == 0 && isset($filter))
120
-		redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
124
+	if ($num_errors == 0 && isset($filter)) {
125
+			redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
126
+	}
121 127
 
122 128
 	// Clean up start.
123
-	if (!isset($_GET['start']) || $_GET['start'] < 0)
124
-		$_GET['start'] = 0;
129
+	if (!isset($_GET['start']) || $_GET['start'] < 0) {
130
+			$_GET['start'] = 0;
131
+	}
125 132
 
126 133
 	// Do we want to reverse error listing?
127 134
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
@@ -131,9 +138,9 @@  discard block
 block discarded – undo
131 138
 	$context['start'] = $_GET['start'];
132 139
 
133 140
 	// Update the error count
134
-	if (!isset($filter))
135
-		$context['num_errors'] = $num_errors;
136
-	else
141
+	if (!isset($filter)) {
142
+			$context['num_errors'] = $num_errors;
143
+	} else
137 144
 	{
138 145
 		// We want all errors, not just the number of filtered messages...
139 146
 		$query = $smcFunc['db_query']('', '
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
166 173
 	{
167 174
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
168
-		if ($search_message == $filter['value']['sql'])
169
-			$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
175
+		if ($search_message == $filter['value']['sql']) {
176
+					$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
177
+		}
170 178
 		$show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br>'));
171 179
 
172 180
 		$context['errors'][$row['id_error']] = array(
@@ -225,8 +233,9 @@  discard block
 block discarded – undo
225 233
 				'members' => count($members),
226 234
 			)
227 235
 		);
228
-		while ($row = $smcFunc['db_fetch_assoc']($request))
229
-			$members[$row['id_member']] = $row;
236
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+					$members[$row['id_member']] = $row;
238
+		}
230 239
 		$smcFunc['db_free_result']($request);
231 240
 
232 241
 		// This is a guest...
@@ -258,20 +267,18 @@  discard block
 block discarded – undo
258 267
 			$id = $filter['value']['sql'];
259 268
 			loadMemberData($id, false, 'minimal');
260 269
 			$context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
261
-		}
262
-		elseif ($filter['variable'] == 'url')
263
-			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
264
-		elseif ($filter['variable'] == 'message')
270
+		} elseif ($filter['variable'] == 'url') {
271
+					$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
272
+		} elseif ($filter['variable'] == 'message')
265 273
 		{
266 274
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
267 275
 			$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
268
-		}
269
-		elseif ($filter['variable'] == 'error_type')
276
+		} elseif ($filter['variable'] == 'error_type')
270 277
 		{
271 278
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
279
+		} else {
280
+					$context['filter']['value']['html'] = &$filter['value']['sql'];
272 281
 		}
273
-		else
274
-			$context['filter']['value']['html'] = &$filter['value']['sql'];
275 282
 	}
276 283
 
277 284
 	$context['error_types'] = array();
@@ -312,10 +319,11 @@  discard block
 block discarded – undo
312 319
 	$context['error_types']['all']['label'] .= ' (' . $sum . ')';
313 320
 
314 321
 	// Finally, work out what is the last tab!
315
-	if (isset($context['error_types'][$sum]))
316
-		$context['error_types'][$sum]['is_last'] = true;
317
-	else
318
-		$context['error_types']['all']['is_last'] = true;
322
+	if (isset($context['error_types'][$sum])) {
323
+			$context['error_types'][$sum]['is_last'] = true;
324
+	} else {
325
+			$context['error_types']['all']['is_last'] = true;
326
+	}
319 327
 
320 328
 	// And this is pretty basic ;).
321 329
 	$context['page_title'] = $txt['errlog'];
@@ -341,21 +349,23 @@  discard block
 block discarded – undo
341 349
 	validateToken('admin-el');
342 350
 
343 351
 	// Delete all or just some?
344
-	if (isset($_POST['delall']) && !isset($filter))
345
-		$smcFunc['db_query']('truncate_table', '
352
+	if (isset($_POST['delall']) && !isset($filter)) {
353
+			$smcFunc['db_query']('truncate_table', '
346 354
 			TRUNCATE {db_prefix}log_errors',
347 355
 			array(
348 356
 			)
349 357
 		);
358
+	}
350 359
 	// Deleting all with a filter?
351
-	elseif (isset($_POST['delall']) && isset($filter))
352
-		$smcFunc['db_query']('', '
360
+	elseif (isset($_POST['delall']) && isset($filter)) {
361
+			$smcFunc['db_query']('', '
353 362
 			DELETE FROM {db_prefix}log_errors
354 363
 			WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
355 364
 			array(
356 365
 				'filter' => $filter['value']['sql'],
357 366
 			)
358 367
 		);
368
+	}
359 369
 	// Just specific errors?
360 370
 	elseif (!empty($_POST['delete']))
361 371
 	{
@@ -401,15 +411,17 @@  discard block
 block discarded – undo
401 411
 	$line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
402 412
 
403 413
 	// Make sure the file we are looking for is one they are allowed to look at
404
-	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
405
-		fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
414
+	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) {
415
+			fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
416
+	}
406 417
 
407 418
 	// get the min and max lines
408 419
 	$min = $line - 20 <= 0 ? 1 : $line - 20;
409 420
 	$max = $line + 21; // One additional line to make everything work out correctly
410 421
 
411
-	if ($max <= 0 || $min >= $max)
412
-		fatal_lang_error('error_bad_line');
422
+	if ($max <= 0 || $min >= $max) {
423
+			fatal_lang_error('error_bad_line');
424
+	}
413 425
 
414 426
 	$file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file)))));
415 427
 
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 
255 255
 		case 'datetime':
256 256
 			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)
257
-				return 'str_to_date('.
258
-					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]).
257
+				return 'str_to_date(' .
258
+					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]) .
259 259
 					',\'%Y-%m-%d %h:%i:%s\')';
260 260
 			else
261 261
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 		$old_pos = 0;
407 407
 		$pos = -1;
408 408
 		// Remove the string escape for better runtime
409
-		$db_string_1 = str_replace('\\\'','',$db_string);
409
+		$db_string_1 = str_replace('\\\'', '', $db_string);
410 410
 		while (true)
411 411
 		{
412 412
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 	{
788 788
 		$count = count($insertRows);
789 789
 		$ai = 0;
790
-		for($i = 0; $i < $count; $i++)
790
+		for ($i = 0; $i < $count; $i++)
791 791
 		{
792 792
 			$old_id = $smcFunc['db_insert_id']();
793 793
 
@@ -813,13 +813,13 @@  discard block
 block discarded – undo
813 813
 				$count2 = count($indexed_columns);
814 814
 				for ($x = 0; $x < $count2; $x++)
815 815
 				{
816
-					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
816
+					$where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x];
817 817
 					if (($x + 1) < $count2)
818 818
 						$where_string += ' AND ';
819 819
 				}
820 820
 
821
-				$request = $smcFunc['db_query']('','
822
-					SELECT `'. $keys[0] . '` FROM ' . $table .'
821
+				$request = $smcFunc['db_query']('', '
822
+					SELECT `'. $keys[0] . '` FROM ' . $table . '
823 823
 					WHERE ' . $where_string . ' LIMIT 1',
824 824
 					array()
825 825
 				);
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 			$return_var = array();
849 849
 			$count = count($insertRows);
850 850
 			$start = smf_db_insert_id($table, $keys[0]);
851
-			for ($i = 0; $i < $count; $i++ )
851
+			for ($i = 0; $i < $count; $i++)
852 852
 				$return_var[] = $start + $i;
853 853
 		}
854 854
 		return $return_var;
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis',
986 986
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
987 987
 		$error_array[7], $error_array[8], $error_array[9]);
988
-	mysqli_stmt_execute ($mysql_error_data_prep);
988
+	mysqli_stmt_execute($mysql_error_data_prep);
989 989
 }
990 990
 
991 991
 /**
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
  */
1000 1000
 function smf_db_custom_order($field, $array_values, $desc = false)
1001 1001
 {
1002
-	$return = 'CASE '. $field . ' ';
1002
+	$return = 'CASE ' . $field . ' ';
1003 1003
 	$count = count($array_values);
1004 1004
 	$then = ($desc ? ' THEN -' : ' THEN ');
1005 1005
 
Please login to merge, or discard this 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.
Sources/ManageMembergroups.php 1 patch
Braces   +125 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 
20 21
 /**
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings');
45 46
 
46 47
 	// Is it elsewhere?
47
-	if (isset($subActions[$_REQUEST['sa']][2]))
48
-		require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
48
+	if (isset($subActions[$_REQUEST['sa']][2])) {
49
+			require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
50
+	}
49 51
 
50 52
 	// Do the permission check, you might not be allowed her.
51 53
 	isAllowedTo($subActions[$_REQUEST['sa']][1]);
@@ -104,19 +106,20 @@  discard block
 block discarded – undo
104 106
 					'function' => function($rowData) use ($scripturl)
105 107
 					{
106 108
 						// Since the moderator group has no explicit members, no link is needed.
107
-						if ($rowData['id_group'] == 3)
108
-							$group_name = $rowData['group_name'];
109
-						else
109
+						if ($rowData['id_group'] == 3) {
110
+													$group_name = $rowData['group_name'];
111
+						} else
110 112
 						{
111 113
 							$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']);
112 114
 							$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
113 115
 						}
114 116
 
115 117
 						// Add a help option for moderator and administrator.
116
-						if ($rowData['id_group'] == 1)
117
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
-						elseif ($rowData['id_group'] == 3)
119
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
118
+						if ($rowData['id_group'] == 1) {
119
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
120
+						} elseif ($rowData['id_group'] == 3) {
121
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
122
+						}
120 123
 
121 124
 						return $group_name;
122 125
 					},
@@ -329,12 +332,14 @@  discard block
 block discarded – undo
329 332
 		call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
330 333
 
331 334
 		// Update the post groups now, if this is a post group!
332
-		if (isset($_POST['min_posts']))
333
-			updateStats('postgroups');
335
+		if (isset($_POST['min_posts'])) {
336
+					updateStats('postgroups');
337
+		}
334 338
 
335 339
 		// You cannot set permissions for post groups if they are disabled.
336
-		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups']))
337
-			$_POST['perm_type'] = '';
340
+		if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) {
341
+					$_POST['perm_type'] = '';
342
+		}
338 343
 
339 344
 		if ($_POST['perm_type'] == 'predefined')
340 345
 		{
@@ -364,8 +369,9 @@  discard block
 block discarded – undo
364 369
 				$smcFunc['db_free_result']($request);
365 370
 
366 371
 				// Protected groups are... well, protected!
367
-				if ($copy_type == 1)
368
-					fatal_lang_error('membergroup_does_not_exist');
372
+				if ($copy_type == 1) {
373
+									fatal_lang_error('membergroup_does_not_exist');
374
+				}
369 375
 			}
370 376
 
371 377
 			// Don't allow copying of a real priviledged person!
@@ -383,18 +389,20 @@  discard block
 block discarded – undo
383 389
 			$inserts = array();
384 390
 			while ($row = $smcFunc['db_fetch_assoc']($request))
385 391
 			{
386
-				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions']))
387
-					$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
392
+				if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) {
393
+									$inserts[] = array($id_group, $row['permission'], $row['add_deny']);
394
+				}
388 395
 			}
389 396
 			$smcFunc['db_free_result']($request);
390 397
 
391
-			if (!empty($inserts))
392
-				$smcFunc['db_insert']('insert',
398
+			if (!empty($inserts)) {
399
+							$smcFunc['db_insert']('insert',
393 400
 					'{db_prefix}permissions',
394 401
 					array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
395 402
 					$inserts,
396 403
 					array('id_group', 'permission')
397 404
 				);
405
+			}
398 406
 
399 407
 			$request = $smcFunc['db_query']('', '
400 408
 				SELECT id_profile, permission, add_deny
@@ -405,17 +413,19 @@  discard block
 block discarded – undo
405 413
 				)
406 414
 			);
407 415
 			$inserts = array();
408
-			while ($row = $smcFunc['db_fetch_assoc']($request))
409
-				$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
416
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
417
+							$inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
418
+			}
410 419
 			$smcFunc['db_free_result']($request);
411 420
 
412
-			if (!empty($inserts))
413
-				$smcFunc['db_insert']('insert',
421
+			if (!empty($inserts)) {
422
+							$smcFunc['db_insert']('insert',
414 423
 					'{db_prefix}board_permissions',
415 424
 					array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
416 425
 					$inserts,
417 426
 					array('id_group', 'id_profile', 'permission')
418 427
 				);
428
+			}
419 429
 
420 430
 			// Also get some membergroup information if we're copying and not copying from guests...
421 431
 			if ($copy_id > 0 && $_POST['perm_type'] == 'copy')
@@ -468,14 +478,15 @@  discard block
 block discarded – undo
468 478
 		$changed_boards['allow'] = array();
469 479
 		$changed_boards['deny'] = array();
470 480
 		$changed_boards['ignore'] = array();
471
-		foreach ($accesses as $group_id => $action)
472
-			$changed_boards[$action][] = (int) $group_id;
481
+		foreach ($accesses as $group_id => $action) {
482
+					$changed_boards[$action][] = (int) $group_id;
483
+		}
473 484
 
474 485
 		foreach (array('allow', 'deny') as $board_action)
475 486
 		{
476 487
 			// Only do this if they have special access requirements.
477
-			if (!empty($changed_boards[$board_action]))
478
-				$smcFunc['db_query']('', '
488
+			if (!empty($changed_boards[$board_action])) {
489
+							$smcFunc['db_query']('', '
479 490
 					UPDATE {db_prefix}boards
480 491
 					SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
481 492
 					WHERE id_board IN ({array_int:board_list})',
@@ -487,11 +498,13 @@  discard block
 block discarded – undo
487 498
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
488 499
 					)
489 500
 				);
501
+			}
490 502
 		}
491 503
 
492 504
 		// If this is joinable then set it to show group membership in people's profiles.
493
-		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
494
-			updateSettings(array('show_group_membership' => 1));
505
+		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) {
506
+					updateSettings(array('show_group_membership' => 1));
507
+		}
495 508
 
496 509
 		// Rebuild the group cache.
497 510
 		updateSettings(array(
@@ -512,8 +525,9 @@  discard block
 block discarded – undo
512 525
 	$context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
513 526
 	$context['allow_protected'] = allowedTo('admin_forum');
514 527
 
515
-	if (!empty($modSettings['deny_boards_access']))
516
-		loadLanguage('ManagePermissions');
528
+	if (!empty($modSettings['deny_boards_access'])) {
529
+			loadLanguage('ManagePermissions');
530
+	}
517 531
 
518 532
 	$result = $smcFunc['db_query']('', '
519 533
 		SELECT id_group, group_name
@@ -530,11 +544,12 @@  discard block
 block discarded – undo
530 544
 		)
531 545
 	);
532 546
 	$context['groups'] = array();
533
-	while ($row = $smcFunc['db_fetch_assoc']($result))
534
-		$context['groups'][] = array(
547
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
548
+			$context['groups'][] = array(
535 549
 			'id' => $row['id_group'],
536 550
 			'name' => $row['group_name']
537 551
 		);
552
+	}
538 553
 	$smcFunc['db_free_result']($result);
539 554
 
540 555
 	$request = $smcFunc['db_query']('', '
@@ -551,12 +566,13 @@  discard block
 block discarded – undo
551 566
 	while ($row = $smcFunc['db_fetch_assoc']($request))
552 567
 	{
553 568
 		// This category hasn't been set up yet..
554
-		if (!isset($context['categories'][$row['id_cat']]))
555
-			$context['categories'][$row['id_cat']] = array(
569
+		if (!isset($context['categories'][$row['id_cat']])) {
570
+					$context['categories'][$row['id_cat']] = array(
556 571
 				'id' => $row['id_cat'],
557 572
 				'name' => $row['cat_name'],
558 573
 				'boards' => array()
559 574
 			);
575
+		}
560 576
 
561 577
 		// Set this board up, and let the template know when it's a child.  (indent them..)
562 578
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -603,8 +619,9 @@  discard block
 block discarded – undo
603 619
 	require_once($sourcedir . '/Subs-Membergroups.php');
604 620
 	$result = deleteMembergroups((int) $_REQUEST['group']);
605 621
 	// Need to throw a warning if it went wrong, but this is the only one we have a message for...
606
-	if ($result === 'group_cannot_delete_sub')
607
-		fatal_lang_error('membergroups_cannot_delete_paid', false);
622
+	if ($result === 'group_cannot_delete_sub') {
623
+			fatal_lang_error('membergroups_cannot_delete_paid', false);
624
+	}
608 625
 
609 626
 	// Go back to the membergroup index.
610 627
 	redirectexit('action=admin;area=membergroups;');
@@ -626,8 +643,9 @@  discard block
 block discarded – undo
626 643
 
627 644
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
628 645
 
629
-	if (!empty($modSettings['deny_boards_access']))
630
-		loadLanguage('ManagePermissions');
646
+	if (!empty($modSettings['deny_boards_access'])) {
647
+			loadLanguage('ManagePermissions');
648
+	}
631 649
 
632 650
 	// Make sure this group is editable.
633 651
 	if (!empty($_REQUEST['group']))
@@ -649,8 +667,9 @@  discard block
 block discarded – undo
649 667
 	}
650 668
 
651 669
 	// Now, do we have a valid id?
652
-	if (empty($_REQUEST['group']))
653
-		fatal_lang_error('membergroup_does_not_exist', false);
670
+	if (empty($_REQUEST['group'])) {
671
+			fatal_lang_error('membergroup_does_not_exist', false);
672
+	}
654 673
 
655 674
 	// People who can manage boards are a bit special.
656 675
 	require_once($sourcedir . '/Subs-Members.php');
@@ -681,8 +700,9 @@  discard block
 block discarded – undo
681 700
 		require_once($sourcedir . '/Subs-Membergroups.php');
682 701
 		$result = deleteMembergroups($_REQUEST['group']);
683 702
 		// Need to throw a warning if it went wrong, but this is the only one we have a message for...
684
-		if ($result === 'group_cannot_delete_sub')
685
-			fatal_lang_error('membergroups_cannot_delete_paid', false);
703
+		if ($result === 'group_cannot_delete_sub') {
704
+					fatal_lang_error('membergroups_cannot_delete_paid', false);
705
+		}
686 706
 
687 707
 		redirectexit('action=admin;area=membergroups;');
688 708
 	}
@@ -759,16 +779,18 @@  discard block
 block discarded – undo
759 779
 				$request = $smcFunc['db_query']('', '
760 780
 					SELECT id_board
761 781
 					FROM {db_prefix}boards');
762
-				while ($row = $smcFunc['db_fetch_assoc']($request))
763
-					$accesses[(int) $row['id_board']] = 'allow';
782
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
783
+									$accesses[(int) $row['id_board']] = 'allow';
784
+				}
764 785
 				$smcFunc['db_free_result']($request);
765 786
 			}
766 787
 
767 788
 			$changed_boards['allow'] = array();
768 789
 			$changed_boards['deny'] = array();
769 790
 			$changed_boards['ignore'] = array();
770
-			foreach ($accesses as $group_id => $action)
771
-				$changed_boards[$action][] = (int) $group_id;
791
+			foreach ($accesses as $group_id => $action) {
792
+							$changed_boards[$action][] = (int) $group_id;
793
+			}
772 794
 
773 795
 			foreach (array('allow', 'deny') as $board_action)
774 796
 			{
@@ -784,8 +806,8 @@  discard block
 block discarded – undo
784 806
 						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
785 807
 					)
786 808
 				);
787
-				while ($row = $smcFunc['db_fetch_assoc']($request))
788
-					$smcFunc['db_query']('', '
809
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
810
+									$smcFunc['db_query']('', '
789 811
 						UPDATE {db_prefix}boards
790 812
 						SET {raw:column} = {string:member_group_access}
791 813
 						WHERE id_board = {int:current_board}',
@@ -795,11 +817,12 @@  discard block
 block discarded – undo
795 817
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
796 818
 						)
797 819
 					);
820
+				}
798 821
 				$smcFunc['db_free_result']($request);
799 822
 
800 823
 				// Add the membergroup to all boards that hadn't been set yet.
801
-				if (!empty($changed_boards[$board_action]))
802
-					$smcFunc['db_query']('', '
824
+				if (!empty($changed_boards[$board_action])) {
825
+									$smcFunc['db_query']('', '
803 826
 						UPDATE {db_prefix}boards
804 827
 						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
805 828
 						WHERE id_board IN ({array_int:board_list})
@@ -813,6 +836,7 @@  discard block
 block discarded – undo
813 836
 							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
814 837
 						)
815 838
 					);
839
+				}
816 840
 			}
817 841
 		}
818 842
 
@@ -838,12 +862,14 @@  discard block
 block discarded – undo
838 862
 				)
839 863
 			);
840 864
 			$updates = array();
841
-			while ($row = $smcFunc['db_fetch_assoc']($request))
842
-				$updates[$row['additional_groups']][] = $row['id_member'];
865
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
866
+							$updates[$row['additional_groups']][] = $row['id_member'];
867
+			}
843 868
 			$smcFunc['db_free_result']($request);
844 869
 
845
-			foreach ($updates as $additional_groups => $memberArray)
846
-				updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
870
+			foreach ($updates as $additional_groups => $memberArray) {
871
+							updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
872
+			}
847 873
 
848 874
 			// Sorry, but post groups can't moderate boards
849 875
 			$smcFunc['db_query']('', '
@@ -853,8 +879,7 @@  discard block
 block discarded – undo
853 879
 					'current_group' => (int) $_REQUEST['group'],
854 880
 				)
855 881
 			);
856
-		}
857
-		elseif ($_REQUEST['group'] != 3)
882
+		} elseif ($_REQUEST['group'] != 3)
858 883
 		{
859 884
 			// Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
860 885
 			if ($_POST['group_hidden'] == 2)
@@ -869,8 +894,9 @@  discard block
 block discarded – undo
869 894
 					)
870 895
 				);
871 896
 				$updates = array();
872
-				while ($row = $smcFunc['db_fetch_assoc']($request))
873
-					$updates[$row['additional_groups']][] = $row['id_member'];
897
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
898
+									$updates[$row['additional_groups']][] = $row['id_member'];
899
+				}
874 900
 				$smcFunc['db_free_result']($request);
875 901
 
876 902
 				foreach ($updates as $additional_groups => $memberArray)
@@ -912,8 +938,9 @@  discard block
 block discarded – undo
912 938
 			$smcFunc['db_free_result']($request);
913 939
 
914 940
 			// Do we need to update the setting?
915
-			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
916
-				updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
941
+			if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) {
942
+							updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
943
+			}
917 944
 		}
918 945
 
919 946
 		// Do we need to set inherited permissions?
@@ -946,8 +973,9 @@  discard block
 block discarded – undo
946 973
 				{
947 974
 					$moderators[$k] = trim($moderators[$k]);
948 975
 
949
-					if (strlen($moderators[$k]) == 0)
950
-						unset($moderators[$k]);
976
+					if (strlen($moderators[$k]) == 0) {
977
+											unset($moderators[$k]);
978
+					}
951 979
 				}
952 980
 
953 981
 				// Find all the id_member's for the member_name's in the list.
@@ -963,8 +991,9 @@  discard block
 block discarded – undo
963 991
 							'count' => count($moderators),
964 992
 						)
965 993
 					);
966
-					while ($row = $smcFunc['db_fetch_assoc']($request))
967
-						$group_moderators[] = $row['id_member'];
994
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
995
+											$group_moderators[] = $row['id_member'];
996
+					}
968 997
 					$smcFunc['db_free_result']($request);
969 998
 				}
970 999
 			}
@@ -972,8 +1001,9 @@  discard block
 block discarded – undo
972 1001
 			if (!empty($_POST['moderator_list']))
973 1002
 			{
974 1003
 				$moderators = array();
975
-				foreach ($_POST['moderator_list'] as $moderator)
976
-					$moderators[] = (int) $moderator;
1004
+				foreach ($_POST['moderator_list'] as $moderator) {
1005
+									$moderators[] = (int) $moderator;
1006
+				}
977 1007
 
978 1008
 				if (!empty($moderators))
979 1009
 				{
@@ -987,8 +1017,9 @@  discard block
 block discarded – undo
987 1017
 							'num_moderators' => count($moderators),
988 1018
 						)
989 1019
 					);
990
-					while ($row = $smcFunc['db_fetch_assoc']($request))
991
-						$group_moderators[] = $row['id_member'];
1020
+					while ($row = $smcFunc['db_fetch_assoc']($request)) {
1021
+											$group_moderators[] = $row['id_member'];
1022
+					}
992 1023
 					$smcFunc['db_free_result']($request);
993 1024
 				}
994 1025
 			}
@@ -1000,8 +1031,9 @@  discard block
 block discarded – undo
1000 1031
 			if (!empty($group_moderators))
1001 1032
 			{
1002 1033
 				$mod_insert = array();
1003
-				foreach ($group_moderators as $moderator)
1004
-					$mod_insert[] = array($_REQUEST['group'], $moderator);
1034
+				foreach ($group_moderators as $moderator) {
1035
+									$mod_insert[] = array($_REQUEST['group'], $moderator);
1036
+				}
1005 1037
 
1006 1038
 				$smcFunc['db_insert']('insert',
1007 1039
 					'{db_prefix}group_moderators',
@@ -1035,8 +1067,9 @@  discard block
 block discarded – undo
1035 1067
 			'current_group' => (int) $_REQUEST['group'],
1036 1068
 		)
1037 1069
 	);
1038
-	if ($smcFunc['db_num_rows']($request) == 0)
1039
-		fatal_lang_error('membergroup_does_not_exist', false);
1070
+	if ($smcFunc['db_num_rows']($request) == 0) {
1071
+			fatal_lang_error('membergroup_does_not_exist', false);
1072
+	}
1040 1073
 	$row = $smcFunc['db_fetch_assoc']($request);
1041 1074
 	$smcFunc['db_free_result']($request);
1042 1075
 
@@ -1073,14 +1106,16 @@  discard block
 block discarded – undo
1073 1106
 		)
1074 1107
 	);
1075 1108
 	$context['group']['moderators'] = array();
1076
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1077
-		$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1109
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1110
+			$context['group']['moderators'][$row['id_member']] = $row['real_name'];
1111
+	}
1078 1112
 	$smcFunc['db_free_result']($request);
1079 1113
 
1080 1114
 	$context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
1081 1115
 
1082
-	if (!empty($context['group']['moderators']))
1083
-		list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1116
+	if (!empty($context['group']['moderators'])) {
1117
+			list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
1118
+	}
1084 1119
 
1085 1120
 	// Get a list of boards this membergroup is allowed to see.
1086 1121
 	$context['boards'] = array();
@@ -1100,12 +1135,13 @@  discard block
 block discarded – undo
1100 1135
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1101 1136
 		{
1102 1137
 			// This category hasn't been set up yet..
1103
-			if (!isset($context['categories'][$row['id_cat']]))
1104
-				$context['categories'][$row['id_cat']] = array(
1138
+			if (!isset($context['categories'][$row['id_cat']])) {
1139
+							$context['categories'][$row['id_cat']] = array(
1105 1140
 					'id' => $row['id_cat'],
1106 1141
 					'name' => $row['cat_name'],
1107 1142
 					'boards' => array()
1108 1143
 				);
1144
+			}
1109 1145
 
1110 1146
 			// Set this board up, and let the template know when it's a child.  (indent them..)
1111 1147
 			$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -1147,14 +1183,16 @@  discard block
 block discarded – undo
1147 1183
 			$ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION);
1148 1184
 
1149 1185
 			// If the extension is not empty, and it is valid
1150
-			if (!empty($ext) && in_array($ext, $imageExts))
1151
-				$context['possible_icons'][] = $value;
1186
+			if (!empty($ext) && in_array($ext, $imageExts)) {
1187
+							$context['possible_icons'][] = $value;
1188
+			}
1152 1189
 		}
1153 1190
 	}
1154 1191
 
1155 1192
 	// Insert our JS, if we have possible icons.
1156
-	if (!empty($context['possible_icons']))
1157
-		loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown');
1193
+	if (!empty($context['possible_icons'])) {
1194
+			loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown');
1195
+	}
1158 1196
 
1159 1197
 	loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
1160 1198
 
@@ -1176,8 +1214,9 @@  discard block
 block discarded – undo
1176 1214
 		)
1177 1215
 	);
1178 1216
 	$context['inheritable_groups'] = array();
1179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1180
-		$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1217
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1218
+			$context['inheritable_groups'][$row['id_group']] = $row['group_name'];
1219
+	}
1181 1220
 	$smcFunc['db_free_result']($request);
1182 1221
 
1183 1222
 	call_integration_hook('integrate_view_membergroup');
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
 	$smcFunc['db_free_result']($result_boards);
87 87
 
88 88
 	// Run through the categories and boards (or only boards)....
89
-	for (reset($row_boards); key($row_boards)!==null; next($row_boards))
89
+	for (reset($row_boards); key($row_boards) !== null; next($row_boards))
90 90
 	{
91 91
 		$row_board = current($row_boards);
92 92
 
Please login to merge, or discard this patch.
Braces   +71 added lines, -55 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
  * Fetches a list of boards and (optional) categories including
@@ -37,19 +38,21 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// This setting is not allowed to be empty
47
-	if (empty($modSettings['boardindex_max_depth']))
48
-		$modSettings['boardindex_max_depth'] = 1;
49
+	if (empty($modSettings['boardindex_max_depth'])) {
50
+			$modSettings['boardindex_max_depth'] = 1;
51
+	}
49 52
 
50 53
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
51
-	if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']())
52
-		$result_boards = $smcFunc['db_query']('', '
54
+	if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) {
55
+			$result_boards = $smcFunc['db_query']('', '
53 56
 			WITH RECURSIVE 
54 57
 				boards_cte (child_level, id_board, name , description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order)
55 58
 			as
@@ -90,8 +93,8 @@  discard block
 block discarded – undo
90 93
 				'id_parent' => $boardIndexOptions['parent_id'],
91 94
 			)
92 95
 		);
93
-	else
94
-		$result_boards = $smcFunc['db_query']('', '
96
+	} else {
97
+			$result_boards = $smcFunc['db_query']('', '
95 98
 			SELECT' . ($boardIndexOptions['include_categories'] ? '
96 99
 				c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
97 100
 				b.id_board, b.name AS board_name, b.description,
@@ -119,18 +122,21 @@  discard block
 block discarded – undo
119 122
 				'blank_string' => '',
120 123
 			)
121 124
 		);
125
+	}
122 126
 
123 127
 	// Start with an empty array.
124
-	if ($boardIndexOptions['include_categories'])
125
-		$categories = array();
126
-	else
127
-		$this_category = array();
128
+	if ($boardIndexOptions['include_categories']) {
129
+			$categories = array();
130
+	} else {
131
+			$this_category = array();
132
+	}
128 133
 	$boards = array();
129 134
 
130 135
 	// Children can affect parents, so we need to gather all the boards first and then process them after.
131 136
 	$row_boards = array();
132
-	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards))
133
-		$row_boards[$row_board['id_board']] = $row_board;
137
+	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) {
138
+			$row_boards[$row_board['id_board']] = $row_board;
139
+	}
134 140
 	$smcFunc['db_free_result']($result_boards);
135 141
 
136 142
 	// Run through the categories and boards (or only boards)....
@@ -143,8 +149,9 @@  discard block
 block discarded – undo
143 149
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
144 150
 
145 151
 		// Add parent boards to the $boards list later used to fetch moderators
146
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
147
-			$boards[] = $row_board['id_board'];
152
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
153
+					$boards[] = $row_board['id_board'];
154
+		}
148 155
 
149 156
 		if ($boardIndexOptions['include_categories'])
150 157
 		{
@@ -166,8 +173,9 @@  discard block
 block discarded – undo
166 173
 			}
167 174
 
168 175
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
169
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
170
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
176
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
177
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
178
+			}
171 179
 
172 180
 			// Avoid showing category unread link where it only has redirection boards.
173 181
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -186,8 +194,9 @@  discard block
 block discarded – undo
186 194
 				$isChild = false;
187 195
 
188 196
 				// We might or might not have already added this board, so...
189
-				if (!isset($this_category[$row_board['id_board']]))
190
-					$this_category[$row_board['id_board']] = array();
197
+				if (!isset($this_category[$row_board['id_board']])) {
198
+									$this_category[$row_board['id_board']] = array();
199
+				}
191 200
 
192 201
 				$this_category[$row_board['id_board']] += array(
193 202
 					'new' => empty($row_board['is_read']),
@@ -220,14 +229,12 @@  discard block
 block discarded – undo
220 229
 				{
221 230
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
222 231
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
223
-				}
224
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
232
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
225 233
 				{
226 234
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
227 235
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
228 236
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
229
-				}
230
-				else
237
+				} else
231 238
 				{
232 239
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
233 240
 				}
@@ -239,12 +246,13 @@  discard block
 block discarded – undo
239 246
 			$isChild = true;
240 247
 
241 248
 			// Ensure the parent has at least the most important info defined
242
-			if (!isset($this_category[$row_board['id_parent']]))
243
-				$this_category[$row_board['id_parent']] = array(
249
+			if (!isset($this_category[$row_board['id_parent']])) {
250
+							$this_category[$row_board['id_parent']] = array(
244 251
 					'children' => array(),
245 252
 					'children_new' => false,
246 253
 					'board_class' => 'off',
247 254
 				);
255
+			}
248 256
 
249 257
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array(
250 258
 				'id' => $row_board['id_board'],
@@ -288,8 +296,9 @@  discard block
 block discarded – undo
288 296
 			// Propagate some values to the parent board
289 297
 			if (isset($row_boards[$row_board['id_parent']]))
290 298
 			{
291
-				if (empty($row_board['is_read']))
292
-					$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
299
+				if (empty($row_board['is_read'])) {
300
+									$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
301
+				}
293 302
 
294 303
 				if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect'])
295 304
 				{
@@ -320,12 +329,13 @@  discard block
 block discarded – undo
320 329
 			'topic' => $row_board['id_topic']
321 330
 		);
322 331
 
323
-		if (!empty($settings['avatars_on_boardIndex']))
324
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
332
+		if (!empty($settings['avatars_on_boardIndex'])) {
333
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
325 334
 				'avatar' => $row_board['avatar'],
326 335
 				'email' => $row_board['email_address'],
327 336
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
328 337
 			));
338
+		}
329 339
 
330 340
 		// Provide the href and link.
331 341
 		if ($row_board['subject'] != '')
@@ -337,8 +347,7 @@  discard block
 block discarded – undo
337 347
 			link, href, subject, start (where they should go for the first unread post.),
338 348
 			and member. (which has id, name, link, href, username in it.) */
339 349
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
340
-		}
341
-		else
350
+		} else
342 351
 		{
343 352
 			$this_last_post['href'] = '';
344 353
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -346,18 +355,21 @@  discard block
 block discarded – undo
346 355
 		}
347 356
 
348 357
 		// Set the last post in the parent board.
349
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time'])))
350
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
358
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))) {
359
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
360
+		}
351 361
 		// Just in the child...?
352
-		if ($isChild)
353
-			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
362
+		if ($isChild) {
363
+					$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
364
+		}
354 365
 
355 366
 		// Determine a global most recent topic.
356
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
357
-			$latest_post = array(
367
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
368
+					$latest_post = array(
358 369
 				'timestamp' => $row_board['poster_time'],
359 370
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
360 371
 			);
372
+		}
361 373
 	}
362 374
 
363 375
 	// Fetch the board's moderators and moderator groups
@@ -373,8 +385,9 @@  discard block
 block discarded – undo
373 385
 				if (!empty($moderators[$board['id']]))
374 386
 				{
375 387
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
376
-					foreach ($moderators[$board['id']] as $moderator)
377
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
388
+					foreach ($moderators[$board['id']] as $moderator) {
389
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
390
+					}
378 391
 				}
379 392
 				if (!empty($groups[$board['id']]))
380 393
 				{
@@ -387,16 +400,16 @@  discard block
 block discarded – undo
387 400
 				}
388 401
 			}
389 402
 		}
390
-	}
391
-	else
403
+	} else
392 404
 	{
393 405
 		foreach ($this_category as $k => $board)
394 406
 		{
395 407
 			if (!empty($moderators[$board['id']]))
396 408
 			{
397 409
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
398
-				foreach ($moderators[$board['id']] as $moderator)
399
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
410
+				foreach ($moderators[$board['id']] as $moderator) {
411
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
412
+				}
400 413
 			}
401 414
 			if (!empty($groups[$board['id']]))
402 415
 			{
@@ -410,20 +423,23 @@  discard block
 block discarded – undo
410 423
 		}
411 424
 	}
412 425
 
413
-	if ($boardIndexOptions['include_categories'])
414
-		sortCategories($categories);
415
-	else
416
-		sortBoards($this_category);
426
+	if ($boardIndexOptions['include_categories']) {
427
+			sortCategories($categories);
428
+	} else {
429
+			sortBoards($this_category);
430
+	}
417 431
 
418 432
 	// By now we should know the most recent post...if we wanna know it that is.
419
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
420
-		$context['latest_post'] = $latest_post['ref'];
433
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
434
+			$context['latest_post'] = $latest_post['ref'];
435
+	}
421 436
 
422 437
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
423
-	if ($boardIndexOptions['include_categories'])
424
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
425
-	else
426
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
438
+	if ($boardIndexOptions['include_categories']) {
439
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
440
+	} else {
441
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
442
+	}
427 443
 
428 444
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
429 445
 }
Please login to merge, or discard this patch.
Sources/ManageBoards.php 1 patch
Braces   +150 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main dispatcher; doesn't do anything, just delegates.
@@ -92,18 +93,19 @@  discard block
 block discarded – undo
92 93
 		checkSession('get');
93 94
 		validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');
94 95
 
95
-		if ($_REQUEST['move_to'] === 'top')
96
-			$boardOptions = array(
96
+		if ($_REQUEST['move_to'] === 'top') {
97
+					$boardOptions = array(
97 98
 				'move_to' => $_REQUEST['move_to'],
98 99
 				'target_category' => (int) $_REQUEST['target_cat'],
99 100
 				'move_first_child' => true,
100 101
 			);
101
-		else
102
-			$boardOptions = array(
102
+		} else {
103
+					$boardOptions = array(
103 104
 				'move_to' => $_REQUEST['move_to'],
104 105
 				'target_board' => (int) $_REQUEST['target_board'],
105 106
 				'move_first_child' => true,
106 107
 			);
108
+		}
107 109
 		modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
108 110
 	}
109 111
 
@@ -148,15 +150,16 @@  discard block
 block discarded – undo
148 150
 			$security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token'];
149 151
 			foreach ($boardList[$catid] as $boardid)
150 152
 			{
151
-				if (!isset($context['categories'][$catid]['move_link']))
152
-					$context['categories'][$catid]['move_link'] = array(
153
+				if (!isset($context['categories'][$catid]['move_link'])) {
154
+									$context['categories'][$catid]['move_link'] = array(
153 155
 						'child_level' => 0,
154 156
 						'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
155 157
 						'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security,
156 158
 					);
159
+				}
157 160
 
158
-				if (!$context['categories'][$catid]['boards'][$boardid]['move'])
159
-				$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
161
+				if (!$context['categories'][$catid]['boards'][$boardid]['move']) {
162
+								$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
160 163
 					array(
161 164
 						'child_level' => $boards[$boardid]['level'],
162 165
 						'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
@@ -170,33 +173,38 @@  discard block
 block discarded – undo
170 173
 						'class' => 'here',
171 174
 					),
172 175
 				);
176
+				}
173 177
 
174 178
 				$difference = $boards[$boardid]['level'] - $prev_child_level;
175
-				if ($difference == 1)
176
-					array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
177
-				elseif ($difference < 0)
179
+				if ($difference == 1) {
180
+									array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
181
+				} elseif ($difference < 0)
178 182
 				{
179
-					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
180
-						$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
181
-					for ($i = 0; $i < -$difference; $i++)
182
-						if (($temp = array_pop($stack)) != null)
183
+					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
184
+											$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
185
+					}
186
+					for ($i = 0; $i < -$difference; $i++) {
187
+											if (($temp = array_pop($stack)) != null)
183 188
 							array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp);
189
+					}
184 190
 				}
185 191
 
186 192
 				$prev_board = $boardid;
187 193
 				$prev_child_level = $boards[$boardid]['level'];
188 194
 			}
189
-			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
190
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
191
-			elseif (!empty($stack))
192
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
195
+			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
196
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
197
+			} elseif (!empty($stack)) {
198
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
199
+			}
193 200
 
194
-			if (empty($boardList[$catid]))
195
-				$context['categories'][$catid]['move_link'] = array(
201
+			if (empty($boardList[$catid])) {
202
+							$context['categories'][$catid]['move_link'] = array(
196 203
 					'child_level' => 0,
197 204
 					'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'',
198 205
 					'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security,
199 206
 				);
207
+			}
200 208
 		}
201 209
 	}
202 210
 
@@ -252,9 +260,9 @@  discard block
 block discarded – undo
252 260
 		);
253 261
 	}
254 262
 	// Category doesn't exist, man... sorry.
255
-	elseif (!isset($cat_tree[$_REQUEST['cat']]))
256
-		redirectexit('action=admin;area=manageboards');
257
-	else
263
+	elseif (!isset($cat_tree[$_REQUEST['cat']])) {
264
+			redirectexit('action=admin;area=manageboards');
265
+	} else
258 266
 	{
259 267
 		$context['category'] = array(
260 268
 			'id' => $_REQUEST['cat'],
@@ -266,30 +274,31 @@  discard block
 block discarded – undo
266 274
 			'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
267 275
 		);
268 276
 
269
-		foreach ($boardList[$_REQUEST['cat']] as $child_board)
270
-			$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
277
+		foreach ($boardList[$_REQUEST['cat']] as $child_board) {
278
+					$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
279
+		}
271 280
 	}
272 281
 
273 282
 	$prevCat = 0;
274 283
 	foreach ($cat_tree as $catid => $tree)
275 284
 	{
276
-		if ($catid == $_REQUEST['cat'] && $prevCat > 0)
277
-			$context['category_order'][$prevCat]['selected'] = true;
278
-		elseif ($catid != $_REQUEST['cat'])
279
-			$context['category_order'][$catid] = array(
285
+		if ($catid == $_REQUEST['cat'] && $prevCat > 0) {
286
+					$context['category_order'][$prevCat]['selected'] = true;
287
+		} elseif ($catid != $_REQUEST['cat']) {
288
+					$context['category_order'][$catid] = array(
280 289
 				'id' => $catid,
281 290
 				'name' => $txt['mboards_order_after'] . $tree['node']['name'],
282 291
 				'selected' => false,
283 292
 				'true_name' => $tree['node']['name']
284 293
 			);
294
+		}
285 295
 		$prevCat = $catid;
286 296
 	}
287 297
 	if (!isset($_REQUEST['delete']))
288 298
 	{
289 299
 		$context['sub_template'] = 'modify_category';
290 300
 		$context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit'];
291
-	}
292
-	else
301
+	} else
293 302
 	{
294 303
 		$context['sub_template'] = 'confirm_category_delete';
295 304
 		$context['page_title'] = $txt['mboards_delete_cat'];
@@ -326,8 +335,9 @@  discard block
 block discarded – undo
326 335
 	{
327 336
 		$catOptions = array();
328 337
 
329
-		if (isset($_POST['cat_order']))
330
-			$catOptions['move_after'] = (int) $_POST['cat_order'];
338
+		if (isset($_POST['cat_order'])) {
339
+					$catOptions['move_after'] = (int) $_POST['cat_order'];
340
+		}
331 341
 
332 342
 		// Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
333 343
 		$catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']);
@@ -335,10 +345,11 @@  discard block
 block discarded – undo
335 345
 
336 346
 		$catOptions['is_collapsible'] = isset($_POST['collapse']);
337 347
 
338
-		if (isset($_POST['add']))
339
-			createCategory($catOptions);
340
-		else
341
-			modifyCategory($_POST['cat'], $catOptions);
348
+		if (isset($_POST['add'])) {
349
+					createCategory($catOptions);
350
+		} else {
351
+					modifyCategory($_POST['cat'], $catOptions);
352
+		}
342 353
 	}
343 354
 	// If they want to delete - first give them confirmation.
344 355
 	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty']))
@@ -352,13 +363,14 @@  discard block
 block discarded – undo
352 363
 		// First off - check if we are moving all the current boards first - before we start deleting!
353 364
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
354 365
 		{
355
-			if (empty($_POST['cat_to']))
356
-				fatal_lang_error('mboards_delete_error');
366
+			if (empty($_POST['cat_to'])) {
367
+							fatal_lang_error('mboards_delete_error');
368
+			}
357 369
 
358 370
 			deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']);
371
+		} else {
372
+					deleteCategories(array($_POST['cat']));
359 373
 		}
360
-		else
361
-			deleteCategories(array($_POST['cat']));
362 374
 	}
363 375
 
364 376
 	redirectexit('action=admin;area=manageboards');
@@ -403,8 +415,9 @@  discard block
 block discarded – undo
403 415
 	if ($_REQUEST['sa'] == 'newboard')
404 416
 	{
405 417
 		// Category doesn't exist, man... sorry.
406
-		if (empty($_REQUEST['cat']))
407
-			redirectexit('action=admin;area=manageboards');
418
+		if (empty($_REQUEST['cat'])) {
419
+					redirectexit('action=admin;area=manageboards');
420
+		}
408 421
 
409 422
 		// Some things that need to be setup for a new board.
410 423
 		$curBoard = array(
@@ -428,8 +441,7 @@  discard block
 block discarded – undo
428 441
 			'category' => (int) $_REQUEST['cat'],
429 442
 			'no_children' => true,
430 443
 		);
431
-	}
432
-	else
444
+	} else
433 445
 	{
434 446
 		// Just some easy shortcuts.
435 447
 		$curBoard = &$boards[$_REQUEST['boardid']];
@@ -477,8 +489,9 @@  discard block
 block discarded – undo
477 489
 	);
478 490
 	while ($row = $smcFunc['db_fetch_assoc']($request))
479 491
 	{
480
-		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1)
481
-			$curBoard['member_groups'][] = $row['id_group'];
492
+		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) {
493
+					$curBoard['member_groups'][] = $row['id_group'];
494
+		}
482 495
 
483 496
 		$context['groups'][(int) $row['id_group']] = array(
484 497
 			'id' => $row['id_group'],
@@ -491,8 +504,9 @@  discard block
 block discarded – undo
491 504
 	$smcFunc['db_free_result']($request);
492 505
 
493 506
 	// Category doesn't exist, man... sorry.
494
-	if (!isset($boardList[$curBoard['category']]))
495
-		redirectexit('action=admin;area=manageboards');
507
+	if (!isset($boardList[$curBoard['category']])) {
508
+			redirectexit('action=admin;area=manageboards');
509
+	}
496 510
 
497 511
 	foreach ($boardList[$curBoard['category']] as $boardid)
498 512
 	{
@@ -506,8 +520,7 @@  discard block
 block discarded – undo
506 520
 				'is_child' => false,
507 521
 				'selected' => true
508 522
 			);
509
-		}
510
-		else
523
+		} else
511 524
 		{
512 525
 			$context['board_order'][] = array(
513 526
 				'id' => $boardid,
@@ -524,19 +537,21 @@  discard block
 block discarded – undo
524 537
 		$context['can_move_children'] = false;
525 538
 		$context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
526 539
 
527
-		foreach ($context['board_order'] as $lBoard)
528
-			if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
540
+		foreach ($context['board_order'] as $lBoard) {
541
+					if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
529 542
 				$context['can_move_children'] = true;
543
+		}
530 544
 	}
531 545
 
532 546
 	// Get other available categories.
533 547
 	$context['categories'] = array();
534
-	foreach ($cat_tree as $catID => $tree)
535
-		$context['categories'][] = array(
548
+	foreach ($cat_tree as $catID => $tree) {
549
+			$context['categories'][] = array(
536 550
 			'id' => $catID == $curBoard['category'] ? 0 : $catID,
537 551
 			'name' => $tree['node']['name'],
538 552
 			'selected' => $catID == $curBoard['category']
539 553
 		);
554
+	}
540 555
 
541 556
 	$request = $smcFunc['db_query']('', '
542 557
 		SELECT mem.id_member, mem.real_name
@@ -548,14 +563,16 @@  discard block
 block discarded – undo
548 563
 		)
549 564
 	);
550 565
 	$context['board']['moderators'] = array();
551
-	while ($row = $smcFunc['db_fetch_assoc']($request))
552
-		$context['board']['moderators'][$row['id_member']] = $row['real_name'];
566
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
567
+			$context['board']['moderators'][$row['id_member']] = $row['real_name'];
568
+	}
553 569
 	$smcFunc['db_free_result']($request);
554 570
 
555 571
 	$context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['board']['moderators']) . '&quot;';
556 572
 
557
-	if (!empty($context['board']['moderators']))
558
-		list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
573
+	if (!empty($context['board']['moderators'])) {
574
+			list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
575
+	}
559 576
 
560 577
 	// Get all the groups assigned as moderators
561 578
 	$request = $smcFunc['db_query']('', '
@@ -567,14 +584,16 @@  discard block
 block discarded – undo
567 584
 		)
568 585
 	);
569 586
 	$context['board']['moderator_groups'] = array();
570
-	while ($row = $smcFunc['db_fetch_assoc']($request))
571
-		$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
587
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
588
+			$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
589
+	}
572 590
 	$smcFunc['db_free_result']($request);
573 591
 
574 592
 	$context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '&quot;' . implode('&quot;, &qout;', $context['board']['moderator_groups']) . '&quot;';
575 593
 
576
-	if (!empty($context['board']['moderator_groups']))
577
-		list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
594
+	if (!empty($context['board']['moderator_groups'])) {
595
+			list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
596
+	}
578 597
 
579 598
 	// Get all the themes...
580 599
 	$request = $smcFunc['db_query']('', '
@@ -586,8 +605,9 @@  discard block
 block discarded – undo
586 605
 		)
587 606
 	);
588 607
 	$context['themes'] = array();
589
-	while ($row = $smcFunc['db_fetch_assoc']($request))
590
-		$context['themes'][] = $row;
608
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
609
+			$context['themes'][] = $row;
610
+	}
591 611
 	$smcFunc['db_free_result']($request);
592 612
 
593 613
 	if (!isset($_REQUEST['delete']))
@@ -595,8 +615,7 @@  discard block
 block discarded – undo
595 615
 		$context['sub_template'] = 'modify_board';
596 616
 		$context['page_title'] = $txt['boardsEdit'];
597 617
 		loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
598
-	}
599
-	else
618
+	} else
600 619
 	{
601 620
 		$context['sub_template'] = 'confirm_board_delete';
602 621
 		$context['page_title'] = $txt['mboards_delete_board'];
@@ -640,8 +659,9 @@  discard block
 block discarded – undo
640 659
 		// Change the boardorder of this board?
641 660
 		elseif (!empty($_POST['placement']) && !empty($_POST['board_order']))
642 661
 		{
643
-			if (!in_array($_POST['placement'], array('before', 'after', 'child')))
644
-				fatal_lang_error('mangled_post', false);
662
+			if (!in_array($_POST['placement'], array('before', 'after', 'child'))) {
663
+							fatal_lang_error('mangled_post', false);
664
+			}
645 665
 
646 666
 			$boardOptions['move_to'] = $_POST['placement'];
647 667
 			$boardOptions['target_board'] = (int) $_POST['board_order'];
@@ -654,13 +674,14 @@  discard block
 block discarded – undo
654 674
 		$boardOptions['access_groups'] = array();
655 675
 		$boardOptions['deny_groups'] = array();
656 676
 
657
-		if (!empty($_POST['groups']))
658
-			foreach ($_POST['groups'] as $group => $action)
677
+		if (!empty($_POST['groups'])) {
678
+					foreach ($_POST['groups'] as $group => $action)
659 679
 			{
660 680
 				if ($action == 'allow')
661 681
 					$boardOptions['access_groups'][] = (int) $group;
662
-				elseif ($action == 'deny')
663
-					$boardOptions['deny_groups'][] = (int) $group;
682
+		} elseif ($action == 'deny') {
683
+									$boardOptions['deny_groups'][] = (int) $group;
684
+				}
664 685
 			}
665 686
 
666 687
 		// People with manage-boards are special.
@@ -672,8 +693,9 @@  discard block
 block discarded – undo
672 693
 		// Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded.
673 694
 		$boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers));
674 695
 
675
-		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
676
-			fatal_lang_error('too_many_groups', false);
696
+		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) {
697
+					fatal_lang_error('too_many_groups', false);
698
+		}
677 699
 
678 700
 		// Do not allow HTML tags. Parse the string.
679 701
 		$boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']);
@@ -684,8 +706,9 @@  discard block
 block discarded – undo
684 706
 		if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list']))
685 707
 		{
686 708
 			$moderators = array();
687
-			foreach ($_POST['moderator_list'] as $moderator)
688
-				$moderators[(int) $moderator] = (int) $moderator;
709
+			foreach ($_POST['moderator_list'] as $moderator) {
710
+							$moderators[(int) $moderator] = (int) $moderator;
711
+			}
689 712
 			$boardOptions['moderators'] = $moderators;
690 713
 		}
691 714
 
@@ -694,8 +717,9 @@  discard block
 block discarded – undo
694 717
 		if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list']))
695 718
 		{
696 719
 			$moderator_groups = array();
697
-			foreach ($_POST['moderator_group_list'] as $moderator_group)
698
-				$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
720
+			foreach ($_POST['moderator_group_list'] as $moderator_group) {
721
+							$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
722
+			}
699 723
 			$boardOptions['moderator_groups'] = $moderator_groups;
700 724
 		}
701 725
 
@@ -721,56 +745,62 @@  discard block
 block discarded – undo
721 745
 			$smcFunc['db_free_result']($request);
722 746
 
723 747
 			// If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board.
724
-			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts)
725
-				unset($boardOptions['redirect']);
748
+			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) {
749
+							unset($boardOptions['redirect']);
750
+			}
726 751
 			// Reset the redirection count when switching on/off.
727
-			elseif (empty($boardOptions['redirect']) != empty($oldRedirect))
728
-				$boardOptions['num_posts'] = 0;
752
+			elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) {
753
+							$boardOptions['num_posts'] = 0;
754
+			}
729 755
 			// Resetting the count?
730
-			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect']))
731
-				$boardOptions['num_posts'] = 0;
756
+			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) {
757
+							$boardOptions['num_posts'] = 0;
758
+			}
732 759
 		}
733 760
 
734 761
 		// Create a new board...
735 762
 		if (isset($_POST['add']))
736 763
 		{
737 764
 			// New boards by default go to the bottom of the category.
738
-			if (empty($_POST['new_cat']))
739
-				$boardOptions['target_category'] = (int) $_POST['cur_cat'];
740
-			if (!isset($boardOptions['move_to']))
741
-				$boardOptions['move_to'] = 'bottom';
765
+			if (empty($_POST['new_cat'])) {
766
+							$boardOptions['target_category'] = (int) $_POST['cur_cat'];
767
+			}
768
+			if (!isset($boardOptions['move_to'])) {
769
+							$boardOptions['move_to'] = 'bottom';
770
+			}
742 771
 
743 772
 			createBoard($boardOptions);
744 773
 		}
745 774
 
746 775
 		// ...or update an existing board.
747
-		else
748
-			modifyBoard($_POST['boardid'], $boardOptions);
749
-	}
750
-	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
776
+		else {
777
+					modifyBoard($_POST['boardid'], $boardOptions);
778
+		}
779
+	} elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
751 780
 	{
752 781
 		EditBoard();
753 782
 		return;
754
-	}
755
-	elseif (isset($_POST['delete']))
783
+	} elseif (isset($_POST['delete']))
756 784
 	{
757 785
 		// First off - check if we are moving all the current child boards first - before we start deleting!
758 786
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
759 787
 		{
760
-			if (empty($_POST['board_to']))
761
-				fatal_lang_error('mboards_delete_board_error');
788
+			if (empty($_POST['board_to'])) {
789
+							fatal_lang_error('mboards_delete_board_error');
790
+			}
762 791
 
763 792
 			deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
793
+		} else {
794
+					deleteBoards(array($_POST['boardid']), 0);
764 795
 		}
765
-		else
766
-			deleteBoards(array($_POST['boardid']), 0);
767 796
 	}
768 797
 
769
-	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions')
770
-		redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
771
-	else
772
-		redirectexit('action=admin;area=manageboards');
773
-}
798
+	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') {
799
+			redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
800
+	} else {
801
+			redirectexit('action=admin;area=manageboards');
802
+	}
803
+	}
774 804
 
775 805
 /**
776 806
  * Used to retrieve data for modifying a board category
@@ -807,8 +837,9 @@  discard block
 block discarded – undo
807 837
 	$smcFunc['db_free_result']($request);
808 838
 
809 839
 	// This would probably never happen, but just to be sure.
810
-	if ($cat .= $allowed_sa[1])
811
-		die(str_replace(',', ' to', $cat));
840
+	if ($cat .= $allowed_sa[1]) {
841
+			die(str_replace(',', ' to', $cat));
842
+	}
812 843
 
813 844
 	redirectexit();
814 845
 }
@@ -834,8 +865,9 @@  discard block
 block discarded – undo
834 865
 			'empty_string' => '',
835 866
 		)
836 867
 	);
837
-	while ($row = $smcFunc['db_fetch_assoc']($request))
838
-		$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
868
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
869
+			$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
870
+	}
839 871
 	$smcFunc['db_free_result']($request);
840 872
 
841 873
 	if (!empty($recycle_boards))
@@ -843,13 +875,14 @@  discard block
 block discarded – undo
843 875
 		require_once($sourcedir . '/Subs-Boards.php');
844 876
 		sortBoards($recycle_boards);
845 877
 		$recycle_boards = array('') + $recycle_boards;
878
+	} else {
879
+			$recycle_boards = array('');
846 880
 	}
847
-	else
848
-		$recycle_boards = array('');
849 881
 
850 882
 	// If this setting is missing, set it to 1
851
-	if (empty($modSettings['boardindex_max_depth']))
852
-		$modSettings['boardindex_max_depth'] = 1;
883
+	if (empty($modSettings['boardindex_max_depth'])) {
884
+			$modSettings['boardindex_max_depth'] = 1;
885
+	}
853 886
 
854 887
 	// Here and the board settings...
855 888
 	$config_vars = array(
@@ -868,8 +901,9 @@  discard block
 block discarded – undo
868 901
 
869 902
 	call_integration_hook('integrate_modify_board_settings', array(&$config_vars));
870 903
 
871
-	if ($return_config)
872
-		return $config_vars;
904
+	if ($return_config) {
905
+			return $config_vars;
906
+	}
873 907
 
874 908
 	// Needed for the settings template.
875 909
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/Session.php 1 patch
Braces   +40 added lines, -27 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 4
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -63,23 +66,26 @@  discard block
 block discarded – undo
63 66
 		if (!empty($modSettings['databaseSession_enable']))
64 67
 		{
65 68
 			@ini_set('session.serialize_handler', 'php_serialize');
66
-			if (ini_get('session.serialize_handler') != 'php_serialize')
67
-				@ini_set('session.serialize_handler', 'php');
69
+			if (ini_get('session.serialize_handler') != 'php_serialize') {
70
+							@ini_set('session.serialize_handler', 'php');
71
+			}
68 72
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
69 73
 			@ini_set('session.gc_probability', '1');
74
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
75
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
70 76
 		}
71
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
72
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
73 77
 
74 78
 		// Use cache setting sessions?
75
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
76
-			call_integration_hook('integrate_session_handlers');
79
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
80
+					call_integration_hook('integrate_session_handlers');
81
+		}
77 82
 
78 83
 		session_start();
79 84
 
80 85
 		// Change it so the cache settings are a little looser than default.
81
-		if (!empty($modSettings['databaseSession_loose']))
82
-			header('cache-control: private');
86
+		if (!empty($modSettings['databaseSession_loose'])) {
87
+					header('cache-control: private');
88
+		}
83 89
 	}
84 90
 
85 91
 	// Set the randomly generated code.
@@ -125,8 +131,9 @@  discard block
 block discarded – undo
125 131
 {
126 132
 	global $smcFunc;
127 133
 
128
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
129
-		return '';
134
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
135
+			return '';
136
+	}
130 137
 
131 138
 	// Look for it in the database.
132 139
 	$result = $smcFunc['db_query']('', '
@@ -156,8 +163,9 @@  discard block
 block discarded – undo
156 163
 	global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd;
157 164
 	global $db_prefix, $db_persist, $db_port, $db_mb4;
158 165
 
159
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
160
-		return false;
166
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
167
+			return false;
168
+	}
161 169
 
162 170
 	// php < 7.0 need this
163 171
 	if (empty($db_connection))
@@ -165,11 +173,13 @@  discard block
 block discarded – undo
165 173
 		$db_options = array();
166 174
 
167 175
 		// Add in the port if needed
168
-		if (!empty($db_port))
169
-			$db_options['port'] = $db_port;
176
+		if (!empty($db_port)) {
177
+					$db_options['port'] = $db_port;
178
+		}
170 179
 
171
-		if (!empty($db_mb4))
172
-		$db_options['db_mb4'] = $db_mb4;
180
+		if (!empty($db_mb4)) {
181
+				$db_options['db_mb4'] = $db_mb4;
182
+		}
173 183
 
174 184
 		$options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI'));
175 185
 
@@ -189,13 +199,14 @@  discard block
 block discarded – undo
189 199
 	);
190 200
 
191 201
 	// If that didn't work, try inserting a new one.
192
-	if ($smcFunc['db_affected_rows']() == 0)
193
-		$smcFunc['db_insert']('ignore',
202
+	if ($smcFunc['db_affected_rows']() == 0) {
203
+			$smcFunc['db_insert']('ignore',
194 204
 			'{db_prefix}sessions',
195 205
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
196 206
 			array($session_id, $data, time()),
197 207
 			array('session_id')
198 208
 		);
209
+	}
199 210
 
200 211
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
201 212
 }
@@ -210,8 +221,9 @@  discard block
 block discarded – undo
210 221
 {
211 222
 	global $smcFunc;
212 223
 
213
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
214
-		return false;
224
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
225
+			return false;
226
+	}
215 227
 
216 228
 	// Just delete the row...
217 229
 	$smcFunc['db_query']('', '
@@ -237,8 +249,9 @@  discard block
 block discarded – undo
237 249
 	global $modSettings, $smcFunc;
238 250
 
239 251
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
240
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
241
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
252
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
253
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
254
+	}
242 255
 
243 256
 	// Clean up after yerself ;).
244 257
 	$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Sources/Search.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 
660 660
 	// Remove the phrase parts and extract the words.
661 661
 	$wordArray = preg_replace('~(?:^|\s)(?:[-]?)"(?:[^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']);
662
-	$wordArray = explode(' ',  $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES));
662
+	$wordArray = explode(' ', $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES));
663 663
 
664 664
 	// A minus sign in front of a word excludes the word.... so...
665 665
 	$excludedWords = array();
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 		// Are the result fresh?
998 998
 		if (!$update_cache && !empty($_SESSION['search_cache']['id_search']))
999 999
 		{
1000
-			$request = $smcFunc['db_query']('','
1000
+			$request = $smcFunc['db_query']('', '
1001 1001
 				SELECT id_search 
1002 1002
 				FROM {db_prefix}log_search_results
1003 1003
 				WHERE id_search = {int:search_id}
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 						SELECT
1120 1120
 							{int:id_search},
1121 1121
 							t.id_topic,
1122
-							' . $relevance. ',
1122
+							' . $relevance . ',
1123 1123
 							' . (empty($userQuery) ? 't.id_first_msg' : 'm.id_msg') . ',
1124 1124
 							1
1125 1125
 						FROM ' . $subject_query['from'] . (empty($subject_query['inner_join']) ? '' : '
@@ -1352,7 +1352,7 @@  discard block
 block discarded – undo
1352 1352
 						if (empty($subject_query['where']))
1353 1353
 							continue;
1354 1354
 
1355
-						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( '
1355
+						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ('
1356 1356
 							INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics
1357 1357
 								(' . ($createTemporary ? '' : 'id_search, ') . 'id_topic)') : '') . '
1358 1358
 							SELECT ' . ($createTemporary ? '' : $_SESSION['search_cache']['id_search'] . ', ') . 't.id_topic
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
 					}
1580 1580
 					$main_query['select']['relevance'] = substr($relevance, 0, -3) . ') / ' . $new_weight_total . ' AS relevance';
1581 1581
 
1582
-					$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? ( '
1582
+					$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? ('
1583 1583
 						INSERT IGNORE INTO ' . '{db_prefix}log_search_results
1584 1584
 							(' . implode(', ', array_keys($main_query['select'])) . ')') : '') . '
1585 1585
 						SELECT
@@ -1647,7 +1647,7 @@  discard block
 block discarded – undo
1647 1647
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
1648 1648
 
1649 1649
 					$usedIDs = array_flip(empty($inserts) ? array() : array_keys($inserts));
1650
-					$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? ( '
1650
+					$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? ('
1651 1651
 						INSERT IGNORE INTO {db_prefix}log_search_results
1652 1652
 							(id_search, id_topic, relevance, id_msg, num_matches)') : '') . '
1653 1653
 						SELECT
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
 		if (strlen($query) == 0)
2117 2117
 			continue;
2118 2118
 
2119
-		$body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m)
2119
+		$body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function($m)
2120 2120
 		{
2121 2121
 			return isset($m[2]) && "$m[2]" == "$m[1]" ? stripslashes("$m[1]") : "<strong class=\"highlight\">$m[1]</strong>";
2122 2122
 		}, $body_highlighted);
Please login to merge, or discard this 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/MessageIndex.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 				' . (empty($sort_methods_table[$context['sort_by']]) ? '' : $sort_methods_table[$context['sort_by']]) . '
325 325
 				WHERE t.id_board = {int:current_board} '
326 326
 				. (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
327
-					AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') .'
327
+					AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
328 328
 				ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . ' 
329 329
 				LIMIT {int:maxindex}
330 330
 					OFFSET {int:start} ';
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		SELECT
334 334
 			t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
335 335
 			' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from,
336
-			' . ( $enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
336
+			' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
337 337
 			'	: '') . '
338 338
 			t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic,
339 339
 			ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 			LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . '
358 358
 			' . (!empty($message_index_tables) ? implode("\n\t\t\t\t", $message_index_tables) : '') . '
359 359
 			' . (!empty($message_index_wheres) ? ' WHERE ' . implode("\n\t\t\t\tAND ", $message_index_wheres) : '') . '
360
-		ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') ,
360
+		ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC'),
361 361
 		$message_index_parameters
362 362
 	);
363 363
 
Please login to merge, or discard this patch.
Braces   +260 added lines, -195 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the list of topics in this board, along with any child boards.
@@ -56,8 +57,9 @@  discard block
 block discarded – undo
56 57
 
57 58
 	$context['name'] = $board_info['name'];
58 59
 	$context['description'] = $board_info['description'];
59
-	if (!empty($board_info['description']))
60
-		$context['meta_description'] = strip_tags($board_info['description']);
60
+	if (!empty($board_info['description'])) {
61
+			$context['meta_description'] = strip_tags($board_info['description']);
62
+	}
61 63
 
62 64
 	// How many topics do we have in total?
63 65
 	$board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
@@ -73,12 +75,14 @@  discard block
 block discarded – undo
73 75
 		$session_name = session_name();
74 76
 		foreach ($_GET as $k => $v)
75 77
 		{
76
-			if (!in_array($k, array('board', 'start', $session_name)))
77
-				$context['robot_no_index'] = true;
78
+			if (!in_array($k, array('board', 'start', $session_name))) {
79
+							$context['robot_no_index'] = true;
80
+			}
78 81
 		}
79 82
 	}
80
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
81
-		$context['robot_no_index'] = true;
83
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
84
+			$context['robot_no_index'] = true;
85
+	}
82 86
 
83 87
 	// If we can view unapproved messages and there are some build up a list.
84 88
 	if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts']))
@@ -89,14 +93,16 @@  discard block
 block discarded – undo
89 93
 	}
90 94
 
91 95
 	// We only know these.
92
-	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post')))
93
-		$_REQUEST['sort'] = 'last_post';
96
+	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) {
97
+			$_REQUEST['sort'] = 'last_post';
98
+	}
94 99
 
95 100
 	// Make sure the starting place makes sense and construct the page index.
96
-	if (isset($_REQUEST['sort']))
97
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
101
+	if (isset($_REQUEST['sort'])) {
102
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
105
+	}
100 106
 	$context['start'] = &$_REQUEST['start'];
101 107
 
102 108
 	// Set a canonical URL for this page.
@@ -132,14 +138,16 @@  discard block
 block discarded – undo
132 138
 	$context['link_moderators'] = array();
133 139
 	if (!empty($board_info['moderators']))
134 140
 	{
135
-		foreach ($board_info['moderators'] as $mod)
136
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
141
+		foreach ($board_info['moderators'] as $mod) {
142
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
143
+		}
137 144
 	}
138 145
 	if (!empty($board_info['moderator_groups']))
139 146
 	{
140 147
 		// By default just tack the moderator groups onto the end of the members
141
-		foreach ($board_info['moderator_groups'] as $mod_group)
142
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
148
+		foreach ($board_info['moderator_groups'] as $mod_group) {
149
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
150
+		}
143 151
 	}
144 152
 
145 153
 	// Now we tack the info onto the end of the linktree
@@ -191,20 +199,24 @@  discard block
 block discarded – undo
191 199
 		);
192 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
193 201
 		{
194
-			if (empty($row['id_member']))
195
-				continue;
202
+			if (empty($row['id_member'])) {
203
+							continue;
204
+			}
196 205
 
197
-			if (!empty($row['online_color']))
198
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
199
-			else
200
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
206
+			if (!empty($row['online_color'])) {
207
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
208
+			} else {
209
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
210
+			}
201 211
 
202 212
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
203
-			if ($is_buddy)
204
-				$link = '<strong>' . $link . '</strong>';
213
+			if ($is_buddy) {
214
+							$link = '<strong>' . $link . '</strong>';
215
+			}
205 216
 
206
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
207
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
217
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
218
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
219
+			}
208 220
 			// @todo why are we filling this array of data that are just counted (twice) and discarded? ???
209 221
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
210 222
 				'id' => $row['id_member'],
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 				'hidden' => empty($row['show_online']),
218 230
 			);
219 231
 
220
-			if (empty($row['show_online']))
221
-				$context['view_num_hidden']++;
232
+			if (empty($row['show_online'])) {
233
+							$context['view_num_hidden']++;
234
+			}
222 235
 		}
223 236
 		$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
224 237
 		$smcFunc['db_free_result']($request);
@@ -273,8 +286,9 @@  discard block
 block discarded – undo
273 286
 	// Bring in any changes we want to make before the query.
274 287
 	call_integration_hook('integrate_pre_messageindex', array(&$sort_methods));
275 288
 
276
-	foreach ($sort_methods as $key => $val)
277
-		$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
289
+	foreach ($sort_methods as $key => $val) {
290
+			$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
291
+	}
278 292
 
279 293
 	// Calculate the fastest way to get the topics.
280 294
 	$start = (int) $_REQUEST['start'];
@@ -284,14 +298,15 @@  discard block
 block discarded – undo
284 298
 		$fake_ascending = true;
285 299
 		$context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex'];
286 300
 		$start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex'];
301
+	} else {
302
+			$fake_ascending = false;
287 303
 	}
288
-	else
289
-		$fake_ascending = false;
290 304
 
291 305
 	// Setup the default topic icons...
292 306
 	$context['icon_sources'] = array();
293
-	foreach ($context['stable_icons'] as $icon)
294
-		$context['icon_sources'][$icon] = 'images_url';
307
+	foreach ($context['stable_icons'] as $icon) {
308
+			$context['icon_sources'][$icon] = 'images_url';
309
+	}
295 310
 
296 311
 	$topic_ids = array();
297 312
 	$context['topics'] = array();
@@ -314,10 +329,11 @@  discard block
 block discarded – undo
314 329
 	$message_index_wheres = array();
315 330
 	call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters, &$message_index_wheres, &$topic_ids));
316 331
 
317
-	if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
318
-		$enableParticipation = true;
319
-	else
320
-		$enableParticipation = false;
332
+	if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) {
333
+			$enableParticipation = true;
334
+	} else {
335
+			$enableParticipation = false;
336
+	}
321 337
 
322 338
 	$sort_table = 'SELECT t.id_topic, t.id_first_msg, t.id_last_msg
323 339
 				FROM {db_prefix}topics t
@@ -364,8 +380,9 @@  discard block
 block discarded – undo
364 380
 	// Begin 'printing' the message index for current board.
365 381
 	while ($row = $smcFunc['db_fetch_assoc']($result))
366 382
 	{
367
-		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
368
-			continue;
383
+		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
384
+					continue;
385
+		}
369 386
 
370 387
 		$topic_ids[] = $row['id_topic'];
371 388
 
@@ -377,8 +394,9 @@  discard block
 block discarded – undo
377 394
 		{
378 395
 			// Limit them to $modSettings['preview_characters'] characters
379 396
 			$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
380
-			if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
381
-				$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
397
+			if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
398
+							$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
399
+			}
382 400
 
383 401
 			// Censor the subject and message preview.
384 402
 			censorText($row['first_subject']);
@@ -389,27 +407,27 @@  discard block
 block discarded – undo
389 407
 			{
390 408
 				$row['last_subject'] = $row['first_subject'];
391 409
 				$row['last_body'] = $row['first_body'];
392
-			}
393
-			else
410
+			} else
394 411
 			{
395 412
 				$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
396
-				if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
397
-					$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
413
+				if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
414
+									$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
415
+				}
398 416
 
399 417
 				censorText($row['last_subject']);
400 418
 				censorText($row['last_body']);
401 419
 			}
402
-		}
403
-		else
420
+		} else
404 421
 		{
405 422
 			$row['first_body'] = '';
406 423
 			$row['last_body'] = '';
407 424
 			censorText($row['first_subject']);
408 425
 
409
-			if ($row['id_first_msg'] == $row['id_last_msg'])
410
-				$row['last_subject'] = $row['first_subject'];
411
-			else
412
-				censorText($row['last_subject']);
426
+			if ($row['id_first_msg'] == $row['id_last_msg']) {
427
+							$row['last_subject'] = $row['first_subject'];
428
+			} else {
429
+							censorText($row['last_subject']);
430
+			}
413 431
 		}
414 432
 
415 433
 		// Decide how many pages the topic should have.
@@ -420,42 +438,50 @@  discard block
 block discarded – undo
420 438
 			$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
421 439
 
422 440
 			// If we can use all, show all.
423
-			if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
424
-				$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
441
+			if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) {
442
+							$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
443
+			}
444
+		} else {
445
+					$pages = '';
425 446
 		}
426
-		else
427
-			$pages = '';
428 447
 
429 448
 		// We need to check the topic icons exist...
430 449
 		if (!empty($modSettings['messageIconChecks_enable']))
431 450
 		{
432
-			if (!isset($context['icon_sources'][$row['first_icon']]))
433
-				$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
434
-			if (!isset($context['icon_sources'][$row['last_icon']]))
435
-				$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
436
-		}
437
-		else
451
+			if (!isset($context['icon_sources'][$row['first_icon']])) {
452
+							$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
453
+			}
454
+			if (!isset($context['icon_sources'][$row['last_icon']])) {
455
+							$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
456
+			}
457
+		} else
438 458
 		{
439
-			if (!isset($context['icon_sources'][$row['first_icon']]))
440
-				$context['icon_sources'][$row['first_icon']] = 'images_url';
441
-			if (!isset($context['icon_sources'][$row['last_icon']]))
442
-				$context['icon_sources'][$row['last_icon']] = 'images_url';
459
+			if (!isset($context['icon_sources'][$row['first_icon']])) {
460
+							$context['icon_sources'][$row['first_icon']] = 'images_url';
461
+			}
462
+			if (!isset($context['icon_sources'][$row['last_icon']])) {
463
+							$context['icon_sources'][$row['last_icon']] = 'images_url';
464
+			}
443 465
 		}
444 466
 
445
-		if (!empty($board_info['recycle']))
446
-			$row['first_icon'] = 'recycled';
467
+		if (!empty($board_info['recycle'])) {
468
+					$row['first_icon'] = 'recycled';
469
+		}
447 470
 
448 471
 		// Is this topic pending approval, or does it have any posts pending approval?
449
-		if ($context['can_approve_posts'] && $row['unapproved_posts'])
450
-			$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
472
+		if ($context['can_approve_posts'] && $row['unapproved_posts']) {
473
+					$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
474
+		}
451 475
 
452 476
 		// Sticky topics should get a different color, too.
453
-		if ($row['is_sticky'])
454
-			$colorClass .= ' sticky';
477
+		if ($row['is_sticky']) {
478
+					$colorClass .= ' sticky';
479
+		}
455 480
 
456 481
 		// Locked topics get special treatment as well.
457
-		if ($row['locked'])
458
-			$colorClass .= ' locked';
482
+		if ($row['locked']) {
483
+					$colorClass .= ' locked';
484
+		}
459 485
 
460 486
 		// 'Print' the topic info.
461 487
 		$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -536,8 +562,9 @@  discard block
 block discarded – undo
536 562
 	$smcFunc['db_free_result']($result);
537 563
 
538 564
 	// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
539
-	if ($fake_ascending)
540
-		$context['topics'] = array_reverse($context['topics'], true);
565
+	if ($fake_ascending) {
566
+			$context['topics'] = array_reverse($context['topics'], true);
567
+	}
541 568
 
542 569
 
543 570
 	$context['jump_to'] = array(
@@ -560,9 +587,9 @@  discard block
 block discarded – undo
560 587
 		// Can we restore topics?
561 588
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
562 589
 
563
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
564
-			$context['can_move_any'] = true;
565
-		else
590
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
591
+					$context['can_move_any'] = true;
592
+		} else
566 593
 		{
567 594
 			// We'll use this in a minute
568 595
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -589,11 +616,13 @@  discard block
 block discarded – undo
589 616
 		}
590 617
 
591 618
 		// Can we use quick moderation checkboxes?
592
-		if ($options['display_quick_mod'] == 1)
593
-			$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
619
+		if ($options['display_quick_mod'] == 1) {
620
+					$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
621
+		}
594 622
 		// Or the icons?
595
-		else
596
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
623
+		else {
624
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
625
+		}
597 626
 	}
598 627
 
599 628
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -627,13 +656,15 @@  discard block
 block discarded – undo
627 656
 			);
628 657
 
629 658
 			// We've seen all these boards now!
630
-			foreach ($board_info['parent_boards'] as $k => $dummy)
631
-				if (isset($_SESSION['topicseen_cache'][$k]))
659
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
660
+							if (isset($_SESSION['topicseen_cache'][$k]))
632 661
 					unset($_SESSION['topicseen_cache'][$k]);
662
+			}
633 663
 		}
634 664
 
635
-		if (isset($_SESSION['topicseen_cache'][$board]))
636
-			unset($_SESSION['topicseen_cache'][$board]);
665
+		if (isset($_SESSION['topicseen_cache'][$board])) {
666
+					unset($_SESSION['topicseen_cache'][$board]);
667
+		}
637 668
 
638 669
 		$request = $smcFunc['db_query']('', '
639 670
 			SELECT id_topic, id_board, sent
@@ -654,8 +685,9 @@  discard block
 block discarded – undo
654 685
 				$context['is_marked_notify'] = true;
655 686
 				$board_sent = $row['sent'];
656 687
 			}
657
-			if (!empty($row['id_topic']))
658
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
688
+			if (!empty($row['id_topic'])) {
689
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
690
+			}
659 691
 		}
660 692
 		$smcFunc['db_free_result']($request);
661 693
 
@@ -679,8 +711,7 @@  discard block
 block discarded – undo
679 711
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
680 712
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
681 713
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
682
-	}
683
-	else
714
+	} else
684 715
 	{
685 716
 		$context['is_marked_notify'] = false;
686 717
 		$context['board_notification_mode'] = 1;
@@ -693,23 +724,27 @@  discard block
 block discarded – undo
693 724
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
694 725
 
695 726
 	// Don't want to show this forever...
696
-	if ($context['becomesUnapproved'])
697
-		unset($_SESSION['becomesUnapproved']);
727
+	if ($context['becomesUnapproved']) {
728
+			unset($_SESSION['becomesUnapproved']);
729
+	}
698 730
 
699 731
 	// Build the message index button array.
700 732
 	$context['normal_buttons'] = array();
701 733
 
702
-	if ($context['can_post_new'])
703
-		$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
734
+	if ($context['can_post_new']) {
735
+			$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
736
+	}
704 737
 
705
-	if ($context['can_post_poll'])
706
-		$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
738
+	if ($context['can_post_poll']) {
739
+			$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
740
+	}
707 741
 
708
-	if ($context['user']['is_logged'])
709
-		$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
742
+	if ($context['user']['is_logged']) {
743
+			$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
744
+	}
710 745
 
711
-	if ($context['can_mark_notify'])
712
-		$context['normal_buttons']['notify'] = array(
746
+	if ($context['can_mark_notify']) {
747
+			$context['normal_buttons']['notify'] = array(
713 748
 			'lang' => true,
714 749
 			'text' => 'notify_board_' . $context['board_notification_mode'],
715 750
 			'sub_buttons' => array(
@@ -727,6 +762,7 @@  discard block
 block discarded – undo
727 762
 				),
728 763
 			),
729 764
 		);
765
+	}
730 766
 
731 767
 	// Javascript for inline editing.
732 768
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -748,18 +784,21 @@  discard block
 block discarded – undo
748 784
 	checkSession('request');
749 785
 
750 786
 	// Lets go straight to the restore area.
751
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
752
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
787
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
788
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
789
+	}
753 790
 
754
-	if (isset($_SESSION['topicseen_cache']))
755
-		$_SESSION['topicseen_cache'] = array();
791
+	if (isset($_SESSION['topicseen_cache'])) {
792
+			$_SESSION['topicseen_cache'] = array();
793
+	}
756 794
 
757 795
 	// This is going to be needed to send off the notifications and for updateLastMessages().
758 796
 	require_once($sourcedir . '/Subs-Post.php');
759 797
 
760 798
 	// Remember the last board they moved things to.
761
-	if (isset($_REQUEST['move_to']))
762
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
799
+	if (isset($_REQUEST['move_to'])) {
800
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
801
+	}
763 802
 
764 803
 	// Only a few possible actions.
765 804
 	$possibleActions = array();
@@ -779,8 +818,7 @@  discard block
 block discarded – undo
779 818
 		);
780 819
 
781 820
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
782
-	}
783
-	else
821
+	} else
784 822
 	{
785 823
 		/**
786 824
 		 * @todo Ugly. There's no getting around this, is there?
@@ -798,8 +836,7 @@  discard block
 block discarded – undo
798 836
 		if (!empty($board))
799 837
 		{
800 838
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
801
-		}
802
-		else
839
+		} else
803 840
 		{
804 841
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
805 842
 		}
@@ -810,55 +847,67 @@  discard block
 block discarded – undo
810 847
 		}
811 848
 	}
812 849
 
813
-	if (!$user_info['is_guest'])
814
-		$possibleActions[] = 'markread';
815
-	if (!empty($boards_can['make_sticky']))
816
-		$possibleActions[] = 'sticky';
817
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
818
-		$possibleActions[] = 'move';
819
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
820
-		$possibleActions[] = 'remove';
821
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
822
-		$possibleActions[] = 'lock';
823
-	if (!empty($boards_can['merge_any']))
824
-		$possibleActions[] = 'merge';
825
-	if (!empty($boards_can['approve_posts']))
826
-		$possibleActions[] = 'approve';
850
+	if (!$user_info['is_guest']) {
851
+			$possibleActions[] = 'markread';
852
+	}
853
+	if (!empty($boards_can['make_sticky'])) {
854
+			$possibleActions[] = 'sticky';
855
+	}
856
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
857
+			$possibleActions[] = 'move';
858
+	}
859
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
860
+			$possibleActions[] = 'remove';
861
+	}
862
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
863
+			$possibleActions[] = 'lock';
864
+	}
865
+	if (!empty($boards_can['merge_any'])) {
866
+			$possibleActions[] = 'merge';
867
+	}
868
+	if (!empty($boards_can['approve_posts'])) {
869
+			$possibleActions[] = 'approve';
870
+	}
827 871
 
828 872
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
829 873
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
830 874
 	if (!empty($_REQUEST['topics']))
831 875
 	{
832 876
 		// If the action isn't valid, just quit now.
833
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
834
-			redirectexit($redirect_url);
877
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
878
+					redirectexit($redirect_url);
879
+		}
835 880
 
836 881
 		// Merge requires all topics as one parameter and can be done at once.
837 882
 		if ($_REQUEST['qaction'] == 'merge')
838 883
 		{
839 884
 			// Merge requires at least two topics.
840
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
841
-				redirectexit($redirect_url);
885
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
886
+							redirectexit($redirect_url);
887
+			}
842 888
 
843 889
 			require_once($sourcedir . '/SplitTopics.php');
844 890
 			return MergeExecute($_REQUEST['topics']);
845 891
 		}
846 892
 
847 893
 		// Just convert to the other method, to make it easier.
848
-		foreach ($_REQUEST['topics'] as $topic)
849
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
894
+		foreach ($_REQUEST['topics'] as $topic) {
895
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
896
+		}
850 897
 	}
851 898
 
852 899
 	// Weird... how'd you get here?
853
-	if (empty($_REQUEST['actions']))
854
-		redirectexit($redirect_url);
900
+	if (empty($_REQUEST['actions'])) {
901
+			redirectexit($redirect_url);
902
+	}
855 903
 
856 904
 	// Validate each action.
857 905
 	$temp = array();
858 906
 	foreach ($_REQUEST['actions'] as $topic => $action)
859 907
 	{
860
-		if (in_array($action, $possibleActions))
861
-			$temp[(int) $topic] = $action;
908
+		if (in_array($action, $possibleActions)) {
909
+					$temp[(int) $topic] = $action;
910
+		}
862 911
 	}
863 912
 	$_REQUEST['actions'] = $temp;
864 913
 
@@ -879,27 +928,31 @@  discard block
 block discarded – undo
879 928
 		{
880 929
 			if (!empty($board))
881 930
 			{
882
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
883
-					unset($_REQUEST['actions'][$row['id_topic']]);
884
-			}
885
-			else
931
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
932
+									unset($_REQUEST['actions'][$row['id_topic']]);
933
+				}
934
+			} else
886 935
 			{
887 936
 				// Don't allow them to act on unapproved posts they can't see...
888
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
889
-					unset($_REQUEST['actions'][$row['id_topic']]);
937
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
938
+									unset($_REQUEST['actions'][$row['id_topic']]);
939
+				}
890 940
 				// Goodness, this is fun.  We need to validate the action.
891
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
892
-					unset($_REQUEST['actions'][$row['id_topic']]);
893
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
894
-					unset($_REQUEST['actions'][$row['id_topic']]);
895
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
896
-					unset($_REQUEST['actions'][$row['id_topic']]);
941
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
942
+									unset($_REQUEST['actions'][$row['id_topic']]);
943
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) {
944
+									unset($_REQUEST['actions'][$row['id_topic']]);
945
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) {
946
+									unset($_REQUEST['actions'][$row['id_topic']]);
947
+				}
897 948
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
898
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))))
899
-					unset($_REQUEST['actions'][$row['id_topic']]);
949
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) {
950
+									unset($_REQUEST['actions'][$row['id_topic']]);
951
+				}
900 952
 				// If the topic is approved then you need permission to approve the posts within.
901
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))))
902
-					unset($_REQUEST['actions'][$row['id_topic']]);
953
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) {
954
+									unset($_REQUEST['actions'][$row['id_topic']]);
955
+				}
903 956
 			}
904 957
 		}
905 958
 		$smcFunc['db_free_result']($request);
@@ -917,11 +970,11 @@  discard block
 block discarded – undo
917 970
 	{
918 971
 		$topic = (int) $topic;
919 972
 
920
-		if ($action == 'markread')
921
-			$markCache[] = $topic;
922
-		elseif ($action == 'sticky')
923
-			$stickyCache[] = $topic;
924
-		elseif ($action == 'move')
973
+		if ($action == 'markread') {
974
+					$markCache[] = $topic;
975
+		} elseif ($action == 'sticky') {
976
+					$stickyCache[] = $topic;
977
+		} elseif ($action == 'move')
925 978
 		{
926 979
 			require_once($sourcedir . '/MoveTopic.php');
927 980
 			moveTopicConcurrence();
@@ -929,23 +982,25 @@  discard block
 block discarded – undo
929 982
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
930 983
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
931 984
 
932
-			if (empty($moveCache[1][$topic]))
933
-				continue;
985
+			if (empty($moveCache[1][$topic])) {
986
+							continue;
987
+			}
934 988
 
935 989
 			$moveCache[0][] = $topic;
990
+		} elseif ($action == 'remove') {
991
+					$removeCache[] = $topic;
992
+		} elseif ($action == 'lock') {
993
+					$lockCache[] = $topic;
994
+		} elseif ($action == 'approve') {
995
+					$approveCache[] = $topic;
936 996
 		}
937
-		elseif ($action == 'remove')
938
-			$removeCache[] = $topic;
939
-		elseif ($action == 'lock')
940
-			$lockCache[] = $topic;
941
-		elseif ($action == 'approve')
942
-			$approveCache[] = $topic;
943 997
 	}
944 998
 
945
-	if (empty($board))
946
-		$affectedBoards = array();
947
-	else
948
-		$affectedBoards = array($board => array(0, 0));
999
+	if (empty($board)) {
1000
+			$affectedBoards = array();
1001
+	} else {
1002
+			$affectedBoards = array($board => array(0, 0));
1003
+	}
949 1004
 
950 1005
 	// Do all the stickies...
951 1006
 	if (!empty($stickyCache))
@@ -1005,14 +1060,16 @@  discard block
 block discarded – undo
1005 1060
 		{
1006 1061
 			$to = $moveCache[1][$row['id_topic']];
1007 1062
 
1008
-			if (empty($to))
1009
-				continue;
1063
+			if (empty($to)) {
1064
+							continue;
1065
+			}
1010 1066
 
1011 1067
 			// Does this topic's board count the posts or not?
1012 1068
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1013 1069
 
1014
-			if (!isset($moveTos[$to]))
1015
-				$moveTos[$to] = array();
1070
+			if (!isset($moveTos[$to])) {
1071
+							$moveTos[$to] = array();
1072
+			}
1016 1073
 
1017 1074
 			$moveTos[$to][] = $row['id_topic'];
1018 1075
 
@@ -1026,8 +1083,9 @@  discard block
 block discarded – undo
1026 1083
 		require_once($sourcedir . '/MoveTopic.php');
1027 1084
 
1028 1085
 		// Do the actual moves...
1029
-		foreach ($moveTos as $to => $topics)
1030
-			moveTopics($topics, $to);
1086
+		foreach ($moveTos as $to => $topics) {
1087
+					moveTopics($topics, $to);
1088
+		}
1031 1089
 
1032 1090
 		// Does the post counts need to be updated?
1033 1091
 		if (!empty($moveTos))
@@ -1076,20 +1134,23 @@  discard block
 block discarded – undo
1076 1134
 
1077 1135
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1078 1136
 				{
1079
-					if (!isset($members[$row['id_member']]))
1080
-						$members[$row['id_member']] = 0;
1137
+					if (!isset($members[$row['id_member']])) {
1138
+											$members[$row['id_member']] = 0;
1139
+					}
1081 1140
 
1082
-					if ($topicRecounts[$row['id_topic']] === '+')
1083
-						$members[$row['id_member']] += 1;
1084
-					else
1085
-						$members[$row['id_member']] -= 1;
1141
+					if ($topicRecounts[$row['id_topic']] === '+') {
1142
+											$members[$row['id_member']] += 1;
1143
+					} else {
1144
+											$members[$row['id_member']] -= 1;
1145
+					}
1086 1146
 				}
1087 1147
 
1088 1148
 				$smcFunc['db_free_result']($request);
1089 1149
 
1090 1150
 				// And now update them member's post counts
1091
-				foreach ($members as $id_member => $post_adj)
1092
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1151
+				foreach ($members as $id_member => $post_adj) {
1152
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1153
+				}
1093 1154
 			}
1094 1155
 		}
1095 1156
 	}
@@ -1168,8 +1229,9 @@  discard block
 block discarded – undo
1168 1229
 			approveTopics($approveCache);
1169 1230
 
1170 1231
 			// Time for some logging!
1171
-			foreach ($approveCache as $topic)
1172
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1232
+			foreach ($approveCache as $topic) {
1233
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1234
+			}
1173 1235
 		}
1174 1236
 	}
1175 1237
 
@@ -1204,8 +1266,7 @@  discard block
 block discarded – undo
1204 1266
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1205 1267
 			}
1206 1268
 			$smcFunc['db_free_result']($result);
1207
-		}
1208
-		else
1269
+		} else
1209 1270
 		{
1210 1271
 			$result = $smcFunc['db_query']('', '
1211 1272
 				SELECT id_topic, locked, id_board
@@ -1255,13 +1316,15 @@  discard block
 block discarded – undo
1255 1316
 			)
1256 1317
 		);
1257 1318
 		$logged_topics = array();
1258
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1259
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1319
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1320
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1321
+		}
1260 1322
 		$smcFunc['db_free_result']($request);
1261 1323
 
1262 1324
 		$markArray = array();
1263
-		foreach ($markCache as $topic)
1264
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1325
+		foreach ($markCache as $topic) {
1326
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1327
+		}
1265 1328
 
1266 1329
 		$smcFunc['db_insert']('replace',
1267 1330
 			'{db_prefix}log_topics',
@@ -1274,8 +1337,9 @@  discard block
 block discarded – undo
1274 1337
 	foreach ($moveCache as $topic)
1275 1338
 	{
1276 1339
 		// Didn't actually move anything!
1277
-		if (!isset($topic[0]))
1278
-			break;
1340
+		if (!isset($topic[0])) {
1341
+					break;
1342
+		}
1279 1343
 
1280 1344
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1281 1345
 		sendNotifications($topic[0], 'move');
@@ -1297,8 +1361,9 @@  discard block
 block discarded – undo
1297 1361
 		'calendar_updated' => time(),
1298 1362
 	));
1299 1363
 
1300
-	if (!empty($affectedBoards))
1301
-		updateLastMessages(array_keys($affectedBoards));
1364
+	if (!empty($affectedBoards)) {
1365
+			updateLastMessages(array_keys($affectedBoards));
1366
+	}
1302 1367
 
1303 1368
 	redirectexit($redirect_url);
1304 1369
 }
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.