Completed
Push — release-2.1 ( 15bff3...0c2197 )
by Jeremy
23s
created
Sources/Errors.php 1 patch
Braces   +127 added lines, -90 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
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 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
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason, COALESCE(bg.expire_time, 0) AS expire_time
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -298,14 +315,15 @@  discard block
 block discarded – undo
298 315
 	if (isset($_SESSION['ban']['cannot_access']))
299 316
 	{
300 317
 		// We don't wanna see you!
301
-		if (!$user_info['is_guest'])
302
-			$smcFunc['db_query']('', '
318
+		if (!$user_info['is_guest']) {
319
+					$smcFunc['db_query']('', '
303 320
 				DELETE FROM {db_prefix}log_online
304 321
 				WHERE id_member = {int:current_member}',
305 322
 				array(
306 323
 					'current_member' => $user_info['id'],
307 324
 				)
308 325
 			);
326
+		}
309 327
 
310 328
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
311 329
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -391,9 +409,10 @@  discard block
 block discarded – undo
391 409
 	}
392 410
 
393 411
 	// Fix up the banning permissions.
394
-	if (isset($user_info['permissions']))
395
-		banPermissions();
396
-}
412
+	if (isset($user_info['permissions'])) {
413
+			banPermissions();
414
+	}
415
+	}
397 416
 
398 417
 /**
399 418
  * Fix permissions according to ban status.
@@ -404,8 +423,9 @@  discard block
 block discarded – undo
404 423
 	global $user_info, $sourcedir, $modSettings, $context;
405 424
 
406 425
 	// Somehow they got here, at least take away all permissions...
407
-	if (isset($_SESSION['ban']['cannot_access']))
408
-		$user_info['permissions'] = array();
426
+	if (isset($_SESSION['ban']['cannot_access'])) {
427
+			$user_info['permissions'] = array();
428
+	}
409 429
 	// Okay, well, you can watch, but don't touch a thing.
410 430
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
411 431
 	{
@@ -447,19 +467,20 @@  discard block
 block discarded – undo
447 467
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
448 468
 		foreach ($permission_change as $old => $new)
449 469
 		{
450
-			if (!in_array($old, $user_info['permissions']))
451
-				unset($permission_change[$old]);
452
-			else
453
-				$user_info['permissions'][] = $new;
470
+			if (!in_array($old, $user_info['permissions'])) {
471
+							unset($permission_change[$old]);
472
+			} else {
473
+							$user_info['permissions'][] = $new;
474
+			}
454 475
 		}
455 476
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
456 477
 	}
457 478
 
458 479
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
459 480
 	// Finally, some bits we cache in the session because it saves queries.
460
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
461
-		$user_info['mod_cache'] = $_SESSION['mc'];
462
-	else
481
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
482
+			$user_info['mod_cache'] = $_SESSION['mc'];
483
+	} else
463 484
 	{
464 485
 		require_once($sourcedir . '/Subs-Auth.php');
465 486
 		rebuildModCache();
@@ -470,14 +491,12 @@  discard block
 block discarded – undo
470 491
 	{
471 492
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
472 493
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
473
-	}
474
-	elseif ($_SESSION['mc']['bq'] != '0=1')
494
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
475 495
 	{
476 496
 		require_once($sourcedir . '/Subs-ReportedContent.php');
477 497
 		$context['open_mod_reports'] = recountOpenReports('posts');
478 498
 		$context['open_member_reports'] = recountOpenReports('members');
479
-	}
480
-	else
499
+	} else
481 500
 	{
482 501
 		$context['open_mod_reports'] = 0;
483 502
 		$context['open_member_reports'] = 0;
@@ -497,8 +516,9 @@  discard block
 block discarded – undo
497 516
 	global $user_info, $smcFunc;
498 517
 
499 518
 	// Don't log web accelerators, it's very confusing...
500
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
501
-		return;
519
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
520
+			return;
521
+	}
502 522
 
503 523
 	$smcFunc['db_insert']('',
504 524
 		'{db_prefix}log_banned',
@@ -508,8 +528,8 @@  discard block
 block discarded – undo
508 528
 	);
509 529
 
510 530
 	// One extra point for these bans.
511
-	if (!empty($ban_ids))
512
-		$smcFunc['db_query']('', '
531
+	if (!empty($ban_ids)) {
532
+			$smcFunc['db_query']('', '
513 533
 			UPDATE {db_prefix}ban_items
514 534
 			SET hits = hits + 1
515 535
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -517,7 +537,8 @@  discard block
 block discarded – undo
517 537
 				'ban_ids' => $ban_ids,
518 538
 			)
519 539
 		);
520
-}
540
+	}
541
+	}
521 542
 
522 543
 /**
523 544
  * Checks if a given email address might be banned.
@@ -533,8 +554,9 @@  discard block
 block discarded – undo
533 554
 	global $txt, $smcFunc;
534 555
 
535 556
 	// Can't ban an empty email
536
-	if (empty($email) || trim($email) == '')
537
-		return;
557
+	if (empty($email) || trim($email) == '') {
558
+			return;
559
+	}
538 560
 
539 561
 	// Let's start with the bans based on your IP/hostname/memberID...
540 562
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -607,16 +629,18 @@  discard block
 block discarded – undo
607 629
 	if ($type == 'post')
608 630
 	{
609 631
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
610
-		if ($check !== $sc)
611
-			$error = 'session_timeout';
632
+		if ($check !== $sc) {
633
+					$error = 'session_timeout';
634
+		}
612 635
 	}
613 636
 
614 637
 	// How about $_GET['sesc']?
615 638
 	elseif ($type == 'get')
616 639
 	{
617 640
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
618
-		if ($check !== $sc)
619
-			$error = 'session_verify_fail';
641
+		if ($check !== $sc) {
642
+					$error = 'session_verify_fail';
643
+		}
620 644
 	}
621 645
 
622 646
 	// Or can it be in either?
@@ -624,13 +648,15 @@  discard block
 block discarded – undo
624 648
 	{
625 649
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
626 650
 
627
-		if ($check !== $sc)
628
-			$error = 'session_verify_fail';
651
+		if ($check !== $sc) {
652
+					$error = 'session_verify_fail';
653
+		}
629 654
 	}
630 655
 
631 656
 	// Verify that they aren't changing user agents on us - that could be bad.
632
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
633
-		$error = 'session_verify_fail';
657
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
658
+			$error = 'session_verify_fail';
659
+	}
634 660
 
635 661
 	// Make sure a page with session check requirement is not being prefetched.
636 662
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -641,30 +667,35 @@  discard block
 block discarded – undo
641 667
 	}
642 668
 
643 669
 	// Check the referring site - it should be the same server at least!
644
-	if (isset($_SESSION['request_referer']))
645
-		$referrer = $_SESSION['request_referer'];
646
-	else
647
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
670
+	if (isset($_SESSION['request_referer'])) {
671
+			$referrer = $_SESSION['request_referer'];
672
+	} else {
673
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
674
+	}
648 675
 	if (!empty($referrer['host']))
649 676
 	{
650
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
651
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
652
-		else
653
-			$real_host = $_SERVER['HTTP_HOST'];
677
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
678
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
679
+		} else {
680
+					$real_host = $_SERVER['HTTP_HOST'];
681
+		}
654 682
 
655 683
 		$parsed_url = parse_url($boardurl);
656 684
 
657 685
 		// Are global cookies on?  If so, let's check them ;).
658 686
 		if (!empty($modSettings['globalCookies']))
659 687
 		{
660
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
661
-				$parsed_url['host'] = $parts[1];
688
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
689
+							$parsed_url['host'] = $parts[1];
690
+			}
662 691
 
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
664
-				$referrer['host'] = $parts[1];
692
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
693
+							$referrer['host'] = $parts[1];
694
+			}
665 695
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
667
-				$real_host = $parts[1];
696
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
697
+							$real_host = $parts[1];
698
+			}
668 699
 		}
669 700
 
670 701
 		// Okay: referrer must either match parsed_url or real_host.
@@ -682,12 +713,14 @@  discard block
 block discarded – undo
682 713
 		$log_error = true;
683 714
 	}
684 715
 
685
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
686
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
716
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
717
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
718
+	}
687 719
 
688 720
 	// Everything is ok, return an empty string.
689
-	if (!isset($error))
690
-		return '';
721
+	if (!isset($error)) {
722
+			return '';
723
+	}
691 724
 	// A session error occurred, show the error.
692 725
 	elseif ($is_fatal)
693 726
 	{
@@ -696,13 +729,14 @@  discard block
 block discarded – undo
696 729
 			ob_end_clean();
697 730
 			send_http_status(403, 'Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (mt_rand(0, 138) == 23)
813
-		cleanTokens();
846
+	if (mt_rand(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -899,16 +939,19 @@  discard block
 block discarded – undo
899 939
 	global $user_info, $smcFunc;
900 940
 
901 941
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
902
-	if (empty($permission))
903
-		return true;
942
+	if (empty($permission)) {
943
+			return true;
944
+	}
904 945
 
905 946
 	// You're never allowed to do something if your data hasn't been loaded yet!
906
-	if (empty($user_info))
907
-		return false;
947
+	if (empty($user_info)) {
948
+			return false;
949
+	}
908 950
 
909 951
 	// Administrators are supermen :P.
910
-	if ($user_info['is_admin'])
911
-		return true;
952
+	if ($user_info['is_admin']) {
953
+			return true;
954
+	}
912 955
 
913 956
 	// Let's ensure this is an array.
914 957
 	$permission = (array) $permission;
@@ -916,14 +959,16 @@  discard block
 block discarded – undo
916 959
 	// Are we checking the _current_ board, or some other boards?
917 960
 	if ($boards === null)
918 961
 	{
919
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
920
-			return true;
962
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
963
+					return true;
964
+		}
921 965
 		// You aren't allowed, by default.
922
-		else
923
-			return false;
966
+		else {
967
+					return false;
968
+		}
969
+	} elseif (!is_array($boards)) {
970
+			$boards = array($boards);
924 971
 	}
925
-	elseif (!is_array($boards))
926
-		$boards = array($boards);
927 972
 
928 973
 	$request = $smcFunc['db_query']('', '
929 974
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -951,20 +996,23 @@  discard block
 block discarded – undo
951 996
 		while ($row = $smcFunc['db_fetch_assoc']($request))
952 997
 		{
953 998
 			$result = !empty($row['add_deny']);
954
-			if ($result == true)
955
-				break;
999
+			if ($result == true) {
1000
+							break;
1001
+			}
956 1002
 		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 		return $result;
959 1005
 	}
960 1006
 
961 1007
 	// Make sure they can do it on all of the boards.
962
-	if ($smcFunc['db_num_rows']($request) != count($boards))
963
-		return false;
1008
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1009
+			return false;
1010
+	}
964 1011
 
965 1012
 	$result = true;
966
-	while ($row = $smcFunc['db_fetch_assoc']($request))
967
-		$result &= !empty($row['add_deny']);
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$result &= !empty($row['add_deny']);
1015
+	}
968 1016
 	$smcFunc['db_free_result']($request);
969 1017
 
970 1018
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1031,9 +1079,10 @@  discard block
 block discarded – undo
1031 1079
 
1032 1080
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1033 1081
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1034
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1035
-		validateSession();
1036
-}
1082
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1083
+			validateSession();
1084
+	}
1085
+	}
1037 1086
 
1038 1087
 /**
1039 1088
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1064,13 +1113,14 @@  discard block
 block discarded – undo
1064 1113
 	// Administrators are all powerful, sorry.
1065 1114
 	if ($user_info['is_admin'])
1066 1115
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1116
+		if ($simple) {
1117
+					return array(0);
1118
+		} else
1070 1119
 		{
1071 1120
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1121
+			foreach ($permissions as $permission) {
1122
+							$boards[$permission] = array(0);
1123
+			}
1074 1124
 
1075 1125
 			return $boards;
1076 1126
 		}
@@ -1102,31 +1152,32 @@  discard block
 block discarded – undo
1102 1152
 	{
1103 1153
 		if ($simple)
1104 1154
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1155
+			if (empty($row['add_deny'])) {
1156
+							$deny_boards[] = $row['id_board'];
1157
+			} else {
1158
+							$boards[] = $row['id_board'];
1159
+			}
1160
+		} else
1111 1161
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1162
+			if (empty($row['add_deny'])) {
1163
+							$deny_boards[$row['permission']][] = $row['id_board'];
1164
+			} else {
1165
+							$boards[$row['permission']][] = $row['id_board'];
1166
+			}
1116 1167
 		}
1117 1168
 	}
1118 1169
 	$smcFunc['db_free_result']($request);
1119 1170
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1171
+	if ($simple) {
1172
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1173
+	} else
1123 1174
 	{
1124 1175
 		foreach ($permissions as $permission)
1125 1176
 		{
1126 1177
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1178
+			if (empty($boards[$permission])) {
1179
+							$boards[$permission] = array();
1180
+			} else
1130 1181
 			{
1131 1182
 				// Or it may have been removed
1132 1183
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1213,11 @@  discard block
 block discarded – undo
1162 1213
 
1163 1214
 
1164 1215
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1216
+	if (!allowedTo('moderate_board')) {
1217
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1218
+	} else {
1219
+			$timeLimit = 2;
1220
+	}
1169 1221
 
1170 1222
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1223
 
@@ -1192,8 +1244,9 @@  discard block
 block discarded – undo
1192 1244
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1245
 	{
1194 1246
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1247
+		if (!$only_return_result) {
1248
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1249
+		}
1197 1250
 
1198 1251
 		return true;
1199 1252
 	}
@@ -1211,11 +1264,13 @@  discard block
 block discarded – undo
1211 1264
  */
1212 1265
 function secureDirectory($path, $attachments = false)
1213 1266
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1267
+	if (empty($path)) {
1268
+			return 'empty_path';
1269
+	}
1216 1270
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1271
+	if (!is_writable($path)) {
1272
+			return 'path_not_writable';
1273
+	}
1219 1274
 
1220 1275
 	$directoryname = basename($path);
1221 1276
 
@@ -1227,9 +1282,9 @@  discard block
 block discarded – undo
1227 1282
 
1228 1283
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1284
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1285
+	if (file_exists($path . '/.htaccess')) {
1286
+			$errors[] = 'htaccess_exists';
1287
+	} else
1233 1288
 	{
1234 1289
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1290
 		if ($fh)
@@ -1242,9 +1297,9 @@  discard block
 block discarded – undo
1242 1297
 		$errors[] = 'htaccess_cannot_create_file';
1243 1298
 	}
1244 1299
 
1245
-	if (file_exists($path . '/index.php'))
1246
-		$errors[] = 'index-php_exists';
1247
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1248 1303
 	{
1249 1304
 		$fh = @fopen($path . '/index.php', 'w');
1250 1305
 		if ($fh)
@@ -1272,11 +1327,12 @@  discard block
 block discarded – undo
1272 1327
 		$errors[] = 'index-php_cannot_create_file';
1273 1328
 	}
1274 1329
 
1275
-	if (!empty($errors))
1276
-		return $errors;
1277
-	else
1278
-		return true;
1279
-}
1330
+	if (!empty($errors)) {
1331
+			return $errors;
1332
+	} else {
1333
+			return true;
1334
+	}
1335
+	}
1280 1336
 
