Completed
Push — release-2.1 ( b01710...0edd4f )
by
unknown
13s
created
Sources/Subs-Db-mysql.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 
256 256
 		case 'datetime':
257 257
 			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)
258
-				return 'str_to_date('.
259
-					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]).
258
+				return 'str_to_date(' .
259
+					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]) .
260 260
 					',\'%Y-%m-%d %h:%i:%s\')';
261 261
 			else
262 262
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		$old_pos = 0;
461 461
 		$pos = -1;
462 462
 		// Remove the string escape for better runtime
463
-		$db_string_1 = str_replace('\\\'','',$db_string);
463
+		$db_string_1 = str_replace('\\\'', '', $db_string);
464 464
 		while (true)
465 465
 		{
466 466
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 	{
843 843
 		$count = count($insertRows);
844 844
 		$ai = 0;
845
-		for($i = 0; $i < $count; $i++)
845
+		for ($i = 0; $i < $count; $i++)
846 846
 		{
847 847
 			$old_id = $smcFunc['db_insert_id']();
848 848
 
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 				$count2 = count($indexed_columns);
869 869
 				for ($x = 0; $x < $count2; $x++)
870 870
 				{
871
-					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
871
+					$where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x];
872 872
 					if (($x + 1) < $count2)
873 873
 						$where_string += ' AND ';
874 874
 				}
875 875
 
876
-				$request = $smcFunc['db_query']('','
877
-					SELECT `'. $keys[0] . '` FROM ' . $table .'
876
+				$request = $smcFunc['db_query']('', '
877
+					SELECT `'. $keys[0] . '` FROM ' . $table . '
878 878
 					WHERE ' . $where_string . ' LIMIT 1',
879 879
 					array()
880 880
 				);
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 			$return_var = array();
904 904
 			$count = count($insertRows);
905 905
 			$start = smf_db_insert_id($table, $keys[0]);
906
-			for ($i = 0; $i < $count; $i++ )
906
+			for ($i = 0; $i < $count; $i++)
907 907
 				$return_var[] = $start + $i;
908 908
 		}
909 909
 		return $return_var;
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
1037 1037
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1038 1038
 		$error_array[7], $error_array[8]);
1039
-	mysqli_stmt_execute ($mysql_error_data_prep);
1039
+	mysqli_stmt_execute($mysql_error_data_prep);
1040 1040
 }
1041 1041
 
1042 1042
 /**
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
  */
1051 1051
 function smf_db_custom_order($field, $array_values, $desc = false)
1052 1052
 {
1053
-	$return = 'CASE '. $field . ' ';
1053
+	$return = 'CASE ' . $field . ' ';
1054 1054
 	$count = count($array_values);
1055 1055
 	$then = ($desc ? ' THEN -' : ' THEN ');
1056 1056
 
Please login to merge, or discard this patch.
Braces   +254 added lines, -187 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',
@@ -63,9 +64,11 @@  discard block
 block discarded – undo
63 64
 			'db_error_insert'			=> 'smf_db_error_insert',
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 		);
67
+	}
66 68
 
67
-	if (!empty($db_options['persist']))
68
-		$db_server = 'p:' . $db_server;
69
+	if (!empty($db_options['persist'])) {
70
+			$db_server = 'p:' . $db_server;
71
+	}
69 72
 
70 73
 	$connection = mysqli_init();
71 74
 
@@ -75,24 +78,27 @@  discard block
 block discarded – undo
75 78
 
76 79
 	if ($connection)
77 80
 	{
78
-		if (!empty($db_options['port']))
79
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
80
-		else
81
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
81
+		if (!empty($db_options['port'])) {
82
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
83
+		} else {
84
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
85
+		}
82 86
 	}
83 87
 
84 88
 	// Something's wrong, show an error if its fatal (which we assume it is)
85 89
 	if ($success === false)
86 90
 	{
87
-		if (!empty($db_options['non_fatal']))
88
-			return null;
89
-		else
90
-			display_db_error();
91
+		if (!empty($db_options['non_fatal'])) {
92
+					return null;
93
+		} else {
94
+					display_db_error();
95
+		}
91 96
 	}
92 97
 
93 98
 	// Select the database, unless told not to
94
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
95
-		display_db_error();
99
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
100
+			display_db_error();
101
+	}
96 102
 
97 103
 	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\'');
98 104
 
@@ -165,34 +171,42 @@  discard block
 block discarded – undo
165 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
166 172
 
167 173
 	list ($values, $connection) = $db_callback;
168
-	if (!is_object($connection))
169
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
170 177
 
171
-	if ($matches[1] === 'db_prefix')
172
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
173 181
 
174
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
175
-		return $user_info[$matches[1]];
182
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
183
+			return $user_info[$matches[1]];
184
+	}
176 185
 
177
-	if ($matches[1] === 'empty')
178
-		return '\'\'';
186
+	if ($matches[1] === 'empty') {
187
+			return '\'\'';
188
+	}
179 189
 
180
-	if (!isset($matches[2]))
181
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
190
+	if (!isset($matches[2])) {
191
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
192
+	}
182 193
 
183
-	if ($matches[1] === 'literal')
184
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
194
+	if ($matches[1] === 'literal') {
195
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
196
+	}
185 197
 
186
-	if (!isset($values[$matches[2]]))
187
-		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__);
198
+	if (!isset($values[$matches[2]])) {
199
+			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__);
200
+	}
188 201
 
189 202
 	$replacement = $values[$matches[2]];
190 203
 
191 204
 	switch ($matches[1])
192 205
 	{
193 206
 		case 'int':
194
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
195
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
209
+			}
196 210
 			return (string) (int) $replacement;
197 211
 		break;
198 212
 
@@ -204,65 +218,73 @@  discard block
 block discarded – undo
204 218
 		case 'array_int':
205 219
 			if (is_array($replacement))
206 220
 			{
207
-				if (empty($replacement))
208
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+				if (empty($replacement)) {
222
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+				}
209 224
 
210 225
 				foreach ($replacement as $key => $value)
211 226
 				{
212
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
213
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
228
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+					}
214 230
 
215 231
 					$replacement[$key] = (string) (int) $value;
216 232
 				}
217 233
 
218 234
 				return implode(', ', $replacement);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219 237
 			}
220
-			else
221
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222 238
 
223 239
 		break;
224 240
 
225 241
 		case 'array_string':
226 242
 			if (is_array($replacement))
227 243
 			{
228
-				if (empty($replacement))
229
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+				if (empty($replacement)) {
245
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
246
+				}
230 247
 
231
-				foreach ($replacement as $key => $value)
232
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
248
+				foreach ($replacement as $key => $value) {
249
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
250
+				}
233 251
 
234 252
 				return implode(', ', $replacement);
253
+			} else {
254
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235 255
 			}
236
-			else
237
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
238 256
 		break;
239 257
 
240 258
 		case 'date':
241
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
242
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
243
-			else
244
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
259
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
260
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
261
+			} else {
262
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			}
245 264
 		break;
246 265
 
247 266
 		case 'time':
248
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
249
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
250
-			else
251
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
268
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
269
+			} else {
270
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			}
252 272
 		break;
253 273
 
254 274
 		case 'datetime':
255
-			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)
256
-				return 'str_to_date('.
275
+			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) {
276
+							return 'str_to_date('.
257 277
 					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]).
258 278
 					',\'%Y-%m-%d %h:%i:%s\')';
259
-			else
260
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			} else {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
261 282
 		break;
262 283
 
263 284
 		case 'float':
264
-			if (!is_numeric($replacement))
265
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
285
+			if (!is_numeric($replacement)) {
286
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+			}
266 288
 			return (string) (float) $replacement;
267 289
 		break;
268 290
 
@@ -276,32 +298,37 @@  discard block
 block discarded – undo
276 298
 		break;
277 299
 
278 300
 		case 'inet':
279
-			if ($replacement == 'null' || $replacement == '')
280
-				return 'null';
281
-			if (!isValidIP($replacement))
282
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
301
+			if ($replacement == 'null' || $replacement == '') {
302
+							return 'null';
303
+			}
304
+			if (!isValidIP($replacement)) {
305
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306
+			}
283 307
 			//we don't use the native support of mysql > 5.6.2
284 308
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
285 309
 
286 310
 		case 'array_inet':
287 311
 			if (is_array($replacement))
288 312
 			{
289
-				if (empty($replacement))
290
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+				if (empty($replacement)) {
314
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
315
+				}
291 316
 
292 317
 				foreach ($replacement as $key => $value)
293 318
 				{
294
-					if ($replacement == 'null' || $replacement == '')
295
-						$replacement[$key] = 'null';
296
-					if (!isValidIP($value))
297
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
319
+					if ($replacement == 'null' || $replacement == '') {
320
+											$replacement[$key] = 'null';
321
+					}
322
+					if (!isValidIP($value)) {
323
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
324
+					}
298 325
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
299 326
 				}
300 327
 
301 328
 				return implode(', ', $replacement);
329
+			} else {
330
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
302 331
 			}
303
-			else
304
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305 332
 		break;
306 333
 
307 334
 		default:
@@ -372,18 +399,20 @@  discard block
 block discarded – undo
372 399
 	// One more query....
373 400
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
374 401
 
375
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
376
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
402
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
403
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	}
377 405
 
378 406
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
379 407
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
380 408
 	{
381 409
 		// Add before LIMIT
382
-		if ($pos = strpos($db_string, 'LIMIT '))
383
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
384
-		else
385
-			// Append it.
410
+		if ($pos = strpos($db_string, 'LIMIT ')) {
411
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
412
+		} else {
413
+					// Append it.
386 414
 			$db_string .= "\n\t\t\tORDER BY null";
415
+		}
387 416
 	}
388 417
 
389 418
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -409,17 +438,18 @@  discard block
 block discarded – undo
409 438
 		while (true)
410 439
 		{
411 440
 			$pos = strpos($db_string_1, '\'', $pos + 1);
412
-			if ($pos === false)
413
-				break;
441
+			if ($pos === false) {
442
+							break;
443
+			}
414 444
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
415 445
 
416 446
 			while (true)
417 447
 			{
418 448
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
419 449
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
420
-				if ($pos1 === false)
421
-					break;
422
-				elseif ($pos2 === false || $pos2 > $pos1)
450
+				if ($pos1 === false) {
451
+									break;
452
+				} elseif ($pos2 === false || $pos2 > $pos1)
423 453
 				{
424 454
 					$pos = $pos1;
425 455
 					break;
@@ -435,16 +465,19 @@  discard block
 block discarded – undo
435 465
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
436 466
 
437 467
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
438
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
439
-			$fail = true;
468
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
469
+					$fail = true;
470
+		}
440 471
 		// Trying to change passwords, slow us down, or something?
441
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
442
-			$fail = true;
443
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
444
-			$fail = true;
472
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
473
+					$fail = true;
474
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
475
+					$fail = true;
476
+		}
445 477
 
446
-		if (!empty($fail) && function_exists('log_error'))
447
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
478
+		if (!empty($fail) && function_exists('log_error')) {
479
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
480
+		}
448 481
 	}
449 482
 
450 483
 	// Debugging.
@@ -454,8 +487,9 @@  discard block
 block discarded – undo
454 487
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
455 488
 
456 489
 		// Initialize $db_cache if not already initialized.
457
-		if (!isset($db_cache))
458
-			$db_cache = array();
490
+		if (!isset($db_cache)) {
491
+					$db_cache = array();
492
+		}
459 493
 
460 494
 		if (!empty($_SESSION['debug_redirect']))
461 495
 		{
@@ -471,17 +505,20 @@  discard block
 block discarded – undo
471 505
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
472 506
 	}
473 507
 
474
-	if (empty($db_unbuffered))
475
-		$ret = @mysqli_query($connection, $db_string);
476
-	else
477
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
508
+	if (empty($db_unbuffered)) {
509
+			$ret = @mysqli_query($connection, $db_string);
510
+	} else {
511
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
512
+	}
478 513
 
479
-	if ($ret === false && empty($db_values['db_error_skip']))
480
-		$ret = smf_db_error($db_string, $connection);
514
+	if ($ret === false && empty($db_values['db_error_skip'])) {
515
+			$ret = smf_db_error($db_string, $connection);
516
+	}
481 517
 
482 518
 	// Debugging.
483
-	if (isset($db_show_debug) && $db_show_debug === true)
484
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
519
+	if (isset($db_show_debug) && $db_show_debug === true) {
520
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
521
+	}
485 522
 
486 523
 	return $ret;
487 524
 }
@@ -528,12 +565,13 @@  discard block
 block discarded – undo
528 565
 	// Decide which connection to use
529 566
 	$connection = $connection === null ? $db_connection : $connection;
530 567
 
531
-	if ($type == 'begin')
532
-		return @mysqli_query($connection, 'BEGIN');
533
-	elseif ($type == 'rollback')
534
-		return @mysqli_query($connection, 'ROLLBACK');
535
-	elseif ($type == 'commit')
536
-		return @mysqli_query($connection, 'COMMIT');
568
+	if ($type == 'begin') {
569
+			return @mysqli_query($connection, 'BEGIN');
570
+	} elseif ($type == 'rollback') {
571
+			return @mysqli_query($connection, 'ROLLBACK');
572
+	} elseif ($type == 'commit') {
573
+			return @mysqli_query($connection, 'COMMIT');
574
+	}
537 575
 
538 576
 	return false;
539 577
 }
@@ -571,8 +609,9 @@  discard block
 block discarded – undo
571 609
 	//    1213: Deadlock found.
572 610
 
573 611
 	// Log the error.
574
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
575
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
612
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
613
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
614
+	}
576 615
 
577 616
 	// Database error auto fixing ;).
578 617
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -581,8 +620,9 @@  discard block
 block discarded – undo
581 620
 		$old_cache = @$modSettings['cache_enable'];
582 621
 		$modSettings['cache_enable'] = '1';
583 622
 
584
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
585
-			$db_last_error = max(@$db_last_error, $temp);
623
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
624
+					$db_last_error = max(@$db_last_error, $temp);
625
+		}
586 626
 
587 627
 		if (@$db_last_error < time() - 3600 * 24 * 3)
588 628
 		{
@@ -598,8 +638,9 @@  discard block
 block discarded – undo
598 638
 					foreach ($tables as $table)
599 639
 					{
600 640
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
601
-						if (trim($table) != '')
602
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
641
+						if (trim($table) != '') {
642
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
643
+						}
603 644
 					}
604 645
 				}
605 646
 
@@ -608,8 +649,9 @@  discard block
 block discarded – undo
608 649
 			// Table crashed.  Let's try to fix it.
609 650
 			elseif ($query_errno == 1016)
610 651
 			{
611
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
612
-					$fix_tables = array('`' . $match[1] . '`');
652
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
653
+									$fix_tables = array('`' . $match[1] . '`');
654
+				}
613 655
 			}
614 656
 			// Indexes crashed.  Should be easy to fix!
615 657
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -628,13 +670,15 @@  discard block
 block discarded – undo
628 670
 
629 671
 			// Make a note of the REPAIR...
630 672
 			cache_put_data('db_last_error', time(), 600);
631
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
632
-				updateSettingsFile(array('db_last_error' => time()));
673
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
674
+							updateSettingsFile(array('db_last_error' => time()));
675
+			}
633 676
 
634 677
 			// Attempt to find and repair the broken table.
635
-			foreach ($fix_tables as $table)
636
-				$smcFunc['db_query']('', "
678
+			foreach ($fix_tables as $table) {
679
+							$smcFunc['db_query']('', "
637 680
 					REPAIR TABLE $table", false, false);
681
+			}
638 682
 
639 683
 			// And send off an email!
640 684
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -643,11 +687,12 @@  discard block
 block discarded – undo
643 687
 
644 688
 			// Try the query again...?
645 689
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
646
-			if ($ret !== false)
647
-				return $ret;
690
+			if ($ret !== false) {
691
+							return $ret;
692
+			}
693
+		} else {
694
+					$modSettings['cache_enable'] = $old_cache;
648 695
 		}
649
-		else
650
-			$modSettings['cache_enable'] = $old_cache;
651 696
 
652 697
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
653 698
 		if (in_array($query_errno, array(1205, 1213)))
@@ -660,24 +705,27 @@  discard block
 block discarded – undo
660 705
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
661 706
 
662 707
 					$new_errno = mysqli_errno($db_connection);
663
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
664
-						break;
708
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
709
+											break;
710
+					}
665 711
 				}
