Completed
Pull Request — release-2.1 (#4959)
by Jeremy
07:43
created
Sources/Subs-Db-postgresql.php 1 patch
Braces   +238 added lines, -175 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)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'					=> 'smf_db_query',
40 41
 			'db_quote'					=> 'smf_db_quote',
41 42
 			'db_insert'					=> 'smf_db_insert',
@@ -65,15 +66,18 @@  discard block
 block discarded – undo
65 66
 			'db_custom_order'			=> 'smf_db_custom_order',
66 67
 			'db_native_replace'			=> 'smf_db_native_replace',
67 68
 		);
69
+	}
68 70
 
69 71
 	// We are not going to make it very far without these.
70
-	if (!function_exists('pg_pconnect'))
71
-		display_db_error();
72
+	if (!function_exists('pg_pconnect')) {
73
+			display_db_error();
74
+	}
72 75
 
73
-	if (!empty($db_options['persist']))
74
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
75
-	else
76
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
76
+	if (!empty($db_options['persist'])) {
77
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
78
+	} else {
79
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
80
+	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if (!$connection)
@@ -81,15 +85,15 @@  discard block
 block discarded – undo
81 85
 		if (!empty($db_options['non_fatal']))
82 86
 		{
83 87
 			return null;
84
-		}
85
-		else
88
+		} else
86 89
 		{
87 90
 			display_db_error();
88 91
 		}
89 92
 	}
90 93
 
91
-	if (!empty($db_options['db_mb4']))
92
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
94
+	if (!empty($db_options['db_mb4'])) {
95
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
96
+	}
93 97
 
94 98
 	return $connection;
95 99
 }
@@ -136,31 +140,38 @@  discard block
 block discarded – undo
136 140
 
137 141
 	list ($values, $connection) = $db_callback;
138 142
 
139
-	if ($matches[1] === 'db_prefix')
140
-		return $db_prefix;
143
+	if ($matches[1] === 'db_prefix') {
144
+			return $db_prefix;
145
+	}
141 146
 
142
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
143
-		return $user_info[$matches[1]];
147
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
148
+			return $user_info[$matches[1]];
149
+	}
144 150
 
145
-	if ($matches[1] === 'empty')
146
-		return '\'\'';
151
+	if ($matches[1] === 'empty') {
152
+			return '\'\'';
153
+	}
147 154
 
148
-	if (!isset($matches[2]))
149
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
155
+	if (!isset($matches[2])) {
156
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
157
+	}
150 158
 
151
-	if ($matches[1] === 'literal')
152
-		return '\'' . pg_escape_string($matches[2]) . '\'';
159
+	if ($matches[1] === 'literal') {
160
+			return '\'' . pg_escape_string($matches[2]) . '\'';
161
+	}
153 162
 
154
-	if (!isset($values[$matches[2]]))
155
-		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__);
163
+	if (!isset($values[$matches[2]])) {
164
+			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__);
165
+	}
156 166
 
157 167
 	$replacement = $values[$matches[2]];
158 168
 
159 169
 	switch ($matches[1])
160 170
 	{
161 171
 		case 'int':
162
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
163
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
172
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
173
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
174
+			}
164 175
 			return (string) (int) $replacement;
165 176
 		break;
166 177
 
@@ -172,65 +183,73 @@  discard block
 block discarded – undo
172 183
 		case 'array_int':
173 184
 			if (is_array($replacement))
174 185
 			{
175
-				if (empty($replacement))
176
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
186
+				if (empty($replacement)) {
187
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
188
+				}
177 189
 
178 190
 				foreach ($replacement as $key => $value)
179 191
 				{
180
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
181
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
192
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
193
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194
+					}
182 195
 
183 196
 					$replacement[$key] = (string) (int) $value;
184 197
 				}
185 198
 
186 199
 				return implode(', ', $replacement);
200
+			} else {
201
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
187 202
 			}
188
-			else
189
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
190 203
 
191 204
 		break;
192 205
 
193 206
 		case 'array_string':
194 207
 			if (is_array($replacement))
195 208
 			{
196
-				if (empty($replacement))
197
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
209
+				if (empty($replacement)) {
210
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+				}
198 212
 
199
-				foreach ($replacement as $key => $value)
200
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
213
+				foreach ($replacement as $key => $value) {
214
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
215
+				}
201 216
 
202 217
 				return implode(', ', $replacement);
218
+			} else {
219
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203 220
 			}
204
-			else
205
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206 221
 		break;
207 222
 
208 223
 		case 'date':
209
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
210
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
211
-			else
212
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
225
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
226
+			} else {
227
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+			}
213 229
 		break;
214 230
 
215 231
 		case 'time':
216
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
217
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
218
-			else
219
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
233
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			}
220 237
 		break;
221 238
 
222 239
 		case 'datetime':
223
-			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)
224
-				return 'to_timestamp('.
240
+			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) {
241
+							return 'to_timestamp('.
225 242
 					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]).
226 243
 					',\'YYYY-MM-DD HH24:MI:SS\')';
227
-			else
228
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+			} else {
245
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
246
+			}
229 247
 		break;
230 248
 
231 249
 		case 'float':
232
-			if (!is_numeric($replacement))
233
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+			if (!is_numeric($replacement)) {
251
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+			}
234 253
 			return (string) (float) $replacement;
235 254
 		break;
236 255
 
@@ -243,31 +262,36 @@  discard block
 block discarded – undo
243 262
 		break;
244 263
 
245 264
 		case 'inet':
246
-			if ($replacement == 'null' || $replacement == '')
247
-				return 'null';
248
-			if (inet_pton($replacement) === false)
249
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if ($replacement == 'null' || $replacement == '') {
266
+							return 'null';
267
+			}
268
+			if (inet_pton($replacement) === false) {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
250 271
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
251 272
 
252 273
 		case 'array_inet':
253 274
 			if (is_array($replacement))
254 275
 			{
255
-				if (empty($replacement))
256
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
276
+				if (empty($replacement)) {
277
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+				}
257 279
 
258 280
 				foreach ($replacement as $key => $value)
259 281
 				{
260
-					if ($replacement == 'null' || $replacement == '')
261
-						$replacement[$key] = 'null';
262
-					if (!isValidIP($value))
263
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+					if ($replacement == 'null' || $replacement == '') {
283
+											$replacement[$key] = 'null';
284
+					}
285
+					if (!isValidIP($value)) {
286
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+					}
264 288
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
265 289
 				}
266 290
 
267 291
 				return implode(', ', $replacement);
292
+			} else {
293
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268 294
 			}
269
-			else
270
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271 295
 		break;
272 296
 
273 297
 		default:
@@ -355,14 +379,16 @@  discard block
 block discarded – undo
355 379
 		),
356 380
 	);
357 381
 
358
-	if (isset($replacements[$identifier]))
359
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
382
+	if (isset($replacements[$identifier])) {
383
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
384
+	}
360 385
 
361 386
 	// Limits need to be a little different.
362 387
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
363 388
 
364
-	if (trim($db_string) == '')
365
-		return false;
389
+	if (trim($db_string) == '') {
390
+			return false;
391
+	}
366 392
 
367 393
 	// Comments that are allowed in a query are preg_removed.
368 394
 	static $allowed_comments_from = array(
@@ -382,8 +408,9 @@  discard block
 block discarded – undo
382 408
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
383 409
 	$db_replace_result = 0;
384 410
 
385
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
386
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
411
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
412
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
413
+	}
387 414
 
388 415
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
389 416
 	{
@@ -408,17 +435,18 @@  discard block
 block discarded – undo
408 435
 		while (true)
409 436
 		{
410 437
 			$pos = strpos($db_string_1, '\'', $pos + 1);
411
-			if ($pos === false)
412
-				break;
438
+			if ($pos === false) {
439
+							break;
440
+			}
413 441
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
414 442
 
415 443
 			while (true)
416 444
 			{
417 445
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
418 446
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
419
-				if ($pos1 === false)
420
-					break;
421
-				elseif ($pos2 === false || $pos2 > $pos1)
447
+				if ($pos1 === false) {
448
+									break;
449
+				} elseif ($pos2 === false || $pos2 > $pos1)
422 450
 				{
423 451
 					$pos = $pos1;
424 452
 					break;
@@ -434,16 +462,19 @@  discard block
 block discarded – undo
434 462
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
435 463
 
436 464
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
437
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
438
-			$fail = true;
465
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
466
+					$fail = true;
467
+		}
439 468
 		// Trying to change passwords, slow us down, or something?
440
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
441
-			$fail = true;
442
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
443
-			$fail = true;
469
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
470
+					$fail = true;
471
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		}
444 474
 
445
-		if (!empty($fail) && function_exists('log_error'))
446
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
475
+		if (!empty($fail) && function_exists('log_error')) {
476
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		}
447 478
 	}
448 479
 
449 480
 	// Set optimize stuff
@@ -470,8 +501,9 @@  discard block
 block discarded – undo
470 501
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
471 502
 
472 503
 		// Initialize $db_cache if not already initialized.
473
-		if (!isset($db_cache))
474
-			$db_cache = array();
504
+		if (!isset($db_cache)) {
505
+					$db_cache = array();
506
+		}
475 507
 
476 508
 		if (!empty($_SESSION['debug_redirect']))
477 509
 		{
@@ -489,12 +521,14 @@  discard block
 block discarded – undo
489 521
 
490 522
 	$db_last_result = @pg_query($connection, $db_string);
491 523
 
492
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
493
-		$db_last_result = smf_db_error($db_string, $connection);
524
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
525
+			$db_last_result = smf_db_error($db_string, $connection);
526
+	}
494 527
 
495 528
 	// Debugging.
496
-	if (isset($db_show_debug) && $db_show_debug === true)
497
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
529
+	if (isset($db_show_debug) && $db_show_debug === true) {
530
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
531
+	}
498 532
 
499 533
 	return $db_last_result;
500 534
 }
@@ -511,10 +545,11 @@  discard block
 block discarded – undo
511 545
 {
512 546
 	global $db_last_result, $db_replace_result;
513 547
 
514
-	if ($db_replace_result)
515
-		return $db_replace_result;
516
-	elseif ($result === null && !$db_last_result)
517
-		return 0;
548
+	if ($db_replace_result) {
549
+			return $db_replace_result;
550
+	} elseif ($result === null && !$db_last_result) {
551
+			return 0;
552
+	}
518 553
 
519 554
 	return pg_affected_rows($result === null ? $db_last_result : $result);
520 555
 }
@@ -538,8 +573,9 @@  discard block
 block discarded – undo
538 573
 		array(
539 574
 		)
540 575
 	);
541
-	if (!$request)
542
-		return false;
576
+	if (!$request) {
577
+			return false;
578
+	}
543 579
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
544 580
 	$smcFunc['db_free_result']($request);
545 581
 
@@ -560,12 +596,13 @@  discard block
 block discarded – undo
560 596
 	// Decide which connection to use
561 597
 	$connection = $connection === null ? $db_connection : $connection;
562 598
 
563
-	if ($type == 'begin')
564
-		return @pg_query($connection, 'BEGIN');
565
-	elseif ($type == 'rollback')
566
-		return @pg_query($connection, 'ROLLBACK');
567
-	elseif ($type == 'commit')
568
-		return @pg_query($connection, 'COMMIT');
599
+	if ($type == 'begin') {
600
+			return @pg_query($connection, 'BEGIN');
601
+	} elseif ($type == 'rollback') {
602
+			return @pg_query($connection, 'ROLLBACK');
603
+	} elseif ($type == 'commit') {
604
+			return @pg_query($connection, 'COMMIT');
605
+	}
569 606
 
570 607
 	return false;
571 608
 }
@@ -593,19 +630,22 @@  discard block
 block discarded – undo
593 630
 	$query_error = @pg_last_error($connection);
594 631
 
595 632
 	// Log the error.
596
-	if (function_exists('log_error'))
597
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
633
+	if (function_exists('log_error')) {
634
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
635
+	}
598 636
 
599 637
 	// Nothing's defined yet... just die with it.
600
-	if (empty($context) || empty($txt))
601
-		die($query_error);
638
+	if (empty($context) || empty($txt)) {
639
+			die($query_error);
640
+	}
602 641
 
603 642
 	// Show an error message, if possible.
604 643
 	$context['error_title'] = $txt['database_error'];
605
-	if (allowedTo('admin_forum'))
606
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
607
-	else
608
-		$context['error_message'] = $txt['try_again'];
644
+	if (allowedTo('admin_forum')) {
645
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
646
+	} else {
647
+			$context['error_message'] = $txt['try_again'];
648
+	}
609 649
 
610 650
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
611 651
 	{
@@ -627,12 +667,14 @@  discard block
 block discarded – undo
627 667
 {
628 668
 	global $db_row_count;
629 669
 
630
-	if ($counter !== false)
631
-		return pg_fetch_row($request, $counter);
670
+	if ($counter !== false) {
671
+			return pg_fetch_row($request, $counter);
672
+	}
632 673
 
633 674
 	// Reset the row counter...
634
-	if (!isset($db_row_count[(int) $request]))
635
-		$db_row_count[(int) $request] = 0;
675
+	if (!isset($db_row_count[(int) $request])) {
676
+			$db_row_count[(int) $request] = 0;
677
+	}
636 678
 
637 679
 	// Return the right row.
638 680
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -649,12 +691,14 @@  discard block
 block discarded – undo
649 691
 {
650 692
 	global $db_row_count;
651 693
 
652
-	if ($counter !== false)
653
-		return pg_fetch_assoc($request, $counter);
694
+	if ($counter !== false) {
695
+			return pg_fetch_assoc($request, $counter);
696
+	}
654 697
 
655 698
 	// Reset the row counter...
656
-	if (!isset($db_row_count[(int) $request]))
657
-		$db_row_count[(int) $request] = 0;
699
+	if (!isset($db_row_count[(int) $request])) {
700
+			$db_row_count[(int) $request] = 0;
701
+	}
658 702
 
659 703
 	// Return the right row.
660 704
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -707,11 +751,13 @@  discard block
 block discarded – undo
707 751
 
708 752
 	$replace = '';
709 753
 
710
-	if (empty($data))
711
-		return;
754
+	if (empty($data)) {
755
+			return;
756
+	}
712 757
 
713
-	if (!is_array($data[array_rand($data)]))
714
-		$data = array($data);
758
+	if (!is_array($data[array_rand($data)])) {
759
+			$data = array($data);
760
+	}
715 761
 
716 762
 	// Replace the prefix holder with the actual prefix.
717 763
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -737,32 +783,35 @@  discard block
 block discarded – undo
737 783
 					$key_str .= ($count_pk > 0 ? ',' : '');
738 784
 					$key_str .= $columnName;
739 785
 					$count_pk++;
740
-				}
741
-				else if ($method == 'replace') //normal field
786
+				} else if ($method == 'replace') {
787
+					//normal field
742 788
 				{
743 789
 					$col_str .= ($count > 0 ? ',' : '');
790
+				}
744 791
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
745 792
 					$count++;
746 793
 				}
747 794
 			}
748
-			if ($method == 'replace')
749
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
750
-			else
751
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
752
-		}
753
-		else if ($method == 'replace')
795
+			if ($method == 'replace') {
796
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
797
+			} else {
798
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
799
+			}
800
+		} else if ($method == 'replace')
754 801
 		{
755 802
 			foreach ($columns as $columnName => $type)
756 803
 			{
757 804
 				// Are we restricting the length?
758
-				if (strpos($type, 'string-') !== false)
759
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
760
-				else
761
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
805
+				if (strpos($type, 'string-') !== false) {
806
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
807
+				} else {
808
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
809
+				}
762 810
 
763 811
 				// A key? That's what we were looking for.
764
-				if (in_array($columnName, $keys))
765
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
812
+				if (in_array($columnName, $keys)) {
813
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
814
+				}
766 815
 				$count++;
767 816
 			}
768 817
 
@@ -798,10 +847,11 @@  discard block
 block discarded – undo
798 847
 		foreach ($columns as $columnName => $type)
799 848
 		{
800 849
 			// Are we restricting the length?
801
-			if (strpos($type, 'string-') !== false)
802
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
803
-			else
804
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+			if (strpos($type, 'string-') !== false) {
851
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
852
+			} else {
853
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+			}
805 855
 		}
806 856
 		$insertData = substr($insertData, 0, -2) . ')';
807 857
 
@@ -810,8 +860,9 @@  discard block
 block discarded – undo
810 860
 
811 861
 		// Here's where the variables are injected to the query.
812 862
 		$insertRows = array();
813
-		foreach ($data as $dataRow)
814
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
863
+		foreach ($data as $dataRow) {
864
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
865
+		}
815 866
 
816 867
 		// Do the insert.
817 868
 		$request = $smcFunc['db_query']('', '
@@ -828,19 +879,21 @@  discard block
 block discarded – undo
828 879
 
829 880
 		if ($with_returning && $request !== false)
830 881
 		{
831
-			if ($returnmode === 2)
832
-				$return_var = array();
882
+			if ($returnmode === 2) {
883
+							$return_var = array();
884
+			}
833 885
 
834 886
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
835 887
 			{
836
-				if (is_numeric($row[0])) // try to emulate mysql limitation
888
+				if (is_numeric($row[0])) {
889
+					// try to emulate mysql limitation
837 890
 				{
838 891
 					if ($returnmode === 1)
839 892
 						$return_var = $row[0];
840
-					elseif ($returnmode === 2)
841
-						$return_var[] = $row[0];
842
-				}
843
-				else
893
+				} elseif ($returnmode === 2) {
894
+											$return_var[] = $row[0];
895
+					}
896
+				} else
844 897
 				{
845 898
 					$with_returning = false;
846 899
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -849,9 +902,10 @@  discard block
 block discarded – undo
849 902
 		}
850 903
 	}
851 904
 
852
-	if ($with_returning && !empty($return_var))
853
-		return $return_var;
854
-}
905
+	if ($with_returning && !empty($return_var)) {
906
+			return $return_var;
907
+	}
908
+	}
855 909
 
856 910
 /**
857 911
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -888,8 +942,9 @@  discard block
 block discarded – undo
888 942
  */
889 943
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
890 944
 {
891
-	if (empty($log_message))
892
-		$log_message = $error_message;
945
+	if (empty($log_message)) {
946
+			$log_message = $error_message;
947
+	}
893 948
 
894 949
 	foreach (debug_backtrace() as $step)
895 950
 	{
@@ -908,12 +963,14 @@  discard block
 block discarded – undo
908 963
 	}
909 964
 
910 965
 	// A special case - we want the file and line numbers for debugging.
911
-	if ($error_type == 'return')
912
-		return array($file, $line);
966
+	if ($error_type == 'return') {
967
+			return array($file, $line);
968
+	}
913 969
 
914 970
 	// Is always a critical error.
915
-	if (function_exists('log_error'))
916
-		log_error($log_message, 'critical', $file, $line);
971
+	if (function_exists('log_error')) {
972
+			log_error($log_message, 'critical', $file, $line);
973
+	}
917 974
 
918 975
 	if (function_exists('fatal_error'))
919 976
 	{
@@ -921,12 +978,12 @@  discard block
 block discarded – undo
921 978
 
922 979
 		// Cannot continue...
923 980
 		exit;
981
+	} elseif ($error_type) {
982
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
983
+	} else {
984
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
985
+	}
924 986
 	}
925
-	elseif ($error_type)
926
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
927
-	else
928
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
929
-}
930 987
 