1281 1337
 /**
1282 1338
 * This sets the X-Frame-Options header.
@@ -1289,14 +1345,16 @@  discard block
 block discarded – undo
1289 1345
 	global $modSettings;
1290 1346
 
1291 1347
 	$option = 'SAMEORIGIN';
1292
-	if (is_null($override) && !empty($modSettings['frame_security']))
1293
-		$option = $modSettings['frame_security'];
1294
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1295
-		$option = $override;
1348
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1349
+			$option = $modSettings['frame_security'];
1350
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1351
+			$option = $override;
1352
+	}
1296 1353
 
1297 1354
 	// Don't bother setting the header if we have disabled it.
1298
-	if ($option == 'DISABLE')
1299
-		return;
1355
+	if ($option == 'DISABLE') {
1356
+			return;
1357
+	}
1300 1358
 
1301 1359
 	// Finally set it.
1302 1360
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +298 added lines, -219 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -365,9 +370,10 @@  discard block
 block discarded – undo
365 370
 		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
366 371
 		$sig_limits = explode(',', $sig_limits);
367 372
 
368
-		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
369
-			addInlineCss('
373
+		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
374
+					addInlineCss('
370 375
 	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
376
+		}
371 377
 	}
372 378
 
373 379
 	// Censor the title...
@@ -405,21 +411,25 @@  discard block
 block discarded – undo
405 411
 		);
406 412
 		while ($row = $smcFunc['db_fetch_assoc']($request))
407 413
 		{
408
-			if (empty($row['id_member']))
409
-				continue;
414
+			if (empty($row['id_member'])) {
415
+							continue;
416
+			}
410 417
 
411
-			if (!empty($row['online_color']))
412
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
413
-			else
414
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
418
+			if (!empty($row['online_color'])) {
419
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
420
+			} else {
421
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
422
+			}
415 423
 
416 424
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
417
-			if ($is_buddy)
418
-				$link = '<strong>' . $link . '</strong>';
425
+			if ($is_buddy) {
426
+							$link = '<strong>' . $link . '</strong>';
427
+			}
419 428
 
420 429
 			// Add them both to the list and to the more detailed list.
421
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
422
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
430
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
431
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
432
+			}
423 433
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
424 434
 				'id' => $row['id_member'],
425 435
 				'username' => $row['member_name'],
@@ -431,8 +441,9 @@  discard block
 block discarded – undo
431 441
 				'hidden' => empty($row['show_online']),
432 442
 			);
433 443
 
434
-			if (empty($row['show_online']))
435
-				$context['view_num_hidden']++;
444
+			if (empty($row['show_online'])) {
445
+							$context['view_num_hidden']++;
446
+			}
436 447
 		}
437 448
 
438 449
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -446,11 +457,13 @@  discard block
 block discarded – undo
446 457
 
447 458
 	// If all is set, but not allowed... just unset it.
448 459
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
449
-	if (isset($_REQUEST['all']) && !$can_show_all)
450
-		unset($_REQUEST['all']);
460
+	if (isset($_REQUEST['all']) && !$can_show_all) {
461
+			unset($_REQUEST['all']);
462
+	}
451 463
 	// Otherwise, it must be allowed... so pretend start was -1.
452
-	elseif (isset($_REQUEST['all']))
453
-		$_REQUEST['start'] = -1;
464
+	elseif (isset($_REQUEST['all'])) {
465
+			$_REQUEST['start'] = -1;
466
+	}
454 467
 
455 468
 	// Construct the page index, allowing for the .START method...
456 469
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -487,8 +500,9 @@  discard block
 block discarded – undo
487 500
 			$_REQUEST['start'] = 0;
488 501
 		}
489 502
 		// They aren't using it, but the *option* is there, at least.
490
-		else
491
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
503
+		else {
504
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
505
+		}
492 506
 	}
493 507
 
494 508
 	// Build the link tree.
@@ -504,14 +518,16 @@  discard block
 block discarded – undo
504 518
 	if (!empty($board_info['moderators']))
505 519
 	{
506 520
 		// Add a link for each moderator...
507
-		foreach ($board_info['moderators'] as $mod)
508
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
521
+		foreach ($board_info['moderators'] as $mod) {
522
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
523
+		}
509 524
 	}
510 525
 	if (!empty($board_info['moderator_groups']))
511 526
 	{
512 527
 		// Add a link for each moderator group as well...
513
-		foreach ($board_info['moderator_groups'] as $mod_group)
514
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
528
+		foreach ($board_info['moderator_groups'] as $mod_group) {
529
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
530
+		}
515 531
 	}
516 532
 
517 533
 	if (!empty($context['link_moderators']))
@@ -542,9 +558,9 @@  discard block
 block discarded – undo
542 558
 	// For quick reply we need a response prefix in the default forum language.
543 559
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
544 560
 	{
545
-		if ($language === $user_info['language'])
546
-			$context['response_prefix'] = $txt['response_prefix'];
547
-		else
561
+		if ($language === $user_info['language']) {
562
+					$context['response_prefix'] = $txt['response_prefix'];
563
+		} else
548 564
 		{
549 565
 			loadLanguage('index', $language, false);
550 566
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -576,8 +592,9 @@  discard block
 block discarded – undo
576 592
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
577 593
 
578 594
 			// Sanity check
579
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
580
-				continue;
595
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
596
+							continue;
597
+			}
581 598
 
582 599
 			$linked_calendar_event = array(
583 600
 				'id' => $row['id_event'],
@@ -626,8 +643,9 @@  discard block
 block discarded – undo
626 643
 		}
627 644
 		$smcFunc['db_free_result']($request);
628 645
 
629
-		if (!empty($context['linked_calendar_events']))
630
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
646
+		if (!empty($context['linked_calendar_events'])) {
647
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
648
+		}
631 649
 	}
632 650
 
633 651
 	// Create the poll info if it exists.
@@ -651,9 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Create the poll info if it exists and is valid.
654
-	if ($context['is_poll'] && empty($pollinfo))
655
-		$context['is_poll'] = false;
656
-	elseif ($context['is_poll'])
672
+	if ($context['is_poll'] && empty($pollinfo)) {
673
+			$context['is_poll'] = false;
674
+	} elseif ($context['is_poll'])
657 675
 	{
658 676
 		$request = $smcFunc['db_query']('', '
659 677
 			SELECT COUNT(DISTINCT id_member) AS total
@@ -696,8 +714,9 @@  discard block
 block discarded – undo
696 714
 		$smcFunc['db_free_result']($request);
697 715
 
698 716
 		// Got we multi choice?
699
-		if ($pollinfo['max_votes'] > 1)
700
-			$realtotal = $pollinfo['total'];
717
+		if ($pollinfo['max_votes'] > 1) {
718
+					$realtotal = $pollinfo['total'];
719
+		}
701 720
 
702 721
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
703 722
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -710,20 +729,21 @@  discard block
 block discarded – undo
710 729
 				foreach ($guestinfo as $i => $guestvoted)
711 730
 				{
712 731
 					$guestvoted = explode(',', $guestvoted);
713
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
714
-						break;
732
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
733
+											break;
734
+					}
715 735
 				}
716 736
 				// Has the poll been reset since guest voted?
717 737
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
718 738
 				{
719 739
 					// Remove the poll info from the cookie to allow guest to vote again
720 740
 					unset($guestinfo[$i]);
721
-					if (!empty($guestinfo))
722
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
723
-					else
724
-						unset($_COOKIE['guest_poll_vote']);
725
-				}
726
-				else
741
+					if (!empty($guestinfo)) {
742
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
743
+					} else {
744
+											unset($_COOKIE['guest_poll_vote']);
745
+					}
746
+				} else
727 747
 				{
728 748
 					// What did they vote for?
729 749
 					unset($guestvoted[0], $guestvoted[1]);
@@ -837,23 +857,29 @@  discard block
 block discarded – undo
837 857
 		// Build the poll moderation button array.
838 858
 		$context['poll_buttons'] = array();
839 859
 
840
-		if ($context['allow_return_vote'])
841
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		if ($context['allow_return_vote']) {
861
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
862
+		}
842 863
 
843
-		if ($context['show_view_results_button'])
844
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
864
+		if ($context['show_view_results_button']) {
865
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
866
+		}
845 867
 
846
-		if ($context['allow_change_vote'])
847
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
868
+		if ($context['allow_change_vote']) {
869
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
870
+		}
848 871
 
849
-		if ($context['allow_lock_poll'])
850
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
872
+		if ($context['allow_lock_poll']) {
873
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
874
+		}
851 875
 
852
-		if ($context['allow_edit_poll'])
853
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
876
+		if ($context['allow_edit_poll']) {
877
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
878
+		}
854 879
 
855
-		if ($context['can_remove_poll'])
856
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
880
+		if ($context['can_remove_poll']) {
881
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
882
+		}
857 883
 
858 884
 		// Allow mods to add additional buttons here
859 885
 		call_integration_hook('integrate_poll_buttons');
@@ -889,9 +915,9 @@  discard block
 block discarded – undo
889 915
 	{
890 916
 		$start_char = 'C';
891 917
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
918
+	} else {
919
+			$start_char = null;
892 920
 	}
893
-	else
894
-		$start_char = null;
895 921
 
896 922
 	$limit = $context['messages_per_page'];
897 923
 
@@ -905,17 +931,17 @@  discard block
 block discarded – undo
905 931
 		{
906 932
 			$ascending_seek = true;
907 933
 			$page_operator = $ascending ? '>=' : '<=';
908
-		}
909
-		else
934
+		} else
910 935
 		{
911 936
 			$ascending_seek = false;
912 937
 			$page_operator = $ascending ? '<=' : '>=';
913 938
 		}
914 939
 
915
-		if ($start_char === 'C')
916
-			$limit_seek = $limit;
917
-		else
918
-			$limit_seek  = $limit + 1;
940
+		if ($start_char === 'C') {
941
+					$limit_seek = $limit;
942
+		} else {
943
+					$limit_seek  = $limit + 1;
944
+		}
919 945
 
920 946
 		$request = $smcFunc['db_query']('', '
921 947
 			SELECT id_msg, id_member, approved
@@ -938,21 +964,23 @@  discard block
 block discarded – undo
938 964
 		$found_msg = false;
939 965
 
940 966
 		// Fallback
941
-		if ($smcFunc['db_num_rows']($request) < 1)
942
-			unset($start_char);
943
-		else
967
+		if ($smcFunc['db_num_rows']($request) < 1) {
968
+					unset($start_char);
969
+		} else
944 970
 		{
945 971
 			while ($row = $smcFunc['db_fetch_assoc']($request))
946 972
 			{
947 973
 				// Check if the start msg is in our result
948
-				if ($row['id_msg'] == $page_id)
949
-					$found_msg = true;
974
+				if ($row['id_msg'] == $page_id) {
975
+									$found_msg = true;
976
+				}
950 977
 
951 978
 				// Skip the the start msg if we not in mode C
952 979
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
953 980
 				{
954
-					if (!empty($row['id_member']))
955
-						$all_posters[$row['id_msg']] = $row['id_member'];
981
+					if (!empty($row['id_member'])) {
982
+											$all_posters[$row['id_msg']] = $row['id_member'];
983
+					}
956 984
 
957 985
 					$messages[] = $row['id_msg'];
958 986
 				}
@@ -968,8 +996,9 @@  discard block
 block discarded – undo
968 996
 		}
969 997
 
970 998
 		// Before Page bring in the right order
971
-		if (!empty($start_char) && $start_char === 'L')
972
-			krsort($messages);
999
+		if (!empty($start_char) && $start_char === 'L') {
1000
+					krsort($messages);
1001
+		}
973 1002
 	}
974 1003
 
975 1004
 	// Jump to page
@@ -1004,14 +1033,16 @@  discard block
 block discarded – undo
1004 1033
 
1005 1034
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1006 1035
 		{
1007
-			if (!empty($row['id_member']))
1008
-				$all_posters[$row['id_msg']] = $row['id_member'];
1036
+			if (!empty($row['id_member'])) {
1037
+							$all_posters[$row['id_msg']] = $row['id_member'];
1038
+			}
1009 1039
 			$messages[] = $row['id_msg'];
1010 1040
 		}
1011 1041
 
1012 1042
 		// Sort the messages into the correct display order
1013
-		if (!$ascending)
1014
-			sort($messages);
1043
+		if (!$ascending) {
1044
+					sort($messages);
1045
+		}
1015 1046
 	}
1016 1047
 
1017 1048
 	// Remember the paging data for next time
@@ -1031,8 +1062,9 @@  discard block
 block discarded – undo
1031 1062
 	if (!$user_info['is_guest'] && !empty($messages))
1032 1063
 	{
1033 1064
 		$mark_at_msg = max($messages);
1034
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1035
-			$mark_at_msg = $modSettings['maxMsgID'];
1065
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1066
+					$mark_at_msg = $modSettings['maxMsgID'];
1067
+		}
1036 1068
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1037 1069
 		{
1038 1070
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1064,8 +1096,9 @@  discard block
 block discarded – undo
1064 1096
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1065 1097
 		{
1066 1098
 			// Find if this topic is marked for notification...
1067
-			if (!empty($row['id_topic']))
1068
-				$context['is_marked_notify'] = true;
1099
+			if (!empty($row['id_topic'])) {
1100
+							$context['is_marked_notify'] = true;
1101
+			}
1069 1102
 
1070 1103
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1071 1104
 			if (!empty($row['sent']) && $do_once)
@@ -1087,8 +1120,9 @@  discard block
 block discarded – undo
1087 1120
 		}
1088 1121
 
1089 1122
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1090
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1091
-			$_SESSION['topicseen_cache'][$board]--;
1123
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1124
+					$_SESSION['topicseen_cache'][$board]--;
1125
+		}
1092 1126
 		// Mark board as seen if this is the only new topic.
1093 1127
 		elseif (isset($_REQUEST['topicseen']))
1094 1128
 		{
@@ -1112,14 +1146,16 @@  discard block
 block discarded – undo
1112 1146
 			$smcFunc['db_free_result']($request);
1113 1147
 
1114 1148
 			// If there're no real new topics in this board, mark the board as seen.
1115
-			if (empty($numNewTopics))
1116
-				$_REQUEST['boardseen'] = true;
1117
-			else
1118
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1149
+			if (empty($numNewTopics)) {
1150
+							$_REQUEST['boardseen'] = true;
1151
+			} else {
1152
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1153
+			}
1119 1154
 		}
1120 1155
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1121
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1122
-			$_SESSION['topicseen_cache'][$board]--;
1156
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1157
+					$_SESSION['topicseen_cache'][$board]--;
1158
+		}
1123 1159
 
1124 1160
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1125 1161
 		if (isset($_REQUEST['boardseen']))
@@ -1176,23 +1212,26 @@  discard block
 block discarded – undo
1176 1212
 			$temp = array();
1177 1213
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1178 1214
 			{
1179
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1180
-					continue;
1215
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1216
+									continue;
1217
+				}
1181 1218
 
1182 1219
 				$temp[$row['id_attach']] = $row;
1183 1220
 				$temp[$row['id_attach']]['topic'] = $topic;
1184 1221
 				$temp[$row['id_attach']]['board'] = $board;
1185 1222
 
1186
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1187
-					$context['loaded_attachments'][$row['id_msg']] = array();
1223
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1224
+									$context['loaded_attachments'][$row['id_msg']] = array();
1225
+				}
1188 1226
 			}
1189 1227
 			$smcFunc['db_free_result']($request);
1190 1228
 
1191 1229
 			// This is better than sorting it with the query...
1192 1230
 			ksort($temp);
1193 1231
 
1194
-			foreach ($temp as $row)
1195
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1232
+			foreach ($temp as $row) {
1233
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1234
+			}
1196 1235
 		}
1197 1236
 
1198 1237
 		$msg_parameters = array(
@@ -1219,21 +1258,23 @@  discard block
 block discarded – undo
1219 1258
 		);
1220 1259
 
1221 1260
 		// And the likes
1222
-		if (!empty($modSettings['enable_likes']))
1223
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1261
+		if (!empty($modSettings['enable_likes'])) {
1262
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1263
+		}
1224 1264
 
1225 1265
 		// Go to the last message if the given time is beyond the time of the last message.
1226
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1227
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1266
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1267
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1268
+		}
1228 1269
 
1229 1270
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1230 1271
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1231
-		if (empty($options['view_newest_first']))
1232
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1233
-		else
1234
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1235
-	}
1236
-	else
1272
+		if (empty($options['view_newest_first'])) {
1273
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1274
+		} else {
1275
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1276
+		}
1277
+	} else
1237 1278
 	{
1238 1279
 		$messages_request = false;
1239 1280
 		$context['first_message'] = 0;
@@ -1268,8 +1309,9 @@  discard block
 block discarded – undo
1268 1309
 		'can_restore_msg' => 'move_any',
1269 1310
 		'can_like' => 'likes_like',
1270 1311
 	);
1271
-	foreach ($common_permissions as $contextual => $perm)
1272
-		$context[$contextual] = allowedTo($perm);
1312
+	foreach ($common_permissions as $contextual => $perm) {
1313
+			$context[$contextual] = allowedTo($perm);
1314
+	}
1273 1315
 
1274 1316
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1275 1317
 	$anyown_permissions = array(
@@ -1282,8 +1324,9 @@  discard block
 block discarded – undo
1282 1324
 		'can_reply_unapproved' => 'post_unapproved_replies',
1283 1325
 		'can_view_warning' => 'profile_warning',
1284 1326
 	);
1285
-	foreach ($anyown_permissions as $contextual => $perm)
1286
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1327
+	foreach ($anyown_permissions as $contextual => $perm) {
1328
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1329
+	}
1287 1330
 
1288 1331
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1289 1332
 	{
@@ -1329,8 +1372,9 @@  discard block
 block discarded – undo
1329 1372
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1330 1373
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1331 1374
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1332
-	if (!empty($context['drafts_save']))
1333
-		loadLanguage('Drafts');
1375
+	if (!empty($context['drafts_save'])) {
1376
+			loadLanguage('Drafts');
1377
+	}
1334 1378
 
1335 1379
 	// When was the last time this topic was replied to?  Should we warn them about it?
1336 1380
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1391,26 +1435,31 @@  discard block
 block discarded – undo
1391 1435
 	// Message icons - customized icons are off?
1392 1436
 	$context['icons'] = getMessageIcons($board);
1393 1437
 
1394
-	if (!empty($context['icons']))
1395
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1438
+	if (!empty($context['icons'])) {
1439
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1440
+	}
1396 1441
 
1397 1442
 	// Build the normal button array.
1398 1443
 	$context['normal_buttons'] = array();
1399 1444
 
1400
-	if ($context['can_reply'])
1401
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1445
+	if ($context['can_reply']) {
1446
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1447
+	}
1402 1448
 
1403
-	if ($context['can_add_poll'])
1404
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1449
+	if ($context['can_add_poll']) {
1450
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1451
+	}
1405 1452
 
1406
-	if ($context['can_mark_unread'])
1407
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1453
+	if ($context['can_mark_unread']) {
1454
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1455
+	}
1408 1456
 
1409
-	if ($context['can_print'])
1410
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1457
+	if ($context['can_print']) {
1458
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1459
+	}
1411 1460
 
1412
-	if ($context['can_set_notify'])
1413
-		$context['normal_buttons']['notify'] = array(
1461
+	if ($context['can_set_notify']) {
1462
+			$context['normal_buttons']['notify'] = array(
1414 1463
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1415 1464
 			'sub_buttons' => array(
1416 1465
 				array(
@@ -1432,38 +1481,47 @@  discard block
 block discarded – undo
1432 1481
 				),
1433 1482
 			),
1434 1483
 		);
1484
+	}
1435 1485
 
1436 1486
 	// Build the mod button array
1437 1487
 	$context['mod_buttons'] = array();
1438 1488
 
1439
-	if ($context['can_move'])
1440
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1489
+	if ($context['can_move']) {
1490
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1491
+	}
1441 1492
 
1442
-	if ($context['can_delete'])
1443
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1493
+	if ($context['can_delete']) {
1494
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1495
+	}
1444 1496
 
1445
-	if ($context['can_lock'])
1446
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1497
+	if ($context['can_lock']) {
1498
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1499
+	}
1447 1500
 
1448
-	if ($context['can_sticky'])
1449
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1501
+	if ($context['can_sticky']) {
1502
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1503
+	}
1450 1504
 
1451
-	if ($context['can_merge'])
1452
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1505
+	if ($context['can_merge']) {
1506
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1507
+	}
1453 1508
 
1454
-	if ($context['calendar_post'])
1455
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1509
+	if ($context['calendar_post']) {
1510
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1511
+	}
1456 1512
 
1457 1513
 	// Restore topic. eh?  No monkey business.
1458
-	if ($context['can_restore_topic'])
1459
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1514
+	if ($context['can_restore_topic']) {
1515
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1516
+	}
1460 1517
 
1461 1518
 	// Show a message in case a recently posted message became unapproved.
1462 1519
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1463 1520
 
1464 1521
 	// Don't want to show this forever...
1465
-	if ($context['becomesUnapproved'])
1466
-		unset($_SESSION['becomesUnapproved']);
1522
+	if ($context['becomesUnapproved']) {
1523
+			unset($_SESSION['becomesUnapproved']);
1524
+	}
1467 1525
 
1468 1526
 	// Allow adding new mod buttons easily.
1469 1527
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1472,12 +1530,14 @@  discard block
 block discarded – undo
1472 1530
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1473 1531
 
1474 1532
 	// Load the drafts js file
1475
-	if ($context['drafts_autosave'])
1476
-		loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1533
+	if ($context['drafts_autosave']) {
1534
+			loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1535
+	}
1477 1536
 
1478 1537
 	// Spellcheck
1479
-	if ($context['show_spellchecking'])
1480
-		loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1538
+	if ($context['show_spellchecking']) {
1539
+			loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1540
+	}
1481 1541
 
1482 1542
 	// topic.js
1483 1543
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -1511,16 +1571,19 @@  discard block
 block discarded – undo
1511 1571
 	static $counter = null;
1512 1572
 
1513 1573
 	// If the query returned false, bail.
1514
-	if ($messages_request == false)
1515
-		return false;
1574
+	if ($messages_request == false) {
1575
+			return false;
1576
+	}
1516 1577
 
1517 1578
 	// Remember which message this is.  (ie. reply #83)
1518
-	if ($counter === null || $reset)
1519
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1579
+	if ($counter === null || $reset) {
1580
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1581
+	}
1520 1582
 
1521 1583
 	// Start from the beginning...
1522
-	if ($reset)
1523
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1584
+	if ($reset) {
1585
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1586
+	}
1524 1587
 
1525 1588
 	// Attempt to get the next message.
1526 1589
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1534,19 +1597,21 @@  discard block
 block discarded – undo
1534 1597
 	if (empty($context['icon_sources']))
1535 1598
 	{
1536 1599
 		$context['icon_sources'] = array();
1537
-		foreach ($context['stable_icons'] as $icon)
1538
-			$context['icon_sources'][$icon] = 'images_url';
1600
+		foreach ($context['stable_icons'] as $icon) {
1601
+					$context['icon_sources'][$icon] = 'images_url';
1602
+		}
1539 1603
 	}
1540 1604
 
1541 1605
 	// Message Icon Management... check the images exist.
1542 1606
 	if (empty($modSettings['messageIconChecks_disable']))
1543 1607
 	{
1544 1608
 		// If the current icon isn't known, then we need to do something...
1545
-		if (!isset($context['icon_sources'][$message['icon']]))
1546
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1609
+		if (!isset($context['icon_sources'][$message['icon']])) {
1610
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1611
+		}
1612
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1613
+			$context['icon_sources'][$message['icon']] = 'images_url';
1547 1614
 	}
1548
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1549
-		$context['icon_sources'][$message['icon']] = 'images_url';
1550 1615
 
1551 1616
 	// If you're a lazy bum, you probably didn't give a subject...
1552 1617
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1571,8 +1636,7 @@  discard block
 block discarded – undo
1571 1636
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1572 1637
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1573 1638
 		$memberContext[$message['id_member']]['is_guest'] = true;
1574
-	}
1575
-	else
1639
+	} else
1576 1640
 	{
1577 1641
 		// Define this here to make things a bit more readable
1578 1642
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1595,8 +1659,9 @@  discard block
 block discarded – undo
1595 1659
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1596 1660
 
1597 1661
 	// If it's in the recycle bin we need to override whatever icon we did have.
1598
-	if (!empty($board_info['recycle']))
1599
-		$message['icon'] = 'recycled';
1662
+	if (!empty($board_info['recycle'])) {
1663
+			$message['icon'] = 'recycled';
1664
+	}
1600 1665
 
1601 1666
 	require_once($sourcedir . '/Subs-Attachments.php');
1602 1667
 
@@ -1640,32 +1705,36 @@  discard block
 block discarded – undo
1640 1705
 	}
1641 1706
 
1642 1707
 	// Are likes enable?
1643
-	if (!empty($modSettings['enable_likes']))
1644
-		$output['likes'] = array(
1708
+	if (!empty($modSettings['enable_likes'])) {
1709
+			$output['likes'] = array(
1645 1710
 			'count' => $message['likes'],
1646 1711
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1647 1712
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1648 1713
 		);
1714
+	}
1649 1715
 
1650 1716
 	// Is this user the message author?
1651 1717
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1652
-	if (!empty($output['modified']['name']))
1653
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1718
+	if (!empty($output['modified']['name'])) {
1719
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1720
+	}
1654 1721
 
1655 1722
 	// Did they give a reason for editing?
1656
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1657
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1723
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1724
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1725
+	}
1658 1726
 
1659 1727
 	// Any custom profile fields?
1660
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1661
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1728
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1729
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1662 1730
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1731
+	}
1663 1732
 
1664
-	if (empty($options['view_newest_first']))
1665
-		$counter++;
1666
-
1667
-	else
1668
-		$counter--;
1733
+	if (empty($options['view_newest_first'])) {
1734
+			$counter++;
1735
+	} else {
1736
+			$counter--;
1737
+	}
1669 1738
 
1670 1739
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1671 1740
 
@@ -1691,8 +1760,9 @@  discard block
 block discarded – undo
1691 1760
  */
1692 1761
 function approved_attach_sort($a, $b)
1693 1762
 {
1694
-	if ($a['is_approved'] == $b['is_approved'])
1695
-		return 0;
1763
+	if ($a['is_approved'] == $b['is_approved']) {
1764
+			return 0;
1765
+	}
1696 1766
 
1697 1767
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1698 1768
 }
@@ -1709,16 +1779,19 @@  discard block
 block discarded – undo
1709 1779
 
1710 1780
 	require_once($sourcedir . '/RemoveTopic.php');
1711 1781
 
1712
-	if (empty($_REQUEST['msgs']))
1713
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1782
+	if (empty($_REQUEST['msgs'])) {
1783
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1784
+	}
1714 1785
 
1715 1786
 	$messages = array();
1716
-	foreach ($_REQUEST['msgs'] as $dummy)
1717
-		$messages[] = (int) $dummy;
1787
+	foreach ($_REQUEST['msgs'] as $dummy) {
1788
+			$messages[] = (int) $dummy;
1789
+	}
1718 1790
 
1719 1791
 	// We are restoring messages. We handle this in another place.
1720
-	if (isset($_REQUEST['restore_selected']))
1721
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1792
+	if (isset($_REQUEST['restore_selected'])) {
1793
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1794
+	}
1722 1795
 	if (isset($_REQUEST['split_selection']))
1723 1796
 	{
1724 1797
 		$request = $smcFunc['db_query']('', '
@@ -1737,8 +1810,9 @@  discard block
 block discarded – undo
1737 1810
 	}
1738 1811
 
1739 1812
 	// Allowed to delete any message?
1740
-	if (allowedTo('delete_any'))
1741
-		$allowed_all = true;
1813
+	if (allowedTo('delete_any')) {
1814
+			$allowed_all = true;
1815
+	}
1742 1816
 	// Allowed to delete replies to their messages?
1743 1817
 	elseif (allowedTo('delete_replies'))
1744 1818
 	{
@@ -1755,13 +1829,14 @@  discard block
 block discarded – undo
1755 1829
 		$smcFunc['db_free_result']($request);
1756 1830
 
1757 1831
 		$allowed_all = $starter == $user_info['id'];
1832
+	} else {
1833
+			$allowed_all = false;
1758 1834
 	}
1759
-	else
1760
-		$allowed_all = false;
1761 1835
 
1762 1836
 	// Make sure they're allowed to delete their own messages, if not any.
1763
-	if (!$allowed_all)
1764
-		isAllowedTo('delete_own');
1837
+	if (!$allowed_all) {
1838
+			isAllowedTo('delete_own');
1839
+	}
1765 1840
 
1766 1841
 	// Allowed to remove which messages?
1767 1842
 	$request = $smcFunc['db_query']('', '
@@ -1781,8 +1856,9 @@  discard block
 block discarded – undo
1781 1856
 	$messages = array();
1782 1857
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1783 1858
 	{
1784
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1785
-			continue;
1859
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1860
+					continue;
1861
+		}
1786 1862
 
1787 1863
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1788 1864
 	}
@@ -1805,17 +1881,20 @@  discard block
 block discarded – undo
1805 1881
 	foreach ($messages as $message => $info)
1806 1882
 	{
1807 1883
 		// Just skip the first message - if it's not the last.
1808
-		if ($message == $first_message && $message != $last_message)
1809
-			continue;
1884
+		if ($message == $first_message && $message != $last_message) {
1885
+					continue;
1886
+		}
1810 1887
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1811
-		elseif ($message == $first_message)
1812
-			$topicGone = true;
1888
+		elseif ($message == $first_message) {
1889
+					$topicGone = true;
1890
+		}
1813 1891
 
1814 1892
 		removeMessage($message);
1815 1893
 
1816 1894
 		// Log this moderation action ;).
1817
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1818
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1895
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1896
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1897
+		}
1819 1898
 	}
1820 1899
 
1821 1900
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Themes/default/Memberlist.template.php 1 patch
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,9 +27,10 @@  discard block
 block discarded – undo
27 27
 			<h3 class="catbg">
28 28
 				<span class="floatleft">', $txt['members_list'], '</span>';
29 29
 
30
-	if (!isset($context['old_search']))
31
-		echo '
30
+	if (!isset($context['old_search'])) {
31
+			echo '
32 32
 				<span class="floatright">', $context['letter_links'], '</span>';
33
+	}
33 34
 	echo '
34 35
 			</h3>
35 36
 		</div>';
@@ -44,20 +45,23 @@  discard block
 block discarded – undo
44 45
 	foreach ($context['columns'] as $key => $column)
45 46
 	{
46 47
 		// @TODO maybe find something nicer?
47
-		if ($key == 'email_address' && !$context['can_send_email'])
48
-			continue;
48
+		if ($key == 'email_address' && !$context['can_send_email']) {
49
+					continue;
50
+		}
49 51
 
50 52
 		// This is a selected column, so underline it or some such.
51
-		if ($column['selected'])
52
-			echo '
53
+		if ($column['selected']) {
54
+					echo '
53 55
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '>
54 56
 							<a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>';
57
+		}
55 58
 
56 59
 		// This is just some column... show the link and be done with it.
57
-		else
58
-			echo '
60
+		else {
61
+					echo '
59 62
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '>
60 63
 						', $column['link'], '</th>';
64
+		}
61 65
 	}
62 66
 
63 67
 	echo '
@@ -77,9 +81,10 @@  discard block
 block discarded – undo
77 81
 						</td>
78 82
 						<td class="real_name lefttext">', $member['link'], '</td>';
79 83
 
80
-			if (!isset($context['disabled_fields']['website']))
81
-				echo '
84
+			if (!isset($context['disabled_fields']['website'])) {
85
+							echo '
82 86
 						<td class="website_url centertext">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>';
87
+			}
83 88
 
84 89
 			// Group and date.
85 90
 			echo '
@@ -91,33 +96,36 @@  discard block
 block discarded – undo
91 96
 				echo '
92 97
 						<td class="post_count centertext">';
93 98
 