666 712
 
667 713
 				// If it failed again, shucks to be you... we're not trying it over and over.
668
-				if ($ret !== false)
669
-					return $ret;
714
+				if ($ret !== false) {
715
+									return $ret;
716
+				}
670 717
 			}
671 718
 		}
672 719
 		// Are they out of space, perhaps?
673 720
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
674 721
 		{
675
-			if (!isset($txt))
676
-				$query_error .= ' - check database storage space.';
677
-			else
722
+			if (!isset($txt)) {
723
+							$query_error .= ' - check database storage space.';
724
+			} else
678 725
 			{
679
-				if (!isset($txt['mysql_error_space']))
680
-					loadLanguage('Errors');
726
+				if (!isset($txt['mysql_error_space'])) {
727
+									loadLanguage('Errors');
728
+				}
681 729
 
682 730
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
683 731
 			}
@@ -685,15 +733,17 @@  discard block
 block discarded – undo
685 733
 	}
686 734
 
687 735
 	// Nothing's defined yet... just die with it.
688
-	if (empty($context) || empty($txt))
689
-		die($query_error);
736
+	if (empty($context) || empty($txt)) {
737
+			die($query_error);
738
+	}
690 739
 
691 740
 	// Show an error message, if possible.
692 741
 	$context['error_title'] = $txt['database_error'];
693
-	if (allowedTo('admin_forum'))
694
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
695
-	else
696
-		$context['error_message'] = $txt['try_again'];
742
+	if (allowedTo('admin_forum')) {
743
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
744
+	} else {
745
+			$context['error_message'] = $txt['try_again'];
746
+	}
697 747
 
698 748
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
699 749
 	{
@@ -725,8 +775,9 @@  discard block
 block discarded – undo
725 775
 	$return_var = null;
726 776
 
727 777
 	// With nothing to insert, simply return.
728
-	if (empty($data))
729
-		return;
778
+	if (empty($data)) {
779
+			return;
780
+	}
730 781
 
731 782
 	// Replace the prefix holder with the actual prefix.
732 783
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -736,23 +787,26 @@  discard block
 block discarded – undo
736 787
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
737 788
 	{
738 789
 		$with_returning = true;
739
-		if ($returnmode == 2)
740
-			$return_var = array();
790
+		if ($returnmode == 2) {
791
+					$return_var = array();
792
+		}
741 793
 	}
742 794
 
743 795
 	// Inserting data as a single row can be done as a single array.
744
-	if (!is_array($data[array_rand($data)]))
745
-		$data = array($data);
796
+	if (!is_array($data[array_rand($data)])) {
797
+			$data = array($data);
798
+	}
746 799
 
747 800
 	// Create the mold for a single row insert.
748 801
 	$insertData = '(';
749 802
 	foreach ($columns as $columnName => $type)
750 803
 	{
751 804
 		// Are we restricting the length?
752
-		if (strpos($type, 'string-') !== false)
753
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
754
-		else
755
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
805
+		if (strpos($type, 'string-') !== false) {
806
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
807
+		} else {
808
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
809
+		}
756 810
 	}
757 811
 	$insertData = substr($insertData, 0, -2) . ')';
758 812
 
@@ -761,8 +815,9 @@  discard block
 block discarded – undo
761 815
 
762 816
 	// Here's where the variables are injected to the query.
763 817
 	$insertRows = array();
764
-	foreach ($data as $dataRow)
765
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
818
+	foreach ($data as $dataRow) {
819
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
820
+	}
766 821
 
767 822
 	// Determine the method of insertion.
768 823
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -781,8 +836,7 @@  discard block
 block discarded – undo
781 836
 			),
782 837
 			$connection
783 838
 		);
784
-	}
785
-	else //special way for ignore method with returning
839
+	} else //special way for ignore method with returning
786 840
 	{
787 841
 		$count = count($insertRows);
788 842
 		$ai = 0;
@@ -802,19 +856,21 @@  discard block
 block discarded – undo
802 856
 			);
803 857
 			$new_id = $smcFunc['db_insert_id']();
804 858
 
805
-			if ($last_id != $new_id) //the inserted value was new
859
+			if ($last_id != $new_id) {
860
+				//the inserted value was new
806 861
 			{
807 862
 				$ai = $new_id;
808 863
 			}
809
-			else	// the inserted value already exists we need to find the pk
864
+			} else	// the inserted value already exists we need to find the pk
810 865
 			{
811 866
 				$where_string = '';
812 867
 				$count2 = count($indexed_columns);
813 868
 				for ($x = 0; $x < $count2; $x++)
814 869
 				{
815 870
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
816
-					if (($x + 1) < $count2)
817
-						$where_string += ' AND ';
871
+					if (($x + 1) < $count2) {
872
+											$where_string += ' AND ';
873
+					}
818 874
 				}
819 875
 
820 876
 				$request = $smcFunc['db_query']('','
@@ -830,25 +886,27 @@  discard block
 block discarded – undo
830 886
 				}
831 887
 			}
832 888
 
833
-			if ($returnmode == 1)
834
-				$return_var = $ai;
835
-			else if ($returnmode == 2)
836
-				$return_var[] = $ai;
889
+			if ($returnmode == 1) {
890
+							$return_var = $ai;
891
+			} else if ($returnmode == 2) {
892
+							$return_var[] = $ai;
893
+			}
837 894
 		}
838 895
 	}
839 896
 
840 897
 
841 898
 	if ($with_returning)
842 899
 	{
843
-		if ($returnmode == 1 && empty($return_var))
844
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
845
-		else if ($returnmode == 2 && empty($return_var))
900
+		if ($returnmode == 1 && empty($return_var)) {
901
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
902
+		} else if ($returnmode == 2 && empty($return_var))
846 903
 		{
847 904
 			$return_var = array();
848 905
 			$count = count($insertRows);
849 906
 			$start = smf_db_insert_id($table, $keys[0]);
850
-			for ($i = 0; $i < $count; $i++ )
851
-				$return_var[] = $start + $i;
907
+			for ($i = 0; $i < $count; $i++ ) {
908
+							$return_var[] = $start + $i;
909
+			}
852 910
 		}
853 911
 		return $return_var;
854 912
 	}
@@ -866,8 +924,9 @@  discard block
 block discarded – undo
866 924
  */
867 925
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
868 926
 {
869
-	if (empty($log_message))
870
-		$log_message = $error_message;
927
+	if (empty($log_message)) {
928
+			$log_message = $error_message;
929
+	}
871 930
 
872 931
 	foreach (debug_backtrace() as $step)
873 932
 	{
@@ -886,12 +945,14 @@  discard block
 block discarded – undo
886 945
 	}
887 946
 
888 947
 	// A special case - we want the file and line numbers for debugging.
889
-	if ($error_type == 'return')
890
-		return array($file, $line);
948
+	if ($error_type == 'return') {
949
+			return array($file, $line);
950
+	}
891 951
 
892 952
 	// Is always a critical error.
893
-	if (function_exists('log_error'))
894
-		log_error($log_message, 'critical', $file, $line);
953
+	if (function_exists('log_error')) {
954
+			log_error($log_message, 'critical', $file, $line);
955
+	}
895 956
 
896 957
 	if (function_exists('fatal_error'))
897 958
 	{
@@ -899,12 +960,12 @@  discard block
 block discarded – undo
899 960
 
900 961
 		// Cannot continue...
901 962
 		exit;
963
+	} elseif ($error_type) {
964
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
965
+	} else {
966
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
967
+	}
902 968
 	}
903
-	elseif ($error_type)
904
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
905
-	else
906
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
907
-}
908 969
 
909 970
 /**
910 971
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -921,10 +982,11 @@  discard block
 block discarded – undo
921 982
 		'\\' => '\\\\',
922 983
 	);
923 984
 
924
-	if ($translate_human_wildcards)
925
-		$replacements += array(
985
+	if ($translate_human_wildcards) {
986
+			$replacements += array(
926 987
 			'*' => '%',
927 988
 		);
989
+	}
928 990
 
929 991
 	return strtr($string, $replacements);
930 992
 }
@@ -938,8 +1000,9 @@  discard block
 block discarded – undo
938 1000
  */
939 1001
 function smf_is_resource($result)
940 1002
 {
941
-	if ($result instanceof mysqli_result)
942
-		return true;
1003
+	if ($result instanceof mysqli_result) {
1004
+			return true;
1005
+	}
943 1006
 
944 1007
 	return false;
945 1008
 }
@@ -968,19 +1031,22 @@  discard block
 block discarded – undo
968 1031
 	static $mysql_error_data_prep;
969 1032
 
970 1033
 	// without database we can't do anything
971
-	if (empty($db_connection))
972
-		return;
1034
+	if (empty($db_connection)) {
1035
+			return;
1036
+	}
973 1037
 
974
-	if (empty($mysql_error_data_prep))
975
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1038
+	if (empty($mysql_error_data_prep)) {
1039
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
976 1040
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
977 1041
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
978 1042
 			);
1043
+	}
979 1044
 
980
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
981
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
982
-	else
983
-		$error_array[2] = null;
1045
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1046
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1047
+	} else {
1048
+			$error_array[2] = null;
1049
+	}
984 1050
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
985 1051
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
986 1052
 		$error_array[7], $error_array[8]);
@@ -1002,8 +1068,9 @@  discard block
 block discarded – undo
1002 1068
 	$count = count($array_values);
1003 1069
 	$then = ($desc ? ' THEN -' : ' THEN ');
1004 1070
 
1005
-	for ($i = 0; $i < $count; $i++)
1006
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1071
+	for ($i = 0; $i < $count; $i++) {
1072
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1073
+	}
1007 1074
 
1008 1075
 	$return .= 'END';
1009 1076
 	return $return;
Please login to merge, or discard this patch.
Themes/default/Login.template.php 1 patch
Braces   +35 added lines, -24 removed lines patch added patch discarded remove patch
@@ -28,15 +28,17 @@  discard block
 block discarded – undo
28 28
 				<form class="login" action="', $context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '">';
29 29
 
30 30
 	// Did they make a mistake last time?
31
-	if (!empty($context['login_errors']))
32
-		echo '
31
+	if (!empty($context['login_errors'])) {
32
+			echo '
33 33
 					<div class="errorbox">', implode('<br>', $context['login_errors']), '</div>
34 34
 					<br>';
35
+	}
35 36
 
36 37
 	// Or perhaps there's some special description for this time?
37
-	if (isset($context['description']))
38
-		echo '
38
+	if (isset($context['description'])) {
39
+			echo '
39 40
 					<div class="information">', $context['description'], '</div>';
41
+	}
40 42
 
41 43
 	// Now just get the basic information - username, password, etc.
42 44
 	echo '
@@ -61,10 +63,11 @@  discard block
 block discarded – undo
61 63
 						</dd>';
62 64
 
63 65
 	// If they have deleted their account, give them a chance to change their mind.
64
-	if (isset($context['login_show_undelete']))
65
-		echo '
66
+	if (isset($context['login_show_undelete'])) {
67
+			echo '
66 68
 						<dt class="alert">', $txt['undelete_account'], ':</dt>
67 69
 						<dd><input type="checkbox" name="undelete"></dd>';
70
+	}
68 71
 
69 72
 	echo '
70 73
 					</dl>
@@ -82,8 +85,8 @@  discard block
 block discarded – undo
82 85
 							document.getElementById("', !empty($context['from_ajax']) ? 'ajax_' : '', isset($context['default_username']) && $context['default_username'] != '' ? 'loginpass' : 'loginuser', '").focus();
83 86
 						}, 150);';
84 87
 
85
-	if (!empty($context['from_ajax']))
86
-		echo '
88
+	if (!empty($context['from_ajax'])) {
89
+			echo '
87 90
 						form = $("#frmLogin");
88 91
 						form.submit(function(e) {
89 92
 							e.preventDefault();
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 
117 120
 							return false;
118 121
 						});';
122
+	}
119 123
 
120 124
 	echo '
121 125
 					</script>
122 126
 				</form>';
123 127
 
124 128
 	// It is a long story as to why we have this when we're clearly not going to use it.
125
-	if (!empty($context['from_ajax']))
126
-		echo '
129
+	if (!empty($context['from_ajax'])) {
130
+			echo '
127 131
 				<br>
128 132
 				<a href="javascript:self.close();"></a>';
133
+	}
129 134
 
130 135
 	echo '
131 136
 			</div><!-- .roundframe -->
@@ -148,11 +153,12 @@  discard block
 block discarded – undo
148 153
 			</div>
149 154
 			<div class="roundframe noup">';
150 155
 
151
-	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
152
-		echo '
156
+	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error'])) {
157
+			echo '
153 158
 				<div class="error">
154 159
 					', $txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' : 'backup_') . 'invalid'], '
155 160
 				</div>';
161
+	}
156 162
 
157 163
 	echo '
158 164
 				<form action="', $context['tfa_url'], '" method="post" id="frmTfa">
@@ -181,8 +187,8 @@  discard block
 block discarded – undo
181 187
 				<script>
182 188
 					form = $("#frmTfa");';
183 189
 
184
-	if (!empty($context['from_ajax']))
185
-		echo '
190
+	if (!empty($context['from_ajax'])) {
191
+			echo '
186 192
 					form.submit(function(e) {
187 193
 						// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
188 194
 						if (form.find("input[name=tfa_backup]:first").val().length > 0)
@@ -201,6 +207,7 @@  discard block
 block discarded – undo
201 207
 
202 208
 						return false;
203 209
 					});';
210
+	}
204 211
 
205 212
 	echo '
206 213
 					form.find("input[name=backup]").click(function(e) {
@@ -232,10 +239,11 @@  discard block
 block discarded – undo
232 239
 			<p class="information centertext">
233 240
 				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';
234 241
 
235
-	if ($context['can_register'])
236
-		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
237
-	else
238
-		echo $txt['login_below'];
242
+	if ($context['can_register']) {
243
+			echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
244
+	} else {
245
+			echo $txt['login_below'];
246
+	}
239 247
 
240 248
 	// And now the login information.
241 249
 	echo '
@@ -335,9 +343,10 @@  discard block
 block discarded – undo
335 343
 			</div>
336 344
 			<div class="roundframe centertext noup">';
337 345
 
338
-	if (!empty($context['incorrect_password']))
339
-		echo '
346
+	if (!empty($context['incorrect_password'])) {
347
+			echo '
340 348
 				<div class="error">', $txt['admin_incorrect_password'], '</div>';
349
+	}
341 350
 
342 351
 	echo '
343 352
 				<strong>', $txt['password'], ':</strong>
@@ -378,10 +387,11 @@  discard block
 block discarded – undo
378 387
 				<dl>';
379 388
 
380 389
 	// You didn't even have an ID?
381
-	if (empty($context['member_id']))
382
-		echo '
390
+	if (empty($context['member_id'])) {
391
+			echo '
383 392
 					<dt>', $txt['invalid_activation_username'], ':</dt>
384 393
 					<dd><input type="text" name="user" size="30"></dd>';
394
+	}
385 395
 
386 396
 	echo '
387 397
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
@@ -418,13 +428,14 @@  discard block
 block discarded – undo
418 428
 					<dd><input type="password" name="passwd" size="30"></dd>
419 429
 				</dl>';
420 430
 
421
-	if ($context['can_activate'])
422
-		echo '
431
+	if ($context['can_activate']) {
432
+			echo '
423 433
 				<p>', $txt['invalid_activation_known'], '</p>
424 434
 				<dl>
425 435
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
426 436
 					<dd><input type="text" name="code" size="30"></dd>
427 437
 				</dl>';
438
+	}
428 439
 
429 440
 	echo '
430 441
 				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button"></p>
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -430,8 +430,8 @@
 block discarded – undo
430 430
 	$real_name = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
431 431
 
432 432
 	// Searches.
433
-	$member_name_search = $member_name . ' ' . $comparison . ' ' . implode( ' OR ' . $member_name . ' ' . $comparison . ' ', $names_list);
434
-	$real_name_search = $real_name . ' ' . $comparison . ' ' . implode( ' OR ' . $real_name . ' ' . $comparison . ' ', $names_list);
433
+	$member_name_search = $member_name . ' ' . $comparison . ' ' . implode(' OR ' . $member_name . ' ' . $comparison . ' ', $names_list);
434
+	$real_name_search = $real_name . ' ' . $comparison . ' ' . implode(' OR ' . $real_name . ' ' . $comparison . ' ', $names_list);
435 435
 
436 436
 	// Search by username, display name, and email address.
437 437
 	$request = $smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Braces   +165 added lines, -119 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -47,8 +48,9 @@  discard block
 block discarded – undo
47 48
 	if (isset($_COOKIE[$cookiename]))
48 49
 	{
49 50
 		// First check for 2.1 json-format cookie
50
-		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1)
51
-			list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
51
+		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) {
52
+					list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
53
+		}
52 54
 
53 55
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
54 56
 		elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1)