931 988
 /**
932 989
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -943,10 +1000,11 @@  discard block
 block discarded – undo
943 1000
 		'\\' => '\\\\',
944 1001
 	);
945 1002
 
946
-	if ($translate_human_wildcards)
947
-		$replacements += array(
1003
+	if ($translate_human_wildcards) {
1004
+			$replacements += array(
948 1005
 			'*' => '%',
949 1006
 		);
1007
+	}
950 1008
 
951 1009
 	return strtr($string, $replacements);
952 1010
 }
@@ -975,14 +1033,16 @@  discard block
 block discarded – undo
975 1033
 	static $pg_error_data_prep;
976 1034
 
977 1035
 	// without database we can't do anything
978
-	if (empty($db_connection))
979
-		return;
1036
+	if (empty($db_connection)) {
1037
+			return;
1038
+	}
980 1039
 
981
-	if (empty($pg_error_data_prep))
982
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1040
+	if (empty($pg_error_data_prep)) {
1041
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
983 1042
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
984 1043
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9, $10)'
985 1044
 			);
1045
+	}
986 1046
 
987 1047
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
988 1048
 }
@@ -1002,8 +1062,9 @@  discard block
 block discarded – undo
1002 1062
 	$count = count($array_values);
1003 1063
 	$then = ($desc ? ' THEN -' : ' THEN ');
1004 1064
 
1005
-	for ($i = 0; $i < $count; $i++)
1006
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1065
+	for ($i = 0; $i < $count; $i++) {
1066
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1067
+	}
1007 1068
 
1008 1069
 	$return .= 'END';
1009 1070
 	return $return;
@@ -1026,11 +1087,13 @@  discard block
 block discarded – undo
1026 1087
 		//pg 9.5 got replace support
1027 1088
 		$pg_version = $smcFunc['db_get_version']();
1028 1089
 		// if we got a Beta Version
1029
-		if (stripos($pg_version, 'beta') !== false)
1030
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1090
+		if (stripos($pg_version, 'beta') !== false) {
1091
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1092
+		}
1031 1093
 		// or RC
1032
-		if (stripos($pg_version, 'rc') !== false)
1033
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1094
+		if (stripos($pg_version, 'rc') !== false) {
1095
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1096
+		}
1034 1097
 
1035 1098
 		$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
1036 1099
 	}
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 1 patch
Braces   +280 added lines, -203 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
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -519,15 +544,17 @@  discard block
 block discarded – undo
519 544
 
520 545
 		// Store this useful data!
521 546
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
547
+		if ($row['id_topic']) {
548
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
549
+		} else {
550
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
551
+		}
526 552
 	}
527 553
 	$smcFunc['db_free_result']($request);
528 554
 
529
-	if (empty($boards))
530
-		return true;
555
+	if (empty($boards)) {
556
+			return true;
557
+	}
531 558
 
532 559
 	// Just get the board names.
533 560
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +566,14 @@  discard block
 block discarded – undo
539 566
 		)
540 567
 	);
541 568
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
569
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
570
+			$boards[$row['id_board']] = $row['name'];
571
+	}
544 572
 	$smcFunc['db_free_result']($request);
545 573
 
546
-	if (empty($boards))
547
-		return true;
574
+	if (empty($boards)) {
575
+			return true;
576
+	}
548 577
 
549 578
 	// Get the actual topics...
550 579
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +593,57 @@  discard block
 block discarded – undo
564 593
 	$types = array();
565 594
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 595
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
596
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
597
+					$types[$row['note_type']][$row['id_board']] = array(
569 598
 				'lines' => array(),
570 599
 				'name' => $row['board_name'],
571 600
 				'id' => $row['id_board'],
572 601
 			);
602
+		}
573 603
 
574 604
 		if ($row['note_type'] == 'reply')
575 605
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
606
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
607
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
608
+			} else {
609
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 610
 					'id' => $row['id_topic'],
581 611
 					'subject' => un_htmlspecialchars($row['subject']),
582 612
 					'count' => 1,
583 613
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
614
+			}
615
+		} elseif ($row['note_type'] == 'topic')
586 616
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
617
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
618
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 619
 					'id' => $row['id_topic'],
590 620
 					'subject' => un_htmlspecialchars($row['subject']),
591 621
 				);
592
-		}
593
-		else
622
+			}
623
+		} else
594 624
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
625
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
626
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 627
 					'id' => $row['id_topic'],
598 628
 					'subject' => un_htmlspecialchars($row['subject']),
599 629
 					'starter' => $row['id_member_started'],
600 630
 				);
631
+			}
601 632
 		}
602 633
 
603 634
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
635
+		if (!empty($notify['topics'][$row['id_topic']])) {
636
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
637
+		}
638
+		if (!empty($notify['boards'][$row['id_board']])) {
639
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
640
+		}
608 641
 	}
609 642
 	$smcFunc['db_free_result']($request);
610 643
 
611
-	if (empty($types))
612
-		return true;
644
+	if (empty($types)) {
645
+			return true;
646
+	}
613 647
 
614 648
 	// Let's load all the languages into a cache thingy.
615 649
 	$langtxt = array();
@@ -651,8 +685,9 @@  discard block
 block discarded – undo
651 685
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
652 686
 
653 687
 		// Did they not elect to choose this?
654
-		if ($frequency < 3 || $frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
655
-			continue;
688
+		if ($frequency < 3 || $frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
689
+					continue;
690
+		}
656 691
 
657 692
 		// Right character set!
658 693
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -668,39 +703,43 @@  discard block
 block discarded – undo
668 703
 		if (isset($types['topic']))
669 704
 		{
670 705
 			$titled = false;
671
-			foreach ($types['topic'] as $id => $board)
672
-				foreach ($board['lines'] as $topic)
706
+			foreach ($types['topic'] as $id => $board) {
707
+							foreach ($board['lines'] as $topic)
673 708
 					if (in_array($mid, $topic['members']))
674 709
 					{
675 710
 						if (!$titled)
676 711
 						{
677 712
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
713
+			}
678 714
 							$titled = true;
679 715
 						}
680 716
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
681 717
 					}
682
-			if ($titled)
683
-				$email['body'] .= "\n";
718
+			if ($titled) {
719
+							$email['body'] .= "\n";
720
+			}
684 721
 		}
685 722
 
686 723
 		// What about replies?
687 724
 		if (isset($types['reply']))
688 725
 		{
689 726
 			$titled = false;
690
-			foreach ($types['reply'] as $id => $board)
691
-				foreach ($board['lines'] as $topic)
727
+			foreach ($types['reply'] as $id => $board) {
728
+							foreach ($board['lines'] as $topic)
692 729
 					if (in_array($mid, $topic['members']))
693 730
 					{
694 731
 						if (!$titled)
695 732
 						{
696 733
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
734
+			}
697 735
 							$titled = true;
698 736
 						}
699 737
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
700 738
 					}
701 739
 
702
-			if ($titled)
703
-				$email['body'] .= "\n";
740
+			if ($titled) {
741
+							$email['body'] .= "\n";
742
+			}
704 743
 		}
705 744
 
706 745
 		// Finally, moderation actions!
@@ -709,24 +748,27 @@  discard block
 block discarded – undo
709 748
 			$titled = false;
710 749
 			foreach ($types as $note_type => $type)
711 750
 			{
712
-				if ($note_type == 'topic' || $note_type == 'reply')
713
-					continue;
751
+				if ($note_type == 'topic' || $note_type == 'reply') {
752
+									continue;
753
+				}
714 754
 
715
-				foreach ($type as $id => $board)
716
-					foreach ($board['lines'] as $topic)
755
+				foreach ($type as $id => $board) {
756
+									foreach ($board['lines'] as $topic)
717 757
 						if (in_array($mid, $topic['members']))
718 758
 						{
719 759
 							if (!$titled)
720 760
 							{
721 761
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
762
+				}
722 763
 								$titled = true;
723 764
 							}
724 765
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
725 766
 						}
726 767
 			}
727 768
 		}
728
-		if ($titled)
729
-			$email['body'] .= "\n";
769
+		if ($titled) {
770
+					$email['body'] .= "\n";
771
+		}
730 772
 
731 773
 		// Then just say our goodbyes!
732 774
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -756,8 +798,7 @@  discard block
 block discarded – undo
756 798
 				'not_daily' => 0,
757 799
 			)
758 800
 		);
759
-	}
760
-	else
801
+	} else
761 802
 	{
762 803
 		// Clear any only weekly ones, and stop us from sending daily again.
763 804
 		$smcFunc['db_query']('', '
@@ -821,16 +862,19 @@  discard block
 block discarded – undo
821 862
 	global $modSettings, $smcFunc, $sourcedir;
822 863
 
823 864
 	// Are we intending another script to be sending out the queue?
824
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
825
-		return false;
865
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
866
+			return false;
867
+	}
826 868
 
827 869
 	// By default send 5 at once.
828
-	if (!$number)
829
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
870
+	if (!$number) {
871
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
872
+	}
830 873
 
831 874
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
832
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
833
-		return false;
875
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
876
+			return false;
877
+	}
834 878
 
835 879
 	// By default move the next sending on by 10 seconds, and require an affected row.
836 880
 	if (!$override_limit)
@@ -847,8 +891,9 @@  discard block
 block discarded – undo
847 891
 				'last_send' => $modSettings['mail_next_send'],
848 892
 			)
849 893
 		);
850
-		if ($smcFunc['db_affected_rows']() == 0)
851
-			return false;
894
+		if ($smcFunc['db_affected_rows']() == 0) {
895
+					return false;
896
+		}
852 897
 		$modSettings['mail_next_send'] = time() + $delay;
853 898
 	}
854 899
 
@@ -869,8 +914,9 @@  discard block
 block discarded – undo
869 914
 			$mn += $number;
870 915
 		}
871 916
 		// No more I'm afraid, return!
872
-		else
873
-			return false;
917
+		else {
918
+					return false;
919
+		}
874 920
 
875 921
 		// Reflect that we're about to send some, do it now to be safe.
876 922
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -905,14 +951,15 @@  discard block
 block discarded – undo
905 951
 	$smcFunc['db_free_result']($request);
906 952
 
907 953
 	// Delete, delete, delete!!!
908
-	if (!empty($ids))
909
-		$smcFunc['db_query']('', '
954
+	if (!empty($ids)) {
955
+			$smcFunc['db_query']('', '
910 956
 			DELETE FROM {db_prefix}mail_queue
911 957
 			WHERE id_mail IN ({array_int:mail_list})',
912 958
 			array(
913 959
 				'mail_list' => $ids,
914 960
 			)
915 961
 		);
962
+	}
916 963
 
917 964
 	// Don't believe we have any left?
918 965
 	if (count($ids) < $number)
@@ -930,11 +977,13 @@  discard block
 block discarded – undo
930 977
 		);
931 978
 	}
932 979
 
933
-	if (empty($ids))
934
-		return false;
980
+	if (empty($ids)) {
981
+			return false;
982
+	}
935 983
 
936
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
937
-		require_once($sourcedir . '/Subs-Post.php');
984
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
985
+			require_once($sourcedir . '/Subs-Post.php');
986
+	}
938 987
 
939 988
 	// Send each email, yea!
940 989
 	$failed_emails = array();
@@ -954,15 +1003,17 @@  discard block
 block discarded – undo
954 1003
 
955 1004
 			// Try to stop a timeout, this would be bad...
956 1005
 			@set_time_limit(300);
957
-			if (function_exists('apache_reset_timeout'))
958
-				@apache_reset_timeout();
1006
+			if (function_exists('apache_reset_timeout')) {
1007
+							@apache_reset_timeout();
1008
+			}
1009
+		} else {
1010
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
959 1011
 		}
960
-		else
961
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
962 1012
 
963 1013
 		// Hopefully it sent?
964
-		if (!$result)
965
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1014
+		if (!$result) {
1015
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1016
+		}
966 1017
 	}
967 1018
 
968 1019
 	// Any emails that didn't send?
@@ -977,8 +1028,8 @@  discard block
 block discarded – undo
977 1028
 		);
978 1029
 
979 1030
 		// If we have failed to many times, tell mail to wait a bit and try again.
980
-		if ($modSettings['mail_failed_attempts'] > 5)
981
-			$smcFunc['db_query']('', '
1031
+		if ($modSettings['mail_failed_attempts'] > 5) {
1032
+					$smcFunc['db_query']('', '
982 1033
 				UPDATE {db_prefix}settings
983 1034
 				SET value = {string:next_mail_send}
984 1035
 				WHERE variable = {literal:mail_next_send}
@@ -987,6 +1038,7 @@  discard block
 block discarded – undo
987 1038
 					'next_mail_send' => time() + 60,
988 1039
 					'last_send' => $modSettings['mail_next_send'],
989 1040
 			));
1041
+		}
990 1042
 
991 1043
 		// Add our email back to the queue, manually.
992 1044
 		$smcFunc['db_insert']('insert',
@@ -999,8 +1051,8 @@  discard block
 block discarded – undo
999 1051
 		return false;
1000 1052
 	}
1001 1053
 	// We where unable to send the email, clear our failed attempts.
1002
-	elseif (!empty($modSettings['mail_failed_attempts']))
1003
-		$smcFunc['db_query']('', '
1054
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1055
+			$smcFunc['db_query']('', '
1004 1056
 			UPDATE {db_prefix}settings
1005 1057
 			SET value = {string:zero}
1006 1058
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1008,6 +1060,7 @@  discard block
 block discarded – undo
1008 1060
 				'zero' => '0',
1009 1061
 				'mail_failed_attempts' => 'mail_failed_attempts',
1010 1062
 		));
1063
+	}
1011 1064
 
1012 1065
 	// Had something to send...
1013 1066
 	return true;
@@ -1024,16 +1077,18 @@  discard block
 block discarded – undo
1024 1077
 	global $modSettings, $smcFunc;
1025 1078
 
1026 1079
 	$task_query = '';
1027
-	if (!is_array($tasks))
1028
-		$tasks = array($tasks);
1080
+	if (!is_array($tasks)) {
1081
+			$tasks = array($tasks);
1082
+	}
1029 1083
 
1030 1084
 	// Actually have something passed?
1031 1085
 	if (!empty($tasks))
1032 1086
 	{
1033
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1034
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1035
-		else
1036
-			$task_query = ' AND task IN ({array_string:tasks})';
1087
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1088
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1089
+		} else {
1090
+					$task_query = ' AND task IN ({array_string:tasks})';
1091
+		}
1037 1092
 	}
1038 1093
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1039 1094
 
@@ -1054,20 +1109,22 @@  discard block
 block discarded – undo
1054 1109
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1055 1110
 
1056 1111
 		// Only bother moving the task if it's out of place or we're forcing it!
1057
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1058
-			$tasks[$row['id_task']] = $next_time;
1059
-		else
1060
-			$next_time = $row['next_time'];
1112
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1113
+					$tasks[$row['id_task']] = $next_time;
1114
+		} else {
1115
+					$next_time = $row['next_time'];
1116
+		}
1061 1117
 
1062 1118
 		// If this is sooner than the current next task, make this the next task.
1063
-		if ($next_time < $nextTaskTime)
1064
-			$nextTaskTime = $next_time;
1119
+		if ($next_time < $nextTaskTime) {
1120
+					$nextTaskTime = $next_time;
1121
+		}
1065 1122
 	}
1066 1123
 	$smcFunc['db_free_result']($request);
1067 1124
 
1068 1125
 	// Now make the changes!
1069
-	foreach ($tasks as $id => $time)
1070
-		$smcFunc['db_query']('', '
1126
+	foreach ($tasks as $id => $time) {
1127
+			$smcFunc['db_query']('', '
1071 1128
 			UPDATE {db_prefix}scheduled_tasks
1072 1129
 			SET next_time = {int:next_time}
1073 1130
 			WHERE id_task = {int:id_task}',
@@ -1076,11 +1133,13 @@  discard block
 block discarded – undo
1076 1133
 				'id_task' => $id,
1077 1134
 			)
1078 1135
 		);
1136
+	}
1079 1137
 
1080 1138
 	// If the next task is now different update.
1081
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1082
-		updateSettings(array('next_task_time' => $nextTaskTime));
1083
-}
1139
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1140
+			updateSettings(array('next_task_time' => $nextTaskTime));
1141
+	}
1142
+	}
1084 1143
 
1085 1144
 /**
1086 1145
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1093,8 +1152,9 @@  discard block
 block discarded – undo
1093 1152
 function next_time($regularity, $unit, $offset)
1094 1153
 {
1095 1154
 	// Just in case!
1096
-	if ($regularity == 0)
1097
-		$regularity = 2;
1155
+	if ($regularity == 0) {
1156
+			$regularity = 2;
1157
+	}
1098 1158
 
1099 1159
 	$curMin = date('i', time());
1100 1160
 
@@ -1104,15 +1164,16 @@  discard block
 block discarded – undo
1104 1164
 		$off = date('i', $offset);
1105 1165
 
1106 1166
 		// If it's now just pretend it ain't,
1107
-		if ($off == $curMin)
1108
-			$next_time = time() + $regularity;
1109
-		else
1167
+		if ($off == $curMin) {
1168
+					$next_time = time() + $regularity;
1169
+		} else
1110 1170
 		{
1111 1171
 			// Make sure that the offset is always in the past.
1112 1172
 			$off = $off > $curMin ? $off - 60 : $off;
1113 1173
 
1114
-			while ($off <= $curMin)
1115
-				$off += $regularity;
1174
+			while ($off <= $curMin) {
1175
+							$off += $regularity;
1176
+			}
1116 1177
 
1117 1178
 			// Now we know when the time should be!
1118 1179
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1132,11 +1193,13 @@  discard block
 block discarded – undo
1132 1193
 		// Default we'll jump in hours.
1133 1194
 		$applyOffset = 3600;
1134 1195
 		// 24 hours = 1 day.
1135
-		if ($unit == 'd')
1136
-			$applyOffset = 86400;
1196
+		if ($unit == 'd') {
1197
+					$applyOffset = 86400;
1198
+		}
1137 1199
 		// Otherwise a week.
1138
-		if ($unit == 'w')
1139
-			$applyOffset = 604800;
1200
+		if ($unit == 'w') {
1201
+					$applyOffset = 604800;
1202
+		}
1140 1203
 
1141 1204
 		$applyOffset *= $regularity;
1142 1205
 
@@ -1173,8 +1236,9 @@  discard block
 block discarded – undo
1173 1236
 		$settings[$row['variable']] = $row['value'];
1174 1237
 
1175 1238
 		// Is this the default theme?
1176
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1177
-			$settings['default_' . $row['variable']] = $row['value'];
1239
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1240
+					$settings['default_' . $row['variable']] = $row['value'];
1241
+		}
1178 1242
 	}
1179 1243
 	$smcFunc['db_free_result']($result);
1180 1244
 
@@ -1184,12 +1248,14 @@  discard block
 block discarded – undo
1184 1248
 		$settings['template_dirs'] = array($settings['theme_dir']);
1185 1249
 
1186 1250
 		// Based on theme (if there is one).
1187
-		if (!empty($settings['base_theme_dir']))
1188
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1251
+		if (!empty($settings['base_theme_dir'])) {
1252
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1253
+		}
1189 1254
 
1190 1255
 		// Lastly the default theme.
1191
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1192
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1256
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1257
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1258
+		}
1193 1259
 	}
1194 1260
 
1195 1261
 	// Assume we want this.
@@ -1333,8 +1399,9 @@  discard block
 block discarded – undo
1333 1399
 	// Ok should we prune the logs?
1334 1400
 	if (!empty($modSettings['pruningOptions']))
1335 1401
 	{
1336
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1337
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1402
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1403
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1404
+		}
1338 1405
 
1339 1406
 		if (!empty($modSettings['pruneErrorLog']))
1340 1407
 		{
@@ -1400,8 +1467,9 @@  discard block
 block discarded – undo
1400 1467
 				)
1401 1468
 			);
1402 1469
 
1403
-			while ($row = $smcFunc['db_fetch_row']($result))
1404
-				$reports[] = $row[0];
1470
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1471
+							$reports[] = $row[0];
1472
+			}
1405 1473
 
1406 1474
 			$smcFunc['db_free_result']($result);
1407 1475
 
@@ -1486,8 +1554,9 @@  discard block
 block discarded – undo
1486 1554
 	);
1487 1555
 
1488 1556
 	// Run Cache housekeeping
1489
-	if (!empty($cache_enable) && !empty($cacheAPI))
1490
-		$cacheAPI->housekeeping();
1557
+	if (!empty($cache_enable) && !empty($cacheAPI)) {
1558
+			$cacheAPI->housekeeping();
1559
+	}
1491 1560
 
1492 1561
 	// Prevent stale minimized CSS and JavaScript from cluttering up the theme directories
1493 1562
 	deleteAllMinified();
@@ -1570,8 +1639,9 @@  discard block
 block discarded – undo
1570 1639
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1571 1640
 
1572 1641
 		// Send the actual email.
1573
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1574
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1642
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1643
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1644
+		}
1575 1645
 
1576 1646
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1577 1647
 		{
@@ -1594,18 +1664,19 @@  discard block
 block discarded – undo
1594 1664
 	}
1595 1665
 
1596 1666
 	// Insert the alerts if any
1597
-	if (!empty($alert_rows))
1598
-		$smcFunc['db_insert']('',
1667
+	if (!empty($alert_rows)) {
1668
+			$smcFunc['db_insert']('',
1599 1669
 			'{db_prefix}user_alerts',
1600 1670
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1601 1671
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1602 1672
 			$alert_rows,
1603 1673
 			array()
1604 1674
 		);
1675
+	}
1605 1676
 
1606 1677
 	// Mark the reminder as sent.
1607
-	if (!empty($subs_reminded))
1608
-		$smcFunc['db_query']('', '
1678
+	if (!empty($subs_reminded)) {
1679
+			$smcFunc['db_query']('', '
1609 1680
 			UPDATE {db_prefix}log_subscribed
1610 1681
 			SET reminder_sent = {int:reminder_sent}
1611 1682
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1614,6 +1685,7 @@  discard block
 block discarded – undo
1614 1685
 				'reminder_sent' => 1,
1615 1686
 			)
1616 1687
 		);
1688
+	}
1617 1689
 
1618 1690
 	return true;
1619 1691
 }
@@ -1629,13 +1701,13 @@  discard block
 block discarded – undo
1629 1701
 	// We need to know where this thing is going.
1630 1702
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1631 1703
 	{
1632
-		if (!is_array($modSettings['attachmentUploadDir']))
1633
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1704
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1705
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1706
+		}
1634 1707
 
1635 1708
 		// Just use the current path for temp files.
1636 1709
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1637
-	}
1638
-	else
1710
+	} else
1639 1711
 	{
1640 1712
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1641 1713
 	}
@@ -1654,14 +1726,16 @@  discard block
 block discarded – undo
1654 1726
 
1655 1727
 		while ($file = readdir($dir))
1656 1728
 		{
1657
-			if ($file == '.' || $file == '..')
1658
-				continue;
1729
+			if ($file == '.' || $file == '..') {
1730
+							continue;
1731
+			}
1659 1732
 
1660 1733
 			if (strpos($file, 'post_tmp_') !== false)
1661 1734
 			{
1662 1735
 				// Temp file is more than 5 hours old!
1663
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1664
-					@unlink($attach_dir . '/' . $file);
1736
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1737
+									@unlink($attach_dir . '/' . $file);
1738
+				}
1665 1739
 			}
1666 1740
 		}
1667 1741
 		closedir($dir);
@@ -1694,8 +1768,9 @@  discard block
 block discarded – undo
1694 1768
 		)
1695 1769
 	);
1696 1770
 
1697
-	while ($row = $smcFunc['db_fetch_row']($request))
1698
-		$topics[] = $row[0];
1771
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1772
+			$topics[] = $row[0];
1773
+	}
1699 1774
 	$smcFunc['db_free_result']($request);
1700 1775
 
1701 1776
 	// Zap, your gone
@@ -1715,8 +1790,9 @@  discard block
 block discarded – undo
1715 1790
 {
1716 1791
 	global $smcFunc, $sourcedir, $modSettings;
1717 1792
 
1718
-	if (empty($modSettings['drafts_keep_days']))
1719
-		return true;
1793
+	if (empty($modSettings['drafts_keep_days'])) {
1794
+			return true;
1795
+	}
1720 1796
 
1721 1797
 	// init
1722 1798
 	$drafts = array();
@@ -1734,8 +1810,9 @@  discard block
 block discarded – undo
1734 1810
 		)
1735 1811
 	);
1736 1812
 
1737
-	while ($row = $smcFunc['db_fetch_row']($request))
1738
-		$drafts[] = (int) $row[0];
1813
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1814
+			$drafts[] = (int) $row[0];
1815
+	}
1739 1816
 	$smcFunc['db_free_result']($request);
1740 1817
 
1741 1818
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Themes/default/Post.template.php 1 patch
Braces   +108 added lines, -73 removed lines patch added patch discarded remove patch
@@ -22,24 +22,26 @@  discard block
 block discarded – undo
22 22
 		<script>';
23 23
 
24 24
 	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
-	if (isBrowser('is_firefox'))
26
-		echo '
25
+	if (isBrowser('is_firefox')) {
26
+			echo '
27 27
 			window.addEventListener("pageshow", reActivate, false);';
28
+	}
28 29
 
29 30
 	// Start with message icons - and any missing from this theme.
30 31
 	echo '
31 32
 			var icon_urls = {';
32 33
 
33
-	foreach ($context['icons'] as $icon)
34
-		echo '
34
+	foreach ($context['icons'] as $icon) {
35
+			echo '
35 36
 				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
37
+	}
36 38
 
37 39
 	echo '
38 40
 			};';
39 41
 
40 42
 	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
41
-	if ($context['make_poll'])
42
-		echo '
43
+	if ($context['make_poll']) {
44
+			echo '
43 45
 			var pollOptionNum = 0, pollTabIndex;
44 46
 			var pollOptionId = ', $context['last_choice_id'], ';
45 47
 			function addPollOption()
@@ -58,11 +60,13 @@  discard block
 block discarded – undo
58 60
 
59 61
 				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('"></dd><p id="pollMoreOptions"></p>'), ');
60 62
 			}';
63
+	}
61 64
 
62 65
 	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
63
-	if ($context['make_event'])
64
-		echo '
66
+	if ($context['make_event']) {
67
+			echo '
65 68
 			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
69
+	}
66 70
 
67 71
 	// End of the javascript, start the form and display the link tree.
68 72
 	echo '
@@ -83,9 +87,10 @@  discard block
 block discarded – undo
83 87
 			</div>
84 88
 			<br>';
85 89
 
86
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
87
-		echo '
90
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) {
91
+			echo '
88 92
 			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
93
+	}
89 94
 
90 95
 	// Start the main table.
91 96
 	echo '
@@ -110,26 +115,29 @@  discard block
 block discarded – undo
110 115
 					</div>';
111 116
 
112 117
 	// If this won't be approved let them know!
113
-	if (!$context['becomes_approved'])
114
-		echo '
118
+	if (!$context['becomes_approved']) {
119
+			echo '
115 120
 					<div class="noticebox">
116 121
 						<em>', $txt['wait_for_approval'], '</em>
117 122
 						<input type="hidden" name="not_approved" value="1">
118 123
 					</div>';
124
+	}
119 125
 
120 126
 	// If it's locked, show a message to warn the replier.
121
-	if (!empty($context['locked']))
122
-	echo '
127
+	if (!empty($context['locked'])) {
128
+		echo '
123 129
 					<div class="errorbox">
124 130
 						', $txt['topic_locked_no_reply'], '
125 131
 					</div>';
132
+	}
126 133
 
127
-	if (!empty($modSettings['drafts_post_enabled']))
128
-		echo '
134
+	if (!empty($modSettings['drafts_post_enabled'])) {
135
+			echo '
129 136
 					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
130 137
 						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
131 138
 						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
132 139
 					</div>';
140
+	}
133 141
 
134 142
 	// The post header... important stuff
135 143
 	echo '
@@ -139,14 +147,15 @@  discard block
 block discarded – undo
139 147
 	// Mod & theme authors can use the 'integrate_post_end' hook to modify or add to these (see Post.php)
140 148
 	if (!empty($context['posting_fields']) && is_array($context['posting_fields']))
141 149
 	{
142
-		foreach ($context['posting_fields'] as $pfid => $pf)
143
-			echo '
150
+		foreach ($context['posting_fields'] as $pfid => $pf) {
151
+					echo '
144 152
 						<dt class="clear', !is_numeric($pfid) ? ' pf_' . $pfid : '', '">
145 153
 							', $pf['dt'], '
146 154
 						</dt>
147 155
 						<dd', !is_numeric($pfid) ? ' class="pf_' . $pfid . '"' : '', '>
148 156
 							', preg_replace('~<(input|select|textarea|button|area|a|object)\b~', '<$1 tabindex="' . $context['tabindex']++ . '"', $pf['dd']), '
149 157
 						</dd>';
158
+		}
150 159
 	}
151 160
 
152 161
 	echo '
@@ -180,9 +189,10 @@  discard block
 block discarded – undo
180 189
 				echo '
181 190
 										<optgroup label="', $category['name'], '">';
182 191
 
183
-				foreach ($category['boards'] as $board)
184
-					echo '
192
+				foreach ($category['boards'] as $board) {
193
+									echo '
185 194
 											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
195
+				}
186 196
 				echo '
187 197
 										</optgroup>';
188 198
 			}
@@ -218,9 +228,10 @@  discard block
 block discarded – undo
218 228
 									<span class="label">', $txt['calendar_timezone'], '</span>
219 229
 									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
220 230
 
221
-		foreach ($context['all_timezones'] as $tz => $tzname)
222
-			echo '
231
+		foreach ($context['all_timezones'] as $tz => $tzname) {
232
+					echo '
223 233
 										<option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
234
+		}
224 235
 
225 236
 		echo '
226 237
 									</select>
@@ -249,14 +260,15 @@  discard block
 block discarded – undo
249 260
 								</dd>';
250 261
 
251 262
 		// Loop through all the choices and print them out.
252
-		foreach ($context['choices'] as $choice)
253
-			echo '
263
+		foreach ($context['choices'] as $choice) {
264
+					echo '
254 265
 								<dt>
255 266
 									<label for="options-', $choice['id'], '">', $txt['option'], ' ', $choice['number'], '</label>:
256 267
 								</dt>
257 268
 								<dd>
258 269
 									<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="255">
259 270
 								</dd>';
271
+		}
260 272
 
261 273
 		echo '
262 274
 								<p id="pollMoreOptions"></p>
@@ -286,14 +298,15 @@  discard block
 block discarded – undo
286 298
 									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', '>
287 299
 								</dd>';
288 300
 
289
-		if ($context['poll_options']['guest_vote_enabled'])
290
-			echo '
301
+		if ($context['poll_options']['guest_vote_enabled']) {
302
+					echo '
291 303
 								<dt>
292 304
 									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
293 305
 								</dt>
294 306
 								<dd>
295 307
 									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', '>
296 308
 								</dd>';
309
+		}
297 310
 
298 311
 		echo '
299 312
 								<dt>
@@ -314,8 +327,8 @@  discard block
 block discarded – undo
314 327
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
315 328
 
316 329
 	// If we're editing and displaying edit details, show a box where they can say why
317
-	if (isset($context['editing']) && $modSettings['show_modify'])
318
-		echo '
330
+	if (isset($context['editing']) && $modSettings['show_modify']) {
331
+			echo '
319 332
 					<dl>
320 333
 						<dt class="clear">
321 334
 							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
@@ -324,20 +337,23 @@  discard block
 block discarded – undo
324 337
 							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80">
325 338
 						</dd>
326 339
 					</dl>';
340
+	}
327 341
 
328 342
 	// If this message has been edited in the past - display when it was.
329
-	if (isset($context['last_modified']))
330
-		echo '
343
+	if (isset($context['last_modified'])) {
344
+			echo '
331 345
 					<div class="padding smalltext">
332 346
 						', $context['last_modified_text'], '
333 347
 					</div>';
348
+	}
334 349
 
335 350
 	// If the admin has enabled the hiding of the additional options - show a link and image for it.
336
-	if (!empty($modSettings['additional_options_collapsable']))
337
-		echo '
351
+	if (!empty($modSettings['additional_options_collapsable'])) {
352
+			echo '
338 353
 					<div id="postAdditionalOptionsHeader">
339 354
 						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
340 355
 					</div>';
356
+	}
341 357
 
342 358
 	echo '
343 359
 					<div id="postAdditionalOptions">';
@@ -370,19 +386,21 @@  discard block
 block discarded – undo
370 386
 								', $txt['uncheck_unwatchd_attach'], ':
371 387
 							</dd>';
372 388
 
373
-		foreach ($context['current_attachments'] as $attachment)
374
-			echo '
389
+		foreach ($context['current_attachments'] as $attachment) {
390
+					echo '
375 391
 							<dd class="smalltext">
376 392
 								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', '> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
377 393
 								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1024) / 1024), 0)) : '', '</label>
378 394
 							</dd>';
395
+		}
379 396
 
380 397
 		echo '
381 398
 						</dl>';
382 399
 
383
-		if (!empty($context['files_in_session_warning']))
384
-			echo '
400
+		if (!empty($context['files_in_session_warning'])) {
401
+					echo '
385 402
 						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
403
+		}
386 404
 	}
387 405
 
388 406
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
@@ -447,13 +465,14 @@  discard block
 block discarded – undo
447 465
 									<div class="fallback">
448 466
 										<input type="file" multiple="multiple" name="attachment[]" id="attachment1" class="fallback"> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
449 467
 
450
-		if (!empty($modSettings['attachmentSizeLimit']))
451
-			echo '
468
+		if (!empty($modSettings['attachmentSizeLimit'])) {
469
+					echo '
452 470
 										<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1024 . '">';
471
+		}
453 472
 
454 473
 		// Show more boxes if they aren't approaching that limit.
455
-		if ($context['num_allowed_attachments'] > 1)
456
-			echo '
474
+		if ($context['num_allowed_attachments'] > 1) {
475
+					echo '
457 476
 										<script>
458 477
 											var allowed_attachments = ', $context['num_allowed_attachments'], ';
459 478
 											var current_attachment = 1;
@@ -473,6 +492,7 @@  discard block
 block discarded – undo
473 492
 										<a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')</a>
474 493
 									</div><!-- .fallback -->
475 494
 								</div><!-- #attachUpload -->';
495
+		}
476 496
 
477 497
 		echo '
478 498
 							</dd>';
@@ -484,21 +504,25 @@  discard block
 block discarded – undo
484 504
 							<dd class="smalltext">';
485 505
 
486 506
 		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
487
-		if (!empty($modSettings['attachmentCheckExtensions']))
488
-			echo '
507
+		if (!empty($modSettings['attachmentCheckExtensions'])) {
508
+					echo '
489 509
 								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
510
+		}
490 511
 
491
-		if (!empty($context['attachment_restrictions']))
492
-			echo '
512
+		if (!empty($context['attachment_restrictions'])) {
513
+					echo '
493 514
 								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
515
+		}
494 516
 
495
-		if ($context['num_allowed_attachments'] == 0)
496
-			echo '
517
+		if ($context['num_allowed_attachments'] == 0) {
518
+					echo '
497 519
 								', $txt['attach_limit_nag'], '<br>';
520
+		}
498 521
 
499
-		if (!$context['can_post_attachment_unapproved'])
500
-			echo '
522
+		if (!$context['can_post_attachment_unapproved']) {
523
+					echo '
501 524
 								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
525
+		}
502 526
 
503 527
 		echo '
504 528
 							</dd>
@@ -522,24 +546,26 @@  discard block
 block discarded – undo
522 546
 							<dt><strong>', $txt['subject'], '</strong></dt>
523 547
 							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
524 548
 
525
-		foreach ($context['drafts'] as $draft)
526
-			echo '
549
+		foreach ($context['drafts'] as $draft) {
550
+					echo '
527 551
 							<dt>', $draft['link'], '</dt>
528 552
 							<dd>', $draft['poster_time'], '</dd>';
553
+		}
529 554
 		echo '
530 555
 						</dl>
531 556
 					</div>';
532 557
 	}
533 558
 
534 559
 	// Is visual verification enabled?
535
-	if ($context['require_verification'])
536
-		echo '
560
+	if ($context['require_verification']) {
561
+			echo '
537 562
 					<div class="post_verification">
538 563
 						<span', !empty($context['post_error']['need_qr_verification']) ? ' class="error"' : '', '>
539 564
 							<strong>', $txt['verification'], ':</strong>
540 565
 						</span>
541 566
 						', template_control_verification($context['visual_verification_id'], 'all'), '
542 567
 					</div>';
568
+	}
543 569
 
544 570
 	// Finally, the submit buttons.
545 571
 	echo '
@@ -548,9 +574,10 @@  discard block
 block discarded – undo
548 574
 						', template_control_richedit_buttons($context['post_box_name']);
549 575
 
550 576
 	// Option to delete an event if user is editing one.
551
-	if ($context['make_event'] && !$context['event']['new'])
552
-		echo '
577
+	if ($context['make_event'] && !$context['event']['new']) {
578
+			echo '
553 579
 						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button you_sure">';
580
+	}
554 581
 
555 582
 	echo '
556 583
 					</span>
@@ -559,9 +586,10 @@  discard block
 block discarded – undo
559 586
 			<br class="clear">';
560 587
 
561 588
 	// Assuming this isn't a new topic pass across the last message id.
562
-	if (isset($context['topic_last_message']))
563
-		echo '
589
+	if (isset($context['topic_last_message'])) {
590
+			echo '
564 591
 			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
592
+	}
565 593
 
566 594
 	echo '
567 595
 			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
@@ -704,9 +732,10 @@  discard block
 block discarded – undo
704 732
 
705 733
 						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
706 734
 
707
-	if ($context['can_quote'])
708
-		echo '
735
+	if ($context['can_quote']) {
736
+			echo '
709 737
 						newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';';
738
+	}
710 739
 
711 740
 	echo '
712 741
 						newPostsHTML += \'<br class="clear">\';
@@ -749,8 +778,8 @@  discard block
 block discarded – undo
749 778
 			}';
750 779
 
751 780
 	// Code for showing and hiding additional options.
752
-	if (!empty($modSettings['additional_options_collapsable']))
753
-		echo '
781
+	if (!empty($modSettings['additional_options_collapsable'])) {
782
+			echo '
754 783
 			var oSwapAdditionalOptions = new smc_Toggle({
755 784
 				bToggleEnabled: true,
756 785
 				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
@@ -778,10 +807,11 @@  discard block
 block discarded – undo
778 807
 					}
779 808
 				]
780 809
 			});';
810
+	}
781 811
 
782 812
 	// Code for showing and hiding drafts
783
-	if (!empty($context['drafts']))
784
-		echo '
813
+	if (!empty($context['drafts'])) {
814
+			echo '
785 815
 			var oSwapDraftOptions = new smc_Toggle({
786 816
 				bToggleEnabled: true,
787 817
 				bCurrentlyCollapsed: true,
@@ -803,6 +833,7 @@  discard block
 block discarded – undo
803 833
 					}
804 834
 				]
805 835
 			});';
836
+	}
806 837
 
807 838
 	echo '
808 839
 			var oEditorID = "', $context['post_box_name'] ,'";
@@ -823,8 +854,9 @@  discard block
 block discarded – undo
823 854
 		foreach ($context['previous_posts'] as $post)
824 855
 		{
825 856
 			$ignoring = false;
826
-			if (!empty($post['is_ignored']))
827
-				$ignored_posts[] = $ignoring = $post['id'];
857
+			if (!empty($post['is_ignored'])) {
858
+							$ignored_posts[] = $ignoring = $post['id'];
859
+			}
828 860
 
829 861
 			echo '
830 862
 			<div class="windowbg">
@@ -834,22 +866,24 @@  discard block
 block discarded – undo
834 866
 					</h5>
835 867
 					&nbsp;-&nbsp;', $post['time'];
836 868
 
837
-			if ($context['can_quote'])
838
-				echo '
869
+			if ($context['can_quote']) {
870
+							echo '
839 871
 					<ul class="quickbuttons" id="msg_', $post['id'], '_quote">
840 872
 						<li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>
841 873
 						<li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');"><span class="generic_icons quote"></span>', $txt['quote'], '</a></li>
842 874
 					</ul>';
875
+			}
843 876
 
844 877
 			echo '
845 878
 					<br class="clear">';
846 879
 
847
-			if ($ignoring)
848
-				echo '
880
+			if ($ignoring) {
881
+							echo '
849 882
 					<div id="msg_', $post['id'], '_ignored_prompt" class="smalltext">
850 883
 						', $txt['ignoring_user'], '
851 884
 						<a href="#" id="msg_', $post['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
852 885
 					</div>';
886
+			}
853 887
 
854 888
 			echo '
855 889
 					<div class="list_posts smalltext" id="msg_', $post['id'], '_body" data-msgid="', $post['id'], '">', $post['message'], '</div>
@@ -1004,10 +1038,10 @@  discard block
 block discarded – undo
1004 1038
 		<div id="temporary_posting_area" style="display: none;"></div>
1005 1039
 		<script>';
1006 1040
 
1007
-	if ($context['close_window'])
1008
-		echo '
1041
+	if ($context['close_window']) {
1042
+			echo '
1009 1043
 			window.close();';
1010
-	else
1044
+	} else
1011 1045
 	{
1012 1046
 		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;)
1013 1047
 		echo '
@@ -1061,11 +1095,12 @@  discard block
 block discarded – undo
1061 1095
 				</p>
1062 1096
 				<ul>';
1063 1097
 
1064
-	foreach ($context['groups'] as $group)
1065
-		echo '
1098
+	foreach ($context['groups'] as $group) {
1099
+			echo '
1066 1100
 					<li>
1067 1101
 						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
1068 1102
 					</li>';
1103
+	}
1069 1104
 
1070 1105
 	echo '
1071 1106
 					<li>
Please login to merge, or discard this patch.
Themes/default/MessageIndex.template.php 1 patch
Braces   +103 added lines, -72 removed lines patch added patch discarded remove patch
@@ -18,11 +18,12 @@  discard block
 block discarded – undo
18 18
 	global $context, $settings, $options, $scripturl, $modSettings, $txt;
19 19
 
20 20
 	// Let them know why their message became unapproved.
21
-	if ($context['becomesUnapproved'])
22
-		echo '
21
+	if ($context['becomesUnapproved']) {
22
+			echo '
23 23
 	<div class="noticebox">
24 24
 		', $txt['post_becomesUnapproved'], '
25 25
 	</div>';
26
+	}
26 27
 
27 28
 	if (!empty($context['boards']) && (!empty($options['show_children']) || $context['start'] == 0))
28 29
 	{
@@ -46,17 +47,19 @@  discard block
 block discarded – undo
46 47
 				</a>';
47 48
 
48 49
 			// Has it outstanding posts for approval?
49
-			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
50
-				echo '
50
+			if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) {
51
+							echo '
51 52
 				<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
53
+			}
52 54
 
53 55
 			echo '
54 56
 				<p class="board_description">', $board['description'], '</p>';
55 57
 
56 58
 			// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
57
-			if (!empty($board['moderators']) || !empty($board['moderator_groups']))
58
-				echo '
59
+			if (!empty($board['moderators']) || !empty($board['moderator_groups'])) {
60
+							echo '
59 61
 				<p class="moderators">', count($board['link_moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>';
62
+			}
60 63
 
61 64
 			// Show some basic information about the number of posts, etc.
62 65
 			echo '
@@ -68,9 +71,10 @@  discard block
 block discarded – undo
68 71
 			</div>
69 72
 			<div class="lastpost lpr_border">';
70 73
 
71
-			if (!empty($board['last_post']['id']))
72
-				echo '
74
+			if (!empty($board['last_post']['id'])) {
75
+							echo '
73 76
 				<p>', $board['last_post']['last_post_message'], '</p>';
77
+			}
74 78
 
75 79
 			echo '
76 80
 			</div>';
@@ -84,14 +88,16 @@  discard block
 block discarded – undo
84 88
 					id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */
85 89
 				foreach ($board['children'] as $child)
86 90
 				{
87
-					if (!$child['is_redirect'])
88
-						$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')" class="new_posts">' . $txt['new'] . '</a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
89
-					else
90
-						$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
91
+					if (!$child['is_redirect']) {
92
+											$child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')" class="new_posts">' . $txt['new'] . '</a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>';
93
+					} else {
94
+											$child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>';
95
+					}
91 96
 
92 97
 					// Has it posts awaiting approval?
93
-					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics']))
94
-						$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
98
+					if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) {
99
+											$child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>';
100
+					}
95 101
 
96 102
 					$children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>';
97 103
 				}
@@ -113,11 +119,12 @@  discard block
 block discarded – undo
113 119
 	if (!$context['no_topic_listing'])
114 120
 	{
115 121
 		// Mobile action buttons (top)
116
-		if (!empty($context['normal_buttons']))
117
-		echo '
122
+		if (!empty($context['normal_buttons'])) {
123
+				echo '
118 124
 	<div class="mobile_buttons floatright">
119 125
 		<a class="button mobile_act">', $txt['mobile_action'], '</a>
120 126
 	</div>';
127
+		}
121 128
 
122 129
 		echo '
123 130
 	<div class="pagesection">
@@ -136,13 +143,15 @@  discard block
 block discarded – undo
136 143
 		<h3>', $context['name'], '</h3>
137 144
 		<p>';
138 145
 
139
-			if ($context['description'] != '')
140
-				echo '
146
+			if ($context['description'] != '') {
147
+							echo '
141 148
 			', $context['description'];
149
+			}
142 150
 
143
-			if (!empty($context['moderators']))
144
-				echo '
151
+			if (!empty($context['moderators'])) {
152
+							echo '
145 153
 			', count($context['moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $context['link_moderators']), '.';
154
+			}
146 155
 
147 156
 			echo '
148 157
 		</p>
@@ -150,9 +159,10 @@  discard block
 block discarded – undo
150 159
 		}
151 160
 
152 161
 		// If Quick Moderation is enabled start the form.
153
-		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics']))
154
-			echo '
162
+		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) {
163
+					echo '
155 164
 	<form action="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '" class="clear" name="quickModForm" id="quickModForm">';
165
+		}
156 166
 
157 167
 		echo '
158 168
 		<div id="messageindex">';
@@ -162,11 +172,11 @@  discard block
 block discarded – undo
162 172
 			echo '
163 173
 			<div class="information">';
164 174
 
165
-			if ($settings['display_who_viewing'] == 1)
166
-				echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
167
-
168
-			else
169
-				echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
175
+			if ($settings['display_who_viewing'] == 1) {
176
+							echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
177
+			} else {
178
+							echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
179
+			}
170 180
 			echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board'];
171 181
 
172 182
 		echo '
@@ -186,32 +196,36 @@  discard block
 block discarded – undo
186 196
 				<div class="lastpost">', $context['topics_headers']['last_post'], '</div>';
187 197
 
188 198
 			// Show a "select all" box for quick moderation?
189
-			if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
190
-				echo '
199
+			if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) {
200
+							echo '
191 201
 				<div class="moderation">
192 202
 					<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
193 203
 				</div>';
204
+			}
194 205
 
195 206
 			// If it's on in "image" mode, don't show anything but the column.
196
-			elseif (!empty($context['can_quick_mod']))
197
-				echo '
207
+			elseif (!empty($context['can_quick_mod'])) {
208
+							echo '
198 209
 				<div class="moderation"></div>';
210
+			}
199 211
 		}
200 212
 
201 213
 		// No topics... just say, "sorry bub".
202
-		else
203
-			echo '
214
+		else {
215
+					echo '
204 216
 				<h3 class="titlebg">', $txt['topic_alert_none'], '</h3>';
217
+		}
205 218
 
206 219
 		echo '
207 220
 			</div><!-- #topic_header -->';
208 221
 
209 222
 		// If this person can approve items and we have some awaiting approval tell them.
210
-		if (!empty($context['unapproved_posts_message']))
211
-			echo '
223
+		if (!empty($context['unapproved_posts_message'])) {
224
+					echo '
212 225
 			<div class="information">
213 226
 				<span class="alert">!</span> ', $context['unapproved_posts_message'], '
214 227
 			</div>';
228
+		}
215 229
 
216 230
 		// Contain the topic list
217 231
 		echo '
@@ -232,25 +246,30 @@  discard block
 block discarded – undo
232 246
 			echo '
233 247
 							<div class="icons floatright">';
234 248
 
235
-			if ($topic['is_watched'])
236
-				echo '
249
+			if ($topic['is_watched']) {
250
+							echo '
237 251
 								<span class="generic_icons watch" title="', $txt['watching_this_topic'], '"></span>';
252
+			}
238 253
 
239
-			if ($topic['is_locked'])
240
-				echo '
254
+			if ($topic['is_locked']) {
255
+							echo '
241 256
 								<span class="generic_icons lock"></span>';
257
+			}
242 258
 
243
-			if ($topic['is_sticky'])
244
-				echo '
259
+			if ($topic['is_sticky']) {
260
+							echo '
245 261
 								<span class="generic_icons sticky"></span>';
262
+			}
246 263
 
247
-			if ($topic['is_redirect'])
248
-				echo '
264
+			if ($topic['is_redirect']) {
265
+							echo '
249 266
 								<span class="generic_icons move"></span>';
267
+			}
250 268
 
251
-			if ($topic['is_poll'])
252
-				echo '
269
+			if ($topic['is_poll']) {
270
+							echo '
253 271
 								<span class="generic_icons poll"></span>';
272
+			}
254 273
 
255 274
 			echo '
256 275
 							</div>';
@@ -282,26 +301,31 @@  discard block
 block discarded – undo
282 301
 				echo '
283 302
 					<div class="moderation">';
284 303
 
285
-				if ($options['display_quick_mod'] == 1)
286
-					echo '
304
+				if ($options['display_quick_mod'] == 1) {
305
+									echo '
287 306
 						<input type="checkbox" name="topics[]" value="', $topic['id'], '">';
288
-				else
307
+				} else
289 308
 				{
290 309
 					// Check permissions on each and show only the ones they are allowed to use.
291
-					if ($topic['quick_mod']['remove'])
292
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
310
+					if ($topic['quick_mod']['remove']) {
311
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>';
312
+					}
293 313
 
294
-					if ($topic['quick_mod']['lock'])
295
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
314
+					if ($topic['quick_mod']['lock']) {
315
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>';
316
+					}
296 317
 
297
-					if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
298
-						echo '<br>';
318
+					if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) {
319
+											echo '<br>';
320
+					}
299 321
 
300
-					if ($topic['quick_mod']['sticky'])
301
-						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
322
+					if ($topic['quick_mod']['sticky']) {
323
+											echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>';
324
+					}
302 325
 
303
-					if ($topic['quick_mod']['move'])
304
-						echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
326
+					if ($topic['quick_mod']['move']) {
327
+											echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
328
+					}
305 329
 				}
306 330
 				echo '
307 331
 					</div><!-- .moderation -->';
@@ -319,18 +343,20 @@  discard block
 block discarded – undo
319 343
 				<select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
320 344
 					<option value="">--------</option>';
321 345
 
322
-			foreach ($context['qmod_actions'] as $qmod_action)
323
-				if ($context['can_' . $qmod_action])
346
+			foreach ($context['qmod_actions'] as $qmod_action) {
347
+							if ($context['can_' . $qmod_action])
324 348
 					echo '
325 349
 					<option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>';
350
+			}
326 351
 
327 352
 			echo '
328 353
 				</select>';
329 354
 
330 355
 			// Show a list of boards they can move the topic to.
331
-			if ($context['can_move'])
332
-				echo '
356
+			if ($context['can_move']) {
357
+							echo '
333 358
 				<span id="quick_mod_jump_to"></span>';
359
+			}
334 360
 
335 361
 			echo '
336 362
 				<input type="submit" value="', $txt['quick_mod_go'], '" onclick="return document.forms.quickModForm.qaction.value != \'\' &amp;&amp; confirm(\'', $txt['quickmod_confirm'], '\');" class="button qaction">
@@ -341,17 +367,19 @@  discard block
 block discarded – undo
341 367
 		</div><!-- #messageindex -->';
342 368
 
343 369
 		// Finish off the form - again.
344
-		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics']))
345
-			echo '
370
+		if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) {
371
+					echo '
346 372
 		<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '">
347 373
 	</form>';
374
+		}
348 375
 
349 376
 		// Mobile action buttons (bottom)
350
-		if (!empty($context['normal_buttons']))
351
-		echo '
377
+		if (!empty($context['normal_buttons'])) {
378
+				echo '
352 379
 	<div class="mobile_buttons floatright">
353 380
 		<a class="button mobile_act">', $txt['mobile_action'], '</a>
354 381
 	</div>';
382
+		}
355 383
 
356 384
 		echo '
357 385
 	<div class="pagesection">
@@ -367,8 +395,8 @@  discard block
 block discarded – undo
367 395
 	// Show breadcrumbs at the bottom too.
368 396
 	theme_linktree();
369 397
 
370
-	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move'])
371
-		echo '
398
+	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) {
399
+			echo '
372 400
 	<script>
373 401
 		if (typeof(window.XMLHttpRequest) != "undefined")
374 402
 			aJumpTo[aJumpTo.length] = new JumpTo({
@@ -387,6 +415,7 @@  discard block
 block discarded – undo
387 415
 				sCustomName: "move_to"
388 416
 			});
389 417
 	</script>';
418
+	}
390 419
 
391 420
 	// Javascript for inline editing.
392 421
 	echo '
@@ -423,8 +452,8 @@  discard block
 block discarded – undo
423 452
 		<div class="information">
424 453
 			<p class="floatright" id="message_index_jump_to"></p>';
425 454
 
426
-	if (empty($context['no_topic_listing']))
427
-		echo '
455
+	if (empty($context['no_topic_listing'])) {
456
+			echo '
428 457
 			<p class="floatleft">', !empty($modSettings['enableParticipation']) && $context['user']['is_logged'] ? '
429 458
 				<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="" class="centericon"> ' . $txt['participation_caption'] . '<br>' : '', '
430 459
 				'. ($modSettings['pollMode'] == '1' ? '<span class="generic_icons poll centericon"></span> ' . $txt['poll'] : '') . '<br>
@@ -434,9 +463,10 @@  discard block
 block discarded – undo
434 463
 				<span class="generic_icons lock centericon"></span> ' . $txt['locked_topic'] . '<br>
435 464
 				<span class="generic_icons sticky centericon"></span> ' . $txt['sticky_topic'] . '<br>
436 465
 			</p>';
466
+	}
437 467
 
438
-	if (!empty($context['jump_to']))
439
-		echo '
468
+	if (!empty($context['jump_to'])) {
469
+			echo '
440 470
 			<script>
441 471
 				if (typeof(window.XMLHttpRequest) != "undefined")
442 472
 					aJumpTo[aJumpTo.length] = new JumpTo({
@@ -452,6 +482,7 @@  discard block
 block discarded – undo
452 482
 						sGoButtonLabel: "', $txt['quick_mod_go'], '"
453 483
 					});
454 484
 			</script>';
485
+	}
455 486
 
456 487
 	echo '
457 488
 			<br class="clear">
Please login to merge, or discard this patch.
Themes/default/Display.template.php 1 patch
Braces   +254 added lines, -174 removed lines patch added patch discarded remove patch
@@ -18,18 +18,20 @@  discard block
 block discarded – undo
18 18
 	global $context, $settings, $options, $txt, $scripturl, $modSettings;
19 19
 
20 20
 	// Let them know, if their report was a success!
21
-	if ($context['report_sent'])
22
-		echo '
21
+	if ($context['report_sent']) {
22
+			echo '
23 23
 		<div class="infobox">
24 24
 			', $txt['report_sent'], '
25 25
 		</div>';
26
+	}
26 27
 
27 28
 	// Let them know why their message became unapproved.
28
-	if ($context['becomesUnapproved'])
29
-		echo '
29
+	if ($context['becomesUnapproved']) {
30
+			echo '
30 31
 		<div class="noticebox">
31 32
 			', $txt['post_becomesUnapproved'], '
32 33
 		</div>';
34
+	}
33 35
 
34 36
 	// Show new topic info here?
35 37
 	echo '
@@ -49,11 +51,13 @@  discard block
 block discarded – undo
49 51
 			<p>';
50 52
 
51 53
 		// Show just numbers...?
52
-		if ($settings['display_who_viewing'] == 1)
53
-			echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
54
+		if ($settings['display_who_viewing'] == 1) {
55
+					echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
56
+		}
54 57
 		// Or show the actual people viewing the topic?
55
-		else
56
-			echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
58
+		else {
59
+					echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
60
+		}
57 61
 
58 62
 		// Now show how many guests are here too.
59 63
 		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_topic'], '
@@ -91,10 +95,11 @@  discard block
 block discarded – undo
91 95
 						<dt class="', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
92 96
 						<dd class="statsbar generic_bar', $option['voted_this'] ? ' voted' : '', '">';
93 97
 
94
-				if ($context['allow_results_view'])
95
-					echo '
98
+				if ($context['allow_results_view']) {
99
+									echo '
96 100
 							', $option['bar_ndt'], '
97 101
 							<span class="percentage">', $option['votes'], ' (', $option['percent'], '%)</span>';
102
+				}
98 103
 
99 104
 				echo '
100 105
 						</dd>';
@@ -103,9 +108,10 @@  discard block
 block discarded – undo
103 108
 			echo '
104 109
 					</dl>';
105 110
 
106
-			if ($context['allow_results_view'])
107
-				echo '
111
+			if ($context['allow_results_view']) {
112
+							echo '
108 113
 					<p><strong>', $txt['poll_total_voters'], ':</strong> ', $context['poll']['total_votes'], '</p>';
114
+			}
109 115
 		}
110 116
 		// They are allowed to vote! Go to it!
111 117
 		else
@@ -114,17 +120,19 @@  discard block
 block discarded – undo
114 120
 					<form action="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" accept-charset="', $context['character_set'], '">';
115 121
 
116 122
 			// Show a warning if they are allowed more than one option.
117
-			if ($context['poll']['allowed_warning'])
118
-				echo '
123
+			if ($context['poll']['allowed_warning']) {
124
+							echo '
119 125
 						<p class="smallpadding">', $context['poll']['allowed_warning'], '</p>';
126
+			}
120 127
 
121 128
 			echo '
122 129
 						<ul class="options">';
123 130
 
124 131
 			// Show each option with its button - a radio likely.
125
-			foreach ($context['poll']['options'] as $option)
126
-				echo '
132
+			foreach ($context['poll']['options'] as $option) {
133
+							echo '
127 134
 							<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
135
+			}
128 136
 
129 137
 			echo '
130 138
 						</ul>
@@ -136,9 +144,10 @@  discard block
 block discarded – undo
136 144
 		}
137 145
 
138 146
 		// Is the clock ticking?
139
-		if (!empty($context['poll']['expire_time']))
140
-			echo '
147
+		if (!empty($context['poll']['expire_time'])) {
148
+					echo '
141 149
 					<p><strong>', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ':</strong> ', $context['poll']['expire_time'], '</p>';
150
+		}
142 151
 
143 152
 		echo '
144 153
 				</div><!-- #poll_options -->
@@ -168,11 +177,13 @@  discard block
 block discarded – undo
168 177
 				<li>
169 178
 					<strong class="event_title"><a href="', $scripturl, '?action=calendar;event=', $event['id'], '">', $event['title'], '</a></strong>';
170 179
 
171
-			if ($event['can_edit'])
172
-				echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
180
+			if ($event['can_edit']) {
181
+							echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
182
+			}
173 183
 
174
-			if ($event['can_export'])
175
-				echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
184
+			if ($event['can_export']) {
185
+							echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
186
+			}
176 187
 
177 188
 			echo '
178 189
 					<br>';
@@ -180,14 +191,14 @@  discard block
 block discarded – undo
180 191
 			if (!empty($event['allday']))