94
-				if (!empty($member['post_percent']))
95
-					echo '
99
+				if (!empty($member['post_percent'])) {
100
+									echo '
96 101
 							<div class="generic_bar">
97 102
 								<div class="bar" style="width: ', $member['post_percent'], '%;"></div>
98 103
 								<span>', $member['posts'], '</span>
99 104
 							</div>';
105
+				}
100 106
 
101 107
 				echo '
102 108
 						</td>';
103 109
 			}
104 110
 
105 111
 			// Show custom fields marked to be shown here
106
-			if (!empty($context['custom_profile_fields']['columns']))
107
-				foreach ($context['custom_profile_fields']['columns'] as $key => $column)
112
+			if (!empty($context['custom_profile_fields']['columns'])) {
113
+							foreach ($context['custom_profile_fields']['columns'] as $key => $column)
108 114
 					echo '
109 115
 						<td class="' , $key , ' centertext">', $member['options'][$key], '</td>';
116
+			}
110 117
 
111 118
 			echo '
112 119
 					</tr>';
113 120
 		}
114 121
 	}
115 122
 	// No members?
116
-	else
117
-		echo '
123
+	else {
124
+			echo '
118 125
 					<tr>
119 126
 						<td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td>
120 127
 					</tr>';
128
+	}
121 129
 
122 130
 	echo '
123 131
 				</tbody>
@@ -130,11 +138,12 @@  discard block
 block discarded – undo
130 138
 			<div class="pagelinks floatleft">', $context['page_index'], '</div>';
131 139
 
132 140
 	// If it is displaying the result of a search show a "search again" link to edit their criteria.
133
-	if (isset($context['old_search']))
134
-		echo '
141
+	if (isset($context['old_search'])) {
142
+			echo '
135 143
 			<div class="buttonlist floatright">
136 144
 				<a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>
137 145
 			</div>';
146
+	}
138 147
 	echo '
139 148
 		</div>
140 149
 	</div><!-- #memberlist -->';
@@ -174,12 +183,13 @@  discard block
 block discarded – undo
174 183
 					<dd>
175 184
 						<ul>';
176 185
 
177
-	foreach ($context['search_fields'] as $id => $title)
178
-		echo '
186
+	foreach ($context['search_fields'] as $id => $title) {
187
+			echo '
179 188
 							<li>
180 189
 								<input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '>
181 190
 								<label for="fields-', $id, '">', $title, '</label>
182 191
 							</li>';
192
+	}
183 193
 
184 194
 	echo '
185 195
 						</ul>
Please login to merge, or discard this patch.
Sources/ManageSmileys.php 1 patch
Braces   +299 added lines, -213 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 is the dispatcher of smileys administration.
@@ -91,8 +92,9 @@  discard block
 block discarded – undo
91 92
 	);
92 93
 
93 94
 	// Some settings may not be enabled, disallow these from the tabs as appropriate.
94
-	if (empty($modSettings['messageIcons_enable']))
95
-		$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
95
+	if (empty($modSettings['messageIcons_enable'])) {
96
+			$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
97
+	}
96 98
 	if (empty($modSettings['smiley_enable']))
97 99
 	{
98 100
 		$context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
@@ -125,8 +127,9 @@  discard block
 block discarded – undo
125 127
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
126 128
 
127 129
 	$smiley_context = array();
128
-	foreach ($smiley_sets as $i => $set)
129
-		$smiley_context[$set] = $set_names[$i];
130
+	foreach ($smiley_sets as $i => $set) {
131
+			$smiley_context[$set] = $set_names[$i];
132
+	}
130 133
 
131 134
 	// All the settings for the page...
132 135
 	$config_vars = array(
@@ -147,8 +150,9 @@  discard block
 block discarded – undo
147 150
 
148 151
 	call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
149 152
 
150
-	if ($return_config)
151
-		return $config_vars;
153
+	if ($return_config) {
154
+			return $config_vars;
155
+	}
152 156
 
153 157
 	// Setup the basics of the settings template.
154 158
 	require_once($sourcedir . '/ManageServer.php');
@@ -208,8 +212,9 @@  discard block
 block discarded – undo
208 212
 			foreach ($_POST['smiley_set'] as $id => $val)
209 213
 			{
210 214
 				// If this is the set you've marked as default, or the only one remaining, you can't delete it
211
-				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id]))
212
-					unset($set_paths[$id], $set_names[$id], $set_exts[$id]);
215
+				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) {
216
+									unset($set_paths[$id], $set_names[$id], $set_exts[$id]);
217
+				}
213 218
 			}
214 219
 
215 220
 			// Shortcut... array_merge() on a single array resets the numeric keys
@@ -225,8 +230,9 @@  discard block
 block discarded – undo
225 230
 			));
226 231
 		}
227 232
 		// Add a new smiley set.
228
-		elseif (!empty($_POST['add']))
229
-			$context['sub_action'] = 'modifyset';
233
+		elseif (!empty($_POST['add'])) {
234
+					$context['sub_action'] = 'modifyset';
235
+		}
230 236
 		// Create or modify a smiley set.
231 237
 		elseif (isset($_POST['set']))
232 238
 		{
@@ -237,8 +243,9 @@  discard block
 block discarded – undo
237 243
 			// Create a new smiley set.
238 244
 			if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
239 245
 			{
240
-				if (in_array($_POST['smiley_sets_path'], $set_paths))
241
-					fatal_lang_error('smiley_set_already_exists');
246
+				if (in_array($_POST['smiley_sets_path'], $set_paths)) {
247
+									fatal_lang_error('smiley_set_already_exists');
248
+				}
242 249
 
243 250
 				updateSettings(array(
244 251
 					'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
@@ -251,12 +258,14 @@  discard block
 block discarded – undo
251 258
 			else
252 259
 			{
253 260
 				// Make sure the smiley set exists.
254
-				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
255
-					fatal_lang_error('smiley_set_not_found');
261
+				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) {
262
+									fatal_lang_error('smiley_set_not_found');
263
+				}
256 264
 
257 265
 				// Make sure the path is not yet used by another smileyset.
258
-				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
259
-					fatal_lang_error('smiley_set_path_already_used');
266
+				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) {
267
+									fatal_lang_error('smiley_set_path_already_used');
268
+				}
260 269
 
261 270
 				$set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
262 271
 				$set_exts[$_POST['set']] = $_POST['smiley_sets_ext'];
@@ -270,8 +279,9 @@  discard block
 block discarded – undo
270 279
 			}
271 280
 
272 281
 			// The user might have checked to also import smileys.
273
-			if (!empty($_POST['smiley_sets_import']))
274
-				ImportSmileys($_POST['smiley_sets_path']);
282
+			if (!empty($_POST['smiley_sets_import'])) {
283
+							ImportSmileys($_POST['smiley_sets_path']);
284
+			}
275 285
 		}
276 286
 		cache_put_data('parsing_smileys', null, 480);
277 287
 		cache_put_data('posting_smileys', null, 480);
@@ -281,14 +291,15 @@  discard block
 block discarded – undo
281 291
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
282 292
 	$set_exts = explode(",", $modSettings['smiley_sets_exts']);
283 293
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
284
-	foreach ($context['smiley_sets'] as $i => $set)
285
-		$context['smiley_sets'][$i] = array(
294
+	foreach ($context['smiley_sets'] as $i => $set) {
295
+			$context['smiley_sets'][$i] = array(
286 296
 			'id' => $i,
287 297
 			'path' => $smcFunc['htmlspecialchars']($set),
288 298
 			'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]),
289 299
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
290 300
 			'selected' => $set == $modSettings['smiley_sets_default']
291 301
 		);
302
+	}
292 303
 
293 304
 	// Importing any smileys from an existing set?
294 305
 	if ($context['sub_action'] == 'import')
@@ -299,8 +310,9 @@  discard block
 block discarded – undo
299 310
 		$_GET['set'] = (int) $_GET['set'];
300 311
 
301 312
 		// Sanity check - then import.
302
-		if (isset($context['smiley_sets'][$_GET['set']]))
303
-			ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
313
+		if (isset($context['smiley_sets'][$_GET['set']])) {
314
+					ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
315
+		}
304 316
 
305 317
 		// Force the process to continue.
306 318
 		$context['sub_action'] = 'modifyset';
@@ -310,8 +322,8 @@  discard block
 block discarded – undo
310 322
 	if ($context['sub_action'] == 'modifyset')
311 323
 	{
312 324
 		$_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
313
-		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
314
-			$context['current_set'] = array(
325
+		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) {
326
+					$context['current_set'] = array(
315 327
 				'id' => '-1',
316 328
 				'path' => '',
317 329
 				'ext' => '',
@@ -319,7 +331,7 @@  discard block
 block discarded – undo
319 331
 				'selected' => false,
320 332
 				'is_new' => true,
321 333
 			);
322
-		else
334
+		} else
323 335
 		{
324 336
 			$context['current_set'] = &$context['smiley_sets'][$_GET['set']];
325 337
 			$context['current_set']['is_new'] = false;
@@ -333,13 +345,15 @@  discard block
 block discarded – undo
333 345
 				{
334 346
 					// strip extension before comparison
335 347
 					$filename = pathinfo($entry, PATHINFO_FILENAME);
336
-					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg')))
337
-						$smileys[strtolower($filename)] = $filename;
348
+					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) {
349
+											$smileys[strtolower($filename)] = $filename;
350
+					}
338 351
 				}
339 352
 				$dir->close();
340 353
 
341
-				if (empty($smileys))
342
-					fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
354
+				if (empty($smileys)) {
355
+									fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
356
+				}
343 357
 
344 358
 				// Exclude the smileys that are already in the database.
345 359
 				$request = $smcFunc['db_query']('', '
@@ -350,9 +364,10 @@  discard block
 block discarded – undo
350 364
 						'smiley_list' => $smileys,
351 365
 					)
352 366
 				);
353
-				while ($row = $smcFunc['db_fetch_assoc']($request))
354
-					if (isset($smileys[strtolower($row['filename'])]))
367
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
368
+									if (isset($smileys[strtolower($row['filename'])]))
355 369
 						unset($smileys[strtolower($row['filename'])]);
370
+				}
356 371
 				$smcFunc['db_free_result']($request);
357 372
 
358 373
 				$context['current_set']['can_import'] = count($smileys);
@@ -367,13 +382,14 @@  discard block
 block discarded – undo
367 382
 			$dir = dir($modSettings['smileys_dir']);
368 383
 			while ($entry = $dir->read())
369 384
 			{
370
-				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
371
-					$context['smiley_set_dirs'][] = array(
385
+				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) {
386
+									$context['smiley_set_dirs'][] = array(
372 387
 						'id' => $entry,
373 388
 						'path' => $modSettings['smileys_dir'] . '/' . $entry,
374 389
 						'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
375 390
 						'current' => $entry == $context['current_set']['path'],
376 391
 					);
392
+				}
377 393
 			}
378 394
 			$dir->close();
379 395
 		}
@@ -383,8 +399,9 @@  discard block
 block discarded – undo
383 399
 	createToken('admin-mss', 'request');
384 400
 
385 401
 	// In case we need to import smileys, we need to add the token in now.
386
-	if (isset($context['current_set']['import_url']))
387
-		$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
402
+	if (isset($context['current_set']['import_url'])) {
403
+			$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
404
+	}
388 405
 
389 406
 	$listOptions = array(
390 407
 		'id' => 'smiley_set_list',
@@ -537,24 +554,26 @@  discard block
 block discarded – undo
537 554
 		$cols['ext'][] = $set_exts[$i];
538 555
 	}
539 556
 	$sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
540
-	if (substr($sort, 0, 4) === 'name')
541
-		array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id'], $cols['ext']);
542
-	elseif (substr($sort, 0, 3) === 'ext')
543
-		array_multisort($cols['ext'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['path']);
544
-	elseif (substr($sort, 0, 4) === 'path')
545
-		array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['ext']);
546
-	else
547
-		array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id'], $cols['ext']);
557
+	if (substr($sort, 0, 4) === 'name') {
558
+			array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id'], $cols['ext']);
559
+	} elseif (substr($sort, 0, 3) === 'ext') {
560
+			array_multisort($cols['ext'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['path']);
561
+	} elseif (substr($sort, 0, 4) === 'path') {
562
+			array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['ext']);
563
+	} else {
564
+			array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id'], $cols['ext']);
565
+	}
548 566
 
549 567
 	$smiley_sets = array();
550
-	foreach ($cols['id'] as $i => $id)
551
-		$smiley_sets[] = array(
568
+	foreach ($cols['id'] as $i => $id) {
569
+			$smiley_sets[] = array(
552 570
 			'id' => $id,
553 571
 			'path' => $cols['path'][$i],
554 572
 			'name' => $cols['name'][$i],
555 573
 			'ext' => $cols['ext'][$i],
556 574
 			'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
557 575
 		);
576
+	}
558 577
 
559 578
 	return $smiley_sets;
560 579
 }
@@ -584,14 +603,15 @@  discard block
 block discarded – undo
584 603
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
585 604
 	$set_exts = explode(',', $modSettings['smiley_sets_exts']);
586 605
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
587
-	foreach ($context['smiley_sets'] as $i => $set)
588
-		$context['smiley_sets'][$i] = array(
606
+	foreach ($context['smiley_sets'] as $i => $set) {
607
+			$context['smiley_sets'][$i] = array(
589 608
 			'id' => $i,
590 609
 			'path' => $smcFunc['htmlspecialchars']($set),
591 610
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
592 611
 			'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]),
593 612
 			'selected' => $set == $modSettings['smiley_sets_default']
594 613
 		);
614
+	}
595 615
 
596 616
 	// Submitting a form?
597 617
 	if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
@@ -607,8 +627,9 @@  discard block
 block discarded – undo
607 627
 		$_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
608 628
 
609 629
 		// Make sure some code was entered.
610
-		if (empty($_POST['smiley_code']))
611
-			fatal_lang_error('smiley_has_no_code');
630
+		if (empty($_POST['smiley_code'])) {
631
+					fatal_lang_error('smiley_has_no_code');
632
+		}
612 633
 
613 634
 		// Check whether the new code has duplicates. It should be unique.
614 635
 		$request = $smcFunc['db_query']('', '
@@ -620,8 +641,9 @@  discard block
 block discarded – undo
620 641
 				'smiley_code' => $_POST['smiley_code'],
621 642
 			)
622 643
 		);
623
-		if ($smcFunc['db_num_rows']($request) > 0)
624
-			fatal_lang_error('smiley_not_unique');
644
+		if ($smcFunc['db_num_rows']($request) > 0) {
645
+					fatal_lang_error('smiley_not_unique');
646
+		}
625 647
 		$smcFunc['db_free_result']($request);
626 648
 
627 649
 		// If we are uploading - check all the smiley sets are writable!
@@ -630,38 +652,44 @@  discard block
 block discarded – undo
630 652
 			$writeErrors = array();
631 653
 			foreach ($context['smiley_sets'] as $set)
632 654
 			{
633
-				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
634
-					$writeErrors[] = $set['path'];
655
+				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) {
656
+									$writeErrors[] = $set['path'];
657
+				}
658
+			}
659
+			if (!empty($writeErrors)) {
660
+							fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
635 661
 			}
636
-			if (!empty($writeErrors))
637
-				fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
638 662
 		}
639 663
 
640 664
 		// Uploading just one smiley for all of them?
641 665
 		if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
642 666
 		{
643
-			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
644
-				fatal_lang_error('smileys_upload_error');
667
+			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) {
668
+							fatal_lang_error('smileys_upload_error');
669
+			}
645 670
 
646 671
 			// Sorry, no spaces, dots, or anything else but letters allowed.
647 672
 			$_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
648 673
 
649 674
 			// We only allow image files - it's THAT simple - no messing around here...
650
-			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
651
-				fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
675
+			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) {
676
+							fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
677
+			}
652 678
 
653 679
 			// We only need the filename...
654 680
 			$destName = basename($_FILES['uploadSmiley']['name']);
655 681
 
656 682
 			// Make sure they aren't trying to upload a nasty file - for their own good here!
657
-			if (in_array(strtolower($destName), $disabledFiles))
658
-				fatal_lang_error('smileys_upload_error_illegal');
683
+			if (in_array(strtolower($destName), $disabledFiles)) {
684
+							fatal_lang_error('smileys_upload_error_illegal');
685
+			}
659 686
 
660 687
 			// Check if the file already exists... and if not move it to EVERY smiley set directory.
661 688
 			$i = 0;
662 689
 			// Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
663
-			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
664
-				$i++;
690
+			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) {
691
+							$i++;
692
+			}
665 693
 
666 694
 			// Okay, we're going to put the smiley right here, since it's not there yet!
667 695
 			if (isset($context['smiley_sets'][$i]['path']))
@@ -676,8 +704,9 @@  discard block
 block discarded – undo
676 704
 					$currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
677 705
 
678 706
 					// The file is already there!  Don't overwrite it!
679
-					if (file_exists($currentPath))
680
-						continue;
707
+					if (file_exists($currentPath)) {
708
+											continue;
709
+					}
681 710
 
682 711
 					// Okay, so copy the first one we made to here.
683 712
 					copy($smileyLocation, $currentPath);
@@ -694,13 +723,15 @@  discard block
 block discarded – undo
694 723
 			$newName = '';
695 724
 			foreach ($_FILES as $name => $data)
696 725
 			{
697
-				if ($_FILES[$name]['name'] == '')
698
-					fatal_lang_error('smileys_upload_error_blank');
726
+				if ($_FILES[$name]['name'] == '') {
727
+									fatal_lang_error('smileys_upload_error_blank');
728
+				}
699 729
 
700
-				if (empty($newName))
701
-					$newName = basename($_FILES[$name]['name']);
702
-				elseif (basename($_FILES[$name]['name']) != $newName)
703
-					fatal_lang_error('smileys_upload_error_name');
730
+				if (empty($newName)) {
731
+									$newName = basename($_FILES[$name]['name']);
732
+				} elseif (basename($_FILES[$name]['name']) != $newName) {
733
+									fatal_lang_error('smileys_upload_error_name');
734
+				}
704 735
 			}
705 736
 
706 737
 			foreach ($context['smiley_sets'] as $i => $set)
@@ -708,31 +739,36 @@  discard block
 block discarded – undo
708 739
 				$set['name'] = un_htmlspecialchars($set['name']);
709 740
 				$set['path'] = un_htmlspecialchars($set['path']);
710 741
 
711
-				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
712
-					continue;
742
+				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') {
743
+									continue;
744
+				}
713 745
 
714 746
 				// Got one...
715
-				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
716
-					fatal_lang_error('smileys_upload_error');
747
+				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) {
748
+									fatal_lang_error('smileys_upload_error');
749
+				}
717 750
 
718 751
 				// Sorry, no spaces, dots, or anything else but letters allowed.
719 752
 				$_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
720 753
 
721 754
 				// We only allow image files - it's THAT simple - no messing around here...
722
-				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
723
-					fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
755
+				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) {
756
+									fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
757
+				}
724 758
 
725 759
 				// We only need the filename...
726 760
 				$destName = basename($_FILES['individual_' . $set['name']]['name']);
727 761
 
728 762
 				// Make sure they aren't trying to upload a nasty file - for their own good here!
729
-				if (in_array(strtolower($destName), $disabledFiles))
730
-					fatal_lang_error('smileys_upload_error_illegal');
763
+				if (in_array(strtolower($destName), $disabledFiles)) {
764
+									fatal_lang_error('smileys_upload_error_illegal');
765
+				}
731 766
 
732 767
 				// If the file exists - ignore it.
733 768
 				$smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
734
-				if (file_exists($smileyLocation))
735
-					continue;
769
+				if (file_exists($smileyLocation)) {
770
+									continue;
771
+				}
736 772
 
737 773
 				// Finally - move the image!
738 774
 				move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
@@ -744,8 +780,9 @@  discard block
 block discarded – undo
744 780
 		}
745 781
 
746 782
 		// Also make sure a filename was given.
747
-		if (empty($_POST['smiley_filename']))
748
-			fatal_lang_error('smiley_has_no_filename');
783
+		if (empty($_POST['smiley_filename'])) {
784
+					fatal_lang_error('smiley_has_no_filename');
785
+		}
749 786
 
750 787
 		// Find the position on the right.
751 788
 		$smiley_order = '0';
@@ -764,8 +801,9 @@  discard block
 block discarded – undo
764 801
 			list ($smiley_order) = $smcFunc['db_fetch_row']($request);
765 802
 			$smcFunc['db_free_result']($request);
766 803
 
767
-			if (empty($smiley_order))
768
-				$smiley_order = '0';
804
+			if (empty($smiley_order)) {
805
+							$smiley_order = '0';
806
+			}
769 807
 		}
770 808
 		$smcFunc['db_insert']('',
771 809
 			'{db_prefix}smileys',
@@ -793,19 +831,21 @@  discard block
 block discarded – undo
793 831
 	{
794 832
 		foreach ($context['smiley_sets'] as $smiley_set)
795 833
 		{
796
-			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
797
-				continue;
834
+			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
835
+							continue;
836
+			}
798 837
 
799 838
 			$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
800 839
 			while ($entry = $dir->read())
801 840
 			{
802 841
 				// Strip extension
803 842
 				$filename = pathinfo($entry, PATHINFO_FILENAME);
804
-				if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg')))
805
-					$context['filenames'][strtolower($filename)] = array(
843
+				if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) {
844
+									$context['filenames'][strtolower($filename)] = array(
806 845
 						'id' => $smcFunc['htmlspecialchars']($filename),
807 846
 						'selected' => false,
808 847
 					);
848
+				}
809 849
 			}
810 850
 			$dir->close();
811 851
 		}
@@ -843,17 +883,19 @@  discard block
 block discarded – undo
843 883
 		// Changing the selected smileys?
844 884
 		if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
845 885
 		{
846
-			foreach ($_POST['checked_smileys'] as $id => $smiley_id)
847
-				$_POST['checked_smileys'][$id] = (int) $smiley_id;
886
+			foreach ($_POST['checked_smileys'] as $id => $smiley_id) {
887
+							$_POST['checked_smileys'][$id] = (int) $smiley_id;
888
+			}
848 889
 
849
-			if ($_POST['smiley_action'] == 'delete')
850
-				$smcFunc['db_query']('', '
890
+			if ($_POST['smiley_action'] == 'delete') {
891
+							$smcFunc['db_query']('', '
851 892
 					DELETE FROM {db_prefix}smileys
852 893
 					WHERE id_smiley IN ({array_int:checked_smileys})',
853 894
 					array(
854 895
 						'checked_smileys' => $_POST['checked_smileys'],
855 896
 					)
856 897
 				);
898
+			}
857 899
 			// Changing the status of the smiley?
858 900
 			else
859 901
 			{
@@ -863,8 +905,8 @@  discard block
 block discarded – undo
863 905
 					'hidden' => 1,
864 906
 					'popup' => 2
865 907
 				);
866
-				if (isset($displayTypes[$_POST['smiley_action']]))
867
-					$smcFunc['db_query']('', '
908
+				if (isset($displayTypes[$_POST['smiley_action']])) {
909
+									$smcFunc['db_query']('', '
868 910
 						UPDATE {db_prefix}smileys
869 911
 						SET hidden = {int:display_type}
870 912
 						WHERE id_smiley IN ({array_int:checked_smileys})',
@@ -873,6 +915,7 @@  discard block
 block discarded – undo
873 915
 							'display_type' => $displayTypes[$_POST['smiley_action']],
874 916
 						)
875 917
 					);
918
+				}
876 919
 			}
877 920
 		}
878 921
 		// Create/modify a smiley.
@@ -898,12 +941,14 @@  discard block
 block discarded – undo
898 941
 				$_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
899 942
 
900 943
 				// Make sure some code was entered.
901
-				if (empty($_POST['smiley_code']))
902
-					fatal_lang_error('smiley_has_no_code');
944
+				if (empty($_POST['smiley_code'])) {
945
+									fatal_lang_error('smiley_has_no_code');
946
+				}
903 947
 
904 948
 				// Also make sure a filename was given.
905
-				if (empty($_POST['smiley_filename']))
906
-					fatal_lang_error('smiley_has_no_filename');
949
+				if (empty($_POST['smiley_filename'])) {
950
+									fatal_lang_error('smiley_has_no_filename');
951
+				}
907 952
 
908 953
 				// Check whether the new code has duplicates. It should be unique.
909 954
 				$request = $smcFunc['db_query']('', '
@@ -917,8 +962,9 @@  discard block
 block discarded – undo
917 962
 						'smiley_code' => $_POST['smiley_code'],
918 963
 					)
919 964
 				);