@@ -58,15 +60,17 @@  discard block
 block discarded – undo
58 60
 			$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
59 61
 
60 62
 			// Maybe we need to temporarily pretend to be using local cookies
61
-			if ($cookie_state == 0 && $old_state == 1)
62
-				list($old_domain, $old_path) = url_parts(true, false);
63
-			else
64
-				list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
63
+			if ($cookie_state == 0 && $old_state == 1) {
64
+							list($old_domain, $old_path) = url_parts(true, false);
65
+			} else {
66
+							list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
67
+			}
65 68
 		}
66 69
 
67 70
 		// Out with the old, in with the new!
68
-		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1])
69
-			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
71
+		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) {
72
+					smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
73
+		}
70 74
 	}
71 75
 
72 76
 	// Get the data and path to set it on.
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
 	smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
83 87
 
84 88
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
85
-	if (empty($id) && !empty($modSettings['globalCookies']))
86
-		smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
89
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
90
+			smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
91
+	}
87 92
 
88 93
 	// Any alias URLs?  This is mainly for use with frames, etc.
89 94
 	if (!empty($modSettings['forum_alias_urls']))
@@ -99,8 +104,9 @@  discard block
 block discarded – undo
99 104
 
100 105
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
101 106
 
102
-			if ($cookie_url[0] == '')
103
-				$cookie_url[0] = strtok($alias, '/');
107
+			if ($cookie_url[0] == '') {
108
+							$cookie_url[0] = strtok($alias, '/');
109
+			}
104 110
 
105 111
 			$alias_data = $smcFunc['json_decode']($data, true);
106 112
 			$alias_data[3] = $cookie_url[0];
@@ -159,8 +165,9 @@  discard block
 block discarded – undo
159 165
 	smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
160 166
 
161 167
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
162
-	if (empty($id) && !empty($modSettings['globalCookies']))
163
-		smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
168
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
169
+			smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
170
+	}
164 171
 
165 172
 	$_COOKIE[$identifier] = $data;
166 173
 }
@@ -182,23 +189,28 @@  discard block
 block discarded – undo
182 189
 	$parsed_url = parse_url($boardurl);
183 190
 
184 191
 	// Is local cookies off?
185
-	if (empty($parsed_url['path']) || !$local)
186
-		$parsed_url['path'] = '';
192
+	if (empty($parsed_url['path']) || !$local) {
193
+			$parsed_url['path'] = '';
194
+	}
187 195
 
188
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
189
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
196
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
197
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
198
+	}
190 199
 
191 200
 	// Globalize cookies across domains (filter out IP-addresses)?
192
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
193
-		$parsed_url['host'] = '.' . $parts[1];
201
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
202
+			$parsed_url['host'] = '.' . $parts[1];
203
+	}
194 204
 
195 205
 	// We shouldn't use a host at all if both options are off.
196
-	elseif (!$local && !$global)
197
-		$parsed_url['host'] = '';
206
+	elseif (!$local && !$global) {
207
+			$parsed_url['host'] = '';
208
+	}
198 209
 
199 210
 	// The host also shouldn't be set if there aren't any dots in it.
200
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
201
-		$parsed_url['host'] = '';
211
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
212
+			$parsed_url['host'] = '';
213
+	}
202 214
 
203 215
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
204 216
 }
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 	createToken('login');
218 230
 
219 231
 	// Never redirect to an attachment
220
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
221
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
232
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
233
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
234
+	}
222 235
 
223 236
 	$context['sub_template'] = 'kick_guest';
224 237
 	$context['page_title'] = $txt['login'];
@@ -273,10 +286,12 @@  discard block
 block discarded – undo
273 286
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
274 287
 		log_error($txt['security_wrong'], 'critical');
275 288
 
276
-		if (isset($_POST[$type . '_hash_pass']))
277
-			unset($_POST[$type . '_hash_pass']);
278
-		if (isset($_POST[$type . '_pass']))
279
-			unset($_POST[$type . '_pass']);
289
+		if (isset($_POST[$type . '_hash_pass'])) {
290
+					unset($_POST[$type . '_hash_pass']);
291
+		}
292
+		if (isset($_POST[$type . '_pass'])) {
293
+					unset($_POST[$type . '_pass']);
294
+		}
280 295
 
281 296
 		$context['incorrect_password'] = true;
282 297
 	}
@@ -289,15 +304,17 @@  discard block
 block discarded – undo
289 304
 
290 305
 	// Now go through $_POST.  Make sure the session hash is sent.
291 306
 	$_POST[$context['session_var']] = $context['session_id'];
292
-	foreach ($_POST as $k => $v)
293
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
307
+	foreach ($_POST as $k => $v) {
308
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
309
+	}
294 310
 
295 311
 	// Now we'll use the admin_login sub template of the Login template.
296 312
 	$context['sub_template'] = 'admin_login';
297 313
 
298 314
 	// And title the page something like "Login".
299
-	if (!isset($context['page_title']))
300
-		$context['page_title'] = $txt['login'];
315
+	if (!isset($context['page_title'])) {
316
+			$context['page_title'] = $txt['login'];
317
+	}
301 318
 
302 319
 	// The type of action.
303 320
 	$context['sessionCheckType'] = $type;
@@ -320,14 +337,15 @@  discard block
 block discarded – undo
320 337
 {
321 338
 	global $smcFunc;
322 339
 
323
-	if (!is_array($v))
324
-		return '
340
+	if (!is_array($v)) {
341
+			return '
325 342
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
326
-	else
343
+	} else
327 344
 	{
328 345
 		$ret = '';
329
-		foreach ($v as $k2 => $v2)
330
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
346
+		foreach ($v as $k2 => $v2) {
347
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
348
+		}
331 349
 
332 350
 		return $ret;
333 351
 	}
@@ -354,18 +372,20 @@  discard block
 block discarded – undo
354 372
 		foreach ($get as $k => $v)
355 373
 		{
356 374
 			// Only if it's not already in the $scripturl!
357
-			if (!isset($temp[$k]))
358
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
375
+			if (!isset($temp[$k])) {
376
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
377
+			}
359 378
 			// If it changed, put it out there, but with an ampersand.
360
-			elseif ($temp[$k] != $get[$k])
361
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
379
+			elseif ($temp[$k] != $get[$k]) {
380
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
381
+			}
362 382
 		}
363
-	}
364
-	else
383
+	} else
365 384
 	{
366 385
 		// Add up all the data from $_GET into get_data.
367
-		foreach ($get as $k => $v)
368
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
386
+		foreach ($get as $k => $v) {
387
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
388
+		}
369 389
 	}
370 390
 
371 391
 	$query_string = substr($query_string, 0, -1);
@@ -388,8 +408,9 @@  discard block
 block discarded – undo
388 408
 	global $scripturl, $user_info, $smcFunc;
389 409
 
390 410
 	// If it's not already an array, make it one.
391
-	if (!is_array($names))
392
-		$names = explode(',', $names);
411
+	if (!is_array($names)) {
412
+			$names = explode(',', $names);
413
+	}
393 414
 
394 415
 	$maybe_email = false;
395 416
 	$names_list = array();
@@ -401,10 +422,11 @@  discard block
 block discarded – undo
401 422
 		$maybe_email |= strpos($name, '@') !== false;
402 423
 
403 424
 		// Make it so standard wildcards will work. (* and ?)
404
-		if ($use_wildcards)
405
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
406
-		else
407
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
425
+		if ($use_wildcards) {
426
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
427
+		} else {
428
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
429
+		}
408 430
 
409 431
 		$names_list[] = '{string:lookup_name_' . $i . '}';
410 432
 		$where_params['lookup_name_' . $i] = $names[$i];
@@ -417,11 +439,12 @@  discard block
 block discarded – undo
417 439
 	$results = array();
418 440
 
419 441
 	// This ensures you can't search someones email address if you can't see it.
420
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
421
-		$email_condition = '
442
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
443
+			$email_condition = '
422 444
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
423
-	else
424
-		$email_condition = '';
445
+	} else {
446
+			$email_condition = '';
447
+	}
425 448
 
426 449
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
427 450
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -480,10 +503,11 @@  discard block
 block discarded – undo
480 503
 	$context['template_layers'] = array();
481 504
 	$context['sub_template'] = 'find_members';
482 505
 
483
-	if (isset($_REQUEST['search']))
484
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
485
-	else
486
-		$_REQUEST['start'] = 0;
506
+	if (isset($_REQUEST['search'])) {
507
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
508
+	} else {
509
+			$_REQUEST['start'] = 0;
510
+	}
487 511
 
488 512
 	// Allow the user to pass the input to be added to to the box.
489 513
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -524,10 +548,10 @@  discard block
 block discarded – undo
524 548
 		);
525 549
 
526 550
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
551
+	} else {
552
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
553
+	}
527 554
 	}
528
-	else
529
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
530
-}
531 555
 