181 192
 			{
182 193
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
183
-			}
184
-			else
194
+			} else
185 195
 			{
186 196
 				// Display event info relative to user's local timezone
187 197
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
188 198
 
189
-				if ($event['start_date_local'] != $event['end_date_local'])
190
-					echo trim($event['end_date_local']) . ', ';
199
+				if ($event['start_date_local'] != $event['end_date_local']) {
200
+									echo trim($event['end_date_local']) . ', ';
201
+				}
191 202
 
192 203
 				echo trim($event['end_time_local']);
193 204
 
@@ -196,24 +207,28 @@  discard block
 block discarded – undo
196 207
 				{
197 208
 					echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
198 209
 
199
-					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
200
-						echo trim($event['start_date_orig']), ', ';
210
+					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
211
+											echo trim($event['start_date_orig']), ', ';
212
+					}
201 213
 
202 214
 					echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
203 215
 
204
-					if ($event['start_date_orig'] != $event['end_date_orig'])
205
-						echo trim($event['end_date_orig']) . ', ';
216
+					if ($event['start_date_orig'] != $event['end_date_orig']) {
217
+											echo trim($event['end_date_orig']) . ', ';
218
+					}
206 219
 
207 220
 					echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
208 221
 				}
209 222
 				// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
210
-				else
211
-					echo ' ', $event['tz_abbrev'], '</time>';
223
+				else {
224
+									echo ' ', $event['tz_abbrev'], '</time>';
225
+				}
212 226
 			}
213 227
 
214
-			if (!empty($event['location']))
215
-				echo '
228
+			if (!empty($event['location'])) {
229
+							echo '
216 230
 					<br>', $event['location'];
231
+			}
217 232
 
218 233
 			echo '
219 234
 				</li>';
@@ -235,12 +250,13 @@  discard block
 block discarded – undo
235 250
 		</div>';
236 251
 
237 252
 	// Mobile action - moderation buttons (top)
238
-	if (!empty($context['normal_buttons']))
239
-	echo '
253
+	if (!empty($context['normal_buttons'])) {
254
+		echo '
240 255
 		<div class="mobile_buttons floatright">
241 256
 			<a class="button mobile_act">', $txt['mobile_action'], '</a>
242 257
 			', !empty($context['mod_buttons']) ? '<a class="button mobile_mod">' . $txt['mobile_moderation'] . '</a>' : '', '
243 258
 		</div>';
259
+	}
244 260
 
245 261
 	// Show the topic information - icon, subject, etc.
246 262
 	echo '
@@ -251,20 +267,22 @@  discard block
 block discarded – undo
251 267
 	$context['removableMessageIDs'] = array();
252 268
 
253 269
 	// Get all the messages...
254
-	while ($message = $context['get_message']())
255
-		template_single_post($message);
270
+	while ($message = $context['get_message']()) {
271
+			template_single_post($message);
272
+	}
256 273
 
257 274
 	echo '
258 275
 			</form>
259 276
 		</div><!-- #forumposts -->';
260 277
 
261 278
 	// Mobile action - moderation buttons (bottom)
262
-	if (!empty($context['normal_buttons']))
263
-	echo '
279
+	if (!empty($context['normal_buttons'])) {
280
+		echo '
264 281
 		<div class="mobile_buttons floatright">
265 282
 			<a class="button mobile_act">', $txt['mobile_action'], '</a>
266 283
 			', !empty($context['mod_buttons']) ? '<a class="button mobile_mod">' . $txt['mobile_moderation'] . '</a>' : '', '
267 284
 		</div>';
285
+	}
268 286
 
269 287
 	// Show the page index... "Pages: [1]".
270 288
 	echo '
@@ -291,8 +309,9 @@  discard block
 block discarded – undo
291 309
 		<div id="display_jump_to"></div>';
292 310
 
293 311
 	// Show quickreply
294
-	if ($context['can_reply'])
295
-		template_quickreply();
312
+	if ($context['can_reply']) {
313
+			template_quickreply();
314
+	}
296 315
 
297 316
 	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
298 317
 	echo '
@@ -307,8 +326,8 @@  discard block
 block discarded – undo
307 326
 		</div>';
308 327
 
309 328
 	// Show the moderation button & pop (if there is anything to show)
310
-	if (!empty($context['mod_buttons']))
311
-		echo '
329
+	if (!empty($context['mod_buttons'])) {
330
+			echo '
312 331
 		<div id="mobile_moderation" class="popup_container">
313 332
 			<div class="popup_window description">
314 333
 				<div class="popup_heading">
@@ -320,6 +339,7 @@  discard block
 block discarded – undo
320 339
 				</div>
321 340
 			</div>
322 341
 		</div>';
342
+	}
323 343
 
324 344
 	echo '
325 345
 		<script>';
@@ -443,9 +463,10 @@  discard block
 block discarded – undo
443 463
 				});
444 464
 			}';
445 465
 
446
-	if (!empty($context['ignoredMsgs']))
447
-		echo '
466
+	if (!empty($context['ignoredMsgs'])) {
467
+			echo '
448 468
 			ignore_toggles([', implode(', ', $context['ignoredMsgs']), '], ', JavaScriptEscape($txt['show_ignore_user_post']), ');';
469
+	}
449 470
 
450 471
 	echo '
451 472
 		</script>';
@@ -462,8 +483,9 @@  discard block
 block discarded – undo
462 483
 
463 484
 	$ignoring = false;
464 485
 
465
-	if ($message['can_remove'])
466
-		$context['removableMessageIDs'][] = $message['id'];
486
+	if ($message['can_remove']) {
487
+			$context['removableMessageIDs'][] = $message['id'];
488
+	}
467 489
 
468 490
 	// Are we ignoring this message?
469 491
 	if (!empty($message['is_ignored']))
@@ -490,9 +512,10 @@  discard block
 block discarded – undo
490 512
 							<div class="custom_fields_above_member">
491 513
 								<ul class="nolist">';
492 514
 
493
-		foreach ($message['custom_fields']['above_member'] as $custom)
494
-			echo '
515
+		foreach ($message['custom_fields']['above_member'] as $custom) {
516
+					echo '
495 517
 									<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
518
+		}
496 519
 
497 520
 		echo '
498 521
 								</ul>
@@ -503,25 +526,28 @@  discard block
 block discarded – undo
503 526
 							<h4>';
504 527
 
505 528
 	// Show online and offline buttons?
506
-	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
507
-		echo '
529
+	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) {
530
+			echo '
508 531
 								', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', '<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>', $context['can_send_pm'] ? '</a>' : '';
532
+	}
509 533
 
510 534
 	// Custom fields BEFORE the username?
511
-	if (!empty($message['custom_fields']['before_member']))
512
-		foreach ($message['custom_fields']['before_member'] as $custom)
535
+	if (!empty($message['custom_fields']['before_member'])) {
536
+			foreach ($message['custom_fields']['before_member'] as $custom)
513 537
 			echo '
514 538
 								<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
539
+	}
515 540
 
516 541
 	// Show a link to the member's profile.
517 542
 	echo '
518 543
 								', $message['member']['link'];
519 544
 
520 545
 	// Custom fields AFTER the username?
521
-	if (!empty($message['custom_fields']['after_member']))
522
-		foreach ($message['custom_fields']['after_member'] as $custom)
546
+	if (!empty($message['custom_fields']['after_member'])) {
547
+			foreach ($message['custom_fields']['after_member'] as $custom)
523 548
 			echo '
524 549
 								<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
550
+	}
525 551
 
526 552
 	// Begin display of user info
527 553
 	echo '
@@ -529,50 +555,58 @@  discard block
 block discarded – undo
529 555
 							<ul class="user_info">';
530 556
 
531 557
 	// Show the user's avatar.
532
-	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
533
-		echo '
558
+	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) {
559
+			echo '
534 560
 								<li class="avatar">
535 561
 									<a href="', $message['member']['href'], '">', $message['member']['avatar']['image'], '</a>
536 562
 								</li>';
563
+	}
537 564
 
538 565
 	// Are there any custom fields below the avatar?
539
-	if (!empty($message['custom_fields']['below_avatar']))
540
-		foreach ($message['custom_fields']['below_avatar'] as $custom)
566
+	if (!empty($message['custom_fields']['below_avatar'])) {
567
+			foreach ($message['custom_fields']['below_avatar'] as $custom)
541 568
 			echo '
542 569
 								<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
570
+	}
543 571
 
544 572
 	// Show the post group icons, but not for guests.
545
-	if (!$message['member']['is_guest'])
546
-		echo '
573
+	if (!$message['member']['is_guest']) {
574
+			echo '
547 575
 								<li class="icons">', $message['member']['group_icons'], '</li>';
576
+	}
548 577
 
549 578
 	// Show the member's primary group (like 'Administrator') if they have one.
550
-	if (!empty($message['member']['group']))
551
-		echo '
579
+	if (!empty($message['member']['group'])) {
580
+			echo '
552 581
 								<li class="membergroup">', $message['member']['group'], '</li>';
582
+	}
553 583
 
554 584
 	// Show the member's custom title, if they have one.
555
-	if (!empty($message['member']['title']))
556
-		echo '
585
+	if (!empty($message['member']['title'])) {
586
+			echo '
557 587
 								<li class="title">', $message['member']['title'], '</li>';
588
+	}
558 589
 
559 590
 	// Don't show these things for guests.
560 591
 	if (!$message['member']['is_guest'])
561 592
 	{
562 593
 		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
563
-		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group']))
564
-			echo '
594
+		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group'])) {
595
+					echo '
565 596
 								<li class="postgroup">', $message['member']['post_group'], '</li>';
597
+		}
566 598
 
567 599
 		// Show how many posts they have made.
568
-		if (!isset($context['disabled_fields']['posts']))
569
-			echo '
600
+		if (!isset($context['disabled_fields']['posts'])) {
601
+					echo '
570 602
 								<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
603
+		}
571 604
 
572 605
 		// Show their personal text?
573
-		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb']))
574
-			echo '
606
+		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb'])) {
607
+					echo '
575 608
 								<li class="blurb">', $message['member']['blurb'], '</li>';
609
+		}
576 610
 
577 611
 		// Any custom fields to show as icons?
578 612
 		if (!empty($message['custom_fields']['icons']))
@@ -581,9 +615,10 @@  discard block
 block discarded – undo
581 615
 								<li class="im_icons">
582 616
 									<ol>';
583 617
 
584
-			foreach ($message['custom_fields']['icons'] as $custom)
585
-				echo '
618
+			foreach ($message['custom_fields']['icons'] as $custom) {
619
+							echo '
586 620
 										<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
621
+			}
587 622
 
588 623
 			echo '
589 624
 									</ol>
@@ -598,19 +633,22 @@  discard block
 block discarded – undo
598 633
 									<ol class="profile_icons">';
599 634
 
600 635
 			// Don't show an icon if they haven't specified a website.
601
-			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website']))
602
-				echo '
636
+			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website'])) {
637
+							echo '
603 638
 										<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
639
+			}
604 640
 
605 641
 			// Since we know this person isn't a guest, you *can* message them.
606
-			if ($context['can_send_pm'])
607
-				echo '
642
+			if ($context['can_send_pm']) {
643
+							echo '
608 644
 										<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
645
+			}
609 646
 
610 647
 			// Show the email if necessary
611
-			if (!empty($message['member']['email']) && $message['member']['show_email'])
612
-				echo '
648
+			if (!empty($message['member']['email']) && $message['member']['show_email']) {
649
+							echo '
613 650
 										<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
651
+			}
614 652
 
615 653
 			echo '
616 654
 									</ol>
@@ -618,57 +656,65 @@  discard block
 block discarded – undo
618 656
 		}
619 657
 
620 658
 		// Any custom fields for standard placement?
621
-		if (!empty($message['custom_fields']['standard']))
622
-			foreach ($message['custom_fields']['standard'] as $custom)
659
+		if (!empty($message['custom_fields']['standard'])) {
660
+					foreach ($message['custom_fields']['standard'] as $custom)
623 661
 				echo '
624 662
 								<li class="custom ', $custom['col_name'], '">', $custom['title'], ': ', $custom['value'], '</li>';
663
+		}
625 664
 	}
626 665
 	// Otherwise, show the guest's email.
627
-	elseif (!empty($message['member']['email']) && $message['member']['show_email'])
628
-		echo '
666
+	elseif (!empty($message['member']['email']) && $message['member']['show_email']) {
667
+			echo '
629 668
 								<li class="email">
630 669
 									<a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a>
631 670
 								</li>';
671
+	}
632 672
 
633 673
 	// Show the IP to this user for this post - because you can moderate?
634
-	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
635
-		echo '
674
+	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) {
675
+			echo '
636 676
 								<li class="poster_ip">
637 677
 									<a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a>
638 678
 								</li>';
679
+	}
639 680
 
640 681
 	// Or, should we show it because this is you?
641
-	elseif ($message['can_see_ip'])
642
-		echo '
682
+	elseif ($message['can_see_ip']) {
683
+			echo '
643 684
 								<li class="poster_ip">
644 685
 									<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a>
645 686
 								</li>';
687
+	}
646 688
 
647 689
 	// Okay, are you at least logged in? Then we can show something about why IPs are logged...
648
-	elseif (!$context['user']['is_guest'])
649
-		echo '
690
+	elseif (!$context['user']['is_guest']) {
691
+			echo '
650 692
 								<li class="poster_ip">
651 693
 									<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a>
652 694
 								</li>';
695
+	}
653 696
 
654 697
 	// Otherwise, you see NOTHING!
655
-	else
656
-		echo '
698
+	else {
699
+			echo '
657 700
 								<li class="poster_ip">', $txt['logged'], '</li>';
701
+	}
658 702
 
659 703
 	// Are we showing the warning status?
660 704
 	// Don't show these things for guests.
661
-	if (!$message['member']['is_guest'] && $message['member']['can_see_warning'])
662
-		echo '
705
+	if (!$message['member']['is_guest'] && $message['member']['can_see_warning']) {
706
+			echo '
663 707
 								<li class="warning">
664 708
 									', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span> ', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span>
665 709
 								</li>';
710
+	}
666 711
 
667 712
 	// Are there any custom fields to show at the bottom of the poster info?
668
-	if (!empty($message['custom_fields']['bottom_poster']))
669
-		foreach ($message['custom_fields']['bottom_poster'] as $custom)
713
+	if (!empty($message['custom_fields']['bottom_poster'])) {
714
+			foreach ($message['custom_fields']['bottom_poster'] as $custom)
670 715
 			echo '
671 716
 								<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
717
+	}
672 718
 
673 719
 	// Poster info ends.
674 720
 	echo '
@@ -698,9 +744,10 @@  discard block
 block discarded – undo
698 744
 	echo '
699 745
 									<span class="smalltext modified floatright', !empty($modSettings['show_modify']) && !empty($message['modified']['name']) ? ' mvisible' : '','" id="modified_', $message['id'], '">';
700 746
 
701
-	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name']))
702
-		echo
747
+	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name'])) {
748
+			echo
703 749
 										$message['modified']['last_edit_text'];
750
+	}
704 751
 
705 752
 	echo '
706 753
 									</span>
@@ -709,22 +756,24 @@  discard block
 block discarded – undo
709 756
 							</div><!-- .keyinfo -->';
710 757
 
711 758
 	// Ignoring this user? Hide the post.
712
-	if ($ignoring)
713
-		echo '
759
+	if ($ignoring) {
760
+			echo '
714 761
 							<div id="msg_', $message['id'], '_ignored_prompt">
715 762
 								', $txt['ignoring_user'], '
716 763
 								<a href="#" id="msg_', $message['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
717 764
 							</div>';
765
+	}
718 766
 
719 767
 	// Show the post itself, finally!
720 768
 	echo '
721 769
 							<div class="post">';
722 770
 
723
-	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id'])
724
-		echo '
771
+	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id']) {
772
+			echo '
725 773
 								<div class="approve_post">
726 774
 									', $txt['post_awaiting_approval'], '
727 775
 								</div>';
776
+	}
728 777
 	echo '
729 778
 								<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>
730 779
 									', $message['body'], '
@@ -743,9 +792,9 @@  discard block
 block discarded – undo
743 792
 		foreach ($message['attachment'] as $attachment)
744 793
 		{
745 794
 			// Do we want this attachment to not be showed here?
746
-			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']]))
747
-				continue;
748
-			elseif (!$div_output)
795
+			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']])) {
796
+							continue;
797
+			} elseif (!$div_output)
749 798
 			{
750 799
 				$div_output = true;
751 800
 
@@ -762,9 +811,10 @@  discard block
 block discarded – undo
762 811
 									<legend>
763 812
 										', $txt['attach_awaiting_approve'];
764 813
 
765
-				if ($context['can_approve'])
766
-					echo '
814
+				if ($context['can_approve']) {
815
+									echo '
767 816
 										&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=all;mid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve_all'], '</a>]';
817
+				}
768 818
 
769 819
 				echo '
770 820
 									</legend>';
@@ -778,12 +828,13 @@  discard block
 block discarded – undo
778 828
 				echo '
779 829
 										<div class="attachments_top">';
780 830
 
781
-				if ($attachment['thumbnail']['has_thumb'])
782
-					echo '
831
+				if ($attachment['thumbnail']['has_thumb']) {
832
+									echo '
783 833
 											<a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" class="atc_img"></a>';
784
-				else
785
-					echo '
834
+				} else {
835
+									echo '
786 836
 											<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" class="atc_img">';
837
+				}
787 838
 
788 839
 				echo '
789 840
 										</div><!-- .attachments_top -->';
@@ -793,9 +844,10 @@  discard block
 block discarded – undo
793 844
 										<div class="attachments_bot">
794 845
 											<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.png" class="centericon" alt="*">&nbsp;' . $attachment['name'] . '</a> ';
795 846
 
796
-			if (!$attachment['is_approved'] && $context['can_approve'])
797
-				echo '
847
+			if (!$attachment['is_approved'] && $context['can_approve']) {
848
+							echo '
798 849
 											[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>] [<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';
850
+			}
799 851
 			echo '
800 852
 											<br>', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . '<br>' . sprintf($txt['attach_viewed'], $attachment['downloads']) : '<br>' . sprintf($txt['attach_downloaded'], $attachment['downloads'])), '
801 853
 										</div><!-- .attachments_bot -->';
@@ -804,35 +856,40 @@  discard block
 block discarded – undo
804 856
 									</div><!-- .attached -->';
805 857
 
806 858
 			// Next attachment line ?
807
-			if (++$i % $attachments_per_line === 0)
808
-				echo '
859
+			if (++$i % $attachments_per_line === 0) {
860
+							echo '
809 861
 									<br>';
862
+			}
810 863
 		}
811 864
 
812 865
 		// If we had unapproved attachments clean up.
813
-		if ($last_approved_state == 0)
814
-			echo '
866
+		if ($last_approved_state == 0) {
867
+					echo '
815 868
 								</fieldset>';
869
+		}
816 870
 
817 871
 		// Only do this if we output a div above - otherwise it'll break things
818
-		if ($div_output)
819
-			echo '
872
+		if ($div_output) {
873
+					echo '
820 874
 							</div><!-- #msg_[id]_footer -->';
875
+		}
821 876
 	}
822 877
 
823 878
 	// And stuff below the attachments.
824
-	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
825
-		echo '
879
+	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
880
+			echo '
826 881
 							<div class="under_message">';
882
+	}
827 883
 
828 884
 	// Maybe they want to report this post to the moderator(s)?
829
-	if ($context['can_report_moderator'])
830
-		echo '
885
+	if ($context['can_report_moderator']) {
886
+			echo '
831 887
 								<ul class="floatright smalltext">
832 888
 									<li class="report_link">
833 889
 										<a href="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $message['counter'], ';msg=', $message['id'], '">', $txt['report_to_mod'], '</a>
834 890
 									</li>
835 891
 								</ul>';
892
+	}
836 893
 
837 894
 	// What about likes?
838 895
 	if (!empty($modSettings['enable_likes']))
@@ -879,83 +936,95 @@  discard block
 block discarded – undo
879 936
 								<ul class="quickbuttons">';
880 937
 
881 938
 		// Can they quote? if so they can select and quote as well!
882
-		if ($context['can_quote'])
883
-			echo '
939
+		if ($context['can_quote']) {
940
+					echo '
884 941
 									<li><a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';last_msg=', $context['topic_last_message'], '" onclick="return oQuickReply.quote(', $message['id'], ');"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>
885 942
 									<li style="display:none;" id="quoteSelected_', $message['id'], '">
886 943
 										<a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'], '</a>
887 944
 									</li>';
945
+		}
888 946
 
889 947
 		// Can the user modify the contents of this post? Show the modify inline image.
890
-		if ($message['can_modify'])
891
-			echo '
948
+		if ($message['can_modify']) {
949
+					echo '
892 950
 									<li class="quick_edit">
893 951
 										<a title="', $txt['modify_msg'], '" class="modifybutton" id="modify_button_', $message['id'], '" onclick="oQuickModify.modifyMsg(\'', $message['id'], '\', \'', !empty($modSettings['toggle_subject']), '\')"><span class="generic_icons quick_edit_button"></span>', $txt['quick_edit'], '</a>
894 952
 									</li>';
953
+		}
895 954
 
896
-		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
897
-			echo '
955
+		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
956
+					echo '
898 957
 									<li class="post_options">', $txt['post_options'];
958
+		}
899 959
 
900 960
 		echo '
901 961
 										<ul>';
902 962
 
903 963
 		// Can the user modify the contents of this post?
904
-		if ($message['can_modify'])
905
-			echo '
964
+		if ($message['can_modify']) {
965
+					echo '
906 966
 											<li><a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], '"><span class="generic_icons modify_button"></span>', $txt['modify'], '</a></li>';
967
+		}
907 968
 
908 969
 		// How about... even... remove it entirely?!
909
-		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id']))
910
-			echo '
970
+		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id'])) {
971
+					echo '
911 972
 											<li><a href="', $scripturl, '?action=removetopic2;topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['are_sure_remove_topic'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove_topic'], '</a></li>';
912
-
913
-		elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id']))
914
-			echo '
973
+		} elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id'])) {
974
+					echo '
915 975
 											<li><a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message_question'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
976
+		}
916 977
 
917 978
 		// What about splitting it off the rest of the topic?
918
-		if ($context['can_split'] && !empty($context['real_num_replies']))
919
-			echo '
979
+		if ($context['can_split'] && !empty($context['real_num_replies'])) {
980
+					echo '
920 981
 											<li><a href="', $scripturl, '?action=splittopics;topic=', $context['current_topic'], '.0;at=', $message['id'], '"><span class="generic_icons split_button"></span>', $txt['split'], '</a></li>';
982
+		}
921 983
 
922 984
 		// Can we issue a warning because of this post? Remember, we can't give guests warnings.
923
-		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest'])
924
-			echo '
985
+		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest']) {
986
+					echo '
925 987
 											<li><a href="', $scripturl, '?action=profile;area=issuewarning;u=', $message['member']['id'], ';msg=', $message['id'], '"><span class="generic_icons warn_button"></span>', $txt['issue_warning'], '</a></li>';
988
+		}
926 989
 
927 990
 		// Can we restore topics?
928
-		if ($context['can_restore_msg'])
929
-			echo '
991
+		if ($context['can_restore_msg']) {
992
+					echo '
930 993
 											<li><a href="', $scripturl, '?action=restoretopic;msgs=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons restore_button"></span>', $txt['restore_message'], '</a></li>';
994
+		}
931 995
 
932 996
 		// Maybe we can approve it, maybe we should?
933
-		if ($message['can_approve'])
934
-			echo '
997
+		if ($message['can_approve']) {
998
+					echo '
935 999
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons approve_button"></span>', $txt['approve'], '</a></li>';
1000
+		}
936 1001
 
937 1002
 		// Maybe we can unapprove it?
938
-		if ($message['can_unapprove'])
939
-			echo '
1003
+		if ($message['can_unapprove']) {
1004
+					echo '
940 1005
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons unapprove_button"></span>', $txt['unapprove'], '</a></li>';
1006
+		}
941 1007
 
942 1008
 		echo '
943 1009
 										</ul>
944 1010
 									</li>';
945 1011
 
946 1012
 		// Show a checkbox for quick moderation?
947
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove'])
948
-			echo '
1013
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove']) {
1014
+					echo '
949 1015
 									<li style="display: none;" id="in_topic_mod_check_', $message['id'], '"></li>';
1016
+		}
950 1017
 
951
-		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
952
-			echo '
1018
+		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
1019
+					echo '
953 1020
 								</ul><!-- .quickbuttons -->';
1021
+		}
954 1022
 	}
955 1023
 
956
-	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
957
-		echo '
1024
+	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
1025
+			echo '
958 1026
 							</div><!-- .under_message -->';
1027
+	}
959 1028
 
960 1029
 	echo '
961 1030
 						</div><!-- .postarea -->
@@ -968,9 +1037,10 @@  discard block
 block discarded – undo
968 1037
 							<div class="custom_fields_above_signature">
969 1038
 								<ul class="nolist">';
970 1039
 
971
-		foreach ($message['custom_fields']['above_signature'] as $custom)
972
-			echo '
1040
+		foreach ($message['custom_fields']['above_signature'] as $custom) {
1041
+					echo '
973 1042
 									<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
1043
+		}
974 1044
 
975 1045
 		echo '
976 1046
 								</ul>
@@ -978,11 +1048,12 @@  discard block
 block discarded – undo
978 1048
 	}
979 1049
 
980 1050
 	// Show the member's signature?
981
-	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
982
-		echo '
1051
+	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) {
1052
+			echo '
983 1053
 							<div class="signature" id="msg_', $message['id'], '_signature"', $ignoring ? ' style="display:none;"' : '', '>
984 1054
 								', $message['member']['signature'], '
985 1055
 							</div>';
1056
+	}
986 1057
 
987 1058
 
988 1059
 	// Are there any custom profile fields for below the signature?
@@ -992,9 +1063,10 @@  discard block
 block discarded – undo
992 1063
 							<div class="custom_fields_below_signature">
993 1064
 								<ul class="nolist">';
994 1065
 
995
-		foreach ($message['custom_fields']['below_signature'] as $custom)
996
-			echo '
1066
+		foreach ($message['custom_fields']['below_signature'] as $custom) {
1067
+					echo '
997 1068
 									<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
1069
+		}
998 1070
 
999 1071
 		echo '
1000 1072
 								</ul>
@@ -1027,24 +1099,28 @@  discard block
 block discarded – undo