920
-				if ($smcFunc['db_num_rows']($request) > 0)
921
-					fatal_lang_error('smiley_not_unique');
965
+				if ($smcFunc['db_num_rows']($request) > 0) {
966
+									fatal_lang_error('smiley_not_unique');
967
+				}
922 968
 				$smcFunc['db_free_result']($request);
923 969
 
924 970
 				$smcFunc['db_query']('', '
@@ -948,14 +994,15 @@  discard block
 block discarded – undo
948 994
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
949 995
 	$set_exts = explode(',', $modSettings['smiley_sets_exts']);
950 996
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
951
-	foreach ($context['smiley_sets'] as $i => $set)
952
-		$context['smiley_sets'][$i] = array(
997
+	foreach ($context['smiley_sets'] as $i => $set) {
998
+			$context['smiley_sets'][$i] = array(
953 999
 			'id' => $i,
954 1000
 			'path' => $smcFunc['htmlspecialchars']($set),
955 1001
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
956 1002
 			'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]),
957 1003
 			'selected' => $set == $modSettings['smiley_sets_default']
958 1004
 		);
1005
+	}
959 1006
 
960 1007
 	// Prepare overview of all (custom) smileys.
961 1008
 	if ($context['sub_action'] == 'editsmileys')
@@ -971,9 +1018,10 @@  discard block
 block discarded – undo
971 1018
 		// Create a list of options for selecting smiley sets.
972 1019
 		$smileyset_option_list = '
973 1020
 			<select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
974
-		foreach ($context['smiley_sets'] as $smiley_set)
975
-			$smileyset_option_list .= '
1021
+		foreach ($context['smiley_sets'] as $smiley_set) {
1022
+					$smileyset_option_list .= '
976 1023
 				<option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>';
1024
+		}
977 1025
 		$smileyset_option_list .= '
978 1026
 			</select>';
979 1027
 
@@ -1035,12 +1083,13 @@  discard block
 block discarded – undo
1035 1083
 					'data' => array(
1036 1084
 						'function' => function ($rowData) use ($txt)
1037 1085
 						{
1038
-							if (empty($rowData['hidden']))
1039
-								return $txt['smileys_location_form'];
1040
-							elseif ($rowData['hidden'] == 1)
1041
-								return $txt['smileys_location_hidden'];
1042
-							else
1043
-								return $txt['smileys_location_popup'];
1086
+							if (empty($rowData['hidden'])) {
1087
+															return $txt['smileys_location_form'];
1088
+							} elseif ($rowData['hidden'] == 1) {
1089
+															return $txt['smileys_location_hidden'];
1090
+							} else {
1091
+															return $txt['smileys_location_popup'];
1092
+							}
1044 1093
 						},
1045 1094
 					),
1046 1095
 					'sort' => array(
@@ -1055,19 +1104,22 @@  discard block
 block discarded – undo
1055 1104
 					'data' => array(
1056 1105
 						'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc)
1057 1106
 						{
1058
-							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']))
1059
-								return $smcFunc['htmlspecialchars']($rowData['description']);
1107
+							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) {
1108
+															return $smcFunc['htmlspecialchars']($rowData['description']);
1109
+							}
1060 1110
 
1061 1111
 							// Check if there are smileys missing in some sets.
1062 1112
 							$missing_sets = array();
1063
-							foreach ($context['smiley_sets'] as $smiley_set)
1064
-								if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1113
+							foreach ($context['smiley_sets'] as $smiley_set) {
1114
+															if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1065 1115
 									$missing_sets[] = $smiley_set['path'];
1116
+							}
1066 1117
 
1067 1118
 							$description = $smcFunc['htmlspecialchars']($rowData['description']);
1068 1119
 
1069
-							if (!empty($missing_sets))
1070
-								$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1120
+							if (!empty($missing_sets)) {
1121
+															$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1122
+							}
1071 1123
 
1072 1124
 							return $description;
1073 1125
 						},
@@ -1186,14 +1238,15 @@  discard block
 block discarded – undo
1186 1238
 		$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
1187 1239
 		$set_exts = explode(',', $modSettings['smiley_sets_exts']);
1188 1240
 		$set_names = explode("\n", $modSettings['smiley_sets_names']);
1189
-		foreach ($context['smiley_sets'] as $i => $set)
1190
-			$context['smiley_sets'][$i] = array(
1241
+		foreach ($context['smiley_sets'] as $i => $set) {
1242
+					$context['smiley_sets'][$i] = array(
1191 1243
 				'id' => $i,
1192 1244
 				'path' => $smcFunc['htmlspecialchars']($set),
1193 1245
 				'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
1194 1246
 				'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]),
1195 1247
 				'selected' => $set == $modSettings['smiley_sets_default']
1196 1248
 			);
1249
+		}
1197 1250
 
1198 1251
 		$context['selected_set'] = $modSettings['smiley_sets_default'];
1199 1252
 
@@ -1203,19 +1256,21 @@  discard block
 block discarded – undo
1203 1256
 		{
1204 1257
 			foreach ($context['smiley_sets'] as $smiley_set)
1205 1258
 			{
1206
-				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
1207
-					continue;
1259
+				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
1260
+									continue;
1261
+				}
1208 1262
 
1209 1263
 				$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
1210 1264
 				while ($entry = $dir->read())
1211 1265
 				{
1212 1266
 					// Strip extension
1213 1267
 					$filename = pathinfo($entry, PATHINFO_FILENAME);
1214
-					if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg')))
1215
-						$context['filenames'][strtolower($filename)] = array(
1268
+					if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) {
1269
+											$context['filenames'][strtolower($filename)] = array(
1216 1270
 							'id' => $smcFunc['htmlspecialchars']($filename),
1217 1271
 							'selected' => false,
1218 1272
 						);
1273
+					}
1219 1274
 				}
1220 1275
 				$dir->close();
1221 1276
 			}
@@ -1230,8 +1285,9 @@  discard block
 block discarded – undo
1230 1285
 				'current_smiley' => (int) $_REQUEST['smiley'],
1231 1286
 			)
1232 1287
 		);
1233
-		if ($smcFunc['db_num_rows']($request) != 1)
1234
-			fatal_lang_error('smiley_not_found');
1288
+		if ($smcFunc['db_num_rows']($request) != 1) {
1289
+					fatal_lang_error('smiley_not_found');
1290
+		}
1235 1291
 		$context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
1236 1292
 		$smcFunc['db_free_result']($request);
1237 1293
 
@@ -1239,8 +1295,9 @@  discard block
 block discarded – undo
1239 1295
 		$context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']);
1240 1296
 		$context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']);
1241 1297
 
1242
-		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
1243
-			$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1298
+		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) {
1299
+					$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1300
+		}
1244 1301
 	}
1245 1302
 }
1246 1303
 
@@ -1265,8 +1322,9 @@  discard block
 block discarded – undo
1265 1322
 		)
1266 1323
 	);
1267 1324
 	$smileys = array();
1268
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1269
-		$smileys[] = $row;
1325
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1326
+			$smileys[] = $row;
1327
+	}
1270 1328
 	$smcFunc['db_free_result']($request);
1271 1329
 
1272 1330
 	return $smileys;
@@ -1306,8 +1364,9 @@  discard block
 block discarded – undo
1306 1364
 		$_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
1307 1365
 		$_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
1308 1366
 
1309
-		if (empty($_GET['source']))
1310
-			fatal_lang_error('smiley_not_found');
1367
+		if (empty($_GET['source'])) {
1368
+					fatal_lang_error('smiley_not_found');
1369
+		}
1311 1370
 
1312 1371
 		if (!empty($_GET['after']))
1313 1372
 		{
@@ -1323,12 +1382,12 @@  discard block
 block discarded – undo
1323 1382
 					'after_smiley' => $_GET['after'],
1324 1383
 				)
1325 1384
 			);
1326
-			if ($smcFunc['db_num_rows']($request) != 1)
1327
-				fatal_lang_error('smiley_not_found');
1385
+			if ($smcFunc['db_num_rows']($request) != 1) {
1386
+							fatal_lang_error('smiley_not_found');
1387
+			}
1328 1388
 			list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
1329 1389
 			$smcFunc['db_free_result']($request);
1330
-		}
1331
-		else
1390
+		} else
1332 1391
 		{
1333 1392
 			$smiley_row = (int) $_GET['row'];
1334 1393
 			$smiley_order = -1;
@@ -1402,14 +1461,15 @@  discard block
 block discarded – undo
1402 1461
 	$context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
1403 1462
 
1404 1463
 	// Make sure all rows are sequential.
1405
-	foreach (array_keys($context['smileys']) as $location)
1406
-		$context['smileys'][$location] = array(
1464
+	foreach (array_keys($context['smileys']) as $location) {
1465
+			$context['smileys'][$location] = array(
1407 1466
 			'id' => $location,
1408 1467
 			'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
1409 1468
 			'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
1410 1469
 			'last_row' => count($context['smileys'][$location]['rows']),
1411 1470
 			'rows' => array_values($context['smileys'][$location]['rows']),
1412 1471
 		);
1472
+	}
1413 1473
 
1414 1474
 	// Check & fix smileys that are not ordered properly in the database.
1415 1475
 	foreach (array_keys($context['smileys']) as $location)
@@ -1434,8 +1494,8 @@  discard block
 block discarded – undo
1434 1494
 				$context['smileys'][$location]['rows'][$id][0]['row'] = $id;
1435 1495
 			}
1436 1496
 			// Make sure the smiley order is always sequential.
1437
-			foreach ($smiley_row as $order_id => $smiley)
1438
-				if ($order_id != $smiley['order'])
1497
+			foreach ($smiley_row as $order_id => $smiley) {
1498
+							if ($order_id != $smiley['order'])
1439 1499
 					$smcFunc['db_query']('', '
1440 1500
 						UPDATE {db_prefix}smileys
1441 1501
 						SET smiley_order = {int:new_order}
@@ -1445,6 +1505,7 @@  discard block
 block discarded – undo
1445 1505
 							'current_smiley' => $smiley['id'],
1446 1506
 						)
1447 1507
 					);
1508
+			}
1448 1509
 		}
1449 1510
 	}
1450 1511
 
@@ -1478,19 +1539,20 @@  discard block
 block discarded – undo
1478 1539
 
1479 1540
 		// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
1480 1541
 		// @ TODO: Our current xml files serve http links.  Allowing both for now until we serve https.
1481
-		if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
1482
-			fatal_lang_error('not_on_simplemachines');
1542
+		if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) {
1543
+					fatal_lang_error('not_on_simplemachines');
1544
+		}
1483 1545
 
1484 1546
 		$destination = $packagesdir . '/' . $base_name;
1485 1547
 
1486
-		if (file_exists($destination))
1487
-			fatal_lang_error('package_upload_error_exists');
1548
+		if (file_exists($destination)) {
1549
+					fatal_lang_error('package_upload_error_exists');
1550
+		}
1488 1551
 
1489 1552
 		// Let's copy it to the Packages directory
1490 1553
 		file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
1491 1554
 		$testing = true;
1492
-	}
1493
-	elseif (isset($_REQUEST['package']))
1555
+	} elseif (isset($_REQUEST['package']))
1494 1556
 	{
1495 1557
 		$base_name = basename($_REQUEST['package']);
1496 1558
 		$name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.'));
@@ -1499,12 +1561,14 @@  discard block
 block discarded – undo
1499 1561
 		$destination = $packagesdir . '/' . basename($_REQUEST['package']);
1500 1562
 	}
1501 1563
 
1502
-	if (empty($destination) || !file_exists($destination))
1503
-		fatal_lang_error('package_no_file', false);
1564
+	if (empty($destination) || !file_exists($destination)) {
1565
+			fatal_lang_error('package_no_file', false);
1566
+	}
1504 1567
 
1505 1568
 	// Make sure temp directory exists and is empty.
1506
-	if (file_exists($packagesdir . '/temp'))
1507
-		deltree($packagesdir . '/temp', false);
1569
+	if (file_exists($packagesdir . '/temp')) {
1570
+			deltree($packagesdir . '/temp', false);
1571
+	}
1508 1572
 
1509 1573
 	if (!mktree($packagesdir . '/temp', 0755))
1510 1574
 	{
@@ -1516,31 +1580,37 @@  discard block
 block discarded – undo
1516 1580
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true));
1517 1581
 
1518 1582
 			deltree($packagesdir . '/temp', false);
1519
-			if (!mktree($packagesdir . '/temp', 0777))
1520
-				fatal_lang_error('package_cant_download', false);
1583
+			if (!mktree($packagesdir . '/temp', 0777)) {
1584
+							fatal_lang_error('package_cant_download', false);
1585
+			}
1521 1586
 		}
1522 1587
 	}
1523 1588
 
1524 1589
 	$extracted = read_tgz_file($destination, $packagesdir . '/temp');
1525
-	if (!$extracted)
1526
-		fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1527
-	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml'))
1528
-		foreach ($extracted as $file)
1590
+	if (!$extracted) {
1591
+			fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1592
+	}
1593
+	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) {
1594
+			foreach ($extracted as $file)
1529 1595
 			if (basename($file['filename']) == 'package-info.xml')
1530 1596
 			{
1531 1597
 				$base_path = dirname($file['filename']) . '/';
1598
+	}
1532 1599
 				break;
1533 1600
 			}
1534 1601
 
1535
-	if (!isset($base_path))
1536
-		$base_path = '';
1602
+	if (!isset($base_path)) {
1603
+			$base_path = '';
1604
+	}
1537 1605
 
1538
-	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml'))
1539
-		fatal_lang_error('package_get_error_missing_xml', false);
1606
+	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) {
1607
+			fatal_lang_error('package_get_error_missing_xml', false);
1608
+	}
1540 1609
 
1541 1610
 	$smileyInfo = getPackageInfo($context['filename']);
1542
-	if (!is_array($smileyInfo))
1543
-		fatal_lang_error($smileyInfo);
1611
+	if (!is_array($smileyInfo)) {
1612
+			fatal_lang_error($smileyInfo);
1613
+	}
1544 1614
 
1545 1615
 	// See if it is installed?
1546 1616
 	$request = $smcFunc['db_query']('', '
@@ -1556,8 +1626,9 @@  discard block
 block discarded – undo
1556 1626
 		)
1557 1627
 	);
1558 1628
 
1559
-	if ($smcFunc['db_num_rows']($request) > 0)
1560
-		fatal_lang_error('package_installed_warning1');
1629
+	if ($smcFunc['db_num_rows']($request) > 0) {
1630
+			fatal_lang_error('package_installed_warning1');
1631
+	}
1561 1632
 
1562 1633
 	// Everything is fine, now it's time to do something
1563 1634
 	$actions = parsePackageInfo($smileyInfo['xml'], true, 'install');
@@ -1572,23 +1643,23 @@  discard block
 block discarded – undo
1572 1643
 		if ($action['type'] == 'readme' || $action['type'] == 'license')
1573 1644
 		{
1574 1645
 			$type = 'package_' . $action['type'];
1575
-			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename']))
1576
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1577
-			elseif (file_exists($action['filename']))
1578
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1646
+			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) {
1647
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1648
+			} elseif (file_exists($action['filename'])) {
1649
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1650
+			}
1579 1651
 
1580 1652
 			if (!empty($action['parse_bbc']))
1581 1653
 			{
1582 1654
 				require_once($sourcedir . '/Subs-Post.php');
1583 1655
 				preparsecode($context[$type]);
1584 1656
 				$context[$type] = parse_bbc($context[$type]);
1657
+			} else {
1658
+							$context[$type] = nl2br($context[$type]);
1585 1659
 			}
1586
-			else
1587
-				$context[$type] = nl2br($context[$type]);
1588 1660
 
1589 1661
 			continue;
1590
-		}
1591
-		elseif ($action['type'] == 'require-dir')
1662
+		} elseif ($action['type'] == 'require-dir')
1592 1663
 		{
1593 1664
 			// Do this one...
1594 1665
 			$thisAction = array(
@@ -1607,12 +1678,12 @@  discard block
 block discarded – undo
1607 1678
 				);
1608 1679
 			}
1609 1680
 			// @todo None given?
1610
-			if (empty($thisAction['description']))
1611
-				$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1681
+			if (empty($thisAction['description'])) {
1682
+							$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1683
+			}
1612 1684
 
1613 1685
 			$context['actions'][] = $thisAction;
1614
-		}
1615
-		elseif ($action['type'] == 'credits')
1686
+		} elseif ($action['type'] == 'credits')
1616 1687
 		{
1617 1688
 			// Time to build the billboard
1618 1689
 			$credits_tag = array(
@@ -1672,12 +1743,14 @@  discard block
 block discarded – undo
1672 1743
 		cache_put_data('posting_smileys', null, 480);
1673 1744
 	}
1674 1745
 
1675
-	if (file_exists($packagesdir . '/temp'))
1676
-		deltree($packagesdir . '/temp');
1746
+	if (file_exists($packagesdir . '/temp')) {
1747
+			deltree($packagesdir . '/temp');
1748
+	}
1677 1749
 
1678
-	if (!$testing)
1679
-		redirectexit('action=admin;area=smileys');
1680
-}
1750
+	if (!$testing) {
1751
+			redirectexit('action=admin;area=smileys');
1752
+	}
1753
+	}
1681 1754
 