532 556
 /**
533 557
  * Outputs each member name on its own line.
@@ -543,8 +567,9 @@  discard block
 block discarded – undo
543 567
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
544 568
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
545 569
 
546
-	if (function_exists('iconv'))
547
-		header('content-type: text/plain; charset=UTF-8');
570
+	if (function_exists('iconv')) {
571
+			header('content-type: text/plain; charset=UTF-8');
572
+	}
548 573
 
549 574
 	$request = $smcFunc['db_query']('', '
550 575
 		SELECT real_name
@@ -564,14 +589,16 @@  discard block
 block discarded – undo
564 589
 		if (function_exists('iconv'))
565 590
 		{
566 591
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
567
-			if ($utf8)
568
-				$row['real_name'] = $utf8;
592
+			if ($utf8) {
593
+							$row['real_name'] = $utf8;
594
+			}
569 595
 		}
570 596
 
571 597
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
572 598
 
573
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
574
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
599
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
600
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
601
+		}
575 602
 
576 603
 		echo $row['real_name'], "\n";
577 604
 	}
@@ -628,9 +655,9 @@  discard block
 block discarded – undo
628 655
 
629 656
 		// Update the database...
630 657
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
658
+	} else {
659
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
631 660
 	}
632
-	else
633
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
634 661
 
635 662
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
636 663
 
@@ -661,31 +688,37 @@  discard block
 block discarded – undo
661 688
 	$errors = array();
662 689
 
663 690
 	// Don't use too long a name.
664
-	if ($smcFunc['strlen']($username) > 25)
665
-		$errors[] = array('lang', 'error_long_name');
691
+	if ($smcFunc['strlen']($username) > 25) {
692
+			$errors[] = array('lang', 'error_long_name');
693
+	}
666 694
 
667 695
 	// No name?!  How can you register with no name?
668
-	if ($username == '')
669
-		$errors[] = array('lang', 'need_username');
696
+	if ($username == '') {
697
+			$errors[] = array('lang', 'need_username');
698
+	}
670 699
 
671 700
 	// Only these characters are permitted.
672
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
673
-		$errors[] = array('lang', 'error_invalid_characters_username');
701
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
702
+			$errors[] = array('lang', 'error_invalid_characters_username');
703
+	}
674 704
 
675
-	if (stristr($username, $txt['guest_title']) !== false)
676
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
705
+	if (stristr($username, $txt['guest_title']) !== false) {
706
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
707
+	}
677 708
 
678 709
 	if ($check_reserved_name)
679 710
 	{
680 711
 		require_once($sourcedir . '/Subs-Members.php');
681
-		if (isReservedName($username, $memID, false))
682
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
712
+		if (isReservedName($username, $memID, false)) {
713
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
714
+		}
683 715
 	}
684 716
 
685
-	if ($return_error)
686
-		return $errors;
687
-	elseif (empty($errors))
688
-		return null;
717
+	if ($return_error) {
718
+			return $errors;
719
+	} elseif (empty($errors)) {
720
+			return null;
721
+	}
689 722
 
690 723
 	loadLanguage('Errors');
691 724
 	$error = $errors[0];
@@ -711,22 +744,26 @@  discard block
 block discarded – undo
711 744
 	global $modSettings, $smcFunc;
712 745
 
713 746
 	// Perform basic requirements first.
714
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
715
-		return 'short';
747
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
748
+			return 'short';
749
+	}
716 750
 
717 751
 	// Is this enough?
718
-	if (empty($modSettings['password_strength']))
719
-		return null;
752
+	if (empty($modSettings['password_strength'])) {
753
+			return null;
754
+	}
720 755
 
721 756
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
722
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
723
-		return 'restricted_words';
724
-	elseif ($smcFunc['strpos']($password, $username) !== false)
725
-		return 'restricted_words';
757
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
758
+			return 'restricted_words';
759
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
760
+			return 'restricted_words';
761
+	}
726 762
 
727 763
 	// If just medium, we're done.
728
-	if ($modSettings['password_strength'] == 1)
729
-		return null;
764
+	if ($modSettings['password_strength'] == 1) {
765
+			return null;
766
+	}
730 767
 
731 768
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
732 769
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -758,14 +795,16 @@  discard block
 block discarded – undo
758 795
 			)
759 796
 		);
760 797
 		$groups = array();
761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
762
-			$groups[] = $row['id_group'];
798
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+					$groups[] = $row['id_group'];
800
+		}
763 801
 		$smcFunc['db_free_result']($request);
764 802
 
765
-		if (empty($groups))
766
-			$group_query = '0=1';
767
-		else
768
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
803
+		if (empty($groups)) {
804
+					$group_query = '0=1';
805
+		} else {
806
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
807
+		}
769 808
 	}
770 809
 
771 810
 	// Then, same again, just the boards this time!
@@ -775,10 +814,11 @@  discard block
 block discarded – undo
775 814
 	{
776 815
 		$boards = boardsAllowedTo('moderate_board', true);
777 816
 
778
-		if (empty($boards))
779
-			$board_query = '0=1';
780
-		else
781
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
817
+		if (empty($boards)) {
818
+					$board_query = '0=1';
819
+		} else {
820
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
821
+		}
782 822
 	}
783 823
 
784 824
 	// What boards are they the moderator of?
@@ -793,8 +833,9 @@  discard block
 block discarded – undo
793 833
 				'current_member' => $user_info['id'],
794 834
 			)
795 835
 		);
796
-		while ($row = $smcFunc['db_fetch_assoc']($request))
797
-			$boards_mod[] = $row['id_board'];
836
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
837
+					$boards_mod[] = $row['id_board'];
838
+		}
798 839
 		$smcFunc['db_free_result']($request);
799 840
 
800 841
 		// Can any of the groups they're in moderate any of the boards?
@@ -806,8 +847,9 @@  discard block
 block discarded – undo
806 847
 				'groups' => $user_info['groups'],
807 848
 			)
808 849
 		);
809
-		while ($row = $smcFunc['db_fetch_assoc']($request))
810
-			$boards_mod[] = $row['id_board'];
850
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
851
+					$boards_mod[] = $row['id_board'];
852
+		}
811 853
 		$smcFunc['db_free_result']($request);
812 854
 
813 855
 		// Just in case we've got duplicates here...
@@ -852,10 +894,12 @@  discard block
 block discarded – undo
852 894
 	global $modSettings;
853 895
 
854 896
 	// In case a customization wants to override the default settings
855
-	if ($httponly === null)
856
-		$httponly = !empty($modSettings['httponlyCookies']);
857
-	if ($secure === null)
858
-		$secure = !empty($modSettings['secureCookies']);
897
+	if ($httponly === null) {
898
+			$httponly = !empty($modSettings['httponlyCookies']);
899
+	}
900
+	if ($secure === null) {
901
+			$secure = !empty($modSettings['secureCookies']);
902
+	}
859 903
 
860 904
 	// Intercept cookie?
861 905
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -875,8 +919,9 @@  discard block
 block discarded – undo
875 919
 function hash_password($username, $password, $cost = null)
876 920
 {
877 921
 	global $sourcedir, $smcFunc, $modSettings;
878
-	if (!function_exists('password_hash'))
879
-		require_once($sourcedir . '/Subs-Password.php');
922
+	if (!function_exists('password_hash')) {
923
+			require_once($sourcedir . '/Subs-Password.php');
924
+	}
880 925
 
881 926
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
882 927
 
@@ -908,8 +953,9 @@  discard block
 block discarded – undo
908 953
 function hash_verify_password($username, $password, $hash)
909 954
 {
910 955
 	global $sourcedir, $smcFunc;
911
-	if (!function_exists('password_verify'))
912
-		require_once($sourcedir . '/Subs-Password.php');
956
+	if (!function_exists('password_verify')) {
957
+			require_once($sourcedir . '/Subs-Password.php');
958
+	}
913 959
 
914 960
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
915 961
 }
Please login to merge, or discard this patch.
Sources/Display.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -899,13 +899,13 @@
 block discarded – undo
899 899
 		if ($start_char === 'C')
900 900
 			$limit_seek = $limit;
901 901
 		else
902
-			$limit_seek  = $limit + 1;
902
+			$limit_seek = $limit + 1;
903 903
 
904 904
 		$request = $smcFunc['db_query']('', '
905 905
 			SELECT id_msg, id_member, approved
906 906
 			FROM {db_prefix}messages
907 907
 			WHERE id_topic = {int:current_topic}
908
-			AND id_msg '. $page_operator . ' {int:page_id}'. (!$modSettings['postmod_active'] || $approve_posts ? '' : '
908
+			AND id_msg '. $page_operator . ' {int:page_id}' . (!$modSettings['postmod_active'] || $approve_posts ? '' : '
909 909
 			AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
910 910
 			ORDER BY id_msg ' . ($ascending_seek ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
911 911
 			LIMIT {int:limit}'),
Please login to merge, or discard this patch.
Braces   +292 added lines, -214 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
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct the page index, allowing for the .START method...
445 457
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -476,8 +488,9 @@  discard block
 block discarded – undo
476 488
 			$_REQUEST['start'] = 0;
477 489
 		}
478 490
 		// They aren't using it, but the *option* is there, at least.
479
-		else
480
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
491
+		else {
492
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
493
+		}
481 494
 	}
482 495
 
483 496
 	// Build the link tree.
@@ -493,14 +506,16 @@  discard block
 block discarded – undo
493 506
 	if (!empty($board_info['moderators']))
494 507
 	{
495 508
 		// Add a link for each moderator...
496
-		foreach ($board_info['moderators'] as $mod)
497
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
509
+		foreach ($board_info['moderators'] as $mod) {
510
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
511
+		}
498 512
 	}
499 513
 	if (!empty($board_info['moderator_groups']))
500 514
 	{
501 515
 		// Add a link for each moderator group as well...
502
-		foreach ($board_info['moderator_groups'] as $mod_group)
503
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
516
+		foreach ($board_info['moderator_groups'] as $mod_group) {
517
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
518
+		}
504 519
 	}
505 520
 
506 521
 	if (!empty($context['link_moderators']))
@@ -531,9 +546,9 @@  discard block
 block discarded – undo
531 546
 	// For quick reply we need a response prefix in the default forum language.
532 547
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
533 548
 	{
534
-		if ($language === $user_info['language'])
535
-			$context['response_prefix'] = $txt['response_prefix'];
536
-		else
549
+		if ($language === $user_info['language']) {
550
+					$context['response_prefix'] = $txt['response_prefix'];
551
+		} else
537 552
 		{
538 553
 			loadLanguage('index', $language, false);
539 554
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -565,8 +580,9 @@  discard block
 block discarded – undo
565 580
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
566 581
 
567 582
 			// Sanity check
568
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
569
-				continue;
583
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
584
+							continue;
585
+			}
570 586
 
571 587
 			$linked_calendar_event = array(
572 588
 				'id' => $row['id_event'],
@@ -615,8 +631,9 @@  discard block
 block discarded – undo
615 631
 		}
616 632
 		$smcFunc['db_free_result']($request);
617 633
 
618
-		if (!empty($context['linked_calendar_events']))
619
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
634
+		if (!empty($context['linked_calendar_events'])) {
635
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
636
+		}
620 637
 	}
621 638
 
622 639
 	// Create the poll info if it exists.
@@ -679,8 +696,9 @@  discard block
 block discarded – undo
679 696
 		$smcFunc['db_free_result']($request);
680 697
 
681 698
 		// Got we multi choice?
682
-		if ($pollinfo['max_votes'] > 1)
683
-			$realtotal = $pollinfo['total'];
699
+		if ($pollinfo['max_votes'] > 1) {
700
+					$realtotal = $pollinfo['total'];
701
+		}
684 702
 
685 703
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
686 704
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -693,20 +711,21 @@  discard block
 block discarded – undo
693 711
 				foreach ($guestinfo as $i => $guestvoted)
694 712
 				{
695 713
 					$guestvoted = explode(',', $guestvoted);
696
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
697
-						break;
714
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
715
+											break;
716
+					}
698 717
 				}
699 718
 				// Has the poll been reset since guest voted?
700 719
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
701 720
 				{
702 721
 					// Remove the poll info from the cookie to allow guest to vote again
703 722
 					unset($guestinfo[$i]);
704
-					if (!empty($guestinfo))
705
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
706
-					else
707
-						unset($_COOKIE['guest_poll_vote']);
708
-				}
709
-				else
723
+					if (!empty($guestinfo)) {
724
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
725
+					} else {
726
+											unset($_COOKIE['guest_poll_vote']);
727
+					}
728
+				} else
710 729
 				{
711 730
 					// What did they vote for?
712 731
 					unset($guestvoted[0], $guestvoted[1]);
@@ -820,23 +839,29 @@  discard block
 block discarded – undo
820 839
 		// Build the poll moderation button array.
821 840
 		$context['poll_buttons'] = array();
822 841
 
823
-		if ($context['allow_return_vote'])
824
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
842
+		if ($context['allow_return_vote']) {
843
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
844
+		}
825 845
 
826
-		if ($context['show_view_results_button'])
827
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
846
+		if ($context['show_view_results_button']) {
847
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
848
+		}
828 849
 
829
-		if ($context['allow_change_vote'])
830
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
850
+		if ($context['allow_change_vote']) {
851
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
852
+		}
831 853
 
832
-		if ($context['allow_lock_poll'])
833
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
854
+		if ($context['allow_lock_poll']) {
855
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
856
+		}
834 857
 
835
-		if ($context['allow_edit_poll'])
836
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
858
+		if ($context['allow_edit_poll']) {
859
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		}
837 861
 
838
-		if ($context['can_remove_poll'])
839
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
862
+		if ($context['can_remove_poll']) {
863
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
864
+		}
840 865
 
841 866
 		// Allow mods to add additional buttons here
842 867
 		call_integration_hook('integrate_poll_buttons');
@@ -872,9 +897,9 @@  discard block
 block discarded – undo
872 897
 	{
873 898
 		$start_char = 'C';
874 899
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
900
+	} else {
901
+			$start_char = null;
875 902
 	}
876
-	else
877
-		$start_char = null;
878 903
 
879 904
 	$limit = $context['messages_per_page'];
880 905
 
@@ -888,17 +913,17 @@  discard block
 block discarded – undo
888 913
 		{
889 914
 			$ascending_seek = true;
890 915
 			$page_operator = $ascending ? '>=' : '<=';
891
-		}
892
-		else
916
+		} else
893 917
 		{
894 918
 			$ascending_seek = false;
895 919
 			$page_operator = $ascending ? '<=' : '>=';
896 920
 		}
897 921
 
898
-		if ($start_char === 'C')
899
-			$limit_seek = $limit;
900
-		else
901
-			$limit_seek  = $limit + 1;
922
+		if ($start_char === 'C') {
923
+					$limit_seek = $limit;
924
+		} else {
925
+					$limit_seek  = $limit + 1;
926
+		}
902 927
 
903 928
 		$request = $smcFunc['db_query']('', '
904 929
 			SELECT id_msg, id_member, approved
@@ -921,21 +946,23 @@  discard block
 block discarded – undo
921 946
 		$found_msg = false;
922 947
 
923 948
 		// Fallback
924
-		if ($smcFunc['db_num_rows']($request) < 1)
925
-			unset($start_char);
926
-		else
949
+		if ($smcFunc['db_num_rows']($request) < 1) {
950
+					unset($start_char);
951
+		} else
927 952
 		{
928 953
 			while ($row = $smcFunc['db_fetch_assoc']($request))
929 954
 			{
930 955
 				// Check if the start msg is in our result
931
-				if ($row['id_msg'] == $page_id)
932
-					$found_msg = true;
956
+				if ($row['id_msg'] == $page_id) {
957
+									$found_msg = true;
958
+				}
933 959
 
934 960
 				// Skip the the start msg if we not in mode C
935 961
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
936 962
 				{
937
-					if (!empty($row['id_member']))
938
-						$all_posters[$row['id_msg']] = $row['id_member'];
963
+					if (!empty($row['id_member'])) {
964
+											$all_posters[$row['id_msg']] = $row['id_member'];
965
+					}
939 966
 
940 967
 					$messages[] = $row['id_msg'];
941 968
 				}
@@ -951,8 +978,9 @@  discard block
 block discarded – undo
951 978
 		}
952 979
 
953 980
 		// Before Page bring in the right order
954
-		if (!empty($start_char) && $start_char === 'L')
955
-			krsort($messages);
981
+		if (!empty($start_char) && $start_char === 'L') {
982
+					krsort($messages);
983
+		}
956 984
 	}
957 985
 
958 986
 	// Jump to page
@@ -987,14 +1015,16 @@  discard block
 block discarded – undo
987 1015
 
988 1016
 		while ($row = $smcFunc['db_fetch_assoc']($request))
989 1017
 		{
990
-			if (!empty($row['id_member']))
991
-				$all_posters[$row['id_msg']] = $row['id_member'];
1018
+			if (!empty($row['id_member'])) {
1019
+							$all_posters[$row['id_msg']] = $row['id_member'];
1020
+			}
992 1021
 			$messages[] = $row['id_msg'];
993 1022
 		}
994 1023
 
995 1024
 		// Sort the messages into the correct display order
996
-		if (!$ascending)
997
-			sort($messages);
1025
+		if (!$ascending) {
1026
+					sort($messages);
1027
+		}
998 1028
 	}
999 1029
 
1000 1030
 	// Remember the paging data for next time
@@ -1014,8 +1044,9 @@  discard block
 block discarded – undo
1014 1044
 	if (!$user_info['is_guest'] && !empty($messages))
1015 1045
 	{
1016 1046
 		$mark_at_msg = max($messages);
1017
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1018
-			$mark_at_msg = $modSettings['maxMsgID'];
1047
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1048
+					$mark_at_msg = $modSettings['maxMsgID'];
1049
+		}
1019 1050
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1020 1051
 		{
1021 1052
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1047,8 +1078,9 @@  discard block
 block discarded – undo
1047 1078
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1048 1079
 		{
1049 1080
 			// Find if this topic is marked for notification...
1050
-			if (!empty($row['id_topic']))
1051
-				$context['is_marked_notify'] = true;
1081
+			if (!empty($row['id_topic'])) {
1082
+							$context['is_marked_notify'] = true;
1083
+			}
1052 1084
 
1053 1085
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1054 1086
 			if (!empty($row['sent']) && $do_once)
@@ -1070,8 +1102,9 @@  discard block
 block discarded – undo
1070 1102
 		}
1071 1103
 
1072 1104
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1073
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1074
-			$_SESSION['topicseen_cache'][$board]--;
1105
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1106
+					$_SESSION['topicseen_cache'][$board]--;
1107
+		}
1075 1108
 		// Mark board as seen if this is the only new topic.
1076 1109
 		elseif (isset($_REQUEST['topicseen']))
1077 1110
 		{
@@ -1095,14 +1128,16 @@  discard block
 block discarded – undo
1095 1128
 			$smcFunc['db_free_result']($request);
1096 1129
 
1097 1130
 			// If there're no real new topics in this board, mark the board as seen.
1098
-			if (empty($numNewTopics))
1099
-				$_REQUEST['boardseen'] = true;
1100
-			else
1101
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1131
+			if (empty($numNewTopics)) {
1132
+							$_REQUEST['boardseen'] = true;
1133
+			} else {
1134
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1135
+			}
1102 1136
 		}
1103 1137
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1104
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1105
-			$_SESSION['topicseen_cache'][$board]--;
1138
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1139
+					$_SESSION['topicseen_cache'][$board]--;
1140
+		}
1106 1141
 
1107 1142
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1108 1143
 		if (isset($_REQUEST['boardseen']))
@@ -1159,23 +1194,26 @@  discard block
 block discarded – undo
1159 1194
 			$temp = array();
1160 1195
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1161 1196
 			{
1162
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1163
-					continue;
1197
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1198
+									continue;
1199
+				}
1164 1200
 
1165 1201
 				$temp[$row['id_attach']] = $row;
1166 1202
 				$temp[$row['id_attach']]['topic'] = $topic;
1167 1203
 				$temp[$row['id_attach']]['board'] = $board;
1168 1204
 
1169
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1170
-					$context['loaded_attachments'][$row['id_msg']] = array();
1205
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1206
+									$context['loaded_attachments'][$row['id_msg']] = array();
1207
+				}
1171 1208
 			}
1172 1209
 			$smcFunc['db_free_result']($request);
1173 1210
 
1174 1211
 			// This is better than sorting it with the query...
1175 1212
 			ksort($temp);
1176 1213
 
1177
-			foreach ($temp as $row)
1178
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1214
+			foreach ($temp as $row) {
1215
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1216
+			}
1179 1217
 		}
1180 1218
 
1181 1219
 		$msg_parameters = array(
@@ -1202,21 +1240,23 @@  discard block
 block discarded – undo
1202 1240
 		);
1203 1241
 
1204 1242
 		// And the likes
1205
-		if (!empty($modSettings['enable_likes']))
1206
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1243
+		if (!empty($modSettings['enable_likes'])) {
1244
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1245
+		}
1207 1246
 
1208 1247
 		// Go to the last message if the given time is beyond the time of the last message.
1209
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1210
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1248
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1249
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1250
+		}
1211 1251
 
1212 1252
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1213 1253
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1214
-		if (empty($options['view_newest_first']))
1215
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1216
-		else
1217
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1218
-	}
1219
-	else
1254
+		if (empty($options['view_newest_first'])) {
1255
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1256
+		} else {
1257
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1258
+		}
1259
+	} else
1220 1260
 	{
1221 1261
 		$messages_request = false;
1222 1262
 		$context['first_message'] = 0;
@@ -1251,8 +1291,9 @@  discard block
 block discarded – undo
1251 1291
 		'can_restore_msg' => 'move_any',
1252 1292
 		'can_like' => 'likes_like',
1253 1293
 	);
1254
-	foreach ($common_permissions as $contextual => $perm)
1255
-		$context[$contextual] = allowedTo($perm);
1294
+	foreach ($common_permissions as $contextual => $perm) {
1295
+			$context[$contextual] = allowedTo($perm);
1296
+	}
1256 1297
 
1257 1298
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1258 1299
 	$anyown_permissions = array(
@@ -1265,8 +1306,9 @@  discard block
 block discarded – undo
1265 1306
 		'can_reply_unapproved' => 'post_unapproved_replies',
1266 1307
 		'can_view_warning' => 'profile_warning',
1267 1308
 	);
1268
-	foreach ($anyown_permissions as $contextual => $perm)
1269
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1309
+	foreach ($anyown_permissions as $contextual => $perm) {
1310
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1311
+	}
1270 1312
 
1271 1313
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1272 1314
 	{
@@ -1312,8 +1354,9 @@  discard block
 block discarded – undo
1312 1354
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1313 1355
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1314 1356
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1315
-	if (!empty($context['drafts_save']))
1316
-		loadLanguage('Drafts');
1357
+	if (!empty($context['drafts_save'])) {
1358
+			loadLanguage('Drafts');
1359
+	}
1317 1360
 
1318 1361
 	// When was the last time this topic was replied to?  Should we warn them about it?
1319 1362
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1374,26 +1417,31 @@  discard block
 block discarded – undo
1374 1417
 	// Message icons - customized icons are off?
1375 1418
 	$context['icons'] = getMessageIcons($board);
1376 1419
 
1377
-	if (!empty($context['icons']))
1378
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1420
+	if (!empty($context['icons'])) {
1421
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1422
+	}
1379 1423
 
1380 1424
 	// Build the normal button array.
1381 1425
 	$context['normal_buttons'] = array();
1382 1426
 
1383
-	if ($context['can_reply'])
1384
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1427
+	if ($context['can_reply']) {
1428
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1429
+	}
1385 1430
 
1386
-	if ($context['can_add_poll'])
1387
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1431
+	if ($context['can_add_poll']) {
1432
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1433
+	}
1388 1434
 
1389
-	if ($context['can_mark_unread'])
1390
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1435
+	if ($context['can_mark_unread']) {
1436
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1437
+	}
1391 1438
 
1392
-	if ($context['can_print'])
1393
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1439
+	if ($context['can_print']) {
1440
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1441
+	}
1394 1442
 
1395
-	if ($context['can_set_notify'])
1396
-		$context['normal_buttons']['notify'] = array(
1443
+	if ($context['can_set_notify']) {
1444
+			$context['normal_buttons']['notify'] = array(
1397 1445
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1398 1446
 			'sub_buttons' => array(
1399 1447
 				array(
@@ -1415,38 +1463,47 @@  discard block
 block discarded – undo
1415 1463
 				),
1416 1464
 			),
1417 1465
 		);
1466
+	}
1418 1467
 
1419 1468
 	// Build the mod button array
1420 1469
 	$context['mod_buttons'] = array();
1421 1470
 
1422
-	if ($context['can_move'])
1423
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1471
+	if ($context['can_move']) {
1472
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1473
+	}
1424 1474
 
1425
-	if ($context['can_delete'])
1426
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1475
+	if ($context['can_delete']) {
1476
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1477
+	}
1427 1478
 
1428
-	if ($context['can_lock'])
1429
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1479
+	if ($context['can_lock']) {
1480
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1481
+	}
1430 1482
 
1431
-	if ($context['can_sticky'])
1432
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1483
+	if ($context['can_sticky']) {
1484
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1485
+	}
1433 1486
 
1434
-	if ($context['can_merge'])
1435
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1487
+	if ($context['can_merge']) {
1488
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1489
+	}
1436 1490
 
1437
-	if ($context['calendar_post'])
1438
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1491
+	if ($context['calendar_post']) {
1492
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1493
+	}
1439 1494
 
1440 1495
 	// Restore topic. eh?  No monkey business.
1441
-	if ($context['can_restore_topic'])
1442
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1496
+	if ($context['can_restore_topic']) {
1497
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1498
+	}
1443 1499
 
1444 1500
 	// Show a message in case a recently posted message became unapproved.
1445 1501
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1446 1502
 
1447 1503
 	// Don't want to show this forever...
1448
-	if ($context['becomesUnapproved'])
1449
-		unset($_SESSION['becomesUnapproved']);
1504
+	if ($context['becomesUnapproved']) {
1505
+			unset($_SESSION['becomesUnapproved']);
1506
+	}
1450 1507
 
1451 1508
 	// Allow adding new mod buttons easily.
1452 1509
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1455,12 +1512,14 @@  discard block
 block discarded – undo
1455 1512
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1456 1513
 
1457 1514
 	// Load the drafts js file
1458
-	if ($context['drafts_autosave'])
1459
-		loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1515
+	if ($context['drafts_autosave']) {
1516
+			loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1517
+	}
1460 1518
 
1461 1519
 	// Spellcheck
1462
-	if ($context['show_spellchecking'])
1463
-		loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1520
+	if ($context['show_spellchecking']) {
1521
+			loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1522
+	}
1464 1523
 
1465 1524
 	// topic.js
1466 1525
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -1494,16 +1553,19 @@  discard block
 block discarded – undo
1494 1553
 	static $counter = null;
1495 1554
 
1496 1555
 	// If the query returned false, bail.
1497
-	if ($messages_request == false)
1498
-		return false;
1556
+	if ($messages_request == false) {
1557
+			return false;
1558
+	}
1499 1559
 
1500 1560
 	// Remember which message this is.  (ie. reply #83)
1501
-	if ($counter === null || $reset)
1502
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1561
+	if ($counter === null || $reset) {
1562
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1563
+	}
1503 1564
 
1504 1565
 	// Start from the beginning...
1505
-	if ($reset)
1506
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1566
+	if ($reset) {
1567
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1568
+	}
1507 1569
 
1508 1570
 	// Attempt to get the next message.
1509 1571
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1517,19 +1579,21 @@  discard block
 block discarded – undo
1517 1579
 	if (empty($context['icon_sources']))
1518 1580
 	{
1519 1581
 		$context['icon_sources'] = array();
1520
-		foreach ($context['stable_icons'] as $icon)
1521
-			$context['icon_sources'][$icon] = 'images_url';
1582
+		foreach ($context['stable_icons'] as $icon) {
1583
+					$context['icon_sources'][$icon] = 'images_url';
1584
+		}
1522 1585
 	}
1523 1586
 
1524 1587
 	// Message Icon Management... check the images exist.
1525 1588
 	if (empty($modSettings['messageIconChecks_disable']))
1526 1589
 	{
1527 1590
 		// If the current icon isn't known, then we need to do something...
1528
-		if (!isset($context['icon_sources'][$message['icon']]))
1529
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1591
+		if (!isset($context['icon_sources'][$message['icon']])) {
1592
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1593
+		}
1594
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1595
+			$context['icon_sources'][$message['icon']] = 'images_url';
1530 1596
 	}
1531
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1532
-		$context['icon_sources'][$message['icon']] = 'images_url';
1533 1597
 
1534 1598
 	// If you're a lazy bum, you probably didn't give a subject...
1535 1599
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1554,8 +1618,7 @@  discard block
 block discarded – undo
1554 1618
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1555 1619
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1556 1620
 		$memberContext[$message['id_member']]['is_guest'] = true;
1557
-	}
1558
-	else
1621
+	} else
1559 1622
 	{
1560 1623
 		// Define this here to make things a bit more readable
1561 1624
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1578,8 +1641,9 @@  discard block
 block discarded – undo
1578 1641
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1579 1642
 
1580 1643
 	// If it's in the recycle bin we need to override whatever icon we did have.
1581
-	if (!empty($board_info['recycle']))
1582
-		$message['icon'] = 'recycled';
1644
+	if (!empty($board_info['recycle'])) {
1645
+			$message['icon'] = 'recycled';
1646
+	}
1583 1647
 
1584 1648
 	require_once($sourcedir . '/Subs-Attachments.php');
1585 1649
 
@@ -1623,32 +1687,36 @@  discard block
 block discarded – undo
1623 1687
 	}
1624 1688
 
1625 1689
 	// Are likes enable?
1626
-	if (!empty($modSettings['enable_likes']))
1627
-		$output['likes'] = array(
1690
+	if (!empty($modSettings['enable_likes'])) {
1691
+			$output['likes'] = array(
1628 1692
 			'count' => $message['likes'],
1629 1693
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1630 1694
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1631 1695
 		);
1696
+	}
1632 1697
 
1633 1698
 	// Is this user the message author?
1634 1699
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1635
-	if (!empty($output['modified']['name']))
1636
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1700
+	if (!empty($output['modified']['name'])) {
1701
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1702
+	}
1637 1703
 
1638 1704
 	// Did they give a reason for editing?
1639
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1640
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1705
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1706
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1707
+	}
1641 1708
 
1642 1709
 	// Any custom profile fields?
1643
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1644
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1710
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1711
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1645 1712
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1713
+	}
1646 1714
 
1647
-	if (empty($options['view_newest_first']))
1648
-		$counter++;
1649
-
1650
-	else
1651
-		$counter--;
1715
+	if (empty($options['view_newest_first'])) {
1716
+			$counter++;
1717
+	} else {
1718
+			$counter--;
1719
+	}
1652 1720
 
1653 1721
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1654 1722
 
@@ -1674,8 +1742,9 @@  discard block
 block discarded – undo
1674 1742
  */