1027 1099
 				<div class="roundframe">';
1028 1100
 
1029 1101
 	// Are we hiding the full editor?
1030
-	if (empty($options['use_editor_quick_reply']))
1031
-		echo '
1102
+	if (empty($options['use_editor_quick_reply'])) {
1103
+			echo '
1032 1104
 					<p class="smalltext lefttext">', $txt['quick_reply_desc'], '</p>';
1105
+	}
1033 1106
 
1034 1107
 	// Is the topic locked?
1035
-	if ($context['is_locked'])
1036
-		echo '
1108
+	if ($context['is_locked']) {
1109
+			echo '
1037 1110
 					<p class="alert smalltext">', $txt['quick_reply_warning'], '</p>';
1111
+	}
1038 1112
 
1039 1113
 	// Show a warning if the topic is old
1040
-	if (!empty($context['oldTopicError']))
1041
-		echo '
1114
+	if (!empty($context['oldTopicError'])) {
1115
+			echo '
1042 1116
 					<p class="alert smalltext">', sprintf($txt['error_old_topic'], $modSettings['oldTopicDays']), '</p>';
1117
+	}
1043 1118
 
1044 1119
 	// Does the post need approval?
1045
-	if (!$context['can_reply_approved'])
1046
-		echo '
1120
+	if (!$context['can_reply_approved']) {
1121
+			echo '
1047 1122
 					<p><em>', $txt['wait_for_approval'], '</em></p>';
1123
+	}
1048 1124
 
1049 1125
 	echo '
1050 1126
 					<form action="', $scripturl, '?board=', $context['current_board'], ';action=post2" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" onsubmit="submitonce(this);">
@@ -1060,8 +1136,8 @@  discard block
 block discarded – undo
1060 1136
 						<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">';
1061 1137
 
1062 1138
 	// Guests just need more.
1063
-	if ($context['user']['is_guest'])
1064
-		echo '
1139
+	if ($context['user']['is_guest']) {
1140
+			echo '
1065 1141
 						<dl id="post_header">
1066 1142
 							<dt>
1067 1143
 								', $txt['name'], ':
@@ -1076,6 +1152,7 @@  discard block
 block discarded – undo
1076 1152
 								<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" required>
1077 1153
 							</dd>
1078 1154
 						</dl>';
1155
+	}
1079 1156
 
1080 1157
 	echo '
1081 1158
 						', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'), '
@@ -1100,12 +1177,13 @@  discard block
 block discarded – undo
1100 1177
 						</script>';
1101 1178
 
1102 1179
 	// Is visual verification enabled?
1103
-	if ($context['require_verification'])
1104
-		echo '
1180
+	if ($context['require_verification']) {
1181
+			echo '
1105 1182
 						<div class="post_verification">
1106 1183
 							<strong>', $txt['verification'], ':</strong>
1107 1184
 							', template_control_verification($context['visual_verification_id'], 'all'), '
1108 1185
 						</div>';
1186
+	}
1109 1187
 
1110 1188
 	// Finally, the submit buttons.
1111 1189
 	echo '
@@ -1121,8 +1199,8 @@  discard block
 block discarded – undo
1121 1199
 		<br class="clear">';
1122 1200
 
1123 1201
 	// Draft autosave available and the user has it enabled?
1124
-	if (!empty($context['drafts_autosave']))
1125
-		echo '
1202
+	if (!empty($context['drafts_autosave'])) {
1203
+			echo '
1126 1204
 		<script>
1127 1205
 			var oDraftAutoSave = new smf_DraftAutoSave({
1128 1206
 				sSelf: \'oDraftAutoSave\',
@@ -1134,12 +1212,14 @@  discard block
 block discarded – undo
1134 1212
 				iFreq: ', (empty($modSettings['masterAutoSaveDraftsDelay']) ? 60000 : $modSettings['masterAutoSaveDraftsDelay'] * 1000), '
1135 1213
 			});
1136 1214
 		</script>';
1215
+	}
1137 1216
 
1138
-	if ($context['show_spellchecking'])
1139
-		echo '
1217
+	if ($context['show_spellchecking']) {
1218
+			echo '
1140 1219
 		<form action="', $scripturl, '?action=spellcheck" method="post" accept-charset="', $context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow">
1141 1220
 			<input type="hidden" name="spellstring" value="">
1142 1221
 		</form>';
1222
+	}
1143 1223
 
1144 1224
 	echo '
1145 1225
 		<script>
Please login to merge, or discard this patch.
Sources/Stats.php 1 patch
Braces   +112 added lines, -78 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
  * Display some useful/interesting board statistics.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 
31 32
 	isAllowedTo('view_stats');
32 33
 	// Page disabled - redirect them out
33
-	if (empty($modSettings['trackStats']))
34
-		fatal_lang_error('feature_disabled', true);
34
+	if (empty($modSettings['trackStats'])) {
35
+			fatal_lang_error('feature_disabled', true);
36
+	}
35 37
 
36 38
 	if (!empty($_REQUEST['expand']))
37 39
 	{
@@ -39,31 +41,34 @@  discard block
 block discarded – undo
39 41
 
40 42
 		$month = (int) substr($_REQUEST['expand'], 4);
41 43
 		$year = (int) substr($_REQUEST['expand'], 0, 4);
42
-		if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12)
43
-			$_SESSION['expanded_stats'][$year][] = $month;
44
-	}
45
-	elseif (!empty($_REQUEST['collapse']))
44
+		if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12) {
45
+					$_SESSION['expanded_stats'][$year][] = $month;
46
+		}
47
+	} elseif (!empty($_REQUEST['collapse']))
46 48
 	{
47 49
 		$context['robot_no_index'] = true;
48 50
 
49 51
 		$month = (int) substr($_REQUEST['collapse'], 4);
50 52
 		$year = (int) substr($_REQUEST['collapse'], 0, 4);
51
-		if (!empty($_SESSION['expanded_stats'][$year]))
52
-			$_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month));
53
+		if (!empty($_SESSION['expanded_stats'][$year])) {
54
+					$_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month));
55
+		}
53 56
 	}
54 57
 
55 58
 	// Handle the XMLHttpRequest.
56 59
 	if (isset($_REQUEST['xml']))
57 60
 	{
58 61
 		// Collapsing stats only needs adjustments of the session variables.
59
-		if (!empty($_REQUEST['collapse']))
60
-			obExit(false);
62
+		if (!empty($_REQUEST['collapse'])) {
63
+					obExit(false);
64
+		}
61 65
 
62 66
 		$context['sub_template'] = 'stats';
63 67
 		$context['yearly'] = array();
64 68
 
65
-		if (empty($month) || empty($year))
66
-			return;
69
+		if (empty($month) || empty($year)) {
70
+					return;
71
+		}
67 72
 
68 73
 		getDailyStats('YEAR(date) = {int:year} AND MONTH(date) = {int:month}', array('year' => $year, 'month' => $month));
69 74
 		$context['yearly'][$year]['months'][$month]['date'] = array(
@@ -221,8 +226,9 @@  discard block
 block discarded – undo
221 226
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
222 227
 		);
223 228
 
224
-		if ($max_num_posts < $row_members['posts'])
225
-			$max_num_posts = $row_members['posts'];
229
+		if ($max_num_posts < $row_members['posts']) {
230
+					$max_num_posts = $row_members['posts'];
231
+		}
226 232
 	}
227 233
 	$smcFunc['db_free_result']($members_result);
228 234
 
@@ -258,8 +264,9 @@  discard block
 block discarded – undo
258 264
 			'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['name'] . '</a>'
259 265
 		);
260 266
 
261
-		if ($max_num_posts < $row_board['num_posts'])
262
-			$max_num_posts = $row_board['num_posts'];
267
+		if ($max_num_posts < $row_board['num_posts']) {
268
+					$max_num_posts = $row_board['num_posts'];
269
+		}
263 270
 	}
264 271
 	$smcFunc['db_free_result']($boards_result);
265 272
 
@@ -285,12 +292,13 @@  discard block
 block discarded – undo
285 292
 			)
286 293
 		);
287 294
 		$topic_ids = array();
288
-		while ($row = $smcFunc['db_fetch_assoc']($request))
289
-			$topic_ids[] = $row['id_topic'];
295
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
296
+					$topic_ids[] = $row['id_topic'];
297
+		}
290 298
 		$smcFunc['db_free_result']($request);
299
+	} else {
300
+			$topic_ids = array();
291 301
 	}
292
-	else
293
-		$topic_ids = array();
294 302
 
295 303
 	// Topic replies top 10.
296 304
 	$topic_reply_result = $smcFunc['db_query']('', '
@@ -330,8 +338,9 @@  discard block
 block discarded – undo
330 338
 			'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['id_topic'] . '.0">' . $row_topic_reply['subject'] . '</a>'
331 339
 		);
332 340
 
333
-		if ($max_num_replies < $row_topic_reply['num_replies'])
334
-			$max_num_replies = $row_topic_reply['num_replies'];
341
+		if ($max_num_replies < $row_topic_reply['num_replies']) {
342
+					$max_num_replies = $row_topic_reply['num_replies'];
343
+		}
335 344
 	}
336 345
 	$smcFunc['db_free_result']($topic_reply_result);
337 346
 
@@ -355,12 +364,13 @@  discard block
 block discarded – undo
355 364
 			)
356 365
 		);
357 366
 		$topic_ids = array();
358
-		while ($row = $smcFunc['db_fetch_assoc']($request))
359
-			$topic_ids[] = $row['id_topic'];
367
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
368
+					$topic_ids[] = $row['id_topic'];
369
+		}
360 370
 		$smcFunc['db_free_result']($request);
371
+	} else {
372
+			$topic_ids = array();
361 373
 	}
362
-	else
363
-		$topic_ids = array();
364 374
 
365 375
 	// Topic views top 10.
366 376
 	$topic_view_result = $smcFunc['db_query']('', '
@@ -400,8 +410,9 @@  discard block
 block discarded – undo
400 410
 			'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_views['id_topic'] . '.0">' . $row_topic_views['subject'] . '</a>'
401 411
 		);
402 412
 
403
-		if ($max_num < $row_topic_views['num_views'])
404
-			$max_num = $row_topic_views['num_views'];
413
+		if ($max_num < $row_topic_views['num_views']) {
414
+					$max_num = $row_topic_views['num_views'];
415
+		}
405 416
 	}
406 417
 	$smcFunc['db_free_result']($topic_view_result);
407 418
 
@@ -426,15 +437,17 @@  discard block
 block discarded – undo
426 437
 			)
427 438
 		);
428 439
 		$members = array();
429
-		while ($row = $smcFunc['db_fetch_assoc']($request))
430
-			$members[$row['id_member_started']] = $row['hits'];
440
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
441
+					$members[$row['id_member_started']] = $row['hits'];
442
+		}
431 443
 		$smcFunc['db_free_result']($request);
432 444
 
433 445
 		cache_put_data('stats_top_starters', $members, 360);
434 446
 	}
435 447
 
436
-	if (empty($members))
437
-		$members = array(0 => 0);
448
+	if (empty($members)) {
449
+			$members = array(0 => 0);
450
+	}
438 451
 
439 452
 	// Topic poster top 10.
440 453
 	$members_result = $smcFunc['db_query']('', '
@@ -459,8 +472,9 @@  discard block
 block discarded – undo
459 472
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
460 473
 		);
461 474
 
462
-		if ($max_num < $members[$row_members['id_member']])
463
-			$max_num = $members[$row_members['id_member']];
475
+		if ($max_num < $members[$row_members['id_member']]) {
476
+					$max_num = $members[$row_members['id_member']];
477
+		}
464 478
 	}
465 479
 	ksort($context['stats_blocks']['starters']);
466 480
 	$smcFunc['db_free_result']($members_result);
@@ -489,8 +503,9 @@  discard block
 block discarded – undo
489 503
 	while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
490 504
 	{
491 505
 		$temp2[] = (int) $row_members['id_member'];
492
-		if (count($context['stats_blocks']['time_online']) >= 10)
493
-			continue;
506
+		if (count($context['stats_blocks']['time_online']) >= 10) {
507
+					continue;
508
+		}
494 509
 
495 510
 		// Figure out the days, hours and minutes.
496 511
 		$timeDays = floor($row_members['total_time_logged_in'] / 86400);
@@ -498,10 +513,12 @@  discard block
 block discarded – undo
498 513
 
499 514
 		// Figure out which things to show... (days, hours, minutes, etc.)
500 515
 		$timelogged = '';
501
-		if ($timeDays > 0)
502
-			$timelogged .= $timeDays . $txt['totalTimeLogged5'];
503
-		if ($timeHours > 0)
504
-			$timelogged .= $timeHours . $txt['totalTimeLogged6'];
516
+		if ($timeDays > 0) {
517
+					$timelogged .= $timeDays . $txt['totalTimeLogged5'];
518
+		}
519
+		if ($timeHours > 0) {
520
+					$timelogged .= $timeHours . $txt['totalTimeLogged6'];
521
+		}
505 522
 		$timelogged .= floor(($row_members['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged7'];
506 523
 
507 524
 		$context['stats_blocks']['time_online'][] = array(
@@ -513,17 +530,20 @@  discard block
 block discarded – undo
513 530
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
514 531
 		);
515 532
 
516
-		if ($max_time_online < $row_members['total_time_logged_in'])
517
-			$max_time_online = $row_members['total_time_logged_in'];
533
+		if ($max_time_online < $row_members['total_time_logged_in']) {
534
+					$max_time_online = $row_members['total_time_logged_in'];
535
+		}
518 536
 	}
519 537
 	$smcFunc['db_free_result']($members_result);
520 538
 
521
-	foreach ($context['stats_blocks']['time_online'] as $i => $member)
522
-		$context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online);
539
+	foreach ($context['stats_blocks']['time_online'] as $i => $member) {
540
+			$context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online);
541
+	}
523 542
 
524 543
 	// Cache the ones we found for a bit, just so we don't have to look again.
525
-	if ($temp !== $temp2)
526
-		cache_put_data('stats_total_time_members', $temp2, 480);
544
+	if ($temp !== $temp2) {
545
+			cache_put_data('stats_total_time_members', $temp2, 480);
546
+	}
527 547
 
528 548
 	// Likes.
529 549
 	if (!empty($modSettings['enable_likes']))
@@ -559,13 +579,15 @@  discard block
 block discarded – undo
559 579
 				'link' => '<a href="' . $scripturl . '?msg=' . $row_liked_message['id_msg'] .'">' . $row_liked_message['subject'] . '</a>'
560 580
 			);
561 581
 
562
-			if ($max_liked_message < $row_liked_message['likes'])
563
-				$max_liked_message = $row_liked_message['likes'];
582
+			if ($max_liked_message < $row_liked_message['likes']) {
583
+							$max_liked_message = $row_liked_message['likes'];
584
+			}
564 585
 		}
565 586
 		$smcFunc['db_free_result']($liked_messages);
566 587
 
567
-		foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages)
568
-			$context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message);
588
+		foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages) {
589
+					$context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message);
590
+		}
569 591
 
570 592
 		// Liked users top 10.
571 593
 		$context['stats_blocks']['liked_users'] = array();
@@ -596,14 +618,16 @@  discard block
 block discarded – undo
596 618
 				'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_liked_users['liked_user'] . '">' . $row_liked_users['real_name'] . '</a>',
597 619
 			);
598 620
 
599
-			if ($max_liked_users < $row_liked_users['count'])
600
-				$max_liked_users = $row_liked_users['count'];
621
+			if ($max_liked_users < $row_liked_users['count']) {
622
+							$max_liked_users = $row_liked_users['count'];
623
+			}
601 624
 		}
602 625
 
603 626
 		$smcFunc['db_free_result']($liked_users);
604 627
 
605
-		foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users)
606
-			$context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users);
628
+		foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users) {
629
+					$context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users);
630
+		}
607 631
 	}
608 632
 
609 633
 	// Activity by month.
@@ -621,8 +645,8 @@  discard block
 block discarded – undo
621 645
 		$ID_MONTH = $row_months['stats_year'] . sprintf('%02d', $row_months['stats_month']);
622 646
 		$expanded = !empty($_SESSION['expanded_stats'][$row_months['stats_year']]) && in_array($row_months['stats_month'], $_SESSION['expanded_stats'][$row_months['stats_year']]);
623 647
 
624
-		if (!isset($context['yearly'][$row_months['stats_year']]))
625
-			$context['yearly'][$row_months['stats_year']] = array(
648
+		if (!isset($context['yearly'][$row_months['stats_year']])) {
649
+					$context['yearly'][$row_months['stats_year']] = array(
626 650
 				'year' => $row_months['stats_year'],
627 651
 				'new_topics' => 0,
628 652
 				'new_posts' => 0,
@@ -634,6 +658,7 @@  discard block
 block discarded – undo
634 658
 				'expanded' => false,
635 659
 				'current_year' => $row_months['stats_year'] == date('Y'),
636 660
 			);
661
+		}
637 662
 
638 663
 		$context['yearly'][$row_months['stats_year']]['months'][(int) $row_months['stats_month']] = array(
639 664
 			'id' => $ID_MONTH,
@@ -679,29 +704,33 @@  discard block
 block discarded – undo
679 704
 		$context['yearly'][$year]['hits'] = comma_format($data['hits']);
680 705
 
681 706
 		// Keep a list of collapsed years.
682
-		if (!$data['expanded'] && !$data['current_year'])
683
-			$context['collapsed_years'][] = $year;
707
+		if (!$data['expanded'] && !$data['current_year']) {
708
+					$context['collapsed_years'][] = $year;
709
+		}
684 710
 	}
685 711
 
686 712
 	// Custom stats (just add a template_layer to add it to the template!)
687 713
 	call_integration_hook('integrate_forum_stats');
688 714
 
689
-	if (empty($_SESSION['expanded_stats']))
690
-		return;
715
+	if (empty($_SESSION['expanded_stats'])) {
716
+			return;
717
+	}
691 718
 
692 719
 	$condition_text = array();
693 720
 	$condition_params = array();
694
-	foreach ($_SESSION['expanded_stats'] as $year => $months)
695
-		if (!empty($months))
721
+	foreach ($_SESSION['expanded_stats'] as $year => $months) {
722
+			if (!empty($months))
696 723
 		{
697 724
 			$condition_text[] = 'YEAR(date) = {int:year_' . $year . '} AND MONTH(date) IN ({array_int:months_' . $year . '})';
725
+	}
698 726
 			$condition_params['year_' . $year] = $year;
699 727
 			$condition_params['months_' . $year] = $months;
700 728
 		}
701 729
 
702 730
 	// No daily stats to even look at?
703
-	if (empty($condition_text))
704
-		return;
731
+	if (empty($condition_text)) {
732
+			return;
733
+	}
705 734
 
706 735
 	getDailyStats(implode(' OR ', $condition_text), $condition_params);
707 736
 }
@@ -724,8 +753,8 @@  discard block
 block discarded – undo
724 753
 		ORDER BY stats_day ASC',
725 754
 		$condition_parameters
726 755
 	);
727
-	while ($row_days = $smcFunc['db_fetch_assoc']($days_result))
728
-		$context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array(
756
+	while ($row_days = $smcFunc['db_fetch_assoc']($days_result)) {
757
+			$context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array(
729 758
 			'day' => sprintf('%02d', $row_days['stats_day']),
730 759
 			'month' => sprintf('%02d', $row_days['stats_month']),
731 760
 			'year' => $row_days['stats_year'],
@@ -735,6 +764,7 @@  discard block
 block discarded – undo
735 764
 			'most_members_online' => comma_format($row_days['most_on']),
736 765
 			'hits' => comma_format($row_days['hits'])
737 766
 		);
767
+	}
738 768
 	$smcFunc['db_free_result']($days_result);
739 769
 }
740 770
 
@@ -752,16 +782,19 @@  discard block
 block discarded – undo
752 782
 	global $modSettings, $user_info, $forum_version, $sourcedir;
753 783
 
754 784
 	// First, is it disabled?
755
-	if (empty($modSettings['enable_sm_stats']) || empty($modSettings['sm_stats_key']))
756
-		die();
785
+	if (empty($modSettings['enable_sm_stats']) || empty($modSettings['sm_stats_key'])) {
786
+			die();
787
+	}
757 788
 
758 789
 	// Are we saying who we are, and are we right? (OR an admin)
759
-	if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['sm_stats_key']))
760
-		die();
790
+	if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['sm_stats_key'])) {
791
+			die();
792
+	}
761 793
 
762 794
 	// Verify the referer...
763
-	if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085'))
764
-		die();
795
+	if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085')) {
796
+			die();
797
+	}
765 798
 
766 799
 	// Get some server versions.
767 800
 	require_once($sourcedir . '/Subs-Admin.php');
@@ -787,16 +820,17 @@  discard block
 block discarded – undo
787 820
 	);
788 821
 
789 822
 	// Encode all the data, for security.
790
-	foreach ($stats_to_send as $k => $v)
791
-		$stats_to_send[$k] = urlencode($k) . '=' . urlencode($v);
823
+	foreach ($stats_to_send as $k => $v) {
824
+			$stats_to_send[$k] = urlencode($k) . '=' . urlencode($v);
825
+	}
792 826
 
793 827
 	// Turn this into the query string!
794 828
 	$stats_to_send = implode('&', $stats_to_send);
795 829
 
796 830
 	// If we're an admin, just plonk them out.
797
-	if ($user_info['is_admin'])
798
-		echo $stats_to_send;
799
-	else
831
+	if ($user_info['is_admin']) {
832
+			echo $stats_to_send;
833
+	} else
800 834
 	{
801 835
 		// Connect to the collection script.
802 836
 		$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +315 added lines, -243 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 4
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -142,10 +144,11 @@  discard block
 block discarded – undo
142 144
 
143 145
 	// If no cert, force_ssl must remain 0
144 146
 	require_once($sourcedir . '/Subs.php');
145
-	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl']))
146
-		$disable_force_ssl = true;
147
-	else
148
-		$disable_force_ssl = false;
147
+	if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) {
148
+			$disable_force_ssl = true;
149
+	} else {
150
+			$disable_force_ssl = false;
151
+	}
149 152
 