1682 1755
 /**
1683 1756
  * A function to import new smileys from an existing directory into the database.
@@ -1688,16 +1761,18 @@  discard block
 block discarded – undo
1688 1761
 {
1689 1762
 	global $modSettings, $smcFunc;
1690 1763
 
1691
-	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
1692
-		fatal_lang_error('smiley_set_unable_to_import');
1764
+	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) {
1765
+			fatal_lang_error('smiley_set_unable_to_import');
1766
+	}
1693 1767
 
1694 1768
 	$smileys = array();
1695 1769
 	$dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
1696 1770
 	while ($entry = $dir->read())
1697 1771
 	{
1698 1772
 		$filename = pathinfo($entry, PATHINFO_FILENAME);
1699
-		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg')))
1700
-			$smileys[strtolower($filename)] = $filename;
1773
+		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) {
1774
+					$smileys[strtolower($filename)] = $filename;
1775
+		}
1701 1776
 	}
1702 1777
 	$dir->close();
1703 1778
 
@@ -1710,9 +1785,10 @@  discard block
 block discarded – undo
1710 1785
 			'smiley_list' => $smileys,
1711 1786
 		)
1712 1787
 	);
1713
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1714
-		if (isset($smileys[strtolower($row['filename'])]))
1788
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1789
+			if (isset($smileys[strtolower($row['filename'])]))
1715 1790
 			unset($smileys[strtolower($row['filename'])]);
1791
+	}
1716 1792
 	$smcFunc['db_free_result']($request);
1717 1793
 
1718 1794
 	$request = $smcFunc['db_query']('', '
@@ -1729,9 +1805,10 @@  discard block
 block discarded – undo
1729 1805
 	$smcFunc['db_free_result']($request);
1730 1806
 
1731 1807
 	$new_smileys = array();
1732
-	foreach ($smileys as $smiley)
1733
-		if (strlen($smiley) <= 48)
1808
+	foreach ($smileys as $smiley) {
1809
+			if (strlen($smiley) <= 48)
1734 1810
 			$new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
1811
+	}
1735 1812
 
1736 1813
 	if (!empty($new_smileys))
1737 1814
 	{
@@ -1796,8 +1873,9 @@  discard block
 block discarded – undo
1796 1873
 		if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
1797 1874
 		{
1798 1875
 			$deleteIcons = array();
1799
-			foreach ($_POST['checked_icons'] as $icon)
1800
-				$deleteIcons[] = (int) $icon;
1876
+			foreach ($_POST['checked_icons'] as $icon) {
1877
+							$deleteIcons[] = (int) $icon;
1878
+			}
1801 1879
 
1802 1880
 			// Do the actual delete!
1803 1881
 			$smcFunc['db_query']('', '
@@ -1814,35 +1892,41 @@  discard block
 block discarded – undo
1814 1892
 			$_GET['icon'] = (int) $_GET['icon'];
1815 1893
 
1816 1894
 			// Do some preperation with the data... like check the icon exists *somewhere*
1817
-			if (strpos($_POST['icon_filename'], '.png') !== false)
1818
-				$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1819
-			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png'))
1820
-				fatal_lang_error('icon_not_found');
1895
+			if (strpos($_POST['icon_filename'], '.png') !== false) {
1896
+							$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1897
+			}
1898
+			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) {
1899
+							fatal_lang_error('icon_not_found');
1900
+			}
1821 1901
 			// There is a 16 character limit on message icons...
1822
-			elseif (strlen($_POST['icon_filename']) > 16)
1823
-				fatal_lang_error('icon_name_too_long');
1824
-			elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
1825
-				fatal_lang_error('icon_after_itself');
1902
+			elseif (strlen($_POST['icon_filename']) > 16) {
1903
+							fatal_lang_error('icon_name_too_long');
1904
+			} elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) {
1905
+							fatal_lang_error('icon_after_itself');
1906
+			}
1826 1907
 
1827 1908
 			// First do the sorting... if this is an edit reduce the order of everything after it by one ;)
1828 1909
 			if ($_GET['icon'] != 0)
1829 1910
 			{
1830 1911
 				$oldOrder = $context['icons'][$_GET['icon']]['true_order'];
1831
-				foreach ($context['icons'] as $id => $data)
1832
-					if ($data['true_order'] > $oldOrder)
1912
+				foreach ($context['icons'] as $id => $data) {
1913
+									if ($data['true_order'] > $oldOrder)
1833 1914
 						$context['icons'][$id]['true_order']--;
1915
+				}
1834 1916
 			}
1835 1917
 
1836 1918
 			// If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
1837
-			if (empty($_GET['icon']) && empty($context['icons']))
1838
-				$_GET['icon'] = 1;
1919
+			if (empty($_GET['icon']) && empty($context['icons'])) {
1920
+							$_GET['icon'] = 1;
1921
+			}
1839 1922
 
1840 1923
 			// Get the new order.
1841 1924
 			$newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
1842 1925
 			// Do the same, but with the one that used to be after this icon, done to avoid conflict.
1843
-			foreach ($context['icons'] as $id => $data)
1844
-				if ($data['true_order'] >= $newOrder)
1926
+			foreach ($context['icons'] as $id => $data) {
1927
+							if ($data['true_order'] >= $newOrder)
1845 1928
 					$context['icons'][$id]['true_order']++;
1929
+			}
1846 1930
 
1847 1931
 			// Finally set the current icon's position!
1848 1932
 			$context['icons'][$_GET['icon']]['true_order'] = $newOrder;
@@ -1860,8 +1944,7 @@  discard block
 block discarded – undo
1860 1944
 				if ($id != 0)
1861 1945
 				{
1862 1946
 					$iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1863
-				}
1864
-				else
1947
+				} else
1865 1948
 				{
1866 1949
 					$iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1867 1950
 				}
@@ -1886,8 +1969,9 @@  discard block
 block discarded – undo
1886 1969
 		}
1887 1970
 
1888 1971
 		// Unless we're adding a new thing, we'll escape
1889
-		if (!isset($_POST['add']))
1890
-			redirectexit('action=admin;area=smileys;sa=editicons');
1972
+		if (!isset($_POST['add'])) {
1973
+					redirectexit('action=admin;area=smileys;sa=editicons');
1974
+		}
1891 1975
 	}
1892 1976
 
1893 1977
 	$context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
@@ -1997,8 +2081,9 @@  discard block
 block discarded – undo
1997 2081
 		$context['new_icon'] = !isset($_GET['icon']);
1998 2082
 
1999 2083
 		// Get the properties of the current icon from the icon list.
2000
-		if (!$context['new_icon'])
2001
-			$context['icon'] = $context['icons'][$_GET['icon']];
2084
+		if (!$context['new_icon']) {
2085
+					$context['icon'] = $context['icons'][$_GET['icon']];
2086
+		}
2002 2087
 
2003 2088
 		// Get a list of boards needed for assigning this icon to a specific board.
2004 2089
 		$boardListOptions = array(
@@ -2032,8 +2117,9 @@  discard block
 block discarded – undo
2032 2117
 	);
2033 2118
 
2034 2119
 	$message_icons = array();
2035
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2036
-		$message_icons[] = $row;
2120
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2121
+			$message_icons[] = $row;
2122
+	}
2037 2123
 	$smcFunc['db_free_result']($request);
2038 2124
 
2039 2125
 	return $message_icons;
Please login to merge, or discard this patch.
Sources/tasks/CreatePost-Notify.php 1 patch
Braces   +74 added lines, -54 removed lines patch added patch discarded remove patch
@@ -96,8 +96,9 @@  discard block
 block discarded – undo
96 96
 		while ($row = $smcFunc['db_fetch_assoc']($request))
97 97
 		{
98 98
 			$groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups'])));
99
-			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0)
100
-				continue;
99
+			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) {
100
+							continue;
101
+			}
101 102
 
102 103
 			$members[] = $row['id_member'];
103 104
 			$watched[$row['id_member']] = $row;
@@ -105,8 +106,9 @@  discard block
 block discarded – undo
105 106
 
106 107
 		$smcFunc['db_free_result']($request);
107 108
 
108
-		if (empty($members))
109
-			return true;
109
+		if (empty($members)) {
110
+					return true;
111
+		}
110 112
 
111 113
 		$members = array_unique($members);
112 114
 		$prefs = getNotifyPrefs($members, '', true);
@@ -122,8 +124,9 @@  discard block
 block discarded – undo
122 124
 		self::handleQuoteNotifications($msgOptions, $posterOptions, $quotedMembers, $prefs, $done_members, $alert_rows);
123 125
 
124 126
 		// Save ourselves a bit of work in the big loop below
125
-		foreach ($done_members as $done_member)
126
-			unset($watched[$done_member]);
127
+		foreach ($done_members as $done_member) {
128
+					unset($watched[$done_member]);
129
+		}
127 130
 
128 131
 		// Handle rest of the notifications for watched topics and boards
129 132
 		foreach ($watched as $member => $data)
@@ -132,26 +135,31 @@  discard block
 block discarded – undo
132 135
 			$notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : self::NOTIFY_TYPE_REPLY_AND_MODIFY;
133 136
 
134 137
 			// Don't send a notification if the watching member ignored the member who made the action.
135
-			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list'])))
136
-				continue;
137
-			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started'])
138
-				continue;
139
-			elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id'])
140
-				continue;
141
-			elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES)
142
-				continue;
143
-			elseif ($notify_types == self::NOTIFY_TYPE_NOTHING)
144
-				continue;
138
+			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) {
139
+							continue;
140
+			}
141
+			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started']) {
142
+							continue;
143
+			} elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) {
144
+							continue;
145
+			} elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES) {
146
+							continue;
147
+			} elseif ($notify_types == self::NOTIFY_TYPE_NOTHING) {
148
+							continue;
149
+			}
145 150
 
146 151
 			// Don't send a notification if they don't want any...
147
-			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST)))
148
-				continue;
152
+			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST))) {
153
+							continue;
154
+			}
149 155
 			// ... or if we already sent one and they don't want more...
150
-			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent'])
151
-				continue;
156
+			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent']) {
157
+							continue;
158
+			}
152 159
 			// ... or if they aren't on the bouncer's list.
153
-			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))
154
-				continue;
160
+			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only'])) {
161
+							continue;
162
+			}
155 163
 
156 164
 			// Watched topic?
157 165
 			if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member]))
@@ -161,10 +169,12 @@  discard block
 block discarded – undo
161 169
 
162 170
 				if ($type == 'reply')
163 171
 				{
164
-					if (!empty($prefs[$member]['msg_receive_body']))
165
-						$message_type .= '_body';
166
-					if (!empty($frequency))
167
-						$message_type .= '_once';
172
+					if (!empty($prefs[$member]['msg_receive_body'])) {
173
+											$message_type .= '_body';
174
+					}
175
+					if (!empty($frequency)) {
176
+											$message_type .= '_once';
177
+					}
168 178
 				}
169 179
 
170 180
 				$content_type = 'topic';
@@ -177,12 +187,14 @@  discard block
 block discarded – undo
177 187
 				$content_type = 'board';
178 188
 
179 189
 				$message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards';
180
-				if (!empty($prefs[$member]['msg_receive_body']))
181
-					$message_type .= '_body';
190
+				if (!empty($prefs[$member]['msg_receive_body'])) {
191
+									$message_type .= '_body';
192
+				}
182 193
 			}
183 194
 			// If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip
184
-			else
185
-				continue;
195
+			else {
196
+							continue;
197
+			}
186 198
 
187 199
 			// Bitwise check: Receiving a email notification?
188 200
 			if ($pref & self::RECEIVE_NOTIFY_EMAIL)
@@ -199,8 +211,9 @@  discard block
 block discarded – undo
199 211
 				$mail_result = sendmail($data['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicOptions['id'], $emaildata['is_html']);
200 212
 
201 213
 				// We failed, don't trigger a alert as we don't have a way to attempt to resend just the email currently.
202
-				if ($mail_result === false)
203
-					continue;
214
+				if ($mail_result === false) {
215
+									continue;
216
+				}
204 217
 			}
205 218
 
206 219
 			// Bitwise check: Receiving a alert?
@@ -251,14 +264,15 @@  discard block
 block discarded – undo
251 264
 		);
252 265
 
253 266
 		// Insert the alerts if any
254
-		if (!empty($alert_rows))
255
-			$smcFunc['db_insert']('',
267
+		if (!empty($alert_rows)) {
268
+					$smcFunc['db_insert']('',
256 269
 				'{db_prefix}user_alerts',
257 270
 				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
258 271
 					'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
259 272
 				$alert_rows,
260 273
 				array()
261 274
 			);
275
+		}
262 276
 
263 277
 		return true;
264 278
 	}
@@ -269,8 +283,9 @@  discard block
 block discarded – undo
269 283
 
270 284
 		foreach ($quotedMembers as $id => $member)
271 285
 		{
272
-			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote']))
273
-				continue;
286
+			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) {
287
+							continue;
288
+			}
274 289
 
275 290
 			$done_members[] = $id;
276 291
 
@@ -324,32 +339,35 @@  discard block
 block discarded – undo
324 339
 		{
325 340
 			if (preg_match('/\[quote(.*)?\]/i', $block, $matches))
326 341
 			{
327
-				if ($quote_level == 0)
328
-					$message .= '[quote' . $matches[1] . ']';
342
+				if ($quote_level == 0) {
343
+									$message .= '[quote' . $matches[1] . ']';
344
+				}
329 345
 				$quote_level++;
330
-			}
331
-			elseif (preg_match('/\[\/quote\]/i', $block))
346
+			} elseif (preg_match('/\[\/quote\]/i', $block))
332 347
 			{
333
-				if ($quote_level <= 1)
334
-					$message .= '[/quote]';
348
+				if ($quote_level <= 1) {
349
+									$message .= '[/quote]';
350
+				}
335 351
 				if ($quote_level >= 1)
336 352
 				{
337 353
 					$quote_level--;
338 354
 					$message .= "\n";
339 355
 				}
356
+			} elseif ($quote_level <= 1) {
357
+							$message .= $block;
340 358
 			}
341
-			elseif ($quote_level <= 1)
342
-				$message .= $block;
343 359
 		}
344 360
 
345 361
 		preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches);
346 362
 
347 363
 		$id_msgs = $matches[1];
348
-		foreach ($id_msgs as $k => $id_msg)
349
-			$id_msgs[$k] = (int) $id_msg;
364
+		foreach ($id_msgs as $k => $id_msg) {
365
+					$id_msgs[$k] = (int) $id_msg;
366
+		}
350 367
 
351
-		if (empty($id_msgs))
352
-			return array();
368
+		if (empty($id_msgs)) {
369
+					return array();
370
+		}
353 371
 
354 372
 		// Get the messages
355 373
 		$request = $smcFunc['db_query']('', '
@@ -367,8 +385,9 @@  discard block
 block discarded – undo
367 385
 		$members = array();
368 386
 		while ($row = $smcFunc['db_fetch_assoc']($request))
369 387
 		{
370
-			if ($posterOptions['id'] == $row['id_member'])
371
-				continue;
388
+			if ($posterOptions['id'] == $row['id_member']) {
389
+							continue;
390
+			}
372 391
 
373 392
 			$members[$row['id_member']] = $row;
374 393
 		}
@@ -382,10 +401,11 @@  discard block
 block discarded – undo
382 401
 
383 402
 		foreach ($members as $id => $member)
384 403
 		{
385
-			if (!empty($prefs[$id]['msg_mention']))
386
-				$done_members[] = $id;
387
-			else
388
-				continue;
404
+			if (!empty($prefs[$id]['msg_mention'])) {
405
+							$done_members[] = $id;
406
+			} else {
407
+							continue;
408
+			}
389 409
 
390 410
 			// Alerts' emails are always instant
391 411
 			if ($prefs[$id]['msg_mention'] & self::RECEIVE_NOTIFY_EMAIL)
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +677 added lines, -523 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
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -60,12 +63,14 @@  discard block
 block discarded – undo
60 63
 	{
61 64
 		// Get ids of all the boards they can post in.
62 65
 		$post_permissions = array('post_new');
63
-		if ($modSettings['postmod_active'])
64
-			$post_permissions[] = 'post_unapproved_topics';
66
+		if ($modSettings['postmod_active']) {
67
+					$post_permissions[] = 'post_unapproved_topics';
68
+		}
65 69
 
66 70
 		$boards = boardsAllowedTo($post_permissions);
67
-		if (empty($boards))
68
-			fatal_lang_error('cannot_post_new', false);
71
+		if (empty($boards)) {
72
+					fatal_lang_error('cannot_post_new', false);
73
+		}
69 74
 
70 75
 		// Get a list of boards for the select menu
71 76
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -78,8 +83,9 @@  discard block
 block discarded – undo
78 83
 		$board_list = getBoardList($boardListOptions);
79 84
 	}
80 85
 	// Let's keep things simple for ourselves below
81
-	else
82
-		$boards = array($board);
86
+	else {
87
+			$boards = array($board);
88
+	}
83 89
 
84 90
 	require_once($sourcedir . '/Subs-Post.php');
85 91
 
@@ -102,10 +108,11 @@  discard block
 block discarded – undo
102 108
 			array(
103 109
 				'msg' => (int) $_REQUEST['msg'],
104 110
 		));
105
-		if ($smcFunc['db_num_rows']($request) != 1)
106
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
107
-		else
108
-			list ($topic) = $smcFunc['db_fetch_row']($request);
111
+		if ($smcFunc['db_num_rows']($request) != 1) {
112
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
113
+		} else {
114
+					list ($topic) = $smcFunc['db_fetch_row']($request);
115
+		}
109 116
 		$smcFunc['db_free_result']($request);
110 117
 	}
111 118
 
@@ -132,33 +139,36 @@  discard block
 block discarded – undo
132 139
 		$smcFunc['db_free_result']($request);
133 140
 
134 141
 		// If this topic already has a poll, they sure can't add another.
135
-		if (isset($_REQUEST['poll']) && $pollID > 0)
136
-			unset($_REQUEST['poll']);
142
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
143
+					unset($_REQUEST['poll']);
144
+		}
137 145
 
138 146
 		if (empty($_REQUEST['msg']))
139 147
 		{
140
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
141
-				is_not_guest();
148
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
149
+							is_not_guest();
150
+			}
142 151
 
143 152
 			// By default the reply will be approved...
144 153
 			$context['becomes_approved'] = true;
145 154
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
146 155
 			{
147
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
148
-					$context['becomes_approved'] = false;
149
-				else
150
-					isAllowedTo('post_reply_any');
151
-			}
152
-			elseif (!allowedTo('post_reply_any'))
156
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
157
+									$context['becomes_approved'] = false;
158
+				} else {
159
+									isAllowedTo('post_reply_any');
160
+				}
161
+			} elseif (!allowedTo('post_reply_any'))
153 162
 			{
154
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
155
-					$context['becomes_approved'] = false;
156
-				else
157
-					isAllowedTo('post_reply_own');
163
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
164
+									$context['becomes_approved'] = false;
165
+				} else {
166
+									isAllowedTo('post_reply_own');
167
+				}
158 168
 			}
169
+		} else {
170
+					$context['becomes_approved'] = true;
159 171
 		}
160
-		else
161
-			$context['becomes_approved'] = true;
162 172
 
163 173
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
164 174
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -173,17 +183,18 @@  discard block
 block discarded – undo
173 183
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
174 184
 
175 185
 		// Check whether this is a really old post being bumped...
176
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
177
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
178
-	}
179
-	else
186
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
187
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
188
+		}
189
+	} else
180 190
 	{
181 191
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
182 192
 		$context['becomes_approved'] = true;
183
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
184
-			$context['becomes_approved'] = false;
185
-		else
186
-			isAllowedTo('post_new', $boards, true);
193
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
194
+					$context['becomes_approved'] = false;
195
+		} else {
196
+					isAllowedTo('post_new', $boards, true);
197
+		}
187 198
 
188 199
 		$locked = 0;
189 200
 		$context['already_locked'] = 0;
@@ -213,27 +224,32 @@  discard block
 block discarded – undo
213 224
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
214 225
 	{
215 226
 		require_once($sourcedir . '/ManageAttachments.php');
216
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
217
-			removeAttachments(array('id_attach' => $attachID));
227
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
228
+					removeAttachments(array('id_attach' => $attachID));
229
+		}
218 230
 
219 231
 		unset($_SESSION['already_attached']);
220 232
 	}
221 233
 
222 234
 	// Don't allow a post if it's locked and you aren't all powerful.
223
-	if ($locked && !allowedTo('moderate_board'))
224
-		fatal_lang_error('topic_locked', false);
235
+	if ($locked && !allowedTo('moderate_board')) {
236
+			fatal_lang_error('topic_locked', false);
237
+	}
225 238
 	// Check the users permissions - is the user allowed to add or post a poll?
226 239
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
227 240
 	{
228 241
 		// New topic, new poll.
229
-		if (empty($topic))
230
-			isAllowedTo('poll_post');
242
+		if (empty($topic)) {
243
+					isAllowedTo('poll_post');
244
+		}
231 245
 		// This is an old topic - but it is yours!  Can you add to it?
232
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
233
-			isAllowedTo('poll_add_own');
246
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
247
+					isAllowedTo('poll_add_own');
248
+		}
234 249
 		// If you're not the owner, can you add to any poll?
235
-		else
236
-			isAllowedTo('poll_add_any');
250
+		else {
251
+					isAllowedTo('poll_add_any');
252
+		}
237 253
 
238 254
 		if (!empty($board))
239 255
 		{
@@ -242,8 +258,9 @@  discard block
 block discarded – undo
242 258
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
243 259
 		}
244 260
 		// No board, so we'll have to check this again in Post2
245
-		else
246
-			$guest_vote_enabled = true;
261
+		else {
262
+					$guest_vote_enabled = true;
263
+		}
247 264
 
248 265
 		// Set up the poll options.
249 266
 		$context['poll_options'] = array(
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 	if ($context['make_event'])
270 287
 	{
271 288
 		// They might want to pick a board.
272
-		if (!isset($context['current_board']))
273
-			$context['current_board'] = 0;
289
+		if (!isset($context['current_board'])) {
290
+					$context['current_board'] = 0;
291
+		}
274 292
 
275 293
 		// Start loading up the event info.
276 294
 		$context['event'] = array();
@@ -284,10 +302,11 @@  discard block
 block discarded – undo
284 302
 		isAllowedTo('calendar_post');
285 303
 
286 304
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
287
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
288
-			$time_string = '%k:%M';
289
-		else
290
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
305
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
306
+					$time_string = '%k:%M';
307
+		} else {
308
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
309
+		}
291 310
 
292 311
 		$js_time_string = str_replace(
293 312
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -309,8 +328,7 @@  discard block
 block discarded – undo
309 328
 			require_once($sourcedir . '/Subs-Calendar.php');
310 329
 			$eventProperties = getEventProperties($context['event']['id']);
311 330
 			$context['event'] = array_merge($context['event'], $eventProperties);
312
-		}
313
-		else
331
+		} else
314 332
 		{
315 333
 			// Get the current event information.
316 334
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -318,10 +336,12 @@  discard block
 block discarded – undo
318 336
 			$context['event'] = array_merge($context['event'], $eventProperties);
319 337
 
320 338
 			// Make sure the year and month are in the valid range.
321
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
322
-				fatal_lang_error('invalid_month', false);
323
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
324
-				fatal_lang_error('invalid_year', false);
339
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
340
+							fatal_lang_error('invalid_month', false);
341
+			}
342
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
343
+							fatal_lang_error('invalid_year', false);
344
+			}
325 345
 
326 346
 			$context['event']['categories'] = $board_list;
327 347
 		}
@@ -432,10 +452,11 @@  discard block
 block discarded – undo
432 452
 
433 453
 			if (!empty($context['new_replies']))
434 454
 			{
435
-				if ($context['new_replies'] == 1)
436
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
437
-				else
438
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
455
+				if ($context['new_replies'] == 1) {
456
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
457
+				} else {
458
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
459
+				}
439 460
 
440 461
 				$post_errors[] = 'new_replies';
441 462
 
@@ -447,9 +468,9 @@  discard block
 block discarded – undo
447 468
 	// Get a response prefix (like 'Re:') in the default forum language.
448 469
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
449 470
 	{
450
-		if ($language === $user_info['language'])
451
-			$context['response_prefix'] = $txt['response_prefix'];
452
-		else
471
+		if ($language === $user_info['language']) {
472
+					$context['response_prefix'] = $txt['response_prefix'];
473
+		} else
453 474
 		{
454 475
 			loadLanguage('index', $language, false);
455 476
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -462,23 +483,26 @@  discard block
 block discarded – undo
462 483
 	// Do we have a body, but an error happened.
463 484
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
464 485
 	{
465
-		if (isset($_REQUEST['quickReply']))
466
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		if (isset($_REQUEST['quickReply'])) {
487
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
488
+		}
467 489
 
468 490
 		// Validate inputs.
469 491
 		if (empty($context['post_error']))
470 492
 		{
471 493
 			// This means they didn't click Post and get an error.
472 494
 			$really_previewing = true;
473
-		}
474
-		else
495
+		} else
475 496
 		{
476
-			if (!isset($_REQUEST['subject']))
477
-				$_REQUEST['subject'] = '';
478
-			if (!isset($_REQUEST['message']))
479
-				$_REQUEST['message'] = '';
480
-			if (!isset($_REQUEST['icon']))
481
-				$_REQUEST['icon'] = 'xx';
497
+			if (!isset($_REQUEST['subject'])) {
498
+							$_REQUEST['subject'] = '';
499
+			}
500
+			if (!isset($_REQUEST['message'])) {
501
+							$_REQUEST['message'] = '';
502
+			}
503
+			if (!isset($_REQUEST['icon'])) {
504
+							$_REQUEST['icon'] = 'xx';
505
+			}
482 506
 
483 507
 			// They are previewing if they asked to preview (i.e. came from quick reply).
484 508
 			$really_previewing = !empty($_POST['preview']);
@@ -494,8 +518,9 @@  discard block
 block discarded – undo
494 518
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
495 519
 
496 520
 		// Make sure the subject isn't too long - taking into account special characters.
497
-		if ($smcFunc['strlen']($form_subject) > 100)
498
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		if ($smcFunc['strlen']($form_subject) > 100) {
522
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
523
+		}
499 524
 
500 525
 		if (isset($_REQUEST['poll']))
501 526
 		{
@@ -507,8 +532,9 @@  discard block
 block discarded – undo
507 532
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
508 533
 			foreach ($_POST['options'] as $option)
509 534
 			{
510
-				if (trim($option) == '')
511
-					continue;
535
+				if (trim($option) == '') {
536
+									continue;
537
+				}
512 538
 
513 539
 				$context['choices'][] = array(
514 540
 					'id' => $choice_id++,
@@ -570,13 +596,14 @@  discard block
 block discarded – undo
570 596
 				$context['preview_subject'] = $form_subject;
571 597
 
572 598
 				censorText($context['preview_subject']);
599
+			} else {
600
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
573 601
 			}
574
-			else
575
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
576 602
 
577 603
 			// Protect any CDATA blocks.
578
-			if (isset($_REQUEST['xml']))
579
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			if (isset($_REQUEST['xml'])) {
605
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
606
+			}
580 607
 		}
581 608
 
582 609
 		// Set up the checkboxes.
@@ -615,29 +642,32 @@  discard block
 block discarded – undo
615 642
 			);
616 643
 			// The message they were trying to edit was most likely deleted.
617 644
 			// @todo Change this error message?
618
-			if ($smcFunc['db_num_rows']($request) == 0)
619
-				fatal_lang_error('no_board', false);
645
+			if ($smcFunc['db_num_rows']($request) == 0) {
646
+							fatal_lang_error('no_board', false);
647
+			}
620 648
 			$row = $smcFunc['db_fetch_assoc']($request);
621 649
 
622 650
 			$attachment_stuff = array($row);
623
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
624
-				$attachment_stuff[] = $row2;
651
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
652
+							$attachment_stuff[] = $row2;
653
+			}
625 654
 			$smcFunc['db_free_result']($request);
626 655
 
627 656
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
628 657
 			{
629 658
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
630
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
631
-					fatal_lang_error('modify_post_time_passed', false);
632
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
633
-					isAllowedTo('modify_replies');
634
-				else
635
-					isAllowedTo('modify_own');
659
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
660
+									fatal_lang_error('modify_post_time_passed', false);
661
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
662
+									isAllowedTo('modify_replies');
663
+				} else {
664
+									isAllowedTo('modify_own');
665
+				}
666
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
667
+							isAllowedTo('modify_replies');
668
+			} else {
669
+							isAllowedTo('modify_any');
636 670
 			}
637
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
638
-				isAllowedTo('modify_replies');
639
-			else
640
-				isAllowedTo('modify_any');
641 671
 
642 672
 			if ($context['can_announce'] && !empty($row['id_action']))
643 673
 			{
@@ -661,8 +691,9 @@  discard block
 block discarded – undo
661 691
 
662 692
 				while ($row = $smcFunc['db_fetch_assoc']($request))
663 693
 				{
664
-					if ($row['filesize'] <= 0)
665
-						continue;
694
+					if ($row['filesize'] <= 0) {
695
+											continue;
696
+					}
666 697
 					$context['current_attachments'][$row['id_attach']] = array(
667 698
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
668 699
 						'size' => $row['filesize'],
@@ -732,29 +763,32 @@  discard block
 block discarded – undo
732 763
 			)
733 764
 		);
734 765
 		// The message they were trying to edit was most likely deleted.
735
-		if ($smcFunc['db_num_rows']($request) == 0)
736
-			fatal_lang_error('no_message', false);
766
+		if ($smcFunc['db_num_rows']($request) == 0) {
767
+					fatal_lang_error('no_message', false);
768
+		}
737 769
 		$row = $smcFunc['db_fetch_assoc']($request);
738 770
 
739 771
 		$attachment_stuff = array($row);
740
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
741
-			$attachment_stuff[] = $row2;
772
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
773
+					$attachment_stuff[] = $row2;
774
+		}
742 775
 		$smcFunc['db_free_result']($request);
743 776
 
744 777
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
745 778
 		{
746 779
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
747
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
748
-				fatal_lang_error('modify_post_time_passed', false);
749
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
750
-				isAllowedTo('modify_replies');
751
-			else
752
-				isAllowedTo('modify_own');
780
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
781
+							fatal_lang_error('modify_post_time_passed', false);
782
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
783
+							isAllowedTo('modify_replies');
784
+			} else {
785
+							isAllowedTo('modify_own');
786
+			}
787
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
788
+					isAllowedTo('modify_replies');
789
+		} else {
790
+					isAllowedTo('modify_any');
753 791
 		}
754
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
755
-			isAllowedTo('modify_replies');
756
-		else
757
-			isAllowedTo('modify_any');
758 792
 
759 793
 		if ($context['can_announce'] && !empty($row['id_action']))
760 794
 		{
@@ -781,15 +815,17 @@  discard block
 block discarded – undo
781 815
 		$context['icon'] = $row['icon'];
782 816
 
783 817
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
784
-		if (!$row['approved'] && !$context['show_approval'])
785
-			$context['show_approval'] = allowedTo('approve_posts');
818
+		if (!$row['approved'] && !$context['show_approval']) {
819
+					$context['show_approval'] = allowedTo('approve_posts');
820
+		}
786 821
 
787 822
 		// Sort the attachments so they are in the order saved
788 823
 		$temp = array();
789 824
 		foreach ($attachment_stuff as $attachment)
790 825
 		{
791
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
792
-				$temp[$attachment['id_attach']] = $attachment;
826
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
827
+							$temp[$attachment['id_attach']] = $attachment;
828
+			}
793 829
 		}
794 830
 		ksort($temp);
795 831
 
@@ -850,14 +886,16 @@  discard block
 block discarded – undo
850 886
 					'is_approved' => 1,
851 887
 				)
852 888
 			);
853
-			if ($smcFunc['db_num_rows']($request) == 0)
854
-				fatal_lang_error('quoted_post_deleted', false);
889
+			if ($smcFunc['db_num_rows']($request) == 0) {
890
+							fatal_lang_error('quoted_post_deleted', false);
891
+			}
855 892
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
856 893
 			$smcFunc['db_free_result']($request);
857 894
 
858 895
 			// Add 'Re: ' to the front of the quoted subject.
859
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
860
-				$form_subject = $context['response_prefix'] . $form_subject;
896
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
897
+							$form_subject = $context['response_prefix'] . $form_subject;
898
+			}
861 899
 
862 900
 			// Censor the message and subject.
863 901
 			censorText($form_message);
@@ -870,10 +908,11 @@  discard block
 block discarded – undo
870 908
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
871 909
 				{
872 910
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
873
-					if ($i % 4 == 0)
874
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
911
+					if ($i % 4 == 0) {
912
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
875 913
 						{
876 914
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
915
+					}
877 916
 						}, $parts[$i]);
878 917
 				}
879 918
 				$form_message = implode('', $parts);
@@ -882,8 +921,9 @@  discard block
 block discarded – undo
882 921
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
883 922
 
884 923
 			// Remove any nested quotes, if necessary.
885
-			if (!empty($modSettings['removeNestedQuotes']))
886
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
924
+			if (!empty($modSettings['removeNestedQuotes'])) {
925
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
926
+			}
887 927
 
888 928
 			// Add a quote string on the front and end.
889 929
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -895,15 +935,15 @@  discard block
 block discarded – undo
895 935
 			$form_subject = $first_subject;
896 936
 
897 937
 			// Add 'Re: ' to the front of the subject.
898
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
899
-				$form_subject = $context['response_prefix'] . $form_subject;
938
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
939
+							$form_subject = $context['response_prefix'] . $form_subject;
940
+			}
900 941
 
901 942
 			// Censor the subject.
902 943
 			censorText($form_subject);
903 944
 
904 945
 			$form_message = '';
905
-		}
906
-		else
946
+		} else
907 947
 		{
908 948
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
909 949
 			$form_message = '';
@@ -922,13 +962,15 @@  discard block
 block discarded – undo
922 962
 		if (isset($_REQUEST['msg']))
923 963
 		{
924 964
 			$context['attachments']['quantity'] = count($context['current_attachments']);
925
-			foreach ($context['current_attachments'] as $attachment)
926
-				$context['attachments']['total_size'] += $attachment['size'];
965
+			foreach ($context['current_attachments'] as $attachment) {
966
+							$context['attachments']['total_size'] += $attachment['size'];
967
+			}
927 968
 		}
928 969
 
929 970
 		// A bit of house keeping first.
930
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
931
-			unset($_SESSION['temp_attachments']);
971
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
972
+					unset($_SESSION['temp_attachments']);
973
+		}
932 974
 
933 975
 		if (!empty($_SESSION['temp_attachments']))
934 976
 		{
@@ -937,9 +979,10 @@  discard block
 block discarded – undo
937 979
 			{
938 980
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
939 981
 				{
940
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
941
-						if (file_exists($attachment['tmp_name']))
982
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
983
+											if (file_exists($attachment['tmp_name']))
942 984
 							unlink($attachment['tmp_name']);
985
+					}
943 986
 				}
944 987
 				$post_errors[] = 'temp_attachments_gone';
945 988
 				$_SESSION['temp_attachments'] = array();
@@ -953,8 +996,9 @@  discard block
 block discarded – undo
953 996
 					// See if any files still exist before showing the warning message and the files attached.
954 997
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
955 998
 					{
956
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
957
-							continue;
999
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1000
+													continue;
1001
+						}
958 1002
 
959 1003
 						if (file_exists($attachment['tmp_name']))
960 1004
 						{
@@ -964,20 +1008,21 @@  discard block
 block discarded – undo
964 1008
 							break;
965 1009
 						}
966 1010
 					}
967
-				}
968
-				else
1011
+				} else
969 1012
 				{
970 1013
 					// Since, they don't belong here. Let's inform the user that they exist..
971
-					if (!empty($topic))
972
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
973
-					else
974
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1014
+					if (!empty($topic)) {
1015
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1016
+					} else {
1017
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1018
+					}
975 1019
 
976 1020
 					// Compile a list of the files to show the user.
977 1021
 					$file_list = array();
978
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
979
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1022
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1023
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
980 1024
 							$file_list[] = $attachment['name'];
1025
+					}
981 1026
 
982 1027
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
983 1028
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -989,8 +1034,7 @@  discard block
 block discarded – undo
989 1034
 
990 1035
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
991 1036
 						$context['ignore_temp_attachments'] = true;
992
-					}
993
-					else
1037
+					} else
994 1038
 					{
995 1039
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
996 1040
 						$context['ignore_temp_attachments'] = true;
@@ -998,16 +1042,19 @@  discard block
 block discarded – undo
998 1042
 				}
999 1043
 			}
1000 1044
 
1001
-			if (!empty($context['we_are_history']))
1002
-				$post_errors[] = $context['we_are_history'];
1045
+			if (!empty($context['we_are_history'])) {
1046
+							$post_errors[] = $context['we_are_history'];
1047
+			}
1003 1048
 
1004 1049
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1005 1050
 			{
1006
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1007
-					break;
1051
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1052
+									break;
1053
+				}
1008 1054
 
1009
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1010
-					continue;
1055
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1056
+									continue;
1057
+				}
1011 1058
 
1012 1059
 				if ($attachID == 'initial_error')
1013 1060
 				{
@@ -1022,15 +1069,17 @@  discard block
 block discarded – undo
1022 1069
 				{
1023 1070
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1024 1071
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1025
-					foreach ($attachment['errors'] as $error)
1026
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1072
+					foreach ($attachment['errors'] as $error) {
1073
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1074
+					}
1027 1075
 					$txt['error_attach_errors'] .= '</div>';
1028 1076
 					$post_errors[] = 'attach_errors';
1029 1077
 
1030 1078
 					// Take out the trash.
1031 1079
 					unset($_SESSION['temp_attachments'][$attachID]);
1032
-					if (file_exists($attachment['tmp_name']))
1033
-						unlink($attachment['tmp_name']);
1080
+					if (file_exists($attachment['tmp_name'])) {
1081
+											unlink($attachment['tmp_name']);
1082
+					}
1034 1083
 					continue;
1035 1084
 				}
1036 1085
 
@@ -1043,8 +1092,9 @@  discard block
 block discarded – undo
1043 1092
 
1044 1093
 				$context['attachments']['quantity']++;
1045 1094
 				$context['attachments']['total_size'] += $attachment['size'];
1046
-				if (!isset($context['files_in_session_warning']))
1047
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1095
+				if (!isset($context['files_in_session_warning'])) {
1096
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1097
+				}
1048 1098
 
1049 1099
 				$context['current_attachments'][$attachID] = array(
1050 1100
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1072,8 +1122,9 @@  discard block
 block discarded – undo
1072 1122
 	}
1073 1123
 
1074 1124
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1075
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1076
-		$post_errors[] = 'need_qr_verification';
1125
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1126
+			$post_errors[] = 'need_qr_verification';
1127
+	}
1077 1128
 
1078 1129
 	/*
1079 1130
 	 * There are two error types: serious and minor. Serious errors
@@ -1090,52 +1141,56 @@  discard block
 block discarded – undo
1090 1141
 	{
1091 1142
 		loadLanguage('Errors');
1092 1143
 		$context['error_type'] = 'minor';
1093
-		foreach ($post_errors as $post_error)
1094
-			if (is_array($post_error))
1144
+		foreach ($post_errors as $post_error) {
1145
+					if (is_array($post_error))
1095 1146
 			{
1096 1147
 				$post_error_id = $post_error[0];
1148
+		}
1097 1149
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1098 1150
 
1099 1151
 				// If it's not a minor error flag it as such.
1100
-				if (!in_array($post_error_id, $minor_errors))
1101
-					$context['error_type'] = 'serious';
1102
-			}
1103
-			else
1152
+				if (!in_array($post_error_id, $minor_errors)) {
1153
+									$context['error_type'] = 'serious';
1154
+				}
1155
+			} else
1104 1156
 			{
1105 1157
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1106 1158
 
1107 1159
 				// If it's not a minor error flag it as such.
1108
-				if (!in_array($post_error, $minor_errors))
1109
-					$context['error_type'] = 'serious';
1160
+				if (!in_array($post_error, $minor_errors)) {
1161
+									$context['error_type'] = 'serious';
1162
+				}
1110 1163
 			}
1111 1164
 	}
1112 1165
 
1113 1166
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1114
-	if (isset($_REQUEST['poll']))
1115
-		$context['page_title'] = $txt['new_poll'];
1116
-	elseif ($context['make_event'])
1117
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1118
-	elseif (isset($_REQUEST['msg']))
1119
-		$context['page_title'] = $txt['modify_msg'];
1120
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1121
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1122
-	elseif (empty($topic))
1123
-		$context['page_title'] = $txt['start_new_topic'];
1124
-	else
1125
-		$context['page_title'] = $txt['post_reply'];
1167
+	if (isset($_REQUEST['poll'])) {
1168
+			$context['page_title'] = $txt['new_poll'];
1169
+	} elseif ($context['make_event']) {
1170
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1171
+	} elseif (isset($_REQUEST['msg'])) {
1172
+			$context['page_title'] = $txt['modify_msg'];
1173
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1174
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1175
+	} elseif (empty($topic)) {
1176
+			$context['page_title'] = $txt['start_new_topic'];
1177
+	} else {
1178
+			$context['page_title'] = $txt['post_reply'];
1179
+	}
1126 1180
 
1127 1181
 	// Build the link tree.
1128
-	if (empty($topic))
1129
-		$context['linktree'][] = array(
1182
+	if (empty($topic)) {
1183
+			$context['linktree'][] = array(
1130 1184
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1131 1185
 		);
1132
-	else
1133
-		$context['linktree'][] = array(
1186
+	} else {
1187
+			$context['linktree'][] = array(
1134 1188
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1135 1189
 			'name' => $form_subject,
1136 1190
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1137 1191
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1138 1192
 		);
1193
+	}
1139 1194
 
1140 1195
 	$context['subject'] = addcslashes($form_subject, '"');
1141 1196
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1179,8 +1234,9 @@  discard block
 block discarded – undo
1179 1234
 	// Message icons - customized icons are off?
1180 1235
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1181 1236
 
1182
-	if (!empty($context['icons']))
1183
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1237
+	if (!empty($context['icons'])) {
1238
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1239
+	}
1184 1240
 
1185 1241
 	// Are we starting a poll? if set the poll icon as selected if its available
1186 1242
 	if (isset($_REQUEST['poll']))
@@ -1200,8 +1256,9 @@  discard block
 block discarded – undo
1200 1256
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1201 1257
 	{
1202 1258
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1203
-		if ($context['icons'][$i]['selected'])
1204
-			$context['icon_url'] = $context['icons'][$i]['url'];
1259
+		if ($context['icons'][$i]['selected']) {
1260
+					$context['icon_url'] = $context['icons'][$i]['url'];
1261
+		}
1205 1262
 	}
1206 1263
 	if (empty($context['icon_url']))
1207 1264
 	{
@@ -1215,8 +1272,9 @@  discard block
 block discarded – undo
1215 1272
 		));
1216 1273
 	}
1217 1274
 
1218
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1219
-		getTopic();
1275
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1276
+			getTopic();
1277
+	}
1220 1278
 
1221 1279
 	// If the user can post attachments prepare the warning labels.
1222 1280
 	if ($context['can_post_attachment'])
@@ -1227,12 +1285,13 @@  discard block
 block discarded – undo
1227 1285
 		$context['attachment_restrictions'] = array();
1228 1286
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1229 1287
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1230
-		foreach ($attachmentRestrictionTypes as $type)
1231
-			if (!empty($modSettings[$type]))
1288
+		foreach ($attachmentRestrictionTypes as $type) {
1289
+					if (!empty($modSettings[$type]))
1232 1290
 			{
1233 1291
 				// Show the max number of attachments if not 0.
1234 1292
 				if ($type == 'attachmentNumPerPostLimit')
1235 1293
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1294
+		}
1236 1295
 			}
1237 1296
 	}
1238 1297
 
@@ -1266,8 +1325,8 @@  discard block
 block discarded – undo
1266 1325
 
1267 1326
 	if (!empty($context['current_attachments']))
1268 1327
 	{
1269
-		foreach ($context['current_attachments'] as $key => $mock)
1270
-			addInlineJavaScript('
1328
+		foreach ($context['current_attachments'] as $key => $mock) {
1329
+					addInlineJavaScript('
1271 1330
 	current_attachments.push({
1272 1331
 		name: '. JavaScriptEscape($mock['name']) . ',
1273 1332
 		size: '. $mock['size'] . ',
@@ -1276,6 +1335,7 @@  discard block
 block discarded – undo
1276 1335
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1277 1336
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1278 1337
 	});');
1338
+		}
1279 1339
 	}
1280 1340
 
1281 1341
 	// File Upload.
@@ -1374,12 +1434,13 @@  discard block
 block discarded – undo
1374 1434
 		{
1375 1435
 			$context['posting_fields']['board']['input']['options'][$category['name']] = array('options' => array());
1376 1436
 
1377
-			foreach ($category['boards'] as $brd)
1378
-				$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1437
+			foreach ($category['boards'] as $brd) {
1438
+							$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1379 1439
 					'value' => $brd['id'],
1380 1440
 					'selected' => (bool) $brd['selected'],
1381 1441
 					'label' => ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'],
1382 1442
 				);
1443
+			}
1383 1444
 		}
1384 1445
 	}
1385 1446
 
@@ -1425,8 +1486,9 @@  discard block
 block discarded – undo
1425 1486
 
1426 1487
 
1427 1488
 	// Finally, load the template.
1428
-	if (!isset($_REQUEST['xml']))
1429
-		loadTemplate('Post');
1489
+	if (!isset($_REQUEST['xml'])) {
1490
+			loadTemplate('Post');
1491
+	}
1430 1492
 
1431 1493
 	call_integration_hook('integrate_post_end');
1432 1494
 }
@@ -1447,13 +1509,14 @@  discard block
 block discarded – undo
1447 1509
 	// Sneaking off, are we?
1448 1510
 	if (empty($_POST) && empty($topic))
1449 1511
 	{
1450
-		if (empty($_SERVER['CONTENT_LENGTH']))
1451
-			redirectexit('action=post;board=' . $board . '.0');
1452
-		else
1453
-			fatal_lang_error('post_upload_error', false);
1512
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1513
+					redirectexit('action=post;board=' . $board . '.0');
1514
+		} else {
1515
+					fatal_lang_error('post_upload_error', false);
1516
+		}
1517
+	} elseif (empty($_POST) && !empty($topic)) {
1518
+			redirectexit('action=post;topic=' . $topic . '.0');
1454 1519
 	}
1455
-	elseif (empty($_POST) && !empty($topic))
1456
-		redirectexit('action=post;topic=' . $topic . '.0');
1457 1520
 
1458 1521
 	// No need!
1459 1522
 	$context['robot_no_index'] = true;
@@ -1465,8 +1528,9 @@  discard block
 block discarded – undo
1465 1528
 	$post_errors = array();
1466 1529
 
1467 1530
 	// If the session has timed out, let the user re-submit their form.
1468
-	if (checkSession('post', '', false) != '')
1469
-		$post_errors[] = 'session_timeout';
1531
+	if (checkSession('post', '', false) != '') {
1532
+			$post_errors[] = 'session_timeout';
1533
+	}
1470 1534
 
1471 1535
 	// Wrong verification code?
1472 1536
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1476,8 +1540,9 @@  discard block
 block discarded – undo
1476 1540
 			'id' => 'post',
1477 1541
 		);
1478 1542
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1479
-		if (is_array($context['require_verification']))
1480
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1543
+		if (is_array($context['require_verification'])) {
1544
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1545
+		}
1481 1546
 	}
1482 1547
 
1483 1548
 	require_once($sourcedir . '/Subs-Post.php');
@@ -1486,25 +1551,29 @@  discard block
 block discarded – undo
1486 1551
 	call_integration_hook('integrate_post2_start');
1487 1552
 
1488 1553
 	// Drafts enabled and needed?
1489
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1490
-		require_once($sourcedir . '/Drafts.php');
1554
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1555
+			require_once($sourcedir . '/Drafts.php');
1556
+	}
1491 1557
 
1492 1558
 	// First check to see if they are trying to delete any current attachments.
1493 1559
 	if (isset($_POST['attach_del']))
1494 1560
 	{
1495 1561
 		$keep_temp = array();
1496 1562
 		$keep_ids = array();
1497
-		foreach ($_POST['attach_del'] as $dummy)
1498
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1563
+		foreach ($_POST['attach_del'] as $dummy) {
1564
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1499 1565
 				$keep_temp[] = $dummy;
1500
-			else
1501
-				$keep_ids[] = (int) $dummy;
1566
+		}
1567
+			else {
1568
+							$keep_ids[] = (int) $dummy;
1569
+			}
1502 1570
 
1503
-		if (isset($_SESSION['temp_attachments']))
1504
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1571
+		if (isset($_SESSION['temp_attachments'])) {
1572
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1505 1573
 			{
1506 1574
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1507 1575
 					continue;
1576
+		}
1508 1577
 
1509 1578
 				unset($_SESSION['temp_attachments'][$attachID]);
1510 1579
 				unlink($attachment['tmp_name']);
@@ -1536,8 +1605,9 @@  discard block
 block discarded – undo
1536 1605
 	{
1537 1606
 		require_once($sourcedir . '/ManageAttachments.php');
1538 1607
 
1539
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1540
-			removeAttachments(array('id_attach' => $attachID));
1608
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1609
+					removeAttachments(array('id_attach' => $attachID));
1610
+		}
1541 1611
 
1542 1612
 		unset($_SESSION['already_attached']);
1543 1613
 
@@ -1560,12 +1630,14 @@  discard block
 block discarded – undo
1560 1630
 		$smcFunc['db_free_result']($request);
1561 1631
 
1562 1632
 		// Though the topic should be there, it might have vanished.
1563
-		if (!is_array($topic_info))
1564
-			fatal_lang_error('topic_doesnt_exist', 404);
1633
+		if (!is_array($topic_info)) {
1634
+					fatal_lang_error('topic_doesnt_exist', 404);
1635
+		}
1565 1636
 
1566 1637
 		// Did this topic suddenly move? Just checking...
1567
-		if ($topic_info['id_board'] != $board)
1568
-			fatal_lang_error('not_a_topic');
1638
+		if ($topic_info['id_board'] != $board) {
1639
+					fatal_lang_error('not_a_topic');
1640
+		}
1569 1641
 
1570 1642
 		// Do the permissions and approval stuff...
1571 1643
 		$becomesApproved = true;
@@ -1588,49 +1660,50 @@  discard block
 block discarded – undo
1588 1660
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1589 1661
 	{
1590 1662
 		// Don't allow a post if it's locked.
1591
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1592
-			fatal_lang_error('topic_locked', false);
1663
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1664
+					fatal_lang_error('topic_locked', false);
1665
+		}
1593 1666
 
1594 1667
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1595
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1596
-			unset($_REQUEST['poll']);
1597
-
1598
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1599
-		{
1600
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1601
-				$becomesApproved = false;
1602
-
1603
-			else
1604
-				isAllowedTo('post_reply_any');
1605
-		}
1606
-		elseif (!allowedTo('post_reply_any'))
1668
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1669
+					unset($_REQUEST['poll']);
1670
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1671
+		{
1672
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1673
+							$becomesApproved = false;
1674
+			} else {
1675
+							isAllowedTo('post_reply_any');
1676
+			}
1677
+		} elseif (!allowedTo('post_reply_any'))
1607 1678
 		{
1608
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1609
-				$becomesApproved = false;
1610
-
1611
-			else
1612
-				isAllowedTo('post_reply_own');
1679
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1680
+							$becomesApproved = false;
1681
+			} else {
1682
+							isAllowedTo('post_reply_own');
1683
+			}
1613 1684
 		}
1614 1685
 
1615 1686
 		if (isset($_POST['lock']))
1616 1687
 		{
1617 1688
 			// Nothing is changed to the lock.
1618
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1619
-				unset($_POST['lock']);
1689
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1690
+							unset($_POST['lock']);
1691
+			}
1620 1692
 
1621 1693
 			// You're have no permission to lock this topic.
1622
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1623
-				unset($_POST['lock']);
1694
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1695
+							unset($_POST['lock']);
1696
+			}
1624 1697
 
1625 1698
 			// You are allowed to (un)lock your own topic only.
1626 1699
 			elseif (!allowedTo('lock_any'))
1627 1700
 			{
1628 1701
 				// You cannot override a moderator lock.
1629
-				if ($topic_info['locked'] == 1)
1630
-					unset($_POST['lock']);
1631
-
1632
-				else
1633
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1702
+				if ($topic_info['locked'] == 1) {
1703
+									unset($_POST['lock']);
1704
+				} else {
1705
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1706
+				}
1634 1707
 			}
1635 1708
 			// Hail mighty moderator, (un)lock this topic immediately.
1636 1709
 			else
@@ -1638,19 +1711,21 @@  discard block
 block discarded – undo
1638 1711
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1639 1712
 
1640 1713
 				// Did someone (un)lock this while you were posting?
1641
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1642
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1714
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1715
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1716
+				}
1643 1717
 			}
1644 1718
 		}
1645 1719
 
1646 1720
 		// So you wanna (un)sticky this...let's see.
1647
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1648
-			unset($_POST['sticky']);
1649
-		elseif (isset($_POST['sticky']))
1721
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1722
+					unset($_POST['sticky']);
1723
+		} elseif (isset($_POST['sticky']))
1650 1724
 		{
1651 1725
 			// Did someone (un)sticky this while you were posting?
1652
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1653
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1726
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1727
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1728
+			}
1654 1729
 		}
1655 1730
 
1656 1731
 		// If drafts are enabled, then pass this off
@@ -1677,26 +1752,31 @@  discard block
 block discarded – undo
1677 1752
 
1678 1753
 		// Do like, the permissions, for safety and stuff...
1679 1754
 		$becomesApproved = true;
1680
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1681
-			$becomesApproved = false;
1682
-		else
1683
-			isAllowedTo('post_new');
1755
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1756
+					$becomesApproved = false;
1757
+		} else {
1758
+					isAllowedTo('post_new');
1759
+		}
1684 1760
 
1685 1761
 		if (isset($_POST['lock']))
1686 1762
 		{
1687 1763
 			// New topics are by default not locked.
1688
-			if (empty($_POST['lock']))
1689
-				unset($_POST['lock']);
1764
+			if (empty($_POST['lock'])) {
1765
+							unset($_POST['lock']);
1766
+			}
1690 1767
 			// Besides, you need permission.
1691
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1692
-				unset($_POST['lock']);
1768
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1769
+							unset($_POST['lock']);
1770
+			}
1693 1771
 			// A moderator-lock (1) can override a user-lock (2).
1694
-			else
1695
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1772
+			else {
1773
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1774
+			}
1696 1775
 		}
1697 1776
 
1698
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1699
-			unset($_POST['sticky']);
1777
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1778
+					unset($_POST['sticky']);
1779
+		}
1700 1780
 
1701 1781
 		// Saving your new topic as a draft first?
1702 1782
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1721,31 +1801,37 @@  discard block
 block discarded – undo
1721 1801
 				'id_msg' => $_REQUEST['msg'],
1722 1802
 			)
1723 1803
 		);
1724
-		if ($smcFunc['db_num_rows']($request) == 0)
1725
-			fatal_lang_error('cant_find_messages', false);
1804
+		if ($smcFunc['db_num_rows']($request) == 0) {
1805
+					fatal_lang_error('cant_find_messages', false);
1806
+		}
1726 1807
 		$row = $smcFunc['db_fetch_assoc']($request);
1727 1808
 		$smcFunc['db_free_result']($request);
1728 1809
 
1729
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1730
-			fatal_lang_error('topic_locked', false);
1810
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1811
+					fatal_lang_error('topic_locked', false);
1812
+		}
1731 1813
 
1732 1814
 		if (isset($_POST['lock']))
1733 1815
 		{
1734 1816
 			// Nothing changes to the lock status.
1735
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1736
-				unset($_POST['lock']);
1817
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1818
+							unset($_POST['lock']);
1819
+			}
1737 1820
 			// You're simply not allowed to (un)lock this.
1738
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1739
-				unset($_POST['lock']);
1821
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1822
+							unset($_POST['lock']);
1823
+			}
1740 1824
 			// You're only allowed to lock your own topics.
1741 1825
 			elseif (!allowedTo('lock_any'))
1742 1826
 			{
1743 1827
 				// You're not allowed to break a moderator's lock.
1744
-				if ($topic_info['locked'] == 1)
1745
-					unset($_POST['lock']);
1828
+				if ($topic_info['locked'] == 1) {
1829
+									unset($_POST['lock']);
1830
+				}
1746 1831
 				// Lock it with a soft lock or unlock it.
1747
-				else
1748
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1832
+				else {
1833
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1834
+				}
1749 1835
 			}
1750 1836
 			// You must be the moderator.
1751 1837
 			else
@@ -1753,44 +1839,46 @@  discard block
 block discarded – undo
1753 1839
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1754 1840
 
1755 1841
 				// Did someone (un)lock this while you were posting?
1756
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1757
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1842
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1843
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1844
+				}
1758 1845
 			}
1759 1846
 		}
1760 1847
 
1761 1848
 		// Change the sticky status of this topic?
1762
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1763
-			unset($_POST['sticky']);
1764
-		elseif (isset($_POST['sticky']))
1849
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1850
+					unset($_POST['sticky']);
1851
+		} elseif (isset($_POST['sticky']))
1765 1852
 		{
1766 1853
 			// Did someone (un)sticky this while you were posting?
1767
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1768
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1854
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1855
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1856
+			}
1769 1857
 		}
1770 1858
 
1771 1859
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1772 1860
 		{
1773
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1774
-				fatal_lang_error('modify_post_time_passed', false);
1775
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1776
-				isAllowedTo('modify_replies');
1777
-			else
1778
-				isAllowedTo('modify_own');
1779
-		}
1780
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1861
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1862
+							fatal_lang_error('modify_post_time_passed', false);
1863
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1864
+							isAllowedTo('modify_replies');
1865
+			} else {
1866
+							isAllowedTo('modify_own');
1867
+			}
1868
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1781 1869
 		{
1782 1870
 			isAllowedTo('modify_replies');
1783 1871
 
1784 1872
 			// If you're modifying a reply, I say it better be logged...
1785 1873
 			$moderationAction = true;
1786
-		}
1787
-		else
1874
+		} else
1788 1875
 		{
1789 1876
 			isAllowedTo('modify_any');
1790 1877
 
1791 1878
 			// Log it, assuming you're not modifying your own post.
1792
-			if ($row['id_member'] != $user_info['id'])
1793
-				$moderationAction = true;
1879
+			if ($row['id_member'] != $user_info['id']) {
1880
+							$moderationAction = true;
1881
+			}
1794 1882
 		}
1795 1883
 
1796 1884
 		// If drafts are enabled, then lets send this off to save
@@ -1817,8 +1905,9 @@  discard block
 block discarded – undo
1817 1905
 		// Update search api
1818 1906
 		require_once($sourcedir . '/Search.php');
1819 1907
 		$searchAPI = findSearchAPI();
1820
-		if ($searchAPI->supportsMethod('postRemoved'))
1821
-			$searchAPI->postRemoved($_REQUEST['msg']);
1908
+		if ($searchAPI->supportsMethod('postRemoved')) {
1909
+					$searchAPI->postRemoved($_REQUEST['msg']);
1910
+		}
1822 1911
 
1823 1912
 	}
1824 1913
 
@@ -1836,20 +1925,24 @@  discard block
 block discarded – undo
1836 1925
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1837 1926
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1838 1927
 
1839
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1840
-			$post_errors[] = 'no_name';
1841
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1842
-			$post_errors[] = 'long_name';
1928
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1929
+					$post_errors[] = 'no_name';
1930
+		}
1931
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1932
+					$post_errors[] = 'long_name';
1933
+		}
1843 1934
 
1844 1935
 		if (empty($modSettings['guest_post_no_email']))
1845 1936
 		{
1846 1937
 			// Only check if they changed it!
1847 1938
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1848 1939
 			{
1849
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1850
-					$post_errors[] = 'no_email';
1851
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1852
-					$post_errors[] = 'bad_email';
1940
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1941
+									$post_errors[] = 'no_email';
1942
+				}
1943
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1944
+									$post_errors[] = 'bad_email';
1945
+				}
1853 1946
 			}
1854 1947
 
1855 1948
 			// Now make sure this email address is not banned from posting.
@@ -1865,76 +1958,90 @@  discard block
 block discarded – undo
1865 1958
 	}
1866 1959
 
1867 1960
 	// Coming from the quickReply?
1868
-	if (isset($_POST['quickReply']))
1869
-		$_POST['message'] = $_POST['quickReply'];
1961
+	if (isset($_POST['quickReply'])) {
1962
+			$_POST['message'] = $_POST['quickReply'];
1963
+	}
1870 1964
 
1871 1965
 	// Check the subject and message.
1872
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1873
-		$post_errors[] = 'no_subject';
1874
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1875
-		$post_errors[] = 'no_message';
1876
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1877
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1878
-	else
1966
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1967
+			$post_errors[] = 'no_subject';
1968
+	}
1969
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1970
+			$post_errors[] = 'no_message';
1971
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1972
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1973
+	} else
1879 1974
 	{
1880 1975
 		// Prepare the message a bit for some additional testing.
1881 1976
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1882 1977
 
1883 1978
 		// Preparse code. (Zef)
1884
-		if ($user_info['is_guest'])
1885
-			$user_info['name'] = $_POST['guestname'];
1979
+		if ($user_info['is_guest']) {
1980
+					$user_info['name'] = $_POST['guestname'];
1981
+		}
1886 1982
 		preparsecode($_POST['message']);
1887 1983
 
1888 1984
 		// Let's see if there's still some content left without the tags.
1889
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1890
-			$post_errors[] = 'no_message';
1985
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1986
+					$post_errors[] = 'no_message';
1987
+		}
1891 1988
 
1892 1989
 	}
1893
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1894
-		$post_errors[] = 'no_event';
1990
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1991
+			$post_errors[] = 'no_event';
1992
+	}
1895 1993
 	// You are not!
1896
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1897
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1994
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1995
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1996
+	}
1898 1997
 
1899 1998
 	// Validate the poll...
1900 1999
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1901 2000
 	{
1902
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1903
-			fatal_lang_error('no_access', false);
2001
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
2002
+					fatal_lang_error('no_access', false);
2003
+		}
1904 2004
 
1905 2005
 		// This is a new topic... so it's a new poll.
1906
-		if (empty($topic))
1907
-			isAllowedTo('poll_post');
2006
+		if (empty($topic)) {
2007
+					isAllowedTo('poll_post');
2008
+		}
1908 2009
 		// Can you add to your own topics?
1909
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1910
-			isAllowedTo('poll_add_own');
2010
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
2011
+					isAllowedTo('poll_add_own');
2012
+		}
1911 2013
 		// Can you add polls to any topic, then?
1912
-		else
1913
-			isAllowedTo('poll_add_any');
2014
+		else {
2015
+					isAllowedTo('poll_add_any');
2016
+		}
1914 2017
 
1915
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1916
-			$post_errors[] = 'no_question';
2018
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
2019
+					$post_errors[] = 'no_question';
2020
+		}
1917 2021
 
1918 2022
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1919 2023
 
1920 2024
 		// Get rid of empty ones.
1921
-		foreach ($_POST['options'] as $k => $option)
1922
-			if ($option == '')
2025
+		foreach ($_POST['options'] as $k => $option) {
2026
+					if ($option == '')
1923 2027
 				unset($_POST['options'][$k], $_POST['options'][$k]);
2028
+		}
1924 2029
 
1925 2030
 		// What are you going to vote between with one choice?!?
1926
-		if (count($_POST['options']) < 2)
1927
-			$post_errors[] = 'poll_few';
1928
-		elseif (count($_POST['options']) > 256)
1929
-			$post_errors[] = 'poll_many';
2031
+		if (count($_POST['options']) < 2) {
2032
+					$post_errors[] = 'poll_few';
2033
+		} elseif (count($_POST['options']) > 256) {
2034
+					$post_errors[] = 'poll_many';
2035
+		}
1930 2036
 	}
1931 2037
 
1932 2038
 	if ($posterIsGuest)
1933 2039
 	{
1934 2040
 		// If user is a guest, make sure the chosen name isn't taken.
1935 2041
 		require_once($sourcedir . '/Subs-Members.php');
1936
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1937
-			$post_errors[] = 'bad_name';
2042
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
2043
+					$post_errors[] = 'bad_name';
2044
+		}
1938 2045
 	}
1939 2046
 	// If the user isn't a guest, get his or her name and email.
1940 2047
 	elseif (!isset($_REQUEST['msg']))
@@ -1965,8 +2072,9 @@  discard block
 block discarded – undo
1965 2072
 	}
1966 2073
 
1967 2074
 	// Make sure the user isn't spamming the board.
1968
-	if (!isset($_REQUEST['msg']))
1969
-		spamProtection('post');
2075
+	if (!isset($_REQUEST['msg'])) {
2076
+			spamProtection('post');
2077
+	}
1970 2078
 
1971 2079
 	// At about this point, we're posting and that's that.
1972 2080
 	ignore_user_abort(true);
@@ -1979,32 +2087,36 @@  discard block
 block discarded – undo
1979 2087
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1980 2088
 
1981 2089
 	// At this point, we want to make sure the subject isn't too long.
1982
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1983
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2090
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2091
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2092
+	}
1984 2093
 
1985 2094
 	// Same with the "why did you edit this" text.
1986
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1987
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2095
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2096
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2097
+	}
1988 2098
 
1989 2099
 	// Make the poll...
1990 2100
 	if (isset($_REQUEST['poll']))
1991 2101
 	{
1992 2102
 		// Make sure that the user has not entered a ridiculous number of options..
1993
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1994
-			$_POST['poll_max_votes'] = 1;
1995
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1996
-			$_POST['poll_max_votes'] = count($_POST['options']);
1997
-		else
1998
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2103
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2104
+					$_POST['poll_max_votes'] = 1;
2105
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2106
+					$_POST['poll_max_votes'] = count($_POST['options']);
2107
+		} else {
2108
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2109
+		}
1999 2110
 
2000 2111
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
2001 2112
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
2002 2113
 
2003 2114
 		// Just set it to zero if it's not there..
2004
-		if (!isset($_POST['poll_hide']))
2005
-			$_POST['poll_hide'] = 0;
2006
-		else
2007
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2115
+		if (!isset($_POST['poll_hide'])) {
2116
+					$_POST['poll_hide'] = 0;
2117
+		} else {
2118
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2119
+		}
2008 2120
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
2009 2121
 
2010 2122
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -2013,16 +2125,19 @@  discard block
 block discarded – undo
2013 2125
 		{
2014 2126
 			require_once($sourcedir . '/Subs-Members.php');
2015 2127
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
2016
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
2017
-				$_POST['poll_guest_vote'] = 0;
2128
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2129
+							$_POST['poll_guest_vote'] = 0;
2130
+			}
2018 2131
 		}
2019 2132
 
2020 2133
 		// If the user tries to set the poll too far in advance, don't let them.
2021
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
2022
-			fatal_lang_error('poll_range_error', false);
2134
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2135
+					fatal_lang_error('poll_range_error', false);
2136
+		}
2023 2137
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
2024
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
2025
-			$_POST['poll_hide'] = 1;
2138
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2139
+					$_POST['poll_hide'] = 1;
2140
+		}
2026 2141
 
2027 2142
 		// Clean up the question and answers.
2028 2143
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -2036,13 +2151,15 @@  discard block
 block discarded – undo
2036 2151
 	{
2037 2152
 		$attachIDs = array();
2038 2153
 		$attach_errors = array();
2039
-		if (!empty($context['we_are_history']))
2040
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2154
+		if (!empty($context['we_are_history'])) {
2155
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2156
+		}
2041 2157
 
2042 2158
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
2043 2159
 		{
2044
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
2045
-				continue;
2160
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2161
+							continue;
2162
+			}
2046 2163
 
2047 2164
 			// If there was an initial error just show that message.
2048 2165
 			if ($attachID == 'initial_error')
@@ -2071,12 +2188,13 @@  discard block
 block discarded – undo
2071 2188
 				if (createAttachment($attachmentOptions))
2072 2189
 				{
2073 2190
 					$attachIDs[] = $attachmentOptions['id'];
2074
-					if (!empty($attachmentOptions['thumb']))
2075
-						$attachIDs[] = $attachmentOptions['thumb'];
2191
+					if (!empty($attachmentOptions['thumb'])) {
2192
+											$attachIDs[] = $attachmentOptions['thumb'];
2193
+					}
2076 2194
 				}
2195
+			} else {
2196
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2077 2197
 			}
2078
-			else
2079
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2080 2198
 
2081 2199
 			if (!empty($attachmentOptions['errors']))
2082 2200
 			{
@@ -2088,14 +2206,16 @@  discard block
 block discarded – undo
2088 2206
 					if (!is_array($error))
2089 2207
 					{
2090 2208
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2091
-						if (in_array($error, $log_these))
2092
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2209
+						if (in_array($error, $log_these)) {
2210
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2211
+						}
2212
+					} else {
2213
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2093 2214
 					}
2094
-					else
2095
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2096 2215
 				}
2097
-				if (file_exists($attachment['tmp_name']))
2098
-					unlink($attachment['tmp_name']);
2216
+				if (file_exists($attachment['tmp_name'])) {
2217
+									unlink($attachment['tmp_name']);
2218
+				}
2099 2219
 			}
2100 2220
 		}
2101 2221
 		unset($_SESSION['temp_attachments']);
@@ -2136,24 +2256,24 @@  discard block
 block discarded – undo
2136 2256
 		);
2137 2257
 
2138 2258
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2259
+	} else {
2260
+			$id_poll = 0;
2139 2261
 	}
2140
-	else
2141
-		$id_poll = 0;
2142 2262
 
2143 2263
 	// Creating a new topic?
2144 2264
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2145 2265
 
2146 2266
 	// Check the icon.
2147
-	if (!isset($_POST['icon']))
2148
-		$_POST['icon'] = 'xx';
2149
-
2150
-	else
2267
+	if (!isset($_POST['icon'])) {
2268
+			$_POST['icon'] = 'xx';
2269
+	} else
2151 2270
 	{
2152 2271
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2153 2272
 
2154 2273
 		// Need to figure it out if this is a valid icon name.
2155
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2156
-			$_POST['icon'] = 'xx';
2274
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2275
+					$_POST['icon'] = 'xx';
2276
+		}
2157 2277
 	}
2158 2278
 
2159 2279
 	// Collect all parameters for the creation or modification of a post.
@@ -2194,8 +2314,9 @@  discard block
 block discarded – undo
2194 2314
 		}
2195 2315
 
2196 2316
 		// This will save some time...
2197
-		if (empty($approve_has_changed))
2198
-			unset($msgOptions['approved']);
2317
+		if (empty($approve_has_changed)) {
2318
+					unset($msgOptions['approved']);
2319
+		}
2199 2320
 
2200 2321
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2201 2322
 	}
@@ -2204,8 +2325,9 @@  discard block
 block discarded – undo
2204 2325
 	{
2205 2326
 		createPost($msgOptions, $topicOptions, $posterOptions);
2206 2327
 
2207
-		if (isset($topicOptions['id']))
2208
-			$topic = $topicOptions['id'];
2328
+		if (isset($topicOptions['id'])) {
2329
+					$topic = $topicOptions['id'];
2330
+		}
2209 2331
 	}
2210 2332
 
2211 2333
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2217,8 +2339,9 @@  discard block
 block discarded – undo
2217 2339
 	}
2218 2340
 
2219 2341
 	// If we had a draft for this, its time to remove it since it was just posted
2220
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2221
-		DeleteDraft($_POST['id_draft']);
2342
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2343
+			DeleteDraft($_POST['id_draft']);
2344
+	}
2222 2345
 
2223 2346
 	// Editing or posting an event?
2224 2347
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2237,8 +2360,7 @@  discard block
 block discarded – undo
2237 2360
 			'member' => $user_info['id'],
2238 2361
 		);
2239 2362
 		insertEvent($eventOptions);
2240
-	}
2241
-	elseif (isset($_POST['calendar']))
2363
+	} elseif (isset($_POST['calendar']))
2242 2364
 	{
2243 2365
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2244 2366
 
@@ -2266,14 +2388,15 @@  discard block
 block discarded – undo
2266 2388
 		}
2267 2389
 
2268 2390
 		// Delete it?
2269
-		if (isset($_REQUEST['deleteevent']))
2270
-			$smcFunc['db_query']('', '
2391
+		if (isset($_REQUEST['deleteevent'])) {
2392
+					$smcFunc['db_query']('', '
2271 2393
 				DELETE FROM {db_prefix}calendar
2272 2394
 				WHERE id_event = {int:id_event}',
2273 2395
 				array(
2274 2396
 					'id_event' => $_REQUEST['eventid'],
2275 2397
 				)
2276 2398
 			);
2399
+		}
2277 2400
 		// ... or just update it?
2278 2401
 		else
2279 2402
 		{
@@ -2315,9 +2438,8 @@  discard block
 block discarded – undo
2315 2438
 			array($user_info['id'], $topic, 0),
2316 2439
 			array('id_member', 'id_topic', 'id_board')
2317 2440
 		);
2318
-	}
2319
-	elseif (!$newTopic)
2320
-		$smcFunc['db_query']('', '
2441
+	} elseif (!$newTopic) {
2442
+			$smcFunc['db_query']('', '
2321 2443
 			DELETE FROM {db_prefix}log_notify
2322 2444
 			WHERE id_member = {int:current_member}
2323 2445
 				AND id_topic = {int:current_topic}',
@@ -2326,16 +2448,20 @@  discard block
 block discarded – undo
2326 2448
 				'current_topic' => $topic,
2327 2449
 			)
2328 2450
 		);
2451
+	}
2329 2452
 
2330 2453
 	// Log an act of moderation - modifying.
2331
-	if (!empty($moderationAction))
2332
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2454
+	if (!empty($moderationAction)) {
2455
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2456
+	}
2333 2457
 
2334
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2335
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2458
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2459
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2460
+	}
2336 2461
 
2337
-	if (isset($_POST['sticky']))
2338
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2462
+	if (isset($_POST['sticky'])) {
2463
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2464
+	}
2339 2465
 
2340 2466
 	// Returning to the topic?
2341 2467
 	if (!empty($_REQUEST['goback']))
@@ -2354,26 +2480,31 @@  discard block
 block discarded – undo
2354 2480
 		);
2355 2481
 	}
2356 2482
 
2357
-	if ($board_info['num_topics'] == 0)
2358
-		cache_put_data('board-' . $board, null, 120);
2483
+	if ($board_info['num_topics'] == 0) {
2484
+			cache_put_data('board-' . $board, null, 120);
2485
+	}
2359 2486
 
2360 2487
 	call_integration_hook('integrate_post2_end');
2361 2488
 
2362
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2363
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2489
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2490
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2491
+	}
2364 2492
 
2365
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2366
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2493
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2494
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2495
+	}
2367 2496
 
2368 2497
 	// Return to post if the mod is on.
2369
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2370
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2371
-	elseif (!empty($_REQUEST['goback']))
2372
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2498
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2499
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2500
+	} elseif (!empty($_REQUEST['goback'])) {
2501
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2502
+	}
2373 2503
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2374
-	else
2375
-		redirectexit('board=' . $board . '.0');
2376
-}
2504
+	else {
2505
+			redirectexit('board=' . $board . '.0');
2506
+	}
2507
+	}
2377 2508
 
2378 2509
 /**
2379 2510
  * Handle the announce topic function (action=announce).
@@ -2391,8 +2522,9 @@  discard block
 block discarded – undo
2391 2522
 
2392 2523
 	validateSession();
2393 2524
 
2394
-	if (empty($topic))
2395
-		fatal_lang_error('topic_gone', false);
2525
+	if (empty($topic)) {
2526
+			fatal_lang_error('topic_gone', false);
2527
+	}
2396 2528
 
2397 2529
 	loadLanguage('Post');
2398 2530
 	loadTemplate('Post');
@@ -2419,8 +2551,9 @@  discard block
 block discarded – undo
2419 2551
 	global $txt, $context, $topic, $board_info, $smcFunc;
2420 2552
 
2421 2553
 	$groups = array_merge($board_info['groups'], array(1));
2422
-	foreach ($groups as $id => $group)
2423
-		$groups[$id] = (int) $group;
2554
+	foreach ($groups as $id => $group) {
2555
+			$groups[$id] = (int) $group;
2556
+	}
2424 2557
 
2425 2558
 	$context['groups'] = array();
2426 2559
 	if (in_array(0, $groups))
@@ -2463,8 +2596,9 @@  discard block
 block discarded – undo
2463 2596
 			'group_list' => $groups,
2464 2597
 		)
2465 2598
 	);
2466
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2467
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2599
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2600
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2601
+	}
2468 2602
 	$smcFunc['db_free_result']($request);
2469 2603
 
2470 2604
 	// Get the subject of the topic we're about to announce.
@@ -2506,16 +2640,19 @@  discard block
 block discarded – undo
2506 2640
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2507 2641
 	$groups = array_merge($board_info['groups'], array(1));
2508 2642
 
2509
-	if (isset($_POST['membergroups']))
2510
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2643
+	if (isset($_POST['membergroups'])) {
2644
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2645
+	}
2511 2646
 
2512 2647
 	// Check whether at least one membergroup was selected.
2513
-	if (empty($_POST['who']))
2514
-		fatal_lang_error('no_membergroup_selected');
2648
+	if (empty($_POST['who'])) {
2649
+			fatal_lang_error('no_membergroup_selected');
2650
+	}
2515 2651
 
2516 2652
 	// Make sure all membergroups are integers and can access the board of the announcement.
2517
-	foreach ($_POST['who'] as $id => $mg)
2518
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2653
+	foreach ($_POST['who'] as $id => $mg) {
2654
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2655
+	}
2519 2656
 
2520 2657
 	// Get the topic subject and censor it.
2521 2658
 	$request = $smcFunc['db_query']('', '
@@ -2561,12 +2698,13 @@  discard block
 block discarded – undo
2561 2698
 	if ($smcFunc['db_num_rows']($request) == 0)
2562 2699
 	{
2563 2700
 		logAction('announce_topic', array('topic' => $topic), 'user');
2564
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2565
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2566
-		elseif (!empty($_REQUEST['goback']))
2567
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2568
-		else
2569
-			redirectexit('board=' . $board . '.0');
2701
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2702
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2703
+		} elseif (!empty($_REQUEST['goback'])) {
2704
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2705
+		} else {
2706
+					redirectexit('board=' . $board . '.0');
2707
+		}
2570 2708
 	}
2571 2709
 
2572 2710
 	$announcements = array();
@@ -2585,8 +2723,9 @@  discard block
 block discarded – undo
2585 2723
 	foreach ($rows as $row)
2586 2724
 	{
2587 2725
 		// Force them to have it?
2588
-		if (empty($prefs[$row['id_member']]['announcements']))
2589
-			continue;
2726
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2727
+					continue;
2728
+		}
2590 2729
 
2591 2730
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2592 2731
 
@@ -2614,8 +2753,9 @@  discard block
 block discarded – undo
2614 2753
 	}
2615 2754
 
2616 2755
 	// For each language send a different mail - low priority...
2617
-	foreach ($announcements as $lang => $mail)
2618
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2756
+	foreach ($announcements as $lang => $mail) {
2757
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2758
+	}
2619 2759
 
2620 2760
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2621 2761
 
@@ -2625,9 +2765,10 @@  discard block
 block discarded – undo
2625 2765
 	$context['sub_template'] = 'announcement_send';
2626 2766
 
2627 2767
 	// Go back to the correct language for the user ;).
2628
-	if (!empty($modSettings['userLanguage']))
2629
-		loadLanguage('Post');
2630
-}
2768
+	if (!empty($modSettings['userLanguage'])) {
2769
+			loadLanguage('Post');
2770
+	}
2771
+	}
2631 2772
 
2632 2773
 /**
2633 2774
  * Get the topic for display purposes.
@@ -2640,12 +2781,13 @@  discard block
 block discarded – undo
2640 2781
 {
2641 2782
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2642 2783
 
2643
-	if (isset($_REQUEST['xml']))
2644
-		$limit = '
2784
+	if (isset($_REQUEST['xml'])) {
2785
+			$limit = '
2645 2786
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2646
-	else
2647
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2787
+	} else {
2788
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2648 2789
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2790
+	}
2649 2791
 
2650 2792
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2651 2793
 	$request = $smcFunc['db_query']('', '
@@ -2683,8 +2825,9 @@  discard block
 block discarded – undo
2683 2825
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2684 2826
 		);
2685 2827
 
2686
-		if (!empty($context['new_replies']))
2687
-			$context['new_replies']--;
2828
+		if (!empty($context['new_replies'])) {
2829
+					$context['new_replies']--;
2830
+		}
2688 2831
 	}
2689 2832
 	$smcFunc['db_free_result']($request);
2690 2833
 }
@@ -2701,8 +2844,9 @@  discard block
 block discarded – undo
2701 2844
 	global $sourcedir, $smcFunc;
2702 2845
 
2703 2846
 	loadLanguage('Post');
2704
-	if (!isset($_REQUEST['xml']))
2705
-		loadTemplate('Post');
2847
+	if (!isset($_REQUEST['xml'])) {
2848
+			loadTemplate('Post');
2849
+	}
2706 2850
 
2707 2851
 	include_once($sourcedir . '/Subs-Post.php');
2708 2852
 
@@ -2733,8 +2877,9 @@  discard block
 block discarded – undo
2733 2877
 	$smcFunc['db_free_result']($request);
2734 2878
 
2735 2879
 	$context['sub_template'] = 'quotefast';
2736
-	if (!empty($row))
2737
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2880
+	if (!empty($row)) {
2881
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2882
+	}
2738 2883
 
2739 2884
 	if (!empty($can_view_post))
2740 2885
 	{
@@ -2767,8 +2912,9 @@  discard block
 block discarded – undo
2767 2912
 		}
2768 2913
 
2769 2914
 		// Remove any nested quotes.
2770
-		if (!empty($modSettings['removeNestedQuotes']))
2771
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2915
+		if (!empty($modSettings['removeNestedQuotes'])) {
2916
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2917
+		}
2772 2918
 
2773 2919
 		$lb = "\n";
2774 2920
 
@@ -2794,14 +2940,14 @@  discard block
 block discarded – undo
2794 2940
 				'time' => '',
2795 2941
 			),
2796 2942
 		);
2797
-	}
2798
-	else
2799
-		$context['quote'] = array(
2943
+	} else {
2944
+			$context['quote'] = array(
2800 2945
 			'xml' => '',
2801 2946
 			'mozilla' => '',
2802 2947
 			'text' => '',
2803 2948
 		);
2804
-}
2949
+	}
2950
+	}
2805 2951
 
2806 2952
 /**
2807 2953
  * Used to edit the body or subject of a message inline
@@ -2813,8 +2959,9 @@  discard block
 block discarded – undo
2813 2959
 	global $user_info, $context, $smcFunc, $language, $board_info;
2814 2960
 
2815 2961
 	// We have to have a topic!
2816
-	if (empty($topic))
2817
-		obExit(false);
2962
+	if (empty($topic)) {
2963
+			obExit(false);
2964
+	}
2818 2965
 
2819 2966
 	checkSession('get');
2820 2967
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2840,31 +2987,35 @@  discard block
 block discarded – undo
2840 2987
 			'guest_id' => 0,
2841 2988
 		)
2842 2989
 	);
2843
-	if ($smcFunc['db_num_rows']($request) == 0)
2844
-		fatal_lang_error('no_board', false);
2990
+	if ($smcFunc['db_num_rows']($request) == 0) {
2991
+			fatal_lang_error('no_board', false);
2992
+	}
2845 2993
 	$row = $smcFunc['db_fetch_assoc']($request);
2846 2994
 	$smcFunc['db_free_result']($request);
2847 2995
 
2848 2996
 	// Change either body or subject requires permissions to modify messages.
2849 2997
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2850 2998
 	{
2851
-		if (!empty($row['locked']))
2852
-			isAllowedTo('moderate_board');
2999
+		if (!empty($row['locked'])) {
3000
+					isAllowedTo('moderate_board');
3001
+		}
2853 3002
 
2854 3003
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2855 3004
 		{
2856
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2857
-				fatal_lang_error('modify_post_time_passed', false);
2858
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2859
-				isAllowedTo('modify_replies');
2860
-			else
2861
-				isAllowedTo('modify_own');
3005
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
3006
+							fatal_lang_error('modify_post_time_passed', false);
3007
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
3008
+							isAllowedTo('modify_replies');
3009
+			} else {
3010
+							isAllowedTo('modify_own');
3011
+			}
2862 3012
 		}
2863 3013
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2864
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2865
-			isAllowedTo('modify_replies');
2866
-		else
2867
-			isAllowedTo('modify_any');
3014
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
3015
+					isAllowedTo('modify_replies');
3016
+		} else {
3017
+					isAllowedTo('modify_any');
3018
+		}
2868 3019
 
2869 3020
 		// Only log this action if it wasn't your message.
2870 3021
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2876,10 +3027,10 @@  discard block
 block discarded – undo
2876 3027
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2877 3028
 
2878 3029
 		// Maximum number of characters.
2879
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2880
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2881
-	}
2882
-	elseif (isset($_POST['subject']))
3030
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
3031
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
3032
+		}
3033
+	} elseif (isset($_POST['subject']))
2883 3034
 	{
2884 3035
 		$post_errors[] = 'no_subject';
2885 3036
 		unset($_POST['subject']);
@@ -2891,13 +3042,11 @@  discard block
 block discarded – undo
2891 3042
 		{
2892 3043
 			$post_errors[] = 'no_message';
2893 3044
 			unset($_POST['message']);
2894
-		}
2895
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
3045
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2896 3046
 		{
2897 3047
 			$post_errors[] = 'long_message';
2898 3048
 			unset($_POST['message']);
2899
-		}
2900
-		else
3049
+		} else
2901 3050
 		{
2902 3051
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2903 3052
 
@@ -2913,31 +3062,34 @@  discard block
 block discarded – undo
2913 3062
 
2914 3063
 	if (isset($_POST['lock']))
2915 3064
 	{
2916
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2917
-			unset($_POST['lock']);
2918
-		elseif (!allowedTo('lock_any'))
3065
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3066
+					unset($_POST['lock']);
3067
+		} elseif (!allowedTo('lock_any'))
2919 3068
 		{
2920
-			if ($row['locked'] == 1)
2921
-				unset($_POST['lock']);
2922
-			else
2923
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3069
+			if ($row['locked'] == 1) {
3070
+							unset($_POST['lock']);
3071
+			} else {
3072
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3073
+			}
3074
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3075
+					unset($_POST['lock']);
3076
+		} else {
3077
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2924 3078
 		}
2925
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2926
-			unset($_POST['lock']);
2927
-		else
2928
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2929 3079
 	}
2930 3080
 
2931
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2932
-		unset($_POST['sticky']);
3081
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3082
+			unset($_POST['sticky']);
3083
+	}
2933 3084
 
2934 3085
 	if (isset($_POST['modify_reason']))
2935 3086
 	{
2936 3087
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2937 3088
 
2938 3089
 		// Maximum number of characters.
2939
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2940
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3090
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3091
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3092
+		}
2941 3093
 	}
2942 3094
 
2943 3095
 	if (empty($post_errors))
@@ -2974,8 +3126,9 @@  discard block
 block discarded – undo
2974 3126
 			}
2975 3127
 		}
2976 3128
 		// If nothing was changed there's no need to add an entry to the moderation log.
2977
-		else
2978
-			$moderationAction = false;
3129
+		else {
3130
+					$moderationAction = false;
3131
+		}
2979 3132
 
2980 3133
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2981 3134
 
@@ -2993,9 +3146,9 @@  discard block
 block discarded – undo
2993 3146
 			// Get the proper (default language) response prefix first.
2994 3147
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2995 3148
 			{
2996
-				if ($language === $user_info['language'])
2997
-					$context['response_prefix'] = $txt['response_prefix'];
2998
-				else
3149
+				if ($language === $user_info['language']) {
3150
+									$context['response_prefix'] = $txt['response_prefix'];
3151
+				} else
2999 3152
 				{
3000 3153
 					loadLanguage('index', $language, false);
3001 3154
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -3017,8 +3170,9 @@  discard block
 block discarded – undo
3017 3170
 			);
3018 3171
 		}
3019 3172
 
3020
-		if (!empty($moderationAction))
3021
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3173
+		if (!empty($moderationAction)) {
3174
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3175
+		}
3022 3176
 	}
3023 3177
 
3024 3178
 	if (isset($_REQUEST['xml']))
@@ -3059,8 +3213,7 @@  discard block
 block discarded – undo
3059 3213
 			);
3060 3214
 
3061 3215
 			censorText($context['message']['subject']);
3062
-		}
3063
-		else
3216
+		} else
3064 3217
 		{
3065 3218
 			$context['message'] = array(
3066 3219
 				'id' => $row['id_msg'],
@@ -3072,15 +3225,16 @@  discard block
 block discarded – undo
3072 3225
 			loadLanguage('Errors');
3073 3226
 			foreach ($post_errors as $post_error)
3074 3227
 			{
3075
-				if ($post_error == 'long_message')
3076
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3077
-				else
3078
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3228
+				if ($post_error == 'long_message') {
3229
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3230
+				} else {
3231
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3232
+				}
3079 3233
 			}
3080 3234
 		}
3235
+	} else {
3236
+			obExit(false);
3237
+	}
3081 3238
 	}
3082
-	else
3083
-		obExit(false);
3084
-}
3085 3239
 
3086 3240
 ?>
3087 3241
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/ManageSmileys.template.php 1 patch
Braces   +56 added lines, -41 removed lines patch added patch discarded remove patch
@@ -34,11 +34,12 @@  discard block
 block discarded – undo
34 34
 		</div>';
35 35
 
36 36
 	// If this is an existing set, and there are still un-added smileys - offer an import opportunity.
37
-	if (!empty($context['current_set']['can_import']))
38
-		echo '
37
+	if (!empty($context['current_set']['can_import'])) {
38
+			echo '
39 39
 		<div class="information noup">
40 40
 			', $context['current_set']['can_import'] == 1 ? sprintf($txt['smiley_set_import_single'], $context['current_set']['import_url']) : sprintf($txt['smiley_set_import_multiple'], $context['current_set']['can_import'], $context['current_set']['import_url']), '
41 41
 		</div>';
42
+	}
42 43
 
43 44
 	echo '
44 45
 		<div class="windowbg noup">
@@ -67,17 +68,18 @@  discard block
 block discarded – undo
67 68
 				<dd>
68 69
 					', $modSettings['smileys_url'], '/';
69 70
 
70
-	if (empty($context['smiley_set_dirs']))
71
-		echo '
71
+	if (empty($context['smiley_set_dirs'])) {
72
+			echo '
72 73
 					<input type="text" name="smiley_sets_path" id="smiley_sets_path" value="', $context['current_set']['path'], '"> ';
73
-	else
74
+	} else
74 75
 	{
75 76
 		echo '
76 77
 					<select name="smiley_sets_path" id="smiley_sets_path">';
77 78
 
78
-		foreach ($context['smiley_set_dirs'] as $smiley_set_dir)
79
-			echo '
79
+		foreach ($context['smiley_set_dirs'] as $smiley_set_dir) {
80
+					echo '
80 81
 						<option value="', $smiley_set_dir['id'], '"', $smiley_set_dir['current'] ? ' selected' : '', $smiley_set_dir['selectable'] ? '' : ' disabled', '>', $smiley_set_dir['id'], '</option>';
82
+		}
81 83
 		echo '
82 84
 					</select> ';
83 85
 	}
@@ -92,14 +94,15 @@  discard block
 block discarded – undo
92 94
 				</dd>';
93 95
 
94 96
 	// If this is a new smiley set they have the option to import smileys already in the directory.
95
-	if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable']))
96
-		echo '
97
+	if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable'])) {
98
+			echo '
97 99
 				<dt>
98 100
 					<strong><label for="smiley_sets_import">', $txt['smiley_set_import_directory'], '</label>: </strong>
99 101
 				</dt>
100 102
 				<dd>
101 103
 					<input type="checkbox" name="smiley_sets_import" id="smiley_sets_import" value="1">
102 104
 				</dd>';
105
+	}
103 106
 
104 107
 	echo '
105 108
 			</dl>
@@ -131,9 +134,10 @@  discard block
 block discarded – undo
131 134
 				<dd>
132 135
 					<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['current_smiley']['filename'] . $context['user']['smiley_set_default_ext'], '" id="preview" alt=""> ', $txt['smiley_preview_using'], ': <select id="set" onchange="updatePreview();">';
133 136
 
134
-	foreach ($context['smiley_sets'] as $smiley_set)
135
-		echo '
137
+	foreach ($context['smiley_sets'] as $smiley_set) {
138
+			echo '
136 139
 					<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected' : '', '>', $smiley_set['name'], '</option>';
140
+	}
137 141
 
138 142
 	echo '
139 143
 					</select>
@@ -149,17 +153,18 @@  discard block
 block discarded – undo
149 153
 				</dt>
150 154
 				<dd>';
151 155
 
152
-	if (empty($context['filenames']))
153
-		echo '
156
+	if (empty($context['filenames'])) {
157
+			echo '
154 158
 					<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '">';
155
-	else
159
+	} else
156 160
 	{
157 161
 		echo '
158 162
 					<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();">';
159 163
 
160
-		foreach ($context['filenames'] as $filename)
161
-			echo '
164
+		foreach ($context['filenames'] as $filename) {
165
+					echo '
162 166
 						<option value="', $filename['id'], '"', $filename['selected'] ? ' selected' : '', '>', $filename['id'], '</option>';
167
+		}
163 168
 		echo '
164 169
 					</select>';
165 170
 	}
@@ -226,9 +231,10 @@  discard block
 block discarded – undo
226 231
 					<dd>
227 232
 						', $txt['smiley_preview_using'], ': <select id="set" onchange="updatePreview();selectMethod(\'existing\');">';
228 233
 
229
-	foreach ($context['smiley_sets'] as $smiley_set)
230
-		echo '
234
+	foreach ($context['smiley_sets'] as $smiley_set) {
235
+			echo '
231 236
 							<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected' : '', '>', $smiley_set['name'], '</option>';
237
+	}
232 238
 
233 239
 	echo '
234 240
 						</select>
@@ -238,17 +244,18 @@  discard block
 block discarded – undo
238 244
 					</dt>
239 245
 					<dd>';
240 246
 
241
-	if (empty($context['filenames']))
242
-		echo '
247
+	if (empty($context['filenames'])) {
248
+			echo '
243 249
 						<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" onchange="selectMethod(\'existing\');">';
244
-	else
250
+	} else
245 251
 	{
246 252
 		echo '
247 253
 						<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();selectMethod(\'existing\');">';
248 254
 
249
-		foreach ($context['filenames'] as $filename)
250
-			echo '
255
+		foreach ($context['filenames'] as $filename) {
256
+					echo '
251 257
 							<option value="', $filename['id'], '"', $filename['selected'] ? ' selected' : '', '>', $filename['id'], '</option>';
258
+		}
252 259
 		echo '
253 260
 						</select>';
254 261
 	}
@@ -261,14 +268,15 @@  discard block
 block discarded – undo
261 268
 
262 269
 			<dl id="uploadMore" class="settings">';
263 270
 
264
-	foreach ($context['smiley_sets'] as $smiley_set)
265
-		echo '
271
+	foreach ($context['smiley_sets'] as $smiley_set) {
272
+			echo '
266 273
 				<dt>
267 274
 					', sprintf($txt['smileys_add_upload_for'], '<strong>' . $smiley_set['name'] . '</strong>'), ':
268 275
 				</dt>
269 276
 				<dd>
270 277
 					<input type="file" name="individual_', $smiley_set['name'], '" onchange="selectMethod(\'upload\');">
271 278
 				</dd>';
279
+	}
272 280
 
273 281
 	echo '
274 282
 			</dl>
@@ -336,27 +344,30 @@  discard block
 block discarded – undo
336 344
 
337 345
 		foreach ($location['rows'] as $row)
338 346
 		{
339
-			if (!empty($context['move_smiley']))
340
-				echo '
347
+			if (!empty($context['move_smiley'])) {
348
+							echo '
341 349
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $row[0]['row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
350
+			}
342 351
 
343 352
 			foreach ($row as $smiley)
344 353
 			{
345
-				if (empty($context['move_smiley']))
346
-					echo '
354
+				if (empty($context['move_smiley'])) {
355
+									echo '
347 356
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;move=', $smiley['id'], '"><img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" alt="', $smiley['description'], '"></a>';
348
-				else
349
-					echo '
357
+				} else {
358
+									echo '
350 359
 			<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" alt="', $smiley['description'], '" ', $smiley['selected'] ? 'class="selected_item"' : '', '>
351 360
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';after=', $smiley['id'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '" title="', $txt['smileys_move_here'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
361
+				}
352 362
 			}
353 363
 
354 364
 			echo '
355 365
 			<br>';
356 366
 		}
357
-		if (!empty($context['move_smiley']))
358
-			echo '
367
+		if (!empty($context['move_smiley'])) {
368
+					echo '
359 369
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $location['last_row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
370
+		}
360 371
 		echo '
361 372
 		</div><!-- .windowbg -->
362 373
 		<input type="hidden" name="reorder" value="1">
@@ -389,14 +400,15 @@  discard block
 block discarded – undo
389 400
 		<div class="windowbg">
390 401
 			<dl class="settings">';
391 402
 
392
-	if (!$context['new_icon'])
393
-		echo '
403
+	if (!$context['new_icon']) {
404
+			echo '
394 405
 				<dt>
395 406
 					<strong>', $txt['smiley_preview'], ': </strong>
396 407
 				</dt>
397 408
 				<dd>
398 409
 					<img src="', $context['icon']['image_url'], '" alt="', $context['icon']['title'], '">
399 410
 				</dd>';
411
+	}
400 412
 
401 413
 	echo '
402 414
 				<dt>
@@ -423,9 +435,10 @@  discard block
 block discarded – undo
423 435
 		echo '
424 436
 						<optgroup label="', $category['name'], '">';
425 437
 
426
-		foreach ($category['boards'] as $board)
427
-			echo '
438
+		foreach ($category['boards'] as $board) {
439
+					echo '
428 440
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
441
+		}
429 442
 
430 443
 		echo '
431 444
 						</optgroup>';
@@ -442,19 +455,21 @@  discard block
 block discarded – undo
442 455
 						<option value="0"', empty($context['icon']['after']) ? ' selected' : '', '>', $txt['icons_location_first_icon'], '</option>';
443 456
 
444 457
 	// Print the list of all the icons it can be put after...
445
-	foreach ($context['icons'] as $id => $data)
446
-		if (empty($context['icon']['id']) || $id != $context['icon']['id'])
458
+	foreach ($context['icons'] as $id => $data) {
459
+			if (empty($context['icon']['id']) || $id != $context['icon']['id'])
447 460
 			echo '
448 461
 						<option value="', $id, '"', !empty($context['icon']['after']) && $id == $context['icon']['after'] ? ' selected' : '', '>', $txt['icons_location_after'], ': ', $data['title'], '</option>';
462
+	}
449 463
 
450 464
 	echo '
451 465
 					</select>
452 466
 				</dd>
453 467
 			</dl>';
454 468
 
455
-	if (!$context['new_icon'])
456
-		echo '
469
+	if (!$context['new_icon']) {
470
+			echo '
457 471
 			<input type="hidden" name="icon" value="', $context['icon']['id'], '">';
472
+	}
458 473
 
459 474
 	echo '
460 475
 			<input type="submit" name="icons_save" value="', $txt['smileys_save'], '" class="button">
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.