1675 1743
 function approved_attach_sort($a, $b)
1676 1744
 {
1677
-	if ($a['is_approved'] == $b['is_approved'])
1678
-		return 0;
1745
+	if ($a['is_approved'] == $b['is_approved']) {
1746
+			return 0;
1747
+	}
1679 1748
 
1680 1749
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1681 1750
 }
@@ -1692,16 +1761,19 @@  discard block
 block discarded – undo
1692 1761
 
1693 1762
 	require_once($sourcedir . '/RemoveTopic.php');
1694 1763
 
1695
-	if (empty($_REQUEST['msgs']))
1696
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1764
+	if (empty($_REQUEST['msgs'])) {
1765
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1766
+	}
1697 1767
 
1698 1768
 	$messages = array();
1699
-	foreach ($_REQUEST['msgs'] as $dummy)
1700
-		$messages[] = (int) $dummy;
1769
+	foreach ($_REQUEST['msgs'] as $dummy) {
1770
+			$messages[] = (int) $dummy;
1771
+	}
1701 1772
 
1702 1773
 	// We are restoring messages. We handle this in another place.
1703
-	if (isset($_REQUEST['restore_selected']))
1704
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1774
+	if (isset($_REQUEST['restore_selected'])) {
1775
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1776
+	}
1705 1777
 	if (isset($_REQUEST['split_selection']))
1706 1778
 	{
1707 1779
 		$request = $smcFunc['db_query']('', '
@@ -1720,8 +1792,9 @@  discard block
 block discarded – undo
1720 1792
 	}
1721 1793
 
1722 1794
 	// Allowed to delete any message?
1723
-	if (allowedTo('delete_any'))
1724
-		$allowed_all = true;
1795
+	if (allowedTo('delete_any')) {
1796
+			$allowed_all = true;
1797
+	}
1725 1798
 	// Allowed to delete replies to their messages?
1726 1799
 	elseif (allowedTo('delete_replies'))
1727 1800
 	{
@@ -1738,13 +1811,14 @@  discard block
 block discarded – undo
1738 1811
 		$smcFunc['db_free_result']($request);
1739 1812
 
1740 1813
 		$allowed_all = $starter == $user_info['id'];
1814
+	} else {
1815
+			$allowed_all = false;
1741 1816
 	}
1742
-	else
1743
-		$allowed_all = false;
1744 1817
 
1745 1818
 	// Make sure they're allowed to delete their own messages, if not any.
1746
-	if (!$allowed_all)
1747
-		isAllowedTo('delete_own');
1819
+	if (!$allowed_all) {
1820
+			isAllowedTo('delete_own');
1821
+	}
1748 1822
 
1749 1823
 	// Allowed to remove which messages?
1750 1824
 	$request = $smcFunc['db_query']('', '
@@ -1764,8 +1838,9 @@  discard block
 block discarded – undo
1764 1838
 	$messages = array();
1765 1839
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1766 1840
 	{
1767
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1768
-			continue;
1841
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1842
+					continue;
1843
+		}
1769 1844
 
1770 1845
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1771 1846
 	}
@@ -1788,17 +1863,20 @@  discard block
 block discarded – undo
1788 1863
 	foreach ($messages as $message => $info)
1789 1864
 	{
1790 1865
 		// Just skip the first message - if it's not the last.
1791
-		if ($message == $first_message && $message != $last_message)
1792
-			continue;
1866
+		if ($message == $first_message && $message != $last_message) {
1867
+					continue;
1868
+		}
1793 1869
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1794
-		elseif ($message == $first_message)
1795
-			$topicGone = true;
1870
+		elseif ($message == $first_message) {
1871
+					$topicGone = true;
1872
+		}
1796 1873
 
1797 1874
 		removeMessage($message);
1798 1875
 
1799 1876
 		// Log this moderation action ;).
1800
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1801
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1877
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1878
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1879
+		}
1802 1880
 	}
1803 1881
 
1804 1882
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Smileys/alienine/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 		
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
Please login to merge, or discard this patch.
Sources/Themes.php 1 patch
Braces   +348 added lines, -271 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 4
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -581,13 +593,13 @@  discard block
 block discarded – undo
581 593
 			)
582 594
 		);
583 595
 		$context['theme_options'] = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$context['theme_options'][$row['variable']] = $row['value'];
596
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
597
+					$context['theme_options'][$row['variable']] = $row['value'];
598
+		}
586 599
 		$smcFunc['db_free_result']($request);
587 600
 
588 601
 		$context['theme_options_reset'] = false;
589
-	}
590
-	else
602
+	} else
591 603
 	{
592 604
 		$context['theme_options'] = array();
593 605
 		$context['theme_options_reset'] = true;
@@ -596,30 +608,32 @@  discard block
 block discarded – undo
596 608
 	foreach ($context['options'] as $i => $setting)
597 609
 	{
598 610
 		// Just skip separators
599
-		if (!is_array($setting))
600
-			continue;
611
+		if (!is_array($setting)) {
612
+					continue;
613
+		}
601 614
 
602 615
 		// Is this disabled?
603 616
 		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
604 617
 		{
605 618
 			unset($context['options'][$i]);
606 619
 			continue;
607
-		}
608
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
620
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
609 621
 		{
610 622
 			unset($context['options'][$i]);
611 623
 			continue;
612 624
 		}
613 625
 
614
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
615
-			$context['options'][$i]['type'] = 'checkbox';
616
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
617
-			$context['options'][$i]['type'] = 'number';
618
-		elseif ($setting['type'] == 'string')
619
-			$context['options'][$i]['type'] = 'text';
626
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
627
+					$context['options'][$i]['type'] = 'checkbox';
628
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
629
+					$context['options'][$i]['type'] = 'number';
630
+		} elseif ($setting['type'] == 'string') {
631
+					$context['options'][$i]['type'] = 'text';
632
+		}
620 633
 
621
-		if (isset($setting['options']))
622
-			$context['options'][$i]['type'] = 'list';
634
+		if (isset($setting['options'])) {
635
+					$context['options'][$i]['type'] = 'list';
636
+		}
623 637
 
624 638
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
625 639
 	}
@@ -644,8 +658,9 @@  discard block
 block discarded – undo