150 153
 	/* If you're writing a mod, it's a bad idea to add things here....
151 154
 	For each option:
@@ -174,8 +177,9 @@  discard block
 block discarded – undo
174 177
 
175 178
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
176 179
 
177
-	if ($return_config)
178
-		return $config_vars;
180
+	if ($return_config) {
181
+			return $config_vars;
182
+	}
179 183
 
180 184
 	// Setup the template stuff.
181 185
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -192,16 +196,18 @@  discard block
 block discarded – undo
192 196
 			$registerSMStats = registerSMStats();
193 197
 
194 198
 			// Failed to register, disable it again.
195
-			if (empty($registerSMStats))
196
-				$_POST['enable_sm_stats'] = 0;
199
+			if (empty($registerSMStats)) {
200
+							$_POST['enable_sm_stats'] = 0;
201
+			}
197 202
 		}
198 203
 
199 204
 		// Ensure all URLs are aligned with the new force_ssl setting
200 205
 		// Treat unset like 0
201
-		if (isset($_POST['force_ssl']))
202
-			AlignURLsWithSSLSetting($_POST['force_ssl']);
203
-		else
204
-			AlignURLsWithSSLSetting(0);
206
+		if (isset($_POST['force_ssl'])) {
207
+					AlignURLsWithSSLSetting($_POST['force_ssl']);
208
+		} else {
209
+					AlignURLsWithSSLSetting(0);
210
+		}
205 211
 
206 212
 		saveSettings($config_vars);
207 213
 		$_SESSION['adm-save'] = true;
@@ -254,10 +260,11 @@  discard block
 block discarded – undo
254 260
 	require_once($sourcedir . '/Subs-Admin.php');
255 261
 
256 262
 	// Check $boardurl
257
-	if (!empty($new_force_ssl))
258
-		$newval = strtr($boardurl, array('http://' => 'https://'));
259
-	else
260
-		$newval = strtr($boardurl, array('https://' => 'http://'));
263
+	if (!empty($new_force_ssl)) {
264
+			$newval = strtr($boardurl, array('http://' => 'https://'));
265
+	} else {
266
+			$newval = strtr($boardurl, array('https://' => 'http://'));
267
+	}
261 268
 	updateSettingsFile(array('boardurl' => '\'' . addslashes($newval) . '\''));
262 269
 
263 270
 	$new_settings = array();
@@ -265,20 +272,22 @@  discard block
 block discarded – undo
265 272
 	// Check $smileys_url, but only if it points to a subfolder of $boardurl
266 273
 	if (BoardurlMatch($modSettings['smileys_url']))
267 274
 	{
268
-		if (!empty($new_force_ssl))
269
-			$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
270
-		else
271
-			$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
275
+		if (!empty($new_force_ssl)) {
276
+					$newval = strtr($modSettings['smileys_url'], array('http://' => 'https://'));
277
+		} else {
278
+					$newval = strtr($modSettings['smileys_url'], array('https://' => 'http://'));
279
+		}
272 280
 		$new_settings['smileys_url'] = $newval;
273 281
 	}
274 282
 
275 283
 	// Check $avatar_url, but only if it points to a subfolder of $boardurl
276 284
 	if (BoardurlMatch($modSettings['avatar_url']))
277 285
 	{
278
-		if (!empty($new_force_ssl))
279
-			$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
280
-		else
281
-			$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
286
+		if (!empty($new_force_ssl)) {
287
+					$newval = strtr($modSettings['avatar_url'], array('http://' => 'https://'));
288
+		} else {
289
+					$newval = strtr($modSettings['avatar_url'], array('https://' => 'http://'));
290
+		}
282 291
 		$new_settings['avatar_url'] = $newval;
283 292
 	}
284 293
 
@@ -286,16 +295,18 @@  discard block
 block discarded – undo
286 295
 	// This one had been optional in the past, make sure it is set first
287 296
 	if (isset($modSettings['custom_avatar_url']) && BoardurlMatch($modSettings['custom_avatar_url']))
288 297
 	{
289
-		if (!empty($new_force_ssl))
290
-			$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
291
-		else
292
-			$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
298
+		if (!empty($new_force_ssl)) {
299
+					$newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://'));
300
+		} else {
301
+					$newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://'));
302
+		}
293 303
 		$new_settings['custom_avatar_url'] = $newval;
294 304
 	}
295 305
 
296 306
 	// Save updates to the settings table
297
-	if (!empty($new_settings))
298
-		updateSettings($new_settings, true);
307
+	if (!empty($new_settings)) {
308
+			updateSettings($new_settings, true);
309
+	}
299 310
 
300 311
 	// Now we move onto the themes.
301 312
 	// First, get a list of theme URLs...
@@ -316,10 +327,11 @@  discard block
 block discarded – undo
316 327
 		// First check to see if it points to a subfolder of $boardurl
317 328
 		if (BoardurlMatch($row['value']))
318 329
 		{
319
-			if (!empty($new_force_ssl))
320
-				$newval = strtr($row['value'], array('http://' => 'https://'));
321
-			else
322
-				$newval = strtr($row['value'], array('https://' => 'http://'));
330
+			if (!empty($new_force_ssl)) {
331
+							$newval = strtr($row['value'], array('http://' => 'https://'));
332
+			} else {
333
+							$newval = strtr($row['value'], array('https://' => 'http://'));
334
+			}
323 335
 			$smcFunc['db_query']('', '
324 336
 				UPDATE {db_prefix}themes
325 337
 				   SET value = {string:theme_val}
@@ -359,11 +371,12 @@  discard block
 block discarded – undo
359 371
 
360 372
 	// If leftmost portion of path matches boardurl, return true
361 373
 	$result = strpos($urlpath, $boardurlpath);
362
-	if ($result === false || $result != 0)
363
-		return false;
364
-	else
365
-		return true;
366
-}
374
+	if ($result === false || $result != 0) {
375
+			return false;
376
+	} else {
377
+			return true;
378
+	}
379
+	}
367 380
 
368 381
 /**
369 382
  * Basic database and paths settings - database name, host, etc.
@@ -402,8 +415,9 @@  discard block
 block discarded – undo
402 415
 		$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array());
403 416
 		$fts_language = array();
404 417
 
405
-		while ($row = $smcFunc['db_fetch_assoc']($request))
406
-			$fts_language[$row['cfgname']] = $row['cfgname'];
418
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
419
+					$fts_language[$row['cfgname']] = $row['cfgname'];
420
+		}
407 421
 
408 422
 		$config_vars = array_merge ($config_vars, array(
409 423
 				'',
@@ -415,20 +429,22 @@  discard block
 block discarded – undo
415 429
 
416 430
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
417 431
 
418
-	if ($return_config)
419
-		return $config_vars;
432
+	if ($return_config) {
433
+			return $config_vars;
434
+	}
420 435
 
421 436
 	// Setup the template stuff.
422 437
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
423 438
 	$context['settings_title'] = $txt['database_settings'];
424 439
 	$context['save_disabled'] = $context['settings_not_writable'];
425 440
 
426
-	if (!$smcFunc['db_allow_persistent']())
427
-		addInlineJavaScript('
441
+	if (!$smcFunc['db_allow_persistent']()) {
442
+			addInlineJavaScript('
428 443
 			$(function()
429 444
 			{
430 445
 				$("#db_persist").prop("disabled", true);
431 446
 			});', true);
447
+	}
432 448
 
433 449
 	// Saving settings?
434 450
 	if (isset($_REQUEST['save']))
@@ -498,13 +514,15 @@  discard block
 block discarded – undo
498 514
 		hideGlobalCookies();
499 515
 	});', true);
500 516
 
501
-	if (empty($user_settings['tfa_secret']))
502
-		addInlineJavaScript('');
517
+	if (empty($user_settings['tfa_secret'])) {
518
+			addInlineJavaScript('');
519
+	}
503 520
 
504 521
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
505 522
 
506
-	if ($return_config)
507
-		return $config_vars;
523
+	if ($return_config) {
524
+			return $config_vars;
525
+	}
508 526
 
509 527
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
510 528
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -515,14 +533,17 @@  discard block
 block discarded – undo
515 533
 		call_integration_hook('integrate_save_cookie_settings');
516 534
 
517 535
 		// Local and global do not play nicely together.
518
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
519
-			unset ($_POST['globalCookies']);
536
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
537
+					unset ($_POST['globalCookies']);
538
+		}
520 539
 
521
-		if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies']))
522
-			$scope_changed = true;
540
+		if (empty($modSettings['localCookies']) != empty($_POST['localCookies']) || empty($modSettings['globalCookies']) != empty($_POST['globalCookies'])) {
541
+					$scope_changed = true;
542
+		}
523 543
 
524
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
525
-			fatal_lang_error('invalid_cookie_domain', false);
544
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
545
+					fatal_lang_error('invalid_cookie_domain', false);
546
+		}
526 547
 
527 548
 		saveSettings($config_vars);
528 549
 
@@ -605,8 +626,9 @@  discard block
 block discarded – undo
605 626
 
606 627
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
607 628
 
608
-	if ($return_config)
609
-		return $config_vars;
629
+	if ($return_config) {
630
+			return $config_vars;
631
+	}
610 632
 
611 633
 	// Saving?
612 634
 	if (isset($_GET['save']))
@@ -645,8 +667,7 @@  discard block
 block discarded – undo
645 667
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
646 668
 		$cache_level = array($txt['cache_off']);
647 669
 		$detected['none'] = $txt['cache_off'];
648
-	}
649
-	else
670
+	} else
650 671
 	{
651 672
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
652 673
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -683,8 +704,9 @@  discard block
 block discarded – undo
683 704
 			}
684 705
 		}
685 706
 	}
686
-	if ($return_config)
687
-		return $config_vars;
707
+	if ($return_config) {
708
+			return $config_vars;
709
+	}
688 710
 
689 711
 	// Saving again?
690 712
 	if (isset($_GET['save']))
@@ -712,8 +734,9 @@  discard block
 block discarded – undo
712 734
 	$context['save_disabled'] = $context['settings_not_writable'];
713 735
 
714 736
 	// Decide what message to show.
715
-	if (!$context['save_disabled'])
716
-		$context['settings_message'] = $txt['caching_information'];
737
+	if (!$context['save_disabled']) {
738
+			$context['settings_message'] = $txt['caching_information'];
739
+	}
717 740
 
718 741
 	// Prepare the template.
719 742
 	prepareServerSettingsContext($config_vars);
@@ -736,24 +759,25 @@  discard block
 block discarded – undo
736 759
 	if (stripos(PHP_OS, 'win') === 0)
737 760
 	{
738 761
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
739
-		if (isset($_GET['save']))
740
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
741
-	}
742
-	elseif (stripos(PHP_OS, 'darwin') === 0)
762
+		if (isset($_GET['save'])) {
763
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
764
+		}
765
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
743 766
 	{
744 767
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
745
-		if (isset($_GET['save']))
746
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
747
-	}
748
-	else
768
+		if (isset($_GET['save'])) {
769
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
770
+		}
771
+	} else
749 772
 	{
750 773
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
751
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
752
-			$modSettings['load_average'] = (float) $matches[1];
753
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
754
-			$modSettings['load_average'] = (float) $matches[1];
755
-		else
756
-			unset($modSettings['load_average']);
774
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
775
+					$modSettings['load_average'] = (float) $matches[1];
776
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
777
+					$modSettings['load_average'] = (float) $matches[1];
778
+		} else {
779
+					unset($modSettings['load_average']);
780
+		}
757 781
 
758 782
 		if (!empty($modSettings['load_average']) || (isset($modSettings['load_average']) && $modSettings['load_average'] === 0.0))
759 783
 		{
@@ -789,8 +813,9 @@  discard block
 block discarded – undo
789 813
 
790 814
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
791 815
 
792
-	if ($return_config)
793
-		return $config_vars;
816
+	if ($return_config) {
817
+			return $config_vars;
818
+	}
794 819
 
795 820
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
796 821
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -801,24 +826,27 @@  discard block
 block discarded – undo
801 826
 		// Stupidity is not allowed.
802 827
 		foreach ($_POST as $key => $value)
803 828
 		{
804
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
805
-				continue;
806
-			else
807
-				$_POST[$key] = (float) $value;
808
-
809
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
810
-				$_POST['loadavg_auto_opt'] = 1.0;
811
-			elseif ($key == 'loadavg_forum' && $value < 10)
812
-				$_POST['loadavg_forum'] = 10.0;
813
-			elseif ($value < 2)
814
-				$_POST[$key] = 2.0;
829
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
830
+							continue;
831
+			} else {
832
+							$_POST[$key] = (float) $value;
833
+			}
834
+
835
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
836
+							$_POST['loadavg_auto_opt'] = 1.0;
837
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
838
+							$_POST['loadavg_forum'] = 10.0;
839
+			} elseif ($value < 2) {
840
+							$_POST[$key] = 2.0;
841
+			}
815 842
 		}
816 843
 
817 844
 		call_integration_hook('integrate_save_loadavg_settings');
818 845
 
819 846
 		saveDBSettings($config_vars);
820
-		if (!isset($_SESSION['adm-save']))
821
-			$_SESSION['adm-save'] = true;
847
+		if (!isset($_SESSION['adm-save'])) {
848
+					$_SESSION['adm-save'] = true;
849
+		}
822 850
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
823 851
 	}
824 852
 
@@ -854,10 +882,11 @@  discard block
 block discarded – undo
854 882
 
855 883
 	if (isset($_SESSION['adm-save']))
856 884
 	{
857
-		if ($_SESSION['adm-save'] === true)
858
-			$context['saved_successful'] = true;
859
-		else
860
-			$context['saved_failed'] = $_SESSION['adm-save'];
885
+		if ($_SESSION['adm-save'] === true) {
886
+					$context['saved_successful'] = true;
887
+		} else {
888
+					$context['saved_failed'] = $_SESSION['adm-save'];
889
+		}
861 890
 
862 891
 		unset($_SESSION['adm-save']);
863 892
 	}
@@ -865,9 +894,9 @@  discard block
 block discarded – undo
865 894
 	$context['config_vars'] = array();
866 895
 	foreach ($config_vars as $identifier => $config_var)
867 896
 	{
868
-		if (!is_array($config_var) || !isset($config_var[1]))
869
-			$context['config_vars'][] = $config_var;
870
-		else
897
+		if (!is_array($config_var) || !isset($config_var[1])) {
898
+					$context['config_vars'][] = $config_var;
899
+		} else
871 900
 		{
872 901
 			$varname = $config_var[0];
873 902
 			global $$varname;
@@ -902,16 +931,19 @@  discard block
 block discarded – undo
902 931
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
903 932
 			{
904 933
 				// Default to a min of 0 if one isn't set
905
-				if (isset($config_var['min']))
906
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
907
-				else
908
-					$context['config_vars'][$config_var[0]]['min'] = 0;
934
+				if (isset($config_var['min'])) {
935
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
936
+				} else {
937
+									$context['config_vars'][$config_var[0]]['min'] = 0;
938
+				}
909 939
 
910
-				if (isset($config_var['max']))
911
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
940
+				if (isset($config_var['max'])) {
941
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
942
+				}
912 943
 
913
-				if (isset($config_var['step']))
914
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
944
+				if (isset($config_var['step'])) {
945
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
946
+				}
915 947
 			}
916 948
 
917 949
 			// If this is a select box handle any data.
@@ -919,12 +951,13 @@  discard block
 block discarded – undo
919 951
 			{
920 952
 				// If it's associative
921 953
 				$config_values = array_values($config_var[4]);
922
-				if (isset($config_values[0]) && is_array($config_values[0]))
923
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
924
-				else
954
+				if (isset($config_values[0]) && is_array($config_values[0])) {
955
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
956
+				} else
925 957
 				{
926
-					foreach ($config_var[4] as $key => $item)
927
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
958
+					foreach ($config_var[4] as $key => $item) {
959
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
960
+					}
928 961
 				}
929 962
 			}
930 963
 		}
@@ -949,10 +982,11 @@  discard block
 block discarded – undo
949 982
 
950 983
 	if (isset($_SESSION['adm-save']))
951 984
 	{
952
-		if ($_SESSION['adm-save'] === true)
953
-			$context['saved_successful'] = true;
954
-		else
955
-			$context['saved_failed'] = $_SESSION['adm-save'];
985
+		if ($_SESSION['adm-save'] === true) {
986
+					$context['saved_successful'] = true;
987
+		} else {
988
+					$context['saved_failed'] = $_SESSION['adm-save'];
989
+		}
956 990
 
957 991
 		unset($_SESSION['adm-save']);
958 992
 	}
@@ -964,26 +998,30 @@  discard block
 block discarded – undo
964 998
 	foreach ($config_vars as $config_var)
965 999
 	{
966 1000
 		// HR?
967
-		if (!is_array($config_var))
968
-			$context['config_vars'][] = $config_var;
969
-		else
1001
+		if (!is_array($config_var)) {
1002
+					$context['config_vars'][] = $config_var;
1003
+		} else
970 1004
 		{
971 1005
 			// If it has no name it doesn't have any purpose!
972
-			if (empty($config_var[1]))
973
-				continue;
1006
+			if (empty($config_var[1])) {
1007
+							continue;
1008
+			}
974 1009
 
975 1010
 			// Special case for inline permissions
976
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
977
-				$inlinePermissions[] = $config_var[1];
978
-			elseif ($config_var[0] == 'permissions')
979
-				continue;
1011
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
1012
+							$inlinePermissions[] = $config_var[1];
1013
+			} elseif ($config_var[0] == 'permissions') {
1014
+							continue;
1015
+			}
980 1016
 
981
-			if ($config_var[0] == 'boards')
982
-				$board_list = true;
1017
+			if ($config_var[0] == 'boards') {
1018
+							$board_list = true;
1019
+			}
983 1020
 
984 1021
 			// Are we showing the BBC selection box?
985
-			if ($config_var[0] == 'bbc')
986
-				$bbcChoice[] = $config_var[1];
1022
+			if ($config_var[0] == 'bbc') {
1023
+							$bbcChoice[] = $config_var[1];
1024
+			}
987 1025
 
988 1026
 			// We need to do some parsing of the value before we pass it in.
989 1027
 			if (isset($modSettings[$config_var[1]]))
@@ -1002,8 +1040,7 @@  discard block
 block discarded – undo
1002 1040
 					default:
1003 1041
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
1004 1042
 				}
1005
-			}
1006
-			else
1043
+			} else
1007 1044
 			{
1008 1045
 				// Darn, it's empty. What type is expected?
1009 1046
 				switch ($config_var[0])
@@ -1043,16 +1080,19 @@  discard block
 block discarded – undo
1043 1080
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
1044 1081
 			{
1045 1082
 				// Default to a min of 0 if one isn't set
1046
-				if (isset($config_var['min']))
1047
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1048
-				else
1049
-					$context['config_vars'][$config_var[1]]['min'] = 0;
1083
+				if (isset($config_var['min'])) {
1084
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
1085
+				} else {
1086
+									$context['config_vars'][$config_var[1]]['min'] = 0;
1087
+				}
1050 1088
 
1051
-				if (isset($config_var['max']))
1052
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1089
+				if (isset($config_var['max'])) {
1090
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
1091
+				}
1053 1092
 
1054
-				if (isset($config_var['step']))
1055
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1093
+				if (isset($config_var['step'])) {
1094
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
1095
+				}
1056 1096
 			}
1057 1097
 
1058 1098
 			// If this is a select box handle any data.
@@ -1066,12 +1106,13 @@  discard block
 block discarded – undo
1066 1106
 				}
1067 1107
 
1068 1108
 				// If it's associative
1069
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
1070
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1071
-				else
1109
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
1110
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
1111
+				} else
1072 1112
 				{
1073
-					foreach ($config_var[2] as $key => $item)
1074
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1113
+					foreach ($config_var[2] as $key => $item) {
1114
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
1115
+					}
1075 1116
 				}
1076 1117
 			}
1077 1118
 
@@ -1080,17 +1121,19 @@  discard block
 block discarded – undo
1080 1121
 			{
1081 1122
 				if (!is_numeric($k))
1082 1123
 				{
1083
-					if (substr($k, 0, 2) == 'on')
1084
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1085
-					else
1086
-						$context['config_vars'][$config_var[1]][$k] = $v;
1124
+					if (substr($k, 0, 2) == 'on') {
1125
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
1126
+					} else {
1127
+											$context['config_vars'][$config_var[1]][$k] = $v;
1128
+					}
1087 1129
 				}
1088 1130
 
1089 1131
 				// See if there are any other labels that might fit?
1090
-				if (isset($txt['setting_' . $config_var[1]]))
1091
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1092
-				elseif (isset($txt['groups_' . $config_var[1]]))
1093
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1132
+				if (isset($txt['setting_' . $config_var[1]])) {
1133
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
1134
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
1135
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
1136
+				}
1094 1137
 			}
1095 1138
 
1096 1139
 			// Set the subtext in case it's part of the label.
@@ -1123,8 +1166,9 @@  discard block
 block discarded – undo
1123 1166
 		// What are the options, eh?
1124 1167
 		$temp = parse_bbc(false);
1125 1168
 		$bbcTags = array();
1126
-		foreach ($temp as $tag)
1127
-			$bbcTags[] = $tag['tag'];
1169
+		foreach ($temp as $tag) {
1170
+					$bbcTags[] = $tag['tag'];
1171
+		}
1128 1172
 
1129 1173
 		$bbcTags = array_unique($bbcTags);
1130 1174
 		$totalTags = count($bbcTags);
@@ -1139,8 +1183,9 @@  discard block
 block discarded – undo
1139 1183
 		$col = 0; $i = 0;
1140 1184
 		foreach ($bbcTags as $tag)
1141 1185
 		{
1142
-			if ($i % $tagsPerColumn == 0 && $i != 0)
1143
-				$col++;
1186
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
1187
+							$col++;
1188
+			}
1144 1189
 
1145 1190
 			$context['bbc_columns'][$col][] = array(
1146 1191
 				'tag' => $tag,
@@ -1183,18 +1228,21 @@  discard block
 block discarded – undo
1183 1228
 	validateToken('admin-ssc');
1184 1229
 
1185 1230
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1186
-	if (isset($_POST['cookiename']))
1187
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1231
+	if (isset($_POST['cookiename'])) {
1232
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1233
+	}
1188 1234
 
1189 1235
 	// Fix the forum's URL if necessary.
1190 1236
 	if (isset($_POST['boardurl']))
1191 1237
 	{
1192
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1193
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1194
-		elseif (substr($_POST['boardurl'], -1) == '/')
1195
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1196
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1197
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1238
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1239
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1240
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1241
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1242
+		}
1243
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1244
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1245
+		}
1198 1246
 	}
1199 1247
 
1200 1248
 	// Any passwords?
@@ -1229,21 +1277,21 @@  discard block
 block discarded – undo
1229 1277
 	// Figure out which config vars we're saving here...
1230 1278
 	foreach ($config_vars as $var)
1231 1279
 	{
1232
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1233
-			continue;
1280
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1281
+					continue;
1282
+		}
1234 1283
 
1235 1284
 		$config_var = $var[0];
1236 1285
 
1237 1286
 		if (in_array($config_var, $config_passwords))
1238 1287
 		{
1239
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1240
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1241
-		}
1242
-		elseif (in_array($config_var, $config_strs))
1288
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1289
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1290
+			}
1291
+		} elseif (in_array($config_var, $config_strs))
1243 1292
 		{
1244 1293
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1245
-		}
1246
-		elseif (in_array($config_var, $config_ints))
1294
+		} elseif (in_array($config_var, $config_ints))
1247 1295
 		{
1248 1296
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1249 1297
 
@@ -1252,17 +1300,17 @@  discard block
 block discarded – undo
1252 1300
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1253 1301
 
1254 1302
 			// Is there a max value for this as well?
1255
-			if (isset($var['max']))
1256
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1257
-		}
1258
-		elseif (in_array($config_var, $config_bools))
1303
+			if (isset($var['max'])) {
1304
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1305
+			}
1306
+		} elseif (in_array($config_var, $config_bools))
1259 1307
 		{
1260
-			if (!empty($_POST[$config_var]))
1261
-				$new_settings[$config_var] = '1';
1262
-			else
1263
-				$new_settings[$config_var] = '0';
1264
-		}
1265
-		else
1308
+			if (!empty($_POST[$config_var])) {
1309
+							$new_settings[$config_var] = '1';
1310
+			} else {
1311
+							$new_settings[$config_var] = '0';
1312
+			}
1313
+		} else
1266 1314
 		{
1267 1315
 			// This shouldn't happen, but it might...
1268 1316
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1278,30 +1326,35 @@  discard block
 block discarded – undo
1278 1326
 	foreach ($config_vars as $config_var)
1279 1327
 	{
1280 1328
 		// We just saved the file-based settings, so skip their definitions.
1281
-		if (!is_array($config_var) || $config_var[2] == 'file')
1282
-			continue;
1329
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1330
+					continue;
1331
+		}
1283 1332
 
1284 1333
 		$new_setting = array($config_var[3], $config_var[0]);
1285 1334
 
1286 1335
 		// Select options need carried over, too.
1287
-		if (isset($config_var[4]))
1288
-			$new_setting[] = $config_var[4];
1336
+		if (isset($config_var[4])) {
1337
+					$new_setting[] = $config_var[4];
1338
+		}
1289 1339
 
1290 1340
 		// Include min and max if necessary
1291
-		if (isset($config_var['min']))
1292
-			$new_setting['min'] = $config_var['min'];
1341
+		if (isset($config_var['min'])) {
1342
+					$new_setting['min'] = $config_var['min'];
1343
+		}
1293 1344
 
1294
-		if (isset($config_var['max']))
1295
-			$new_setting['max'] = $config_var['max'];
1345
+		if (isset($config_var['max'])) {
1346
+					$new_setting['max'] = $config_var['max'];
1347
+		}
1296 1348
 
1297 1349
 		// Rewrite the definition a bit.
1298 1350
 		$new_settings[] = $new_setting;
1299 1351
 	}
1300 1352
 
1301 1353
 	// Save the new database-based settings, if any.
1302
-	if (!empty($new_settings))
1303
-		saveDBSettings($new_settings);
1304
-}
1354
+	if (!empty($new_settings)) {
1355
+			saveDBSettings($new_settings);
1356
+	}
1357
+	}
1305 1358
 
1306 1359
 /**
1307 1360
  * Helper function for saving database settings.
@@ -1319,22 +1372,25 @@  discard block
 block discarded – undo
1319 1372
 	$inlinePermissions = array();
1320 1373
 	foreach ($config_vars as $var)
1321 1374
 	{
1322
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1323
-			continue;
1375
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1376
+					continue;
1377
+		}
1324 1378
 
1325 1379
 		// Checkboxes!
1326
-		elseif ($var[0] == 'check')
1327
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1380
+		elseif ($var[0] == 'check') {
1381
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1382
+		}
1328 1383
 		// Select boxes!
1329
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1330
-			$setArray[$var[1]] = $_POST[$var[1]];
1331
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1384
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1385
+					$setArray[$var[1]] = $_POST[$var[1]];
1386
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1332 1387
 		{
1333 1388
 			// For security purposes we validate this line by line.
1334 1389
 			$lOptions = array();
1335
-			foreach ($_POST[$var[1]] as $invar)
1336
-				if (in_array($invar, array_keys($var[2])))
1390
+			foreach ($_POST[$var[1]] as $invar) {
1391
+							if (in_array($invar, array_keys($var[2])))
1337 1392
 					$lOptions[] = $invar;
1393
+			}
1338 1394
 
1339 1395
 			$setArray[$var[1]] = $smcFunc['json_encode']($lOptions);
1340 1396
 		}
@@ -1348,18 +1404,20 @@  discard block
 block discarded – undo
1348 1404
 				$request = $smcFunc['db_query']('', '
1349 1405
 					SELECT id_board
1350 1406
 					FROM {db_prefix}boards');
1351
-				while ($row = $smcFunc['db_fetch_row']($request))
1352
-					$board_list[$row[0]] = true;
1407
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1408
+									$board_list[$row[0]] = true;
1409
+				}
1353 1410
 
1354 1411
 				$smcFunc['db_free_result']($request);
1355 1412
 			}
1356 1413
 
1357 1414
 			$lOptions = array();
1358 1415
 
1359
-			if (!empty($_POST[$var[1]]))
1360
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1416
+			if (!empty($_POST[$var[1]])) {
1417
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1361 1418
 					if (isset($board_list[$invar]))
1362 1419
 						$lOptions[] = $invar;
1420
+			}
1363 1421
 
1364 1422
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1365 1423
 		}
@@ -1373,8 +1431,9 @@  discard block
 block discarded – undo
1373 1431
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1374 1432
 
1375 1433
 			// Do we have a max value for this as well?
1376
-			if (isset($var['max']))
1377
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1434
+			if (isset($var['max'])) {
1435
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1436
+			}
1378 1437
 		}
1379 1438
 		// Floating point!
1380 1439
 		elseif ($var[0] == 'float')
@@ -1386,39 +1445,46 @@  discard block
 block discarded – undo
1386 1445
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1387 1446
 
1388 1447
 			// Do we have a max value for this as well?
1389
-			if (isset($var['max']))
1390
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1448
+			if (isset($var['max'])) {
1449
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1450
+			}
1391 1451
 		}
1392 1452
 		// Text!
1393
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1394
-			$setArray[$var[1]] = $_POST[$var[1]];
1453
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1454
+					$setArray[$var[1]] = $_POST[$var[1]];
1455
+		}
1395 1456
 		// Passwords!
1396 1457
 		elseif ($var[0] == 'password')
1397 1458
 		{
1398
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1399
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1459
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1460
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1461
+			}
1400 1462
 		}
1401 1463
 		// BBC.
1402 1464
 		elseif ($var[0] == 'bbc')
1403 1465
 		{
1404 1466
 			$bbcTags = array();
1405
-			foreach (parse_bbc(false) as $tag)
1406
-				$bbcTags[] = $tag['tag'];
1467
+			foreach (parse_bbc(false) as $tag) {
1468
+							$bbcTags[] = $tag['tag'];
1469
+			}
1407 1470
 
1408
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1409
-				$_POST[$var[1] . '_enabledTags'] = array();
1410
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1411
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1471
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1472
+							$_POST[$var[1] . '_enabledTags'] = array();
1473
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1474
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1475
+			}
1412 1476
 
1413 1477
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1414 1478
 		}
1415 1479
 		// Permissions?
1416
-		elseif ($var[0] == 'permissions')
1417
-			$inlinePermissions[] = $var[1];
1480
+		elseif ($var[0] == 'permissions') {
1481
+					$inlinePermissions[] = $var[1];
1482
+		}
1418 1483
 	}
1419 1484
 
1420
-	if (!empty($setArray))
1421
-		updateSettings($setArray);
1485
+	if (!empty($setArray)) {
1486
+			updateSettings($setArray);
1487
+	}
1422 1488
 
1423 1489
 	// If we have inline permissions we need to save them.
1424 1490
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1455,18 +1521,21 @@  discard block
 block discarded – undo
1455 1521
 	// put all of it into an array
1456 1522
 	foreach ($info_lines as $line)
1457 1523
 	{
1458
-		if (preg_match('~(' . $remove . ')~', $line))
1459
-			continue;
1524
+		if (preg_match('~(' . $remove . ')~', $line)) {
1525
+					continue;
1526
+		}
1460 1527
 
1461 1528
 		// new category?
1462
-		if (strpos($line, '<h2>') !== false)
1463
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1529
+		if (strpos($line, '<h2>') !== false) {
1530
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1531
+		}
1464 1532
 
1465 1533
 		// load it as setting => value or the old setting local master
1466
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1467
-			$pinfo[$category][$val[1]] = $val[2];
1468
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1469
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1534
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1535
+					$pinfo[$category][$val[1]] = $val[2];
1536
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1537
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1538
+		}
1470 1539
 	}
1471 1540
 
1472 1541
 	// load it in to context and display it
@@ -1501,8 +1570,9 @@  discard block
 block discarded – undo
1501 1570
 				$testAPI = new $cache_class_name();
1502 1571
 
1503 1572
 				// No Support?  NEXT!
1504
-				if (!$testAPI->isSupported(true))
1505
-					continue;
1573
+				if (!$testAPI->isSupported(true)) {
1574
+									continue;
1575
+				}
1506 1576
 
1507 1577
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1508 1578
 			}
@@ -1527,8 +1597,9 @@  discard block
 block discarded – undo
1527 1597
 	global $modSettings, $boardurl, $smcFunc;
1528 1598
 
1529 1599
 	// Already have a key?  Can't register again.
1530
-	if (!empty($modSettings['sm_stats_key']))
1531
-		return true;
1600
+	if (!empty($modSettings['sm_stats_key'])) {
1601
+			return true;
1602
+	}
1532 1603
 
1533 1604
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1534 1605
 	if ($fp)
@@ -1539,8 +1610,9 @@  discard block
 block discarded – undo
1539 1610
 		fwrite($fp, $out);
1540 1611
 
1541 1612
 		$return_data = '';
1542
-		while (!feof($fp))
1543
-			$return_data .= fgets($fp, 128);
1613
+		while (!feof($fp)) {
1614
+					$return_data .= fgets($fp, 128);
1615
+		}
1544 1616
 
1545 1617
 		fclose($fp);
1546 1618
 
Please login to merge, or discard this patch.
Sources/Errors.php 1 patch
Braces   +133 added lines, -95 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Log an error, if the error logging is enabled.
@@ -39,10 +40,11 @@  discard block
 block discarded – undo
39 40
 	$error_call++;
40 41
 
41 42
 	// Collect a backtrace
42
-	if (!isset($db_show_debug) || $db_show_debug === false)
43
-		$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
44
-	else
45
-		$backtrace = debug_backtrace();
43
+	if (!isset($db_show_debug) || $db_show_debug === false) {
44
+			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
45
+	} else {
46
+			$backtrace = debug_backtrace();
47
+	}
46 48
 
47 49
 	// are we in a loop?
48 50
 	if($error_call > 2)
@@ -52,8 +54,9 @@  discard block
 block discarded – undo
52 54
 	}
53 55
 
54 56
 	// Check if error logging is actually on.
55
-	if (empty($modSettings['enableErrorLogging']))
56
-		return $error_message;
57
+	if (empty($modSettings['enableErrorLogging'])) {
58
+			return $error_message;
59
+	}
57 60
 
58 61
 	// Basically, htmlspecialchars it minus &. (for entities!)
59 62
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -61,33 +64,39 @@  discard block
 block discarded – undo
61 64
 
62 65
 	// Add a file and line to the error message?
63 66
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
64
-	if ($file == null)
65
-		$file = '';
66
-	else
67
-		// Window style slashes don't play well, lets convert them to the unix style.
67
+	if ($file == null) {
68
+			$file = '';
69
+	} else {
70
+			// Window style slashes don't play well, lets convert them to the unix style.
68 71
 		$file = str_replace('\\', '/', $file);
72
+	}
69 73
 
70
-	if ($line == null)
71
-		$line = 0;
72
-	else
73
-		$line = (int) $line;
74
+	if ($line == null) {
75
+			$line = 0;
76
+	} else {
77
+			$line = (int) $line;
78
+	}
74 79
 
75 80
 	// Just in case there's no id_member or IP set yet.
76
-	if (empty($user_info['id']))
77
-		$user_info['id'] = 0;
78
-	if (empty($user_info['ip']))
79
-		$user_info['ip'] = '';
81
+	if (empty($user_info['id'])) {
82
+			$user_info['id'] = 0;
83
+	}
84
+	if (empty($user_info['ip'])) {
85
+			$user_info['ip'] = '';
86
+	}
80 87
 
81 88
 	// Find the best query string we can...
82 89
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
83 90
 
84 91
 	// Don't log the session hash in the url twice, it's a waste.
85
-	if (!empty($smcFunc['htmlspecialchars']))
86
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
92
+	if (!empty($smcFunc['htmlspecialchars'])) {
93
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
94
+	}
87 95
 
88 96
 	// Just so we know what board error messages are from.
89
-	if (isset($_POST['board']) && !isset($_GET['board']))
90
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
97
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
98
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
99
+	}
91 100
 
92 101
 	// What types of categories do we have?
93 102
 	$known_error_types = array(
@@ -140,9 +149,9 @@  discard block
 block discarded – undo
140 149
 
141 150
 			list($context['num_errors']) = $smcFunc['db_fetch_row']($query);
142 151
 			$smcFunc['db_free_result']($query);
152
+		} else {
153
+					$context['num_errors']++;
143 154
 		}
144
-		else
145
-			$context['num_errors']++;
146 155
 	}
147 156
 
148 157
 	// reset error call
@@ -164,12 +173,14 @@  discard block
 block discarded – undo
164 173
 	global $txt;
165 174
 
166 175
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
167
-	if (!empty($status))
168
-		send_http_status($status);
176
+	if (!empty($status)) {
177
+			send_http_status($status);
178
+	}
169 179
 
170 180
 	// We don't have $txt yet, but that's okay...
171
-	if (empty($txt))
172
-		die($error);
181
+	if (empty($txt)) {
182
+			die($error);
183
+	}
173 184
 
174 185
 	log_error_online($error, false);
175 186
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -196,8 +207,9 @@  discard block
 block discarded – undo
196 207
 	static $fatal_error_called = false;
197 208
 
198 209
 	// Send the status header - set this to 0 or false if you don't want to send one at all
199
-	if (!empty($status))
200
-		send_http_status($status);
210
+	if (!empty($status)) {
211
+			send_http_status($status);
212
+	}
201 213
 
202 214
 	// Try to load a theme if we don't have one.
203 215
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -207,8 +219,9 @@  discard block
 block discarded – undo
207 219
 	}
208 220
 
209 221
 	// If we have no theme stuff we can't have the language file...
210
-	if (empty($context['theme_loaded']))
211
-		die($error);
222
+	if (empty($context['theme_loaded'])) {
223
+			die($error);
224
+	}
212 225
 
213 226
 	$reload_lang_file = true;
214 227
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -244,8 +257,9 @@  discard block
 block discarded – undo
244 257
 	global $settings, $modSettings, $db_show_debug;
245 258
 
246 259
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
247
-	if (error_reporting() == 0)
248
-		return;
260
+	if (error_reporting() == 0) {
261
+			return;
262
+	}
249 263
 
250 264
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
251 265
 	{
@@ -253,19 +267,22 @@  discard block
 block discarded – undo
253 267
 		$count = count($array);
254 268
 		for ($i = 0; $i < $count; $i++)
255 269
 		{
256
-			if ($array[$i]['function'] != 'loadSubTemplate')
257
-				continue;
270
+			if ($array[$i]['function'] != 'loadSubTemplate') {
271
+							continue;
272
+			}
258 273
 
259 274
 			// This is a bug in PHP, with eval, it seems!
260
-			if (empty($array[$i]['args']))
261
-				$i++;
275
+			if (empty($array[$i]['args'])) {
276
+							$i++;
277
+			}
262 278
 			break;
263 279
 		}
264 280
 
265
-		if (isset($array[$i]) && !empty($array[$i]['args']))
266
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
267
-		else
268
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
281
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
282
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
283
+		} else {
284
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
285
+		}
269 286
 	}
270 287
 
271 288
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -274,8 +291,9 @@  discard block
 block discarded – undo
274 291
 		if ($error_level % 255 != E_ERROR)
275 292
 		{
276 293
 			$temporary = ob_get_contents();
277
-			if (substr($temporary, -2) == '="')
278
-				echo '"';
294
+			if (substr($temporary, -2) == '="') {
295
+							echo '"';
296
+			}
279 297
 		}
280 298
 
281 299
 		// Debugging!  This should look like a PHP error message.
@@ -291,23 +309,27 @@  discard block
 block discarded – undo
291 309
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
292 310
 
293 311
 	// Dying on these errors only causes MORE problems (blank pages!)
294
-	if ($file == 'Unknown')
295
-		return;
312
+	if ($file == 'Unknown') {
313
+			return;
314
+	}
296 315
 
297 316
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
298
-	if ($error_level % 255 == E_ERROR)
299
-		obExit(false);
300
-	else
301
-		return;
317
+	if ($error_level % 255 == E_ERROR) {
318
+			obExit(false);
319
+	} else {
320
+			return;
321
+	}
302 322
 
303 323
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
304
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
305
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
324
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
325
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
326
+	}
306 327
 
307 328
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
308
-	if ($error_level % 255 == E_ERROR)
309
-		die('No direct access...');
310
-}
329
+	if ($error_level % 255 == E_ERROR) {
330
+			die('No direct access...');
331
+	}
332
+	}
311 333
 
312 334
 /**
313 335
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -323,24 +345,28 @@  discard block
 block discarded – undo
323 345
 
324 346
 	// Attempt to prevent a recursive loop.
325 347
 	++$level;
326
-	if ($level > 1)
327
-		return false;
348
+	if ($level > 1) {
349
+			return false;
350
+	}
328 351
 
329 352
 	// Maybe they came from dlattach or similar?
330
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
331
-		loadTheme();
353
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
354
+			loadTheme();
355
+	}
332 356
 
333 357
 	// Don't bother indexing errors mate...
334 358
 	$context['robot_no_index'] = true;
335 359
 
336
-	if (!isset($context['error_title']))
337
-		$context['error_title'] = $txt['error_occured'];
360
+	if (!isset($context['error_title'])) {
361
+			$context['error_title'] = $txt['error_occured'];
362
+	}
338 363
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
339 364
 
340 365
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
341 366
 
342
-	if (empty($context['page_title']))
343
-		$context['page_title'] = $context['error_title'];
367
+	if (empty($context['page_title'])) {
368
+			$context['page_title'] = $context['error_title'];
369
+	}
344 370
 
345 371
 	loadTemplate('Errors');
346 372
 	$context['sub_template'] = 'fatal_error';
@@ -348,23 +374,26 @@  discard block
 block discarded – undo
348 374
 	// If this is SSI, what do they want us to do?
349 375
 	if (SMF == 'SSI')
350 376
 	{
351
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
352
-			$ssi_on_error_method();
353
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
354
-			loadSubTemplate('fatal_error');
377
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
378
+					$ssi_on_error_method();
379
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
380
+					loadSubTemplate('fatal_error');
381
+		}
355 382
 
356 383
 		// No layers?
357
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
358
-			exit;
384
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
385
+					exit;
386
+		}
359 387
 	}
360 388
 	// Alternatively from the cron call?
361 389
 	elseif (SMF == 'BACKGROUND')
362 390
 	{
363 391
 		// We can't rely on even having language files available.
364
-		if (defined('FROM_CLI') && FROM_CLI)
365
-			echo 'cron error: ', $context['error_message'];
366
-		else
367
-			echo 'An error occurred. More information may be available in your logs.';
392
+		if (defined('FROM_CLI') && FROM_CLI) {
393
+					echo 'cron error: ', $context['error_message'];
394
+		} else {
395
+					echo 'An error occurred. More information may be available in your logs.';
396
+		}
368 397
 		exit;
369 398
 	}
370 399
 
@@ -392,8 +421,8 @@  discard block
 block discarded – undo
392 421
 
393 422
 	set_fatal_error_headers();
394 423
 
395
-	if (!empty($maintenance))
396
-		echo '<!DOCTYPE html>
424
+	if (!empty($maintenance)) {
425
+			echo '<!DOCTYPE html>
397 426
 <html>
398 427
 	<head>
399 428
 		<meta name="robots" content="noindex">
@@ -404,6 +433,7 @@  discard block
 block discarded – undo
404 433
 		', $mmessage, '
405 434
 	</body>
406 435
 </html>';
436
+	}
407 437
 
408 438
 	die();
409 439
 }
@@ -425,15 +455,17 @@  discard block
 block discarded – undo
425 455
 	// For our purposes, we're gonna want this on if at all possible.
426 456
 	$modSettings['cache_enable'] = '1';
427 457
 
428
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
429
-		$db_last_error = max($db_last_error, $temp);
458
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
459
+			$db_last_error = max($db_last_error, $temp);
460
+	}
430 461
 
431 462
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
432 463
 	{
433 464
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
434 465
 		cache_put_data('db_last_error', time(), 600);
435
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
436
-			logLastDatabaseError();
466
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
467
+					logLastDatabaseError();
468
+		}
437 469
 
438 470
 		// Language files aren't loaded yet :(.
439 471
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -490,8 +522,9 @@  discard block
 block discarded – undo
490 522
  */
491 523
 function set_fatal_error_headers()
492 524
 {
493
-	if (headers_sent())
494
-		return;
525
+	if (headers_sent()) {
526
+			return;
527
+	}
495 528
 
496 529
 	// Don't cache this page!
497 530
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -517,12 +550,14 @@  discard block
 block discarded – undo
517 550
 	global $smcFunc, $user_info, $modSettings;
518 551
 
519 552
 	// Don't bother if Who's Online is disabled.
520
-	if (empty($modSettings['who_enabled']))
521
-		return;
553
+	if (empty($modSettings['who_enabled'])) {
554
+			return;
555
+	}
522 556
 
523 557
 	// Maybe they came from SSI or similar where sessions are not recorded?
524
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
525
-		return;
558
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
559
+			return;
560
+	}
526 561
 
527 562
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
528 563
 
@@ -548,11 +583,13 @@  discard block
 block discarded – undo
548 583
 		$url = $smcFunc['json_decode']($url, true);
549 584
 		$url['error'] = $error;
550 585
 		// Url field got a max length of 1024 in db
551
-		if (strlen($url['error']) > 500)
552
-			$url['error'] = substr($url['error'],0,500);
586
+		if (strlen($url['error']) > 500) {
587
+					$url['error'] = substr($url['error'],0,500);
588
+		}
553 589
 
554
-		if (!empty($sprintf))
555
-			$url['error_params'] = $sprintf;
590
+		if (!empty($sprintf)) {
591
+					$url['error_params'] = $sprintf;
592
+		}
556 593
 
557 594
 		$smcFunc['db_query']('', '
558 595
 			UPDATE {db_prefix}log_online
@@ -583,10 +620,11 @@  discard block
 block discarded – undo
583 620
 
584 621
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
585 622
 
586
-	if (!isset($statuses[$code]))
587
-		header($protocol . ' 500 Internal Server Error');
588
-	else
589
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
590
-}
623
+	if (!isset($statuses[$code])) {
624
+			header($protocol . ' 500 Internal Server Error');
625
+	} else {
626
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
627
+	}
628
+	}
591 629
 
592 630
 ?>
593 631
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageBans.php 1 patch
Braces   +257 added lines, -207 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ban center. The main entrance point for all ban center functions.
@@ -120,10 +121,11 @@  discard block
 block discarded – undo
120 121
 	}
121 122
 
122 123
 	// Create a date string so we don't overload them with date info.
123
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
124
-		$context['ban_time_format'] = $user_info['time_format'];
125
-	else
126
-		$context['ban_time_format'] = $matches[0];
124
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
125
+			$context['ban_time_format'] = $user_info['time_format'];
126
+	} else {
127
+			$context['ban_time_format'] = $matches[0];
128
+	}
127 129
 
128 130
 	$listOptions = array(
129 131
 		'id' => 'ban_list',
@@ -201,16 +203,19 @@  discard block
 block discarded – undo
201 203
 					'function' => function($rowData) use ($txt)
202 204
 					{
203 205
 						// This ban never expires...whahaha.
204
-						if ($rowData['expire_time'] === null)
205
-							return $txt['never'];
206
+						if ($rowData['expire_time'] === null) {
207
+													return $txt['never'];
208
+						}
206 209
 
207 210
 						// This ban has already expired.
208
-						elseif ($rowData['expire_time'] < time())
209
-							return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
211
+						elseif ($rowData['expire_time'] < time()) {
212
+													return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
213
+						}
210 214
 
211 215
 						// Still need to wait a few days for this ban to expire.
212
-						else
213
-							return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
216
+						else {
217
+													return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
218
+						}
214 219
 					},
215 220
 				),
216 221
 				'sort' => array(
@@ -320,8 +325,9 @@  discard block
 block discarded – undo
320 325
 		)
321 326
 	);
322 327
 	$bans = array();
323
-	while ($row = $smcFunc['db_fetch_assoc']($request))
324
-		$bans[] = $row;
328
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
329
+			$bans[] = $row;
330
+	}
325 331
 
326 332
 	$smcFunc['db_free_result']($request);
327 333
 
@@ -363,8 +369,9 @@  discard block
 block discarded – undo
363 369
 {
364 370
 	global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir;
365 371
 
366
-	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
367
-		BanEdit2();
372
+	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) {
373
+			BanEdit2();
374
+	}
368 375
 
369 376
 	$ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
370 377
 
@@ -373,11 +380,10 @@  discard block
 block discarded – undo
373 380
 	createToken('admin-bet');
374 381
 	$context['form_url'] = $scripturl . '?action=admin;area=ban;sa=edit';
375 382
 
376
-	if (!empty($context['ban_errors']))
377
-		foreach ($context['ban_errors'] as $error)
383
+	if (!empty($context['ban_errors'])) {
384
+			foreach ($context['ban_errors'] as $error)
378 385
 			$context['error_messages'][$error] = $txt[$error];
379
-
380
-	else
386
+	} else
381 387
 	{
382 388
 		// If we're editing an existing ban, get it from the database.
383 389
 		if (!empty($ban_group_id))
@@ -413,12 +419,13 @@  discard block
 block discarded – undo
413 419
 						'data' => array(
414 420
 							'function' => function($ban_item) use ($txt)
415 421
 							{
416
-								if (in_array($ban_item['type'], array('ip', 'hostname', 'email')))
417
-									return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
418
-								elseif ($ban_item['type'] == 'user')
419
-									return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
420
-								else
421
-									return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
422
+								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) {
423
+																	return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
424
+								} elseif ($ban_item['type'] == 'user') {
425
+																	return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
426
+								} else {
427
+																	return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
428
+								}
422 429
 							},
423 430
 							'style' => 'text-align: left;',
424 431
 						),
@@ -556,8 +563,9 @@  discard block
 block discarded – undo
556 563
 					$context['ban']['from_user'] = true;
557 564
 
558 565
 					// Would be nice if we could also ban the hostname.
559
-					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup']))
560
-						$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
566
+					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) {
567
+											$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
568
+					}
561 569
 
562 570
 					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
563 571
 				}
@@ -625,8 +633,9 @@  discard block
 block discarded – undo
625 633
 			'items_per_page' => $items_per_page,
626 634
 		)
627 635
 	);
628
-	if ($smcFunc['db_num_rows']($request) == 0)
629
-		fatal_lang_error('ban_not_found', false);
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			fatal_lang_error('ban_not_found', false);
638
+	}
630 639
 
631 640
 	while ($row = $smcFunc['db_fetch_assoc']($request))
632 641
 	{
@@ -663,18 +672,15 @@  discard block
 block discarded – undo
663 672
 			{
664 673
 				$ban_items[$row['id_ban']]['type'] = 'ip';
665 674
 				$ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);
666
-			}
667
-			elseif (!empty($row['hostname']))
675
+			} elseif (!empty($row['hostname']))
668 676
 			{
669 677
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
670 678
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
671
-			}
672
-			elseif (!empty($row['email_address']))
679
+			} elseif (!empty($row['email_address']))
673 680
 			{
674 681
 				$ban_items[$row['id_ban']]['type'] = 'email';
675 682
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
676
-			}
677
-			elseif (!empty($row['id_member']))
683
+			} elseif (!empty($row['id_member']))
678 684
 			{
679 685
 				$ban_items[$row['id_ban']]['type'] = 'user';
680 686
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -740,9 +746,10 @@  discard block
 block discarded – undo
740 746
 	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError');
741 747
 
742 748
 	$return = array();
743
-	foreach ($search_list as $key => $callable)
744
-		if (is_callable($callable))
749
+	foreach ($search_list as $key => $callable) {
750
+			if (is_callable($callable))
745 751
 			$return[$key] = call_user_func($callable, $member_id);
752
+	}
746 753
 
747 754
 	return $return;
748 755
 }
@@ -767,8 +774,9 @@  discard block
 block discarded – undo
767 774
 			'current_user' => $member_id,
768 775
 		)
769 776
 	);
770
-	while ($row = $smcFunc['db_fetch_assoc']($request))
771
-		$message_ips[] = inet_dtop($row['poster_ip']);
777
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
778
+			$message_ips[] = inet_dtop($row['poster_ip']);
779
+	}
772 780
 	$smcFunc['db_free_result']($request);
773 781
 
774 782
 	return $message_ips;
@@ -793,8 +801,9 @@  discard block
 block discarded – undo
793 801
 			'current_user' => $member_id,
794 802
 		)
795 803
 	);
796
-	while ($row = $smcFunc['db_fetch_assoc']($request))
797
-	    $error_ips[] = inet_dtop($row['ip']);
804
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
805
+		    $error_ips[] = inet_dtop($row['ip']);
806
+	}
798 807
 	$smcFunc['db_free_result']($request);
799 808
 
800 809
 	return $error_ips;
@@ -835,11 +844,13 @@  discard block
 block discarded – undo
835 844
 		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
836 845
 
837 846
 		// Adding a new ban group
838
-		if (empty($_REQUEST['bg']))
839
-			$ban_group_id = insertBanGroup($ban_info);
847
+		if (empty($_REQUEST['bg'])) {
848
+					$ban_group_id = insertBanGroup($ban_info);
849
+		}
840 850
 		// Editing an existing ban group
841
-		else
842
-			$ban_group_id = updateBanGroup($ban_info);
851
+		else {
852
+					$ban_group_id = updateBanGroup($ban_info);
853
+		}
843 854
 
844 855
 		if (is_numeric($ban_group_id))
845 856
 		{
@@ -850,9 +861,10 @@  discard block
 block discarded – undo
850 861
 		$context['ban'] = $ban_info;
851 862
 	}
852 863
 
853
-	if (isset($_POST['ban_suggestions']))
854
-		// @TODO: is $_REQUEST['bi'] ever set?
864
+	if (isset($_POST['ban_suggestions'])) {
865
+			// @TODO: is $_REQUEST['bi'] ever set?
855 866
 		$saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
867
+	}
856 868
 
857 869
 	// Something went wrong somewhere... Oh well, let's go back.
858 870
 	if (!empty($context['ban_errors']))
@@ -862,8 +874,9 @@  discard block
 block discarded – undo
862 874
 		$context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
863 875
 
864 876
 		// Not strictly necessary, but it's nice
865
-		if (!empty($context['ban_suggestions']['member']['id']))
866
-			$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
877
+		if (!empty($context['ban_suggestions']['member']['id'])) {
878
+					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
879
+		}
867 880
 		return BanEdit();
868 881
 	}
869 882
 	$context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();
@@ -910,10 +923,11 @@  discard block
 block discarded – undo
910 923
 
911 924
 	foreach ($suggestions as $key => $value)
912 925
 	{
913
-		if (is_array($value))
914
-			$triggers[$key] = $value;
915
-		else
916
-			$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
926
+		if (is_array($value)) {
927
+					$triggers[$key] = $value;
928
+		} else {
929
+					$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
930
+		}
917 931
 	}
918 932
 
919 933
 	$ban_triggers = validateTriggers($triggers);
@@ -921,16 +935,18 @@  discard block
 block discarded – undo
921 935
 	// Time to save!
922 936
 	if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))
923 937
 	{
924
-		if (empty($ban_id))
925
-			addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
926
-		else
927
-			updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
938
+		if (empty($ban_id)) {
939
+					addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
940
+		} else {
941
+					updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
942
+		}
943
+	}
944
+	if (!empty($context['ban_errors'])) {
945
+			return $triggers;
946
+	} else {
947
+			return false;
948
+	}
928 949
 	}
929
-	if (!empty($context['ban_errors']))
930
-		return $triggers;
931
-	else
932
-		return false;
933
-}
934 950
 