644 658
 {
645 659
 	global $txt, $context, $settings, $modSettings, $smcFunc;
646 660
 
647
-	if (empty($_GET['th']) && empty($_GET['id']))
648
-		return ThemeAdmin();
661
+	if (empty($_GET['th']) && empty($_GET['id'])) {
662
+			return ThemeAdmin();
663
+	}
649 664
 
650 665
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
651 666
 
@@ -656,8 +671,9 @@  discard block
 block discarded – undo
656 671
 	isAllowedTo('admin_forum');
657 672
 
658 673
 	// Validate inputs/user.
659
-	if (empty($_GET['th']))
660
-		fatal_lang_error('no_theme', false);
674
+	if (empty($_GET['th'])) {
675
+			fatal_lang_error('no_theme', false);
676
+	}
661 677
 
662 678
 	// Fetch the smiley sets...
663 679
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -665,8 +681,9 @@  discard block
 block discarded – undo
665 681
 	$context['smiley_sets'] = array(
666 682
 		'' => $txt['smileys_no_default']
667 683
 	);
668
-	foreach ($sets as $i => $set)
669
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
684
+	foreach ($sets as $i => $set) {
685
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
686
+	}
670 687
 
671 688
 	$old_id = $settings['theme_id'];
672 689
 	$old_settings = $settings;
@@ -691,8 +708,9 @@  discard block
 block discarded – undo
691 708
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
692 709
 	{
693 710
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
694
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
695
-				eval('global $settings;' . $matches[0]);
711
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
712
+						eval('global $settings;' . $matches[0]);
713
+		}
696 714
 	}
697 715
 
698 716
 	// Let mods hook into the theme settings.
@@ -704,37 +722,45 @@  discard block
 block discarded – undo
704 722
 		checkSession();
705 723
 		validateToken('admin-sts');
706 724
 
707
-		if (empty($_POST['options']))
708
-			$_POST['options'] = array();
709
-		if (empty($_POST['default_options']))
710
-			$_POST['default_options'] = array();
725
+		if (empty($_POST['options'])) {
726
+					$_POST['options'] = array();
727
+		}
728
+		if (empty($_POST['default_options'])) {
729
+					$_POST['default_options'] = array();
730
+		}
711 731
 
712 732
 		// Make sure items are cast correctly.
713 733
 		foreach ($context['theme_settings'] as $item)
714 734
 		{
715 735
 			// Disregard this item if this is just a separator.
716
-			if (!is_array($item))
717
-				continue;
736
+			if (!is_array($item)) {
737
+							continue;
738
+			}
718 739
 
719 740
 			foreach (array('options', 'default_options') as $option)
720 741
 			{
721
-				if (!isset($_POST[$option][$item['id']]))
722
-					continue;
742
+				if (!isset($_POST[$option][$item['id']])) {
743
+									continue;
744
+				}
723 745
 				// Checkbox.
724
-				elseif (empty($item['type']))
725
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
746
+				elseif (empty($item['type'])) {
747
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
748
+				}
726 749
 				// Number
727
-				elseif ($item['type'] == 'number')
728
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
750
+				elseif ($item['type'] == 'number') {
751
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
752
+				}
729 753
 			}
730 754
 		}
731 755
 
732 756
 		// Set up the sql query.
733 757
 		$inserts = array();
734
-		foreach ($_POST['options'] as $opt => $val)
735
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
736
-		foreach ($_POST['default_options'] as $opt => $val)
737
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
758
+		foreach ($_POST['options'] as $opt => $val) {
759
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
760
+		}
761
+		foreach ($_POST['default_options'] as $opt => $val) {
762
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
763
+		}
738 764
 		// If we're actually inserting something..
739 765
 		if (!empty($inserts))
740 766
 		{
@@ -760,8 +786,9 @@  discard block
 block discarded – undo
760 786
 
761 787
 	foreach ($settings as $setting => $dummy)
762 788
 	{
763
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
764
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
789
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
790
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
791
+		}
765 792
 	}
766 793
 
767 794
 	$context['settings'] = $context['theme_settings'];
@@ -770,18 +797,21 @@  discard block
 block discarded – undo
770 797
 	foreach ($context['settings'] as $i => $setting)
771 798
 	{
772 799
 		// Separators are dummies, so leave them alone.
773
-		if (!is_array($setting))
774
-			continue;
800
+		if (!is_array($setting)) {
801
+					continue;
802
+		}
775 803
 
776
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
777
-			$context['settings'][$i]['type'] = 'checkbox';
778
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
779
-			$context['settings'][$i]['type'] = 'number';
780
-		elseif ($setting['type'] == 'string')
781
-			$context['settings'][$i]['type'] = 'text';
804
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
805
+					$context['settings'][$i]['type'] = 'checkbox';
806
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
807
+					$context['settings'][$i]['type'] = 'number';
808
+		} elseif ($setting['type'] == 'string') {
809
+					$context['settings'][$i]['type'] = 'text';
810
+		}
782 811
 
783
-		if (isset($setting['options']))
784
-			$context['settings'][$i]['type'] = 'list';
812
+		if (isset($setting['options'])) {
813
+					$context['settings'][$i]['type'] = 'list';
814
+		}
785 815
 
786 816
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
787 817
 	}
@@ -834,8 +864,9 @@  discard block
 block discarded – undo
834 864
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
835 865
 
836 866
 	// You can't delete the default theme!
837
-	if ($themeID == 1)
838
-		fatal_lang_error('no_access', false);
867
+	if ($themeID == 1) {
868
+			fatal_lang_error('no_access', false);
869
+	}
839 870
 
840 871
 	$theme_info = get_single_theme($themeID);
841 872
 
@@ -843,8 +874,9 @@  discard block
 block discarded – undo
843 874
 	remove_theme($themeID);
844 875
 
845 876
 	// And remove all its files and folders too.
846
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
847
-		remove_dir($theme_info['theme_dir']);
877
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
878
+			remove_dir($theme_info['theme_dir']);
879
+	}
848 880
 
849 881
 	// Go back to the list page.
850 882
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -869,12 +901,14 @@  discard block
 block discarded – undo
869 901
 	$enableThemes = explode(',', $modSettings['enableThemes']);
870 902
 
871 903
 	// Are we disabling it?
872
-	if (isset($_GET['disabled']))
873
-		$enableThemes = array_diff($enableThemes, array($themeID));
904
+	if (isset($_GET['disabled'])) {
905
+			$enableThemes = array_diff($enableThemes, array($themeID));
906
+	}
874 907
 
875 908
 	// Nope? then enable it!
876
-	else
877
-		$enableThemes[] = (string) $themeID;
909
+	else {
910
+			$enableThemes[] = (string) $themeID;
911
+	}
878 912
 
879 913
 	// Update the setting.
880 914
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -909,18 +943,21 @@  discard block
 block discarded – undo
909 943
 
910 944
 	$_SESSION['id_theme'] = 0;
911 945
 
912
-	if (isset($_GET['id']))
913
-		$_GET['th'] = $_GET['id'];
946
+	if (isset($_GET['id'])) {
947
+			$_GET['th'] = $_GET['id'];
948
+	}
914 949
 
915 950
 	// Saving a variant cause JS doesn't work - pretend it did ;)
916 951
 	if (isset($_POST['save']))
917 952
 	{
918 953
 		// Which theme?
919
-		foreach ($_POST['save'] as $k => $v)
920
-			$_GET['th'] = (int) $k;
954
+		foreach ($_POST['save'] as $k => $v) {
955
+					$_GET['th'] = (int) $k;
956
+		}
921 957
 
922
-		if (isset($_POST['vrt'][$k]))
923
-			$_GET['vrt'] = $_POST['vrt'][$k];
958
+		if (isset($_POST['vrt'][$k])) {
959
+					$_GET['vrt'] = $_POST['vrt'][$k];
960
+		}
924 961
 	}
925 962
 
926 963
 	// Have we made a decision, or are we just browsing?
@@ -998,8 +1035,9 @@  discard block
 block discarded – undo
998 1035
 		else
999 1036
 		{
1000 1037
 			// The forum's default theme is always 0 and we
1001
-			if (isset($_GET['th']) && $_GET['th'] == 0)
1002
-					$_GET['th'] = $modSettings['theme_guests'];
1038
+			if (isset($_GET['th']) && $_GET['th'] == 0) {
1039
+								$_GET['th'] = $modSettings['theme_guests'];
1040
+			}
1003 1041
 
1004 1042
 			updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
1005 1043
 
@@ -1013,8 +1051,9 @@  discard block
 block discarded – undo
1013 1051
 				);
1014 1052
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1015 1053
 
1016
-				if ($user_info['id'] == $_REQUEST['u'])
1017
-					$_SESSION['id_variant'] = 0;
1054
+				if ($user_info['id'] == $_REQUEST['u']) {
1055
+									$_SESSION['id_variant'] = 0;
1056
+				}
1018 1057
 			}
1019 1058
 
1020 1059
 			redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
@@ -1083,12 +1122,13 @@  discard block
 block discarded – undo
1083 1122
 		);
1084 1123
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1085 1124
 		{
1086
-			if (!isset($context['available_themes'][$row['id_theme']]))
1087
-				$context['available_themes'][$row['id_theme']] = array(
1125
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1126
+							$context['available_themes'][$row['id_theme']] = array(
1088 1127
 					'id' => $row['id_theme'],
1089 1128
 					'selected' => $context['current_theme'] == $row['id_theme'],
1090 1129
 					'num_users' => 0
1091 1130
 				);
1131
+			}
1092 1132
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1093 1133
 		}
1094 1134
 		$smcFunc['db_free_result']($request);
@@ -1101,9 +1141,9 @@  discard block
 block discarded – undo
1101 1141
 			'num_users' => 0
1102 1142
 		);
1103 1143
 		$guest_theme = 0;
1144
+	} else {
1145
+			$guest_theme = $modSettings['theme_guests'];
1104 1146
 	}
1105
-	else
1106
-		$guest_theme = $modSettings['theme_guests'];
1107 1147
 
1108 1148
 	$request = $smcFunc['db_query']('', '
1109 1149
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1116,15 +1156,17 @@  discard block
 block discarded – undo
1116 1156
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1117 1157
 	{
1118 1158
 		// Figure out which theme it is they are REALLY using.
1119
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1120
-			$row['id_theme'] = $guest_theme;
1121
-		elseif (empty($modSettings['theme_allow']))
1122
-			$row['id_theme'] = $guest_theme;
1159
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1160
+					$row['id_theme'] = $guest_theme;
1161
+		} elseif (empty($modSettings['theme_allow'])) {
1162
+					$row['id_theme'] = $guest_theme;
1163
+		}
1123 1164
 
1124
-		if (isset($context['available_themes'][$row['id_theme']]))
1125
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1126
-		else
1127
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1165
+		if (isset($context['available_themes'][$row['id_theme']])) {
1166
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1167
+		} else {
1168
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1169
+		}
1128 1170
 	}
1129 1171
 	$smcFunc['db_free_result']($request);
1130 1172
 
@@ -1143,8 +1185,9 @@  discard block
 block discarded – undo
1143 1185
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1144 1186
 			)
1145 1187
 		);
1146
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1147
-			$variant_preferences[$row['id_theme']] = $row['value'];
1188
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1189
+					$variant_preferences[$row['id_theme']] = $row['value'];
1190
+		}
1148 1191
 		$smcFunc['db_free_result']($request);
1149 1192
 	}
1150 1193
 
@@ -1155,17 +1198,18 @@  discard block
 block discarded – undo
1155 1198
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1156 1199
 	{
1157 1200
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1158
-		if ($id_theme == 0)
1159
-			continue;
1201
+		if ($id_theme == 0) {
1202
+					continue;
1203
+		}
1160 1204
 
1161 1205
 		// The thumbnail needs the correct path.
1162 1206
 		$settings['images_url'] = &$theme_data['images_url'];
1163 1207
 
1164
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1165
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1166
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1167
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1168
-		else
1208
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1209
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1210
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1211
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1212
+		} else
1169 1213
 		{
1170 1214
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1171 1215
 			$txt['theme_description'] = '';
@@ -1190,15 +1234,17 @@  discard block
 block discarded – undo
1190 1234
 					loadLanguage('Settings');
1191 1235
 
1192 1236
 					$context['available_themes'][$id_theme]['variants'] = array();
1193
-					foreach ($settings['theme_variants'] as $variant)
1194
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1237
+					foreach ($settings['theme_variants'] as $variant) {
1238
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1195 1239
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1196 1240
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1197 1241
 						);
1242
+					}
1198 1243
 
1199 1244
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1200
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1201
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1245
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1246
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1247
+					}
1202 1248
 
1203 1249
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1204 1250
 					// Allow themes to override the text.
@@ -1214,8 +1260,9 @@  discard block
 block discarded – undo
1214 1260
 	// As long as we're not doing the default theme...
1215 1261
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1216 1262
 	{
1217
-		if ($guest_theme != 0)
1218
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1263
+		if ($guest_theme != 0) {
1264
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1265
+		}
1219 1266
 
1220 1267
 		$context['available_themes'][0]['id'] = 0;
1221 1268
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1264,14 +1311,16 @@  discard block
 block discarded – undo
1264 1311
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1265 1312
 
1266 1313
 		// Got any info from the specific form?
1267
-		if (!isset($_POST['save_' . $action]))
1268
-			fatal_lang_error('theme_install_no_action', false);
1314
+		if (!isset($_POST['save_' . $action])) {
1315
+					fatal_lang_error('theme_install_no_action', false);
1316
+		}
1269 1317
 
1270 1318
 		validateToken('admin-t-' . $action);
1271 1319
 
1272 1320
 		// Hopefully the themes directory is writable, or we might have a problem.
1273
-		if (!is_writable($themedir))
1274
-			fatal_lang_error('theme_install_write_error', 'critical');
1321
+		if (!is_writable($themedir)) {
1322
+					fatal_lang_error('theme_install_write_error', 'critical');
1323
+		}
1275 1324
 
1276 1325
 		// Call the function and handle the result.
1277 1326
 		$result = $subActions[$action]();
@@ -1286,9 +1335,10 @@  discard block
 block discarded – undo
1286 1335
 	}
1287 1336
 
1288 1337
 	// Nope, show a nice error.
1289
-	else
1290
-		fatal_lang_error('theme_install_no_action', false);
1291
-}
1338
+	else {
1339
+			fatal_lang_error('theme_install_no_action', false);
1340
+	}
1341
+	}
1292 1342
 
1293 1343
 /**
1294 1344
  * Installs a theme from a theme package.
@@ -1304,8 +1354,9 @@  discard block
 block discarded – undo
1304 1354
 	$dirtemp = $themedir . '/temp';
1305 1355
 
1306 1356
 	// Make sure the temp dir doesn't already exist
1307
-	if (file_exists($dirtemp))
1308
-		remove_dir($dirtemp);
1357
+	if (file_exists($dirtemp)) {
1358
+			remove_dir($dirtemp);
1359
+	}
1309 1360
 
1310 1361
 	// Create the temp dir.
1311 1362
 	mkdir($dirtemp, 0777);
@@ -1317,17 +1368,20 @@  discard block
 block discarded – undo
1317 1368
 		smf_chmod($dirtemp, '0755');
1318 1369
 
1319 1370
 		// How about now?
1320
-		if (!is_writable($dirtemp))
1321
-			fatal_lang_error('theme_install_write_error', 'critical');
1371
+		if (!is_writable($dirtemp)) {
1372
+					fatal_lang_error('theme_install_write_error', 'critical');
1373
+		}
1322 1374
 	}
1323 1375
 
1324 1376
 	// This happens when the admin session is gone and the user has to login again.
1325
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1326
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1377
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1378
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1379
+	}
1327 1380
 
1328 1381
 	// Another error check layer, something went wrong with the upload.
1329
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1330
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1382
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1383
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1384
+	}
1331 1385
 
1332 1386
 	// Get the theme's name.
1333 1387
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1358,11 +1412,10 @@  discard block
 block discarded – undo
1358 1412
 
1359 1413
 		// return all the info.
1360 1414
 		return $context['to_install'];
1415
+	} else {
1416
+			fatal_lang_error('theme_install_error_title', false);
1417
+	}
1361 1418
 	}
1362
-
1363
-	else
1364
-		fatal_lang_error('theme_install_error_title', false);
1365
-}
1366 1419
 
1367 1420
 /**
1368 1421
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1376,15 +1429,17 @@  discard block
 block discarded – undo
1376 1429
 	global $forum_version;
1377 1430
 
1378 1431
 	// There's gotta be something to work with.
1379
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1380
-		fatal_lang_error('theme_install_error_title', false);
1432
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1433
+			fatal_lang_error('theme_install_error_title', false);
1434
+	}
1381 1435
 
1382 1436
 	// Get a cleaner version.
1383 1437
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1384 1438
 
1385 1439
 	// Is there a theme already named like this?
1386
-	if (file_exists($themedir . '/' . $name))
1387
-		fatal_lang_error('theme_install_already_dir', false);
1440
+	if (file_exists($themedir . '/' . $name)) {
1441
+			fatal_lang_error('theme_install_already_dir', false);
1442
+	}
1388 1443
 
1389 1444
 	// This is a brand new theme so set all possible values.
1390 1445
 	$context['to_install'] = array(
@@ -1404,8 +1459,9 @@  discard block
 block discarded – undo
1404 1459
 
1405 1460
 	// Buy some time.
1406 1461
 	@set_time_limit(600);
1407
-	if (function_exists('apache_reset_timeout'))
1408
-		@apache_reset_timeout();
1462
+	if (function_exists('apache_reset_timeout')) {
1463
+			@apache_reset_timeout();
1464
+	}
1409 1465
 
1410 1466
 	// Create subdirectories for css and javascript files.
1411 1467
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1441,12 +1497,13 @@  discard block
 block discarded – undo
1441 1497
 
1442 1498
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1443 1499
 	{
1444
-		if ($row['variable'] == 'theme_templates')
1445
-			$theme_templates = $row['value'];
1446
-		elseif ($row['variable'] == 'theme_layers')
1447
-			$theme_layers = $row['value'];
1448
-		else
1449
-			continue;
1500
+		if ($row['variable'] == 'theme_templates') {
1501
+					$theme_templates = $row['value'];
1502
+		} elseif ($row['variable'] == 'theme_layers') {
1503
+					$theme_layers = $row['value'];
1504
+		} else {
1505
+					continue;
1506
+		}
1450 1507
 	}
1451 1508
 
1452 1509
 	$smcFunc['db_free_result']($request);
@@ -1505,12 +1562,14 @@  discard block
 block discarded – undo
1505 1562
 	global $themedir, $themeurl, $context;
1506 1563
 
1507 1564
 	// Cannot use the theme dir as a theme dir.
1508
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1509
-		fatal_lang_error('theme_install_invalid_dir', false);
1565
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1566
+			fatal_lang_error('theme_install_invalid_dir', false);
1567
+	}
1510 1568
 
1511 1569
 	// Check is there is "something" on the dir.
1512
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1513
-		fatal_lang_error('theme_install_error', false);
1570
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1571
+			fatal_lang_error('theme_install_error', false);
1572
+	}
1514 1573
 
1515 1574
 	$name = basename($_REQUEST['theme_dir']);
1516 1575
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1554,24 +1613,27 @@  discard block
 block discarded – undo
1554 1613
 	}
1555 1614
 
1556 1615
 	// Any special layers?
1557
-	if (isset($settings['catch_action']['layers']))
1558
-		$context['template_layers'] = $settings['catch_action']['layers'];
1616
+	if (isset($settings['catch_action']['layers'])) {
1617
+			$context['template_layers'] = $settings['catch_action']['layers'];
1618
+	}
1559 1619
 
1560 1620
 	// Any function to call?
1561 1621
 	if (isset($settings['catch_action']['function']))
1562 1622
 	{
1563 1623
 		$hook = $settings['catch_action']['function'];
1564 1624
 
1565
-		if (!isset($settings['catch_action']['filename']))
1566
-			$settings['catch_action']['filename'] = '';
1625
+		if (!isset($settings['catch_action']['filename'])) {
1626
+					$settings['catch_action']['filename'] = '';
1627
+		}
1567 1628
 
1568 1629
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1569 1630
 		call_integration_hook('integrate_wrap_action');
1570 1631
 	}
1571 1632
 	// And finally, the main sub template ;).
1572
-	if (isset($settings['catch_action']['sub_template']))
1573
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1574
-}
1633
+	if (isset($settings['catch_action']['sub_template'])) {
1634
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1635
+	}
1636
+	}
1575 1637
 
1576 1638
 /**
1577 1639
  * Set an option via javascript.
@@ -1590,12 +1652,14 @@  discard block
 block discarded – undo
1590 1652
 	checkSession('get');
1591 1653
 
1592 1654
 	// This good-for-nothing pixel is being used to keep the session alive.
1593
-	if (empty($_GET['var']) || !isset($_GET['val']))
1594
-		redirectexit($settings['images_url'] . '/blank.png');
1655
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1656
+			redirectexit($settings['images_url'] . '/blank.png');
1657
+	}
1595 1658
 
1596 1659
 	// Sorry, guests can't go any further than this.
1597
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1598
-		obExit(false);
1660
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1661
+			obExit(false);
1662
+	}
1599 1663
 
1600 1664
 	$reservedVars = array(
1601 1665
 		'actual_theme_url',
@@ -1618,8 +1682,9 @@  discard block
 block discarded – undo
1618 1682
 	);
1619 1683
 
1620 1684
 	// Can't change reserved vars.
1621
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1622
-		redirectexit($settings['images_url'] . '/blank.png');
1685
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1686
+			redirectexit($settings['images_url'] . '/blank.png');
1687
+	}
1623 1688
 
1624 1689
 	// Use a specific theme?
1625 1690
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1635,8 +1700,9 @@  discard block
 block discarded – undo
1635 1700
 	{
1636 1701
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
1637 1702
 		// New thingy...
1638
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1639
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1703
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1704
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1705
+		}
1640 1706
 
1641 1707
 		// Change the value to be something nice,
1642 1708
 		$_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']);
@@ -1666,8 +1732,9 @@  discard block
 block discarded – undo
1666 1732
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1667 1733
 
1668 1734
 	// @todo Should this be removed?
1669
-	if (isset($_REQUEST['preview']))
1670
-		die('die() with fire');
1735
+	if (isset($_REQUEST['preview'])) {
1736
+			die('die() with fire');
1737
+	}
1671 1738
 
1672 1739
 	isAllowedTo('admin_forum');
1673 1740
 	loadTemplate('Themes');
@@ -1681,11 +1748,11 @@  discard block
 block discarded – undo
1681 1748
 		foreach ($context['themes'] as $key => $theme)
1682 1749
 		{
1683 1750
 			// There has to be a Settings template!
1684
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1685
-				unset($context['themes'][$key]);
1686
-
1687
-			else
1688
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1751
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1752
+							unset($context['themes'][$key]);
1753
+			} else {
1754
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1755
+			}
1689 1756
 		}
1690 1757
 
1691 1758
 		$context['sub_template'] = 'edit_list';
@@ -1700,22 +1767,24 @@  discard block
 block discarded – undo
1700 1767
 	$context['theme_id'] = $currentTheme['id'];
1701 1768
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1702 1769
 
1703
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1704
-		fatal_lang_error('theme_edit_missing', false);
1770
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1771
+			fatal_lang_error('theme_edit_missing', false);
1772
+	}
1705 1773
 
1706 1774
 	if (!isset($_REQUEST['filename']))
1707 1775
 	{
1708 1776
 		if (isset($_GET['directory']))
1709 1777
 		{
1710
-			if (substr($_GET['directory'], 0, 1) == '.')
1711
-				$_GET['directory'] = '';
1712
-			else
1778
+			if (substr($_GET['directory'], 0, 1) == '.') {
1779
+							$_GET['directory'] = '';
1780
+			} else
1713 1781
 			{
1714 1782
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1715 1783
 
1716 1784
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1717
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1718
-					$_GET['directory'] = '';
1785
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1786
+									$_GET['directory'] = '';
1787
+				}
1719 1788
 			}
1720 1789
 		}
1721 1790
 
@@ -1734,37 +1803,39 @@  discard block
 block discarded – undo
1734 1803
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1735 1804
 				'size' => '',
1736 1805
 			));
1806
+		} else {
1807
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1737 1808
 		}
1738
-		else
1739
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1740 1809
 
1741 1810
 		$context['sub_template'] = 'edit_browse';
1742 1811
 
1743 1812
 		return;
1744
-	}
1745
-	else
1813
+	} else
1746 1814
 	{
1747
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1748
-			$_REQUEST['filename'] = '';
1749
-		else
1815
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1816
+					$_REQUEST['filename'] = '';
1817
+		} else
1750 1818
 		{
1751 1819
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1752 1820
 
1753 1821
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1754
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1755
-				$_REQUEST['filename'] = '';
1822
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1823
+							$_REQUEST['filename'] = '';
1824
+			}
1756 1825
 		}
1757 1826
 
1758
-		if (empty($_REQUEST['filename']))
1759
-			fatal_lang_error('theme_edit_missing', false);
1827
+		if (empty($_REQUEST['filename'])) {
1828
+					fatal_lang_error('theme_edit_missing', false);
1829
+		}
1760 1830
 	}
1761 1831
 
1762 1832
 	if (isset($_POST['save']))
1763 1833
 	{
1764 1834
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1765 1835
 		{
1766
-			if (is_array($_POST['entire_file']))
1767
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1836
+			if (is_array($_POST['entire_file'])) {
1837
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1838
+			}
1768 1839
 
1769 1840
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1770 1841
 
@@ -1776,10 +1847,11 @@  discard block
 block discarded – undo
1776 1847
 				fclose($fp);
1777 1848
 
1778 1849
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1779
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1780
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1781
-				else
1782
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1850
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1851
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1852
+				} else {
1853
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1854
+				}
1783 1855
 			}
1784 1856
 
1785 1857
 			if (!isset($error_file))
@@ -1800,10 +1872,11 @@  discard block
 block discarded – undo
1800 1872
 			$context['sub_template'] = 'edit_file';
1801 1873
 
1802 1874
 			// Recycle the submitted data.
1803
-			if (is_array($_POST['entire_file']))
1804
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1805
-			else
1806
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1875
+			if (is_array($_POST['entire_file'])) {
1876
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1877
+			} else {
1878
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1879
+			}
1807 1880
 
1808 1881
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1809 1882
 
@@ -1826,17 +1899,17 @@  discard block
 block discarded – undo
1826 1899
 		$context['sub_template'] = 'edit_style';
1827 1900
 
1828 1901
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1829
-	}
1830
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1902
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1831 1903
 	{
1832 1904
 		$context['sub_template'] = 'edit_template';
1833 1905
 
1834
-		if (!isset($error_file))
1835
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1836
-		else
1906
+		if (!isset($error_file)) {
1907
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1908
+		} else
1837 1909
 		{
1838
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1839
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1910
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1911
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1912
+			}
1840 1913
 			$file_data = file($error_file);
1841 1914
 			unlink($error_file);
1842 1915
 		}
@@ -1850,8 +1923,9 @@  discard block
 block discarded – undo
1850 1923
 				// Try to format the functions a little nicer...
1851 1924
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1852 1925
 
1853
-				if (empty($context['file_parts'][$j]['lines']))
1854
-					unset($context['file_parts'][$j]);
1926
+				if (empty($context['file_parts'][$j]['lines'])) {
1927
+									unset($context['file_parts'][$j]);
1928
+				}
1855 1929
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1856 1930
 			}
1857 1931
 
@@ -1860,8 +1934,7 @@  discard block
 block discarded – undo
1860 1934
 		}
1861 1935
 
1862 1936
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1863
-	}
1864
-	else
1937
+	} else
1865 1938
 	{
1866 1939
 		$context['sub_template'] = 'edit_file';
1867 1940
 
@@ -1887,8 +1960,9 @@  discard block
 block discarded – undo
1887 1960
 
1888 1961
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1889 1962
 
1890
-	if (empty($_GET['th']))
1891
-		fatal_lang_error('theme_install_invalid_id');
1963
+	if (empty($_GET['th'])) {
1964
+			fatal_lang_error('theme_install_invalid_id');
1965
+	}
1892 1966
 
1893 1967
 	// Get the theme info.
1894 1968
 	$theme = get_single_theme($_GET['th']);
@@ -1896,25 +1970,24 @@  discard block
 block discarded – undo
1896 1970
 
1897 1971
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1898 1972
 	{
1899
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1900
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1901
-
1902
-		else
1903
-			fatal_lang_error('no_access', false);
1973
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1974
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1975
+		} else {
1976
+					fatal_lang_error('no_access', false);
1977
+		}
1904 1978
 
1905 1979
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1906 1980
 		fwrite($fp, file_get_contents($filename));
1907 1981
 		fclose($fp);
1908 1982
 
1909 1983
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1910
-	}
1911
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1984
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1912 1985
 	{
1913
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1914
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1915
-
1916
-		else
1917
-			fatal_lang_error('no_access', false);
1986
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1987
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1988
+		} else {
1989
+					fatal_lang_error('no_access', false);
1990
+		}
1918 1991
 
1919 1992
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1920 1993
 		fwrite($fp, file_get_contents($filename));
@@ -1929,16 +2002,18 @@  discard block
 block discarded – undo
1929 2002
 	$dir = dir($settings['default_theme_dir']);
1930 2003
 	while ($entry = $dir->read())
1931 2004
 	{
1932
-		if (substr($entry, -13) == '.template.php')
1933
-			$templates[] = substr($entry, 0, -13);
2005
+		if (substr($entry, -13) == '.template.php') {
2006
+					$templates[] = substr($entry, 0, -13);
2007
+		}
1934 2008
 	}
1935 2009
 	$dir->close();
1936 2010
 
1937 2011
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1938 2012
 	while ($entry = $dir->read())
1939 2013
 	{
1940
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1941
-			$lang_files[] = $matches[1];
2014
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2015
+					$lang_files[] = $matches[1];
2016
+		}
1942 2017
 	}
1943 2018
 	$dir->close();
1944 2019
 
@@ -1946,21 +2021,23 @@  discard block
 block discarded – undo
1946 2021
 	natcasesort($lang_files);
1947 2022
 
1948 2023
 	$context['available_templates'] = array();
1949
-	foreach ($templates as $template)
1950
-		$context['available_templates'][$template] = array(
2024
+	foreach ($templates as $template) {
2025
+			$context['available_templates'][$template] = array(
1951 2026
 			'filename' => $template . '.template.php',
1952 2027
 			'value' => $template,
1953 2028
 			'already_exists' => false,
1954 2029
 			'can_copy' => is_writable($theme['theme_dir']),
1955 2030
 		);
2031
+	}
1956 2032
 	$context['available_language_files'] = array();
1957
-	foreach ($lang_files as $file)
1958
-		$context['available_language_files'][$file] = array(
2033
+	foreach ($lang_files as $file) {
2034
+			$context['available_language_files'][$file] = array(
1959 2035
 			'filename' => $file . '.php',
1960 2036
 			'value' => $file,
1961 2037
 			'already_exists' => false,
1962 2038
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1963 2039
 		);
2040
+	}
1964 2041
 
1965 2042
 	$dir = dir($theme['theme_dir']);
1966 2043
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.
Sources/Logging.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return array The truncated array
25 25
  */