935 951
 /**
936 952
  * This function removes a bunch of triggers based on ids
@@ -944,14 +960,17 @@  discard block
 block discarded – undo
944 960
 {
945 961
 	global $smcFunc, $scripturl;
946 962
 
947
-	if ($group_id !== false)
948
-		$group_id = (int) $group_id;
963
+	if ($group_id !== false) {
964
+			$group_id = (int) $group_id;
965
+	}
949 966
 
950
-	if (empty($group_id) && empty($items_ids))
951
-		return false;
967
+	if (empty($group_id) && empty($items_ids)) {
968
+			return false;
969
+	}
952 970
 
953
-	if (!is_array($items_ids))
954
-		$items_ids = array($items_ids);
971
+	if (!is_array($items_ids)) {
972
+			$items_ids = array($items_ids);
973
+	}
955 974
 
956 975
 	$log_info = array();
957 976
 	$ban_items = array();
@@ -989,8 +1008,7 @@  discard block
 block discarded – undo
989 1008
 					'bantype' => ($is_range ? 'ip_range' : 'main_ip'),
990 1009
 					'value' => $ban_items[$row['id_ban']]['ip'],
991 1010
 				);
992
-			}
993
-			elseif (!empty($row['hostname']))
1011
+			} elseif (!empty($row['hostname']))
994 1012
 			{
995 1013
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
996 1014
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
@@ -998,8 +1016,7 @@  discard block
 block discarded – undo
998 1016
 					'bantype' => 'hostname',
999 1017
 					'value' => $row['hostname'],
1000 1018
 				);
1001
-			}
1002
-			elseif (!empty($row['email_address']))
1019
+			} elseif (!empty($row['email_address']))
1003 1020
 			{
1004 1021
 				$ban_items[$row['id_ban']]['type'] = 'email';
1005 1022
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
@@ -1007,8 +1024,7 @@  discard block
 block discarded – undo
1007 1024
 					'bantype' => 'email',
1008 1025
 					'value' => $ban_items[$row['id_ban']]['email'],
1009 1026
 				);
1010
-			}
1011
-			elseif (!empty($row['id_member']))
1027
+			} elseif (!empty($row['id_member']))
1012 1028
 			{
1013 1029
 				$ban_items[$row['id_ban']]['type'] = 'user';
1014 1030
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -1041,8 +1057,7 @@  discard block
 block discarded – undo
1041 1057
 				'ban_group' => $group_id,
1042 1058
 			)
1043 1059
 		);
1044
-	}
1045
-	elseif (!empty($items_ids))
1060
+	} elseif (!empty($items_ids))
1046 1061
 	{
1047 1062
 		$smcFunc['db_query']('', '
1048 1063
 			DELETE FROM {db_prefix}ban_items
@@ -1067,13 +1082,15 @@  discard block
 block discarded – undo
1067 1082
 {
1068 1083
 	global $smcFunc;
1069 1084
 
1070
-	if (!is_array($group_ids))
1071
-		$group_ids = array($group_ids);
1085
+	if (!is_array($group_ids)) {
1086
+			$group_ids = array($group_ids);
1087
+	}
1072 1088
 
1073 1089
 	$group_ids = array_unique($group_ids);
1074 1090
 
1075
-	if (empty($group_ids))
1076
-		return false;
1091
+	if (empty($group_ids)) {
1092
+			return false;
1093
+	}
1077 1094
 
1078 1095
 	$smcFunc['db_query']('', '
1079 1096
 		DELETE FROM {db_prefix}ban_groups
@@ -1097,21 +1114,23 @@  discard block
 block discarded – undo
1097 1114
 {
1098 1115
 	global $smcFunc;
1099 1116
 
1100
-	if (empty($ids))
1101
-		$smcFunc['db_query']('truncate_table', '
1117
+	if (empty($ids)) {
1118
+			$smcFunc['db_query']('truncate_table', '
1102 1119
 			TRUNCATE {db_prefix}log_banned',
1103 1120
 			array(
1104 1121
 			)
1105 1122
 		);
1106
-	else
1123
+	} else
1107 1124
 	{
1108
-		if (!is_array($ids))
1109
-			$ids = array($ids);
1125
+		if (!is_array($ids)) {
1126
+					$ids = array($ids);
1127
+		}
1110 1128
 
1111 1129
 		$ids = array_unique($ids);
1112 1130
 
1113
-		if (empty($ids))
1114
-			return false;
1131
+		if (empty($ids)) {
1132
+					return false;
1133
+		}
1115 1134
 
1116 1135
 		$smcFunc['db_query']('', '
1117 1136
 			DELETE FROM {db_prefix}log_banned
@@ -1137,8 +1156,9 @@  discard block
 block discarded – undo
1137 1156
 {
1138 1157
 	global $context, $smcFunc;
1139 1158
 
1140
-	if (empty($triggers))
1141
-		$context['ban_erros'][] = 'ban_empty_triggers';
1159
+	if (empty($triggers)) {
1160
+			$context['ban_erros'][] = 'ban_empty_triggers';
1161
+	}
1142 1162
 
1143 1163
 	$ban_triggers = array();
1144 1164
 	$log_info = array();
@@ -1147,39 +1167,39 @@  discard block
 block discarded – undo
1147 1167
 	{
1148 1168
 		if (!empty($value))
1149 1169
 		{
1150
-			if ($key == 'member')
1151
-				continue;
1170
+			if ($key == 'member') {
1171
+							continue;
1172
+			}
1152 1173
 
1153 1174
 			if ($key == 'main_ip')
1154 1175
 			{
1155 1176
 				$value = trim($value);
1156 1177
 				$ip_parts = ip2range($value);
1157
-				if (!checkExistingTriggerIP($ip_parts, $value))
1158
-					$context['ban_erros'][] = 'invalid_ip';
1159
-				else
1178
+				if (!checkExistingTriggerIP($ip_parts, $value)) {
1179
+									$context['ban_erros'][] = 'invalid_ip';
1180
+				} else
1160 1181
 				{
1161 1182
 					$ban_triggers['main_ip'] = array(
1162 1183
 						'ip_low' => $ip_parts['low'],
1163 1184
 						'ip_high' => $ip_parts['high']
1164 1185
 					);
1165 1186
 				}
1166
-			}
1167
-			elseif ($key == 'hostname')
1187
+			} elseif ($key == 'hostname')
1168 1188
 			{
1169
-				if (preg_match('/[^\w.\-*]/', $value) == 1)
1170
-					$context['ban_erros'][] = 'invalid_hostname';
1171
-				else
1189
+				if (preg_match('/[^\w.\-*]/', $value) == 1) {
1190
+									$context['ban_erros'][] = 'invalid_hostname';
1191
+				} else
1172 1192
 				{
1173 1193
 					// Replace the * wildcard by a MySQL wildcard %.
1174 1194
 					$value = substr(str_replace('*', '%', $value), 0, 255);
1175 1195
 
1176 1196
 					$ban_triggers['hostname']['hostname'] = $value;
1177 1197
 				}
1178
-			}
1179
-			elseif ($key == 'email')
1198
+			} elseif ($key == 'email')
1180 1199
 			{
1181
-				if (preg_match('/[^\w.\-\+*@]/', $value) == 1)
1182
-					$context['ban_erros'][] = 'invalid_email';
1200
+				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) {
1201
+									$context['ban_erros'][] = 'invalid_email';
1202
+				}
1183 1203
 
1184 1204
 				// Check the user is not banning an admin.
1185 1205
 				$request = $smcFunc['db_query']('', '
@@ -1193,15 +1213,15 @@  discard block
 block discarded – undo
1193 1213
 						'email' => $value,
1194 1214
 					)
1195 1215
 				);
1196
-				if ($smcFunc['db_num_rows']($request) != 0)
1197
-					$context['ban_erros'][] = 'no_ban_admin';
1216
+				if ($smcFunc['db_num_rows']($request) != 0) {
1217
+									$context['ban_erros'][] = 'no_ban_admin';
1218
+				}
1198 1219
 				$smcFunc['db_free_result']($request);
1199 1220
 
1200 1221
 				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255);
1201 1222
 
1202 1223
 				$ban_triggers['email']['email_address'] = $value;
1203
-			}
1204
-			elseif ($key == 'user')
1224
+			} elseif ($key == 'user')
1205 1225
 			{
1206 1226
 				$user = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES));
1207 1227
 
@@ -1215,8 +1235,9 @@  discard block
 block discarded – undo
1215 1235
 						'username' => $user,
1216 1236
 					)
1217 1237
 				);
1218
-				if ($smcFunc['db_num_rows']($request) == 0)
1219
-					$context['ban_erros'][] = 'invalid_username';
1238
+				if ($smcFunc['db_num_rows']($request) == 0) {
1239
+									$context['ban_erros'][] = 'invalid_username';
1240
+				}
1220 1241
 				list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);
1221 1242
 				$smcFunc['db_free_result']($request);
1222 1243
 
@@ -1224,25 +1245,25 @@  discard block
 block discarded – undo
1224 1245
 				{
1225 1246
 					unset($value);
1226 1247
 					$context['ban_erros'][] = 'no_ban_admin';
1248
+				} else {
1249
+									$ban_triggers['user']['id_member'] = $value;
1227 1250
 				}
1228
-				else
1229
-					$ban_triggers['user']['id_member'] = $value;
1230
-			}
1231
-			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1251
+			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1232 1252
 			{
1233 1253
 				// Special case, those two are arrays themselves
1234 1254
 				$values = array_unique($value);
1235 1255
 				// Don't add the main IP again.
1236
-				if (isset($triggers['main_ip']))
1237
-					$values = array_diff($values, array($triggers['main_ip']));
1256
+				if (isset($triggers['main_ip'])) {
1257
+									$values = array_diff($values, array($triggers['main_ip']));
1258
+				}
1238 1259
 				unset($value);
1239 1260
 				foreach ($values as $val)
1240 1261
 				{
1241 1262
 					$val = trim($val);
1242 1263
 					$ip_parts = ip2range($val);
1243
-					if (!checkExistingTriggerIP($ip_parts, $val))
1244
-						$context['ban_erros'][] = 'invalid_ip';
1245
-					else
1264
+					if (!checkExistingTriggerIP($ip_parts, $val)) {
1265
+											$context['ban_erros'][] = 'invalid_ip';
1266
+					} else
1246 1267
 					{
1247 1268
 						$ban_triggers[$key][] = array(
1248 1269
 							'ip_low' => $ip_parts['low'],
@@ -1255,15 +1276,16 @@  discard block
 block discarded – undo
1255 1276
 						);
1256 1277
 					}
1257 1278
 				}
1279
+			} else {
1280
+							$context['ban_erros'][] = 'no_bantype_selected';
1258 1281
 			}
1259
-			else
1260
-				$context['ban_erros'][] = 'no_bantype_selected';
1261 1282
 
1262
-			if (isset($value) && !is_array($value))
1263
-				$log_info[] = array(
1283
+			if (isset($value) && !is_array($value)) {
1284
+							$log_info[] = array(
1264 1285
 					'value' => $value,
1265 1286
 					'bantype' => $key,
1266 1287
 				);
1288
+			}
1267 1289
 		}
1268 1290
 	}
1269 1291
 	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info);
@@ -1283,8 +1305,9 @@  discard block
 block discarded – undo
1283 1305
 {
1284 1306
 	global $smcFunc, $context;
1285 1307
 
1286
-	if (empty($group_id))
1287
-		$context['ban_errors'][] = 'ban_id_empty';
1308
+	if (empty($group_id)) {
1309
+			$context['ban_errors'][] = 'ban_id_empty';
1310
+	}
1288 1311
 
1289 1312
 	// Preset all values that are required.
1290 1313
 	$values = array(
@@ -1309,18 +1332,21 @@  discard block
 block discarded – undo
1309 1332
 	foreach ($triggers as $key => $trigger)
1310 1333
 	{
1311 1334
 		// Exceptions, exceptions, exceptions...always exceptions... :P
1312
-		if (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1313
-			foreach ($trigger as $real_trigger)
1335
+		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) {
1336
+					foreach ($trigger as $real_trigger)
1314 1337
 				$insertTriggers[] = array_merge($values, $real_trigger);
1315
-		else
1316
-			$insertTriggers[] = array_merge($values, $trigger);
1338
+		} else {
1339
+					$insertTriggers[] = array_merge($values, $trigger);
1340
+		}
1317 1341
 	}
1318 1342
 
1319
-	if (empty($insertTriggers))
1320
-		$context['ban_errors'][] = 'ban_no_triggers';
1343
+	if (empty($insertTriggers)) {
1344
+			$context['ban_errors'][] = 'ban_no_triggers';
1345
+	}
1321 1346
 
1322
-	if (!empty($context['ban_errors']))
1323
-		return false;
1347
+	if (!empty($context['ban_errors'])) {
1348
+			return false;
1349
+	}
1324 1350
 
1325 1351
 	$smcFunc['db_insert']('',
1326 1352
 		'{db_prefix}ban_items',
@@ -1348,15 +1374,19 @@  discard block
 block discarded – undo
1348 1374
 {
1349 1375
 	global $smcFunc, $context;
1350 1376
 
1351
-	if (empty($ban_item))
1352
-		$context['ban_errors'][] = 'ban_ban_item_empty';
1353
-	if (empty($group_id))
1354
-		$context['ban_errors'][] = 'ban_id_empty';
1355
-	if (empty($trigger))
1356
-		$context['ban_errors'][] = 'ban_no_triggers';
1377
+	if (empty($ban_item)) {
1378
+			$context['ban_errors'][] = 'ban_ban_item_empty';
1379
+	}
1380
+	if (empty($group_id)) {
1381
+			$context['ban_errors'][] = 'ban_id_empty';
1382
+	}
1383
+	if (empty($trigger)) {
1384
+			$context['ban_errors'][] = 'ban_no_triggers';
1385
+	}
1357 1386
 
1358
-	if (!empty($context['ban_errors']))
1359
-		return;
1387
+	if (!empty($context['ban_errors'])) {
1388
+			return;
1389
+	}
1360 1390
 
1361 1391
 	// Preset all values that are required.
1362 1392
 	$values = array(
@@ -1397,8 +1427,9 @@  discard block
 block discarded – undo
1397 1427
  */
1398 1428
 function logTriggersUpdates($logs, $new = true, $removal = false)
1399 1429
 {
1400
-	if (empty($logs))
1401
-		return;
1430
+	if (empty($logs)) {
1431
+			return;
1432
+	}
1402 1433
 
1403 1434
 	$log_name_map = array(
1404 1435
 		'main_ip' => 'ip_range',
@@ -1409,14 +1440,15 @@  discard block
 block discarded – undo
1409 1440
 	);
1410 1441
 
1411 1442
 	// Log the addion of the ban entries into the moderation log.
1412
-	foreach ($logs as $log)
1413
-		logAction('ban' . ($removal == true ? 'remove' : ''), array(
1443
+	foreach ($logs as $log) {
1444
+			logAction('ban' . ($removal == true ? 'remove' : ''), array(
1414 1445
 			$log_name_map[$log['bantype']] => $log['value'],
1415 1446
 			'new' => empty($new) ? 0 : 1,
1416 1447
 			'remove' => empty($removal) ? 0 : 1,
1417 1448
 			'type' => $log['bantype'],
1418 1449
 		));
1419
-}
1450
+	}
1451
+	}
1420 1452
 
1421 1453
 /**
1422 1454
  * Updates an existing ban group
@@ -1430,12 +1462,15 @@  discard block
 block discarded – undo
1430 1462
 {
1431 1463
 	global $smcFunc, $context;
1432 1464
 
1433
-	if (empty($ban_info['name']))
1434
-		$context['ban_errors'][] = 'ban_name_empty';
1435
-	if (empty($ban_info['id']))
1436
-		$context['ban_errors'][] = 'ban_id_empty';
1437
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1438
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1465
+	if (empty($ban_info['name'])) {
1466
+			$context['ban_errors'][] = 'ban_name_empty';
1467
+	}
1468
+	if (empty($ban_info['id'])) {
1469
+			$context['ban_errors'][] = 'ban_id_empty';
1470
+	}
1471
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1472
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1473
+	}
1439 1474
 
1440 1475
 	if (!empty($ban_info['id']))
1441 1476
 	{
@@ -1450,8 +1485,9 @@  discard block
 block discarded – undo
1450 1485
 			)
1451 1486
 		);
1452 1487
 
1453
-		if ($smcFunc['db_num_rows']($request) == 0)
1454
-			$context['ban_errors'][] = 'ban_not_found';
1488
+		if ($smcFunc['db_num_rows']($request) == 0) {
1489
+					$context['ban_errors'][] = 'ban_not_found';
1490
+		}
1455 1491
 		$smcFunc['db_free_result']($request);
1456 1492
 	}
1457 1493
 
@@ -1469,13 +1505,15 @@  discard block
 block discarded – undo
1469 1505
 				'new_ban_name' => $ban_info['name'],
1470 1506
 			)
1471 1507
 		);
1472
-		if ($smcFunc['db_num_rows']($request) != 0)
1473
-			$context['ban_errors'][] = 'ban_name_exists';
1508
+		if ($smcFunc['db_num_rows']($request) != 0) {
1509
+					$context['ban_errors'][] = 'ban_name_exists';
1510
+		}
1474 1511
 		$smcFunc['db_free_result']($request);
1475 1512
 	}
1476 1513
 
1477
-	if (!empty($context['ban_errors']))
1478
-		return $ban_info['id'];
1514
+	if (!empty($context['ban_errors'])) {
1515
+			return $ban_info['id'];
1516
+	}
1479 1517
 
1480 1518
 	$smcFunc['db_query']('', '
1481 1519
 		UPDATE {db_prefix}ban_groups
@@ -1519,10 +1557,12 @@  discard block
 block discarded – undo
1519 1557
 {
1520 1558
 	global $smcFunc, $context;
1521 1559
 
1522
-	if (empty($ban_info['name']))
1523
-		$context['ban_errors'][] = 'ban_name_empty';
1524
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1525
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1560
+	if (empty($ban_info['name'])) {
1561
+			$context['ban_errors'][] = 'ban_name_empty';
1562
+	}
1563
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1564
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1565
+	}
1526 1566
 
1527 1567
 	if (!empty($ban_info['name']))
1528 1568
 	{
@@ -1537,13 +1577,15 @@  discard block
 block discarded – undo
1537 1577
 			)
1538 1578
 		);
1539 1579
 
1540
-		if ($smcFunc['db_num_rows']($request) == 1)
1541
-			$context['ban_errors'][] = 'ban_name_exists';
1580
+		if ($smcFunc['db_num_rows']($request) == 1) {
1581
+					$context['ban_errors'][] = 'ban_name_exists';
1582
+		}
1542 1583
 		$smcFunc['db_free_result']($request);
1543 1584
 	}
1544 1585
 
1545
-	if (!empty($context['ban_errors']))
1546
-		return;
1586
+	if (!empty($context['ban_errors'])) {
1587
+			return;
1588
+	}
1547 1589
 
1548 1590
 	// Yes yes, we're ready to add now.
1549 1591
 	$ban_info['id'] = $smcFunc['db_insert']('',
@@ -1560,8 +1602,9 @@  discard block
 block discarded – undo
1560 1602
 		1
1561 1603
 	);
1562 1604
 
1563
-	if (empty($ban_info['id']))
1564
-		$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1605
+	if (empty($ban_info['id'])) {
1606
+			$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1607
+	}
1565 1608
 
1566 1609
 	return $ban_info['id'];
1567 1610
 }
@@ -1586,24 +1629,24 @@  discard block
 block discarded – undo
1586 1629
 	$ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
1587 1630
 	$ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
1588 1631
 
1589
-	if (empty($ban_group))
1590
-		fatal_lang_error('ban_not_found', false);
1632
+	if (empty($ban_group)) {
1633
+			fatal_lang_error('ban_not_found', false);
1634
+	}
1591 1635
 
1592 1636
 	if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))
1593 1637
 	{
1594 1638
 		saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
1595 1639
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1596
-	}
1597
-	elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1640
+	} elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1598 1641
 	{
1599 1642
 		// The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)
1600 1643
 		saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
1601
-		if (!empty($_POST['ban_suggestions']))
1602
-			saveTriggers($_POST['ban_suggestions'], $ban_group);
1644
+		if (!empty($_POST['ban_suggestions'])) {
1645
+					saveTriggers($_POST['ban_suggestions'], $ban_group);
1646
+		}
1603 1647
 
1604 1648
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1605
-	}
1606
-	elseif (isset($_POST['edit_trigger']))
1649
+	} elseif (isset($_POST['edit_trigger']))
1607 1650
 	{
1608 1651
 		removeBanTriggers($ban_id);
1609 1652
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
@@ -1634,8 +1677,7 @@  discard block
 block discarded – undo
1634 1677
 			),
1635 1678
 			'is_new' => true,
1636 1679
 		);
1637
-	}
1638
-	else
1680
+	} else
1639 1681
 	{
1640 1682
 		$request = $smcFunc['db_query']('', '
1641 1683
 			SELECT
@@ -1652,8 +1694,9 @@  discard block
 block discarded – undo
1652 1694
 				'ban_group' => $ban_group,
1653 1695
 			)
1654 1696
 		);
1655
-		if ($smcFunc['db_num_rows']($request) == 0)
1656
-			fatal_lang_error('ban_not_found', false);
1697
+		if ($smcFunc['db_num_rows']($request) == 0) {
1698
+					fatal_lang_error('ban_not_found', false);
1699
+		}
1657 1700
 		$row = $smcFunc['db_fetch_assoc']($request);
1658 1701
 		$smcFunc['db_free_result']($request);
1659 1702
 
@@ -1702,8 +1745,9 @@  discard block
 block discarded – undo
1702 1745
 		removeBanTriggers($_POST['remove']);
1703 1746
 
1704 1747
 		// Rehabilitate some members.
1705
-		if ($_REQUEST['entity'] == 'member')
1706
-			updateBanMembers();
1748
+		if ($_REQUEST['entity'] == 'member') {
1749
+					updateBanMembers();
1750
+		}
1707 1751
 
1708 1752
 		// Make sure the ban cache is refreshed.
1709 1753
 		updateSettings(array('banLastUpdated' => time()));
@@ -1816,8 +1860,7 @@  discard block
 block discarded – undo
1816 1860
 			'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',
1817 1861
 			'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',
1818 1862
 		);
1819
-	}
1820
-	elseif ($context['selected_entity'] === 'hostname')
1863
+	} elseif ($context['selected_entity'] === 'hostname')
1821 1864
 	{
1822 1865
 		$listOptions['columns']['banned_entity']['data'] = array(
1823 1866
 			'function' => function($rowData) use ($smcFunc)
@@ -1829,8 +1872,7 @@  discard block
 block discarded – undo
1829 1872
 			'default' => 'bi.hostname',
1830 1873
 			'reverse' => 'bi.hostname DESC',
1831 1874
 		);
1832
-	}
1833
-	elseif ($context['selected_entity'] === 'email')
1875
+	} elseif ($context['selected_entity'] === 'email')
1834 1876
 	{
1835 1877
 		$listOptions['columns']['banned_entity']['data'] = array(
1836 1878
 			'function' => function($rowData) use ($smcFunc)
@@ -1842,8 +1884,7 @@  discard block
 block discarded – undo
1842 1884
 			'default' => 'bi.email_address',
1843 1885
 			'reverse' => 'bi.email_address DESC',
1844 1886
 		);
1845
-	}
1846
-	elseif ($context['selected_entity'] === 'member')
1887
+	} elseif ($context['selected_entity'] === 'member')
1847 1888
 	{
1848 1889
 		$listOptions['columns']['banned_entity']['data'] = array(
1849 1890
 			'sprintf' => array(
@@ -1907,8 +1948,9 @@  discard block
 block discarded – undo
1907 1948
 		)
1908 1949
 	);
1909 1950
 	$ban_triggers = array();
1910
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1911
-		$ban_triggers[] = $row;
1951
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1952
+			$ban_triggers[] = $row;
1953
+	}
1912 1954
 	$smcFunc['db_free_result']($request);
1913 1955
 
1914 1956
 	return $ban_triggers;
@@ -1964,8 +2006,9 @@  discard block
 block discarded – undo
1964 2006
 		validateToken('admin-bl');
1965 2007
 
1966 2008
 		// 'Delete all entries' button was pressed.
1967
-		if (!empty($_POST['removeAll']))
1968
-			removeBanLogs();
2009
+		if (!empty($_POST['removeAll'])) {
2010
+					removeBanLogs();
2011
+		}
1969 2012
 		// 'Delete selection' button was pressed.
1970 2013
 		else
1971 2014
 		{
@@ -2174,12 +2217,15 @@  discard block
 block discarded – undo
2174 2217
 	$low = inet_dtop($low);
2175 2218
 	$high = inet_dtop($high);
2176 2219
 
2177
-	if ($low == '255.255.255.255') return 'unknown';
2178
-	if ($low == $high)
2179
-	    return $low;
2180
-	else
2181
-	    return $low . '-' . $high;
2182
-}
2220
+	if ($low == '255.255.255.255') {
2221
+		return 'unknown';
2222
+	}
2223
+	if ($low == $high) {
2224
+		    return $low;
2225
+	} else {
2226
+		    return $low . '-' . $high;
2227
+	}
2228
+	}
2183 2229
 
2184 2230
 /**
2185 2231
  * Checks whether a given IP range already exists in the trigger list.
@@ -2255,15 +2301,17 @@  discard block
 block discarded – undo
2255 2301
 	$memberEmailWild = array();
2256 2302
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2257 2303
 	{
2258
-		if ($row['id_member'])
2259
-			$memberIDs[$row['id_member']] = $row['id_member'];
2304
+		if ($row['id_member']) {
2305
+					$memberIDs[$row['id_member']] = $row['id_member'];
2306
+		}
2260 2307
 		if ($row['email_address'])
2261 2308
 		{
2262 2309
 			// Does it have a wildcard - if so we can't do a IN on it.
2263
-			if (strpos($row['email_address'], '%') !== false)
2264
-				$memberEmailWild[$row['email_address']] = $row['email_address'];
2265
-			else
2266
-				$memberEmails[$row['email_address']] = $row['email_address'];
2310
+			if (strpos($row['email_address'], '%') !== false) {
2311
+							$memberEmailWild[$row['email_address']] = $row['email_address'];
2312
+			} else {
2313
+							$memberEmails[$row['email_address']] = $row['email_address'];
2314
+			}
2267 2315
 		}
2268 2316
 	}
2269 2317
 	$smcFunc['db_free_result']($request);
@@ -2314,14 +2362,15 @@  discard block
 block discarded – undo
2314 2362
 	}
2315 2363
 
2316 2364
 	// We welcome our new members in the realm of the banned.
2317
-	if (!empty($newMembers))
2318
-		$smcFunc['db_query']('', '
2365
+	if (!empty($newMembers)) {
2366
+			$smcFunc['db_query']('', '
2319 2367
 			DELETE FROM {db_prefix}log_online
2320 2368
 			WHERE id_member IN ({array_int:new_banned_members})',
2321 2369
 			array(
2322 2370
 				'new_banned_members' => $newMembers,
2323 2371
 			)
2324 2372
 		);
2373
+	}
2325 2374
 
2326 2375
 	// Find members that are wrongfully marked as banned.
2327 2376
 	$request = $smcFunc['db_query']('', '
@@ -2348,9 +2397,10 @@  discard block
 block discarded – undo
2348 2397
 	}
2349 2398
 	$smcFunc['db_free_result']($request);
2350 2399
 
2351
-	if (!empty($updates))
2352
-		foreach ($updates as $newStatus => $members)
2400
+	if (!empty($updates)) {
2401
+			foreach ($updates as $newStatus => $members)
2353 2402
 			updateMemberData($members, array('is_activated' => $newStatus));
2403
+	}
2354 2404
 
2355 2405
 	// Update the latest member and our total members as banning may change them.
2356 2406
 	updateStats('member');
Please login to merge, or discard this patch.