26
-function truncateArray($arr, $max_length=1900)
26
+function truncateArray($arr, $max_length = 1900)
27 27
 {
28 28
 	$curr_length = 0;
29 29
 	foreach ($arr as $key => $value)
30 30
 		if (is_array($value))
31 31
 			foreach ($value as $key2 => $value2)
32
-				$curr_length += strlen ($value2);
32
+				$curr_length += strlen($value2);
33 33
 		else
34
-			$curr_length += strlen ($value);
34
+			$curr_length += strlen($value);
35 35
 	if ($curr_length <= $max_length)
36 36
 		return $arr;
37 37
 	else
38 38
 	{
39 39
 		// Truncate each element's value to a reasonable length
40
-		$param_max = floor($max_length/count($arr));
40
+		$param_max = floor($max_length / count($arr));
41 41
 		foreach ($arr as $key => &$value)
42 42
 			if (is_array($value))
43 43
 				foreach ($value as $key2 => &$value2)
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	if (filemtime($cachedir . '/db_last_error.php') === $last_db_error_change)
208 208
 	{
209 209
 		// Write the change
210
-		$write_db_change =  '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>';
210
+		$write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>';
211 211
 		$written_bytes = file_put_contents($cachedir . '/db_last_error.php', $write_db_change, LOCK_EX);
212 212
 
213 213
 		// survey says ...
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br>
281 281
 	', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br>
282 282
 	', $txt['debug_hooks'], empty($context['debug']['hooks']) ? 0 : count($context['debug']['hooks']) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_hooks\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_hooks" style="display: none;"><em>' . implode('</em>, <em>', $context['debug']['hooks']), '</em></span>)', '<br>
283
-	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
283
+	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">' . $txt['debug_show'] . '</a><span id="debug_instances" style="display: none;"><em>' . implode('</em>, <em>', array_keys($context['debug']['instances'])) . '</em></span>)' . '<br>') : ''), '
284 284
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
285 285
 
286 286
 	if (function_exists('memory_get_peak_usage'))
Please login to merge, or discard this patch.
Braces   +149 added lines, -107 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Truncate the GET array to a specified length
@@ -26,24 +27,28 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = 0;
29
-	foreach ($arr as $key => $value)
30
-		if (is_array($value))
30
+	foreach ($arr as $key => $value) {
31
+			if (is_array($value))
31 32
 			foreach ($value as $key2 => $value2)
32 33
 				$curr_length += strlen ($value2);
33
-		else
34
-			$curr_length += strlen ($value);
35
-	if ($curr_length <= $max_length)
36
-		return $arr;
37
-	else
34
+	}
35
+		else {
36
+					$curr_length += strlen ($value);
37
+		}
38
+	if ($curr_length <= $max_length) {
39
+			return $arr;
40
+	} else
38 41
 	{
39 42
 		// Truncate each element's value to a reasonable length
40 43
 		$param_max = floor($max_length/count($arr));
41
-		foreach ($arr as $key => &$value)
42
-			if (is_array($value))
44
+		foreach ($arr as $key => &$value) {
45
+					if (is_array($value))
43 46
 				foreach ($value as $key2 => &$value2)
44 47
 					$value2 = substr($value2, 0, $param_max - strlen($key) - 5);
45
-			else
46
-				$value = substr($value, 0, $param_max - strlen($key) - 5);
48
+		}
49
+			else {
50
+							$value = substr($value, 0, $param_max - strlen($key) - 5);
51
+			}
47 52
 		return $arr;
48 53
 	}
49 54
 }
@@ -65,8 +70,9 @@  discard block
 block discarded – undo
65 70
 		// Don't update for every page - this isn't wholly accurate but who cares.
66 71
 		if ($topic)
67 72
 		{
68
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
69
-				$force = false;
73
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
74
+							$force = false;
75
+			}
70 76
 			$_SESSION['last_topic_id'] = $topic;
71 77
 		}
72 78
 	}
@@ -79,22 +85,24 @@  discard block
 block discarded – undo
79 85
 	}
80 86
 
81 87
 	// Don't mark them as online more than every so often.
82
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
83
-		return;
88
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
89
+			return;
90
+	}
84 91
 
85 92
 	if (!empty($modSettings['who_enabled']))
86 93
 	{
87 94
 		$encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
88 95
 
89 96
 		// In the case of a dlattach action, session_var may not be set.
90
-		if (!isset($context['session_var']))
91
-			$context['session_var'] = $_SESSION['session_var'];
97
+		if (!isset($context['session_var'])) {
98
+					$context['session_var'] = $_SESSION['session_var'];
99
+		}
92 100
 
93 101
 		unset($encoded_get['sesc'], $encoded_get[$context['session_var']]);
94 102
 		$encoded_get = $smcFunc['json_encode']($encoded_get);
103
+	} else {
104
+			$encoded_get = '';
95 105
 	}
96
-	else
97
-		$encoded_get = '';
98 106
 
99 107
 	// Guests use 0, members use their session ID.
100 108
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -134,17 +142,18 @@  discard block
 block discarded – undo
134 142
 		);
135 143
 
136 144
 		// Guess it got deleted.
137
-		if ($smcFunc['db_affected_rows']() == 0)
145
+		if ($smcFunc['db_affected_rows']() == 0) {
146
+					$_SESSION['log_time'] = 0;
147
+		}
148
+	} else {
138 149
 			$_SESSION['log_time'] = 0;
139 150
 	}
140
-	else
141
-		$_SESSION['log_time'] = 0;
142 151
 
143 152
 	// Otherwise, we have to delete and insert.
144 153
 	if (empty($_SESSION['log_time']))
145 154
 	{
146
-		if ($do_delete || !empty($user_info['id']))
147
-			$smcFunc['db_query']('', '
155
+		if ($do_delete || !empty($user_info['id'])) {
156
+					$smcFunc['db_query']('', '
148 157
 				DELETE FROM {db_prefix}log_online
149 158
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
150 159
 				array(
@@ -152,6 +161,7 @@  discard block
 block discarded – undo
152 161
 					'log_time' => time() - $modSettings['lastActive'] * 60,
153 162
 				)
154 163
 			);
164
+		}
155 165
 
156 166
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
157 167
 			'{db_prefix}log_online',
@@ -165,21 +175,24 @@  discard block
 block discarded – undo
165 175
 	$_SESSION['log_time'] = time();
166 176
 
167 177
 	// Well, they are online now.
168
-	if (empty($_SESSION['timeOnlineUpdated']))
169
-		$_SESSION['timeOnlineUpdated'] = time();
178
+	if (empty($_SESSION['timeOnlineUpdated'])) {
179
+			$_SESSION['timeOnlineUpdated'] = time();
180
+	}
170 181
 
171 182
 	// Set their login time, if not already done within the last minute.
172 183
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
173 184
 	{
174 185
 		// Don't count longer than 15 minutes.
175
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
176
-			$_SESSION['timeOnlineUpdated'] = time();
186
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
187
+					$_SESSION['timeOnlineUpdated'] = time();
188
+		}
177 189
 
178 190
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
179 191
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
180 192
 
181
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
182
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
193
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
194
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
195
+		}
183 196
 
184 197
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
185 198
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -216,8 +229,7 @@  discard block
 block discarded – undo
216 229
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
217 230
 			// Copy the file back and run for your life!
218 231
 			@copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php');
219
-		}
220
-		else
232
+		} else
221 233
 		{
222 234
 			@touch($boarddir . '/' . 'Settings.php');
223 235
 			return true;
@@ -237,22 +249,27 @@  discard block
 block discarded – undo
237 249
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
238 250
 
239 251
 	// Add to Settings.php if you want to show the debugging information.
240
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
241
-		return;
252
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
253
+			return;
254
+	}
242 255
 
243
-	if (empty($_SESSION['view_queries']))
244
-		$_SESSION['view_queries'] = 0;
245
-	if (empty($context['debug']['language_files']))
246
-		$context['debug']['language_files'] = array();
247
-	if (empty($context['debug']['sheets']))
248
-		$context['debug']['sheets'] = array();
256
+	if (empty($_SESSION['view_queries'])) {
257
+			$_SESSION['view_queries'] = 0;
258
+	}
259
+	if (empty($context['debug']['language_files'])) {
260
+			$context['debug']['language_files'] = array();
261
+	}
262
+	if (empty($context['debug']['sheets'])) {
263
+			$context['debug']['sheets'] = array();
264
+	}
249 265
 
250 266
 	$files = get_included_files();
251 267
 	$total_size = 0;
252 268
 	for ($i = 0, $n = count($files); $i < $n; $i++)
253 269
 	{
254
-		if (file_exists($files[$i]))
255
-			$total_size += filesize($files[$i]);
270
+		if (file_exists($files[$i])) {
271
+					$total_size += filesize($files[$i]);
272
+		}
256 273
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
257 274
 	}
258 275
 
@@ -261,8 +278,9 @@  discard block
 block discarded – undo
261 278
 	{
262 279
 		foreach ($db_cache as $q => $query_data)
263 280
 		{
264
-			if (!empty($query_data['w']))
265
-				$warnings += count($query_data['w']);
281
+			if (!empty($query_data['w'])) {
282
+							$warnings += count($query_data['w']);
283
+			}
266 284
 		}
267 285
 
268 286
 		$_SESSION['debug'] = &$db_cache;
@@ -283,12 +301,14 @@  discard block
 block discarded – undo
283 301
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
284 302
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
285 303
 
286
-	if (function_exists('memory_get_peak_usage'))
287
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
304
+	if (function_exists('memory_get_peak_usage')) {
305
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
306
+	}
288 307
 
289 308
 	// What tokens are active?
290
-	if (isset($_SESSION['token']))
291
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
309
+	if (isset($_SESSION['token'])) {
310
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
311
+	}
292 312
 
293 313
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
294 314
 	{
@@ -302,10 +322,12 @@  discard block
 block discarded – undo
302 322
 			$total_t += $cache_hit['t'];
303 323
 			$total_s += $cache_hit['s'];
304 324
 		}
305
-		if (!isset($cache_misses))
306
-			$cache_misses = array();
307
-		foreach ($cache_misses as $missed)
308
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
325
+		if (!isset($cache_misses)) {
326
+					$cache_misses = array();
327
+		}
328
+		foreach ($cache_misses as $missed) {
329
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
330
+		}
309 331
 
310 332
 		echo '
311 333
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -316,38 +338,44 @@  discard block
 block discarded – undo
316 338
 	<a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
317 339
 	<br>';
318 340
 
319
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
320
-		foreach ($db_cache as $q => $query_data)
341
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
342
+			foreach ($db_cache as $q => $query_data)
321 343
 		{
322 344
 			$is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0;
345
+	}
323 346
 			// Temporary tables created in earlier queries are not explainable.
324 347
 			if ($is_select)
325 348
 			{
326
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
327
-					if (strpos(trim($query_data['q']), $tmp) !== false)
349
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
350
+									if (strpos(trim($query_data['q']), $tmp) !== false)
328 351
 					{
329 352
 						$is_select = false;
353
+				}
330 354
 						break;
331 355
 					}
332 356
 			}
333 357
 			// But actual creation of the temporary tables are.
334
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0)
335
-				$is_select = true;
358
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) {
359
+							$is_select = true;
360
+			}
336 361
 
337 362
 			// Make the filenames look a bit better.
338
-			if (isset($query_data['f']))
339
-				$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
363
+			if (isset($query_data['f'])) {
364
+							$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
365
+			}
340 366
 
341 367
 			echo '
342 368
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
343 369
 	&nbsp;&nbsp;&nbsp;';
344
-			if (!empty($query_data['f']) && !empty($query_data['l']))
345
-				echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
370
+			if (!empty($query_data['f']) && !empty($query_data['l'])) {
371
+							echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
372
+			}
346 373
 
347
-			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at']))
348
-				echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
349
-			elseif (isset($query_data['t']))
350
-				echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
374
+			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) {
375
+							echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
376
+			} elseif (isset($query_data['t'])) {
377
+							echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
378
+			}
351 379
 			echo '
352 380
 	<br>';
353 381
 		}
@@ -372,12 +400,14 @@  discard block
 block discarded – undo
372 400
 	global $modSettings, $smcFunc;
373 401
 	static $cache_stats = array();
374 402
 
375
-	if (empty($modSettings['trackStats']))
376
-		return false;
377
-	if (!empty($stats))
378
-		return $cache_stats = array_merge($cache_stats, $stats);
379
-	elseif (empty($cache_stats))
380
-		return false;
403
+	if (empty($modSettings['trackStats'])) {
404
+			return false;
405
+	}
406
+	if (!empty($stats)) {
407
+			return $cache_stats = array_merge($cache_stats, $stats);
408
+	} elseif (empty($cache_stats)) {
409
+			return false;
410
+	}
381 411
 
382 412
 	$setStringUpdate = '';
383 413
 	$insert_keys = array();
@@ -390,10 +420,11 @@  discard block
 block discarded – undo
390 420
 		$setStringUpdate .= '
391 421
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
392 422
 
393
-		if ($change === '+')
394
-			$cache_stats[$field] = 1;
395
-		else
396
-			$update_parameters[$field] = $change;
423
+		if ($change === '+') {
424
+					$cache_stats[$field] = 1;
425
+		} else {
426
+					$update_parameters[$field] = $change;
427
+		}
397 428
 		$insert_keys[$field] = 'int';
398 429
 	}
399 430
 
@@ -457,43 +488,50 @@  discard block
 block discarded – undo
457 488
 	);
458 489
 
459 490
 	// Make sure this particular log is enabled first...
460
-	if (empty($modSettings['modlog_enabled']))
461
-		unset ($log_types['moderate']);
462
-	if (empty($modSettings['userlog_enabled']))
463
-		unset ($log_types['user']);
464
-	if (empty($modSettings['adminlog_enabled']))
465
-		unset ($log_types['admin']);
491
+	if (empty($modSettings['modlog_enabled'])) {
492
+			unset ($log_types['moderate']);
493
+	}
494
+	if (empty($modSettings['userlog_enabled'])) {
495
+			unset ($log_types['user']);
496
+	}
497
+	if (empty($modSettings['adminlog_enabled'])) {
498
+			unset ($log_types['admin']);
499
+	}
466 500
 
467 501
 	call_integration_hook('integrate_log_types', array(&$log_types));
468 502
 
469 503
 	foreach ($logs as $log)
470 504
 	{
471
-		if (!isset($log_types[$log['log_type']]))
472
-			return false;
505
+		if (!isset($log_types[$log['log_type']])) {
506
+					return false;
507
+		}
473 508
 
474
-		if (!is_array($log['extra']))
475
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
509
+		if (!is_array($log['extra'])) {
510
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
511
+		}
476 512
 
477 513
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
478 514
 		if (isset($log['extra']['topic']))
479 515
 		{
480
-			if (!is_numeric($log['extra']['topic']))
481
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
516
+			if (!is_numeric($log['extra']['topic'])) {
517
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
518
+			}
482 519
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
483 520
 			unset($log['extra']['topic']);
521
+		} else {
522
+					$topic_id = 0;
484 523
 		}
485
-		else
486
-			$topic_id = 0;
487 524
 
488 525
 		if (isset($log['extra']['message']))
489 526
 		{
490
-			if (!is_numeric($log['extra']['message']))
491
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
527
+			if (!is_numeric($log['extra']['message'])) {
528
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
529
+			}
492 530
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
493 531
 			unset($log['extra']['message']);
532
+		} else {
533
+					$msg_id = 0;
494 534
 		}
495
-		else
496
-			$msg_id = 0;
497 535
 
498 536
 		// @todo cache this?
499 537
 		// Is there an associated report on this?
@@ -520,23 +558,26 @@  discard block
 block discarded – undo
520 558
 			$smcFunc['db_free_result']($request);
521 559
 		}
522 560
 
523
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
524
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
561
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
562
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
563
+		}
525 564
 
526 565
 		if (isset($log['extra']['board']))
527 566
 		{
528
-			if (!is_numeric($log['extra']['board']))
529
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
567
+			if (!is_numeric($log['extra']['board'])) {
568
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
569
+			}
530 570
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
531 571
 			unset($log['extra']['board']);
572
+		} else {
573
+					$board_id = 0;
532 574
 		}
533
-		else
534
-			$board_id = 0;
535 575
 
536 576
 		if (isset($log['extra']['board_to']))
537 577
 		{
538
-			if (!is_numeric($log['extra']['board_to']))
539
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
578
+			if (!is_numeric($log['extra']['board_to'])) {
579
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
580
+			}
540 581
 			if (empty($board_id))
541 582
 			{
542 583
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -544,10 +585,11 @@  discard block
 block discarded – undo
544 585
 			}
545 586
 		}
546 587
 
547
-		if (isset($log['extra']['member_affected']))
548
-			$memID = $log['extra']['member_affected'];
549
-		else
550
-			$memID = $user_info['id'];
588
+		if (isset($log['extra']['member_affected'])) {
589
+					$memID = $log['extra']['member_affected'];
590
+		} else {
591
+					$memID = $user_info['id'];
592
+		}
551 593
 
552 594
 		$inserts[] = array(
553 595
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.