Completed
Branch release-2.1 (e49a83)
by Michael
08:59
created
Sources/Errors.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -475,7 +475,7 @@
 block discarded – undo
475 475
  * Used by fatal_error(), fatal_lang_error()
476 476
  *
477 477
  * @param string $error The error
478
- * @param array $sprintf An array of data to be sprintf()'d into the specified message
478
+ * @param boolean $sprintf An array of data to be sprintf()'d into the specified message
479 479
  */
480 480
 function log_error_online($error, $sprintf = array())
481 481
 {
Please login to merge, or discard this patch.
Braces   +117 added lines, -83 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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.
@@ -36,8 +37,9 @@  discard block
 block discarded – undo
36 37
 	static $tried_hook = false;
37 38
 
38 39
 	// Check if error logging is actually on.
39
-	if (empty($modSettings['enableErrorLogging']))
40
-		return $error_message;
40
+	if (empty($modSettings['enableErrorLogging'])) {
41
+			return $error_message;
42
+	}
41 43
 
42 44
 	// Basically, htmlspecialchars it minus &. (for entities!)
43 45
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -45,22 +47,26 @@  discard block
 block discarded – undo
45 47
 
46 48
 	// Add a file and line to the error message?
47 49
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
48
-	if ($file == null)
49
-		$file = '';
50
-	else
51
-		// Window style slashes don't play well, lets convert them to the unix style.
50
+	if ($file == null) {
51
+			$file = '';
52
+	} else {
53
+			// Window style slashes don't play well, lets convert them to the unix style.
52 54
 		$file = str_replace('\\', '/', $file);
55
+	}
53 56
 
54
-	if ($line == null)
55
-		$line = 0;
56
-	else
57
-		$line = (int) $line;
57
+	if ($line == null) {
58
+			$line = 0;
59
+	} else {
60
+			$line = (int) $line;
61
+	}
58 62
 
59 63
 	// Just in case there's no id_member or IP set yet.
60
-	if (empty($user_info['id']))
61
-		$user_info['id'] = 0;
62
-	if (empty($user_info['ip']))
63
-		$user_info['ip'] = '';
64
+	if (empty($user_info['id'])) {
65
+			$user_info['id'] = 0;
66
+	}
67
+	if (empty($user_info['ip'])) {
68
+			$user_info['ip'] = '';
69
+	}
64 70
 
65 71
 	// Find the best query string we can...
66 72
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
@@ -69,8 +75,9 @@  discard block
 block discarded – undo
69 75
 	$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
70 76
 
71 77
 	// Just so we know what board error messages are from.
72
-	if (isset($_POST['board']) && !isset($_GET['board']))
73
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
78
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
79
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
80
+	}
74 81
 
75 82
 	// What types of categories do we have?
76 83
 	$known_error_types = array(
@@ -132,12 +139,14 @@  discard block
 block discarded – undo
132 139
 	global $txt;
133 140
 
134 141
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
135
-	if (!empty($status))
136
-		send_http_status($status);
142
+	if (!empty($status)) {
143
+			send_http_status($status);
144
+	}
137 145
 
138 146
 	// We don't have $txt yet, but that's okay...
139
-	if (empty($txt))
140
-		die($error);
147
+	if (empty($txt)) {
148
+			die($error);
149
+	}
141 150
 
142 151
 	log_error_online($error, false);
143 152
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -164,8 +173,9 @@  discard block
 block discarded – undo
164 173
 	static $fatal_error_called = false;
165 174
 
166 175
 	// Send the 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
 	// Try to load a theme if we don't have one.
171 181
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -175,8 +185,9 @@  discard block
 block discarded – undo
175 185
 	}
176 186
 
177 187
 	// If we have no theme stuff we can't have the language file...
178
-	if (empty($context['theme_loaded']))
179
-		die($error);
188
+	if (empty($context['theme_loaded'])) {
189
+			die($error);
190
+	}
180 191
 
181 192
 	$reload_lang_file = true;
182 193
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -212,8 +223,9 @@  discard block
 block discarded – undo
212 223
 	global $settings, $modSettings, $db_show_debug;
213 224
 
214 225
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
215
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
216
-		return;
226
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
227
+			return;
228
+	}
217 229
 
218 230
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
219 231
 	{
@@ -221,19 +233,22 @@  discard block
 block discarded – undo
221 233
 		$count = count($array);
222 234
 		for ($i = 0; $i < $count; $i++)
223 235
 		{
224
-			if ($array[$i]['function'] != 'loadSubTemplate')
225
-				continue;
236
+			if ($array[$i]['function'] != 'loadSubTemplate') {
237
+							continue;
238
+			}
226 239
 
227 240
 			// This is a bug in PHP, with eval, it seems!
228
-			if (empty($array[$i]['args']))
229
-				$i++;
241
+			if (empty($array[$i]['args'])) {
242
+							$i++;
243
+			}
230 244
 			break;
231 245
 		}
232 246
 
233
-		if (isset($array[$i]) && !empty($array[$i]['args']))
234
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
235
-		else
236
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
247
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
248
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
249
+		} else {
250
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
251
+		}
237 252
 	}
238 253
 
239 254
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -242,8 +257,9 @@  discard block
 block discarded – undo
242 257
 		if ($error_level % 255 != E_ERROR)
243 258
 		{
244 259
 			$temporary = ob_get_contents();
245
-			if (substr($temporary, -2) == '="')
246
-				echo '"';
260
+			if (substr($temporary, -2) == '="') {
261
+							echo '"';
262
+			}
247 263
 		}
248 264
 
249 265
 		// Debugging!  This should look like a PHP error message.
@@ -259,23 +275,27 @@  discard block
 block discarded – undo
259 275
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
260 276
 
261 277
 	// Dying on these errors only causes MORE problems (blank pages!)
262
-	if ($file == 'Unknown')
263
-		return;
278
+	if ($file == 'Unknown') {
279
+			return;
280
+	}
264 281
 
265 282
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
266
-	if ($error_level % 255 == E_ERROR)
267
-		obExit(false);
268
-	else
269
-		return;
283
+	if ($error_level % 255 == E_ERROR) {
284
+			obExit(false);
285
+	} else {
286
+			return;
287
+	}
270 288
 
271 289
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
272
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
273
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
290
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
291
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
292
+	}
274 293
 
275 294
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
276
-	if ($error_level % 255 == E_ERROR)
277
-		die('No direct access...');
278
-}
295
+	if ($error_level % 255 == E_ERROR) {
296
+			die('No direct access...');
297
+	}
298
+	}
279 299
 
280 300
 /**
281 301
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -291,24 +311,28 @@  discard block
 block discarded – undo
291 311
 
292 312
 	// Attempt to prevent a recursive loop.
293 313
 	++$level;
294
-	if ($level > 1)
295
-		return false;
314
+	if ($level > 1) {
315
+			return false;
316
+	}
296 317
 
297 318
 	// Maybe they came from dlattach or similar?
298
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
299
-		loadTheme();
319
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
320
+			loadTheme();
321
+	}
300 322
 
301 323
 	// Don't bother indexing errors mate...
302 324
 	$context['robot_no_index'] = true;
303 325
 
304
-	if (!isset($context['error_title']))
305
-		$context['error_title'] = $txt['error_occured'];
326
+	if (!isset($context['error_title'])) {
327
+			$context['error_title'] = $txt['error_occured'];
328
+	}
306 329
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
307 330
 
308 331
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
309 332
 
310
-	if (empty($context['page_title']))
311
-		$context['page_title'] = $context['error_title'];
333
+	if (empty($context['page_title'])) {
334
+			$context['page_title'] = $context['error_title'];
335
+	}
312 336
 
313 337
 	loadTemplate('Errors');
314 338
 	$context['sub_template'] = 'fatal_error';
@@ -316,23 +340,26 @@  discard block
 block discarded – undo
316 340
 	// If this is SSI, what do they want us to do?
317 341
 	if (SMF == 'SSI')
318 342
 	{
319
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
320
-			$ssi_on_error_method();
321
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
322
-			loadSubTemplate('fatal_error');
343
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
344
+					$ssi_on_error_method();
345
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
346
+					loadSubTemplate('fatal_error');
347
+		}
323 348
 
324 349
 		// No layers?
325
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
326
-			exit;
350
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
351
+					exit;
352
+		}
327 353
 	}
328 354
 	// Alternatively from the cron call?
329 355
 	elseif (SMF == 'BACKGROUND')
330 356
 	{
331 357
 		// We can't rely on even having language files available.
332
-		if (defined('FROM_CLI') && FROM_CLI)
333
-			echo 'cron error: ', $context['error_message'];
334
-		else
335
-			echo 'An error occurred. More information may be available in your logs.';
358
+		if (defined('FROM_CLI') && FROM_CLI) {
359
+					echo 'cron error: ', $context['error_message'];
360
+		} else {
361
+					echo 'An error occurred. More information may be available in your logs.';
362
+		}
336 363
 		exit;
337 364
 	}
338 365
 
@@ -360,8 +387,8 @@  discard block
 block discarded – undo
360 387
 
361 388
 	set_fatal_error_headers();
362 389
 
363
-	if (!empty($maintenance))
364
-		echo '<!DOCTYPE html>
390
+	if (!empty($maintenance)) {
391
+			echo '<!DOCTYPE html>
365 392
 <html>
366 393
 	<head>
367 394
 		<meta name="robots" content="noindex">
@@ -372,6 +399,7 @@  discard block
 block discarded – undo
372 399
 		', $mmessage, '
373 400
 	</body>
374 401
 </html>';
402
+	}
375 403
 
376 404
 	die();
377 405
 }
@@ -393,15 +421,17 @@  discard block
 block discarded – undo
393 421
 	// For our purposes, we're gonna want this on if at all possible.
394 422
 	$modSettings['cache_enable'] = '1';
395 423
 
396
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
397
-		$db_last_error = max($db_last_error, $temp);
424
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
425
+			$db_last_error = max($db_last_error, $temp);
426
+	}
398 427
 
399 428
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
400 429
 	{
401 430
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
402 431
 		cache_put_data('db_last_error', time(), 600);
403
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
404
-			logLastDatabaseError();
432
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
433
+					logLastDatabaseError();
434
+		}
405 435
 
406 436
 		// Language files aren't loaded yet :(.
407 437
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -482,12 +512,14 @@  discard block
 block discarded – undo
482 512
 	global $smcFunc, $user_info, $modSettings;
483 513
 
484 514
 	// Don't bother if Who's Online is disabled.
485
-	if (empty($modSettings['who_enabled']))
486
-		return;
515
+	if (empty($modSettings['who_enabled'])) {
516
+			return;
517
+	}
487 518
 
488 519
 	// Maybe they came from SSI or similar where sessions are not recorded?
489
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
490
-		return;
520
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
521
+			return;
522
+	}
491 523
 
492 524
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
493 525
 
@@ -506,8 +538,9 @@  discard block
 block discarded – undo
506 538
 		$url = smf_json_decode($url, true);
507 539
 		$url['error'] = $error;
508 540
 
509
-		if (!empty($sprintf))
510
-			$url['error_params'] = $sprintf;
541
+		if (!empty($sprintf)) {
542
+					$url['error_params'] = $sprintf;
543
+		}
511 544
 
512 545
 		$smcFunc['db_query']('', '
513 546
 			UPDATE {db_prefix}log_online
@@ -538,10 +571,11 @@  discard block
 block discarded – undo
538 571
 
539 572
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
540 573
 
541
-	if (!isset($statuses[$code]))
542
-		header($protocol . ' 500 Internal Server Error');
543
-	else
544
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
545
-}
574
+	if (!isset($statuses[$code])) {
575
+			header($protocol . ' 500 Internal Server Error');
576
+	} else {
577
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
578
+	}
579
+	}
546 580
 
547 581
 ?>
548 582
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Load.php 4 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2241,9 +2241,9 @@  discard block
 block discarded – undo
2241 2241
  *
2242 2242
  * @uses the template_include() function to include the file.
2243 2243
  * @param string $template_name The name of the template to load
2244
- * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2244
+ * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2245 2245
  * @param bool $fatal If true, dies with an error message if the template cannot be found
2246
- * @return boolean Whether or not the template was loaded
2246
+ * @return boolean|null Whether or not the template was loaded
2247 2247
  */
2248 2248
 function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
2249 2249
 {
@@ -2426,7 +2426,7 @@  discard block
 block discarded – undo
2426 2426
  * - all code added with this function is added to the same <style> tag so do make sure your css is valid!
2427 2427
  *
2428 2428
  * @param string $css Some css code
2429
- * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2429
+ * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2430 2430
  */
2431 2431
 function addInlineCss($css)
2432 2432
 {
@@ -2442,7 +2442,7 @@  discard block
 block discarded – undo
2442 2442
 /**
2443 2443
  * Add a Javascript file for output later
2444 2444
 
2445
- * @param string $filename The name of the file to load
2445
+ * @param string $fileName The name of the file to load
2446 2446
  * @param array $params An array of parameter info
2447 2447
  * Keys are the following:
2448 2448
  * 	- ['external'] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file
@@ -2540,7 +2540,7 @@  discard block
 block discarded – undo
2540 2540
  *
2541 2541
  * @param string $javascript Some JS code
2542 2542
  * @param bool $defer Whether the script should load in <head> or before the closing <html> tag
2543
- * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2543
+ * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2544 2544
  */
2545 2545
 function addInlineJavaScript($javascript, $defer = false)
2546 2546
 {
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -2441,7 +2441,6 @@
 block discarded – undo
2441 2441
 
2442 2442
 /**
2443 2443
  * Add a Javascript file for output later
2444
-
2445 2444
  * @param string $filename The name of the file to load
2446 2445
  * @param array $params An array of parameter info
2447 2446
  * Keys are the following:
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 
77 77
 	// Set a list of common functions.
78 78
 	$ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);';
79
-	$ent_check = empty($modSettings['disableEntityCheck']) ? function ($string)
79
+	$ent_check = empty($modSettings['disableEntityCheck']) ? function($string)
80 80
 		{
81 81
 			$string = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $string);
82 82
 			return $string;
83
-		} : function ($string)
83
+		} : function($string)
84 84
 		{
85 85
 			return $string;
86 86
 		};
87
-	$fix_utf8mb4 = function ($string) use ($utf8)
87
+	$fix_utf8mb4 = function($string) use ($utf8)
88 88
 	{
89 89
 		if (!$utf8)
90 90
 			return $string;
@@ -102,21 +102,21 @@  discard block
 block discarded – undo
102 102
 			}
103 103
 			elseif ($ord < 224)
104 104
 			{
105
-				$new_string .= $string[$i] . $string[$i+1];
105
+				$new_string .= $string[$i] . $string[$i + 1];
106 106
 				$i += 2;
107 107
 			}
108 108
 			elseif ($ord < 240)
109 109
 			{
110
-				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
110
+				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
111 111
 				$i += 3;
112 112
 			}
113 113
 			elseif ($ord < 248)
114 114
 			{
115 115
 				// Magic happens.
116 116
 				$val = (ord($string[$i]) & 0x07) << 18;
117
-				$val += (ord($string[$i+1]) & 0x3F) << 12;
118
-				$val += (ord($string[$i+2]) & 0x3F) << 6;
119
-				$val += (ord($string[$i+3]) & 0x3F);
117
+				$val += (ord($string[$i + 1]) & 0x3F) << 12;
118
+				$val += (ord($string[$i + 2]) & 0x3F) << 6;
119
+				$val += (ord($string[$i + 3]) & 0x3F);
120 120
 				$new_string .= '&#' . $val . ';';
121 121
 				$i += 4;
122 122
 			}
@@ -129,24 +129,24 @@  discard block
 block discarded – undo
129 129
 
130 130
 	// global array of anonymous helper functions, used mostly to properly handle multi byte strings
131 131
 	$smcFunc += array(
132
-		'entity_fix' => function ($string)
132
+		'entity_fix' => function($string)
133 133
 		{
134 134
 			$num = $string[0] === 'x' ? hexdec(substr($string, 1)) : (int) $string;
135 135
 			return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? '' : '&#' . $num . ';';
136 136
 		},
137
-		'htmlspecialchars' => function ($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4)
137
+		'htmlspecialchars' => function($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4)
138 138
 		{
139 139
 			return $fix_utf8mb4($ent_check(htmlspecialchars($string, $quote_style, $utf8 ? 'UTF-8' : $charset)));
140 140
 		},
141
-		'htmltrim' => function ($string) use ($utf8, $space_chars, $ent_check)
141
+		'htmltrim' => function($string) use ($utf8, $space_chars, $ent_check)
142 142
 		{
143 143
 			return preg_replace('~^(?:[ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+|(?:[ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+$~' . ($utf8 ? 'u' : ''), '', $ent_check($string));
144 144
 		},
145
-		'strlen' => function ($string) use ($ent_list, $utf8, $ent_check)
145
+		'strlen' => function($string) use ($ent_list, $utf8, $ent_check)
146 146
 		{
147 147
 			return strlen(preg_replace('~' . $ent_list . ($utf8 ? '|.~u' : '~'), '_', $ent_check($string)));
148 148
 		},
149
-		'strpos' => function ($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings)
149
+		'strpos' => function($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings)
150 150
 		{
151 151
 			$haystack_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : ''), $ent_check($haystack), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
152 152
 
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
 				return false;
172 172
 			}
173 173
 		},
174
-		'substr' => function ($string, $start, $length = null) use ($utf8, $ent_check, $modSettings)
174
+		'substr' => function($string, $start, $length = null) use ($utf8, $ent_check, $modSettings)
175 175
 		{
176 176
 			$ent_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
177 177
 			return $length === null ? implode('', array_slice($ent_arr, $start)) : implode('', array_slice($ent_arr, $start, $length));
178 178
 		},
179
-		'strtolower' => $utf8 ? function ($string) use ($sourcedir)
179
+		'strtolower' => $utf8 ? function($string) use ($sourcedir)
180 180
 		{
181 181
 			if (!function_exists('mb_strtolower'))
182 182
 			{
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 			return mb_strtolower($string, 'UTF-8');
188 188
 		} : 'strtolower',
189
-		'strtoupper' => $utf8 ? function ($string)
189
+		'strtoupper' => $utf8 ? function($string)
190 190
 		{
191 191
 			global $sourcedir;
192 192
 
@@ -201,17 +201,17 @@  discard block
 block discarded – undo
201 201
 		'truncate' => function($string, $length) use ($utf8, $ent_check, $ent_list, &$smcFunc)
202 202
 		{
203 203
 			$string = $ent_check($string);
204
-			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
204
+			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
205 205
 			$string = $matches[0];
206 206
 			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
207
+				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
208 208
 			return $string;
209 209
 		},
210
-		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
210
+		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
211 211
 		{
212 212
 			return $smcFunc['strtoupper']($smcFunc['substr']($string, 0, 1)) . $smcFunc['substr']($string, 1);
213 213
 		} : 'ucfirst',
214
-		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
214
+		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
215 215
 		{
216 216
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217 217
 			for ($i = 0, $n = count($words); $i < $n; $i += 2)
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		else
611 611
 		{
612 612
 			// !!! Compatibility.
613
-			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
613
+			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
614 614
 		}
615 615
 	}
616 616
 	// If the user is a guest, initialize all the critical user settings.
@@ -1265,9 +1265,9 @@  discard block
 block discarded – undo
1265 1265
 			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1266 1266
 				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1267 1267
 
1268
-			if ( isset($row['member_ip']) )
1268
+			if (isset($row['member_ip']))
1269 1269
 				$row['member_ip'] = inet_dtop($row['member_ip']);
1270
-			if ( isset($row['member_ip2']) )
1270
+			if (isset($row['member_ip2']))
1271 1271
 				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1272 1272
 			$new_loaded_ids[] = $row['id_member'];
1273 1273
 			$loaded_ids[] = $row['id_member'];
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
 		'name' => $profile['real_name'],
1416 1416
 		'id' => $profile['id_member'],
1417 1417
 		'href' => $scripturl . '?action=profile;u=' . $profile['id_member'],
1418
-		'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" '. (!empty($modSettings['onlineEnable']) ? 'class="pm_icon"' : '').'>' . $profile['real_name'] . '</a>',
1418
+		'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" ' . (!empty($modSettings['onlineEnable']) ? 'class="pm_icon"' : '') . '>' . $profile['real_name'] . '</a>',
1419 1419
 		'email' => $profile['email_address'],
1420 1420
 		'show_email' => !$user_info['is_guest'] && ($user_info['id'] == $profile['id_member'] || allowedTo('moderate_forum')),
1421 1421
 		'registered' => empty($profile['date_registered']) ? $txt['not_applicable'] : timeformat($profile['date_registered']),
@@ -1430,9 +1430,9 @@  discard block
 block discarded – undo
1430 1430
 			$loadedLanguages = getLanguages();
1431 1431
 
1432 1432
 		$memberContext[$user] += array(
1433
-			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
1434
-			'name_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['real_name'] .'</span>',
1435
-			'link_color' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>' . $profile['real_name'] . '</a>',
1433
+			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
1434
+			'name_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['real_name'] . '</span>',
1435
+			'link_color' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '" ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['real_name'] . '</a>',
1436 1436
 			'is_buddy' => $profile['buddy'],
1437 1437
 			'is_reverse_buddy' => in_array($user_info['id'], $buddy_list),
1438 1438
 			'buddies' => $buddy_list,
@@ -1502,7 +1502,7 @@  discard block
 block discarded – undo
1502 1502
 		if (!empty($image))
1503 1503
 			$memberContext[$user]['avatar'] = array(
1504 1504
 				'name' => $profile['avatar'],
1505
-				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1505
+				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1506 1506
 				'href' => $image,
1507 1507
 				'url' => $image,
1508 1508
 			);
@@ -2828,7 +2828,7 @@  discard block
 block discarded – undo
2828 2828
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2829 2829
 
2830 2830
 					// Get the line we need.
2831
-					$fp = @fopen($language_dir .'/'. $entry);
2831
+					$fp = @fopen($language_dir . '/' . $entry);
2832 2832
 
2833 2833
 					// Yay!
2834 2834
 					if ($fp)
Please login to merge, or discard this patch.
Braces   +793 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function ($string) use ($utf8)
88 98
 	{
89
-		if (!$utf8)
90
-			return $string;
99
+		if (!$utf8) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i+1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -214,15 +223,17 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']))
225
-		date_default_timezone_set($modSettings['default_timezone']);
234
+	if (isset($modSettings['default_timezone'])) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	}
226 237
 
227 238
 	// Check the load averages?
228 239
 	if (!empty($modSettings['loadavg_enable']))
@@ -230,22 +241,26 @@  discard block
 block discarded – undo
230 241
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
231 242
 		{
232 243
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
233
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
234
-				$modSettings['load_average'] = (float) $matches[1];
235
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
236
-				$modSettings['load_average'] = (float) $matches[1];
237
-			else
238
-				unset($modSettings['load_average']);
244
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
245
+							$modSettings['load_average'] = (float) $matches[1];
246
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
247
+							$modSettings['load_average'] = (float) $matches[1];
248
+			} else {
249
+							unset($modSettings['load_average']);
250
+			}
239 251
 
240
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
241
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
252
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
253
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
254
+			}
242 255
 		}
243 256
 
244
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
245
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
257
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
258
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
259
+		}
246 260
 
247
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
248
-			display_loadavg_error();
261
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
262
+					display_loadavg_error();
263
+		}
249 264
 	}
250 265
 
251 266
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -266,8 +281,9 @@  discard block
 block discarded – undo
266 281
 	if (defined('SMF_INTEGRATION_SETTINGS'))
267 282
 	{
268 283
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
269
-		foreach ($integration_settings as $hook => $function)
270
-			add_integration_function($hook, $function, '', false);
284
+		foreach ($integration_settings as $hook => $function) {
285
+					add_integration_function($hook, $function, '', false);
286
+		}
271 287
 	}
272 288
 
273 289
 	// Any files to pre include?
@@ -277,8 +293,9 @@  discard block
 block discarded – undo
277 293
 		foreach ($pre_includes as $include)
278 294
 		{
279 295
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
280
-			if (file_exists($include))
281
-				require_once($include);
296
+			if (file_exists($include)) {
297
+							require_once($include);
298
+			}
282 299
 		}
283 300
 	}
284 301
 
@@ -382,27 +399,28 @@  discard block
 block discarded – undo
382 399
 				break;
383 400
 			}
384 401
 		}
402
+	} else {
403
+			$id_member = 0;
385 404
 	}
386
-	else
387
-		$id_member = 0;
388 405
 
389 406
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
390 407
 	{
391 408
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
392 409
 
393
-		if (empty($cookie_data))
394
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
410
+		if (empty($cookie_data)) {
411
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
412
+		}
395 413
 
396 414
 		list ($id_member, $password) = $cookie_data;
397 415
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
398
-	}
399
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
416
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
400 417
 	{
401 418
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
402 419
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
403 420
 
404
-		if (empty($cookie_data))
405
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
421
+		if (empty($cookie_data)) {
422
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
423
+		}
406 424
 
407 425
 		list ($id_member, $password, $login_span) = $cookie_data;
408 426
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -427,30 +445,34 @@  discard block
 block discarded – undo
427 445
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
428 446
 			$smcFunc['db_free_result']($request);
429 447
 
430
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
431
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
448
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
449
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
450
+			}
432 451
 
433
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
434
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
452
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
453
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
454
+			}
435 455
 		}
436 456
 
437 457
 		// Did we find 'im?  If not, junk it.
438 458
 		if (!empty($user_settings))
439 459
 		{
440 460
 			// As much as the password should be right, we can assume the integration set things up.
441
-			if (!empty($already_verified) && $already_verified === true)
442
-				$check = true;
461
+			if (!empty($already_verified) && $already_verified === true) {
462
+							$check = true;
463
+			}
443 464
 			// SHA-512 hash should be 128 characters long.
444
-			elseif (strlen($password) == 128)
445
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
446
-			else
447
-				$check = false;
465
+			elseif (strlen($password) == 128) {
466
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
+			} else {
468
+							$check = false;
469
+			}
448 470
 
449 471
 			// Wrong password or not activated - either way, you're going nowhere.
450 472
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
473
+		} else {
474
+					$id_member = 0;
451 475
 		}
452
-		else
453
-			$id_member = 0;
454 476
 
455 477
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
456 478
 		if (!$id_member)
@@ -472,13 +494,15 @@  discard block
 block discarded – undo
472 494
 				{
473 495
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
474 496
 
475
-					if (is_null($tfa_data))
476
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
497
+					if (is_null($tfa_data)) {
498
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
499
+					}
477 500
 
478 501
 					list ($tfamember, $tfasecret) = $tfa_data;
479 502
 
480
-					if ((int) $tfamember != $id_member)
481
-						$tfasecret = null;
503
+					if ((int) $tfamember != $id_member) {
504
+											$tfasecret = null;
505
+					}
482 506
 				}
483 507
 
484 508
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -498,10 +522,12 @@  discard block
 block discarded – undo
498 522
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
499 523
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
500 524
 		{
501
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
525
+			if ($modSettings['tfa_mode'] == 2) {
526
+				//only do this if we are just forcing SOME membergroups
502 527
 			{
503 528
 				//Build an array of ALL user membergroups.
504 529
 				$full_groups = array($user_settings['id_group']);
530
+			}
505 531
 				if (!empty($user_settings['additional_groups']))
506 532
 				{
507 533
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -521,15 +547,17 @@  discard block
 block discarded – undo
521 547
 				);
522 548
 				$row = $smcFunc['db_fetch_assoc']($request);
523 549
 				$smcFunc['db_free_result']($request);
550
+			} else {
551
+							$row['total'] = 1;
524 552
 			}
525
-			else
526
-				$row['total'] = 1; //simplifies logics in the next "if"
553
+			//simplifies logics in the next "if"
527 554
 
528 555
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
529 556
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
530 557
 
531
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
532
-				redirectexit('action=profile;area=tfasetup;forced');
558
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
559
+							redirectexit('action=profile;area=tfasetup;forced');
560
+			}
533 561
 		}
534 562
 	}
535 563
 
@@ -566,33 +594,37 @@  discard block
 block discarded – undo
566 594
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
567 595
 				$user_settings['last_login'] = time();
568 596
 
569
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
570
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
597
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
598
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
599
+				}
571 600
 
572
-				if (!empty($modSettings['cache_enable']))
573
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
601
+				if (!empty($modSettings['cache_enable'])) {
602
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
603
+				}
574 604
 			}
605
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
606
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
575 607
 		}
576
-		elseif (empty($_SESSION['id_msg_last_visit']))
577
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
578 608
 
579 609
 		$username = $user_settings['member_name'];
580 610
 
581
-		if (empty($user_settings['additional_groups']))
582
-			$user_info = array(
611
+		if (empty($user_settings['additional_groups'])) {
612
+					$user_info = array(
583 613
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
584 614
 			);
585
-		else
586
-			$user_info = array(
615
+		} else {
616
+					$user_info = array(
587 617
 				'groups' => array_merge(
588 618
 					array($user_settings['id_group'], $user_settings['id_post_group']),
589 619
 					explode(',', $user_settings['additional_groups'])
590 620
 				)
591 621
 			);
622
+		}
592 623
 
593 624
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
594
-		foreach ($user_info['groups'] as $k => $v)
595
-			$user_info['groups'][$k] = (int) $v;
625
+		foreach ($user_info['groups'] as $k => $v) {
626
+					$user_info['groups'][$k] = (int) $v;
627
+		}
596 628
 
597 629
 		// This is a logged in user, so definitely not a spider.
598 630
 		$user_info['possibly_robot'] = false;
@@ -606,8 +638,7 @@  discard block
 block discarded – undo
606 638
 			$time_system = new DateTime('now', $tz_system);
607 639
 			$time_user = new DateTime('now', $tz_user);
608 640
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
609
-		}
610
-		else
641
+		} else
611 642
 		{
612 643
 			// !!! Compatibility.
613 644
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -621,16 +652,18 @@  discard block
 block discarded – undo
621 652
 		$user_info = array('groups' => array(-1));
622 653
 		$user_settings = array();
623 654
 
624
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
625
-			$_COOKIE[$cookiename] = '';
655
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
656
+					$_COOKIE[$cookiename] = '';
657
+		}
626 658
 
627 659
 		// Expire the 2FA cookie
628 660
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
629 661
 		{
630 662
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
631 663
 
632
-			if (is_null($tfa_data))
633
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
664
+			if (is_null($tfa_data)) {
665
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
666
+			}
634 667
 
635 668
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
636 669
 
@@ -642,19 +675,20 @@  discard block
 block discarded – undo
642 675
 		}
643 676
 
644 677
 		// Create a login token if it doesn't exist yet.
645
-		if (!isset($_SESSION['token']['post-login']))
646
-			createToken('login');
647
-		else
648
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
678
+		if (!isset($_SESSION['token']['post-login'])) {
679
+					createToken('login');
680
+		} else {
681
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
682
+		}
649 683
 
650 684
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
651 685
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
652 686
 		{
653 687
 			require_once($sourcedir . '/ManageSearchEngines.php');
654 688
 			$user_info['possibly_robot'] = SpiderCheck();
689
+		} elseif (!empty($modSettings['spider_mode'])) {
690
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
655 691
 		}
656
-		elseif (!empty($modSettings['spider_mode']))
657
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
658 692
 		// If we haven't turned on proper spider hunts then have a guess!
659 693
 		else
660 694
 		{
@@ -702,8 +736,9 @@  discard block
 block discarded – undo
702 736
 	$user_info['groups'] = array_unique($user_info['groups']);
703 737
 
704 738
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
705
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
706
-		unset($user_info['ignoreboards'][$tmp]);
739
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
740
+			unset($user_info['ignoreboards'][$tmp]);
741
+	}
707 742
 
708 743
 	// Allow the user to change their language.
709 744
 	if (!empty($modSettings['userLanguage']))
@@ -716,31 +751,36 @@  discard block
 block discarded – undo
716 751
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
717 752
 
718 753
 			// Make it permanent for members.
719
-			if (!empty($user_info['id']))
720
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
721
-			else
722
-				$_SESSION['language'] = $user_info['language'];
754
+			if (!empty($user_info['id'])) {
755
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
756
+			} else {
757
+							$_SESSION['language'] = $user_info['language'];
758
+			}
759
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
760
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
723 761
 		}
724
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
725
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
726 762
 	}
727 763
 
728 764
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
729
-	if ($user_info['is_admin'])
730
-		$user_info['query_see_board'] = '1=1';
765
+	if ($user_info['is_admin']) {
766
+			$user_info['query_see_board'] = '1=1';
767
+	}
731 768
 	// Otherwise just the groups in $user_info['groups'].
732
-	else
733
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
769
+	else {
770
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
771
+	}
734 772
 
735 773
 	// Build the list of boards they WANT to see.
736 774
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
737 775
 
738 776
 	// If they aren't ignoring any boards then they want to see all the boards they can see
739
-	if (empty($user_info['ignoreboards']))
740
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
777
+	if (empty($user_info['ignoreboards'])) {
778
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
779
+	}
741 780
 	// Ok I guess they don't want to see all the boards
742
-	else
743
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
781
+	else {
782
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
783
+	}
744 784
 
745 785
 	call_integration_hook('integrate_user_info');
746 786
 }
@@ -798,9 +838,9 @@  discard block
 block discarded – undo
798 838
 		}
799 839
 
800 840
 		// Remember redirection is the key to avoiding fallout from your bosses.
801
-		if (!empty($topic))
802
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
803
-		else
841
+		if (!empty($topic)) {
842
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
843
+		} else
804 844
 		{
805 845
 			loadPermissions();
806 846
 			loadTheme();
@@ -818,10 +858,11 @@  discard block
 block discarded – undo
818 858
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
819 859
 	{
820 860
 		// @todo SLOW?
821
-		if (!empty($topic))
822
-			$temp = cache_get_data('topic_board-' . $topic, 120);
823
-		else
824
-			$temp = cache_get_data('board-' . $board, 120);
861
+		if (!empty($topic)) {
862
+					$temp = cache_get_data('topic_board-' . $topic, 120);
863
+		} else {
864
+					$temp = cache_get_data('board-' . $board, 120);
865
+		}
825 866
 
826 867
 		if (!empty($temp))
827 868
 		{
@@ -859,8 +900,9 @@  discard block
 block discarded – undo
859 900
 			$row = $smcFunc['db_fetch_assoc']($request);
860 901
 
861 902
 			// Set the current board.
862
-			if (!empty($row['id_board']))
863
-				$board = $row['id_board'];
903
+			if (!empty($row['id_board'])) {
904
+							$board = $row['id_board'];
905
+			}
864 906
 
865 907
 			// Basic operating information. (globals... :/)
866 908
 			$board_info = array(
@@ -896,21 +938,23 @@  discard block
 block discarded – undo
896 938
 
897 939
 			do
898 940
 			{
899
-				if (!empty($row['id_moderator']))
900
-					$board_info['moderators'][$row['id_moderator']] = array(
941
+				if (!empty($row['id_moderator'])) {
942
+									$board_info['moderators'][$row['id_moderator']] = array(
901 943
 						'id' => $row['id_moderator'],
902 944
 						'name' => $row['real_name'],
903 945
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
904 946
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
905 947
 					);
948
+				}
906 949
 
907
-				if (!empty($row['id_moderator_group']))
908
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
950
+				if (!empty($row['id_moderator_group'])) {
951
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
909 952
 						'id' => $row['id_moderator_group'],
910 953
 						'name' => $row['group_name'],
911 954
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
912 955
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
913 956
 					);
957
+				}
914 958
 			}
915 959
 			while ($row = $smcFunc['db_fetch_assoc']($request));
916 960
 
@@ -942,12 +986,12 @@  discard block
 block discarded – undo
942 986
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
943 987
 			{
944 988
 				// @todo SLOW?
945
-				if (!empty($topic))
946
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
989
+				if (!empty($topic)) {
990
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
991
+				}
947 992
 				cache_put_data('board-' . $board, $board_info, 120);
948 993
 			}
949
-		}
950
-		else
994
+		} else
951 995
 		{
952 996
 			// Otherwise the topic is invalid, there are no moderators, etc.
953 997
 			$board_info = array(
@@ -961,8 +1005,9 @@  discard block
 block discarded – undo
961 1005
 		$smcFunc['db_free_result']($request);
962 1006
 	}
963 1007
 
964
-	if (!empty($topic))
965
-		$_GET['board'] = (int) $board;
1008
+	if (!empty($topic)) {
1009
+			$_GET['board'] = (int) $board;
1010
+	}
966 1011
 
967 1012
 	if (!empty($board))
968 1013
 	{
@@ -972,10 +1017,12 @@  discard block
 block discarded – undo
972 1017
 		// Now check if the user is a moderator.
973 1018
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
974 1019
 
975
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
976
-			$board_info['error'] = 'access';
977
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
978
-			$board_info['error'] = 'access';
1020
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1021
+					$board_info['error'] = 'access';
1022
+		}
1023
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1024
+					$board_info['error'] = 'access';
1025
+		}
979 1026
 
980 1027
 		// Build up the linktree.
981 1028
 		$context['linktree'] = array_merge(
@@ -998,8 +1045,9 @@  discard block
 block discarded – undo
998 1045
 	$context['current_board'] = $board;
999 1046
 
1000 1047
 	// No posting in redirection boards!
1001
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1002
-		$board_info['error'] == 'post_in_redirect';
1048
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1049
+			$board_info['error'] == 'post_in_redirect';
1050
+	}
1003 1051
 
1004 1052
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1005 1053
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1025,24 +1073,23 @@  discard block
 block discarded – undo
1025 1073
 			ob_end_clean();
1026 1074
 			header('HTTP/1.1 403 Forbidden');
1027 1075
 			die;
1028
-		}
1029
-		elseif ($board_info['error'] == 'post_in_redirect')
1076
+		} elseif ($board_info['error'] == 'post_in_redirect')
1030 1077
 		{
1031 1078
 			// Slightly different error message here...
1032 1079
 			fatal_lang_error('cannot_post_redirect', false);
1033
-		}
1034
-		elseif ($user_info['is_guest'])
1080
+		} elseif ($user_info['is_guest'])
1035 1081
 		{
1036 1082
 			loadLanguage('Errors');
1037 1083
 			is_not_guest($txt['topic_gone']);
1084
+		} else {
1085
+					fatal_lang_error('topic_gone', false);
1038 1086
 		}
1039
-		else
1040
-			fatal_lang_error('topic_gone', false);
1041 1087
 	}
1042 1088
 
1043
-	if ($user_info['is_mod'])
1044
-		$user_info['groups'][] = 3;
1045
-}
1089
+	if ($user_info['is_mod']) {
1090
+			$user_info['groups'][] = 3;
1091
+	}
1092
+	}
1046 1093
 
1047 1094
 /**
1048 1095
  * Load this user's permissions.
@@ -1063,8 +1110,9 @@  discard block
 block discarded – undo
1063 1110
 		asort($cache_groups);
1064 1111
 		$cache_groups = implode(',', $cache_groups);
1065 1112
 		// If it's a spider then cache it different.
1066
-		if ($user_info['possibly_robot'])
1067
-			$cache_groups .= '-spider';
1113
+		if ($user_info['possibly_robot']) {
1114
+					$cache_groups .= '-spider';
1115
+		}
1068 1116
 
1069 1117
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1070 1118
 		{
@@ -1072,9 +1120,9 @@  discard block
 block discarded – undo
1072 1120
 			banPermissions();
1073 1121
 
1074 1122
 			return;
1123
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1124
+					list ($user_info['permissions'], $removals) = $temp;
1075 1125
 		}
1076
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1077
-			list ($user_info['permissions'], $removals) = $temp;
1078 1126
 	}
1079 1127
 
1080 1128
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1096,23 +1144,26 @@  discard block
 block discarded – undo
1096 1144
 		$removals = array();
1097 1145
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1098 1146
 		{
1099
-			if (empty($row['add_deny']))
1100
-				$removals[] = $row['permission'];
1101
-			else
1102
-				$user_info['permissions'][] = $row['permission'];
1147
+			if (empty($row['add_deny'])) {
1148
+							$removals[] = $row['permission'];
1149
+			} else {
1150
+							$user_info['permissions'][] = $row['permission'];
1151
+			}
1103 1152
 		}
1104 1153
 		$smcFunc['db_free_result']($request);
1105 1154
 
1106
-		if (isset($cache_groups))
1107
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1155
+		if (isset($cache_groups)) {
1156
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1157
+		}
1108 1158
 	}
1109 1159
 
1110 1160
 	// Get the board permissions.
1111 1161
 	if (!empty($board))
1112 1162
 	{
1113 1163
 		// Make sure the board (if any) has been loaded by loadBoard().
1114
-		if (!isset($board_info['profile']))
1115
-			fatal_lang_error('no_board');
1164
+		if (!isset($board_info['profile'])) {
1165
+					fatal_lang_error('no_board');
1166
+		}
1116 1167
 
1117 1168
 		$request = $smcFunc['db_query']('', '
1118 1169
 			SELECT permission, add_deny
@@ -1128,20 +1179,23 @@  discard block
 block discarded – undo
1128 1179
 		);
1129 1180
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1130 1181
 		{
1131
-			if (empty($row['add_deny']))
1132
-				$removals[] = $row['permission'];
1133
-			else
1134
-				$user_info['permissions'][] = $row['permission'];
1182
+			if (empty($row['add_deny'])) {
1183
+							$removals[] = $row['permission'];
1184
+			} else {
1185
+							$user_info['permissions'][] = $row['permission'];
1186
+			}
1135 1187
 		}
1136 1188
 		$smcFunc['db_free_result']($request);
1137 1189
 	}
1138 1190
 
1139 1191
 	// Remove all the permissions they shouldn't have ;).
1140
-	if (!empty($modSettings['permission_enable_deny']))
1141
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1192
+	if (!empty($modSettings['permission_enable_deny'])) {
1193
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1194
+	}
1142 1195
 
1143
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1144
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1196
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1197
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1198
+	}
1145 1199
 
1146 1200
 	// Banned?  Watch, don't touch..
1147 1201
 	banPermissions();
@@ -1153,17 +1207,18 @@  discard block
 block discarded – undo
1153 1207
 		{
1154 1208
 			require_once($sourcedir . '/Subs-Auth.php');
1155 1209
 			rebuildModCache();
1210
+		} else {
1211
+					$user_info['mod_cache'] = $_SESSION['mc'];
1156 1212
 		}
1157
-		else
1158
-			$user_info['mod_cache'] = $_SESSION['mc'];
1159 1213
 
1160 1214
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1161 1215
 		// For example this drastically simplifies certain changes to the profile area.
1162 1216
 		$user_info['permissions'][] = 'is_not_guest';
1163 1217
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1164 1218
 		$user_info['permissions'][] = 'profile_view_own';
1165
-		if (in_array('profile_view', $user_info['permissions']))
1166
-			$user_info['permissions'][] = 'profile_view_any';
1219
+		if (in_array('profile_view', $user_info['permissions'])) {
1220
+					$user_info['permissions'][] = 'profile_view_any';
1221
+		}
1167 1222
 	}
1168 1223
 }
1169 1224
 
@@ -1181,8 +1236,9 @@  discard block
 block discarded – undo
1181 1236
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1182 1237
 
1183 1238
 	// Can't just look for no users :P.
1184
-	if (empty($users))
1185
-		return array();
1239
+	if (empty($users)) {
1240
+			return array();
1241
+	}
1186 1242
 
1187 1243
 	// Pass the set value
1188 1244
 	$context['loadMemberContext_set'] = $set;
@@ -1197,8 +1253,9 @@  discard block
 block discarded – undo
1197 1253
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1198 1254
 		{
1199 1255
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1200
-			if ($data == null)
1201
-				continue;
1256
+			if ($data == null) {
1257
+							continue;
1258
+			}
1202 1259
 
1203 1260
 			$loaded_ids[] = $data['id_member'];
1204 1261
 			$user_profile[$data['id_member']] = $data;
@@ -1262,13 +1319,16 @@  discard block
 block discarded – undo
1262 1319
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1263 1320
 		{
1264 1321
 			// Take care of proxying avatar if required, do this here for maximum reach
1265
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1266
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1322
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1323
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1324
+			}
1267 1325
 
1268
-			if ( isset($row['member_ip']) )
1269
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1270
-			if ( isset($row['member_ip2']) )
1271
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1326
+			if ( isset($row['member_ip']) ) {
1327
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1328
+			}
1329
+			if ( isset($row['member_ip2']) ) {
1330
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1331
+			}
1272 1332
 			$new_loaded_ids[] = $row['id_member'];
1273 1333
 			$loaded_ids[] = $row['id_member'];
1274 1334
 			$row['options'] = array();
@@ -1287,8 +1347,9 @@  discard block
 block discarded – undo
1287 1347
 				'loaded_ids' => $new_loaded_ids,
1288 1348
 			)
1289 1349
 		);
1290
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1291
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1350
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1351
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1352
+		}
1292 1353
 		$smcFunc['db_free_result']($request);
1293 1354
 	}
1294 1355
 
@@ -1299,10 +1360,11 @@  discard block
 block discarded – undo
1299 1360
 	{
1300 1361
 		foreach ($loaded_ids as $a_member)
1301 1362
 		{
1302
-			if (!empty($user_profile[$a_member]['additional_groups']))
1303
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1304
-			else
1305
-				$groups = array($user_profile[$a_member]['id_group']);
1363
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1364
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1365
+			} else {
1366
+							$groups = array($user_profile[$a_member]['id_group']);
1367
+			}
1306 1368
 
1307 1369
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1308 1370
 
@@ -1315,8 +1377,9 @@  discard block
 block discarded – undo
1315 1377
 
1316 1378
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1317 1379
 	{
1318
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1319
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1380
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1381
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1382
+		}
1320 1383
 	}
1321 1384
 
1322 1385
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1342,14 +1405,17 @@  discard block
 block discarded – undo
1342 1405
 		foreach ($temp_mods as $id)
1343 1406
 		{
1344 1407
 			// By popular demand, don't show admins or global moderators as moderators.
1345
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1346
-				$user_profile[$id]['member_group'] = $row['member_group'];
1408
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1409
+							$user_profile[$id]['member_group'] = $row['member_group'];
1410
+			}
1347 1411
 
1348 1412
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1349
-			if (!empty($row['icons']))
1350
-				$user_profile[$id]['icons'] = $row['icons'];
1351
-			if (!empty($row['member_group_color']))
1352
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1413
+			if (!empty($row['icons'])) {
1414
+							$user_profile[$id]['icons'] = $row['icons'];
1415
+			}
1416
+			if (!empty($row['member_group_color'])) {
1417
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1418
+			}
1353 1419
 		}
1354 1420
 	}
1355 1421
 
@@ -1371,12 +1437,14 @@  discard block
 block discarded – undo
1371 1437
 	static $loadedLanguages = array();
1372 1438
 
1373 1439
 	// If this person's data is already loaded, skip it.
1374
-	if (isset($dataLoaded[$user]))
1375
-		return true;
1440
+	if (isset($dataLoaded[$user])) {
1441
+			return true;
1442
+	}
1376 1443
 
1377 1444
 	// We can't load guests or members not loaded by loadMemberData()!
1378
-	if ($user == 0)
1379
-		return false;
1445
+	if ($user == 0) {
1446
+			return false;
1447
+	}
1380 1448
 	if (!isset($user_profile[$user]))
1381 1449
 	{
1382 1450
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1402,12 +1470,16 @@  discard block
 block discarded – undo
1402 1470
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1403 1471
 
1404 1472
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1405
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1473
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1474
+		//icon is set and exists
1406 1475
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1407
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1476
+	} elseif (isset($profile['icons'][1])) {
1477
+		//icon is set and doesn't exist, fallback to default
1408 1478
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1409
-	else //not set, bye bye
1479
+	} else {
1480
+		//not set, bye bye
1410 1481
 		$group_icon_url = '';
1482
+	}
1411 1483
 
1412 1484
 	// These minimal values are always loaded
1413 1485
 	$memberContext[$user] = array(
@@ -1426,8 +1498,9 @@  discard block
 block discarded – undo
1426 1498
 	if ($context['loadMemberContext_set'] != 'minimal')
1427 1499
 	{
1428 1500
 		// Go the extra mile and load the user's native language name.
1429
-		if (empty($loadedLanguages))
1430
-			$loadedLanguages = getLanguages();
1501
+		if (empty($loadedLanguages)) {
1502
+					$loadedLanguages = getLanguages();
1503
+		}
1431 1504
 
1432 1505
 		$memberContext[$user] += array(
1433 1506
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
@@ -1481,31 +1554,33 @@  discard block
 block discarded – undo
1481 1554
 	{
1482 1555
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1483 1556
 		{
1484
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1485
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1486
-			else
1487
-				$image = get_gravatar_url($profile['email_address']);
1488
-		}
1489
-		else
1557
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1558
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1559
+			} else {
1560
+							$image = get_gravatar_url($profile['email_address']);
1561
+			}
1562
+		} else
1490 1563
 		{
1491 1564
 			// So it's stored in the member table?
1492 1565
 			if (!empty($profile['avatar']))
1493 1566
 			{
1494 1567
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1568
+			} elseif (!empty($profile['filename'])) {
1569
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1495 1570
 			}
1496
-			elseif (!empty($profile['filename']))
1497
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1498 1571
 			// Right... no avatar...use the default one
1499
-			else
1500
-				$image = $modSettings['avatar_url'] . '/default.png';
1572
+			else {
1573
+							$image = $modSettings['avatar_url'] . '/default.png';
1574
+			}
1501 1575
 		}
1502
-		if (!empty($image))
1503
-			$memberContext[$user]['avatar'] = array(
1576
+		if (!empty($image)) {
1577
+					$memberContext[$user]['avatar'] = array(
1504 1578
 				'name' => $profile['avatar'],
1505 1579
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1506 1580
 				'href' => $image,
1507 1581
 				'url' => $image,
1508 1582
 			);
1583
+		}
1509 1584
 	}
1510 1585
 
1511 1586
 	// Are we also loading the members custom fields into context?
@@ -1513,35 +1588,41 @@  discard block
 block discarded – undo
1513 1588
 	{
1514 1589
 		$memberContext[$user]['custom_fields'] = array();
1515 1590
 
1516
-		if (!isset($context['display_fields']))
1517
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1591
+		if (!isset($context['display_fields'])) {
1592
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1593
+		}
1518 1594
 
1519 1595
 		foreach ($context['display_fields'] as $custom)
1520 1596
 		{
1521
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1522
-				continue;
1597
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1598
+							continue;
1599
+			}
1523 1600
 
1524 1601
 			$value = $profile['options'][$custom['col_name']];
1525 1602
 
1526 1603
 			// Don't show the "disabled" option for the "gender" field.
1527
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1528
-				continue;
1604
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1605
+							continue;
1606
+			}
1529 1607
 
1530 1608
 			// BBC?
1531
-			if ($custom['bbc'])
1532
-				$value = parse_bbc($value);
1609
+			if ($custom['bbc']) {
1610
+							$value = parse_bbc($value);
1611
+			}
1533 1612
 			// ... or checkbox?
1534
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1535
-				$value = $value ? $txt['yes'] : $txt['no'];
1613
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1614
+							$value = $value ? $txt['yes'] : $txt['no'];
1615
+			}
1536 1616
 
1537 1617
 			// Enclosing the user input within some other text?
1538
-			if (!empty($custom['enclose']))
1539
-				$value = strtr($custom['enclose'], array(
1618
+			if (!empty($custom['enclose'])) {
1619
+							$value = strtr($custom['enclose'], array(
1540 1620
 					'{SCRIPTURL}' => $scripturl,
1541 1621
 					'{IMAGES_URL}' => $settings['images_url'],
1542 1622
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1543 1623
 					'{INPUT}' => $value,
1544 1624
 				));
1625
+			}
1545 1626
 
1546 1627
 			$memberContext[$user]['custom_fields'][] = array(
1547 1628
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1568,8 +1649,9 @@  discard block
 block discarded – undo
1568 1649
 	global $smcFunc, $txt, $scripturl, $settings;
1569 1650
 
1570 1651
 	// Do not waste my time...
1571
-	if (empty($users) || empty($params))
1572
-		return false;
1652
+	if (empty($users) || empty($params)) {
1653
+			return false;
1654
+	}
1573 1655
 
1574 1656
 	// Make sure it's an array.
1575 1657
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1593,31 +1675,36 @@  discard block
 block discarded – undo
1593 1675
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1676
 	{
1595 1677
 		// BBC?
1596
-		if (!empty($row['bbc']))
1597
-			$row['value'] = parse_bbc($row['value']);
1678
+		if (!empty($row['bbc'])) {
1679
+					$row['value'] = parse_bbc($row['value']);
1680
+		}
1598 1681
 
1599 1682
 		// ... or checkbox?
1600
-		elseif (isset($row['type']) && $row['type'] == 'check')
1601
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1683
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1684
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1685
+		}
1602 1686
 
1603 1687
 		// Enclosing the user input within some other text?
1604
-		if (!empty($row['enclose']))
1605
-			$row['value'] = strtr($row['enclose'], array(
1688
+		if (!empty($row['enclose'])) {
1689
+					$row['value'] = strtr($row['enclose'], array(
1606 1690
 				'{SCRIPTURL}' => $scripturl,
1607 1691
 				'{IMAGES_URL}' => $settings['images_url'],
1608 1692
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1609 1693
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1610 1694
 			));
1695
+		}
1611 1696
 
1612 1697
 		// Send a simple array if there is just 1 param
1613
-		if (count($params) == 1)
1614
-			$return[$row['id_member']] = $row;
1698
+		if (count($params) == 1) {
1699
+					$return[$row['id_member']] = $row;
1700
+		}
1615 1701
 
1616 1702
 		// More than 1? knock yourself out...
1617 1703
 		else
1618 1704
 		{
1619
-			if (!isset($return[$row['id_member']]))
1620
-				$return[$row['id_member']] = array();
1705
+			if (!isset($return[$row['id_member']])) {
1706
+							$return[$row['id_member']] = array();
1707
+			}
1621 1708
 
1622 1709
 			$return[$row['id_member']][$row['variable']] = $row;
1623 1710
 		}
@@ -1651,8 +1738,9 @@  discard block
 block discarded – undo
1651 1738
 	global $context;
1652 1739
 
1653 1740
 	// Don't know any browser!
1654
-	if (empty($context['browser']))
1655
-		detectBrowser();
1741
+	if (empty($context['browser'])) {
1742
+			detectBrowser();
1743
+	}
1656 1744
 
1657 1745
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1658 1746
 }
@@ -1670,8 +1758,9 @@  discard block
 block discarded – undo
1670 1758
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1671 1759
 
1672 1760
 	// The theme was specified by parameter.
1673
-	if (!empty($id_theme))
1674
-		$id_theme = (int) $id_theme;
1761
+	if (!empty($id_theme)) {
1762
+			$id_theme = (int) $id_theme;
1763
+	}
1675 1764
 	// The theme was specified by REQUEST.
1676 1765
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1677 1766
 	{
@@ -1679,51 +1768,58 @@  discard block
 block discarded – undo
1679 1768
 		$_SESSION['id_theme'] = $id_theme;
1680 1769
 	}
1681 1770
 	// The theme was specified by REQUEST... previously.
1682
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1683
-		$id_theme = (int) $_SESSION['id_theme'];
1771
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1772
+			$id_theme = (int) $_SESSION['id_theme'];
1773
+	}
1684 1774
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1685
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1686
-		$id_theme = $user_info['theme'];
1775
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1776
+			$id_theme = $user_info['theme'];
1777
+	}
1687 1778
 	// The theme was specified by the board.
1688
-	elseif (!empty($board_info['theme']))
1689
-		$id_theme = $board_info['theme'];
1779
+	elseif (!empty($board_info['theme'])) {
1780
+			$id_theme = $board_info['theme'];
1781
+	}
1690 1782
 	// The theme is the forum's default.
1691
-	else
1692
-		$id_theme = $modSettings['theme_guests'];
1783
+	else {
1784
+			$id_theme = $modSettings['theme_guests'];
1785
+	}
1693 1786
 
1694 1787
 	// Verify the id_theme... no foul play.
1695 1788
 	// Always allow the board specific theme, if they are overriding.
1696
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1697
-		$id_theme = $board_info['theme'];
1789
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1790
+			$id_theme = $board_info['theme'];
1791
+	}
1698 1792
 	// If they have specified a particular theme to use with SSI allow it to be used.
1699
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1700
-		$id_theme = (int) $id_theme;
1701
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1793
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1794
+			$id_theme = (int) $id_theme;
1795
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1702 1796
 	{
1703 1797
 		$themes = explode(',', $modSettings['enableThemes']);
1704
-		if (!in_array($id_theme, $themes))
1705
-			$id_theme = $modSettings['theme_guests'];
1706
-		else
1798
+		if (!in_array($id_theme, $themes)) {
1799
+					$id_theme = $modSettings['theme_guests'];
1800
+		} else {
1801
+					$id_theme = (int) $id_theme;
1802
+		}
1803
+	} else {
1707 1804
 			$id_theme = (int) $id_theme;
1708 1805
 	}
1709
-	else
1710
-		$id_theme = (int) $id_theme;
1711 1806
 
1712 1807
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1713 1808
 
1714 1809
 	// Disable image proxy if we don't have SSL enabled
1715
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1716
-		$image_proxy_enabled = false;
1810
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1811
+			$image_proxy_enabled = false;
1812
+	}
1717 1813
 
1718 1814
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1719 1815
 	{
1720 1816
 		$themeData = $temp;
1721 1817
 		$flag = true;
1818
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1819
+			$themeData = $temp + array($member => array());
1820
+	} else {
1821
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1722 1822
 	}
1723
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1724
-		$themeData = $temp + array($member => array());
1725
-	else
1726
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1727 1823
 
1728 1824
 	if (empty($flag))
1729 1825
 	{
@@ -1742,31 +1838,37 @@  discard block
 block discarded – undo
1742 1838
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1743 1839
 		{
1744 1840
 			// There are just things we shouldn't be able to change as members.
1745
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1746
-				continue;
1841
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1842
+							continue;
1843
+			}
1747 1844
 
1748 1845
 			// If this is the theme_dir of the default theme, store it.
1749
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1750
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1846
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1847
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1848
+			}
1751 1849
 
1752 1850
 			// If this isn't set yet, is a theme option, or is not the default theme..
1753
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1754
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1851
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1852
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1853
+			}
1755 1854
 		}
1756 1855
 		$smcFunc['db_free_result']($result);
1757 1856
 
1758
-		if (!empty($themeData[-1]))
1759
-			foreach ($themeData[-1] as $k => $v)
1857
+		if (!empty($themeData[-1])) {
1858
+					foreach ($themeData[-1] as $k => $v)
1760 1859
 			{
1761 1860
 				if (!isset($themeData[$member][$k]))
1762 1861
 					$themeData[$member][$k] = $v;
1862
+		}
1763 1863
 			}
1764 1864
 
1765
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1766
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1865
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1866
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1867
+		}
1767 1868
 		// Only if we didn't already load that part of the cache...
1768
-		elseif (!isset($temp))
1769
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1869
+		elseif (!isset($temp)) {
1870
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1871
+		}
1770 1872
 	}
1771 1873
 
1772 1874
 	$settings = $themeData[0];
@@ -1783,20 +1885,24 @@  discard block
 block discarded – undo
1783 1885
 	$settings['template_dirs'][] = $settings['theme_dir'];
1784 1886
 
1785 1887
 	// Based on theme (if there is one).
1786
-	if (!empty($settings['base_theme_dir']))
1787
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1888
+	if (!empty($settings['base_theme_dir'])) {
1889
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1890
+	}
1788 1891
 
1789 1892
 	// Lastly the default theme.
1790
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1791
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1893
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1894
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1895
+	}
1792 1896
 
1793
-	if (!$initialize)
1794
-		return;
1897
+	if (!$initialize) {
1898
+			return;
1899
+	}
1795 1900
 
1796 1901
 	// Check to see if we're forcing SSL
1797 1902
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1798
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1799
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1903
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1904
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1905
+	}
1800 1906
 
1801 1907
 	// Check to see if they're accessing it from the wrong place.
1802 1908
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1804,8 +1910,9 @@  discard block
 block discarded – undo
1804 1910
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1805 1911
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1806 1912
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1807
-		if ($temp != '/')
1808
-			$detected_url .= $temp;
1913
+		if ($temp != '/') {
1914
+					$detected_url .= $temp;
1915
+		}
1809 1916
 	}
1810 1917
 	if (isset($detected_url) && $detected_url != $boardurl)
1811 1918
 	{
@@ -1817,8 +1924,9 @@  discard block
 block discarded – undo
1817 1924
 			foreach ($aliases as $alias)
1818 1925
 			{
1819 1926
 				// Rip off all the boring parts, spaces, etc.
1820
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1821
-					$do_fix = true;
1927
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1928
+									$do_fix = true;
1929
+				}
1822 1930
 			}
1823 1931
 		}
1824 1932
 
@@ -1826,20 +1934,22 @@  discard block
 block discarded – undo
1826 1934
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1827 1935
 		{
1828 1936
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1829
-			if (empty($_GET))
1830
-				redirectexit('wwwRedirect');
1831
-			else
1937
+			if (empty($_GET)) {
1938
+							redirectexit('wwwRedirect');
1939
+			} else
1832 1940
 			{
1833 1941
 				list ($k, $v) = each($_GET);
1834 1942
 
1835
-				if ($k != 'wwwRedirect')
1836
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1943
+				if ($k != 'wwwRedirect') {
1944
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1945
+				}
1837 1946
 			}
1838 1947
 		}
1839 1948
 
1840 1949
 		// #3 is just a check for SSL...
1841
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1842
-			$do_fix = true;
1950
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1951
+					$do_fix = true;
1952
+		}
1843 1953
 
1844 1954
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1845 1955
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1873,8 +1983,9 @@  discard block
 block discarded – undo
1873 1983
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1874 1984
 				}
1875 1985
 			}
1876
-			foreach ($context['linktree'] as $k => $dummy)
1877
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1986
+			foreach ($context['linktree'] as $k => $dummy) {
1987
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1988
+			}
1878 1989
 		}
1879 1990
 	}
1880 1991
 	// Set up the contextual user array.
@@ -1893,16 +2004,16 @@  discard block
 block discarded – undo
1893 2004
 			'email' => $user_info['email'],
1894 2005
 			'ignoreusers' => $user_info['ignoreusers'],
1895 2006
 		);
1896
-		if (!$context['user']['is_guest'])
1897
-			$context['user']['name'] = $user_info['name'];
1898
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1899
-			$context['user']['name'] = $txt['guest_title'];
2007
+		if (!$context['user']['is_guest']) {
2008
+					$context['user']['name'] = $user_info['name'];
2009
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2010
+					$context['user']['name'] = $txt['guest_title'];
2011
+		}
1900 2012
 
1901 2013
 		// Determine the current smiley set.
1902 2014
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1903 2015
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1904
-	}
1905
-	else
2016
+	} else
1906 2017
 	{
1907 2018
 		$context['user'] = array(
1908 2019
 			'id' => -1,
@@ -1918,18 +2029,24 @@  discard block
 block discarded – undo
1918 2029
 	}
1919 2030
 
1920 2031
 	// Some basic information...
1921
-	if (!isset($context['html_headers']))
1922
-		$context['html_headers'] = '';
1923
-	if (!isset($context['javascript_files']))
1924
-		$context['javascript_files'] = array();
1925
-	if (!isset($context['css_files']))
1926
-		$context['css_files'] = array();
1927
-	if (!isset($context['css_header']))
1928
-		$context['css_header'] = array();
1929
-	if (!isset($context['javascript_inline']))
1930
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1931
-	if (!isset($context['javascript_vars']))
1932
-		$context['javascript_vars'] = array();
2032
+	if (!isset($context['html_headers'])) {
2033
+			$context['html_headers'] = '';
2034
+	}
2035
+	if (!isset($context['javascript_files'])) {
2036
+			$context['javascript_files'] = array();
2037
+	}
2038
+	if (!isset($context['css_files'])) {
2039
+			$context['css_files'] = array();
2040
+	}
2041
+	if (!isset($context['css_header'])) {
2042
+			$context['css_header'] = array();
2043
+	}
2044
+	if (!isset($context['javascript_inline'])) {
2045
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2046
+	}
2047
+	if (!isset($context['javascript_vars'])) {
2048
+			$context['javascript_vars'] = array();
2049
+	}
1933 2050
 
1934 2051
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1935 2052
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1941,8 +2058,9 @@  discard block
 block discarded – undo
1941 2058
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1942 2059
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1943 2060
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1944
-	if (isset($modSettings['load_average']))
1945
-		$context['load_average'] = $modSettings['load_average'];
2061
+	if (isset($modSettings['load_average'])) {
2062
+			$context['load_average'] = $modSettings['load_average'];
2063
+	}
1946 2064
 
1947 2065
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1948 2066
 	detectBrowser();
@@ -1956,8 +2074,9 @@  discard block
 block discarded – undo
1956 2074
 	// This allows sticking some HTML on the page output - useful for controls.
1957 2075
 	$context['insert_after_template'] = '';
1958 2076
 
1959
-	if (!isset($txt))
1960
-		$txt = array();
2077
+	if (!isset($txt)) {
2078
+			$txt = array();
2079
+	}
1961 2080
 
1962 2081
 	$simpleActions = array(
1963 2082
 		'findmember',
@@ -2003,9 +2122,10 @@  discard block
 block discarded – undo
2003 2122
 
2004 2123
 	// See if theres any extra param to check.
2005 2124
 	$requiresXML = false;
2006
-	foreach ($extraParams as $key => $extra)
2007
-		if (isset($_REQUEST[$extra]))
2125
+	foreach ($extraParams as $key => $extra) {
2126
+			if (isset($_REQUEST[$extra]))
2008 2127
 			$requiresXML = true;
2128
+	}
2009 2129
 
2010 2130
 	// Output is fully XML, so no need for the index template.
2011 2131
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2020,37 +2140,39 @@  discard block
 block discarded – undo
2020 2140
 	{
2021 2141
 		loadLanguage('index+Modifications');
2022 2142
 		$context['template_layers'] = array();
2023
-	}
2024
-
2025
-	else
2143
+	} else
2026 2144
 	{
2027 2145
 		// Custom templates to load, or just default?
2028
-		if (isset($settings['theme_templates']))
2029
-			$templates = explode(',', $settings['theme_templates']);
2030
-		else
2031
-			$templates = array('index');
2146
+		if (isset($settings['theme_templates'])) {
2147
+					$templates = explode(',', $settings['theme_templates']);
2148
+		} else {
2149
+					$templates = array('index');
2150
+		}
2032 2151
 
2033 2152
 		// Load each template...
2034
-		foreach ($templates as $template)
2035
-			loadTemplate($template);
2153
+		foreach ($templates as $template) {
2154
+					loadTemplate($template);
2155
+		}
2036 2156
 
2037 2157
 		// ...and attempt to load their associated language files.
2038 2158
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2039 2159
 		loadLanguage($required_files, '', false);
2040 2160
 
2041 2161
 		// Custom template layers?
2042
-		if (isset($settings['theme_layers']))
2043
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2044
-		else
2045
-			$context['template_layers'] = array('html', 'body');
2162
+		if (isset($settings['theme_layers'])) {
2163
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2164
+		} else {
2165
+					$context['template_layers'] = array('html', 'body');
2166
+		}
2046 2167
 	}
2047 2168
 
2048 2169
 	// Initialize the theme.
2049 2170
 	loadSubTemplate('init', 'ignore');
2050 2171
 
2051 2172
 	// Allow overriding the board wide time/number formats.
2052
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2053
-		$user_info['time_format'] = $txt['time_format'];
2173
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2174
+			$user_info['time_format'] = $txt['time_format'];
2175
+	}
2054 2176
 
2055 2177
 	// Set the character set from the template.
2056 2178
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2058,12 +2180,14 @@  discard block
 block discarded – undo
2058 2180
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2059 2181
 
2060 2182
 	// Guests may still need a name.
2061
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2062
-		$context['user']['name'] = $txt['guest_title'];
2183
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2184
+			$context['user']['name'] = $txt['guest_title'];
2185
+	}
2063 2186
 
2064 2187
 	// Any theme-related strings that need to be loaded?
2065
-	if (!empty($settings['require_theme_strings']))
2066
-		loadLanguage('ThemeStrings', '', false);
2188
+	if (!empty($settings['require_theme_strings'])) {
2189
+			loadLanguage('ThemeStrings', '', false);
2190
+	}
2067 2191
 
2068 2192
 	// Make a special URL for the language.
2069 2193
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2074,8 +2198,9 @@  discard block
 block discarded – undo
2074 2198
 	// Here is my luvly Responsive CSS
2075 2199
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2076 2200
 
2077
-	if ($context['right_to_left'])
2078
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2201
+	if ($context['right_to_left']) {
2202
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2203
+	}
2079 2204
 
2080 2205
 	// We allow theme variants, because we're cool.
2081 2206
 	$context['theme_variant'] = '';
@@ -2083,14 +2208,17 @@  discard block
 block discarded – undo
2083 2208
 	if (!empty($settings['theme_variants']))
2084 2209
 	{
2085 2210
 		// Overriding - for previews and that ilk.
2086
-		if (!empty($_REQUEST['variant']))
2087
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2211
+		if (!empty($_REQUEST['variant'])) {
2212
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2213
+		}
2088 2214
 		// User selection?
2089
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2090
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2215
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2216
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2217
+		}
2091 2218
 		// If not a user variant, select the default.
2092
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2093
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2219
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2220
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2221
+		}
2094 2222
 
2095 2223
 		// Do this to keep things easier in the templates.
2096 2224
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2099,20 +2227,23 @@  discard block
 block discarded – undo
2099 2227
 		if (!empty($context['theme_variant']))
2100 2228
 		{
2101 2229
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2102
-			if ($context['right_to_left'])
2103
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2230
+			if ($context['right_to_left']) {
2231
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2232
+			}
2104 2233
 		}
2105 2234
 	}
2106 2235
 
2107 2236
 	// Let's be compatible with old themes!
2108
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2109
-		$context['template_layers'] = array('main');
2237
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2238
+			$context['template_layers'] = array('main');
2239
+	}
2110 2240
 
2111 2241
 	$context['tabindex'] = 1;
2112 2242
 
2113 2243
 	// Compatibility.
2114
-	if (!isset($settings['theme_version']))
2115
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2244
+	if (!isset($settings['theme_version'])) {
2245
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2246
+	}
2116 2247
 
2117 2248
 	// Default JS variables for use in every theme
2118 2249
 	$context['javascript_vars'] = array(
@@ -2131,18 +2262,18 @@  discard block
 block discarded – undo
2131 2262
 	);
2132 2263
 
2133 2264
 	// Add the JQuery library to the list of files to load.
2134
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2135
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2136
-
2137
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2138
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2139
-
2140
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2141
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2265
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2266
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2267
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2268
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2269
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2270
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2271
+	}
2142 2272
 
2143 2273
 	// Auto loading? template_javascript() will take care of the local half of this.
2144
-	else
2145
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2274
+	else {
2275
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2276
+	}
2146 2277
 
2147 2278
 	// Queue our JQuery plugins!
2148 2279
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2165,12 +2296,12 @@  discard block
 block discarded – undo
2165 2296
 			require_once($sourcedir . '/ScheduledTasks.php');
2166 2297
 
2167 2298
 			// What to do, what to do?!
2168
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2169
-				AutoTask();
2170
-			else
2171
-				ReduceMailQueue();
2172
-		}
2173
-		else
2299
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2300
+							AutoTask();
2301
+			} else {
2302
+							ReduceMailQueue();
2303
+			}
2304
+		} else
2174 2305
 		{
2175 2306
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2176 2307
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2221,8 +2352,9 @@  discard block
 block discarded – undo
2221 2352
 		foreach ($theme_includes as $include)
2222 2353
 		{
2223 2354
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2224
-			if (file_exists($include))
2225
-				require_once($include);
2355
+			if (file_exists($include)) {
2356
+							require_once($include);
2357
+			}
2226 2358
 		}
2227 2359
 	}
2228 2360
 
@@ -2252,16 +2384,19 @@  discard block
 block discarded – undo
2252 2384
 	// Do any style sheets first, cause we're easy with those.
2253 2385
 	if (!empty($style_sheets))
2254 2386
 	{
2255
-		if (!is_array($style_sheets))
2256
-			$style_sheets = array($style_sheets);
2387
+		if (!is_array($style_sheets)) {
2388
+					$style_sheets = array($style_sheets);
2389
+		}
2257 2390
 
2258
-		foreach ($style_sheets as $sheet)
2259
-			loadCSSFile($sheet . '.css', array(), $sheet);
2391
+		foreach ($style_sheets as $sheet) {
2392
+					loadCSSFile($sheet . '.css', array(), $sheet);
2393
+		}
2260 2394
 	}
2261 2395
 
2262 2396
 	// No template to load?
2263
-	if ($template_name === false)
2264
-		return true;
2397
+	if ($template_name === false) {
2398
+			return true;
2399
+	}
2265 2400
 
2266 2401
 	$loaded = false;
2267 2402
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2276,12 +2411,14 @@  discard block
 block discarded – undo
2276 2411
 
2277 2412
 	if ($loaded)
2278 2413
 	{
2279
-		if ($db_show_debug === true)
2280
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2414
+		if ($db_show_debug === true) {
2415
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2416
+		}
2281 2417
 
2282 2418
 		// If they have specified an initialization function for this template, go ahead and call it now.
2283
-		if (function_exists('template_' . $template_name . '_init'))
2284
-			call_user_func('template_' . $template_name . '_init');
2419
+		if (function_exists('template_' . $template_name . '_init')) {
2420
+					call_user_func('template_' . $template_name . '_init');
2421
+		}
2285 2422
 	}
2286 2423
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2287 2424
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2301,13 +2438,14 @@  discard block
 block discarded – undo
2301 2438
 		loadTemplate($template_name);
2302 2439
 	}
2303 2440
 	// Cause an error otherwise.
2304
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2305
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2306
-	elseif ($fatal)
2307
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2308
-	else
2309
-		return false;
2310
-}
2441
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2442
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2443
+	} elseif ($fatal) {
2444
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2445
+	} else {
2446
+			return false;
2447
+	}
2448
+	}
2311 2449
 
2312 2450
 /**
2313 2451
  * Load a sub-template.
@@ -2325,17 +2463,19 @@  discard block
 block discarded – undo
2325 2463
 {
2326 2464
 	global $context, $txt, $db_show_debug;
2327 2465
 
2328
-	if ($db_show_debug === true)
2329
-		$context['debug']['sub_templates'][] = $sub_template_name;
2466
+	if ($db_show_debug === true) {
2467
+			$context['debug']['sub_templates'][] = $sub_template_name;
2468
+	}
2330 2469
 
2331 2470
 	// Figure out what the template function is named.
2332 2471
 	$theme_function = 'template_' . $sub_template_name;
2333
-	if (function_exists($theme_function))
2334
-		$theme_function();
2335
-	elseif ($fatal === false)
2336
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2337
-	elseif ($fatal !== 'ignore')
2338
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2472
+	if (function_exists($theme_function)) {
2473
+			$theme_function();
2474
+	} elseif ($fatal === false) {
2475
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2476
+	} elseif ($fatal !== 'ignore') {
2477
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2478
+	}
2339 2479
 
2340 2480
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2341 2481
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2372,8 +2512,9 @@  discard block
 block discarded – undo
2372 2512
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2373 2513
 
2374 2514
 	// If this is an external file, automatically set this to false.
2375
-	if (!empty($params['external']))
2376
-		$params['minimize'] = false;
2515
+	if (!empty($params['external'])) {
2516
+			$params['minimize'] = false;
2517
+	}
2377 2518
 
2378 2519
 	// Account for shorthand like admin.css?alp21 filenames
2379 2520
 	$has_seed = strpos($fileName, '.css?');
@@ -2390,13 +2531,10 @@  discard block
 block discarded – undo
2390 2531
 			{
2391 2532
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2392 2533
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2534
+			} else {
2535
+							$fileUrl = false;
2393 2536
 			}
2394
-
2395
-			else
2396
-				$fileUrl = false;
2397
-		}
2398
-
2399
-		else
2537
+		} else
2400 2538
 		{
2401 2539
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2402 2540
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2411,12 +2549,14 @@  discard block
 block discarded – undo
2411 2549
 	}
2412 2550
 
2413 2551
 	// Add it to the array for use in the template
2414
-	if (!empty($fileName))
2415
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2552
+	if (!empty($fileName)) {
2553
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2554
+	}
2416 2555
 
2417
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2418
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2419
-}
2556
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2557
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2558
+	}
2559
+	}
2420 2560
 
2421 2561
 /**
2422 2562
  * Add a block of inline css code to be executed later
@@ -2433,8 +2573,9 @@  discard block
 block discarded – undo
2433 2573
 	global $context;
2434 2574
 
2435 2575
 	// Gotta add something...
2436
-	if (empty($css))
2437
-		return false;
2576
+	if (empty($css)) {
2577
+			return false;
2578
+	}
2438 2579
 
2439 2580
 	$context['css_header'][] = $css;
2440 2581
 }
@@ -2469,8 +2610,9 @@  discard block
 block discarded – undo
2469 2610
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2470 2611
 
2471 2612
 	// If this is an external file, automatically set this to false.
2472
-	if (!empty($params['external']))
2473
-		$params['minimize'] = false;
2613
+	if (!empty($params['external'])) {
2614
+			$params['minimize'] = false;
2615
+	}
2474 2616
 
2475 2617
 	// Account for shorthand like admin.js?alp21 filenames
2476 2618
 	$has_seed = strpos($fileName, '.js?');
@@ -2487,16 +2629,12 @@  discard block
 block discarded – undo
2487 2629
 			{
2488 2630
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2489 2631
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2490
-			}
2491
-
2492
-			else
2632
+			} else
2493 2633
 			{
2494 2634
 				$fileUrl = false;
2495 2635
 				$filePath = false;
2496 2636
 			}
2497
-		}
2498
-
2499
-		else
2637
+		} else
2500 2638
 		{
2501 2639
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2502 2640
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2511,9 +2649,10 @@  discard block
 block discarded – undo
2511 2649
 	}
2512 2650
 
2513 2651
 	// Add it to the array for use in the template
2514
-	if (!empty($fileName))
2515
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2516
-}
2652
+	if (!empty($fileName)) {
2653
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2654
+	}
2655
+	}
2517 2656
 
2518 2657
 /**
2519 2658
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2527,9 +2666,10 @@  discard block
 block discarded – undo
2527 2666
 {
2528 2667
 	global $context;
2529 2668
 
2530
-	if (!empty($key) && (!empty($value) || $value === '0'))
2531
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2532
-}
2669
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2670
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2671
+	}
2672
+	}
2533 2673
 
2534 2674
 /**
2535 2675
  * Add a block of inline Javascript code to be executed later
@@ -2546,8 +2686,9 @@  discard block
 block discarded – undo
2546 2686
 {
2547 2687
 	global $context;
2548 2688
 
2549
-	if (empty($javascript))
2550
-		return false;
2689
+	if (empty($javascript)) {
2690
+			return false;
2691
+	}
2551 2692
 
2552 2693
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2553 2694
 }
@@ -2568,15 +2709,18 @@  discard block
 block discarded – undo
2568 2709
 	static $already_loaded = array();
2569 2710
 
2570 2711
 	// Default to the user's language.
2571
-	if ($lang == '')
2572
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2712
+	if ($lang == '') {
2713
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2714
+	}
2573 2715
 
2574 2716
 	// Do we want the English version of language file as fallback?
2575
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2576
-		loadLanguage($template_name, 'english', false);
2717
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2718
+			loadLanguage($template_name, 'english', false);
2719
+	}
2577 2720
 
2578
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2579
-		return $lang;
2721
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2722
+			return $lang;
2723
+	}
2580 2724
 
2581 2725
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2582 2726
 	if (empty($settings['default_theme_dir']))
@@ -2587,8 +2731,9 @@  discard block
 block discarded – undo
2587 2731
 
2588 2732
 	// What theme are we in?
2589 2733
 	$theme_name = basename($settings['theme_url']);
2590
-	if (empty($theme_name))
2591
-		$theme_name = 'unknown';
2734
+	if (empty($theme_name)) {
2735
+			$theme_name = 'unknown';
2736
+	}
2592 2737
 
2593 2738
 	// For each file open it up and write it out!
2594 2739
 	foreach (explode('+', $template_name) as $template)
@@ -2667,8 +2812,9 @@  discard block
 block discarded – undo
2667 2812
 	}
2668 2813
 
2669 2814
 	// Keep track of what we're up to soldier.
2670
-	if ($db_show_debug === true)
2671
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2815
+	if ($db_show_debug === true) {
2816
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2817
+	}
2672 2818
 
2673 2819
 	// Remember what we have loaded, and in which language.
2674 2820
 	$already_loaded[$template_name] = $lang;
@@ -2714,8 +2860,9 @@  discard block
 block discarded – undo
2714 2860
 				)
2715 2861
 			);
2716 2862
 			// In the EXTREMELY unlikely event this happens, give an error message.
2717
-			if ($smcFunc['db_num_rows']($result) == 0)
2718
-				fatal_lang_error('parent_not_found', 'critical');
2863
+			if ($smcFunc['db_num_rows']($result) == 0) {
2864
+							fatal_lang_error('parent_not_found', 'critical');
2865
+			}
2719 2866
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2720 2867
 			{
2721 2868
 				if (!isset($boards[$row['id_board']]))
@@ -2732,8 +2879,8 @@  discard block
 block discarded – undo
2732 2879
 					);
2733 2880
 				}
2734 2881
 				// If a moderator exists for this board, add that moderator for all children too.
2735
-				if (!empty($row['id_moderator']))
2736
-					foreach ($boards as $id => $dummy)
2882
+				if (!empty($row['id_moderator'])) {
2883
+									foreach ($boards as $id => $dummy)
2737 2884
 					{
2738 2885
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2739 2886
 							'id' => $row['id_moderator'],
@@ -2741,11 +2888,12 @@  discard block
 block discarded – undo
2741 2888
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2742 2889
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2743 2890
 						);
2891
+				}
2744 2892
 					}
2745 2893
 
2746 2894
 				// If a moderator group exists for this board, add that moderator group for all children too
2747
-				if (!empty($row['id_moderator_group']))
2748
-					foreach ($boards as $id => $dummy)
2895
+				if (!empty($row['id_moderator_group'])) {
2896
+									foreach ($boards as $id => $dummy)
2749 2897
 					{
2750 2898
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2751 2899
 							'id' => $row['id_moderator_group'],
@@ -2753,6 +2901,7 @@  discard block
 block discarded – undo
2753 2901
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2754 2902
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2755 2903
 						);
2904
+				}
2756 2905
 					}
2757 2906
 			}
2758 2907
 			$smcFunc['db_free_result']($result);
@@ -2780,23 +2929,27 @@  discard block
 block discarded – undo
2780 2929
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2781 2930
 	{
2782 2931
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2783
-		if (empty($smcFunc['ucwords']))
2784
-			reloadSettings();
2932
+		if (empty($smcFunc['ucwords'])) {
2933
+					reloadSettings();
2934
+		}
2785 2935
 
2786 2936
 		// If we don't have our theme information yet, let's get it.
2787
-		if (empty($settings['default_theme_dir']))
2788
-			loadTheme(0, false);
2937
+		if (empty($settings['default_theme_dir'])) {
2938
+					loadTheme(0, false);
2939
+		}
2789 2940
 
2790 2941
 		// Default language directories to try.
2791 2942
 		$language_directories = array(
2792 2943
 			$settings['default_theme_dir'] . '/languages',
2793 2944
 		);
2794
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2795
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2945
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2946
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2947
+		}
2796 2948
 
2797 2949
 		// We possibly have a base theme directory.
2798
-		if (!empty($settings['base_theme_dir']))
2799
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2950
+		if (!empty($settings['base_theme_dir'])) {
2951
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2952
+		}
2800 2953
 
2801 2954
 		// Remove any duplicates.
2802 2955
 		$language_directories = array_unique($language_directories);
@@ -2810,20 +2963,21 @@  discard block
 block discarded – undo
2810 2963
 		foreach ($language_directories as $language_dir)
2811 2964
 		{
2812 2965
 			// Can't look in here... doesn't exist!
2813
-			if (!file_exists($language_dir))
2814
-				continue;
2966
+			if (!file_exists($language_dir)) {
2967
+							continue;
2968
+			}
2815 2969
 
2816 2970
 			$dir = dir($language_dir);
2817 2971
 			while ($entry = $dir->read())
2818 2972
 			{
2819 2973
 				// Look for the index language file....
2820
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2821
-					continue;
2822
-
2823
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2824
-					$langName = $langList[$matches[1]];
2974
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2975
+									continue;
2976
+				}
2825 2977
 
2826
-				else
2978
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2979
+									$langName = $langList[$matches[1]];
2980
+				} else
2827 2981
 				{
2828 2982
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2829 2983
 
@@ -2866,20 +3020,23 @@  discard block
 block discarded – undo
2866 3020
 		}
2867 3021
 
2868 3022
 		// Do we need to store the lang list?
2869
-		if (empty($langList))
2870
-			updateSettings(array('langList' => json_encode($catchLang)));
3023
+		if (empty($langList)) {
3024
+					updateSettings(array('langList' => json_encode($catchLang)));
3025
+		}
2871 3026
 
2872 3027
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2873 3028
 		if ($favor_utf8)
2874 3029
 		{
2875
-			foreach ($context['languages'] as $lang)
2876
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3030
+			foreach ($context['languages'] as $lang) {
3031
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2877 3032
 					unset($context['languages'][$lang['filename']]);
3033
+			}
2878 3034
 		}
2879 3035
 
2880 3036
 		// Let's cash in on this deal.
2881
-		if (!empty($modSettings['cache_enable']))
2882
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3037
+		if (!empty($modSettings['cache_enable'])) {
3038
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3039
+		}
2883 3040
 	}
2884 3041
 
2885 3042
 	return $context['languages'];
@@ -2902,8 +3059,9 @@  discard block
 block discarded – undo
2902 3059
 	global $modSettings, $options, $txt;
2903 3060
 	static $censor_vulgar = null, $censor_proper;
2904 3061
 
2905
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2906
-		return $text;
3062
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3063
+			return $text;
3064
+	}
2907 3065
 
2908 3066
 	// If they haven't yet been loaded, load them.
2909 3067
 	if ($censor_vulgar == null)
@@ -2931,9 +3089,9 @@  discard block
 block discarded – undo
2931 3089
 	{
2932 3090
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2933 3091
 		$text = $func($censor_vulgar, $censor_proper, $text);
3092
+	} else {
3093
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2934 3094
 	}
2935
-	else
2936
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2937 3095
 
2938 3096
 	return $text;
2939 3097
 }
@@ -2959,38 +3117,42 @@  discard block
 block discarded – undo
2959 3117
 	@ini_set('track_errors', '1');
2960 3118
 
2961 3119
 	// Don't include the file more than once, if $once is true.
2962
-	if ($once && in_array($filename, $templates))
2963
-		return;
3120
+	if ($once && in_array($filename, $templates)) {
3121
+			return;
3122
+	}
2964 3123
 	// Add this file to the include list, whether $once is true or not.
2965
-	else
2966
-		$templates[] = $filename;
3124
+	else {
3125
+			$templates[] = $filename;
3126
+	}
2967 3127
 
2968 3128
 	// Are we going to use eval?
2969 3129
 	if (empty($modSettings['disableTemplateEval']))
2970 3130
 	{
2971 3131
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2972 3132
 		$settings['current_include_filename'] = $filename;
2973
-	}
2974
-	else
3133
+	} else
2975 3134
 	{
2976 3135
 		$file_found = file_exists($filename);
2977 3136
 
2978
-		if ($once && $file_found)
2979
-			require_once($filename);
2980
-		elseif ($file_found)
2981
-			require($filename);
3137
+		if ($once && $file_found) {
3138
+					require_once($filename);
3139
+		} elseif ($file_found) {
3140
+					require($filename);
3141
+		}
2982 3142
 	}
2983 3143
 
2984 3144
 	if ($file_found !== true)
2985 3145
 	{
2986 3146
 		ob_end_clean();
2987
-		if (!empty($modSettings['enableCompressedOutput']))
2988
-			@ob_start('ob_gzhandler');
2989
-		else
2990
-			ob_start();
3147
+		if (!empty($modSettings['enableCompressedOutput'])) {
3148
+					@ob_start('ob_gzhandler');
3149
+		} else {
3150
+					ob_start();
3151
+		}
2991 3152
 
2992
-		if (isset($_GET['debug']))
2993
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3153
+		if (isset($_GET['debug'])) {
3154
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3155
+		}
2994 3156
 
2995 3157
 		// Don't cache error pages!!
2996 3158
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3009,12 +3171,13 @@  discard block
 block discarded – undo
3009 3171
 		echo '<!DOCTYPE html>
3010 3172
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3011 3173
 	<head>';
3012
-		if (isset($context['character_set']))
3013
-			echo '
3174
+		if (isset($context['character_set'])) {
3175
+					echo '
3014 3176
 		<meta charset="', $context['character_set'], '">';
3177
+		}
3015 3178
 
3016
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3017
-			echo '
3179
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3180
+					echo '
3018 3181
 		<title>', $mtitle, '</title>
3019 3182
 	</head>
3020 3183
 	<body>
@@ -3022,8 +3185,8 @@  discard block
 block discarded – undo
3022 3185
 		', $mmessage, '
3023 3186
 	</body>
3024 3187
 </html>';
3025
-		elseif (!allowedTo('admin_forum'))
3026
-			echo '
3188
+		} elseif (!allowedTo('admin_forum')) {
3189
+					echo '
3027 3190
 		<title>', $txt['template_parse_error'], '</title>
3028 3191
 	</head>
3029 3192
 	<body>
@@ -3031,15 +3194,17 @@  discard block
 block discarded – undo
3031 3194
 		', $txt['template_parse_error_message'], '
3032 3195
 	</body>
3033 3196
 </html>';
3034
-		else
3197
+		} else
3035 3198
 		{
3036 3199
 			require_once($sourcedir . '/Subs-Package.php');
3037 3200
 
3038 3201
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3039
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3040
-				$error = $php_errormsg;
3041
-			if (empty($error))
3042
-				$error = $txt['template_parse_errmsg'];
3202
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3203
+							$error = $php_errormsg;
3204
+			}
3205
+			if (empty($error)) {
3206
+							$error = $txt['template_parse_errmsg'];
3207
+			}
3043 3208
 
3044 3209
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3045 3210
 
@@ -3050,11 +3215,12 @@  discard block
 block discarded – undo
3050 3215
 		<h3>', $txt['template_parse_error'], '</h3>
3051 3216
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3052 3217
 
3053
-			if (!empty($error))
3054
-				echo '
3218
+			if (!empty($error)) {
3219
+							echo '
3055 3220
 		<hr>
3056 3221
 
3057 3222
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3223
+			}
3058 3224
 
3059 3225
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3060 3226
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3064,10 +3230,11 @@  discard block
 block discarded – undo
3064 3230
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3065 3231
 
3066 3232
 				// Fix the PHP code stuff...
3067
-				if (!isBrowser('gecko'))
3068
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3069
-				else
3070
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3233
+				if (!isBrowser('gecko')) {
3234
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3235
+				} else {
3236
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3237
+				}
3071 3238
 
3072 3239
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3073 3240
 				$j = -1;
@@ -3075,8 +3242,9 @@  discard block
 block discarded – undo
3075 3242
 				{
3076 3243
 					$j++;
3077 3244
 
3078
-					if (substr_count($line, '<br>') == 0)
3079
-						continue;
3245
+					if (substr_count($line, '<br>') == 0) {
3246
+											continue;
3247
+					}
3080 3248
 
3081 3249
 					$n = substr_count($line, '<br>');
3082 3250
 					for ($i = 0; $i < $n; $i++)
@@ -3095,38 +3263,42 @@  discard block
 block discarded – undo
3095 3263
 				// Figure out what the color coding was before...
3096 3264
 				$line = max($match[1] - 9, 1);
3097 3265
 				$last_line = '';
3098
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3099
-					if (strpos($data2[$line2], '<') !== false)
3266
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3267
+									if (strpos($data2[$line2], '<') !== false)
3100 3268
 					{
3101 3269
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3102 3270
 							$last_line = $color_match[1];
3271
+				}
3103 3272
 						break;
3104 3273
 					}
3105 3274
 
3106 3275
 				// Show the relevant lines...
3107 3276
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3108 3277
 				{
3109
-					if ($line == $match[1])
3110
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3278
+					if ($line == $match[1]) {
3279
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3280
+					}
3111 3281
 
3112 3282
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3113
-					if (isset($data2[$line]) && $data2[$line] != '')
3114
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3283
+					if (isset($data2[$line]) && $data2[$line] != '') {
3284
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3285
+					}
3115 3286
 
3116 3287
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3117 3288
 					{
3118 3289
 						$last_line = $color_match[1];
3119 3290
 						echo '</', substr($last_line, 1, 4), '>';
3291
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3292
+											$last_line = '';
3293
+					} elseif ($last_line != '' && $data2[$line] != '') {
3294
+											echo '</', substr($last_line, 1, 4), '>';
3120 3295
 					}
3121
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3122
-						$last_line = '';
3123
-					elseif ($last_line != '' && $data2[$line] != '')
3124
-						echo '</', substr($last_line, 1, 4), '>';
3125 3296
 
3126
-					if ($line == $match[1])
3127
-						echo '</pre></div><pre style="margin: 0;">';
3128
-					else
3129
-						echo "\n";
3297
+					if ($line == $match[1]) {
3298
+											echo '</pre></div><pre style="margin: 0;">';
3299
+					} else {
3300
+											echo "\n";
3301
+					}
3130 3302
 				}
3131 3303
 
3132 3304
 				echo '</pre></div>';
@@ -3150,8 +3322,9 @@  discard block
 block discarded – undo
3150 3322
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3151 3323
 
3152 3324
 	// Figure out what type of database we are using.
3153
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3154
-		$db_type = 'mysql';
3325
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3326
+			$db_type = 'mysql';
3327
+	}
3155 3328
 
3156 3329
 	// Load the file for the database.
3157 3330
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3159,8 +3332,9 @@  discard block
 block discarded – undo
3159 3332
 	$db_options = array();
3160 3333
 
3161 3334
 	// Add in the port if needed
3162
-	if (!empty($db_port))
3163
-		$db_options['port'] = $db_port;
3335
+	if (!empty($db_port)) {
3336
+			$db_options['port'] = $db_port;
3337
+	}
3164 3338
 
3165 3339
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3166 3340
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3179,13 +3353,15 @@  discard block
 block discarded – undo
3179 3353
 	}
3180 3354
 
3181 3355
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3182
-	if (!$db_connection)
3183
-		display_db_error();
3356
+	if (!$db_connection) {
3357
+			display_db_error();
3358
+	}
3184 3359
 
3185 3360
 	// If in SSI mode fix up the prefix.
3186
-	if (SMF == 'SSI')
3187
-		db_fix_prefix($db_prefix, $db_name);
3188
-}
3361
+	if (SMF == 'SSI') {
3362
+			db_fix_prefix($db_prefix, $db_name);
3363
+	}
3364
+	}
3189 3365
 
3190 3366
 /**
3191 3367
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3199,10 +3375,11 @@  discard block
 block discarded – undo
3199 3375
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3200 3376
 
3201 3377
 	// Not overriding this and we have a cacheAPI, send it back.
3202
-	if (empty($overrideCache) && is_object($cacheAPI))
3203
-		return $cacheAPI;
3204
-	elseif (is_null($cacheAPI))
3205
-		$cacheAPI = false;
3378
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3379
+			return $cacheAPI;
3380
+	} elseif (is_null($cacheAPI)) {
3381
+			$cacheAPI = false;
3382
+	}
3206 3383
 
3207 3384
 	// Make sure our class is in session.
3208 3385
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3223,8 +3400,9 @@  discard block
 block discarded – undo
3223 3400
 		if (!$testAPI->isSupported())
3224 3401
 		{
3225 3402
 			// Can we save ourselves?
3226
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3227
-				return loadCacheAccelerator(null, false);
3403
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3404
+							return loadCacheAccelerator(null, false);
3405
+			}
3228 3406
 			return false;
3229 3407
 		}
3230 3408
 
@@ -3236,9 +3414,9 @@  discard block
 block discarded – undo
3236 3414
 		{
3237 3415
 			$cacheAPI = $testAPI;
3238 3416
 			return $cacheAPI;
3417
+		} else {
3418
+					return $testAPI;
3239 3419
 		}
3240
-		else
3241
-			return $testAPI;
3242 3420
 	}
3243 3421
 }
3244 3422
 
@@ -3258,8 +3436,9 @@  discard block
 block discarded – undo
3258 3436
 
3259 3437
 	// @todo Why are we doing this if caching is disabled?
3260 3438
 
3261
-	if (function_exists('call_integration_hook'))
3262
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3439
+	if (function_exists('call_integration_hook')) {
3440
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3441
+	}
3263 3442
 
3264 3443
 	/* Refresh the cache if either:
3265 3444
 		1. Caching is disabled.
@@ -3273,16 +3452,19 @@  discard block
 block discarded – undo
3273 3452
 		require_once($sourcedir . '/' . $file);
3274 3453
 		$cache_block = call_user_func_array($function, $params);
3275 3454
 
3276
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3277
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3455
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3456
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3457
+		}
3278 3458
 	}
3279 3459
 
3280 3460
 	// Some cached data may need a freshening up after retrieval.
3281
-	if (!empty($cache_block['post_retri_eval']))
3282
-		eval($cache_block['post_retri_eval']);
3461
+	if (!empty($cache_block['post_retri_eval'])) {
3462
+			eval($cache_block['post_retri_eval']);
3463
+	}
3283 3464
 
3284
-	if (function_exists('call_integration_hook'))
3285
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3465
+	if (function_exists('call_integration_hook')) {
3466
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3467
+	}
3286 3468
 
3287 3469
 	return $cache_block['data'];
3288 3470
 }
@@ -3309,8 +3491,9 @@  discard block
 block discarded – undo
3309 3491
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3310 3492
 	global $cache_hits, $cache_count, $db_show_debug;
3311 3493
 
3312
-	if (empty($cache_enable) || empty($cacheAPI))
3313
-		return;
3494
+	if (empty($cache_enable) || empty($cacheAPI)) {
3495
+			return;
3496
+	}
3314 3497
 
3315 3498
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3316 3499
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3323,12 +3506,14 @@  discard block
 block discarded – undo
3323 3506
 	$value = $value === null ? null : json_encode($value);
3324 3507
 	$result = $cacheAPI->putData($key, $value, $ttl);
3325 3508
 
3326
-	if (function_exists('call_integration_hook'))
3327
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3509
+	if (function_exists('call_integration_hook')) {
3510
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3511
+	}
3328 3512
 
3329
-	if (isset($db_show_debug) && $db_show_debug === true)
3330
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3331
-}
3513
+	if (isset($db_show_debug) && $db_show_debug === true) {
3514
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3515
+	}
3516
+	}
3332 3517
 
3333 3518
 /**
3334 3519
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3344,8 +3529,9 @@  discard block
 block discarded – undo
3344 3529
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3345 3530
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3346 3531
 
3347
-	if (empty($cache_enable) || empty($cacheAPI))
3348
-		return;
3532
+	if (empty($cache_enable) || empty($cacheAPI)) {
3533
+			return;
3534
+	}
3349 3535
 
3350 3536
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3351 3537
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3365,16 +3551,18 @@  discard block
 block discarded – undo
3365 3551
 
3366 3552
 		if (empty($value))
3367 3553
 		{
3368
-			if (!is_array($cache_misses))
3369
-				$cache_misses = array();
3554
+			if (!is_array($cache_misses)) {
3555
+							$cache_misses = array();
3556
+			}
3370 3557
 
3371 3558
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3372 3559
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3373 3560
 		}
3374 3561
 	}
3375 3562
 
3376
-	if (function_exists('call_integration_hook') && isset($value))
3377
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3563
+	if (function_exists('call_integration_hook') && isset($value)) {
3564
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3565
+	}
3378 3566
 
3379 3567
 	return empty($value) ? null : smf_json_decode($value, true);
3380 3568
 }
@@ -3396,8 +3584,9 @@  discard block
 block discarded – undo
3396 3584
 	global $cachedir, $sourcedir, $modSettings;
3397 3585
 
3398 3586
 	// If we can't get to the API, can't do this.
3399
-	if (empty($cacheAPI))
3400
-		return false;
3587
+	if (empty($cacheAPI)) {
3588
+			return false;
3589
+	}
3401 3590
 
3402 3591
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3403 3592
 	$value = $cacheAPI->cleanCache($type);
@@ -3422,8 +3611,9 @@  discard block
 block discarded – undo
3422 3611
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3423 3612
 
3424 3613
 	// Come on!
3425
-	if (empty($data))
3426
-		return array();
3614
+	if (empty($data)) {
3615
+			return array();
3616
+	}
3427 3617
 
3428 3618
 	// Set a nice default var.
3429 3619
 	$image = '';
@@ -3431,11 +3621,11 @@  discard block
 block discarded – undo
3431 3621
 	// Gravatar has been set as mandatory!
3432 3622
 	if (!empty($modSettings['gravatarOverride']))
3433 3623
 	{
3434
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3435
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3436
-
3437
-		else if (!empty($data['email']))
3438
-			$image = get_gravatar_url($data['email']);
3624
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3625
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3626
+		} else if (!empty($data['email'])) {
3627
+					$image = get_gravatar_url($data['email']);
3628
+		}
3439 3629
 	}
3440 3630
 
3441 3631
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3447,54 +3637,60 @@  discard block
 block discarded – undo
3447 3637
 			// Gravatar.
3448 3638
 			if (stristr($data['avatar'], 'gravatar://'))
3449 3639
 			{
3450
-				if ($data['avatar'] == 'gravatar://')
3451
-					$image = get_gravatar_url($data['email']);
3452
-
3453
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3454
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3640
+				if ($data['avatar'] == 'gravatar://') {
3641
+									$image = get_gravatar_url($data['email']);
3642
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3643
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3644
+				}
3455 3645
 			}
3456 3646
 
3457 3647
 			// External url.
3458 3648
 			else
3459 3649
 			{
3460 3650
 				// Using ssl?
3461
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3462
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3651
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3652
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3653
+				}
3463 3654
 
3464 3655
 				// Just a plain external url.
3465
-				else
3466
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3656
+				else {
3657
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3658
+				}
3467 3659
 			}
3468 3660
 		}
3469 3661
 
3470 3662
 		// Perhaps this user has an attachment as avatar...
3471
-		else if (!empty($data['filename']))
3472
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3663
+		else if (!empty($data['filename'])) {
3664
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3665
+		}
3473 3666
 
3474 3667
 		// Right... no avatar... use our default image.
3475
-		else
3476
-			$image = $modSettings['avatar_url'] . '/default.png';
3668
+		else {
3669
+					$image = $modSettings['avatar_url'] . '/default.png';
3670
+		}
3477 3671
 	}
3478 3672
 
3479 3673
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3480 3674
 
3481 3675
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3482
-	if (!empty($image))
3483
-		return array(
3676
+	if (!empty($image)) {
3677
+			return array(
3484 3678
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3485 3679
 			'image' => '<img class="avatar" src="' . $image . '" />',
3486 3680
 			'href' => $image,
3487 3681
 			'url' => $image,
3488 3682
 		);
3683
+	}
3489 3684
 
3490 3685
 	// Fallback to make life easier for everyone...
3491
-	else
3492
-		return array(
3686
+	else {
3687
+			return array(
3493 3688
 			'name' => '',
3494 3689
 			'image' => '',
3495 3690
 			'href' => '',
3496 3691
 			'url' => '',
3497 3692
 		);
3498
-}
3693
+	}
3694
+	}
3499 3695
 
3500 3696
 ?>
3501 3697
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageBans.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
  * Doesn't clean the inputs
930 930
  *
931 931
  * @param array $items_ids The items to remove
932
- * @param bool|int $group_id The ID of the group these triggers are associated with or false if deleting them from all groups
932
+ * @param integer $group_id The ID of the group these triggers are associated with or false if deleting them from all groups
933 933
  * @return bool Always returns true
934 934
  */
935 935
 function removeBanTriggers($items_ids = array(), $group_id = false)
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
  * Errors in $context['ban_errors']
1124 1124
  *
1125 1125
  * @param array $triggers The triggers to validate
1126
- * @return array An array of riggers and log info ready to be used
1126
+ * @return integer An array of riggers and log info ready to be used
1127 1127
  */
1128 1128
 function validateTriggers(&$triggers)
1129 1129
 {
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 		)
785 785
 	);
786 786
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787
-	    $error_ips[] = inet_dtop($row['ip']);
787
+		$error_ips[] = inet_dtop($row['ip']);
788 788
 	$smcFunc['db_free_result']($request);
789 789
 
790 790
 	return $error_ips;
@@ -2168,9 +2168,9 @@  discard block
 block discarded – undo
2168 2168
 
2169 2169
 	if ($low == '255.255.255.255') return 'unknown';
2170 2170
 	if ($low == $high)
2171
-	    return $low;
2171
+		return $low;
2172 2172
 	else
2173
-	    return $low . '-'.$high;
2173
+		return $low . '-'.$high;
2174 2174
 }
2175 2175
 
2176 2176
 /**
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 					'value' => $txt['ban_added'],
184 184
 				),
185 185
 				'data' => array(
186
-					'function' => function ($rowData) use ($context)
186
+					'function' => function($rowData) use ($context)
187 187
 					{
188 188
 						return timeformat($rowData['ban_time'], empty($context['ban_time_format']) ? true : $context['ban_time_format']);
189 189
 					},
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 					'value' => $txt['ban_expires'],
199 199
 				),
200 200
 				'data' => array(
201
-					'function' => function ($rowData) use ($txt)
201
+					'function' => function($rowData) use ($txt)
202 202
 					{
203 203
 						// This ban never expires...whahaha.
204 204
 						if ($rowData['expire_time'] === null)
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 							'style' => 'width: 60%;text-align: left;',
402 402
 						),
403 403
 						'data' => array(
404
-							'function' => function ($ban_item) use ($txt)
404
+							'function' => function($ban_item) use ($txt)
405 405
 							{
406 406
 								if (in_array($ban_item['type'], array('ip', 'hostname', 'email')))
407 407
 									return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 							'style' => 'width: 15%; text-align: center;',
430 430
 						),
431 431
 						'data' => array(
432
-							'function' => function ($ban_item) use ($txt, $context, $scripturl)
432
+							'function' => function($ban_item) use ($txt, $context, $scripturl)
433 433
 							{
434 434
 								return '<a href="' . $scripturl . '?action=admin;area=ban;sa=edittrigger;bg=' . $context['ban_group_id'] . ';bi=' . $ban_item['id'] . '">' . $txt['ban_edit_trigger'] . '</a>';
435 435
 							},
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
 			}
555 555
 
556 556
 			// We come from the mod center.
557
-			elseif(isset($_GET['msg']) && !empty($_GET['msg']))
557
+			elseif (isset($_GET['msg']) && !empty($_GET['msg']))
558 558
 			{
559 559
 				$request = $smcFunc['db_query']('', '
560 560
 					SELECT poster_name, poster_ip, poster_email
@@ -1429,7 +1429,7 @@  discard block
 block discarded – undo
1429 1429
 	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1430 1430
 		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1431 1431
 
1432
-	if(!empty($ban_info['id']))
1432
+	if (!empty($ban_info['id']))
1433 1433
 	{
1434 1434
 		// Verify the ban group exists.
1435 1435
 		$request = $smcFunc['db_query']('', '
@@ -1447,7 +1447,7 @@  discard block
 block discarded – undo
1447 1447
 		$smcFunc['db_free_result']($request);
1448 1448
 	}
1449 1449
 
1450
-	if(!empty($ban_info['name']))
1450
+	if (!empty($ban_info['name']))
1451 1451
 	{
1452 1452
 		// Make sure the name does not already exist (Of course, if it exists in the ban group we are editing, proceed.)
1453 1453
 		$request = $smcFunc['db_query']('', '
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
 	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1517 1517
 		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1518 1518
 
1519
-	if(!empty($ban_info['name']))
1519
+	if (!empty($ban_info['name']))
1520 1520
 	{
1521 1521
 		// Check whether a ban with this name already exists.
1522 1522
 		$request = $smcFunc['db_query']('', '
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
 	if ($context['selected_entity'] === 'ip')
1796 1796
 	{
1797 1797
 		$listOptions['columns']['banned_entity']['data'] = array(
1798
-			'function' => function ($rowData)
1798
+			'function' => function($rowData)
1799 1799
 			{
1800 1800
 				return range2ip(
1801 1801
 					$rowData['ip_low']
@@ -1812,7 +1812,7 @@  discard block
 block discarded – undo
1812 1812
 	elseif ($context['selected_entity'] === 'hostname')
1813 1813
 	{
1814 1814
 		$listOptions['columns']['banned_entity']['data'] = array(
1815
-			'function' => function ($rowData) use ($smcFunc)
1815
+			'function' => function($rowData) use ($smcFunc)
1816 1816
 			{
1817 1817
 				return strtr($smcFunc['htmlspecialchars']($rowData['hostname']), array('%' => '*'));
1818 1818
 			},
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
 	elseif ($context['selected_entity'] === 'email')
1826 1826
 	{
1827 1827
 		$listOptions['columns']['banned_entity']['data'] = array(
1828
-			'function' => function ($rowData) use ($smcFunc)
1828
+			'function' => function($rowData) use ($smcFunc)
1829 1829
 			{
1830 1830
 				return strtr($smcFunc['htmlspecialchars']($rowData['email_address']), array('%' => '*'));
1831 1831
 			},
@@ -2032,7 +2032,7 @@  discard block
 block discarded – undo
2032 2032
 					'value' => $txt['ban_log_date'],
2033 2033
 				),
2034 2034
 				'data' => array(
2035
-					'function' => function ($rowData)
2035
+					'function' => function($rowData)
2036 2036
 					{
2037 2037
 						return timeformat($rowData['log_time']);
2038 2038
 					},
@@ -2122,7 +2122,7 @@  discard block
 block discarded – undo
2122 2122
 	$log_entries = array();
2123 2123
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2124 2124
 	{
2125
-		$row['ip'] = $row['ip'] === null? $dash : inet_dtop($row['ip']);
2125
+		$row['ip'] = $row['ip'] === null ? $dash : inet_dtop($row['ip']);
2126 2126
 		$log_entries[] = $row;
2127 2127
 	}
2128 2128
 	$smcFunc['db_free_result']($request);
@@ -2170,7 +2170,7 @@  discard block
 block discarded – undo
2170 2170
 	if ($low == $high)
2171 2171
 	    return $low;
2172 2172
 	else
2173
-	    return $low . '-'.$high;
2173
+	    return $low . '-' . $high;
2174 2174
 }
2175 2175
 
2176 2176
 /**
@@ -2286,7 +2286,7 @@  discard block
 block discarded – undo
2286 2286
 		$request = $smcFunc['db_query']('', '
2287 2287
 			SELECT mem.id_member, mem.is_activated
2288 2288
 			FROM {db_prefix}members AS mem
2289
-			WHERE ' . implode( ' OR ', $queryPart),
2289
+			WHERE ' . implode(' OR ', $queryPart),
2290 2290
 			$queryValues
2291 2291
 		);
2292 2292
 		while ($row = $smcFunc['db_fetch_assoc']($request))
Please login to merge, or discard this patch.
Braces   +258 added lines, -207 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ban center. The main entrance point for all ban center functions.
@@ -120,10 +121,11 @@  discard block
 block discarded – undo
120 121
 	}
121 122
 
122 123
 	// Create a date string so we don't overload them with date info.
123
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
124
-		$context['ban_time_format'] = $user_info['time_format'];
125
-	else
126
-		$context['ban_time_format'] = $matches[0];
124
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
125
+			$context['ban_time_format'] = $user_info['time_format'];
126
+	} else {
127
+			$context['ban_time_format'] = $matches[0];
128
+	}
127 129
 
128 130
 	$listOptions = array(
129 131
 		'id' => 'ban_list',
@@ -201,16 +203,19 @@  discard block
 block discarded – undo
201 203
 					'function' => function ($rowData) use ($txt)
202 204
 					{
203 205
 						// This ban never expires...whahaha.
204
-						if ($rowData['expire_time'] === null)
205
-							return $txt['never'];
206
+						if ($rowData['expire_time'] === null) {
207
+													return $txt['never'];
208
+						}
206 209
 
207 210
 						// This ban has already expired.
208
-						elseif ($rowData['expire_time'] < time())
209
-							return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
211
+						elseif ($rowData['expire_time'] < time()) {
212
+													return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
213
+						}
210 214
 
211 215
 						// Still need to wait a few days for this ban to expire.
212
-						else
213
-							return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
216
+						else {
217
+													return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
218
+						}
214 219
 					},
215 220
 				),
216 221
 				'sort' => array(
@@ -309,8 +314,9 @@  discard block
 block discarded – undo
309 314
 		)
310 315
 	);
311 316
 	$bans = array();
312
-	while ($row = $smcFunc['db_fetch_assoc']($request))
313
-		$bans[] = $row;
317
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
318
+			$bans[] = $row;
319
+	}
314 320
 
315 321
 	$smcFunc['db_free_result']($request);
316 322
 
@@ -352,8 +358,9 @@  discard block
 block discarded – undo
352 358
 {
353 359
 	global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir;
354 360
 
355
-	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
356
-		BanEdit2();
361
+	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) {
362
+			BanEdit2();
363
+	}
357 364
 
358 365
 	$ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
359 366
 
@@ -364,10 +371,10 @@  discard block
 block discarded – undo
364 371
 
365 372
 	if (!empty($context['ban_errors']))
366 373
 	{
367
-		foreach ($context['ban_errors'] as $error)
368
-			$context['error_messages'][$error] = $txt[$error];
369
-	}
370
-	else
374
+		foreach ($context['ban_errors'] as $error) {
375
+					$context['error_messages'][$error] = $txt[$error];
376
+		}
377
+	} else
371 378
 	{
372 379
 		// If we're editing an existing ban, get it from the database.
373 380
 		if (!empty($ban_group_id))
@@ -403,12 +410,13 @@  discard block
 block discarded – undo
403 410
 						'data' => array(
404 411
 							'function' => function ($ban_item) use ($txt)
405 412
 							{
406
-								if (in_array($ban_item['type'], array('ip', 'hostname', 'email')))
407
-									return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
408
-								elseif ($ban_item['type'] == 'user')
409
-									return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
410
-								else
411
-									return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
413
+								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) {
414
+																	return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
415
+								} elseif ($ban_item['type'] == 'user') {
416
+																	return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
417
+								} else {
418
+																	return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
419
+								}
412 420
 							},
413 421
 							'style' => 'text-align: left;',
414 422
 						),
@@ -546,8 +554,9 @@  discard block
 block discarded – undo
546 554
 					$context['ban']['from_user'] = true;
547 555
 
548 556
 					// Would be nice if we could also ban the hostname.
549
-					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup']))
550
-						$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
557
+					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) {
558
+											$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
559
+					}
551 560
 
552 561
 					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
553 562
 				}
@@ -615,8 +624,9 @@  discard block
 block discarded – undo
615 624
 			'items_per_page' => $items_per_page,
616 625
 		)
617 626
 	);
618
-	if ($smcFunc['db_num_rows']($request) == 0)
619
-		fatal_lang_error('ban_not_found', false);
627
+	if ($smcFunc['db_num_rows']($request) == 0) {
628
+			fatal_lang_error('ban_not_found', false);
629
+	}
620 630
 
621 631
 	while ($row = $smcFunc['db_fetch_assoc']($request))
622 632
 	{
@@ -653,18 +663,15 @@  discard block
 block discarded – undo
653 663
 			{
654 664
 				$ban_items[$row['id_ban']]['type'] = 'ip';
655 665
 				$ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);
656
-			}
657
-			elseif (!empty($row['hostname']))
666
+			} elseif (!empty($row['hostname']))
658 667
 			{
659 668
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
660 669
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
661
-			}
662
-			elseif (!empty($row['email_address']))
670
+			} elseif (!empty($row['email_address']))
663 671
 			{
664 672
 				$ban_items[$row['id_ban']]['type'] = 'email';
665 673
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
666
-			}
667
-			elseif (!empty($row['id_member']))
674
+			} elseif (!empty($row['id_member']))
668 675
 			{
669 676
 				$ban_items[$row['id_ban']]['type'] = 'user';
670 677
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -730,9 +737,10 @@  discard block
 block discarded – undo
730 737
 	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError');
731 738
 
732 739
 	$return = array();
733
-	foreach ($search_list as $key => $callable)
734
-		if (is_callable($callable))
740
+	foreach ($search_list as $key => $callable) {
741
+			if (is_callable($callable))
735 742
 			$return[$key] = call_user_func($callable, $member_id);
743
+	}
736 744
 
737 745
 	return $return;
738 746
 }
@@ -757,8 +765,9 @@  discard block
 block discarded – undo
757 765
 			'current_user' => $member_id,
758 766
 		)
759 767
 	);
760
-	while ($row = $smcFunc['db_fetch_assoc']($request))
761
-		$message_ips[] = inet_dtop($row['poster_ip']);
768
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
769
+			$message_ips[] = inet_dtop($row['poster_ip']);
770
+	}
762 771
 	$smcFunc['db_free_result']($request);
763 772
 
764 773
 	return $message_ips;
@@ -783,8 +792,9 @@  discard block
 block discarded – undo
783 792
 			'current_user' => $member_id,
784 793
 		)
785 794
 	);
786
-	while ($row = $smcFunc['db_fetch_assoc']($request))
787
-	    $error_ips[] = inet_dtop($row['ip']);
795
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
796
+		    $error_ips[] = inet_dtop($row['ip']);
797
+	}
788 798
 	$smcFunc['db_free_result']($request);
789 799
 
790 800
 	return $error_ips;
@@ -825,11 +835,13 @@  discard block
 block discarded – undo
825 835
 		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
826 836
 
827 837
 		// Adding a new ban group
828
-		if (empty($_REQUEST['bg']))
829
-			$ban_group_id = insertBanGroup($ban_info);
838
+		if (empty($_REQUEST['bg'])) {
839
+					$ban_group_id = insertBanGroup($ban_info);
840
+		}
830 841
 		// Editing an existing ban group
831
-		else
832
-			$ban_group_id = updateBanGroup($ban_info);
842
+		else {
843
+					$ban_group_id = updateBanGroup($ban_info);
844
+		}
833 845
 
834 846
 		if (is_numeric($ban_group_id))
835 847
 		{
@@ -840,9 +852,10 @@  discard block
 block discarded – undo
840 852
 		$context['ban'] = $ban_info;
841 853
 	}
842 854
 
843
-	if (isset($_POST['ban_suggestions']))
844
-		// @TODO: is $_REQUEST['bi'] ever set?
855
+	if (isset($_POST['ban_suggestions'])) {
856
+			// @TODO: is $_REQUEST['bi'] ever set?
845 857
 		$saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
858
+	}
846 859
 
847 860
 	// Something went wrong somewhere... Oh well, let's go back.
848 861
 	if (!empty($context['ban_errors']))
@@ -852,8 +865,9 @@  discard block
 block discarded – undo
852 865
 		$context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
853 866
 
854 867
 		// Not strictly necessary, but it's nice
855
-		if (!empty($context['ban_suggestions']['member']['id']))
856
-			$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
868
+		if (!empty($context['ban_suggestions']['member']['id'])) {
869
+					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
870
+		}
857 871
 		return BanEdit();
858 872
 	}
859 873
 	$context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();
@@ -902,10 +916,11 @@  discard block
 block discarded – undo
902 916
 
903 917
 	foreach ($suggestions as $key => $value)
904 918
 	{
905
-		if (is_array($value))
906
-			$triggers[$key] = $value;
907
-		else
908
-			$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
919
+		if (is_array($value)) {
920
+					$triggers[$key] = $value;
921
+		} else {
922
+					$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
923
+		}
909 924
 	}
910 925
 
911 926
 	$ban_triggers = validateTriggers($triggers);
@@ -913,16 +928,18 @@  discard block
 block discarded – undo
913 928
 	// Time to save!
914 929
 	if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))
915 930
 	{
916
-		if (empty($ban_id))
917
-			addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
918
-		else
919
-			updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
931
+		if (empty($ban_id)) {
932
+					addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
933
+		} else {
934
+					updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
935
+		}
936
+	}
937
+	if (!empty($context['ban_errors'])) {
938
+			return $triggers;
939
+	} else {
940
+			return false;
941
+	}
920 942
 	}
921
-	if (!empty($context['ban_errors']))
922
-		return $triggers;
923
-	else
924
-		return false;
925
-}
926 943
 
927 944
 /**
928 945
  * This function removes a bunch of triggers based on ids
@@ -936,14 +953,17 @@  discard block
 block discarded – undo
936 953
 {
937 954
 	global $smcFunc, $scripturl;
938 955
 
939
-	if ($group_id !== false)
940
-		$group_id = (int) $group_id;
956
+	if ($group_id !== false) {
957
+			$group_id = (int) $group_id;
958
+	}
941 959
 
942
-	if (empty($group_id) && empty($items_ids))
943
-		return false;
960
+	if (empty($group_id) && empty($items_ids)) {
961
+			return false;
962
+	}
944 963
 
945
-	if (!is_array($items_ids))
946
-		$items_ids = array($items_ids);
964
+	if (!is_array($items_ids)) {
965
+			$items_ids = array($items_ids);
966
+	}
947 967
 
948 968
 	$log_info = array();
949 969
 	$ban_items = array();
@@ -981,8 +1001,7 @@  discard block
 block discarded – undo
981 1001
 					'bantype' => ($is_range ? 'ip_range' : 'main_ip'),
982 1002
 					'value' => $ban_items[$row['id_ban']]['ip'],
983 1003
 				);
984
-			}
985
-			elseif (!empty($row['hostname']))
1004
+			} elseif (!empty($row['hostname']))
986 1005
 			{
987 1006
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
988 1007
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
@@ -990,8 +1009,7 @@  discard block
 block discarded – undo
990 1009
 					'bantype' => 'hostname',
991 1010
 					'value' => $row['hostname'],
992 1011
 				);
993
-			}
994
-			elseif (!empty($row['email_address']))
1012
+			} elseif (!empty($row['email_address']))
995 1013
 			{
996 1014
 				$ban_items[$row['id_ban']]['type'] = 'email';
997 1015
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
@@ -999,8 +1017,7 @@  discard block
 block discarded – undo
999 1017
 					'bantype' => 'email',
1000 1018
 					'value' => $ban_items[$row['id_ban']]['email'],
1001 1019
 				);
1002
-			}
1003
-			elseif (!empty($row['id_member']))
1020
+			} elseif (!empty($row['id_member']))
1004 1021
 			{
1005 1022
 				$ban_items[$row['id_ban']]['type'] = 'user';
1006 1023
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -1033,8 +1050,7 @@  discard block
 block discarded – undo
1033 1050
 				'ban_group' => $group_id,
1034 1051
 			)
1035 1052
 		);
1036
-	}
1037
-	elseif (!empty($items_ids))
1053
+	} elseif (!empty($items_ids))
1038 1054
 	{
1039 1055
 		$smcFunc['db_query']('', '
1040 1056
 			DELETE FROM {db_prefix}ban_items
@@ -1059,13 +1075,15 @@  discard block
 block discarded – undo
1059 1075
 {
1060 1076
 	global $smcFunc;
1061 1077
 
1062
-	if (!is_array($group_ids))
1063
-		$group_ids = array($group_ids);
1078
+	if (!is_array($group_ids)) {
1079
+			$group_ids = array($group_ids);
1080
+	}
1064 1081
 
1065 1082
 	$group_ids = array_unique($group_ids);
1066 1083
 
1067
-	if (empty($group_ids))
1068
-		return false;
1084
+	if (empty($group_ids)) {
1085
+			return false;
1086
+	}
1069 1087
 
1070 1088
 	$smcFunc['db_query']('', '
1071 1089
 		DELETE FROM {db_prefix}ban_groups
@@ -1089,21 +1107,23 @@  discard block
 block discarded – undo
1089 1107
 {
1090 1108
 	global $smcFunc;
1091 1109
 
1092
-	if (empty($ids))
1093
-		$smcFunc['db_query']('truncate_table', '
1110
+	if (empty($ids)) {
1111
+			$smcFunc['db_query']('truncate_table', '
1094 1112
 			TRUNCATE {db_prefix}log_banned',
1095 1113
 			array(
1096 1114
 			)
1097 1115
 		);
1098
-	else
1116
+	} else
1099 1117
 	{
1100
-		if (!is_array($ids))
1101
-			$ids = array($ids);
1118
+		if (!is_array($ids)) {
1119
+					$ids = array($ids);
1120
+		}
1102 1121
 
1103 1122
 		$ids = array_unique($ids);
1104 1123
 
1105
-		if (empty($ids))
1106
-			return false;
1124
+		if (empty($ids)) {
1125
+					return false;
1126
+		}
1107 1127
 
1108 1128
 		$smcFunc['db_query']('', '
1109 1129
 			DELETE FROM {db_prefix}log_banned
@@ -1129,8 +1149,9 @@  discard block
 block discarded – undo
1129 1149
 {
1130 1150
 	global $context, $smcFunc;
1131 1151
 
1132
-	if (empty($triggers))
1133
-		$context['ban_erros'][] = 'ban_empty_triggers';
1152
+	if (empty($triggers)) {
1153
+			$context['ban_erros'][] = 'ban_empty_triggers';
1154
+	}
1134 1155
 
1135 1156
 	$ban_triggers = array();
1136 1157
 	$log_info = array();
@@ -1139,39 +1160,39 @@  discard block
 block discarded – undo
1139 1160
 	{
1140 1161
 		if (!empty($value))
1141 1162
 		{
1142
-			if ($key == 'member')
1143
-				continue;
1163
+			if ($key == 'member') {
1164
+							continue;
1165
+			}
1144 1166
 
1145 1167
 			if ($key == 'main_ip')
1146 1168
 			{
1147 1169
 				$value = trim($value);
1148 1170
 				$ip_parts = ip2range($value);
1149
-				if (!checkExistingTriggerIP($ip_parts, $value))
1150
-					$context['ban_erros'][] = 'invalid_ip';
1151
-				else
1171
+				if (!checkExistingTriggerIP($ip_parts, $value)) {
1172
+									$context['ban_erros'][] = 'invalid_ip';
1173
+				} else
1152 1174
 				{
1153 1175
 					$ban_triggers['main_ip'] = array(
1154 1176
 						'ip_low' => $ip_parts['low'],
1155 1177
 						'ip_high' => $ip_parts['high']
1156 1178
 					);
1157 1179
 				}
1158
-			}
1159
-			elseif ($key == 'hostname')
1180
+			} elseif ($key == 'hostname')
1160 1181
 			{
1161
-				if (preg_match('/[^\w.\-*]/', $value) == 1)
1162
-					$context['ban_erros'][] = 'invalid_hostname';
1163
-				else
1182
+				if (preg_match('/[^\w.\-*]/', $value) == 1) {
1183
+									$context['ban_erros'][] = 'invalid_hostname';
1184
+				} else
1164 1185
 				{
1165 1186
 					// Replace the * wildcard by a MySQL wildcard %.
1166 1187
 					$value = substr(str_replace('*', '%', $value), 0, 255);
1167 1188
 
1168 1189
 					$ban_triggers['hostname']['hostname'] = $value;
1169 1190
 				}
1170
-			}
1171
-			elseif ($key == 'email')
1191
+			} elseif ($key == 'email')
1172 1192
 			{
1173
-				if (preg_match('/[^\w.\-\+*@]/', $value) == 1)
1174
-					$context['ban_erros'][] = 'invalid_email';
1193
+				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) {
1194
+									$context['ban_erros'][] = 'invalid_email';
1195
+				}
1175 1196
 
1176 1197
 				// Check the user is not banning an admin.
1177 1198
 				$request = $smcFunc['db_query']('', '
@@ -1185,15 +1206,15 @@  discard block
 block discarded – undo
1185 1206
 						'email' => $value,
1186 1207
 					)
1187 1208
 				);
1188
-				if ($smcFunc['db_num_rows']($request) != 0)
1189
-					$context['ban_erros'][] = 'no_ban_admin';
1209
+				if ($smcFunc['db_num_rows']($request) != 0) {
1210
+									$context['ban_erros'][] = 'no_ban_admin';
1211
+				}
1190 1212
 				$smcFunc['db_free_result']($request);
1191 1213
 
1192 1214
 				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255);
1193 1215
 
1194 1216
 				$ban_triggers['email']['email_address'] = $value;
1195
-			}
1196
-			elseif ($key == 'user')
1217
+			} elseif ($key == 'user')
1197 1218
 			{
1198 1219
 				$user = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES));
1199 1220
 
@@ -1207,8 +1228,9 @@  discard block
 block discarded – undo
1207 1228
 						'username' => $user,
1208 1229
 					)
1209 1230
 				);
1210
-				if ($smcFunc['db_num_rows']($request) == 0)
1211
-					$context['ban_erros'][] = 'invalid_username';
1231
+				if ($smcFunc['db_num_rows']($request) == 0) {
1232
+									$context['ban_erros'][] = 'invalid_username';
1233
+				}
1212 1234
 				list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);
1213 1235
 				$smcFunc['db_free_result']($request);
1214 1236
 
@@ -1216,25 +1238,25 @@  discard block
 block discarded – undo
1216 1238
 				{
1217 1239
 					unset($value);
1218 1240
 					$context['ban_erros'][] = 'no_ban_admin';
1241
+				} else {
1242
+									$ban_triggers['user']['id_member'] = $value;
1219 1243
 				}
1220
-				else
1221
-					$ban_triggers['user']['id_member'] = $value;
1222
-			}
1223
-			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1244
+			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1224 1245
 			{
1225 1246
 				// Special case, those two are arrays themselves
1226 1247
 				$values = array_unique($value);
1227 1248
 				// Don't add the main IP again.
1228
-				if (isset($triggers['main_ip']))
1229
-					$values = array_diff($values, array($triggers['main_ip']));
1249
+				if (isset($triggers['main_ip'])) {
1250
+									$values = array_diff($values, array($triggers['main_ip']));
1251
+				}
1230 1252
 				unset($value);
1231 1253
 				foreach ($values as $val)
1232 1254
 				{
1233 1255
 					$val = trim($val);
1234 1256
 					$ip_parts = ip2range($val);
1235
-					if (!checkExistingTriggerIP($ip_parts, $val))
1236
-						$context['ban_erros'][] = 'invalid_ip';
1237
-					else
1257
+					if (!checkExistingTriggerIP($ip_parts, $val)) {
1258
+											$context['ban_erros'][] = 'invalid_ip';
1259
+					} else
1238 1260
 					{
1239 1261
 						$ban_triggers[$key][] = array(
1240 1262
 							'ip_low' => $ip_parts['low'],
@@ -1247,15 +1269,16 @@  discard block
 block discarded – undo
1247 1269
 						);
1248 1270
 					}
1249 1271
 				}
1272
+			} else {
1273
+							$context['ban_erros'][] = 'no_bantype_selected';
1250 1274
 			}
1251
-			else
1252
-				$context['ban_erros'][] = 'no_bantype_selected';
1253 1275
 
1254
-			if (isset($value) && !is_array($value))
1255
-				$log_info[] = array(
1276
+			if (isset($value) && !is_array($value)) {
1277
+							$log_info[] = array(
1256 1278
 					'value' => $value,
1257 1279
 					'bantype' => $key,
1258 1280
 				);
1281
+			}
1259 1282
 		}
1260 1283
 	}
1261 1284
 	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info);
@@ -1275,8 +1298,9 @@  discard block
 block discarded – undo
1275 1298
 {
1276 1299
 	global $smcFunc, $context;
1277 1300
 
1278
-	if (empty($group_id))
1279
-		$context['ban_errors'][] = 'ban_id_empty';
1301
+	if (empty($group_id)) {
1302
+			$context['ban_errors'][] = 'ban_id_empty';
1303
+	}
1280 1304
 
1281 1305
 	// Preset all values that are required.
1282 1306
 	$values = array(
@@ -1301,18 +1325,21 @@  discard block
 block discarded – undo
1301 1325
 	foreach ($triggers as $key => $trigger)
1302 1326
 	{
1303 1327
 		// Exceptions, exceptions, exceptions...always exceptions... :P
1304
-		if (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1305
-			foreach ($trigger as $real_trigger)
1328
+		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) {
1329
+					foreach ($trigger as $real_trigger)
1306 1330
 				$insertTriggers[] = array_merge($values, $real_trigger);
1307
-		else
1308
-			$insertTriggers[] = array_merge($values, $trigger);
1331
+		} else {
1332
+					$insertTriggers[] = array_merge($values, $trigger);
1333
+		}
1309 1334
 	}
1310 1335
 
1311
-	if (empty($insertTriggers))
1312
-		$context['ban_errors'][] = 'ban_no_triggers';
1336
+	if (empty($insertTriggers)) {
1337
+			$context['ban_errors'][] = 'ban_no_triggers';
1338
+	}
1313 1339
 
1314
-	if (!empty($context['ban_errors']))
1315
-		return false;
1340
+	if (!empty($context['ban_errors'])) {
1341
+			return false;
1342
+	}
1316 1343
 
1317 1344
 	$smcFunc['db_insert']('',
1318 1345
 		'{db_prefix}ban_items',
@@ -1340,15 +1367,19 @@  discard block
 block discarded – undo
1340 1367
 {
1341 1368
 	global $smcFunc, $context;
1342 1369
 
1343
-	if (empty($ban_item))
1344
-		$context['ban_errors'][] = 'ban_ban_item_empty';
1345
-	if (empty($group_id))
1346
-		$context['ban_errors'][] = 'ban_id_empty';
1347
-	if (empty($trigger))
1348
-		$context['ban_errors'][] = 'ban_no_triggers';
1370
+	if (empty($ban_item)) {
1371
+			$context['ban_errors'][] = 'ban_ban_item_empty';
1372
+	}
1373
+	if (empty($group_id)) {
1374
+			$context['ban_errors'][] = 'ban_id_empty';
1375
+	}
1376
+	if (empty($trigger)) {
1377
+			$context['ban_errors'][] = 'ban_no_triggers';
1378
+	}
1349 1379
 
1350
-	if (!empty($context['ban_errors']))
1351
-		return;
1380
+	if (!empty($context['ban_errors'])) {
1381
+			return;
1382
+	}
1352 1383
 
1353 1384
 	// Preset all values that are required.
1354 1385
 	$values = array(
@@ -1389,8 +1420,9 @@  discard block
 block discarded – undo
1389 1420
  */
1390 1421
 function logTriggersUpdates($logs, $new = true, $removal = false)
1391 1422
 {
1392
-	if (empty($logs))
1393
-		return;
1423
+	if (empty($logs)) {
1424
+			return;
1425
+	}
1394 1426
 
1395 1427
 	$log_name_map = array(
1396 1428
 		'main_ip' => 'ip_range',
@@ -1401,14 +1433,15 @@  discard block
 block discarded – undo
1401 1433
 	);
1402 1434
 
1403 1435
 	// Log the addion of the ban entries into the moderation log.
1404
-	foreach ($logs as $log)
1405
-		logAction('ban' . ($removal == true ? 'remove' : ''), array(
1436
+	foreach ($logs as $log) {
1437
+			logAction('ban' . ($removal == true ? 'remove' : ''), array(
1406 1438
 			$log_name_map[$log['bantype']] => $log['value'],
1407 1439
 			'new' => empty($new) ? 0 : 1,
1408 1440
 			'remove' => empty($removal) ? 0 : 1,
1409 1441
 			'type' => $log['bantype'],
1410 1442
 		));
1411
-}
1443
+	}
1444
+	}
1412 1445
 
1413 1446
 /**
1414 1447
  * Updates an existing ban group
@@ -1422,12 +1455,15 @@  discard block
 block discarded – undo
1422 1455
 {
1423 1456
 	global $smcFunc, $context;
1424 1457
 
1425
-	if (empty($ban_info['name']))
1426
-		$context['ban_errors'][] = 'ban_name_empty';
1427
-	if (empty($ban_info['id']))
1428
-		$context['ban_errors'][] = 'ban_id_empty';
1429
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1430
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1458
+	if (empty($ban_info['name'])) {
1459
+			$context['ban_errors'][] = 'ban_name_empty';
1460
+	}
1461
+	if (empty($ban_info['id'])) {
1462
+			$context['ban_errors'][] = 'ban_id_empty';
1463
+	}
1464
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1465
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1466
+	}
1431 1467
 
1432 1468
 	if(!empty($ban_info['id']))
1433 1469
 	{
@@ -1442,8 +1478,9 @@  discard block
 block discarded – undo
1442 1478
 			)
1443 1479
 		);
1444 1480
 
1445
-		if ($smcFunc['db_num_rows']($request) == 0)
1446
-			$context['ban_errors'][] = 'ban_not_found';
1481
+		if ($smcFunc['db_num_rows']($request) == 0) {
1482
+					$context['ban_errors'][] = 'ban_not_found';
1483
+		}
1447 1484
 		$smcFunc['db_free_result']($request);
1448 1485
 	}
1449 1486
 
@@ -1461,13 +1498,15 @@  discard block
 block discarded – undo
1461 1498
 				'new_ban_name' => $ban_info['name'],
1462 1499
 			)
1463 1500
 		);
1464
-		if ($smcFunc['db_num_rows']($request) != 0)
1465
-			$context['ban_errors'][] = 'ban_name_exists';
1501
+		if ($smcFunc['db_num_rows']($request) != 0) {
1502
+					$context['ban_errors'][] = 'ban_name_exists';
1503
+		}
1466 1504
 		$smcFunc['db_free_result']($request);
1467 1505
 	}
1468 1506
 
1469
-	if (!empty($context['ban_errors']))
1470
-		return $ban_info['id'];
1507
+	if (!empty($context['ban_errors'])) {
1508
+			return $ban_info['id'];
1509
+	}
1471 1510
 
1472 1511
 	$smcFunc['db_query']('', '
1473 1512
 		UPDATE {db_prefix}ban_groups
@@ -1511,10 +1550,12 @@  discard block
 block discarded – undo
1511 1550
 {
1512 1551
 	global $smcFunc, $context;
1513 1552
 
1514
-	if (empty($ban_info['name']))
1515
-		$context['ban_errors'][] = 'ban_name_empty';
1516
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1517
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1553
+	if (empty($ban_info['name'])) {
1554
+			$context['ban_errors'][] = 'ban_name_empty';
1555
+	}
1556
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1557
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1558
+	}
1518 1559
 
1519 1560
 	if(!empty($ban_info['name']))
1520 1561
 	{
@@ -1529,13 +1570,15 @@  discard block
 block discarded – undo
1529 1570
 			)
1530 1571
 		);
1531 1572
 
1532
-		if ($smcFunc['db_num_rows']($request) == 1)
1533
-			$context['ban_errors'][] = 'ban_name_exists';
1573
+		if ($smcFunc['db_num_rows']($request) == 1) {
1574
+					$context['ban_errors'][] = 'ban_name_exists';
1575
+		}
1534 1576
 		$smcFunc['db_free_result']($request);
1535 1577
 	}
1536 1578
 
1537
-	if (!empty($context['ban_errors']))
1538
-		return;
1579
+	if (!empty($context['ban_errors'])) {
1580
+			return;
1581
+	}
1539 1582
 
1540 1583
 	// Yes yes, we're ready to add now.
1541 1584
 	$smcFunc['db_insert']('',
@@ -1552,8 +1595,9 @@  discard block
 block discarded – undo
1552 1595
 	);
1553 1596
 	$ban_info['id'] = $smcFunc['db_insert_id']('{db_prefix}ban_groups', 'id_ban_group');
1554 1597
 
1555
-	if (empty($ban_info['id']))
1556
-		$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1598
+	if (empty($ban_info['id'])) {
1599
+			$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1600
+	}
1557 1601
 
1558 1602
 	return $ban_info['id'];
1559 1603
 }
@@ -1578,24 +1622,24 @@  discard block
 block discarded – undo
1578 1622
 	$ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
1579 1623
 	$ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
1580 1624
 
1581
-	if (empty($ban_group))
1582
-		fatal_lang_error('ban_not_found', false);
1625
+	if (empty($ban_group)) {
1626
+			fatal_lang_error('ban_not_found', false);
1627
+	}
1583 1628
 
1584 1629
 	if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))
1585 1630
 	{
1586 1631
 		saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
1587 1632
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1588
-	}
1589
-	elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1633
+	} elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1590 1634
 	{
1591 1635
 		// The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)
1592 1636
 		saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
1593
-		if (!empty($_POST['ban_suggestions']))
1594
-			saveTriggers($_POST['ban_suggestions'], $ban_group);
1637
+		if (!empty($_POST['ban_suggestions'])) {
1638
+					saveTriggers($_POST['ban_suggestions'], $ban_group);
1639
+		}
1595 1640
 
1596 1641
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1597
-	}
1598
-	elseif (isset($_POST['edit_trigger']))
1642
+	} elseif (isset($_POST['edit_trigger']))
1599 1643
 	{
1600 1644
 		removeBanTriggers($ban_id);
1601 1645
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
@@ -1626,8 +1670,7 @@  discard block
 block discarded – undo
1626 1670
 			),
1627 1671
 			'is_new' => true,
1628 1672
 		);
1629
-	}
1630
-	else
1673
+	} else
1631 1674
 	{
1632 1675
 		$request = $smcFunc['db_query']('', '
1633 1676
 			SELECT
@@ -1644,8 +1687,9 @@  discard block
 block discarded – undo
1644 1687
 				'ban_group' => $ban_group,
1645 1688
 			)
1646 1689
 		);
1647
-		if ($smcFunc['db_num_rows']($request) == 0)
1648
-			fatal_lang_error('ban_not_found', false);
1690
+		if ($smcFunc['db_num_rows']($request) == 0) {
1691
+					fatal_lang_error('ban_not_found', false);
1692
+		}
1649 1693
 		$row = $smcFunc['db_fetch_assoc']($request);
1650 1694
 		$smcFunc['db_free_result']($request);
1651 1695
 
@@ -1694,8 +1738,9 @@  discard block
 block discarded – undo
1694 1738
 		removeBanTriggers($_POST['remove']);
1695 1739
 
1696 1740
 		// Rehabilitate some members.
1697
-		if ($_REQUEST['entity'] == 'member')
1698
-			updateBanMembers();
1741
+		if ($_REQUEST['entity'] == 'member') {
1742
+					updateBanMembers();
1743
+		}
1699 1744
 
1700 1745
 		// Make sure the ban cache is refreshed.
1701 1746
 		updateSettings(array('banLastUpdated' => time()));
@@ -1808,8 +1853,7 @@  discard block
 block discarded – undo
1808 1853
 			'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',
1809 1854
 			'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',
1810 1855
 		);
1811
-	}
1812
-	elseif ($context['selected_entity'] === 'hostname')
1856
+	} elseif ($context['selected_entity'] === 'hostname')
1813 1857
 	{
1814 1858
 		$listOptions['columns']['banned_entity']['data'] = array(
1815 1859
 			'function' => function ($rowData) use ($smcFunc)
@@ -1821,8 +1865,7 @@  discard block
 block discarded – undo
1821 1865
 			'default' => 'bi.hostname',
1822 1866
 			'reverse' => 'bi.hostname DESC',
1823 1867
 		);
1824
-	}
1825
-	elseif ($context['selected_entity'] === 'email')
1868
+	} elseif ($context['selected_entity'] === 'email')
1826 1869
 	{
1827 1870
 		$listOptions['columns']['banned_entity']['data'] = array(
1828 1871
 			'function' => function ($rowData) use ($smcFunc)
@@ -1834,8 +1877,7 @@  discard block
 block discarded – undo
1834 1877
 			'default' => 'bi.email_address',
1835 1878
 			'reverse' => 'bi.email_address DESC',
1836 1879
 		);
1837
-	}
1838
-	elseif ($context['selected_entity'] === 'member')
1880
+	} elseif ($context['selected_entity'] === 'member')
1839 1881
 	{
1840 1882
 		$listOptions['columns']['banned_entity']['data'] = array(
1841 1883
 			'sprintf' => array(
@@ -1899,8 +1941,9 @@  discard block
 block discarded – undo
1899 1941
 		)
1900 1942
 	);
1901 1943
 	$ban_triggers = array();
1902
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1903
-		$ban_triggers[] = $row;
1944
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1945
+			$ban_triggers[] = $row;
1946
+	}
1904 1947
 	$smcFunc['db_free_result']($request);
1905 1948
 
1906 1949
 	return $ban_triggers;
@@ -1956,8 +1999,9 @@  discard block
 block discarded – undo
1956 1999
 		validateToken('admin-bl');
1957 2000
 
1958 2001
 		// 'Delete all entries' button was pressed.
1959
-		if (!empty($_POST['removeAll']))
1960
-			removeBanLogs();
2002
+		if (!empty($_POST['removeAll'])) {
2003
+					removeBanLogs();
2004
+		}
1961 2005
 		// 'Delete selection' button was pressed.
1962 2006
 		else
1963 2007
 		{
@@ -2166,12 +2210,15 @@  discard block
 block discarded – undo
2166 2210
 	$low = inet_dtop($low);
2167 2211
 	$high = inet_dtop($high);
2168 2212
 
2169
-	if ($low == '255.255.255.255') return 'unknown';
2170
-	if ($low == $high)
2171
-	    return $low;
2172
-	else
2173
-	    return $low . '-'.$high;
2174
-}
2213
+	if ($low == '255.255.255.255') {
2214
+		return 'unknown';
2215
+	}
2216
+	if ($low == $high) {
2217
+		    return $low;
2218
+	} else {
2219
+		    return $low . '-'.$high;
2220
+	}
2221
+	}
2175 2222
 
2176 2223
 /**
2177 2224
  * Checks whether a given IP range already exists in the trigger list.
@@ -2247,15 +2294,17 @@  discard block
 block discarded – undo
2247 2294
 	$memberEmailWild = array();
2248 2295
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2249 2296
 	{
2250
-		if ($row['id_member'])
2251
-			$memberIDs[$row['id_member']] = $row['id_member'];
2297
+		if ($row['id_member']) {
2298
+					$memberIDs[$row['id_member']] = $row['id_member'];
2299
+		}
2252 2300
 		if ($row['email_address'])
2253 2301
 		{
2254 2302
 			// Does it have a wildcard - if so we can't do a IN on it.
2255
-			if (strpos($row['email_address'], '%') !== false)
2256
-				$memberEmailWild[$row['email_address']] = $row['email_address'];
2257
-			else
2258
-				$memberEmails[$row['email_address']] = $row['email_address'];
2303
+			if (strpos($row['email_address'], '%') !== false) {
2304
+							$memberEmailWild[$row['email_address']] = $row['email_address'];
2305
+			} else {
2306
+							$memberEmails[$row['email_address']] = $row['email_address'];
2307
+			}
2259 2308
 		}
2260 2309
 	}
2261 2310
 	$smcFunc['db_free_result']($request);
@@ -2306,14 +2355,15 @@  discard block
 block discarded – undo
2306 2355
 	}
2307 2356
 
2308 2357
 	// We welcome our new members in the realm of the banned.
2309
-	if (!empty($newMembers))
2310
-		$smcFunc['db_query']('', '
2358
+	if (!empty($newMembers)) {
2359
+			$smcFunc['db_query']('', '
2311 2360
 			DELETE FROM {db_prefix}log_online
2312 2361
 			WHERE id_member IN ({array_int:new_banned_members})',
2313 2362
 			array(
2314 2363
 				'new_banned_members' => $newMembers,
2315 2364
 			)
2316 2365
 		);
2366
+	}
2317 2367
 
2318 2368
 	// Find members that are wrongfully marked as banned.
2319 2369
 	$request = $smcFunc['db_query']('', '
@@ -2340,9 +2390,10 @@  discard block
 block discarded – undo
2340 2390
 	}
2341 2391
 	$smcFunc['db_free_result']($request);
2342 2392
 
2343
-	if (!empty($updates))
2344
-		foreach ($updates as $newStatus => $members)
2393
+	if (!empty($updates)) {
2394
+			foreach ($updates as $newStatus => $members)
2345 2395
 			updateMemberData($members, array('is_activated' => $newStatus));
2396
+	}
2346 2397
 
2347 2398
 	// Update the latest member and our total members as banning may change them.
2348 2399
 	updateStats('member');
Please login to merge, or discard this patch.
Sources/ManagePaid.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1452,7 +1452,7 @@
 block discarded – undo
1452 1452
  *
1453 1453
  * @param int $id_subscribe The subscription ID
1454 1454
  * @param int $id_member The ID of the member
1455
- * @param int|string $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y')
1455
+ * @param integer $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y')
1456 1456
  * @param int $forceStartTime If set, forces the subscription to start at the specified time
1457 1457
  * @param int $forceEndTime If set, forces the subscription to end at the specified time
1458 1458
  */
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 		'items_per_page' => $modSettings['defaultMaxListItems'],
263 263
 		'base_href' => $scripturl . '?action=admin;area=paidsubscribe;sa=view',
264 264
 		'get_items' => array(
265
-			'function' => function ($start, $items_per_page) use ($context)
265
+			'function' => function($start, $items_per_page) use ($context)
266 266
 			{
267 267
 				$subscriptions = array();
268 268
 				$counter = 0;
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 			},
282 282
 		),
283 283
 		'get_count' => array(
284
-			'function' => function () use ($context)
284
+			'function' => function() use ($context)
285 285
 			{
286 286
 				return count($context['subscriptions']);
287 287
 			},
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 					'style' => 'width: 35%;',
295 295
 				),
296 296
 				'data' => array(
297
-					'function' => function ($rowData) use ($scripturl)
297
+					'function' => function($rowData) use ($scripturl)
298 298
 					{
299 299
 						return sprintf('<a href="%1$s?action=admin;area=paidsubscribe;sa=viewsub;sid=%2$s">%3$s</a>', $scripturl, $rowData['id'], $rowData['name']);
300 300
 					},
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 					'value' => $txt['paid_cost'],
306 306
 				),
307 307
 				'data' => array(
308
-					'function' => function ($rowData) use ($txt)
308
+					'function' => function($rowData) use ($txt)
309 309
 					{
310 310
 						return $rowData['flexible'] ? '<em>' . $txt['flexible'] . '</em>' : $rowData['cost'] . ' / ' . $rowData['length'];
311 311
 					},
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 					'class' => 'centercol',
349 349
 				),
350 350
 				'data' => array(
351
-					'function' => function ($rowData) use ($txt)
351
+					'function' => function($rowData) use ($txt)
352 352
 					{
353 353
 						return '<span style="color: ' . ($rowData['active'] ? 'green' : 'red') . '">' . ($rowData['active'] ? $txt['yes'] : $txt['no']) . '</span>';
354 354
 					},
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 			),
358 358
 			'modify' => array(
359 359
 				'data' => array(
360
-					'function' => function ($rowData) use ($txt, $scripturl)
360
+					'function' => function($rowData) use ($txt, $scripturl)
361 361
 					{
362 362
 						return '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modify;sid=' . $rowData['id'] . '">' . $txt['modify'] . '</a>';
363 363
 					},
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 			),
367 367
 			'delete' => array(
368 368
 				'data' => array(
369
-					'function' => function ($rowData) use ($scripturl, $txt)
369
+					'function' => function($rowData) use ($scripturl, $txt)
370 370
 					{
371 371
 						return '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modify;delete;sid=' . $rowData['id'] . '">' . $txt['delete'] . '</a>';
372 372
 					},
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 					'style' => 'width: 20%;',
824 824
 				),
825 825
 				'data' => array(
826
-					'function' => function ($rowData) use ($scripturl, $txt)
826
+					'function' => function($rowData) use ($scripturl, $txt)
827 827
 					{
828 828
 						return $rowData['id_member'] == 0 ? $txt['guest'] : '<a href="' . $scripturl . '?action=profile;u=' . $rowData['id_member'] . '">' . $rowData['name'] . '</a>';
829 829
 					},
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 					'class' => 'centercol',
894 894
 				),
895 895
 				'data' => array(
896
-					'function' => function ($rowData) use ($scripturl, $txt)
896
+					'function' => function($rowData) use ($scripturl, $txt)
897 897
 					{
898 898
 						return '<a href="' . $scripturl . '?action=admin;area=paidsubscribe;sa=modifyuser;lid=' . $rowData['id'] . '">' . $txt['modify'] . '</a>';
899 899
 					},
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 					'class' => 'centercol',
907 907
 				),
908 908
 				'data' => array(
909
-					'function' => function ($rowData)
909
+					'function' => function($rowData)
910 910
 					{
911 911
 						return '<input type="checkbox" name="delsub[' . $rowData['id'] . ']" class="input_check">';
912 912
 					},
@@ -1950,7 +1950,7 @@  discard block
 block discarded – undo
1950 1950
 	{
1951 1951
 		while (($file = readdir($dh)) !== false)
1952 1952
 		{
1953
-			if (is_file($sourcedir .'/'. $file) && preg_match('~^Subscriptions-([A-Za-z\d]+)\.php$~', $file, $matches))
1953
+			if (is_file($sourcedir . '/' . $file) && preg_match('~^Subscriptions-([A-Za-z\d]+)\.php$~', $file, $matches))
1954 1954
 			{
1955 1955
 				// Check this is definitely a valid gateway!
1956 1956
 				$fp = fopen($sourcedir . '/' . $file, 'rb');
Please login to merge, or discard this patch.
Braces   +202 added lines, -148 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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 main entrance point for the 'Paid Subscription' screen, calling
@@ -32,18 +33,19 @@  discard block
 block discarded – undo
32 33
 	loadLanguage('ManagePaid');
33 34
 	loadTemplate('ManagePaid');
34 35
 
35
-	if (!empty($modSettings['paid_enabled']))
36
-		$subActions = array(
36
+	if (!empty($modSettings['paid_enabled'])) {
37
+			$subActions = array(
37 38
 			'modify' => array('ModifySubscription', 'admin_forum'),
38 39
 			'modifyuser' => array('ModifyUserSubscription', 'admin_forum'),
39 40
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
40 41
 			'view' => array('ViewSubscriptions', 'admin_forum'),
41 42
 			'viewsub' => array('ViewSubscribedUsers', 'admin_forum'),
42 43
 		);
43
-	else
44
-		$subActions = array(
44
+	} else {
45
+			$subActions = array(
45 46
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
46 47
 		);
48
+	}
47 49
 
48 50
 	// Default the sub-action to 'view subscriptions', but only if they have already set things up..
49 51
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($modSettings['paid_currency_symbol']) && !empty($modSettings['paid_enabled']) ? 'view' : 'settings');
@@ -59,8 +61,8 @@  discard block
 block discarded – undo
59 61
 		'help' => '',
60 62
 		'description' => $txt['paid_subscriptions_desc'],
61 63
 	);
62
-	if (!empty($modSettings['paid_enabled']))
63
-		$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64
+	if (!empty($modSettings['paid_enabled'])) {
65
+			$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64 66
 			'view' => array(
65 67
 				'description' => $txt['paid_subs_view_desc'],
66 68
 			),
@@ -68,6 +70,7 @@  discard block
 block discarded – undo
68 70
 				'description' => $txt['paid_subs_settings_desc'],
69 71
 			),
70 72
 		);
73
+	}
71 74
 
72 75
 	call_integration_hook('integrate_manage_subscriptions', array(&$subActions));
73 76
 
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 	{
93 96
 		// If the currency is set to something different then we need to set it to other for this to work and set it back shortly.
94 97
 		$modSettings['paid_currency'] = !empty($modSettings['paid_currency_code']) ? $modSettings['paid_currency_code'] : '';
95
-		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud')))
96
-			$modSettings['paid_currency'] = 'other';
98
+		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) {
99
+					$modSettings['paid_currency'] = 'other';
100
+		}
97 101
 
98 102
 		// These are all the default settings.
99 103
 		$config_vars = array(
@@ -156,8 +160,7 @@  discard block
 block discarded – undo
156 160
 			}
157 161
 		}
158 162
 		toggleOther();', true);
159
-	}
160
-	else
163
+	} else
161 164
 	{
162 165
 		$config_vars = array(
163 166
 			array('check', 'paid_enabled'),
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	}
167 170
 
168 171
 	// Just searching?
169
-	if ($return_config)
170
-		return $config_vars;
172
+	if ($return_config) {
173
+			return $config_vars;
174
+	}
171 175
 
172 176
 	// Get the settings template fired up.
173 177
 	require_once($sourcedir . '/ManageServer.php');
@@ -211,8 +215,9 @@  discard block
 block discarded – undo
211 215
 			foreach (explode(',', $_POST['paid_email_to']) as $email)
212 216
 			{
213 217
 				$email = trim($email);
214
-				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
215
-					$email_addresses[] = $email;
218
+				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
219
+									$email_addresses[] = $email;
220
+				}
216 221
 				$_POST['paid_email_to'] = implode(',', $email_addresses);
217 222
 			}
218 223
 		}
@@ -249,8 +254,9 @@  discard block
 block discarded – undo
249 254
 	global $context, $txt, $modSettings, $sourcedir, $scripturl;
250 255
 
251 256
 	// Not made the settings yet?
252
-	if (empty($modSettings['paid_currency_symbol']))
253
-		fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
257
+	if (empty($modSettings['paid_currency_symbol'])) {
258
+			fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
259
+	}
254 260
 
255 261
 	// Some basic stuff.
256 262
 	$context['page_title'] = $txt['paid_subs_view'];
@@ -270,10 +276,11 @@  discard block
 block discarded – undo
270 276
 
271 277
 				foreach ($context['subscriptions'] as $data)
272 278
 				{
273
-					if (++$counter < $start)
274
-						continue;
275
-					elseif ($counter == $start + $items_per_page)
276
-						break;
279
+					if (++$counter < $start) {
280
+											continue;
281
+					} elseif ($counter == $start + $items_per_page) {
282
+											break;
283
+					}
277 284
 
278 285
 					$subscriptions[] = $data;
279 286
 				}
@@ -450,8 +457,9 @@  discard block
 block discarded – undo
450 457
 			);
451 458
 			$id_group = 0;
452 459
 			$add_groups = '';
453
-			if ($smcFunc['db_num_rows']($request))
454
-				list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
460
+			if ($smcFunc['db_num_rows']($request)) {
461
+							list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
462
+			}
455 463
 			$smcFunc['db_free_result']($request);
456 464
 
457 465
 			$changes = array();
@@ -463,8 +471,9 @@  discard block
 block discarded – undo
463 471
 				{
464 472
 					// If their current primary group isn't what they had before the subscription, and their current group was
465 473
 					// granted by the sub, remove it.
466
-					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group)
467
-						$changes[$id_member]['id_group'] = $member_data['old_id_group'];
474
+					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) {
475
+											$changes[$id_member]['id_group'] = $member_data['old_id_group'];
476
+					}
468 477
 				}
469 478
 			}
470 479
 
@@ -477,15 +486,17 @@  discard block
 block discarded – undo
477 486
 					// First let's get their groups sorted.
478 487
 					$current_groups = explode(',', $member_data['additional_groups']);
479 488
 					$new_groups = implode(',', array_diff($current_groups, $add_groups));
480
-					if ($new_groups != $member_data['additional_groups'])
481
-						$changes[$id_member]['additional_groups'] = $new_groups;
489
+					if ($new_groups != $member_data['additional_groups']) {
490
+											$changes[$id_member]['additional_groups'] = $new_groups;
491
+					}
482 492
 				}
483 493
 			}
484 494
 
485 495
 			// We're going through changes...
486
-			if (!empty($changes))
487
-				foreach ($changes as $id_member => $new_values)
496
+			if (!empty($changes)) {
497
+							foreach ($changes as $id_member => $new_values)
488 498
 					updateMemberData($id_member, $new_values);
499
+			}
489 500
 		}
490 501
 
491 502
 		// Delete the subscription
@@ -533,11 +544,13 @@  discard block
 block discarded – undo
533 544
 				'M' => 24,
534 545
 				'Y' => 5,
535 546
 			);
536
-			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1)
537
-				fatal_lang_error('paid_invalid_duration', false);
547
+			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) {
548
+							fatal_lang_error('paid_invalid_duration', false);
549
+			}
538 550
 
539
-			if ($_POST['span_value'] > $limits[$_POST['span_unit']])
540
-				fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
551
+			if ($_POST['span_value'] > $limits[$_POST['span_unit']]) {
552
+							fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
553
+			}
541 554
 
542 555
 			// Clean the span.
543 556
 			$span = $_POST['span_value'] . $_POST['span_unit'];
@@ -546,8 +559,9 @@  discard block
 block discarded – undo
546 559
 			$cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.')));
547 560
 
548 561
 			// There needs to be something.
549
-			if (empty($_POST['span_value']) || empty($_POST['cost']))
550
-				fatal_lang_error('paid_no_cost_value');
562
+			if (empty($_POST['span_value']) || empty($_POST['cost'])) {
563
+							fatal_lang_error('paid_no_cost_value');
564
+			}
551 565
 		}
552 566
 		// Flexible is harder but more fun ;)
553 567
 		else
@@ -561,8 +575,9 @@  discard block
 block discarded – undo
561 575
 				'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')),
562 576
 			);
563 577
 
564
-			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year']))
565
-				fatal_lang_error('paid_all_freq_blank');
578
+			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) {
579
+							fatal_lang_error('paid_all_freq_blank');
580
+			}
566 581
 		}
567 582
 		$cost = json_encode($cost);
568 583
 
@@ -571,9 +586,10 @@  discard block
 block discarded – undo
571 586
 
572 587
 		// Yep, time to do additional groups.
573 588
 		$addgroups = array();
574
-		if (!empty($_POST['addgroup']))
575
-			foreach ($_POST['addgroup'] as $id => $dummy)
589
+		if (!empty($_POST['addgroup'])) {
590
+					foreach ($_POST['addgroup'] as $id => $dummy)
576 591
 				$addgroups[] = (int) $id;
592
+		}
577 593
 		$addgroups = implode(',', $addgroups);
578 594
 
579 595
 		// Is it new?!
@@ -682,18 +698,18 @@  discard block
 block discarded – undo
682 698
 			{
683 699
 				$span_value = $match[1];
684 700
 				$span_unit = $match[2];
685
-			}
686
-			else
701
+			} else
687 702
 			{
688 703
 				$span_value = 0;
689 704
 				$span_unit = 'D';
690 705
 			}
691 706
 
692 707
 			// Is this a flexible one?
693
-			if ($row['length'] == 'F')
694
-				$isFlexible = true;
695
-			else
696
-				$isFlexible = false;
708
+			if ($row['length'] == 'F') {
709
+							$isFlexible = true;
710
+			} else {
711
+							$isFlexible = false;
712
+			}
697 713
 
698 714
 			$context['sub'] = array(
699 715
 				'name' => $row['name'],
@@ -742,8 +758,9 @@  discard block
 block discarded – undo
742 758
 		)
743 759
 	);
744 760
 	$context['groups'] = array();
745
-	while ($row = $smcFunc['db_fetch_assoc']($request))
746
-		$context['groups'][$row['id_group']] = $row['group_name'];
761
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
762
+			$context['groups'][$row['id_group']] = $row['group_name'];
763
+	}
747 764
 	$smcFunc['db_free_result']($request);
748 765
 
749 766
 	// This always happens.
@@ -777,8 +794,9 @@  discard block
 block discarded – undo
777 794
 		)
778 795
 	);
779 796
 	// Something wrong?
780
-	if ($smcFunc['db_num_rows']($request) == 0)
781
-		fatal_lang_error('no_access', false);
797
+	if ($smcFunc['db_num_rows']($request) == 0) {
798
+			fatal_lang_error('no_access', false);
799
+	}
782 800
 	// Do the subscription context.
783 801
 	$row = $smcFunc['db_fetch_assoc']($request);
784 802
 	$context['subscription'] = array(
@@ -1013,8 +1031,8 @@  discard block
 block discarded – undo
1013 1031
 		))
1014 1032
 	);
1015 1033
 	$subscribers = array();
1016
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1017
-		$subscribers[] = array(
1034
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1035
+			$subscribers[] = array(
1018 1036
 			'id' => $row['id_sublog'],
1019 1037
 			'id_member' => $row['id_member'],
1020 1038
 			'name' => $row['name'],
@@ -1024,6 +1042,7 @@  discard block
 block discarded – undo
1024 1042
 			'status' => $row['status'],
1025 1043
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] == 0 ? $txt['paid_finished'] : $txt['paid_pending']) : $txt['paid_active'],
1026 1044
 		);
1045
+	}
1027 1046
 	$smcFunc['db_free_result']($request);
1028 1047
 
1029 1048
 	return $subscribers;
@@ -1058,14 +1077,16 @@  discard block
 block discarded – undo
1058 1077
 				'current_log_item' => $context['log_id'],
1059 1078
 			)
1060 1079
 		);
1061
-		if ($smcFunc['db_num_rows']($request) == 0)
1062
-			fatal_lang_error('no_access', false);
1080
+		if ($smcFunc['db_num_rows']($request) == 0) {
1081
+					fatal_lang_error('no_access', false);
1082
+		}
1063 1083
 		list ($context['sub_id']) = $smcFunc['db_fetch_row']($request);
1064 1084
 		$smcFunc['db_free_result']($request);
1065 1085
 	}
1066 1086
 
1067
-	if (!isset($context['subscriptions'][$context['sub_id']]))
1068
-		fatal_lang_error('no_access', false);
1087
+	if (!isset($context['subscriptions'][$context['sub_id']])) {
1088
+			fatal_lang_error('no_access', false);
1089
+	}
1069 1090
 	$context['current_subscription'] = $context['subscriptions'][$context['sub_id']];
1070 1091
 
1071 1092
 	// Searching?
@@ -1098,8 +1119,9 @@  discard block
 block discarded – undo
1098 1119
 					'name' => $_POST['name'],
1099 1120
 				)
1100 1121
 			);
1101
-			if ($smcFunc['db_num_rows']($request) == 0)
1102
-				fatal_lang_error('error_member_not_found');
1122
+			if ($smcFunc['db_num_rows']($request) == 0) {
1123
+							fatal_lang_error('error_member_not_found');
1124
+			}
1103 1125
 
1104 1126
 			list ($id_member, $id_group) = $smcFunc['db_fetch_row']($request);
1105 1127
 			$smcFunc['db_free_result']($request);
@@ -1115,14 +1137,15 @@  discard block
 block discarded – undo
1115 1137
 					'current_member' => $id_member,
1116 1138
 				)
1117 1139
 			);
1118
-			if ($smcFunc['db_num_rows']($request) != 0)
1119
-				fatal_lang_error('member_already_subscribed');
1140
+			if ($smcFunc['db_num_rows']($request) != 0) {
1141
+							fatal_lang_error('member_already_subscribed');
1142
+			}
1120 1143
 			$smcFunc['db_free_result']($request);
1121 1144
 
1122 1145
 			// Actually put the subscription in place.
1123
-			if ($status == 1)
1124
-				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1125
-			else
1146
+			if ($status == 1) {
1147
+							addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1148
+			} else
1126 1149
 			{
1127 1150
 				$smcFunc['db_insert']('',
1128 1151
 					'{db_prefix}log_subscribed',
@@ -1149,20 +1172,20 @@  discard block
 block discarded – undo
1149 1172
 					'current_log_item' => $context['log_id'],
1150 1173
 				)
1151 1174
 			);
1152
-			if ($smcFunc['db_num_rows']($request) == 0)
1153
-				fatal_lang_error('no_access', false);
1175
+			if ($smcFunc['db_num_rows']($request) == 0) {
1176
+							fatal_lang_error('no_access', false);
1177
+			}
1154 1178
 
1155 1179
 			list ($id_member, $old_status) = $smcFunc['db_fetch_row']($request);
1156 1180
 			$smcFunc['db_free_result']($request);
1157 1181
 
1158 1182
 			// Pick the right permission stuff depending on what the status is changing from/to.
1159
-			if ($old_status == 1 && $status != 1)
1160
-				removeSubscription($context['sub_id'], $id_member);
1161
-			elseif ($status == 1 && $old_status != 1)
1183
+			if ($old_status == 1 && $status != 1) {
1184
+							removeSubscription($context['sub_id'], $id_member);
1185
+			} elseif ($status == 1 && $old_status != 1)
1162 1186
 			{
1163 1187
 				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1164
-			}
1165
-			else
1188
+			} else
1166 1189
 			{
1167 1190
 				$smcFunc['db_query']('', '
1168 1191
 					UPDATE {db_prefix}log_subscribed
@@ -1190,8 +1213,9 @@  discard block
 block discarded – undo
1190 1213
 		if (!empty($_REQUEST['delsub']))
1191 1214
 		{
1192 1215
 			$toDelete = array();
1193
-			foreach ($_REQUEST['delsub'] as $id => $dummy)
1194
-				$toDelete[] = (int) $id;
1216
+			foreach ($_REQUEST['delsub'] as $id => $dummy) {
1217
+							$toDelete[] = (int) $id;
1218
+			}
1195 1219
 
1196 1220
 			$request = $smcFunc['db_query']('', '
1197 1221
 				SELECT id_subscribe, id_member
@@ -1201,8 +1225,9 @@  discard block
 block discarded – undo
1201 1225
 					'subscription_list' => $toDelete,
1202 1226
 				)
1203 1227
 			);
1204
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1205
-				removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1228
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1229
+							removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1230
+			}
1206 1231
 			$smcFunc['db_free_result']($request);
1207 1232
 		}
1208 1233
 		redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']);
@@ -1246,9 +1271,9 @@  discard block
 block discarded – undo
1246 1271
 			);
1247 1272
 			list ($context['sub']['username']) = $smcFunc['db_fetch_row']($request);
1248 1273
 			$smcFunc['db_free_result']($request);
1274
+		} else {
1275
+					$context['sub']['username'] = '';
1249 1276
 		}
1250
-		else
1251
-			$context['sub']['username'] = '';
1252 1277
 	}
1253 1278
 	// Otherwise load the existing info.
1254 1279
 	else
@@ -1265,8 +1290,9 @@  discard block
 block discarded – undo
1265 1290
 				'blank_string' => '',
1266 1291
 			)
1267 1292
 		);
1268
-		if ($smcFunc['db_num_rows']($request) == 0)
1269
-			fatal_lang_error('no_access', false);
1293
+		if ($smcFunc['db_num_rows']($request) == 0) {
1294
+					fatal_lang_error('no_access', false);
1295
+		}
1270 1296
 		$row = $smcFunc['db_fetch_assoc']($request);
1271 1297
 		$smcFunc['db_free_result']($request);
1272 1298
 
@@ -1287,13 +1313,13 @@  discard block
 block discarded – undo
1287 1313
 					{
1288 1314
 						foreach ($costs as $duration => $cost)
1289 1315
 						{
1290
-							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2])
1291
-								$context['pending_payments'][$id] = array(
1316
+							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) {
1317
+															$context['pending_payments'][$id] = array(
1292 1318
 									'desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]),
1293 1319
 								);
1320
+							}
1294 1321
 						}
1295
-					}
1296
-					elseif ($costs['fixed'] == $pending[1])
1322
+					} elseif ($costs['fixed'] == $pending[1])
1297 1323
 					{
1298 1324
 						$context['pending_payments'][$id] = array(
1299 1325
 							'desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']),
@@ -1311,8 +1337,9 @@  discard block
 block discarded – undo
1311 1337
 					if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id]))
1312 1338
 					{
1313 1339
 						// Flexible?
1314
-						if (isset($_GET['accept']))
1315
-							addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1340
+						if (isset($_GET['accept'])) {
1341
+													addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1342
+						}
1316 1343
 						unset($pending_details[$id]);
1317 1344
 
1318 1345
 						$new_details = json_encode($pending_details);
@@ -1374,8 +1401,9 @@  discard block
 block discarded – undo
1374 1401
 	global $smcFunc;
1375 1402
 
1376 1403
 	// Make it an array.
1377
-	if (!is_array($users))
1378
-		$users = array($users);
1404
+	if (!is_array($users)) {
1405
+			$users = array($users);
1406
+	}
1379 1407
 
1380 1408
 	// Get all the members current groups.
1381 1409
 	$groups = array();
@@ -1413,14 +1441,16 @@  discard block
 block discarded – undo
1413 1441
 		if ($row['id_group'] != 0)
1414 1442
 		{
1415 1443
 			// If this is changing - add the old one to the additional groups so it's not lost.
1416
-			if ($row['id_group'] != $groups[$row['id_member']]['primary'])
1417
-				$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1444
+			if ($row['id_group'] != $groups[$row['id_member']]['primary']) {
1445
+							$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1446
+			}
1418 1447
 			$groups[$row['id_member']]['primary'] = $row['id_group'];
1419 1448
 		}
1420 1449
 
1421 1450
 		// Additional groups.
1422
-		if (!empty($row['add_groups']))
1423
-			$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1451
+		if (!empty($row['add_groups'])) {
1452
+					$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1453
+		}
1424 1454
 	}
1425 1455
 	$smcFunc['db_free_result']($request);
1426 1456
 
@@ -1428,9 +1458,10 @@  discard block
 block discarded – undo
1428 1458
 	foreach ($groups as $id => $group)
1429 1459
 	{
1430 1460
 		$group['additional'] = array_unique($group['additional']);
1431
-		foreach ($group['additional'] as $key => $value)
1432
-			if (empty($value))
1461
+		foreach ($group['additional'] as $key => $value) {
1462
+					if (empty($value))
1433 1463
 				unset($group['additional'][$key]);
1464
+		}
1434 1465
 		$addgroups = implode(',', $group['additional']);
1435 1466
 
1436 1467
 		$smcFunc['db_query']('', '
@@ -1464,8 +1495,9 @@  discard block
 block discarded – undo
1464 1495
 	loadSubscriptions();
1465 1496
 
1466 1497
 	// Exists, yes?
1467
-	if (!isset($context['subscriptions'][$id_subscribe]))
1468
-		return;
1498
+	if (!isset($context['subscriptions'][$id_subscribe])) {
1499
+			return;
1500
+	}
1469 1501
 
1470 1502
 	$curSub = $context['subscriptions'][$id_subscribe];
1471 1503
 
@@ -1513,16 +1545,19 @@  discard block
 block discarded – undo
1513 1545
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1514 1546
 
1515 1547
 		// If this has already expired but is active, extension means the period from now.
1516
-		if ($endtime < time())
1517
-			$endtime = time();
1518
-		if ($starttime == 0)
1519
-			$starttime = time();
1548
+		if ($endtime < time()) {
1549
+					$endtime = time();
1550
+		}
1551
+		if ($starttime == 0) {
1552
+					$starttime = time();
1553
+		}
1520 1554
 
1521 1555
 		// Work out the new expiry date.
1522 1556
 		$endtime += $duration;
1523 1557
 
1524
-		if ($forceEndTime != 0)
1525
-			$endtime = $forceEndTime;
1558
+		if ($forceEndTime != 0) {
1559
+					$endtime = $forceEndTime;
1560
+		}
1526 1561
 
1527 1562
 		// As everything else should be good, just update!
1528 1563
 		$smcFunc['db_query']('', '
@@ -1552,8 +1587,9 @@  discard block
 block discarded – undo
1552 1587
 	);
1553 1588
 
1554 1589
 	// Just in case the member doesn't exist.
1555
-	if ($smcFunc['db_num_rows']($request) == 0)
1556
-		return;
1590
+	if ($smcFunc['db_num_rows']($request) == 0) {
1591
+			return;
1592
+	}
1557 1593
 
1558 1594
 	list ($old_id_group, $additional_groups) = $smcFunc['db_fetch_row']($request);
1559 1595
 	$smcFunc['db_free_result']($request);
@@ -1570,16 +1606,18 @@  discard block
 block discarded – undo
1570 1606
 		$id_group = $curSub['prim_group'];
1571 1607
 
1572 1608
 		// Ensure their old privileges are maintained.
1573
-		if ($old_id_group != 0)
1574
-			$newAddGroups[] = $old_id_group;
1609
+		if ($old_id_group != 0) {
1610
+					$newAddGroups[] = $old_id_group;
1611
+		}
1612
+	} else {
1613
+			$id_group = $old_id_group;
1575 1614
 	}
1576
-	else
1577
-		$id_group = $old_id_group;
1578 1615
 
1579 1616
 	// Yep, make sure it's unique, and no empties.
1580
-	foreach ($newAddGroups as $k => $v)
1581
-		if (empty($v))
1617
+	foreach ($newAddGroups as $k => $v) {
1618
+			if (empty($v))
1582 1619
 			unset($newAddGroups[$k]);
1620
+	}
1583 1621
 	$newAddGroups = array_unique($newAddGroups);
1584 1622
 	$newAddGroups = implode(',', $newAddGroups);
1585 1623
 
@@ -1615,16 +1653,19 @@  discard block
 block discarded – undo
1615 1653
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1616 1654
 
1617 1655
 		// If this has already expired but is active, extension means the period from now.
1618
-		if ($endtime < time())
1619
-			$endtime = time();
1620
-		if ($starttime == 0)
1621
-			$starttime = time();
1656
+		if ($endtime < time()) {
1657
+					$endtime = time();
1658
+		}
1659
+		if ($starttime == 0) {
1660
+					$starttime = time();
1661
+		}
1622 1662
 
1623 1663
 		// Work out the new expiry date.
1624 1664
 		$endtime += $duration;
1625 1665
 
1626
-		if ($forceEndTime != 0)
1627
-			$endtime = $forceEndTime;
1666
+		if ($forceEndTime != 0) {
1667
+					$endtime = $forceEndTime;
1668
+		}
1628 1669
 
1629 1670
 		// As everything else should be good, just update!
1630 1671
 		$smcFunc['db_query']('', '
@@ -1647,13 +1688,15 @@  discard block
 block discarded – undo
1647 1688
 
1648 1689
 	// Otherwise a very simple insert.
1649 1690
 	$endtime = time() + $duration;
1650
-	if ($forceEndTime != 0)
1651
-		$endtime = $forceEndTime;
1691
+	if ($forceEndTime != 0) {
1692
+			$endtime = $forceEndTime;
1693
+	}
1652 1694
 
1653
-	if ($forceStartTime == 0)
1654
-		$starttime = time();
1655
-	else
1656
-		$starttime = $forceStartTime;
1695
+	if ($forceStartTime == 0) {
1696
+			$starttime = time();
1697
+	} else {
1698
+			$starttime = $forceStartTime;
1699
+	}
1657 1700
 
1658 1701
 	$smcFunc['db_insert']('',
1659 1702
 		'{db_prefix}log_subscribed',
@@ -1726,15 +1769,17 @@  discard block
 block discarded – undo
1726 1769
 	$new_id_group = -1;
1727 1770
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1728 1771
 	{
1729
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
1730
-			continue;
1772
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
1773
+					continue;
1774
+		}
1731 1775
 
1732 1776
 		// The one we're removing?
1733 1777
 		if ($row['id_subscribe'] == $id_subscribe)
1734 1778
 		{
1735 1779
 			$removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']);
1736
-			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0)
1737
-				$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1780
+			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) {
1781
+							$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1782
+			}
1738 1783
 			$old_id_group = $row['old_id_group'];
1739 1784
 		}
1740 1785
 		// Otherwise things we allow.
@@ -1752,30 +1797,33 @@  discard block
 block discarded – undo
1752 1797
 
1753 1798
 	// Now, for everything we are removing check they definitely are not allowed it.
1754 1799
 	$existingGroups = explode(',', $additional_groups);
1755
-	foreach ($existingGroups as $key => $group)
1756
-		if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1800
+	foreach ($existingGroups as $key => $group) {
1801
+			if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1757 1802
 			unset($existingGroups[$key]);
1803
+	}
1758 1804
 
1759 1805
 	// Finally, do something with the current primary group.
1760 1806
 	if (in_array($id_group, $removals))
1761 1807
 	{
1762 1808
 		// If this primary group is actually allowed keep it.
1763
-		if (in_array($id_group, $allowed))
1764
-			$existingGroups[] = $id_group;
1809
+		if (in_array($id_group, $allowed)) {
1810
+					$existingGroups[] = $id_group;
1811
+		}
1765 1812
 
1766 1813
 		// Either way, change the id_group back.
1767 1814
 		if ($new_id_group < 1)
1768 1815
 		{
1769 1816
 			// If we revert to the old id-group we need to ensure it wasn't from a subscription.
1770
-			foreach ($context['subscriptions'] as $id => $group)
1771
-				// It was? Make them a regular member then!
1817
+			foreach ($context['subscriptions'] as $id => $group) {
1818
+							// It was? Make them a regular member then!
1772 1819
 				if ($group['prim_group'] == $old_id_group)
1773 1820
 					$old_id_group = 0;
1821
+			}
1774 1822
 
1775 1823
 			$id_group = $old_id_group;
1824
+		} else {
1825
+					$id_group = $new_id_group;
1776 1826
 		}
1777
-		else
1778
-			$id_group = $new_id_group;
1779 1827
 	}
1780 1828
 
1781 1829
 	// Crazy stuff, we seem to have our groups fixed, just make them unique
@@ -1795,8 +1843,8 @@  discard block
 block discarded – undo
1795 1843
 	);
1796 1844
 
1797 1845
 	// Disable the subscription.
1798
-	if (!$delete)
1799
-		$smcFunc['db_query']('', '
1846
+	if (!$delete) {
1847
+			$smcFunc['db_query']('', '
1800 1848
 			UPDATE {db_prefix}log_subscribed
1801 1849
 			SET status = {int:not_active}
1802 1850
 			WHERE id_member = {int:current_member}
@@ -1807,9 +1855,10 @@  discard block
 block discarded – undo
1807 1855
 				'current_subscription' => $id_subscribe,
1808 1856
 			)
1809 1857
 		);
1858
+	}
1810 1859
 	// Otherwise delete it!
1811
-	else
1812
-		$smcFunc['db_query']('', '
1860
+	else {
1861
+			$smcFunc['db_query']('', '
1813 1862
 			DELETE FROM {db_prefix}log_subscribed
1814 1863
 			WHERE id_member = {int:current_member}
1815 1864
 				AND id_subscribe = {int:current_subscription}',
@@ -1818,7 +1867,8 @@  discard block
 block discarded – undo
1818 1867
 				'current_subscription' => $id_subscribe,
1819 1868
 			)
1820 1869
 		);
1821
-}
1870
+	}
1871
+	}
1822 1872
 
1823 1873
 /**
1824 1874
  * This just kind of caches all the subscription data.
@@ -1827,8 +1877,9 @@  discard block
 block discarded – undo
1827 1877
 {
1828 1878
 	global $context, $txt, $modSettings, $smcFunc;
1829 1879
 
1830
-	if (!empty($context['subscriptions']))
1831
-		return;
1880
+	if (!empty($context['subscriptions'])) {
1881
+			return;
1882
+	}
1832 1883
 
1833 1884
 	// Make sure this is loaded, just in case.
1834 1885
 	loadLanguage('ManagePaid');
@@ -1845,10 +1896,11 @@  discard block
 block discarded – undo
1845 1896
 		// Pick a cost.
1846 1897
 		$costs = smf_json_decode($row['cost'], true);
1847 1898
 
1848
-		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed']))
1849
-			$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1850
-		else
1851
-			$cost = '???';
1899
+		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) {
1900
+					$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1901
+		} else {
1902
+					$cost = '???';
1903
+		}
1852 1904
 
1853 1905
 		// Do the span.
1854 1906
 		preg_match('~(\d*)(\w)~', $row['length'], $match);
@@ -1875,9 +1927,9 @@  discard block
 block discarded – undo
1875 1927
 					$num_length *= 31556926;
1876 1928
 					break;
1877 1929
 			}
1930
+		} else {
1931
+					$length = '??';
1878 1932
 		}
1879
-		else
1880
-			$length = '??';
1881 1933
 
1882 1934
 		$context['subscriptions'][$row['id_subscribe']] = array(
1883 1935
 			'id' => $row['id_subscribe'],
@@ -1912,8 +1964,9 @@  discard block
 block discarded – undo
1912 1964
 	{
1913 1965
 		$ind = $row['status'] == 0 ? 'finished' : 'total';
1914 1966
 
1915
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1916
-			$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1967
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1968
+					$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1969
+		}
1917 1970
 	}
1918 1971
 	$smcFunc['db_free_result']($request);
1919 1972
 
@@ -1927,8 +1980,9 @@  discard block
 block discarded – undo
1927 1980
 	);
1928 1981
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1929 1982
 	{
1930
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1931
-			$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1983
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1984
+					$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1985
+		}
1932 1986
 	}
1933 1987
 	$smcFunc['db_free_result']($request);
1934 1988
 }
Please login to merge, or discard this patch.
Sources/PersonalMessage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4070,7 +4070,7 @@
 block discarded – undo
4070 4070
  *
4071 4071
  * @param int $pmID The ID of the PM
4072 4072
  * @param string $validFor Which folders this is valud for - can be 'inbox', 'outbox' or 'in_or_outbox'
4073
- * @return boolean Whether the PM is accessible in that folder for the current user
4073
+ * @return boolean|null Whether the PM is accessible in that folder for the current user
4074 4074
  */
4075 4075
 function isAccessiblePM($pmID, $validFor = 'in_or_outbox')
4076 4076
 {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
620 620
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
621 621
 					WHERE pmr.id_member = {int:current_member}
622
-						AND pmr.deleted = {int:not_deleted}' . $labelQuery .  $labelQuery2 . '
622
+						AND pmr.deleted = {int:not_deleted}' . $labelQuery . $labelQuery2 . '
623 623
 						AND pmr.id_pm ' . ($descending ? '>' : '<') . ' {int:id_pm}',
624 624
 					array(
625 625
 						'current_member' => $user_info['id'],
@@ -682,12 +682,12 @@  discard block
 block discarded – undo
682 682
 				INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
683 683
 					AND pmr.id_member = {int:current_member}
684 684
 					AND pmr.deleted = {int:deleted_by}
685
-					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ( '
685
+					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ('
686 686
 				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:pm_member})') : '') . '
687 687
 				WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {int:current_member}
688 688
 					AND pm.deleted_by_sender = {int:deleted_by}' : '1=1') . (empty($pmsg) ? '' : '
689 689
 					AND pm.id_pm = {int:pmsg}') . $labelQuery2 . '
690
-				GROUP BY pm.id_pm_head'.($_GET['sort'] != 'pm.id_pm' ? ','.$_GET['sort'] : '').'
690
+				GROUP BY pm.id_pm_head'.($_GET['sort'] != 'pm.id_pm' ? ',' . $_GET['sort'] : '') . '
691 691
 				ORDER BY ' . ($_GET['sort'] == 'pm.id_pm' && $context['folder'] != 'sent' ? 'id_pm' : '{raw:sort}') . ($descending ? ' DESC' : ' ASC') . (empty($_GET['pmsg']) ? '
692 692
 				LIMIT ' . $_GET['start'] . ', ' . $maxPerPage : ''),
693 693
 				array(
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 				INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
712 712
 					AND pmr.id_member = {int:current_member}
713 713
 					AND pmr.deleted = {int:is_deleted}
714
-					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ( '
714
+					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ('
715 715
 				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:pm_member})') : '') . '
716 716
 			WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {raw:current_member}
717 717
 				AND pm.deleted_by_sender = {int:is_deleted}' : '1=1') . (empty($pmsg) ? '' : '
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 					)
849 849
 				);
850 850
 
851
-				while($row2 = $smcFunc['db_fetch_assoc']($request2))
851
+				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
852 852
 				{
853 853
 					$l_id = $row2['id_label'];
854 854
 					if (isset($context['labels'][$l_id]))
@@ -1626,7 +1626,7 @@  discard block
 block discarded – undo
1626 1626
 					)
1627 1627
 				);
1628 1628
 
1629
-				while($row2 = $smcFunc['db_fetch_assoc']($request2))
1629
+				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1630 1630
 				{
1631 1631
 					$l_id = $row2['id_label'];
1632 1632
 					if (isset($context['labels'][$l_id]))
@@ -3723,7 +3723,7 @@  discard block
 block discarded – undo
3723 3723
 	// Editing a specific one?
3724 3724
 	if (isset($_GET['add']))
3725 3725
 	{
3726
-		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']])? (int) $_GET['rid'] : 0;
3726
+		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0;
3727 3727
 		$context['sub_template'] = 'add_rule';
3728 3728
 
3729 3729
 		// Current rule information...
@@ -3764,7 +3764,7 @@  discard block
 block discarded – undo
3764 3764
 	elseif (isset($_GET['save']))
3765 3765
 	{
3766 3766
 		checkSession();
3767
-		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']])? (int) $_GET['rid'] : 0;
3767
+		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0;
3768 3768
 
3769 3769
 		// Name is easy!
3770 3770
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
Please login to merge, or discard this patch.
Braces   +633 added lines, -471 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -291,16 +294,17 @@  discard block
 block discarded – undo
291 294
 	);
292 295
 
293 296
 	// Handle labels.
294
-	if (empty($context['currently_using_labels']))
295
-		unset($pm_areas['labels']);
296
-	else
297
+	if (empty($context['currently_using_labels'])) {
298
+			unset($pm_areas['labels']);
299
+	} else
297 300
 	{
298 301
 		// Note we send labels by id as it will have less problems in the querystring.
299 302
 		$unread_in_labels = 0;
300 303
 		foreach ($context['labels'] as $label)
301 304
 		{
302
-			if ($label['id'] == -1)
303
-				continue;
305
+			if ($label['id'] == -1) {
306
+							continue;
307
+			}
304 308
 
305 309
 			// Count the amount of unread items in labels.
306 310
 			$unread_in_labels += $label['unread_messages'];
@@ -314,8 +318,9 @@  discard block
 block discarded – undo
314 318
 			);
315 319
 		}
316 320
 
317
-		if (!empty($unread_in_labels))
318
-			$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
321
+		if (!empty($unread_in_labels)) {
322
+					$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
323
+		}
319 324
 	}
320 325
 
321 326
 	$pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
@@ -356,8 +361,9 @@  discard block
 block discarded – undo
356 361
 	unset($pm_areas);
357 362
 
358 363
 	// No menu means no access.
359
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
360
-		fatal_lang_error('no_access', false);
364
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
365
+			fatal_lang_error('no_access', false);
366
+	}
361 367
 
362 368
 	// Make a note of the Unique ID for this menu.
363 369
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -368,9 +374,10 @@  discard block
 block discarded – undo
368 374
 	$context['menu_item_selected'] = $current_area;
369 375
 
370 376
 	// Set the template for this area and add the profile layer.
371
-	if (!isset($_REQUEST['xml']))
372
-		$context['template_layers'][] = 'pm';
373
-}
377
+	if (!isset($_REQUEST['xml'])) {
378
+			$context['template_layers'][] = 'pm';
379
+	}
380
+	}
374 381
 
375 382
 /**
376 383
  * The popup for when we ask for the popup from the user.
@@ -402,8 +409,9 @@  discard block
 block discarded – undo
402 409
 		)
403 410
 	);
404 411
 	$pms = array();
405
-	while ($row = $smcFunc['db_fetch_row']($request))
406
-		$pms[] = $row[0];
412
+	while ($row = $smcFunc['db_fetch_row']($request)) {
413
+			$pms[] = $row[0];
414
+	}
407 415
 	$smcFunc['db_free_result']($request);
408 416
 
409 417
 	if (!empty($pms))
@@ -431,8 +439,9 @@  discard block
 block discarded – undo
431 439
 		);
432 440
 		while ($row = $smcFunc['db_fetch_assoc']($request))
433 441
 		{
434
-			if (!empty($row['id_member_from']))
435
-				$senders[] = $row['id_member_from'];
442
+			if (!empty($row['id_member_from'])) {
443
+							$senders[] = $row['id_member_from'];
444
+			}
436 445
 
437 446
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
438 447
 			$row['time'] = timeformat($row['timestamp']);
@@ -442,13 +451,15 @@  discard block
 block discarded – undo
442 451
 		$smcFunc['db_free_result']($request);
443 452
 
444 453
 		$senders = loadMemberData($senders);
445
-		foreach ($senders as $member)
446
-			loadMemberContext($member);
454
+		foreach ($senders as $member) {
455
+					loadMemberContext($member);
456
+		}
447 457
 
448 458
 		// Having loaded everyone, attach them to the PMs.
449
-		foreach ($context['unread_pms'] as $id_pm => $details)
450
-			if (!empty($memberContext[$details['id_member_from']]))
459
+		foreach ($context['unread_pms'] as $id_pm => $details) {
460
+					if (!empty($memberContext[$details['id_member_from']]))
451 461
 				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
462
+		}
452 463
 	}
453 464
 }
454 465
 
@@ -468,12 +479,13 @@  discard block
 block discarded – undo
468 479
 	}
469 480
 
470 481
 	// Make sure the starting location is valid.
471
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
472
-		$_GET['start'] = (int) $_GET['start'];
473
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
474
-		$_GET['start'] = 0;
475
-	else
476
-		$_GET['start'] = 'new';
482
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
483
+			$_GET['start'] = (int) $_GET['start'];
484
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
485
+			$_GET['start'] = 0;
486
+	} else {
487
+			$_GET['start'] = 'new';
488
+	}
477 489
 
478 490
 	// Set up some basic theme stuff.
479 491
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -490,8 +502,7 @@  discard block
 block discarded – undo
490 502
 	{
491 503
 		$labelQuery = '
492 504
 			AND pmr.in_inbox = 1';
493
-	}
494
-	elseif ($context['folder'] != 'sent')
505
+	} elseif ($context['folder'] != 'sent')
495 506
 	{
496 507
 		$labelJoin = '
497 508
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -533,22 +544,24 @@  discard block
 block discarded – undo
533 544
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
534 545
 
535 546
 	// Now, build the link tree!
536
-	if ($context['current_label_id'] == -1)
537
-		$context['linktree'][] = array(
547
+	if ($context['current_label_id'] == -1) {
548
+			$context['linktree'][] = array(
538 549
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
539 550
 			'name' => $pmbox
540 551
 		);
552
+	}
541 553
 
542 554
 	// Build it further for a label.
543
-	if ($context['current_label_id'] != -1)
544
-		$context['linktree'][] = array(
555
+	if ($context['current_label_id'] != -1) {
556
+			$context['linktree'][] = array(
545 557
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
546 558
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
547 559
 		);
560
+	}
548 561
 
549 562
 	// Figure out how many messages there are.
550
-	if ($context['folder'] == 'sent')
551
-		$request = $smcFunc['db_query']('', '
563
+	if ($context['folder'] == 'sent') {
564
+			$request = $smcFunc['db_query']('', '
552 565
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
553 566
 			FROM {db_prefix}personal_messages AS pm
554 567
 			WHERE pm.id_member_from = {int:current_member}
@@ -558,8 +571,8 @@  discard block
 block discarded – undo
558 571
 				'not_deleted' => 0,
559 572
 			)
560 573
 		);
561
-	else
562
-		$request = $smcFunc['db_query']('', '
574
+	} else {
575
+			$request = $smcFunc['db_query']('', '
563 576
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
564 577
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
565 578
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -570,6 +583,7 @@  discard block
 block discarded – undo
570 583
 				'not_deleted' => 0,
571 584
 			)
572 585
 		);
586
+	}
573 587
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
574 588
 	$smcFunc['db_free_result']($request);
575 589
 
@@ -578,10 +592,11 @@  discard block
 block discarded – undo
578 592
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
579 593
 
580 594
 	// Start on the last page.
581
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
582
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
583
-	elseif ($_GET['start'] < 0)
584
-		$_GET['start'] = 0;
595
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
596
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
597
+	} elseif ($_GET['start'] < 0) {
598
+			$_GET['start'] = 0;
599
+	}
585 600
 
586 601
 	// ... but wait - what if we want to start from a specific message?
587 602
 	if (isset($_GET['pmid']))
@@ -589,19 +604,21 @@  discard block
 block discarded – undo
589 604
 		$pmID = (int) $_GET['pmid'];
590 605
 
591 606
 		// Make sure you have access to this PM.
592
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
593
-			fatal_lang_error('no_access', false);
607
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
608
+					fatal_lang_error('no_access', false);
609
+		}
594 610
 
595 611
 		$context['current_pm'] = $pmID;
596 612
 
597 613
 		// With only one page of PM's we're gonna want page 1.
598
-		if ($max_messages <= $maxPerPage)
599
-			$_GET['start'] = 0;
614
+		if ($max_messages <= $maxPerPage) {
615
+					$_GET['start'] = 0;
616
+		}
600 617
 		// If we pass kstart we assume we're in the right place.
601 618
 		elseif (!isset($_GET['kstart']))
602 619
 		{
603
-			if ($context['folder'] == 'sent')
604
-				$request = $smcFunc['db_query']('', '
620
+			if ($context['folder'] == 'sent') {
621
+							$request = $smcFunc['db_query']('', '
605 622
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
606 623
 					FROM {db_prefix}personal_messages
607 624
 					WHERE id_member_from = {int:current_member}
@@ -613,8 +630,8 @@  discard block
 block discarded – undo
613 630
 						'id_pm' => $pmID,
614 631
 					)
615 632
 				);
616
-			else
617
-				$request = $smcFunc['db_query']('', '
633
+			} else {
634
+							$request = $smcFunc['db_query']('', '
618 635
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
619 636
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
620 637
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -627,6 +644,7 @@  discard block
 block discarded – undo
627 644
 						'id_pm' => $pmID,
628 645
 					)
629 646
 				);
647
+			}
630 648
 
631 649
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
632 650
 			$smcFunc['db_free_result']($request);
@@ -641,8 +659,9 @@  discard block
 block discarded – undo
641 659
 	{
642 660
 		$pmsg = (int) $_GET['pmsg'];
643 661
 
644
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
645
-			fatal_lang_error('no_access', false);
662
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
663
+					fatal_lang_error('no_access', false);
664
+		}
646 665
 	}
647 666
 
648 667
 	// Set up the page index.
@@ -737,8 +756,9 @@  discard block
 block discarded – undo
737 756
 	{
738 757
 		if (!isset($recipients[$row['id_pm']]))
739 758
 		{
740
-			if (isset($row['id_member_from']))
741
-				$posters[$row['id_pm']] = $row['id_member_from'];
759
+			if (isset($row['id_member_from'])) {
760
+							$posters[$row['id_pm']] = $row['id_member_from'];
761
+			}
742 762
 			$pms[$row['id_pm']] = $row['id_pm'];
743 763
 			$recipients[$row['id_pm']] = array(
744 764
 				'to' => array(),
@@ -747,29 +767,33 @@  discard block
 block discarded – undo
747 767
 		}
748 768
 
749 769
 		// Keep track of the last message so we know what the head is without another query!
750
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
751
-			$lastData = array(
770
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
771
+					$lastData = array(
752 772
 				'id' => $row['id_pm'],
753 773
 				'head' => $row['id_pm_head'],
754 774
 			);
775
+		}
755 776
 	}
756 777
 	$smcFunc['db_free_result']($request);
757 778
 
758 779
 	// Make sure that we have been given a correct head pm id!
759
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
760
-		fatal_lang_error('no_access', false);
780
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
781
+			fatal_lang_error('no_access', false);
782
+	}
761 783
 
762 784
 	if (!empty($pms))
763 785
 	{
764 786
 		// Select the correct current message.
765
-		if (empty($pmID))
766
-			$context['current_pm'] = $lastData['id'];
787
+		if (empty($pmID)) {
788
+					$context['current_pm'] = $lastData['id'];
789
+		}
767 790
 
768 791
 		// This is a list of the pm's that are used for "full" display.
769
-		if ($context['display_mode'] == 0)
770
-			$display_pms = $pms;
771
-		else
772
-			$display_pms = array($context['current_pm']);
792
+		if ($context['display_mode'] == 0) {
793
+					$display_pms = $pms;
794
+		} else {
795
+					$display_pms = array($context['current_pm']);
796
+		}
773 797
 
774 798
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
775 799
 		if ($context['display_mode'] == 2)
@@ -791,16 +815,18 @@  discard block
 block discarded – undo
791 815
 			while ($row = $smcFunc['db_fetch_assoc']($request))
792 816
 			{
793 817
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
794
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
795
-					continue;
796
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
797
-					continue;
818
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
819
+									continue;
820
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
821
+									continue;
822
+				}
798 823
 
799
-				if (!isset($recipients[$row['id_pm']]))
800
-					$recipients[$row['id_pm']] = array(
824
+				if (!isset($recipients[$row['id_pm']])) {
825
+									$recipients[$row['id_pm']] = array(
801 826
 						'to' => array(),
802 827
 						'bcc' => array()
803 828
 					);
829
+				}
804 830
 				$display_pms[] = $row['id_pm'];
805 831
 				$posters[$row['id_pm']] = $row['id_member_from'];
806 832
 			}
@@ -851,8 +877,9 @@  discard block
 block discarded – undo
851 877
 				while($row2 = $smcFunc['db_fetch_assoc']($request2))
852 878
 				{
853 879
 					$l_id = $row2['id_label'];
854
-					if (isset($context['labels'][$l_id]))
855
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
880
+					if (isset($context['labels'][$l_id])) {
881
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
882
+					}
856 883
 				}
857 884
 
858 885
 				$smcFunc['db_free_result']($request2);
@@ -869,9 +896,10 @@  discard block
 block discarded – undo
869 896
 		// Make sure we don't load unnecessary data.
870 897
 		if ($context['display_mode'] == 1)
871 898
 		{
872
-			foreach ($posters as $k => $v)
873
-				if (!in_array($k, $display_pms))
899
+			foreach ($posters as $k => $v) {
900
+							if (!in_array($k, $display_pms))
874 901
 					unset($posters[$k]);
902
+			}
875 903
 		}
876 904
 
877 905
 		// Load any users....
@@ -882,8 +910,9 @@  discard block
 block discarded – undo
882 910
 		{
883 911
 			// Get the order right.
884 912
 			$orderBy = array();
885
-			foreach (array_reverse($pms) as $pm)
886
-				$orderBy[] = 'pm.id_pm = ' . $pm;
913
+			foreach (array_reverse($pms) as $pm) {
914
+							$orderBy[] = 'pm.id_pm = ' . $pm;
915
+			}
887 916
 
888 917
 			// Seperate query for these bits!
889 918
 			$subjects_request = $smcFunc['db_query']('', '
@@ -929,9 +958,9 @@  discard block
 block discarded – undo
929 958
 			// Allow mods to add additional buttons here
930 959
 			call_integration_hook('integrate_conversation_buttons');
931 960
 		}
961
+	} else {
962
+			$messages_request = false;
932 963
 	}
933
-	else
934
-		$messages_request = false;
935 964
 
936 965
 	$context['can_send_pm'] = allowedTo('pm_send');
937 966
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -942,11 +971,13 @@  discard block
 block discarded – undo
942 971
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
943 972
 	{
944 973
 		// If the display mode is "old sk00l" do them all...
945
-		if ($context['display_mode'] == 0)
946
-			markMessages(null, $context['current_label_id']);
974
+		if ($context['display_mode'] == 0) {
975
+					markMessages(null, $context['current_label_id']);
976
+		}
947 977
 		// Otherwise do just the current one!
948
-		elseif (!empty($context['current_pm']))
949
-			markMessages($display_pms, $context['current_label_id']);
978
+		elseif (!empty($context['current_pm'])) {
979
+					markMessages($display_pms, $context['current_label_id']);
980
+		}
950 981
 	}
951 982
 }
952 983
 
@@ -964,8 +995,9 @@  discard block
 block discarded – undo
964 995
 
965 996
 	// Count the current message number....
966 997
 	static $counter = null;
967
-	if ($counter === null || $reset)
968
-		$counter = $context['start'];
998
+	if ($counter === null || $reset) {
999
+			$counter = $context['start'];
1000
+	}
969 1001
 
970 1002
 	static $temp_pm_selected = null;
971 1003
 	if ($temp_pm_selected === null)
@@ -1010,19 +1042,22 @@  discard block
 block discarded – undo
1010 1042
 	}
1011 1043
 
1012 1044
 	// Bail if it's false, ie. no messages.
1013
-	if ($messages_request == false)
1014
-		return false;
1045
+	if ($messages_request == false) {
1046
+			return false;
1047
+	}
1015 1048
 
1016 1049
 	// Reset the data?
1017
-	if ($reset == true)
1018
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1050
+	if ($reset == true) {
1051
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1052
+	}
1019 1053
 
1020 1054
 	// Get the next one... bail if anything goes wrong.
1021 1055
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1022 1056
 	if (!$message)
1023 1057
 	{
1024
-		if ($type != 'subject')
1025
-			$smcFunc['db_free_result']($messages_request);
1058
+		if ($type != 'subject') {
1059
+					$smcFunc['db_free_result']($messages_request);
1060
+		}
1026 1061
 
1027 1062
 		return false;
1028 1063
 	}
@@ -1042,8 +1077,7 @@  discard block
 block discarded – undo
1042 1077
 		$memberContext[$message['id_member_from']]['email'] = '';
1043 1078
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1044 1079
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1045
-	}
1046
-	else
1080
+	} else
1047 1081
 	{
1048 1082
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1049 1083
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1084,12 +1118,13 @@  discard block
 block discarded – undo
1084 1118
 	$counter++;
1085 1119
 
1086 1120
 	// Any custom profile fields?
1087
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1088
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1121
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1122
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1089 1123
 			switch ($custom['placement'])
1090 1124
 			{
1091 1125
 				case 1:
1092 1126
 					$output['custom_fields']['icons'][] = $custom;
1127
+	}
1093 1128
 					break;
1094 1129
 				case 2:
1095 1130
 					$output['custom_fields']['above_signature'][] = $custom;
@@ -1132,22 +1167,28 @@  discard block
 block discarded – undo
1132 1167
 			$context['search_params'][$k] = $v;
1133 1168
 		}
1134 1169
 	}
1135
-	if (isset($_REQUEST['search']))
1136
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1170
+	if (isset($_REQUEST['search'])) {
1171
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1172
+	}
1137 1173
 
1138
-	if (isset($context['search_params']['search']))
1139
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1140
-	if (isset($context['search_params']['userspec']))
1141
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1174
+	if (isset($context['search_params']['search'])) {
1175
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1176
+	}
1177
+	if (isset($context['search_params']['userspec'])) {
1178
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1179
+	}
1142 1180
 
1143
-	if (!empty($context['search_params']['searchtype']))
1144
-		$context['search_params']['searchtype'] = 2;
1181
+	if (!empty($context['search_params']['searchtype'])) {
1182
+			$context['search_params']['searchtype'] = 2;
1183
+	}
1145 1184
 
1146
-	if (!empty($context['search_params']['minage']))
1147
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1185
+	if (!empty($context['search_params']['minage'])) {
1186
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1187
+	}
1148 1188
 
1149
-	if (!empty($context['search_params']['maxage']))
1150
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1189
+	if (!empty($context['search_params']['maxage'])) {
1190
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1191
+	}
1151 1192
 
1152 1193
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1153 1194
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1174,8 +1215,9 @@  discard block
 block discarded – undo
1174 1215
 		$context['search_errors']['messages'] = array();
1175 1216
 		foreach ($context['search_errors'] as $search_error => $dummy)
1176 1217
 		{
1177
-			if ($search_error == 'messages')
1178
-				continue;
1218
+			if ($search_error == 'messages') {
1219
+							continue;
1220
+			}
1179 1221
 
1180 1222
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1181 1223
 		}
@@ -1197,8 +1239,9 @@  discard block
 block discarded – undo
1197 1239
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1198 1240
 	global $memberContext, $smcFunc;
1199 1241
 
1200
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1201
-		fatal_lang_error('loadavg_search_disabled', false);
1242
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1243
+			fatal_lang_error('loadavg_search_disabled', false);
1244
+	}
1202 1245
 
1203 1246
 	/**
1204 1247
 	 * @todo For the moment force the folder to the inbox.
@@ -1227,35 +1270,40 @@  discard block
 block discarded – undo
1227 1270
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1228 1271
 
1229 1272
 	// Store whether simple search was used (needed if the user wants to do another query).
1230
-	if (!isset($search_params['advanced']))
1231
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1273
+	if (!isset($search_params['advanced'])) {
1274
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1275
+	}
1232 1276
 
1233 1277
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1234
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1235
-		$search_params['searchtype'] = 2;
1278
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1279
+			$search_params['searchtype'] = 2;
1280
+	}
1236 1281
 
1237 1282
 	// Minimum age of messages. Default to zero (don't set param in that case).
1238
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1239
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1283
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1284
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1285
+	}
1240 1286
 
1241 1287
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1242
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1243
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1288
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1289
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1290
+	}
1244 1291
 
1245 1292
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1246 1293
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1247 1294
 
1248 1295
 	// Default the user name to a wildcard matching every user (*).
1249
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1250
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1296
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1297
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1298
+	}
1251 1299
 
1252 1300
 	// This will be full of all kinds of parameters!
1253 1301
 	$searchq_parameters = array();
1254 1302
 
1255 1303
 	// If there's no specific user, then don't mention it in the main query.
1256
-	if (empty($search_params['userspec']))
1257
-		$userQuery = '';
1258
-	else
1304
+	if (empty($search_params['userspec'])) {
1305
+			$userQuery = '';
1306
+	} else
1259 1307
 	{
1260 1308
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1261 1309
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1267,8 +1315,9 @@  discard block
 block discarded – undo
1267 1315
 		{
1268 1316
 			$possible_users[$k] = trim($possible_users[$k]);
1269 1317
 
1270
-			if (strlen($possible_users[$k]) == 0)
1271
-				unset($possible_users[$k]);
1318
+			if (strlen($possible_users[$k]) == 0) {
1319
+							unset($possible_users[$k]);
1320
+			}
1272 1321
 		}
1273 1322
 
1274 1323
 		if (!empty($possible_users))
@@ -1280,8 +1329,9 @@  discard block
 block discarded – undo
1280 1329
 			{
1281 1330
 				$where_params['name_' . $k] = $v;
1282 1331
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1283
-				if (!isset($where_params['real_name']))
1284
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1332
+				if (!isset($where_params['real_name'])) {
1333
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1334
+				}
1285 1335
 			}
1286 1336
 
1287 1337
 			// Who matches those criteria?
@@ -1294,28 +1344,28 @@  discard block
 block discarded – undo
1294 1344
 			);
1295 1345
 
1296 1346
 			// Simply do nothing if there're too many members matching the criteria.
1297
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1298
-				$userQuery = '';
1299
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1347
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1348
+							$userQuery = '';
1349
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1300 1350
 			{
1301 1351
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1302 1352
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1303 1353
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1304
-			}
1305
-			else
1354
+			} else
1306 1355
 			{
1307 1356
 				$memberlist = array();
1308
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-					$memberlist[] = $row['id_member'];
1357
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1358
+									$memberlist[] = $row['id_member'];
1359
+				}
1310 1360
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1311 1361
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1312 1362
 				$searchq_parameters['member_list'] = $memberlist;
1313 1363
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1314 1364
 			}
1315 1365
 			$smcFunc['db_free_result']($request);
1366
+		} else {
1367
+					$userQuery = '';
1316 1368
 		}
1317
-		else
1318
-			$userQuery = '';
1319 1369
 	}
1320 1370
 
1321 1371
 	// Setup the sorting variables...
@@ -1323,8 +1373,9 @@  discard block
 block discarded – undo
1323 1373
 	$sort_columns = array(
1324 1374
 		'pm.id_pm',
1325 1375
 	);
1326
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1327
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1376
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1377
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1378
+	}
1328 1379
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1329 1380
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1330 1381
 
@@ -1334,24 +1385,27 @@  discard block
 block discarded – undo
1334 1385
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1335 1386
 	{
1336 1387
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1337
-		if (isset($search_params['labels']))
1338
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1388
+		if (isset($search_params['labels'])) {
1389
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1390
+		}
1339 1391
 
1340 1392
 		// Assuming we have some labels - make them all integers.
1341 1393
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1342 1394
 		{
1343
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1344
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1395
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1396
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1397
+			}
1398
+		} else {
1399
+					$_REQUEST['searchlabel'] = array();
1345 1400
 		}
1346
-		else
1347
-			$_REQUEST['searchlabel'] = array();
1348 1401
 
1349 1402
 		// Now that everything is cleaned up a bit, make the labels a param.
1350 1403
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1351 1404
 
1352 1405
 		// No labels selected? That must be an error!
1353
-		if (empty($_REQUEST['searchlabel']))
1354
-			$context['search_errors']['no_labels_selected'] = true;
1406
+		if (empty($_REQUEST['searchlabel'])) {
1407
+					$context['search_errors']['no_labels_selected'] = true;
1408
+		}
1355 1409
 		// Otherwise prepare the query!
1356 1410
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1357 1411
 		{
@@ -1374,8 +1428,7 @@  discard block
 block discarded – undo
1374 1428
 					// Not searching the inbox - PM must be labeled
1375 1429
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1376 1430
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1377
-				}
1378
-				else
1431
+				} else
1379 1432
 				{
1380 1433
 					// Searching the inbox - PM doesn't have to be labeled
1381 1434
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1390,8 +1443,9 @@  discard block
 block discarded – undo
1390 1443
 	// What are we actually searching for?
1391 1444
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1392 1445
 	// If we ain't got nothing - we should error!
1393
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1394
-		$context['search_errors']['invalid_search_string'] = true;
1446
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1447
+			$context['search_errors']['invalid_search_string'] = true;
1448
+	}
1395 1449
 
1396 1450
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1397 1451
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1404,12 +1458,14 @@  discard block
 block discarded – undo
1404 1458
 	$excludedWords = array();
1405 1459
 
1406 1460
 	// .. first, we check for things like -"some words", but not "-some words".
1407
-	foreach ($matches[1] as $index => $word)
1408
-		if ($word == '-')
1461
+	foreach ($matches[1] as $index => $word) {
1462
+			if ($word == '-')
1409 1463
 		{
1410 1464
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1411
-			if (strlen($word) > 0)
1412
-				$excludedWords[] = $word;
1465
+	}
1466
+			if (strlen($word) > 0) {
1467
+							$excludedWords[] = $word;
1468
+			}
1413 1469
 			unset($searchArray[$index]);
1414 1470
 		}
1415 1471
 
@@ -1419,8 +1475,9 @@  discard block
 block discarded – undo
1419 1475
 		if (strpos(trim($word), '-') === 0)
1420 1476
 		{
1421 1477
 			$word = substr($smcFunc['strtolower']($word), 1);
1422
-			if (strlen($word) > 0)
1423
-				$excludedWords[] = $word;
1478
+			if (strlen($word) > 0) {
1479
+							$excludedWords[] = $word;
1480
+			}
1424 1481
 			unset($tempSearch[$index]);
1425 1482
 		}
1426 1483
 	}
@@ -1431,9 +1488,9 @@  discard block
 block discarded – undo
1431 1488
 	foreach ($searchArray as $index => $value)
1432 1489
 	{
1433 1490
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1434
-		if ($searchArray[$index] == '')
1435
-			unset($searchArray[$index]);
1436
-		else
1491
+		if ($searchArray[$index] == '') {
1492
+					unset($searchArray[$index]);
1493
+		} else
1437 1494
 		{
1438 1495
 			// Sort out entities first.
1439 1496
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1443,27 +1500,32 @@  discard block
 block discarded – undo
1443 1500
 
1444 1501
 	// Create an array of replacements for highlighting.
1445 1502
 	$context['mark'] = array();
1446
-	foreach ($searchArray as $word)
1447
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1503
+	foreach ($searchArray as $word) {
1504
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1505
+	}
1448 1506
 
1449 1507
 	// This contains *everything*
1450 1508
 	$searchWords = array_merge($searchArray, $excludedWords);
1451 1509
 
1452 1510
 	// Make sure at least one word is being searched for.
1453
-	if (empty($searchArray))
1454
-		$context['search_errors']['invalid_search_string'] = true;
1511
+	if (empty($searchArray)) {
1512
+			$context['search_errors']['invalid_search_string'] = true;
1513
+	}
1455 1514
 
1456 1515
 	// Sort out the search query so the user can edit it - if they want.
1457 1516
 	$context['search_params'] = $search_params;
1458
-	if (isset($context['search_params']['search']))
1459
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1460
-	if (isset($context['search_params']['userspec']))
1461
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1517
+	if (isset($context['search_params']['search'])) {
1518
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1519
+	}
1520
+	if (isset($context['search_params']['userspec'])) {
1521
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1522
+	}
1462 1523
 
1463 1524
 	// Now we have all the parameters, combine them together for pagination and the like...
1464 1525
 	$context['params'] = array();
1465
-	foreach ($search_params as $k => $v)
1466
-		$context['params'][] = $k . '|\'|' . $v;
1526
+	foreach ($search_params as $k => $v) {
1527
+			$context['params'][] = $k . '|\'|' . $v;
1528
+	}
1467 1529
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1468 1530
 
1469 1531
 	// Compile the subject query part.
@@ -1471,26 +1533,31 @@  discard block
 block discarded – undo
1471 1533
 
1472 1534
 	foreach ($searchWords as $index => $word)
1473 1535
 	{
1474
-		if ($word == '')
1475
-			continue;
1536
+		if ($word == '') {
1537
+					continue;
1538
+		}
1476 1539
 
1477
-		if ($search_params['subject_only'])
1478
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1479
-		else
1480
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1540
+		if ($search_params['subject_only']) {
1541
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1542
+		} else {
1543
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1544
+		}
1481 1545
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1482 1546
 	}
1483 1547
 
1484 1548
 	$searchQuery = ' 1=1';
1485
-	if (!empty($andQueryParts))
1486
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1549
+	if (!empty($andQueryParts)) {
1550
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1551
+	}
1487 1552
 
1488 1553
 	// Age limits?
1489 1554
 	$timeQuery = '';
1490
-	if (!empty($search_params['minage']))
1491
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1492
-	if (!empty($search_params['maxage']))
1493
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1555
+	if (!empty($search_params['minage'])) {
1556
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1557
+	}
1558
+	if (!empty($search_params['maxage'])) {
1559
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1560
+	}
1494 1561
 
1495 1562
 	// If we have errors - return back to the first screen...
1496 1563
 	if (!empty($context['search_errors']))
@@ -1576,8 +1643,9 @@  discard block
 block discarded – undo
1576 1643
 			)
1577 1644
 		);
1578 1645
 		$real_pm_ids = array();
1579
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1580
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1646
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1647
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1648
+		}
1581 1649
 		$smcFunc['db_free_result']($request);
1582 1650
 	}
1583 1651
 
@@ -1607,8 +1675,9 @@  discard block
 block discarded – undo
1607 1675
 		);
1608 1676
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1609 1677
 		{
1610
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1611
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1678
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1679
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1680
+			}
1612 1681
 
1613 1682
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1614 1683
 			{
@@ -1629,12 +1698,14 @@  discard block
 block discarded – undo
1629 1698
 				while($row2 = $smcFunc['db_fetch_assoc']($request2))
1630 1699
 				{
1631 1700
 					$l_id = $row2['id_label'];
1632
-					if (isset($context['labels'][$l_id]))
1633
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1701
+					if (isset($context['labels'][$l_id])) {
1702
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1703
+					}
1634 1704
 
1635 1705
 					// Here we find the first label on a message - for linking to posts in results
1636
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1637
-						$context['first_label'][$row['id_pm']] = $l_id;
1706
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1707
+											$context['first_label'][$row['id_pm']] = $l_id;
1708
+					}
1638 1709
 				}
1639 1710
 
1640 1711
 				$smcFunc['db_free_result']($request2);
@@ -1761,8 +1832,9 @@  discard block
 block discarded – undo
1761 1832
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1762 1833
 		$smcFunc['db_free_result']($request);
1763 1834
 
1764
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1765
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1835
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1836
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1837
+		}
1766 1838
 	}
1767 1839
 
1768 1840
 	// Quoting/Replying to a message?
@@ -1771,8 +1843,9 @@  discard block
 block discarded – undo
1771 1843
 		$pmsg = (int) $_REQUEST['pmsg'];
1772 1844
 
1773 1845
 		// Make sure this is yours.
1774
-		if (!isAccessiblePM($pmsg))
1775
-			fatal_lang_error('no_access', false);
1846
+		if (!isAccessiblePM($pmsg)) {
1847
+					fatal_lang_error('no_access', false);
1848
+		}
1776 1849
 
1777 1850
 		// Work out whether this is one you've received?
1778 1851
 		$request = $smcFunc['db_query']('', '
@@ -1809,8 +1882,9 @@  discard block
 block discarded – undo
1809 1882
 				'id_pm' => $pmsg,
1810 1883
 			)
1811 1884
 		);
1812
-		if ($smcFunc['db_num_rows']($request) == 0)
1813
-			fatal_lang_error('pm_not_yours', false);
1885
+		if ($smcFunc['db_num_rows']($request) == 0) {
1886
+					fatal_lang_error('pm_not_yours', false);
1887
+		}
1814 1888
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1815 1889
 		$smcFunc['db_free_result']($request);
1816 1890
 
@@ -1821,9 +1895,9 @@  discard block
 block discarded – undo
1821 1895
 		// Add 'Re: ' to it....
1822 1896
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1823 1897
 		{
1824
-			if ($language === $user_info['language'])
1825
-				$context['response_prefix'] = $txt['response_prefix'];
1826
-			else
1898
+			if ($language === $user_info['language']) {
1899
+							$context['response_prefix'] = $txt['response_prefix'];
1900
+			} else
1827 1901
 			{
1828 1902
 				loadLanguage('index', $language, false);
1829 1903
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1832,22 +1906,25 @@  discard block
 block discarded – undo
1832 1906
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1833 1907
 		}
1834 1908
 		$form_subject = $row_quoted['subject'];
1835
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1836
-			$form_subject = $context['response_prefix'] . $form_subject;
1909
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1910
+					$form_subject = $context['response_prefix'] . $form_subject;
1911
+		}
1837 1912
 
1838 1913
 		if (isset($_REQUEST['quote']))
1839 1914
 		{
1840 1915
 			// Remove any nested quotes and <br>...
1841 1916
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1842
-			if (!empty($modSettings['removeNestedQuotes']))
1843
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1844
-			if (empty($row_quoted['id_member']))
1845
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1846
-			else
1847
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1917
+			if (!empty($modSettings['removeNestedQuotes'])) {
1918
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1919
+			}
1920
+			if (empty($row_quoted['id_member'])) {
1921
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1922
+			} else {
1923
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1924
+			}
1925
+		} else {
1926
+					$form_message = '';
1848 1927
 		}
1849
-		else
1850
-			$form_message = '';
1851 1928
 
1852 1929
 		// Do the BBC thang on the message.
1853 1930
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1868,8 +1945,7 @@  discard block
 block discarded – undo
1868 1945
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1869 1946
 			'body' => $row_quoted['body']
1870 1947
 		);
1871
-	}
1872
-	else
1948
+	} else
1873 1949
 	{
1874 1950
 		$context['quoted_message'] = false;
1875 1951
 		$form_subject = '';
@@ -1888,11 +1964,12 @@  discard block
 block discarded – undo
1888 1964
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1889 1965
 		{
1890 1966
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1891
-			if ($row_quoted['id_member'] != $user_info['id'])
1892
-				$context['recipients']['to'][] = array(
1967
+			if ($row_quoted['id_member'] != $user_info['id']) {
1968
+							$context['recipients']['to'][] = array(
1893 1969
 					'id' => $row_quoted['id_member'],
1894 1970
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1895 1971
 				);
1972
+			}
1896 1973
 
1897 1974
 			// Now to get the others.
1898 1975
 			$request = $smcFunc['db_query']('', '
@@ -1908,18 +1985,19 @@  discard block
 block discarded – undo
1908 1985
 					'not_bcc' => 0,
1909 1986
 				)
1910 1987
 			);
1911
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1912
-				$context['recipients']['to'][] = array(
1988
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1989
+							$context['recipients']['to'][] = array(
1913 1990
 					'id' => $row['id_member'],
1914 1991
 					'name' => $row['real_name'],
1915 1992
 				);
1993
+			}
1916 1994
 			$smcFunc['db_free_result']($request);
1917
-		}
1918
-		else
1995
+		} else
1919 1996
 		{
1920 1997
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1921
-			foreach ($_REQUEST['u'] as $key => $uID)
1922
-				$_REQUEST['u'][$key] = (int) $uID;
1998
+			foreach ($_REQUEST['u'] as $key => $uID) {
1999
+							$_REQUEST['u'][$key] = (int) $uID;
2000
+			}
1923 2001
 
1924 2002
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1925 2003
 
@@ -1933,22 +2011,24 @@  discard block
 block discarded – undo
1933 2011
 					'limit' => count($_REQUEST['u']),
1934 2012
 				)
1935 2013
 			);
1936
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1937
-				$context['recipients']['to'][] = array(
2014
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2015
+							$context['recipients']['to'][] = array(
1938 2016
 					'id' => $row['id_member'],
1939 2017
 					'name' => $row['real_name'],
1940 2018
 				);
2019
+			}
1941 2020
 			$smcFunc['db_free_result']($request);
1942 2021
 		}
1943 2022
 
1944 2023
 		// Get a literal name list in case the user has JavaScript disabled.
1945 2024
 		$names = array();
1946
-		foreach ($context['recipients']['to'] as $to)
1947
-			$names[] = $to['name'];
2025
+		foreach ($context['recipients']['to'] as $to) {
2026
+					$names[] = $to['name'];
2027
+		}
1948 2028
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2029
+	} else {
2030
+			$context['to_value'] = '';
1949 2031
 	}
1950
-	else
1951
-		$context['to_value'] = '';
1952 2032
 
1953 2033
 	// Set the defaults...
1954 2034
 	$context['subject'] = $form_subject;
@@ -2018,8 +2098,9 @@  discard block
 block discarded – undo
2018 2098
 
2019 2099
 	// validate with loadMemberData()
2020 2100
 	$memberResult = loadMemberData($user_info['id'], false);
2021
-	if (!$memberResult)
2022
-		fatal_lang_error('not_a_user', false);
2101
+	if (!$memberResult) {
2102
+			fatal_lang_error('not_a_user', false);
2103
+	}
2023 2104
 	list ($memID) = $memberResult;
2024 2105
 
2025 2106
 	// drafts is where the functions reside
@@ -2045,9 +2126,9 @@  discard block
 block discarded – undo
2045 2126
 		$context['sub_template'] = 'send';
2046 2127
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms');
2047 2128
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
2129
+	} else {
2130
+			$context['sub_template'] = 'pm';
2048 2131
 	}
2049
-	else
2050
-		$context['sub_template'] = 'pm';
2051 2132
 
2052 2133
 	$context['page_title'] = $txt['send_message'];
2053 2134
 
@@ -2108,10 +2189,11 @@  discard block
 block discarded – undo
2108 2189
 		);
2109 2190
 		if ($smcFunc['db_num_rows']($request) == 0)
2110 2191
 		{
2111
-			if (!isset($_REQUEST['xml']))
2112
-				fatal_lang_error('pm_not_yours', false);
2113
-			else
2114
-				$error_types[] = 'pm_not_yours';
2192
+			if (!isset($_REQUEST['xml'])) {
2193
+							fatal_lang_error('pm_not_yours', false);
2194
+			} else {
2195
+							$error_types[] = 'pm_not_yours';
2196
+			}
2115 2197
 		}
2116 2198
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2117 2199
 		$smcFunc['db_free_result']($request);
@@ -2158,14 +2240,16 @@  discard block
 block discarded – undo
2158 2240
 		$context['post_error'][$error_type] = true;
2159 2241
 		if (isset($txt['error_' . $error_type]))
2160 2242
 		{
2161
-			if ($error_type == 'long_message')
2162
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2243
+			if ($error_type == 'long_message') {
2244
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2245
+			}
2163 2246
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2164 2247
 		}
2165 2248
 
2166 2249
 		// If it's not a minor error flag it as such.
2167
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2168
-			$context['error_type'] = 'serious';
2250
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2251
+					$context['error_type'] = 'serious';
2252
+		}
2169 2253
 	}
2170 2254
 
2171 2255
 	// We need to load the editor once more.
@@ -2223,8 +2307,9 @@  discard block
 block discarded – undo
2223 2307
 	require_once($sourcedir . '/Subs-Auth.php');
2224 2308
 
2225 2309
 	// PM Drafts enabled and needed?
2226
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2227
-		require_once($sourcedir . '/Drafts.php');
2310
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2311
+			require_once($sourcedir . '/Drafts.php');
2312
+	}
2228 2313
 
2229 2314
 	loadLanguage('PersonalMessage', '', false);
2230 2315
 
@@ -2254,24 +2339,27 @@  discard block
 block discarded – undo
2254 2339
 
2255 2340
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2256 2341
 		{
2257
-			if (!isset($_REQUEST['xml']))
2258
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2259
-			else
2260
-				$post_errors[] = 'pm_too_many_per_hour';
2342
+			if (!isset($_REQUEST['xml'])) {
2343
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2344
+			} else {
2345
+							$post_errors[] = 'pm_too_many_per_hour';
2346
+			}
2261 2347
 		}
2262 2348
 	}
2263 2349
 
2264 2350
 	// If your session timed out, show an error, but do allow to re-submit.
2265
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2266
-		$post_errors[] = 'session_timeout';
2351
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2352
+			$post_errors[] = 'session_timeout';
2353
+	}
2267 2354
 
2268 2355
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2269 2356
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2270 2357
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2271 2358
 
2272 2359
 	// Route the input from the 'u' parameter to the 'to'-list.
2273
-	if (!empty($_POST['u']))
2274
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2360
+	if (!empty($_POST['u'])) {
2361
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2362
+	}
2275 2363
 
2276 2364
 	// Construct the list of recipients.
2277 2365
 	$recipientList = array();
@@ -2283,8 +2371,9 @@  discard block
 block discarded – undo
2283 2371
 		$recipientList[$recipientType] = array();
2284 2372
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2285 2373
 		{
2286
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2287
-				$recipientList[$recipientType][] = (int) $recipient;
2374
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2375
+							$recipientList[$recipientType][] = (int) $recipient;
2376
+			}
2288 2377
 		}
2289 2378
 
2290 2379
 		// Are there also literal names set?
@@ -2298,10 +2387,11 @@  discard block
 block discarded – undo
2298 2387
 
2299 2388
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2300 2389
 			{
2301
-				if (strlen(trim($recipient)) > 0)
2302
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2303
-				else
2304
-					unset($namedRecipientList[$recipientType][$index]);
2390
+				if (strlen(trim($recipient)) > 0) {
2391
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2392
+				} else {
2393
+									unset($namedRecipientList[$recipientType][$index]);
2394
+				}
2305 2395
 			}
2306 2396
 
2307 2397
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2331,8 +2421,9 @@  discard block
 block discarded – undo
2331 2421
 		}
2332 2422
 
2333 2423
 		// Selected a recipient to be deleted? Remove them now.
2334
-		if (!empty($_POST['delete_recipient']))
2335
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2424
+		if (!empty($_POST['delete_recipient'])) {
2425
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2426
+		}
2336 2427
 
2337 2428
 		// Make sure we don't include the same name twice
2338 2429
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2342,8 +2433,9 @@  discard block
 block discarded – undo
2342 2433
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2343 2434
 
2344 2435
 	// Check if there's at least one recipient.
2345
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2346
-		$post_errors[] = 'no_to';
2436
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2437
+			$post_errors[] = 'no_to';
2438
+	}
2347 2439
 
2348 2440
 	// Make sure that we remove the members who did get it from the screen.
2349 2441
 	if (!$is_recipient_change)
@@ -2357,28 +2449,31 @@  discard block
 block discarded – undo
2357 2449
 				// Since we already have a post error, remove the previous one.
2358 2450
 				$post_errors = array_diff($post_errors, array('no_to'));
2359 2451
 
2360
-				foreach ($namesNotFound[$recipientType] as $name)
2361
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2452
+				foreach ($namesNotFound[$recipientType] as $name) {
2453
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2454
+				}
2362 2455
 			}
2363 2456
 		}
2364 2457
 	}
2365 2458
 
2366 2459
 	// Did they make any mistakes?
2367
-	if ($_REQUEST['subject'] == '')
2368
-		$post_errors[] = 'no_subject';
2369
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2370
-		$post_errors[] = 'no_message';
2371
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2372
-		$post_errors[] = 'long_message';
2373
-	else
2460
+	if ($_REQUEST['subject'] == '') {
2461
+			$post_errors[] = 'no_subject';
2462
+	}
2463
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2464
+			$post_errors[] = 'no_message';
2465
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2466
+			$post_errors[] = 'long_message';
2467
+	} else
2374 2468
 	{
2375 2469
 		// Preparse the message.
2376 2470
 		$message = $_REQUEST['message'];
2377 2471
 		preparsecode($message);
2378 2472
 
2379 2473
 		// Make sure there's still some content left without the tags.
2380
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2381
-			$post_errors[] = 'no_message';
2474
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2475
+					$post_errors[] = 'no_message';
2476
+		}
2382 2477
 	}
2383 2478
 
2384 2479
 	// Wrong verification code?
@@ -2390,13 +2485,15 @@  discard block
 block discarded – undo
2390 2485
 		);
2391 2486
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2392 2487
 
2393
-		if (is_array($context['require_verification']))
2394
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2488
+		if (is_array($context['require_verification'])) {
2489
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2490
+		}
2395 2491
 	}
2396 2492
 
2397 2493
 	// If they did, give a chance to make ammends.
2398
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2399
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2494
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2495
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2496
+	}
2400 2497
 
2401 2498
 	// Want to take a second glance before you send?
2402 2499
 	if (isset($_REQUEST['preview']))
@@ -2427,8 +2524,9 @@  discard block
 block discarded – undo
2427 2524
 		foreach ($namesNotFound as $recipientType => $names)
2428 2525
 		{
2429 2526
 			$post_errors[] = 'bad_' . $recipientType;
2430
-			foreach ($names as $name)
2431
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2527
+			foreach ($names as $name) {
2528
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2529
+			}
2432 2530
 		}
2433 2531
 
2434 2532
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2458,13 +2556,14 @@  discard block
 block discarded – undo
2458 2556
 	checkSubmitOnce('check');
2459 2557
 
2460 2558
 	// Do the actual sending of the PM.
2461
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2462
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2463
-	else
2464
-		$context['send_log'] = array(
2559
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2560
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2561
+	} else {
2562
+			$context['send_log'] = array(
2465 2563
 			'sent' => array(),
2466 2564
 			'failed' => array()
2467 2565
 		);
2566
+	}
2468 2567
 
2469 2568
 	// Mark the message as "replied to".
2470 2569
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2482,11 +2581,12 @@  discard block
 block discarded – undo
2482 2581
 	}
2483 2582
 
2484 2583
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2485
-	if (!empty($context['send_log']['failed']))
2486
-		return messagePostError($post_errors, $namesNotFound, array(
2584
+	if (!empty($context['send_log']['failed'])) {
2585
+			return messagePostError($post_errors, $namesNotFound, array(
2487 2586
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2488 2587
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2489 2588
 		));
2589
+	}
2490 2590
 
2491 2591
 	// Message sent successfully?
2492 2592
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2494,8 +2594,9 @@  discard block
 block discarded – undo
2494 2594
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2495 2595
 
2496 2596
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2497
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2498
-			DeleteDraft($_POST['id_pm_draft']);
2597
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2598
+					DeleteDraft($_POST['id_pm_draft']);
2599
+		}
2499 2600
 	}
2500 2601
 
2501 2602
 	// Go back to the where they sent from, if possible...
@@ -2510,24 +2611,28 @@  discard block
 block discarded – undo
2510 2611
 
2511 2612
 	checkSession('request');
2512 2613
 
2513
-	if (isset($_REQUEST['del_selected']))
2514
-		$_REQUEST['pm_action'] = 'delete';
2614
+	if (isset($_REQUEST['del_selected'])) {
2615
+			$_REQUEST['pm_action'] = 'delete';
2616
+	}
2515 2617
 
2516 2618
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2517 2619
 	{
2518
-		foreach ($_REQUEST['pms'] as $pm)
2519
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2620
+		foreach ($_REQUEST['pms'] as $pm) {
2621
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2622
+		}
2520 2623
 	}
2521 2624
 
2522
-	if (empty($_REQUEST['pm_actions']))
2523
-		redirectexit($context['current_label_redirect']);
2625
+	if (empty($_REQUEST['pm_actions'])) {
2626
+			redirectexit($context['current_label_redirect']);
2627
+	}
2524 2628
 
2525 2629
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2526 2630
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2527 2631
 	{
2528 2632
 		$id_pms = array();
2529
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2530
-			$id_pms[] = (int) $pm;
2633
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2634
+					$id_pms[] = (int) $pm;
2635
+		}
2531 2636
 
2532 2637
 		$request = $smcFunc['db_query']('', '
2533 2638
 			SELECT id_pm_head, id_pm
@@ -2538,8 +2643,9 @@  discard block
 block discarded – undo
2538 2643
 			)
2539 2644
 		);
2540 2645
 		$pm_heads = array();
2541
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2542
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2646
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2647
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2648
+		}
2543 2649
 		$smcFunc['db_free_result']($request);
2544 2650
 
2545 2651
 		$request = $smcFunc['db_query']('', '
@@ -2553,8 +2659,9 @@  discard block
 block discarded – undo
2553 2659
 		// Copy the action from the single to PM to the others.
2554 2660
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2555 2661
 		{
2556
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2557
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2662
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2663
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2664
+			}
2558 2665
 		}
2559 2666
 		$smcFunc['db_free_result']($request);
2560 2667
 	}
@@ -2566,22 +2673,21 @@  discard block
 block discarded – undo
2566 2673
 	$labels = array();
2567 2674
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2568 2675
 	{
2569
-		if ($action === 'delete')
2570
-			$to_delete[] = (int) $pm;
2571
-		else
2676
+		if ($action === 'delete') {
2677
+					$to_delete[] = (int) $pm;
2678
+		} else
2572 2679
 		{
2573 2680
 			if (substr($action, 0, 4) == 'add_')
2574 2681
 			{
2575 2682
 				$type = 'add';
2576 2683
 				$action = substr($action, 4);
2577
-			}
2578
-			elseif (substr($action, 0, 4) == 'rem_')
2684
+			} elseif (substr($action, 0, 4) == 'rem_')
2579 2685
 			{
2580 2686
 				$type = 'rem';
2581 2687
 				$action = substr($action, 4);
2688
+			} else {
2689
+							$type = 'unk';
2582 2690
 			}
2583
-			else
2584
-				$type = 'unk';
2585 2691
 
2586 2692
 			if ($action == '-1' || (int) $action > 0)
2587 2693
 			{
@@ -2592,8 +2698,9 @@  discard block
 block discarded – undo
2592 2698
 	}
2593 2699
 
2594 2700
 	// Deleting, it looks like?
2595
-	if (!empty($to_delete))
2596
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2701
+	if (!empty($to_delete)) {
2702
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2703
+	}
2597 2704
 
2598 2705
 	// Are we labeling anything?
2599 2706
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2661,8 +2768,7 @@  discard block
 block discarded – undo
2661 2768
 				}
2662 2769
 
2663 2770
 				$smcFunc['db_free_result']($request2);
2664
-			}
2665
-			elseif ($type == 'rem')
2771
+			} elseif ($type == 'rem')
2666 2772
 			{
2667 2773
 				// If we're removing from the inbox, see if we have at least one other label.
2668 2774
 				// This query is faster than the one above
@@ -2694,21 +2800,25 @@  discard block
 block discarded – undo
2694 2800
 			if ($to_label[$row['id_pm']] != '-1')
2695 2801
 			{
2696 2802
 				// If this label is in the list and we're not adding it, remove it
2697
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2698
-					unset($labels[$to_label[$row['id_pm']]]);
2699
-				else if ($type !== 'rem')
2700
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2803
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2804
+									unset($labels[$to_label[$row['id_pm']]]);
2805
+				} else if ($type !== 'rem') {
2806
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2807
+				}
2701 2808
 			}
2702 2809
 
2703 2810
 			// Removing all labels or just removing the inbox label
2704
-			if ($type == 'rem' && empty($labels))
2705
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2811
+			if ($type == 'rem' && empty($labels)) {
2812
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2813
+			}
2706 2814
 			// Adding new labels, but removing inbox and applying new ones
2707
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2708
-				$in_inbox = 0;
2815
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2816
+							$in_inbox = 0;
2817
+			}
2709 2818
 			// Just adding it to the inbox
2710
-			else
2711
-				$in_inbox = 1;
2819
+			else {
2820
+							$in_inbox = 1;
2821
+			}
2712 2822
 
2713 2823
 			// Are we adding it to or removing it from the inbox?
2714 2824
 			if ($in_inbox != $row['in_inbox'])
@@ -2750,8 +2860,9 @@  discard block
 block discarded – undo
2750 2860
 			if (!empty($labels_to_apply))
2751 2861
 			{
2752 2862
 				$inserts = array();
2753
-				foreach ($labels_to_apply as $label)
2754
-					$inserts[] = array($row['id_pm'], $label);
2863
+				foreach ($labels_to_apply as $label) {
2864
+									$inserts[] = array($row['id_pm'], $label);
2865
+				}
2755 2866
 
2756 2867
 				$smcFunc['db_insert']('',
2757 2868
 					'{db_prefix}pm_labeled_messages',
@@ -2795,11 +2906,13 @@  discard block
 block discarded – undo
2795 2906
 	checkSession('get');
2796 2907
 
2797 2908
 	// If all then delete all messages the user has.
2798
-	if ($_REQUEST['f'] == 'all')
2799
-		deleteMessages(null, null);
2909
+	if ($_REQUEST['f'] == 'all') {
2910
+			deleteMessages(null, null);
2911
+	}
2800 2912
 	// Otherwise just the selected folder.
2801
-	else
2802
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2913
+	else {
2914
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2915
+	}
2803 2916
 
2804 2917
 	// Done... all gone.
2805 2918
 	redirectexit($context['current_label_redirect']);
@@ -2836,8 +2949,9 @@  discard block
 block discarded – undo
2836 2949
 				'msgtime' => $deleteTime,
2837 2950
 			)
2838 2951
 		);
2839
-		while ($row = $smcFunc['db_fetch_row']($request))
2840
-			$toDelete[] = $row[0];
2952
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2953
+					$toDelete[] = $row[0];
2954
+		}
2841 2955
 		$smcFunc['db_free_result']($request);
2842 2956
 
2843 2957
 		// Select all messages in their inbox older than $deleteTime.
@@ -2854,8 +2968,9 @@  discard block
 block discarded – undo
2854 2968
 				'msgtime' => $deleteTime,
2855 2969
 			)
2856 2970
 		);
2857
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2858
-			$toDelete[] = $row['id_pm'];
2971
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2972
+					$toDelete[] = $row['id_pm'];
2973
+		}
2859 2974
 		$smcFunc['db_free_result']($request);
2860 2975
 
2861 2976
 		// Delete the actual messages.
@@ -2886,26 +3001,29 @@  discard block
 block discarded – undo
2886 3001
 {
2887 3002
 	global $user_info, $smcFunc;
2888 3003
 
2889
-	if ($owner === null)
2890
-		$owner = array($user_info['id']);
2891
-	elseif (empty($owner))
2892
-		return;
2893
-	elseif (!is_array($owner))
2894
-		$owner = array($owner);
3004
+	if ($owner === null) {
3005
+			$owner = array($user_info['id']);
3006
+	} elseif (empty($owner)) {
3007
+			return;
3008
+	} elseif (!is_array($owner)) {
3009
+			$owner = array($owner);
3010
+	}
2895 3011
 
2896 3012
 	if ($personal_messages !== null)
2897 3013
 	{
2898
-		if (empty($personal_messages) || !is_array($personal_messages))
2899
-			return;
3014
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3015
+					return;
3016
+		}
2900 3017
 
2901
-		foreach ($personal_messages as $index => $delete_id)
2902
-			$personal_messages[$index] = (int) $delete_id;
3018
+		foreach ($personal_messages as $index => $delete_id) {
3019
+					$personal_messages[$index] = (int) $delete_id;
3020
+		}
2903 3021
 
2904 3022
 		$where = '
2905 3023
 				AND id_pm IN ({array_int:pm_list})';
3024
+	} else {
3025
+			$where = '';
2906 3026
 	}
2907
-	else
2908
-		$where = '';
2909 3027
 
2910 3028
 	if ($folder == 'sent' || $folder === null)
2911 3029
 	{
@@ -2940,17 +3058,19 @@  discard block
 block discarded – undo
2940 3058
 		// ...And update the statistics accordingly - now including unread messages!.
2941 3059
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2942 3060
 		{
2943
-			if ($row['is_read'])
2944
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2945
-			else
2946
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3061
+			if ($row['is_read']) {
3062
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3063
+			} else {
3064
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3065
+			}
2947 3066
 
2948 3067
 			// If this is the current member we need to make their message count correct.
2949 3068
 			if ($user_info['id'] == $row['id_member'])
2950 3069
 			{
2951 3070
 				$user_info['messages'] -= $row['num_deleted_messages'];
2952
-				if (!($row['is_read']))
2953
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3071
+				if (!($row['is_read'])) {
3072
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3073
+				}
2954 3074
 			}
2955 3075
 		}
2956 3076
 		$smcFunc['db_free_result']($request);
@@ -3018,8 +3138,9 @@  discard block
 block discarded – undo
3018 3138
 		)
3019 3139
 	);
3020 3140
 	$remove_pms = array();
3021
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3022
-		$remove_pms[] = $row['sender'];
3141
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3142
+			$remove_pms[] = $row['sender'];
3143
+	}
3023 3144
 	$smcFunc['db_free_result']($request);
3024 3145
 
3025 3146
 	if (!empty($remove_pms))
@@ -3064,8 +3185,9 @@  discard block
 block discarded – undo
3064 3185
 {
3065 3186
 	global $user_info, $context, $smcFunc;
3066 3187
 
3067
-	if ($owner === null)
3068
-		$owner = $user_info['id'];
3188
+	if ($owner === null) {
3189
+			$owner = $user_info['id'];
3190
+	}
3069 3191
 
3070 3192
 	$in_inbox = '';
3071 3193
 
@@ -3089,8 +3211,7 @@  discard block
 block discarded – undo
3089 3211
 		}
3090 3212
 
3091 3213
 		$smcFunc['db_free_result']($get_messages);
3092
-	}
3093
-	elseif ($label = '-1')
3214
+	} elseif ($label = '-1')
3094 3215
 	{
3095 3216
 		// Marking all PMs in your inbox read
3096 3217
 		$in_inbox = '
@@ -3115,8 +3236,9 @@  discard block
 block discarded – undo
3115 3236
 	{
3116 3237
 		if ($owner == $user_info['id'])
3117 3238
 		{
3118
-			foreach ($context['labels'] as $label)
3119
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3239
+			foreach ($context['labels'] as $label) {
3240
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3241
+			}
3120 3242
 		}
3121 3243
 
3122 3244
 		$result = $smcFunc['db_query']('', '
@@ -3136,8 +3258,9 @@  discard block
 block discarded – undo
3136 3258
 		{
3137 3259
 			$total_unread += $row['num'];
3138 3260
 
3139
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3140
-				continue;
3261
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3262
+							continue;
3263
+			}
3141 3264
 
3142 3265
 			$this_labels = array();
3143 3266
 
@@ -3161,11 +3284,13 @@  discard block
 block discarded – undo
3161 3284
 
3162 3285
 			$smcFunc['db_free_result']($result2);
3163 3286
 
3164
-			foreach ($this_labels as $this_label)
3165
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3287
+			foreach ($this_labels as $this_label) {
3288
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3289
+			}
3166 3290
 
3167
-			if ($row['in_inbox'] == 1)
3168
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3291
+			if ($row['in_inbox'] == 1) {
3292
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3293
+			}
3169 3294
 		}
3170 3295
 		$smcFunc['db_free_result']($result);
3171 3296
 
@@ -3174,8 +3299,9 @@  discard block
 block discarded – undo
3174 3299
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3175 3300
 
3176 3301
 		// If it was for the current member, reflect this in the $user_info array too.
3177
-		if ($owner == $user_info['id'])
3178
-			$user_info['unread_messages'] = $total_unread;
3302
+		if ($owner == $user_info['id']) {
3303
+					$user_info['unread_messages'] = $total_unread;
3304
+		}
3179 3305
 	}
3180 3306
 }
3181 3307
 
@@ -3203,8 +3329,9 @@  discard block
 block discarded – undo
3203 3329
 	// Add all existing labels to the array to save, slashing them as necessary...
3204 3330
 	foreach ($context['labels'] as $label)
3205 3331
 	{
3206
-		if ($label['id'] != -1)
3207
-			$the_labels[$label['id']] = $label['name'];
3332
+		if ($label['id'] != -1) {
3333
+					$the_labels[$label['id']] = $label['name'];
3334
+		}
3208 3335
 	}
3209 3336
 
3210 3337
 	if (isset($_POST[$context['session_var']]))
@@ -3223,8 +3350,9 @@  discard block
 block discarded – undo
3223 3350
 		{
3224 3351
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3225 3352
 
3226
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3227
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3353
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3354
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3355
+			}
3228 3356
 			if ($_POST['label'] != '')
3229 3357
 			{
3230 3358
 				$the_labels[] = $_POST['label'];
@@ -3245,24 +3373,25 @@  discard block
 block discarded – undo
3245 3373
 		{
3246 3374
 			foreach ($the_labels as $id => $name)
3247 3375
 			{
3248
-				if ($id == -1)
3249
-					continue;
3250
-				elseif (isset($_POST['label_name'][$id]))
3376
+				if ($id == -1) {
3377
+									continue;
3378
+				} elseif (isset($_POST['label_name'][$id]))
3251 3379
 				{
3252 3380
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3253 3381
 
3254
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3255
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3382
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3383
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3384
+					}
3256 3385
 					if ($_POST['label_name'][$id] != '')
3257 3386
 					{
3258 3387
 						// Changing the name of this label?
3259
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3260
-							$label_updates[$id] = $_POST['label_name'][$id];
3388
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3389
+													$label_updates[$id] = $_POST['label_name'][$id];
3390
+						}
3261 3391
 
3262 3392
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3263 3393
 
3264
-					}
3265
-					else
3394
+					} else
3266 3395
 					{
3267 3396
 						unset($the_labels[(int) $id]);
3268 3397
 						$labels_to_remove[] = $id;
@@ -3276,8 +3405,9 @@  discard block
 block discarded – undo
3276 3405
 		if (!empty($labels_to_add))
3277 3406
 		{
3278 3407
 			$inserts = array();
3279
-			foreach ($labels_to_add AS $label)
3280
-				$inserts[] = array($user_info['id'], $label);
3408
+			foreach ($labels_to_add AS $label) {
3409
+							$inserts[] = array($user_info['id'], $label);
3410
+			}
3281 3411
 
3282 3412
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3283 3413
 		}
@@ -3367,8 +3497,9 @@  discard block
 block discarded – undo
3367 3497
 				// Each action...
3368 3498
 				foreach ($rule['actions'] as $k2 => $action)
3369 3499
 				{
3370
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3371
-						continue;
3500
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3501
+											continue;
3502
+					}
3372 3503
 
3373 3504
 					$rule_changes[] = $rule['id'];
3374 3505
 
@@ -3383,8 +3514,8 @@  discard block
 block discarded – undo
3383 3514
 		{
3384 3515
 			$rule_changes = array_unique($rule_changes);
3385 3516
 			// Update/delete as appropriate.
3386
-			foreach ($rule_changes as $k => $id)
3387
-				if (!empty($context['rules'][$id]['actions']))
3517
+			foreach ($rule_changes as $k => $id) {
3518
+							if (!empty($context['rules'][$id]['actions']))
3388 3519
 				{
3389 3520
 					$smcFunc['db_query']('', '
3390 3521
 						UPDATE {db_prefix}pm_rules
@@ -3397,12 +3528,13 @@  discard block
 block discarded – undo
3397 3528
 							'actions' => json_encode($context['rules'][$id]['actions']),
3398 3529
 						)
3399 3530
 					);
3531
+			}
3400 3532
 					unset($rule_changes[$k]);
3401 3533
 				}
3402 3534
 
3403 3535
 			// Anything left here means it's lost all actions...
3404
-			if (!empty($rule_changes))
3405
-				$smcFunc['db_query']('', '
3536
+			if (!empty($rule_changes)) {
3537
+							$smcFunc['db_query']('', '
3406 3538
 					DELETE FROM {db_prefix}pm_rules
3407 3539
 					WHERE id_rule IN ({array_int:rule_list})
3408 3540
 							AND id_member = {int:current_member}',
@@ -3411,6 +3543,7 @@  discard block
 block discarded – undo
3411 3543
 						'rule_list' => $rule_changes,
3412 3544
 					)
3413 3545
 				);
3546
+			}
3414 3547
 		}
3415 3548
 
3416 3549
 		// Make sure we're not caching this!
@@ -3480,8 +3613,9 @@  discard block
 block discarded – undo
3480 3613
 		// Save the fields.
3481 3614
 		saveProfileFields();
3482 3615
 
3483
-		if (!empty($profile_vars))
3484
-			updateMemberData($user_info['id'], $profile_vars);
3616
+		if (!empty($profile_vars)) {
3617
+					updateMemberData($user_info['id'], $profile_vars);
3618
+		}
3485 3619
 	}
3486 3620
 
3487 3621
 	setupProfileContext(
@@ -3506,13 +3640,15 @@  discard block
 block discarded – undo
3506 3640
 	global $user_info, $language, $modSettings, $smcFunc;
3507 3641
 
3508 3642
 	// Check that this feature is even enabled!
3509
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3510
-		fatal_lang_error('no_access', false);
3643
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3644
+			fatal_lang_error('no_access', false);
3645
+	}
3511 3646
 
3512 3647
 	$pmsg = (int) $_REQUEST['pmsg'];
3513 3648
 
3514
-	if (!isAccessiblePM($pmsg, 'inbox'))
3515
-		fatal_lang_error('no_access', false);
3649
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3650
+			fatal_lang_error('no_access', false);
3651
+	}
3516 3652
 
3517 3653
 	$context['pm_id'] = $pmsg;
3518 3654
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3534,8 +3670,9 @@  discard block
 block discarded – undo
3534 3670
 			)
3535 3671
 		);
3536 3672
 		$context['admins'] = array();
3537
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3538
-			$context['admins'][$row['id_member']] = $row['real_name'];
3673
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3674
+					$context['admins'][$row['id_member']] = $row['real_name'];
3675
+		}
3539 3676
 		$smcFunc['db_free_result']($request);
3540 3677
 
3541 3678
 		// How many admins in total?
@@ -3564,8 +3701,9 @@  discard block
 block discarded – undo
3564 3701
 			)
3565 3702
 		);
3566 3703
 		// Can only be a hacker here!
3567
-		if ($smcFunc['db_num_rows']($request) == 0)
3568
-			fatal_lang_error('no_access', false);
3704
+		if ($smcFunc['db_num_rows']($request) == 0) {
3705
+					fatal_lang_error('no_access', false);
3706
+		}
3569 3707
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3570 3708
 		$smcFunc['db_free_result']($request);
3571 3709
 
@@ -3589,15 +3727,17 @@  discard block
 block discarded – undo
3589 3727
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3590 3728
 		{
3591 3729
 			// If it's hidden still don't reveal their names - privacy after all ;)
3592
-			if ($row['bcc'])
3593
-				$hidden_recipients++;
3594
-			else
3595
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3730
+			if ($row['bcc']) {
3731
+							$hidden_recipients++;
3732
+			} else {
3733
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3734
+			}
3596 3735
 		}
3597 3736
 		$smcFunc['db_free_result']($request);
3598 3737
 
3599
-		if ($hidden_recipients)
3600
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3738
+		if ($hidden_recipients) {
3739
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3740
+		}
3601 3741
 
3602 3742
 		// Now let's get out and loop through the admins.
3603 3743
 		$request = $smcFunc['db_query']('', '
@@ -3613,8 +3753,9 @@  discard block
 block discarded – undo
3613 3753
 		);
3614 3754
 
3615 3755
 		// Maybe we shouldn't advertise this?
3616
-		if ($smcFunc['db_num_rows']($request) == 0)
3617
-			fatal_lang_error('no_access', false);
3756
+		if ($smcFunc['db_num_rows']($request) == 0) {
3757
+					fatal_lang_error('no_access', false);
3758
+		}
3618 3759
 
3619 3760
 		$memberFromName = un_htmlspecialchars($memberFromName);
3620 3761
 
@@ -3633,8 +3774,9 @@  discard block
 block discarded – undo
3633 3774
 				// Make the body.
3634 3775
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3635 3776
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3636
-				if (!empty($recipients))
3637
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3777
+				if (!empty($recipients)) {
3778
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3779
+				}
3638 3780
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3639 3781
 
3640 3782
 				// Plonk it in the array ;)
@@ -3654,12 +3796,14 @@  discard block
 block discarded – undo
3654 3796
 		$smcFunc['db_free_result']($request);
3655 3797
 
3656 3798
 		// Send a different email for each language.
3657
-		foreach ($messagesToSend as $lang => $message)
3658
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3799
+		foreach ($messagesToSend as $lang => $message) {
3800
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3801
+		}
3659 3802
 
3660 3803
 		// Give the user their own language back!
3661
-		if (!empty($modSettings['userLanguage']))
3662
-			loadLanguage('PersonalMessage', '', false);
3804
+		if (!empty($modSettings['userLanguage'])) {
3805
+					loadLanguage('PersonalMessage', '', false);
3806
+		}
3663 3807
 
3664 3808
 		// Leave them with a template.
3665 3809
 		$context['sub_template'] = 'report_message_complete';
@@ -3705,8 +3849,9 @@  discard block
 block discarded – undo
3705 3849
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3706 3850
 	{
3707 3851
 		// Hide hidden groups!
3708
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3709
-			continue;
3852
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3853
+					continue;
3854
+		}
3710 3855
 
3711 3856
 		$context['groups'][$row['id_group']] = $row['group_name'];
3712 3857
 	}
@@ -3732,9 +3877,10 @@  discard block
 block discarded – undo
3732 3877
 			$context['rule'] = $context['rules'][$context['rid']];
3733 3878
 			$members = array();
3734 3879
 			// Need to get member names!
3735
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3736
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3880
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3881
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3737 3882
 					$members[(int) $criteria['v']] = $k;
3883
+			}
3738 3884
 
3739 3885
 			if (!empty($members))
3740 3886
 			{
@@ -3746,19 +3892,20 @@  discard block
 block discarded – undo
3746 3892
 						'member_list' => array_keys($members),
3747 3893
 					)
3748 3894
 				);
3749
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3750
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3895
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3896
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3897
+				}
3751 3898
 				$smcFunc['db_free_result']($request);
3752 3899
 			}
3753
-		}
3754
-		else
3755
-			$context['rule'] = array(
3900
+		} else {
3901
+					$context['rule'] = array(
3756 3902
 				'id' => '',
3757 3903
 				'name' => '',
3758 3904
 				'criteria' => array(),
3759 3905
 				'actions' => array(),
3760 3906
 				'logic' => 'and',
3761 3907
 			);
3908
+		}
3762 3909
 	}
3763 3910
 	// Saving?
3764 3911
 	elseif (isset($_GET['save']))
@@ -3768,22 +3915,25 @@  discard block
 block discarded – undo
3768 3915
 
3769 3916
 		// Name is easy!
3770 3917
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3771
-		if (empty($ruleName))
3772
-			fatal_lang_error('pm_rule_no_name', false);
3918
+		if (empty($ruleName)) {
3919
+					fatal_lang_error('pm_rule_no_name', false);
3920
+		}
3773 3921
 
3774 3922
 		// Sanity check...
3775
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3776
-			fatal_lang_error('pm_rule_no_criteria', false);
3923
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3924
+					fatal_lang_error('pm_rule_no_criteria', false);
3925
+		}
3777 3926
 
3778 3927
 		// Let's do the criteria first - it's also hardest!
3779 3928
 		$criteria = array();
3780 3929
 		foreach ($_POST['ruletype'] as $ind => $type)
3781 3930
 		{
3782 3931
 			// Check everything is here...
3783
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3784
-				continue;
3785
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3786
-				continue;
3932
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3933
+							continue;
3934
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3935
+							continue;
3936
+			}
3787 3937
 
3788 3938
 			// Members need to be found.
3789 3939
 			if ($type == 'mid')
@@ -3807,13 +3957,13 @@  discard block
 block discarded – undo
3807 3957
 				$smcFunc['db_free_result']($request);
3808 3958
 
3809 3959
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3960
+			} elseif ($type == 'bud') {
3961
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3962
+			} elseif ($type == 'gid') {
3963
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3964
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3965
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3810 3966
 			}
3811
-			elseif ($type == 'bud')
3812
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3813
-			elseif ($type == 'gid')
3814
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3815
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3816
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3817 3967
 		}
3818 3968
 
3819 3969
 		// Also do the actions!
@@ -3823,26 +3973,29 @@  discard block
 block discarded – undo
3823 3973
 		foreach ($_POST['acttype'] as $ind => $type)
3824 3974
 		{
3825 3975
 			// Picking a valid label?
3826
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3827
-				continue;
3976
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3977
+							continue;
3978
+			}
3828 3979
 
3829 3980
 			// Record what we're doing.
3830
-			if ($type == 'del')
3831
-				$doDelete = 1;
3832
-			elseif ($type == 'lab')
3833
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3981
+			if ($type == 'del') {
3982
+							$doDelete = 1;
3983
+			} elseif ($type == 'lab') {
3984
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3985
+			}
3834 3986
 		}
3835 3987
 
3836
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3837
-			fatal_lang_error('pm_rule_no_criteria', false);
3988
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3989
+					fatal_lang_error('pm_rule_no_criteria', false);
3990
+		}
3838 3991
 
3839 3992
 		// What are we storing?
3840 3993
 		$criteria = json_encode($criteria);
3841 3994
 		$actions = json_encode($actions);
3842 3995
 
3843 3996
 		// Create the rule?
3844
-		if (empty($context['rid']))
3845
-			$smcFunc['db_insert']('',
3997
+		if (empty($context['rid'])) {
3998
+					$smcFunc['db_insert']('',
3846 3999
 				'{db_prefix}pm_rules',
3847 4000
 				array(
3848 4001
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3853,8 +4006,8 @@  discard block
 block discarded – undo
3853 4006
 				),
3854 4007
 				array('id_rule')
3855 4008
 			);
3856
-		else
3857
-			$smcFunc['db_query']('', '
4009
+		} else {
4010
+					$smcFunc['db_query']('', '
3858 4011
 				UPDATE {db_prefix}pm_rules
3859 4012
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3860 4013
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3870,6 +4023,7 @@  discard block
 block discarded – undo
3870 4023
 					'actions' => $actions,
3871 4024
 				)
3872 4025
 			);
4026
+		}
3873 4027
 
3874 4028
 		redirectexit('action=pm;sa=manrules');
3875 4029
 	}
@@ -3878,11 +4032,12 @@  discard block
 block discarded – undo
3878 4032
 	{
3879 4033
 		checkSession();
3880 4034
 		$toDelete = array();
3881
-		foreach ($_POST['delrule'] as $k => $v)
3882
-			$toDelete[] = (int) $k;
4035
+		foreach ($_POST['delrule'] as $k => $v) {
4036
+					$toDelete[] = (int) $k;
4037
+		}
3883 4038
 
3884
-		if (!empty($toDelete))
3885
-			$smcFunc['db_query']('', '
4039
+		if (!empty($toDelete)) {
4040
+					$smcFunc['db_query']('', '
3886 4041
 				DELETE FROM {db_prefix}pm_rules
3887 4042
 				WHERE id_rule IN ({array_int:delete_list})
3888 4043
 					AND id_member = {int:current_member}',
@@ -3891,6 +4046,7 @@  discard block
 block discarded – undo
3891 4046
 					'delete_list' => $toDelete,
3892 4047
 				)
3893 4048
 			);
4049
+		}
3894 4050
 
3895 4051
 		redirectexit('action=pm;sa=manrules');
3896 4052
 	}
@@ -3909,8 +4065,9 @@  discard block
 block discarded – undo
3909 4065
 	loadRules();
3910 4066
 
3911 4067
 	// No rules?
3912
-	if (empty($context['rules']))
3913
-		return;
4068
+	if (empty($context['rules'])) {
4069
+			return;
4070
+	}
3914 4071
 
3915 4072
 	// Just unread ones?
3916 4073
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3940,8 +4097,9 @@  discard block
 block discarded – undo
3940 4097
 			// Loop through all the criteria hoping to make a match.
3941 4098
 			foreach ($rule['criteria'] as $criterium)
3942 4099
 			{
3943
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3944
-					$match = true;
4100
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4101
+									$match = true;
4102
+				}
3945 4103
 				// If we're adding and one criteria don't match then we stop!
3946 4104
 				elseif ($rule['logic'] == 'and')
3947 4105
 				{
@@ -3953,17 +4111,18 @@  discard block
 block discarded – undo
3953 4111
 			// If we have a match the rule must be true - act!
3954 4112
 			if ($match)
3955 4113
 			{
3956
-				if ($rule['delete'])
3957
-					$actions['deletes'][] = $row['id_pm'];
3958
-				else
4114
+				if ($rule['delete']) {
4115
+									$actions['deletes'][] = $row['id_pm'];
4116
+				} else
3959 4117
 				{
3960 4118
 					foreach ($rule['actions'] as $ruleAction)
3961 4119
 					{
3962 4120
 						if ($ruleAction['t'] == 'lab')
3963 4121
 						{
3964 4122
 							// Get a basic pot started!
3965
-							if (!isset($actions['labels'][$row['id_pm']]))
3966
-								$actions['labels'][$row['id_pm']] = array();
4123
+							if (!isset($actions['labels'][$row['id_pm']])) {
4124
+															$actions['labels'][$row['id_pm']] = array();
4125
+							}
3967 4126
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3968 4127
 						}
3969 4128
 					}
@@ -3974,8 +4133,9 @@  discard block
 block discarded – undo
3974 4133
 	$smcFunc['db_free_result']($request);
3975 4134
 
3976 4135
 	// Deletes are easy!
3977
-	if (!empty($actions['deletes']))
3978
-		deleteMessages($actions['deletes']);
4136
+	if (!empty($actions['deletes'])) {
4137
+			deleteMessages($actions['deletes']);
4138
+	}
3979 4139
 
3980 4140
 	// Relabel?
3981 4141
 	if (!empty($actions['labels']))
@@ -4002,8 +4162,7 @@  discard block
 block discarded – undo
4002 4162
 								'current_member' => $user_info['id'],
4003 4163
 							)
4004 4164
 						);
4005
-					}
4006
-					else
4165
+					} else
4007 4166
 					{
4008 4167
 						$realLabels[] = $label['id'];
4009 4168
 					}
@@ -4012,8 +4171,9 @@  discard block
 block discarded – undo
4012 4171
 
4013 4172
 			$inserts = array();
4014 4173
 			// Now we insert the label info
4015
-			foreach ($realLabels as $a_label)
4016
-				$inserts[] = array($pm, $a_label);
4174
+			foreach ($realLabels as $a_label) {
4175
+							$inserts[] = array($pm, $a_label);
4176
+			}
4017 4177
 
4018 4178
 			$smcFunc['db_insert']('ignore',
4019 4179
 				'{db_prefix}pm_labeled_messages',
@@ -4034,8 +4194,9 @@  discard block
 block discarded – undo
4034 4194
 {
4035 4195
 	global $user_info, $context, $smcFunc;
4036 4196
 
4037
-	if (isset($context['rules']) && !$reload)
4038
-		return;
4197
+	if (isset($context['rules']) && !$reload) {
4198
+			return;
4199
+	}
4039 4200
 
4040 4201
 	$request = $smcFunc['db_query']('', '
4041 4202
 		SELECT
@@ -4059,8 +4220,9 @@  discard block
 block discarded – undo
4059 4220
 			'logic' => $row['is_or'] ? 'or' : 'and',
4060 4221
 		);
4061 4222
 
4062
-		if ($row['delete_pm'])
4063
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4223
+		if ($row['delete_pm']) {
4224
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4225
+		}
4064 4226
 	}
4065 4227
 	$smcFunc['db_free_result']($request);
4066 4228
 }
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2183,7 +2183,7 @@  discard block
 block discarded – undo
2183 2183
  * Deletes a single or a group of alerts by ID
2184 2184
  *
2185 2185
  * @param int|array The ID of a single alert to delete or an array containing the IDs of multiple alerts. The function will convert integers into an array for better handling.
2186
- * @param bool|int $memID The user ID. Used to update the user unread alerts count.
2186
+ * @param integer $memID The user ID. Used to update the user unread alerts count.
2187 2187
  * @return void|int If the $memID param is set, returns the new amount of unread alerts.
2188 2188
  */
2189 2189
 function alert_delete($toDelete, $memID = false)
@@ -2839,7 +2839,7 @@  discard block
 block discarded – undo
2839 2839
 /**
2840 2840
  * Handles the "manage groups" section of the profile
2841 2841
  *
2842
- * @return true Always returns true
2842
+ * @return boolean Always returns true
2843 2843
  */
2844 2844
 function profileLoadGroups()
2845 2845
 {
@@ -2896,7 +2896,7 @@  discard block
 block discarded – undo
2896 2896
 /**
2897 2897
  * Load key signature context data.
2898 2898
  *
2899
- * @return true Always returns true
2899
+ * @return boolean Always returns true
2900 2900
  */
2901 2901
 function profileLoadSignatureData()
2902 2902
 {
@@ -2960,7 +2960,7 @@  discard block
 block discarded – undo
2960 2960
 /**
2961 2961
  * Load avatar context data.
2962 2962
  *
2963
- * @return true Always returns true
2963
+ * @return boolean Always returns true
2964 2964
  */
2965 2965
 function profileLoadAvatarData()
2966 2966
 {
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
  * Save a members group.
3034 3034
  *
3035 3035
  * @param int &$value The ID of the (new) primary group
3036
- * @return true Always returns true
3036
+ * @return boolean Always returns true
3037 3037
  */
3038 3038
 function profileSaveGroups(&$value)
3039 3039
 {
@@ -3138,7 +3138,7 @@  discard block
 block discarded – undo
3138 3138
  * @todo argh, the avatar here. Take this out of here!
3139 3139
  *
3140 3140
  * @param string &$value What kind of avatar we're expecting. Can be 'none', 'server_stored', 'gravatar', 'external' or 'upload'
3141
- * @return bool|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3141
+ * @return false|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3142 3142
  */
3143 3143
 function profileSaveAvatarData(&$value)
3144 3144
 {
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			'type' => 'callback',
87 87
 			'callback_func' => 'birthdate',
88 88
 			'permission' => 'profile_extra',
89
-			'preload' => function () use ($cur_profile, &$context)
89
+			'preload' => function() use ($cur_profile, &$context)
90 90
 			{
91 91
 				// Split up the birthdate....
92 92
 				list ($uyear, $umonth, $uday) = explode('-', empty($cur_profile['birthdate']) || $cur_profile['birthdate'] == '0001-01-01' ? '0000-00-00' : $cur_profile['birthdate']);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
 				return true;
100 100
 			},
101
-			'input_validate' => function (&$value) use (&$cur_profile, &$profile_vars)
101
+			'input_validate' => function(&$value) use (&$cur_profile, &$profile_vars)
102 102
 			{
103 103
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 104
 				{
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 		'birthdate' => array(
121 121
 			'type' => 'hidden',
122 122
 			'permission' => 'profile_extra',
123
-			'input_validate' => function (&$value) use ($cur_profile)
123
+			'input_validate' => function(&$value) use ($cur_profile)
124 124
 			{
125 125
 				// @todo Should we check for this year and tell them they made a mistake :P? (based on coppa at least?)
126 126
 				if (preg_match('/(\d{4})[\-\., ](\d{2})[\-\., ](\d{2})/', $value, $dates) === 1)
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 			'label' => $txt['date_registered'],
142 142
 			'log_change' => true,
143 143
 			'permission' => 'moderate_forum',
144
-			'input_validate' => function (&$value) use ($txt, $user_info, $modSettings, $cur_profile, $context)
144
+			'input_validate' => function(&$value) use ($txt, $user_info, $modSettings, $cur_profile, $context)
145 145
 			{
146 146
 				// Bad date!  Go try again - please?
147 147
 				if (($value = strtotime($value)) === -1)
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
 			'js_submit' => !empty($modSettings['send_validation_onChange']) ? '
168 168
 	form_handle.addEventListener(\'submit\', function(event)
169 169
 	{
170
-		if (this.email_address.value != "'. $cur_profile['email_address'] .'")
170
+		if (this.email_address.value != "'. $cur_profile['email_address'] . '")
171 171
 		{
172
-			alert('. JavaScriptEscape($txt['email_change_logout']) .');
172
+			alert('. JavaScriptEscape($txt['email_change_logout']) . ');
173 173
 			return true;
174 174
 		}
175 175
 	}, false);' : '',
176
-			'input_validate' => function (&$value)
176
+			'input_validate' => function(&$value)
177 177
 			{
178 178
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 179
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			'callback_func' => 'theme_pick',
210 210
 			'permission' => 'profile_extra',
211 211
 			'enabled' => $modSettings['theme_allow'] || allowedTo('admin_forum'),
212
-			'preload' => function () use ($smcFunc, &$context, $cur_profile, $txt)
212
+			'preload' => function() use ($smcFunc, &$context, $cur_profile, $txt)
213 213
 			{
214 214
 				$request = $smcFunc['db_query']('', '
215 215
 					SELECT value
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 				);
231 231
 				return true;
232 232
 			},
233
-			'input_validate' => function (&$value)
233
+			'input_validate' => function(&$value)
234 234
 			{
235 235
 				$value = (int) $value;
236 236
 				return true;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		),
239 239
 		'lngfile' => array(
240 240
 			'type' => 'select',
241
-			'options' => function () use (&$context)
241
+			'options' => function() use (&$context)
242 242
 			{
243 243
 				return $context['profile_languages'];
244 244
 			},
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			'preload' => 'profileLoadLanguages',
248 248
 			'enabled' => !empty($modSettings['userLanguage']),
249 249
 			'value' => empty($cur_profile['lngfile']) ? $language : $cur_profile['lngfile'],
250
-			'input_validate' => function (&$value) use (&$context, $cur_profile)
250
+			'input_validate' => function(&$value) use (&$context, $cur_profile)
251 251
 			{
252 252
 				// Load the languages.
253 253
 				profileLoadLanguages();
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 			'log_change' => true,
274 274
 			'permission' => 'profile_identity',
275 275
 			'prehtml' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? '<div class="alert">' . $txt['username_warning'] . '</div>' : '',
276
-			'input_validate' => function (&$value) use ($sourcedir, $context, $user_info, $cur_profile)
276
+			'input_validate' => function(&$value) use ($sourcedir, $context, $user_info, $cur_profile)
277 277
 			{
278 278
 				if (allowedTo('admin_forum'))
279 279
 				{
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 			'permission' => 'profile_password',
310 310
 			'save_key' => 'passwd',
311 311
 			// Note this will only work if passwrd2 also exists!
312
-			'input_validate' => function (&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
312
+			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 313
 			{
314 314
 				// If we didn't try it then ignore it!
315 315
 				if ($value == '')
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			'input_attr' => array('maxlength="50"'),
349 349
 			'size' => 50,
350 350
 			'permission' => 'profile_blurb',
351
-			'input_validate' => function (&$value) use ($smcFunc)
351
+			'input_validate' => function(&$value) use ($smcFunc)
352 352
 			{
353 353
 				if ($smcFunc['strlen']($value) > 50)
354 354
 					return 'personal_text_too_long';
@@ -361,14 +361,14 @@  discard block
 block discarded – undo
361 361
 			'type' => 'callback',
362 362
 			'callback_func' => 'pm_settings',
363 363
 			'permission' => 'pm_read',
364
-			'preload' => function () use (&$context, $cur_profile)
364
+			'preload' => function() use (&$context, $cur_profile)
365 365
 			{
366 366
 				$context['display_mode'] = $cur_profile['pm_prefs'] & 3;
367 367
 				$context['receive_from'] = !empty($cur_profile['pm_receive_from']) ? $cur_profile['pm_receive_from'] : 0;
368 368
 
369 369
 				return true;
370 370
 			},
371
-			'input_validate' => function (&$value) use (&$cur_profile, &$profile_vars)
371
+			'input_validate' => function(&$value) use (&$cur_profile, &$profile_vars)
372 372
 			{
373 373
 				// Simple validate and apply the two "sub settings"
374 374
 				$value = max(min($value, 2), 0);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 			'log_change' => true,
385 385
 			'size' => 7,
386 386
 			'permission' => 'moderate_forum',
387
-			'input_validate' => function (&$value)
387
+			'input_validate' => function(&$value)
388 388
 			{
389 389
 				if (!is_numeric($value))
390 390
 					return 'digits_only';
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 			'input_attr' => array('maxlength="60"'),
402 402
 			'permission' => 'profile_displayed_name',
403 403
 			'enabled' => allowedTo('profile_displayed_name_own') || allowedTo('profile_displayed_name_any') || allowedTo('moderate_forum'),
404
-			'input_validate' => function (&$value) use ($context, $smcFunc, $sourcedir, $cur_profile)
404
+			'input_validate' => function(&$value) use ($context, $smcFunc, $sourcedir, $cur_profile)
405 405
 			{
406 406
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 407
 
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 			'postinput' => '<span class="smalltext"><a href="' . $scripturl . '?action=helpadmin;help=secret_why_blank" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help"></span> ' . $txt['secret_why_blank'] . '</a></span>',
434 434
 			'value' => '',
435 435
 			'permission' => 'profile_password',
436
-			'input_validate' => function (&$value)
436
+			'input_validate' => function(&$value)
437 437
 			{
438 438
 				$value = $value != '' ? md5($value) : '';
439 439
 				return true;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 			'callback_func' => 'smiley_pick',
459 459
 			'enabled' => !empty($modSettings['smiley_sets_enable']),
460 460
 			'permission' => 'profile_extra',
461
-			'preload' => function () use ($modSettings, &$context, $txt, $cur_profile, $smcFunc)
461
+			'preload' => function() use ($modSettings, &$context, $txt, $cur_profile, $smcFunc)
462 462
 			{
463 463
 				$context['member']['smiley_set']['id'] = empty($cur_profile['smiley_set']) ? '' : $cur_profile['smiley_set'];
464 464
 				$context['smiley_sets'] = explode(',', 'none,,' . $modSettings['smiley_sets_known']);
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 				}
477 477
 				return true;
478 478
 			},
479
-			'input_validate' => function (&$value)
479
+			'input_validate' => function(&$value)
480 480
 			{
481 481
 				global $modSettings;
482 482
 
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 			'callback_func' => 'theme_settings',
493 493
 			'permission' => 'profile_extra',
494 494
 			'is_dummy' => true,
495
-			'preload' => function () use (&$context, $user_info, $modSettings)
495
+			'preload' => function() use (&$context, $user_info, $modSettings)
496 496
 			{
497 497
 				loadLanguage('Settings');
498 498
 
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
 			'type' => 'callback',
520 520
 			'callback_func' => 'timeformat_modify',
521 521
 			'permission' => 'profile_extra',
522
-			'preload' => function () use (&$context, $user_info, $txt, $cur_profile, $modSettings)
522
+			'preload' => function() use (&$context, $user_info, $txt, $cur_profile, $modSettings)
523 523
 			{
524 524
 				$context['easy_timeformats'] = array(
525 525
 					array('format' => '', 'title' => $txt['timeformat_default']),
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 			'options' => smf_list_timezones(),
543 543
 			'permission' => 'profile_extra',
544 544
 			'label' => $txt['timezone'],
545
-			'input_validate' => function ($value)
545
+			'input_validate' => function($value)
546 546
 			{
547 547
 				$tz = smf_list_timezones();
548 548
 				if (!isset($tz[$value]))
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 			'size' => 50,
560 560
 			'permission' => 'profile_title',
561 561
 			'enabled' => !empty($modSettings['titlesEnable']),
562
-			'input_validate' => function (&$value) use ($smcFunc)
562
+			'input_validate' => function(&$value) use ($smcFunc)
563 563
 			{
564 564
 				if ($smcFunc['strlen']($value) > 50)
565 565
 					return 'user_title_too_long';
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 			'size' => 50,
583 583
 			'permission' => 'profile_website',
584 584
 			// Fix the URL...
585
-			'input_validate' => function (&$value)
585
+			'input_validate' => function(&$value)
586 586
 			{
587 587
 				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588 588
 					$value = 'http://' . $value;
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 		if (this.oldpasswrd.value == "")
708 708
 		{
709 709
 			event.preventDefault();
710
-			alert('. (JavaScriptEscape($txt['required_security_reasons'])) .');
710
+			alert('. (JavaScriptEscape($txt['required_security_reasons'])) . ');
711 711
 			return false;
712 712
 		}
713 713
 	}, false);' : ''), true);
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 	if (isset($_POST['ignore_brd']))
907 907
 	{
908 908
 		if (!is_array($_POST['ignore_brd']))
909
-			$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
909
+			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
910 910
 
911 911
 		foreach ($_POST['ignore_brd'] as $k => $d)
912 912
 		{
@@ -1872,7 +1872,7 @@  discard block
 block discarded – undo
1872 1872
 
1873 1873
 	// Now load all the values for this user.
1874 1874
 	require_once($sourcedir . '/Subs-Notify.php');
1875
-	$prefs = getNotifyPrefs($memID,  '', $memID != 0);
1875
+	$prefs = getNotifyPrefs($memID, '', $memID != 0);
1876 1876
 
1877 1877
 	$context['alert_prefs'] = !empty($prefs[$memID]) ? $prefs[$memID] : array();
1878 1878
 
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
 	);
2172 2172
 
2173 2173
 	// Gotta know how many unread alerts are left.
2174
-	$count =  alert_count($memID, true);
2174
+	$count = alert_count($memID, true);
2175 2175
 
2176 2176
 	updateMemberData($memID, array('alerts' => $count));
2177 2177
 
@@ -2206,7 +2206,7 @@  discard block
 block discarded – undo
2206 2206
 	// Gotta know how many unread alerts are left.
2207 2207
 	if ($memID)
2208 2208
 	{
2209
-		$count =  alert_count($memID, true);
2209
+		$count = alert_count($memID, true);
2210 2210
 
2211 2211
 		updateMemberData($memID, array('alerts' => $count));
2212 2212
 
@@ -2242,7 +2242,7 @@  discard block
 block discarded – undo
2242 2242
 		)
2243 2243
 	);
2244 2244
 
2245
-	$count =  $smcFunc['db_num_rows']($request);
2245
+	$count = $smcFunc['db_num_rows']($request);
2246 2246
 	$smcFunc['db_free_result']($request);
2247 2247
 
2248 2248
 	return $count;
@@ -2302,7 +2302,7 @@  discard block
 block discarded – undo
2302 2302
 					'class' => 'lefttext',
2303 2303
 				),
2304 2304
 				'data' => array(
2305
-					'function' => function ($topic) use ($txt)
2305
+					'function' => function($topic) use ($txt)
2306 2306
 					{
2307 2307
 						$link = $topic['link'];
2308 2308
 
@@ -2357,7 +2357,7 @@  discard block
 block discarded – undo
2357 2357
 					'class' => 'lefttext',
2358 2358
 				),
2359 2359
 				'data' => array(
2360
-					'function' => function ($topic) use ($txt)
2360
+					'function' => function($topic) use ($txt)
2361 2361
 					{
2362 2362
 						$pref = $topic['notify_pref'];
2363 2363
 						$mode = !empty($topic['unwatched']) ? 0 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
@@ -2454,7 +2454,7 @@  discard block
 block discarded – undo
2454 2454
 					'class' => 'lefttext',
2455 2455
 				),
2456 2456
 				'data' => array(
2457
-					'function' => function ($board) use ($txt)
2457
+					'function' => function($board) use ($txt)
2458 2458
 					{
2459 2459
 						$link = $board['link'];
2460 2460
 
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
 					'class' => 'lefttext',
2476 2476
 				),
2477 2477
 				'data' => array(
2478
-					'function' => function ($board) use ($txt)
2478
+					'function' => function($board) use ($txt)
2479 2479
 					{
2480 2480
 						$pref = $board['notify_pref'];
2481 2481
 						$mode = $pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1);
Please login to merge, or discard this patch.
Braces   +693 added lines, -519 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function (&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function (&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function (&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function ($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function (&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function (&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -883,8 +922,7 @@  discard block
 block discarded – undo
883 922
 	{
884 923
 		$changeIdentity = allowedTo(array('profile_identity_any', 'profile_identity_own', 'profile_password_any', 'profile_password_own'));
885 924
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
886
-	}
887
-	else
925
+	} else
888 926
 	{
889 927
 		$changeIdentity = allowedTo('profile_identity_any', 'profile_signature_any');
890 928
 		$changeOther = allowedTo('profile_extra_any', 'profile_website_any', 'profile_signature_any');
@@ -899,22 +937,25 @@  discard block
 block discarded – undo
899 937
 		'ignore_boards',
900 938
 	);
901 939
 
902
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
903
-		$_POST['ignore_brd'] = array();
940
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
941
+			$_POST['ignore_brd'] = array();
942
+	}
904 943
 
905 944
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
906 945
 	if (isset($_POST['ignore_brd']))
907 946
 	{
908
-		if (!is_array($_POST['ignore_brd']))
909
-			$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
947
+		if (!is_array($_POST['ignore_brd'])) {
948
+					$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
949
+		}
910 950
 
911 951
 		foreach ($_POST['ignore_brd'] as $k => $d)
912 952
 		{
913 953
 			$d = (int) $d;
914
-			if ($d != 0)
915
-				$_POST['ignore_brd'][$k] = $d;
916
-			else
917
-				unset($_POST['ignore_brd'][$k]);
954
+			if ($d != 0) {
955
+							$_POST['ignore_brd'][$k] = $d;
956
+			} else {
957
+							unset($_POST['ignore_brd'][$k]);
958
+			}
918 959
 		}
919 960
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
920 961
 		unset($_POST['ignore_brd']);
@@ -927,21 +968,26 @@  discard block
 block discarded – undo
927 968
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
928 969
 		//makeAvatarChanges($memID, $post_errors);
929 970
 
930
-		if (!empty($_REQUEST['sa']))
931
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
971
+		if (!empty($_REQUEST['sa'])) {
972
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
973
+		}
932 974
 
933
-		foreach ($profile_bools as $var)
934
-			if (isset($_POST[$var]))
975
+		foreach ($profile_bools as $var) {
976
+					if (isset($_POST[$var]))
935 977
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
936
-		foreach ($profile_ints as $var)
937
-			if (isset($_POST[$var]))
978
+		}
979
+		foreach ($profile_ints as $var) {
980
+					if (isset($_POST[$var]))
938 981
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
939
-		foreach ($profile_floats as $var)
940
-			if (isset($_POST[$var]))
982
+		}
983
+		foreach ($profile_floats as $var) {
984
+					if (isset($_POST[$var]))
941 985
 				$profile_vars[$var] = (float) $_POST[$var];
942
-		foreach ($profile_strings as $var)
943
-			if (isset($_POST[$var]))
986
+		}
987
+		foreach ($profile_strings as $var) {
988
+					if (isset($_POST[$var]))
944 989
 				$profile_vars[$var] = $_POST[$var];
990
+		}
945 991
 	}
946 992
 }
947 993
 
@@ -975,8 +1021,9 @@  discard block
 block discarded – undo
975 1021
 	);
976 1022
 
977 1023
 	// Can't change reserved vars.
978
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
979
-		fatal_lang_error('no_access', false);
1024
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1025
+			fatal_lang_error('no_access', false);
1026
+	}
980 1027
 
981 1028
 	// Don't allow any overriding of custom fields with default or non-default options.
982 1029
 	$request = $smcFunc['db_query']('', '
@@ -988,8 +1035,9 @@  discard block
 block discarded – undo
988 1035
 		)
989 1036
 	);
990 1037
 	$custom_fields = array();
991
-	while ($row = $smcFunc['db_fetch_assoc']($request))
992
-		$custom_fields[] = $row['col_name'];
1038
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1039
+			$custom_fields[] = $row['col_name'];
1040
+	}
993 1041
 	$smcFunc['db_free_result']($request);
994 1042
 
995 1043
 	// These are the theme changes...
@@ -998,33 +1046,39 @@  discard block
 block discarded – undo
998 1046
 	{
999 1047
 		foreach ($_POST['options'] as $opt => $val)
1000 1048
 		{
1001
-			if (in_array($opt, $custom_fields))
1002
-				continue;
1049
+			if (in_array($opt, $custom_fields)) {
1050
+							continue;
1051
+			}
1003 1052
 
1004 1053
 			// These need to be controlled.
1005
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1006
-				$val = max(0, min($val, 50));
1054
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1055
+							$val = max(0, min($val, 50));
1056
+			}
1007 1057
 			// We don't set this per theme anymore.
1008
-			elseif ($opt == 'allow_no_censored')
1009
-				continue;
1058
+			elseif ($opt == 'allow_no_censored') {
1059
+							continue;
1060
+			}
1010 1061
 
1011 1062
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1012 1063
 		}
1013 1064
 	}
1014 1065
 
1015 1066
 	$erase_options = array();
1016
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1017
-		foreach ($_POST['default_options'] as $opt => $val)
1067
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1068
+			foreach ($_POST['default_options'] as $opt => $val)
1018 1069
 		{
1019 1070
 			if (in_array($opt, $custom_fields))
1020 1071
 				continue;
1072
+	}
1021 1073
 
1022 1074
 			// These need to be controlled.
1023
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1024
-				$val = max(0, min($val, 50));
1075
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1076
+							$val = max(0, min($val, 50));
1077
+			}
1025 1078
 			// Only let admins and owners change the censor.
1026
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1027
-					continue;
1079
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1080
+								continue;
1081
+			}
1028 1082
 
1029 1083
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1030 1084
 			$erase_options[] = $opt;
@@ -1060,8 +1114,9 @@  discard block
 block discarded – undo
1060 1114
 
1061 1115
 		// Admins can choose any theme, even if it's not enabled...
1062 1116
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1063
-		foreach ($themes as $t)
1064
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1117
+		foreach ($themes as $t) {
1118
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1119
+		}
1065 1120
 	}
1066 1121
 }
1067 1122
 
@@ -1080,8 +1135,9 @@  discard block
 block discarded – undo
1080 1135
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1081 1136
 	{
1082 1137
 		// Make sure only integers are deleted.
1083
-		foreach ($_POST['notify_boards'] as $index => $id)
1084
-			$_POST['notify_boards'][$index] = (int) $id;
1138
+		foreach ($_POST['notify_boards'] as $index => $id) {
1139
+					$_POST['notify_boards'][$index] = (int) $id;
1140
+		}
1085 1141
 
1086 1142
 		// id_board = 0 is reserved for topic notifications.
1087 1143
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1100,8 +1156,9 @@  discard block
 block discarded – undo
1100 1156
 	// We are editing topic notifications......
1101 1157
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1102 1158
 	{
1103
-		foreach ($_POST['notify_topics'] as $index => $id)
1104
-			$_POST['notify_topics'][$index] = (int) $id;
1159
+		foreach ($_POST['notify_topics'] as $index => $id) {
1160
+					$_POST['notify_topics'][$index] = (int) $id;
1161
+		}
1105 1162
 
1106 1163
 		// Make sure there are no zeros left.
1107 1164
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1115,16 +1172,18 @@  discard block
 block discarded – undo
1115 1172
 				'selected_member' => $memID,
1116 1173
 			)
1117 1174
 		);
1118
-		foreach ($_POST['notify_topics'] as $topic)
1119
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1175
+		foreach ($_POST['notify_topics'] as $topic) {
1176
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1177
+		}
1120 1178
 	}
1121 1179
 
1122 1180
 	// We are removing topic preferences
1123 1181
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1124 1182
 	{
1125 1183
 		$prefs = array();
1126
-		foreach ($_POST['notify_topics'] as $topic)
1127
-			$prefs[] = 'topic_notify_' . $topic;
1184
+		foreach ($_POST['notify_topics'] as $topic) {
1185
+					$prefs[] = 'topic_notify_' . $topic;
1186
+		}
1128 1187
 		deleteNotifyPrefs($memID, $prefs);
1129 1188
 	}
1130 1189
 
@@ -1132,8 +1191,9 @@  discard block
 block discarded – undo
1132 1191
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1133 1192
 	{
1134 1193
 		$prefs = array();
1135
-		foreach ($_POST['notify_boards'] as $board)
1136
-			$prefs[] = 'board_notify_' . $board;
1194
+		foreach ($_POST['notify_boards'] as $board) {
1195
+					$prefs[] = 'board_notify_' . $board;
1196
+		}
1137 1197
 		deleteNotifyPrefs($memID, $prefs);
1138 1198
 	}
1139 1199
 }
@@ -1154,8 +1214,9 @@  discard block
 block discarded – undo
1154 1214
 
1155 1215
 	$errors = array();
1156 1216
 
1157
-	if ($sanitize && isset($_POST['customfield']))
1158
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1217
+	if ($sanitize && isset($_POST['customfield'])) {
1218
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1219
+	}
1159 1220
 
1160 1221
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1161 1222
 
@@ -1180,48 +1241,49 @@  discard block
 block discarded – undo
1180 1241
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1181 1242
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1182 1243
 		*/
1183
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1184
-			continue;
1244
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1245
+					continue;
1246
+		}
1185 1247
 
1186 1248
 		// Validate the user data.
1187
-		if ($row['field_type'] == 'check')
1188
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1189
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1249
+		if ($row['field_type'] == 'check') {
1250
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1251
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1190 1252
 		{
1191 1253
 			$value = $row['default_value'];
1192
-			foreach (explode(',', $row['field_options']) as $k => $v)
1193
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1254
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1255
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1194 1256
 					$value = $v;
1257
+			}
1195 1258
 		}
1196 1259
 		// Otherwise some form of text!
1197 1260
 		else
1198 1261
 		{
1199 1262
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1200
-			if ($row['field_length'])
1201
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			if ($row['field_length']) {
1264
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1265
+			}
1202 1266
 
1203 1267
 			// Any masks?
1204 1268
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1205 1269
 			{
1206 1270
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1207 1271
 				{
1208
-					if ($returnErrors)
1209
-						$errors[] = 'custom_field_mail_fail';
1210
-
1211
-					else
1212
-						$value = '';
1213
-				}
1214
-				elseif ($row['mask'] == 'number')
1272
+					if ($returnErrors) {
1273
+											$errors[] = 'custom_field_mail_fail';
1274
+					} else {
1275
+											$value = '';
1276
+					}
1277
+				} elseif ($row['mask'] == 'number')
1215 1278
 				{
1216 1279
 					$value = (int) $value;
1217
-				}
1218
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1280
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1219 1281
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_regex_fail';
1222
-
1223
-					else
1224
-						$value = '';
1282
+					if ($returnErrors) {
1283
+											$errors[] = 'custom_field_regex_fail';
1284
+					} else {
1285
+											$value = '';
1286
+					}
1225 1287
 				}
1226 1288
 			}
1227 1289
 		}
@@ -1248,8 +1310,9 @@  discard block
 block discarded – undo
1248 1310
 	$hook_errors = array();
1249 1311
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1250 1312
 
1251
-	if (!empty($hook_errors) && is_array($hook_errors))
1252
-		$errors = array_merge($errors, $hook_errors);
1313
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1314
+			$errors = array_merge($errors, $hook_errors);
1315
+	}
1253 1316
 
1254 1317
 	// Make those changes!
1255 1318
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1267,9 +1330,10 @@  discard block
 block discarded – undo
1267 1330
 		}
1268 1331
 	}
1269 1332
 
1270
-	if ($returnErrors)
1271
-		return $errors;
1272
-}
1333
+	if ($returnErrors) {
1334
+			return $errors;
1335
+	}
1336
+	}
1273 1337
 
1274 1338
 /**
1275 1339
  * Show all the users buddies, as well as a add/delete interface.
@@ -1281,8 +1345,9 @@  discard block
 block discarded – undo
1281 1345
 	global $context, $txt, $modSettings;
1282 1346
 
1283 1347
 	// Do a quick check to ensure people aren't getting here illegally!
1284
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1285
-		fatal_lang_error('no_access', false);
1348
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1349
+			fatal_lang_error('no_access', false);
1350
+	}
1286 1351
 
1287 1352
 	// Can we email the user direct?
1288 1353
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1312,9 +1377,10 @@  discard block
 block discarded – undo
1312 1377
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1313 1378
 	$call = call_helper($subActions[$context['list_area']][0], true);
1314 1379
 
1315
-	if (!empty($call))
1316
-		call_user_func($call, $memID);
1317
-}
1380
+	if (!empty($call)) {
1381
+			call_user_func($call, $memID);
1382
+	}
1383
+	}
1318 1384
 
1319 1385
 /**
1320 1386
  * Show all the users buddies, as well as a add/delete interface.
@@ -1328,9 +1394,10 @@  discard block
 block discarded – undo
1328 1394
 
1329 1395
 	// For making changes!
1330 1396
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1331
-	foreach ($buddiesArray as $k => $dummy)
1332
-		if ($dummy == '')
1397
+	foreach ($buddiesArray as $k => $dummy) {
1398
+			if ($dummy == '')
1333 1399
 			unset($buddiesArray[$k]);
1400
+	}
1334 1401
 
1335 1402
 	// Removing a buddy?
1336 1403
 	if (isset($_GET['remove']))
@@ -1342,10 +1409,11 @@  discard block
 block discarded – undo
1342 1409
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1343 1410
 
1344 1411
 		// Heh, I'm lazy, do it the easy way...
1345
-		foreach ($buddiesArray as $key => $buddy)
1346
-			if ($buddy == (int) $_GET['remove'])
1412
+		foreach ($buddiesArray as $key => $buddy) {
1413
+					if ($buddy == (int) $_GET['remove'])
1347 1414
 			{
1348 1415
 				unset($buddiesArray[$key]);
1416
+		}
1349 1417
 				$_SESSION['prf-save'] = true;
1350 1418
 			}
1351 1419
 
@@ -1355,8 +1423,7 @@  discard block
 block discarded – undo
1355 1423
 
1356 1424
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1357 1425
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1358
-	}
1359
-	elseif (isset($_POST['new_buddy']))
1426
+	} elseif (isset($_POST['new_buddy']))
1360 1427
 	{
1361 1428
 		checkSession();
1362 1429
 
@@ -1369,8 +1436,9 @@  discard block
 block discarded – undo
1369 1436
 		{
1370 1437
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1371 1438
 
1372
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1373
-				unset($new_buddies[$k]);
1439
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1440
+							unset($new_buddies[$k]);
1441
+			}
1374 1442
 		}
1375 1443
 
1376 1444
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1390,16 +1458,18 @@  discard block
 block discarded – undo
1390 1458
 				)
1391 1459
 			);
1392 1460
 
1393
-			if ($smcFunc['db_num_rows']($request) != 0)
1394
-				$_SESSION['prf-save'] = true;
1461
+			if ($smcFunc['db_num_rows']($request) != 0) {
1462
+							$_SESSION['prf-save'] = true;
1463
+			}
1395 1464
 
1396 1465
 			// Add the new member to the buddies array.
1397 1466
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1398 1467
 			{
1399
-				if (in_array($row['id_member'], $buddiesArray))
1400
-					continue;
1401
-				else
1402
-					$buddiesArray[] = (int) $row['id_member'];
1468
+				if (in_array($row['id_member'], $buddiesArray)) {
1469
+									continue;
1470
+				} else {
1471
+									$buddiesArray[] = (int) $row['id_member'];
1472
+				}
1403 1473
 			}
1404 1474
 			$smcFunc['db_free_result']($request);
1405 1475
 
@@ -1429,18 +1499,20 @@  discard block
 block discarded – undo
1429 1499
 
1430 1500
 	$context['custom_pf'] = array();
1431 1501
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1432
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1433
-		if (!isset($disabled_fields[$row['col_name']]))
1502
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1503
+			if (!isset($disabled_fields[$row['col_name']]))
1434 1504
 			$context['custom_pf'][$row['col_name']] = array(
1435 1505
 				'label' => $row['field_name'],
1436 1506
 				'type' => $row['field_type'],
1437 1507
 				'bbc' => !empty($row['bbc']),
1438 1508
 				'enclose' => $row['enclose'],
1439 1509
 			);
1510
+	}
1440 1511
 
1441 1512
 	// Gotta disable the gender option.
1442
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1443
-		unset($context['custom_pf']['cust_gender']);
1513
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1514
+			unset($context['custom_pf']['cust_gender']);
1515
+	}
1444 1516
 
1445 1517
 	$smcFunc['db_free_result']($request);
1446 1518
 
@@ -1457,8 +1529,9 @@  discard block
 block discarded – undo
1457 1529
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1458 1530
 			)
1459 1531
 		);
1460
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1461
-			$buddies[] = $row['id_member'];
1532
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1533
+					$buddies[] = $row['id_member'];
1534
+		}
1462 1535
 		$smcFunc['db_free_result']($result);
1463 1536
 	}
1464 1537
 
@@ -1486,30 +1559,32 @@  discard block
 block discarded – undo
1486 1559
 					continue;
1487 1560
 				}
1488 1561
 
1489
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1490
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1491
-
1492
-				elseif ($column['type'] == 'check')
1493
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1563
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1564
+				} elseif ($column['type'] == 'check') {
1565
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1566
+				}
1494 1567
 
1495 1568
 				// Enclosing the user input within some other text?
1496
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1497
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1569
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1570
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1498 1571
 						'{SCRIPTURL}' => $scripturl,
1499 1572
 						'{IMAGES_URL}' => $settings['images_url'],
1500 1573
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1501 1574
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1502 1575
 					));
1576
+				}
1503 1577
 			}
1504 1578
 		}
1505 1579
 	}
1506 1580
 
1507 1581
 	if (isset($_SESSION['prf-save']))
1508 1582
 	{
1509
-		if ($_SESSION['prf-save'] === true)
1510
-			$context['saved_successful'] = true;
1511
-		else
1512
-			$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		if ($_SESSION['prf-save'] === true) {
1584
+					$context['saved_successful'] = true;
1585
+		} else {
1586
+					$context['saved_failed'] = $_SESSION['prf-save'];
1587
+		}
1513 1588
 
1514 1589
 		unset($_SESSION['prf-save']);
1515 1590
 	}
@@ -1529,9 +1604,10 @@  discard block
 block discarded – undo
1529 1604
 
1530 1605
 	// For making changes!
1531 1606
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1532
-	foreach ($ignoreArray as $k => $dummy)
1533
-		if ($dummy == '')
1607
+	foreach ($ignoreArray as $k => $dummy) {
1608
+			if ($dummy == '')
1534 1609
 			unset($ignoreArray[$k]);
1610
+	}
1535 1611
 
1536 1612
 	// Removing a member from the ignore list?
1537 1613
 	if (isset($_GET['remove']))
@@ -1541,10 +1617,11 @@  discard block
 block discarded – undo
1541 1617
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1542 1618
 
1543 1619
 		// Heh, I'm lazy, do it the easy way...
1544
-		foreach ($ignoreArray as $key => $id_remove)
1545
-			if ($id_remove == (int) $_GET['remove'])
1620
+		foreach ($ignoreArray as $key => $id_remove) {
1621
+					if ($id_remove == (int) $_GET['remove'])
1546 1622
 			{
1547 1623
 				unset($ignoreArray[$key]);
1624
+		}
1548 1625
 				$_SESSION['prf-save'] = true;
1549 1626
 			}
1550 1627
 
@@ -1554,8 +1631,7 @@  discard block
 block discarded – undo
1554 1631
 
1555 1632
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1556 1633
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1557
-	}
1558
-	elseif (isset($_POST['new_ignore']))
1634
+	} elseif (isset($_POST['new_ignore']))
1559 1635
 	{
1560 1636
 		checkSession();
1561 1637
 		// Prepare the string for extraction...
@@ -1567,8 +1643,9 @@  discard block
 block discarded – undo
1567 1643
 		{
1568 1644
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1569 1645
 
1570
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1571
-				unset($new_entries[$k]);
1646
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1647
+							unset($new_entries[$k]);
1648
+			}
1572 1649
 		}
1573 1650
 
1574 1651
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1586,16 +1663,18 @@  discard block
 block discarded – undo
1586 1663
 				)
1587 1664
 			);
1588 1665
 
1589
-			if ($smcFunc['db_num_rows']($request) != 0)
1590
-				$_SESSION['prf-save'] = true;
1666
+			if ($smcFunc['db_num_rows']($request) != 0) {
1667
+							$_SESSION['prf-save'] = true;
1668
+			}
1591 1669
 
1592 1670
 			// Add the new member to the buddies array.
1593 1671
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1672
 			{
1595
-				if (in_array($row['id_member'], $ignoreArray))
1596
-					continue;
1597
-				else
1598
-					$ignoreArray[] = (int) $row['id_member'];
1673
+				if (in_array($row['id_member'], $ignoreArray)) {
1674
+									continue;
1675
+				} else {
1676
+									$ignoreArray[] = (int) $row['id_member'];
1677
+				}
1599 1678
 			}
1600 1679
 			$smcFunc['db_free_result']($request);
1601 1680
 
@@ -1624,8 +1703,9 @@  discard block
 block discarded – undo
1624 1703
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1625 1704
 			)
1626 1705
 		);
1627
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1628
-			$ignored[] = $row['id_member'];
1706
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1707
+					$ignored[] = $row['id_member'];
1708
+		}
1629 1709
 		$smcFunc['db_free_result']($result);
1630 1710
 	}
1631 1711
 
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 
1645 1725
 	if (isset($_SESSION['prf-save']))
1646 1726
 	{
1647
-		if ($_SESSION['prf-save'] === true)
1648
-			$context['saved_successful'] = true;
1649
-		else
1650
-			$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		if ($_SESSION['prf-save'] === true) {
1728
+					$context['saved_successful'] = true;
1729
+		} else {
1730
+					$context['saved_failed'] = $_SESSION['prf-save'];
1731
+		}
1651 1732
 
1652 1733
 		unset($_SESSION['prf-save']);
1653 1734
 	}
@@ -1663,8 +1744,9 @@  discard block
 block discarded – undo
1663 1744
 	global $context, $txt;
1664 1745
 
1665 1746
 	loadThemeOptions($memID);
1666
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1667
-		loadCustomFields($memID, 'account');
1747
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1748
+			loadCustomFields($memID, 'account');
1749
+	}
1668 1750
 
1669 1751
 	$context['sub_template'] = 'edit_options';
1670 1752
 	$context['page_desc'] = $txt['account_info'];
@@ -1691,8 +1773,9 @@  discard block
 block discarded – undo
1691 1773
 	global $context, $txt;
1692 1774
 
1693 1775
 	loadThemeOptions($memID);
1694
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1695
-		loadCustomFields($memID, 'forumprofile');
1776
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1777
+			loadCustomFields($memID, 'forumprofile');
1778
+	}
1696 1779
 
1697 1780
 	$context['sub_template'] = 'edit_options';
1698 1781
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1725,18 +1808,21 @@  discard block
 block discarded – undo
1725 1808
 	$dirs = array();
1726 1809
 	$files = array();
1727 1810
 
1728
-	if (!$dir)
1729
-		return array();
1811
+	if (!$dir) {
1812
+			return array();
1813
+	}
1730 1814
 
1731 1815
 	while ($line = $dir->read())
1732 1816
 	{
1733
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1734
-			continue;
1817
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1818
+					continue;
1819
+		}
1735 1820
 
1736
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1737
-			$dirs[] = $line;
1738
-		else
1739
-			$files[] = $line;
1821
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1822
+					$dirs[] = $line;
1823
+		} else {
1824
+					$files[] = $line;
1825
+		}
1740 1826
 	}
1741 1827
 	$dir->close();
1742 1828
 
@@ -1757,14 +1843,15 @@  discard block
 block discarded – undo
1757 1843
 	foreach ($dirs as $line)
1758 1844
 	{
1759 1845
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1760
-		if (!empty($tmp))
1761
-			$result[] = array(
1846
+		if (!empty($tmp)) {
1847
+					$result[] = array(
1762 1848
 				'filename' => $smcFunc['htmlspecialchars']($line),
1763 1849
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1764 1850
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1765 1851
 				'is_dir' => true,
1766 1852
 				'files' => $tmp
1767 1853
 		);
1854
+		}
1768 1855
 		unset($tmp);
1769 1856
 	}
1770 1857
 
@@ -1774,8 +1861,9 @@  discard block
 block discarded – undo
1774 1861
 		$extension = substr(strrchr($line, '.'), 1);
1775 1862
 
1776 1863
 		// Make sure it is an image.
1777
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1778
-			continue;
1864
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1865
+					continue;
1866
+		}
1779 1867
 
1780 1868
 		$result[] = array(
1781 1869
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1783,8 +1871,9 @@  discard block
 block discarded – undo
1783 1871
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1784 1872
 			'is_dir' => false
1785 1873
 		);
1786
-		if ($level == 1)
1787
-			$context['avatar_list'][] = $directory . '/' . $line;
1874
+		if ($level == 1) {
1875
+					$context['avatar_list'][] = $directory . '/' . $line;
1876
+		}
1788 1877
 	}
1789 1878
 
1790 1879
 	return $result;
@@ -1800,8 +1889,9 @@  discard block
 block discarded – undo
1800 1889
 	global $txt, $context;
1801 1890
 
1802 1891
 	loadThemeOptions($memID);
1803
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1804
-		loadCustomFields($memID, 'theme');
1892
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1893
+			loadCustomFields($memID, 'theme');
1894
+	}
1805 1895
 
1806 1896
 	$context['sub_template'] = 'edit_options';
1807 1897
 	$context['page_desc'] = $txt['theme_info'];
@@ -1855,16 +1945,19 @@  discard block
 block discarded – undo
1855 1945
 {
1856 1946
 	global $txt, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;
1857 1947
 
1858
-	if (!isset($context['token_check']))
1859
-		$context['token_check'] = 'profile-nt' . $memID;
1948
+	if (!isset($context['token_check'])) {
1949
+			$context['token_check'] = 'profile-nt' . $memID;
1950
+	}
1860 1951
 
1861 1952
 	is_not_guest();
1862
-	if (!$context['user']['is_owner'])
1863
-		isAllowedTo('profile_extra_any');
1953
+	if (!$context['user']['is_owner']) {
1954
+			isAllowedTo('profile_extra_any');
1955
+	}
1864 1956
 
1865 1957
 	// Set the post action if we're coming from the profile...
1866
-	if (!isset($context['action']))
1867
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1958
+	if (!isset($context['action'])) {
1959
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1960
+	}
1868 1961
 
1869 1962
 	// What options are set
1870 1963
 	loadThemeOptions($memID);
@@ -1951,28 +2044,34 @@  discard block
 block discarded – undo
1951 2044
 	);
1952 2045
 
1953 2046
 	// There are certain things that are disabled at the group level.
1954
-	if (empty($modSettings['cal_enabled']))
1955
-		unset($alert_types['calendar']);
2047
+	if (empty($modSettings['cal_enabled'])) {
2048
+			unset($alert_types['calendar']);
2049
+	}
1956 2050
 
1957 2051
 	// Disable paid subscriptions at group level if they're disabled
1958
-	if (empty($modSettings['paid_enabled']))
1959
-		unset($alert_types['paidsubs']);
2052
+	if (empty($modSettings['paid_enabled'])) {
2053
+			unset($alert_types['paidsubs']);
2054
+	}
1960 2055
 
1961 2056
 	// Disable membergroup requests at group level if they're disabled
1962
-	if (empty($modSettings['show_group_membership']))
1963
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2057
+	if (empty($modSettings['show_group_membership'])) {
2058
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2059
+	}
1964 2060
 
1965 2061
 	// Disable mentions if they're disabled
1966
-	if (empty($modSettings['enable_mentions']))
1967
-		unset($alert_types['msg']['msg_mention']);
2062
+	if (empty($modSettings['enable_mentions'])) {
2063
+			unset($alert_types['msg']['msg_mention']);
2064
+	}
1968 2065
 
1969 2066
 	// Disable likes if they're disabled
1970
-	if (empty($modSettings['enable_likes']))
1971
-		unset($alert_types['msg']['msg_like']);
2067
+	if (empty($modSettings['enable_likes'])) {
2068
+			unset($alert_types['msg']['msg_like']);
2069
+	}
1972 2070
 
1973 2071
 	// Disable buddy requests if they're disabled
1974
-	if (empty($modSettings['enable_buddylist']))
1975
-		unset($alert_types['members']['buddy_request']);
2072
+	if (empty($modSettings['enable_buddylist'])) {
2073
+			unset($alert_types['members']['buddy_request']);
2074
+	}
1976 2075
 
1977 2076
 	// Now, now, we could pass this through global but we should really get into the habit of
1978 2077
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2000,15 +2099,17 @@  discard block
 block discarded – undo
2000 2099
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2001 2100
 		}
2002 2101
 
2003
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2004
-			unset($alert_types['members']['request_group']);
2102
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2103
+					unset($alert_types['members']['request_group']);
2104
+		}
2005 2105
 
2006 2106
 		foreach ($alert_types as $group => $items)
2007 2107
 		{
2008 2108
 			foreach ($items as $alert_key => $alert_value)
2009 2109
 			{
2010
-				if (!isset($alert_value['permission']))
2011
-					continue;
2110
+				if (!isset($alert_value['permission'])) {
2111
+									continue;
2112
+				}
2012 2113
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2013 2114
 				{
2014 2115
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2016,12 +2117,14 @@  discard block
 block discarded – undo
2016 2117
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2017 2118
 				}
2018 2119
 
2019
-				if (!$perms_cache[$alert_value['permission']['name']])
2020
-					unset ($alert_types[$group][$alert_key]);
2120
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2121
+									unset ($alert_types[$group][$alert_key]);
2122
+				}
2021 2123
 			}
2022 2124
 
2023
-			if (empty($alert_types[$group]))
2024
-				unset ($alert_types[$group]);
2125
+			if (empty($alert_types[$group])) {
2126
+							unset ($alert_types[$group]);
2127
+			}
2025 2128
 		}
2026 2129
 	}
2027 2130
 
@@ -2053,9 +2156,9 @@  discard block
 block discarded – undo
2053 2156
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2054 2157
 						break;
2055 2158
 					case 'select':
2056
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2057
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2058
-						else
2159
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2160
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2161
+						} else
2059 2162
 						{
2060 2163
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2061 2164
 							$keys = array_keys($this_option['opts']);
@@ -2075,23 +2178,28 @@  discard block
 block discarded – undo
2075 2178
 				$this_value = 0;
2076 2179
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2077 2180
 				{
2078
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2079
-						$this_value |= $bitvalue;
2181
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2182
+											$this_value |= $bitvalue;
2183
+					}
2184
+				}
2185
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2186
+									$update_prefs[$item_key] = $this_value;
2080 2187
 				}
2081
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2082
-					$update_prefs[$item_key] = $this_value;
2083 2188
 			}
2084 2189
 		}
2085 2190
 
2086
-		if (!empty($_POST['opt_alert_timeout']))
2087
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2191
+		if (!empty($_POST['opt_alert_timeout'])) {
2192
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2193
+		}
2088 2194
 
2089
-		if (!empty($_POST['notify_announcements']))
2090
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2195
+		if (!empty($_POST['notify_announcements'])) {
2196
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2197
+		}
2091 2198
 
2092 2199
 		setNotifyPrefs((int) $memID, $update_prefs);
2093
-		foreach ($update_prefs as $pref => $value)
2094
-			$context['alert_prefs'][$pref] = $value;
2200
+		foreach ($update_prefs as $pref => $value) {
2201
+					$context['alert_prefs'][$pref] = $value;
2202
+		}
2095 2203
 
2096 2204
 		makeNotificationChanges($memID);
2097 2205
 
@@ -2121,8 +2229,9 @@  discard block
 block discarded – undo
2121 2229
 
2122 2230
 	// Now we're all set up.
2123 2231
 	is_not_guest();
2124
-	if (!$context['user']['is_owner'])
2125
-		fatal_error('no_access');
2232
+	if (!$context['user']['is_owner']) {
2233
+			fatal_error('no_access');
2234
+	}
2126 2235
 
2127 2236
 	checkSession('get');
2128 2237
 
@@ -2154,8 +2263,9 @@  discard block
 block discarded – undo
2154 2263
 {
2155 2264
 	global $smcFunc;
2156 2265
 
2157
-	if (empty($toMark) || empty($memID))
2158
-		return false;
2266
+	if (empty($toMark) || empty($memID)) {
2267
+			return false;
2268
+	}
2159 2269
 
2160 2270
 	$toMark = (array) $toMark;
2161 2271
 	$count = 0;
@@ -2190,8 +2300,9 @@  discard block
 block discarded – undo
2190 2300
 {
2191 2301
 	global $smcFunc;
2192 2302
 
2193
-	if (empty($toDelete))
2194
-		return false;
2303
+	if (empty($toDelete)) {
2304
+			return false;
2305
+	}
2195 2306
 
2196 2307
 	$toDelete = (array) $toDelete;
2197 2308
 
@@ -2226,8 +2337,9 @@  discard block
 block discarded – undo
2226 2337
 {
2227 2338
 	global $smcFunc;
2228 2339
 
2229
-	if (empty($memID))
2230
-		return false;
2340
+	if (empty($memID)) {
2341
+			return false;
2342
+	}
2231 2343
 
2232 2344
 	$count = 0;
2233 2345
 
@@ -2306,8 +2418,9 @@  discard block
 block discarded – undo
2306 2418
 					{
2307 2419
 						$link = $topic['link'];
2308 2420
 
2309
-						if ($topic['new'])
2310
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2421
+						if ($topic['new']) {
2422
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2423
+						}
2311 2424
 
2312 2425
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2313 2426
 
@@ -2458,8 +2571,9 @@  discard block
 block discarded – undo
2458 2571
 					{
2459 2572
 						$link = $board['link'];
2460 2573
 
2461
-						if ($board['new'])
2462
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2574
+						if ($board['new']) {
2575
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2576
+						}
2463 2577
 
2464 2578
 						return $link;
2465 2579
 					},
@@ -2659,8 +2773,8 @@  discard block
 block discarded – undo
2659 2773
 		)
2660 2774
 	);
2661 2775
 	$notification_boards = array();
2662
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2663
-		$notification_boards[] = array(
2776
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2777
+			$notification_boards[] = array(
2664 2778
 			'id' => $row['id_board'],
2665 2779
 			'name' => $row['name'],
2666 2780
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2668,6 +2782,7 @@  discard block
 block discarded – undo
2668 2782
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2669 2783
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2670 2784
 		);
2785
+	}
2671 2786
 	$smcFunc['db_free_result']($request);
2672 2787
 
2673 2788
 	return $notification_boards;
@@ -2682,17 +2797,18 @@  discard block
 block discarded – undo
2682 2797
 {
2683 2798
 	global $context, $options, $cur_profile, $smcFunc;
2684 2799
 
2685
-	if (isset($_POST['default_options']))
2686
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2800
+	if (isset($_POST['default_options'])) {
2801
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2802
+	}
2687 2803
 
2688 2804
 	if ($context['user']['is_owner'])
2689 2805
 	{
2690 2806
 		$context['member']['options'] = $options;
2691
-		if (isset($_POST['options']) && is_array($_POST['options']))
2692
-			foreach ($_POST['options'] as $k => $v)
2807
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2808
+					foreach ($_POST['options'] as $k => $v)
2693 2809
 				$context['member']['options'][$k] = $v;
2694
-	}
2695
-	else
2810
+		}
2811
+	} else
2696 2812
 	{
2697 2813
 		$request = $smcFunc['db_query']('', '
2698 2814
 			SELECT id_member, variable, value
@@ -2713,8 +2829,9 @@  discard block
 block discarded – undo
2713 2829
 				continue;
2714 2830
 			}
2715 2831
 
2716
-			if (isset($_POST['options'][$row['variable']]))
2717
-				$row['value'] = $_POST['options'][$row['variable']];
2832
+			if (isset($_POST['options'][$row['variable']])) {
2833
+							$row['value'] = $_POST['options'][$row['variable']];
2834
+			}
2718 2835
 			$context['member']['options'][$row['variable']] = $row['value'];
2719 2836
 		}
2720 2837
 		$smcFunc['db_free_result']($request);
@@ -2722,8 +2839,9 @@  discard block
 block discarded – undo
2722 2839
 		// Load up the default theme options for any missing.
2723 2840
 		foreach ($temp as $k => $v)
2724 2841
 		{
2725
-			if (!isset($context['member']['options'][$k]))
2726
-				$context['member']['options'][$k] = $v;
2842
+			if (!isset($context['member']['options'][$k])) {
2843
+							$context['member']['options'][$k] = $v;
2844
+			}
2727 2845
 		}
2728 2846
 	}
2729 2847
 }
@@ -2738,8 +2856,9 @@  discard block
 block discarded – undo
2738 2856
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2739 2857
 
2740 2858
 	// Have the admins enabled this option?
2741
-	if (empty($modSettings['allow_ignore_boards']))
2742
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2859
+	if (empty($modSettings['allow_ignore_boards'])) {
2860
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2861
+	}
2743 2862
 
2744 2863
 	// Find all the boards this user is allowed to see.
2745 2864
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2759,12 +2878,13 @@  discard block
 block discarded – undo
2759 2878
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2760 2879
 	{
2761 2880
 		// This category hasn't been set up yet..
2762
-		if (!isset($context['categories'][$row['id_cat']]))
2763
-			$context['categories'][$row['id_cat']] = array(
2881
+		if (!isset($context['categories'][$row['id_cat']])) {
2882
+					$context['categories'][$row['id_cat']] = array(
2764 2883
 				'id' => $row['id_cat'],
2765 2884
 				'name' => $row['cat_name'],
2766 2885
 				'boards' => array()
2767 2886
 			);
2887
+		}
2768 2888
 
2769 2889
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2770 2890
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2794,18 +2914,20 @@  discard block
 block discarded – undo
2794 2914
 	}
2795 2915
 
2796 2916
 	$max_boards = ceil(count($temp_boards) / 2);
2797
-	if ($max_boards == 1)
2798
-		$max_boards = 2;
2917
+	if ($max_boards == 1) {
2918
+			$max_boards = 2;
2919
+	}
2799 2920
 
2800 2921
 	// Now, alternate them so they can be shown left and right ;).
2801 2922
 	$context['board_columns'] = array();
2802 2923
 	for ($i = 0; $i < $max_boards; $i++)
2803 2924
 	{
2804 2925
 		$context['board_columns'][] = $temp_boards[$i];
2805
-		if (isset($temp_boards[$i + $max_boards]))
2806
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2807
-		else
2808
-			$context['board_columns'][] = array();
2926
+		if (isset($temp_boards[$i + $max_boards])) {
2927
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2928
+		} else {
2929
+					$context['board_columns'][] = array();
2930
+		}
2809 2931
 	}
2810 2932
 
2811 2933
 	loadThemeOptions($memID);
@@ -2874,8 +2996,9 @@  discard block
 block discarded – undo
2874 2996
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2875 2997
 	{
2876 2998
 		// We should skip the administrator group if they don't have the admin_forum permission!
2877
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2878
-			continue;
2999
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3000
+					continue;
3001
+		}
2879 3002
 
2880 3003
 		$context['member_groups'][$row['id_group']] = array(
2881 3004
 			'id' => $row['id_group'],
@@ -2921,16 +3044,17 @@  discard block
 block discarded – undo
2921 3044
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2922 3045
 	// Warning message for signature image limits?
2923 3046
 	$context['signature_warning'] = '';
2924
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2925
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2926
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2927
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3047
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3048
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3049
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3050
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3051
+	}
2928 3052
 
2929 3053
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2930 3054
 
2931
-	if (empty($context['do_preview']))
2932
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2933
-	else
3055
+	if (empty($context['do_preview'])) {
3056
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3057
+	} else
2934 3058
 	{
2935 3059
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2936 3060
 		$validation = profileValidateSignature($signature);
@@ -2940,8 +3064,9 @@  discard block
 block discarded – undo
2940 3064
 			$context['post_errors'] = array();
2941 3065
 		}
2942 3066
 		$context['post_errors'][] = 'signature_not_yet_saved';
2943
-		if ($validation !== true && $validation !== false)
2944
-			$context['post_errors'][] = $validation;
3067
+		if ($validation !== true && $validation !== false) {
3068
+					$context['post_errors'][] = $validation;
3069
+		}
2945 3070
 
2946 3071
 		censorText($context['member']['signature']);
2947 3072
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2951,8 +3076,9 @@  discard block
 block discarded – undo
2951 3076
 	}
2952 3077
 
2953 3078
 	// Load the spell checker?
2954
-	if ($context['show_spellchecking'])
2955
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3079
+	if ($context['show_spellchecking']) {
3080
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3081
+	}
2956 3082
 
2957 3083
 	return true;
2958 3084
 }
@@ -2986,8 +3112,7 @@  discard block
 block discarded – undo
2986 3112
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2987 3113
 		);
2988 3114
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2989
-	}
2990
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3115
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2991 3116
 	{
2992 3117
 		$context['member']['avatar'] += array(
2993 3118
 			'choice' => 'upload',
@@ -2995,34 +3120,34 @@  discard block
 block discarded – undo
2995 3120
 			'external' => 'http://'
2996 3121
 		);
2997 3122
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2998
-	}
2999
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3000
-		$context['member']['avatar'] += array(
3123
+	} elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3124
+			$context['member']['avatar'] += array(
3001 3125
 			'choice' => 'external',
3002 3126
 			'server_pic' => 'blank.png',
3003 3127
 			'external' => $cur_profile['avatar']
3004 3128
 		);
3005
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3006
-		$context['member']['avatar'] += array(
3129
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3130
+			$context['member']['avatar'] += array(
3007 3131
 			'choice' => 'server_stored',
3008 3132
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3009 3133
 			'external' => 'http://'
3010 3134
 		);
3011
-	else
3012
-		$context['member']['avatar'] += array(
3135
+	} else {
3136
+			$context['member']['avatar'] += array(
3013 3137
 			'choice' => 'none',
3014 3138
 			'server_pic' => 'blank.png',
3015 3139
 			'external' => 'http://'
3016 3140
 		);
3141
+	}
3017 3142
 
3018 3143
 	// Get a list of all the avatars.
3019 3144
 	if ($context['member']['avatar']['allow_server_stored'])
3020 3145
 	{
3021 3146
 		$context['avatar_list'] = array();
3022 3147
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3148
+	} else {
3149
+			$context['avatars'] = array();
3023 3150
 	}
3024
-	else
3025
-		$context['avatars'] = array();
3026 3151
 
3027 3152
 	// Second level selected avatar...
3028 3153
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3051,19 +3176,22 @@  discard block
 block discarded – undo
3051 3176
 			)
3052 3177
 		);
3053 3178
 		$protected_groups = array(1);
3054
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3055
-			$protected_groups[] = $row['id_group'];
3179
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3180
+					$protected_groups[] = $row['id_group'];
3181
+		}
3056 3182
 		$smcFunc['db_free_result']($request);
3057 3183
 
3058 3184
 		$protected_groups = array_unique($protected_groups);
3059 3185
 	}
3060 3186
 
3061 3187
 	// The account page allows the change of your id_group - but not to a protected group!
3062
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3063
-		$value = (int) $value;
3188
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3189
+			$value = (int) $value;
3190
+	}
3064 3191
 	// ... otherwise it's the old group sir.
3065
-	else
3066
-		$value = $old_profile['id_group'];
3192
+	else {
3193
+			$value = $old_profile['id_group'];
3194
+	}
3067 3195
 
3068 3196
 	// Find the additional membergroups (if any)
3069 3197
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3072,16 +3200,18 @@  discard block
 block discarded – undo
3072 3200
 		foreach ($_POST['additional_groups'] as $group_id)
3073 3201
 		{
3074 3202
 			$group_id = (int) $group_id;
3075
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3076
-				$additional_groups[] = $group_id;
3203
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3204
+							$additional_groups[] = $group_id;
3205
+			}
3077 3206
 		}
3078 3207
 
3079 3208
 		// Put the protected groups back in there if you don't have permission to take them away.
3080 3209
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3081 3210
 		foreach ($old_additional_groups as $group_id)
3082 3211
 		{
3083
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3084
-				$additional_groups[] = $group_id;
3212
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3213
+							$additional_groups[] = $group_id;
3214
+			}
3085 3215
 		}
3086 3216
 
3087 3217
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3113,18 +3243,20 @@  discard block
 block discarded – undo
3113 3243
 			list ($another) = $smcFunc['db_fetch_row']($request);
3114 3244
 			$smcFunc['db_free_result']($request);
3115 3245
 
3116
-			if (empty($another))
3117
-				fatal_lang_error('at_least_one_admin', 'critical');
3246
+			if (empty($another)) {
3247
+							fatal_lang_error('at_least_one_admin', 'critical');
3248
+			}
3118 3249
 		}
3119 3250
 	}
3120 3251
 
3121 3252
 	// If we are changing group status, update permission cache as necessary.
3122 3253
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3123 3254
 	{
3124
-		if ($context['user']['is_owner'])
3125
-			$_SESSION['mc']['time'] = 0;
3126
-		else
3127
-			updateSettings(array('settings_updated' => time()));
3255
+		if ($context['user']['is_owner']) {
3256
+					$_SESSION['mc']['time'] = 0;
3257
+		} else {
3258
+					updateSettings(array('settings_updated' => time()));
3259
+		}
3128 3260
 	}
3129 3261
 
3130 3262
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3145,8 +3277,9 @@  discard block
 block discarded – undo
3145 3277
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3146 3278
 
3147 3279
 	$memID = $context['id_member'];
3148
-	if (empty($memID) && !empty($context['password_auth_failed']))
3149
-		return false;
3280
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3281
+			return false;
3282
+	}
3150 3283
 
3151 3284
 	require_once($sourcedir . '/ManageAttachments.php');
3152 3285
 
@@ -3157,8 +3290,9 @@  discard block
 block discarded – undo
3157 3290
 	$downloadedExternalAvatar = false;
3158 3291
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3159 3292
 	{
3160
-		if (!is_writable($uploadDir))
3161
-			fatal_lang_error('attachments_no_write', 'critical');
3293
+		if (!is_writable($uploadDir)) {
3294
+					fatal_lang_error('attachments_no_write', 'critical');
3295
+		}
3162 3296
 
3163 3297
 		require_once($sourcedir . '/Subs-Package.php');
3164 3298
 
@@ -3202,19 +3336,18 @@  discard block
 block discarded – undo
3202 3336
 
3203 3337
 		// Get rid of their old avatar. (if uploaded.)
3204 3338
 		removeAttachments(array('id_member' => $memID));
3205
-	}
3206
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3339
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3207 3340
 	{
3208 3341
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3209
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3210
-			$profile_vars['avatar'] = 'gravatar://';
3211
-		else
3212
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3342
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3343
+					$profile_vars['avatar'] = 'gravatar://';
3344
+		} else {
3345
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3346
+		}
3213 3347
 
3214 3348
 		// Get rid of their old avatar. (if uploaded.)
3215 3349
 		removeAttachments(array('id_member' => $memID));
3216
-	}
3217
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3350
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3218 3351
 	{
3219 3352
 		// We need these clean...
3220 3353
 		$cur_profile['id_attach'] = 0;
@@ -3226,11 +3359,13 @@  discard block
 block discarded – undo
3226 3359
 
3227 3360
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3228 3361
 
3229
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3230
-			$profile_vars['avatar'] = '';
3362
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3363
+					$profile_vars['avatar'] = '';
3364
+		}
3231 3365
 		// Trying to make us do something we'll regret?
3232
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3233
-			return 'bad_avatar_invalid_url';
3366
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3367
+					return 'bad_avatar_invalid_url';
3368
+		}
3234 3369
 		// Should we check dimensions?
3235 3370
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3236 3371
 		{
@@ -3240,9 +3375,9 @@  discard block
 block discarded – undo
3240 3375
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3241 3376
 			{
3242 3377
 				// Houston, we have a problem. The avatar is too large!!
3243
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3244
-					return 'bad_avatar_too_large';
3245
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3378
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3379
+									return 'bad_avatar_too_large';
3380
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3246 3381
 				{
3247 3382
 					// @todo remove this if appropriate
3248 3383
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3252,26 +3387,27 @@  discard block
 block discarded – undo
3252 3387
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3253 3388
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3254 3389
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3390
+					} else {
3391
+											return 'bad_avatar';
3255 3392
 					}
3256
-					else
3257
-						return 'bad_avatar';
3258 3393
 				}
3259 3394
 			}
3260 3395
 		}
3261
-	}
3262
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3396
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3263 3397
 	{
3264 3398
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3265 3399
 		{
3266 3400
 			// Get the dimensions of the image.
3267 3401
 			if (!$downloadedExternalAvatar)
3268 3402
 			{
3269
-				if (!is_writable($uploadDir))
3270
-					fatal_lang_error('attachments_no_write', 'critical');
3403
+				if (!is_writable($uploadDir)) {
3404
+									fatal_lang_error('attachments_no_write', 'critical');
3405
+				}
3271 3406
 
3272 3407
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3273
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3274
-					fatal_lang_error('attach_timeout', 'critical');
3408
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3409
+									fatal_lang_error('attach_timeout', 'critical');
3410
+				}
3275 3411
 
3276 3412
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3277 3413
 			}
@@ -3384,17 +3520,19 @@  discard block
 block discarded – undo
3384 3520
 			$profile_vars['avatar'] = '';
3385 3521
 
3386 3522
 			// Delete any temporary file.
3387
-			if (file_exists($_FILES['attachment']['tmp_name']))
3388
-				@unlink($_FILES['attachment']['tmp_name']);
3523
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3524
+							@unlink($_FILES['attachment']['tmp_name']);
3525
+			}
3389 3526
 		}
3390 3527
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3391
-		else
3528
+		else {
3529
+					$profile_vars['avatar'] = '';
3530
+		}
3531
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3532
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3533
+	} else {
3392 3534
 			$profile_vars['avatar'] = '';
3393 3535
 	}
3394
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3395
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3396
-	else
3397
-		$profile_vars['avatar'] = '';
3398 3536
 
3399 3537
 	// Setup the profile variables so it shows things right on display!
3400 3538
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3442,9 +3580,9 @@  discard block
 block discarded – undo
3442 3580
 		$smiley_parsed = $unparsed_signature;
3443 3581
 		parsesmileys($smiley_parsed);
3444 3582
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3445
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3446
-			return 'signature_allow_smileys';
3447
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3583
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3584
+					return 'signature_allow_smileys';
3585
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3448 3586
 		{
3449 3587
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3450 3588
 			return 'signature_max_smileys';
@@ -3457,14 +3595,15 @@  discard block
 block discarded – undo
3457 3595
 			{
3458 3596
 				$limit_broke = 0;
3459 3597
 				// Attempt to allow all sizes of abuse, so to speak.
3460
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3461
-					$limit_broke = $sig_limits[7] . 'px';
3462
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3463
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3464
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3465
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3466
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3467
-					$limit_broke = 'large';
3598
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3599
+									$limit_broke = $sig_limits[7] . 'px';
3600
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3601
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3602
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3603
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3604
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3605
+									$limit_broke = 'large';
3606
+				}
3468 3607
 
3469 3608
 				if ($limit_broke)
3470 3609
 				{
@@ -3506,24 +3645,26 @@  discard block
 block discarded – undo
3506 3645
 					$width = -1; $height = -1;
3507 3646
 
3508 3647
 					// Does it have predefined restraints? Width first.
3509
-					if ($matches[6][$key])
3510
-						$matches[2][$key] = $matches[6][$key];
3648
+					if ($matches[6][$key]) {
3649
+											$matches[2][$key] = $matches[6][$key];
3650
+					}
3511 3651
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3512 3652
 					{
3513 3653
 						$width = $sig_limits[5];
3514 3654
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3655
+					} elseif ($matches[2][$key]) {
3656
+											$width = $matches[2][$key];
3515 3657
 					}
3516
-					elseif ($matches[2][$key])
3517
-						$width = $matches[2][$key];
3518 3658
 					// ... and height.
3519 3659
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3520 3660
 					{
3521 3661
 						$height = $sig_limits[6];
3522
-						if ($width != -1)
3523
-							$width = $width * ($height / $matches[4][$key]);
3662
+						if ($width != -1) {
3663
+													$width = $width * ($height / $matches[4][$key]);
3664
+						}
3665
+					} elseif ($matches[4][$key]) {
3666
+											$height = $matches[4][$key];
3524 3667
 					}
3525
-					elseif ($matches[4][$key])
3526
-						$height = $matches[4][$key];
3527 3668
 
3528 3669
 					// If the dimensions are still not fixed - we need to check the actual image.
3529 3670
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3541,21 +3682,24 @@  discard block
 block discarded – undo
3541 3682
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3542 3683
 							{
3543 3684
 								$height = $sig_limits[6];
3544
-								if ($width == -1)
3545
-									$width = $sizes[0];
3685
+								if ($width == -1) {
3686
+																	$width = $sizes[0];
3687
+								}
3546 3688
 								$width = $width * ($height / $sizes[1]);
3689
+							} elseif ($width != -1) {
3690
+															$height = $sizes[1];
3547 3691
 							}
3548
-							elseif ($width != -1)
3549
-								$height = $sizes[1];
3550 3692
 						}
3551 3693
 					}
3552 3694
 
3553 3695
 					// Did we come up with some changes? If so remake the string.
3554
-					if ($width != -1 || $height != -1)
3555
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					if ($width != -1 || $height != -1) {
3697
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3698
+					}
3699
+				}
3700
+				if (!empty($replaces)) {
3701
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3556 3702
 				}
3557
-				if (!empty($replaces))
3558
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3559 3703
 			}
3560 3704
 		}
3561 3705
 
@@ -3599,10 +3743,12 @@  discard block
 block discarded – undo
3599 3743
 	$email = strtr($email, array('&#039;' => '\''));
3600 3744
 
3601 3745
 	// Check the name and email for validity.
3602
-	if (trim($email) == '')
3603
-		return 'no_email';
3604
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3605
-		return 'bad_email';
3746
+	if (trim($email) == '') {
3747
+			return 'no_email';
3748
+	}
3749
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3750
+			return 'bad_email';
3751
+	}
3606 3752
 
3607 3753
 	// Email addresses should be and stay unique.
3608 3754
 	$request = $smcFunc['db_query']('', '
@@ -3617,8 +3763,9 @@  discard block
 block discarded – undo
3617 3763
 		)
3618 3764
 	);
3619 3765
 
3620
-	if ($smcFunc['db_num_rows']($request) > 0)
3621
-		return 'email_taken';
3766
+	if ($smcFunc['db_num_rows']($request) > 0) {
3767
+			return 'email_taken';
3768
+	}
3622 3769
 	$smcFunc['db_free_result']($request);
3623 3770
 
3624 3771
 	return true;
@@ -3631,8 +3778,9 @@  discard block
 block discarded – undo
3631 3778
 {
3632 3779
 	global $modSettings, $context, $cur_profile;
3633 3780
 
3634
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3635
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3782
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3783
+	}
3636 3784
 
3637 3785
 	loadUserSettings();
3638 3786
 	writeLog();
@@ -3648,8 +3796,9 @@  discard block
 block discarded – undo
3648 3796
 	require_once($sourcedir . '/Subs-Post.php');
3649 3797
 
3650 3798
 	// Shouldn't happen but just in case.
3651
-	if (empty($profile_vars['email_address']))
3652
-		return;
3799
+	if (empty($profile_vars['email_address'])) {
3800
+			return;
3801
+	}
3653 3802
 
3654 3803
 	$replacements = array(
3655 3804
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3672,8 +3821,9 @@  discard block
 block discarded – undo
3672 3821
 	$_SESSION['log_time'] = 0;
3673 3822
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3674 3823
 
3675
-	if (isset($_COOKIE[$cookiename]))
3676
-		$_COOKIE[$cookiename] = '';
3824
+	if (isset($_COOKIE[$cookiename])) {
3825
+			$_COOKIE[$cookiename] = '';
3826
+	}
3677 3827
 
3678 3828
 	loadUserSettings();
3679 3829
 
@@ -3706,11 +3856,13 @@  discard block
 block discarded – undo
3706 3856
 	$groups[] = $curMember['id_group'];
3707 3857
 
3708 3858
 	// Ensure the query doesn't croak!
3709
-	if (empty($groups))
3710
-		$groups = array(0);
3859
+	if (empty($groups)) {
3860
+			$groups = array(0);
3861
+	}
3711 3862
 	// Just to be sure...
3712
-	foreach ($groups as $k => $v)
3713
-		$groups[$k] = (int) $v;
3863
+	foreach ($groups as $k => $v) {
3864
+			$groups[$k] = (int) $v;
3865
+	}
3714 3866
 
3715 3867
 	// Get all the membergroups they can join.
3716 3868
 	$request = $smcFunc['db_query']('', '
@@ -3740,12 +3892,14 @@  discard block
 block discarded – undo
3740 3892
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3741 3893
 	{
3742 3894
 		// Can they edit their primary group?
3743
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3744
-			$context['can_edit_primary'] = true;
3895
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3896
+					$context['can_edit_primary'] = true;
3897
+		}
3745 3898
 
3746 3899
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3747
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3748
-			continue;
3900
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3901
+					continue;
3902
+		}
3749 3903
 
3750 3904
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3751 3905
 			'id' => $row['id_group'],
@@ -3774,13 +3928,15 @@  discard block
 block discarded – undo
3774 3928
 	);
3775 3929
 
3776 3930
 	// No changing primary one unless you have enough groups!
3777
-	if (count($context['groups']['member']) < 2)
3778
-		$context['can_edit_primary'] = false;
3931
+	if (count($context['groups']['member']) < 2) {
3932
+			$context['can_edit_primary'] = false;
3933
+	}
3779 3934
 
3780 3935
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3781
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3782
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3783
-}
3936
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3937
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3938
+	}
3939
+	}
3784 3940
 
3785 3941
 /**
3786 3942
  * This function actually makes all the group changes
@@ -3795,10 +3951,12 @@  discard block
 block discarded – undo
3795 3951
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3796 3952
 
3797 3953
 	// Let's be extra cautious...
3798
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3799
-		isAllowedTo('manage_membergroups');
3800
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3801
-		fatal_lang_error('no_access', false);
3954
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3955
+			isAllowedTo('manage_membergroups');
3956
+	}
3957
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3958
+			fatal_lang_error('no_access', false);
3959
+	}
3802 3960
 
3803 3961
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3804 3962
 
@@ -3817,8 +3975,9 @@  discard block
 block discarded – undo
3817 3975
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3818 3976
 
3819 3977
 	// Sanity check!!
3820
-	if ($group_id == 1)
3821
-		isAllowedTo('admin_forum');
3978
+	if ($group_id == 1) {
3979
+			isAllowedTo('admin_forum');
3980
+	}
3822 3981
 	// Protected groups too!
3823 3982
 	else
3824 3983
 	{
@@ -3835,8 +3994,9 @@  discard block
 block discarded – undo
3835 3994
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3836 3995
 		$smcFunc['db_free_result']($request);
3837 3996
 
3838
-		if ($is_protected == 1)
3839
-			isAllowedTo('admin_forum');
3997
+		if ($is_protected == 1) {
3998
+					isAllowedTo('admin_forum');
3999
+		}
3840 4000
 	}
3841 4001
 
3842 4002
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3858,36 +4018,43 @@  discard block
 block discarded – undo
3858 4018
 			$group_name = $row['group_name'];
3859 4019
 
3860 4020
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3861
-			if ($changeType == 'request' && $row['group_type'] != 2)
3862
-				fatal_lang_error('no_access', false);
4021
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4022
+							fatal_lang_error('no_access', false);
4023
+			}
3863 4024
 			// What about leaving a requestable group we are not a member of?
3864
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3865
-				fatal_lang_error('no_access', false);
3866
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3867
-				fatal_lang_error('no_access', false);
4025
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4026
+							fatal_lang_error('no_access', false);
4027
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4028
+							fatal_lang_error('no_access', false);
4029
+			}
3868 4030
 
3869 4031
 			// We can't change the primary group if this is hidden!
3870
-			if ($row['hidden'] == 2)
3871
-				$canChangePrimary = false;
4032
+			if ($row['hidden'] == 2) {
4033
+							$canChangePrimary = false;
4034
+			}
3872 4035
 		}
3873 4036
 
3874 4037
 		// If this is their old primary, can we change it?
3875
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3876
-			$canChangePrimary = 1;
4038
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4039
+					$canChangePrimary = 1;
4040
+		}
3877 4041
 
3878 4042
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3879
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3880
-			$canChangePrimary = false;
4043
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4044
+					$canChangePrimary = false;
4045
+		}
3881 4046
 
3882 4047
 		// If this is the one we are acting on, can we even act?
3883
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3884
-			$canChangePrimary = false;
4048
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4049
+					$canChangePrimary = false;
4050
+		}
3885 4051
 	}
3886 4052
 	$smcFunc['db_free_result']($request);
3887 4053
 
3888 4054
 	// Didn't find the target?
3889
-	if (!$foundTarget)
3890
-		fatal_lang_error('no_access', false);
4055
+	if (!$foundTarget) {
4056
+			fatal_lang_error('no_access', false);
4057
+	}
3891 4058
 
3892 4059
 	// Final security check, don't allow users to promote themselves to admin.
3893 4060
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3907,8 +4074,9 @@  discard block
 block discarded – undo
3907 4074
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3908 4075
 		$smcFunc['db_free_result']($request);
3909 4076
 
3910
-		if ($disallow)
3911
-			isAllowedTo('admin_forum');
4077
+		if ($disallow) {
4078
+					isAllowedTo('admin_forum');
4079
+		}
3912 4080
 	}
3913 4081
 
3914 4082
 	// If we're requesting, add the note then return.
@@ -3926,8 +4094,9 @@  discard block
 block discarded – undo
3926 4094
 				'status_open' => 0,
3927 4095
 			)
3928 4096
 		);
3929
-		if ($smcFunc['db_num_rows']($request) != 0)
3930
-			fatal_lang_error('profile_error_already_requested_group');
4097
+		if ($smcFunc['db_num_rows']($request) != 0) {
4098
+					fatal_lang_error('profile_error_already_requested_group');
4099
+		}
3931 4100
 		$smcFunc['db_free_result']($request);
3932 4101
 
3933 4102
 		// Log the request.
@@ -3961,10 +4130,11 @@  discard block
 block discarded – undo
3961 4130
 		// Are we leaving?
3962 4131
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3963 4132
 		{
3964
-			if ($old_profile['id_group'] == $group_id)
3965
-				$newPrimary = 0;
3966
-			else
3967
-				unset($addGroups[$group_id]);
4133
+			if ($old_profile['id_group'] == $group_id) {
4134
+							$newPrimary = 0;
4135
+			} else {
4136
+							unset($addGroups[$group_id]);
4137
+			}
3968 4138
 		}
3969 4139
 		// ... if not, must be joining.
3970 4140
 		else
@@ -3972,36 +4142,42 @@  discard block
 block discarded – undo
3972 4142
 			// Can we change the primary, and do we want to?
3973 4143
 			if ($canChangePrimary)
3974 4144
 			{
3975
-				if ($old_profile['id_group'] != 0)
3976
-					$addGroups[$old_profile['id_group']] = -1;
4145
+				if ($old_profile['id_group'] != 0) {
4146
+									$addGroups[$old_profile['id_group']] = -1;
4147
+				}
3977 4148
 				$newPrimary = $group_id;
3978 4149
 			}
3979 4150
 			// Otherwise it's an additional group...
3980
-			else
3981
-				$addGroups[$group_id] = -1;
4151
+			else {
4152
+							$addGroups[$group_id] = -1;
4153
+			}
3982 4154
 		}
3983 4155
 	}
3984 4156
 	// Finally, we must be setting the primary.
3985 4157
 	elseif ($canChangePrimary)
3986 4158
 	{
3987
-		if ($old_profile['id_group'] != 0)
3988
-			$addGroups[$old_profile['id_group']] = -1;
3989
-		if (isset($addGroups[$group_id]))
3990
-			unset($addGroups[$group_id]);
4159
+		if ($old_profile['id_group'] != 0) {
4160
+					$addGroups[$old_profile['id_group']] = -1;
4161
+		}
4162
+		if (isset($addGroups[$group_id])) {
4163
+					unset($addGroups[$group_id]);
4164
+		}
3991 4165
 		$newPrimary = $group_id;
3992 4166
 	}
3993 4167
 
3994 4168
 	// Finally, we can make the changes!
3995
-	foreach ($addGroups as $id => $dummy)
3996
-		if (empty($id))
4169
+	foreach ($addGroups as $id => $dummy) {
4170
+			if (empty($id))
3997 4171
 			unset($addGroups[$id]);
4172
+	}
3998 4173
 	$addGroups = implode(',', array_flip($addGroups));
3999 4174
 
4000 4175
 	// Ensure that we don't cache permissions if the group is changing.
4001
-	if ($context['user']['is_owner'])
4002
-		$_SESSION['mc']['time'] = 0;
4003
-	else
4004
-		updateSettings(array('settings_updated' => time()));
4176
+	if ($context['user']['is_owner']) {
4177
+			$_SESSION['mc']['time'] = 0;
4178
+	} else {
4179
+			updateSettings(array('settings_updated' => time()));
4180
+	}
4005 4181
 
4006 4182
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4007 4183
 
@@ -4024,8 +4200,9 @@  discard block
 block discarded – undo
4024 4200
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4025 4201
 	{
4026 4202
 		// Check to ensure we're forcing SSL for authentication
4027
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4028
-			fatal_lang_error('login_ssl_required');
4203
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4204
+					fatal_lang_error('login_ssl_required');
4205
+		}
4029 4206
 
4030 4207
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4031 4208
 		// we do not want too much AJAX to confuse them.
@@ -4062,8 +4239,7 @@  discard block
 block discarded – undo
4062 4239
 				$context['sub_template'] = 'tfasetup_backup';
4063 4240
 
4064 4241
 				return;
4065
-			}
4066
-			else
4242
+			} else
4067 4243
 			{
4068 4244
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4069 4245
 				$context['tfa_error'] = !$valid_code;
@@ -4071,8 +4247,7 @@  discard block
 block discarded – undo
4071 4247
 				$context['tfa_pass_value'] = $_POST['passwd'];
4072 4248
 				$context['tfa_value'] = $_POST['tfa_code'];
4073 4249
 			}
4074
-		}
4075
-		else
4250
+		} else
4076 4251
 		{
4077 4252
 			$totp = new \TOTP\Auth();
4078 4253
 			$secret = $totp->generateCode();
@@ -4082,17 +4257,16 @@  discard block
 block discarded – undo
4082 4257
 		}
4083 4258
 
4084 4259
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4085
-	}
4086
-	elseif (isset($_REQUEST['disable']))
4260
+	} elseif (isset($_REQUEST['disable']))
4087 4261
 	{
4088 4262
 		updateMemberData($memID, array(
4089 4263
 			'tfa_secret' => '',
4090 4264
 			'tfa_backup' => '',
4091 4265
 		));
4092 4266
 		redirectexit('action=profile;area=account;u=' . $memID);
4267
+	} else {
4268
+			redirectexit('action=profile;area=account;u=' . $memID);
4269
+	}
4093 4270
 	}
4094
-	else
4095
-		redirectexit('action=profile;area=account;u=' . $memID);
4096
-}
4097 4271
 
4098 4272
 ?>
4099 4273
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Profile-View.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2605,7 +2605,7 @@
 block discarded – undo
2605 2605
  * @param int $start Which item to start with (for pagination purposes)
2606 2606
  * @param int $items_per_page How many items to show on each page
2607 2607
  * @param string $sort A string indicating how to sort the results
2608
- * @param int $memID The ID of the member
2608
+ * @param string $memID The ID of the member
2609 2609
  * @return array An array of information about the user's group requests
2610 2610
  */
2611 2611
 function list_getGroupRequests($start, $items_per_page, $sort, $memID)
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	// Prepare the pagination vars.
369 369
 	$maxIndex = 10;
370 370
 	$start = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
371
-	$count =  alert_count($memID);
371
+	$count = alert_count($memID);
372 372
 
373 373
 	// Get the alerts.
374 374
 	$context['alerts'] = fetch_alerts($memID, true, false, array('start' => $start, 'maxIndex' => $maxIndex));
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			),
834 834
 		),
835 835
 		'data_check' => array(
836
-			'class' => function ($data)
836
+			'class' => function($data)
837 837
 			{
838 838
 				return $data['approved'] ? '' : 'approvebg';
839 839
 			}
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
 				),
1537 1537
 				'data' => array(
1538 1538
 					'sprintf' => array(
1539
-						'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
1539
+						'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID . '">%1$s</a>',
1540 1540
 						'params' => array(
1541 1541
 							'ip' => false,
1542 1542
 						),
Please login to merge, or discard this patch.
Braces   +297 added lines, -216 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']))
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -583,10 +613,11 @@  discard block
 block discarded – undo
583 613
 	$reverse = false;
584 614
 	$range_limit = '';
585 615
 
586
-	if ($context['is_topics'])
587
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
588
-	else
589
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
616
+	if ($context['is_topics']) {
617
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
618
+	} else {
619
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
620
+	}
590 621
 
591 622
 	$maxIndex = $maxPerPage;
592 623
 
@@ -612,9 +643,9 @@  discard block
 block discarded – undo
612 643
 		{
613 644
 			$margin *= 5;
614 645
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
646
+		} else {
647
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
615 648
 		}
616
-		else
617
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
618 649
 	}
619 650
 
620 651
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -646,8 +677,7 @@  discard block
 block discarded – undo
646 677
 					'max' => $maxIndex,
647 678
 				)
648 679
 			);
649
-		}
650
-		else
680
+		} else
651 681
 		{
652 682
 			$request = $smcFunc['db_query']('', '
653 683
 				SELECT
@@ -676,8 +706,9 @@  discard block
 block discarded – undo
676 706
 		}
677 707
 
678 708
 		// Make sure we quit this loop.
679
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
680
-			break;
709
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
710
+					break;
711
+		}
681 712
 		$looped = true;
682 713
 		$range_limit = '';
683 714
 	}
@@ -721,19 +752,21 @@  discard block
 block discarded – undo
721 752
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
722 753
 		);
723 754
 
724
-		if ($user_info['id'] == $row['id_member_started'])
725
-			$board_ids['own'][$row['id_board']][] = $counter;
755
+		if ($user_info['id'] == $row['id_member_started']) {
756
+					$board_ids['own'][$row['id_board']][] = $counter;
757
+		}
726 758
 		$board_ids['any'][$row['id_board']][] = $counter;
727 759
 	}
728 760
 	$smcFunc['db_free_result']($request);
729 761
 
730 762
 	// All posts were retrieved in reverse order, get them right again.
731
-	if ($reverse)
732
-		$context['posts'] = array_reverse($context['posts'], true);
763
+	if ($reverse) {
764
+			$context['posts'] = array_reverse($context['posts'], true);
765
+	}
733 766
 
734 767
 	// These are all the permissions that are different from board to board..
735
-	if ($context['is_topics'])
736
-		$permissions = array(
768
+	if ($context['is_topics']) {
769
+			$permissions = array(
737 770
 			'own' => array(
738 771
 				'post_reply_own' => 'can_reply',
739 772
 			),
@@ -741,8 +774,8 @@  discard block
 block discarded – undo
741 774
 				'post_reply_any' => 'can_reply',
742 775
 			)
743 776
 		);
744
-	else
745
-		$permissions = array(
777
+	} else {
778
+			$permissions = array(
746 779
 			'own' => array(
747 780
 				'post_reply_own' => 'can_reply',
748 781
 				'delete_own' => 'can_delete',
@@ -752,6 +785,7 @@  discard block
 block discarded – undo
752 785
 				'delete_any' => 'can_delete',
753 786
 			)
754 787
 		);
788
+	}
755 789
 
756 790
 	// For every permission in the own/any lists...
757 791
 	foreach ($permissions as $type => $list)
@@ -762,19 +796,22 @@  discard block
 block discarded – undo
762 796
 			$boards = boardsAllowedTo($permission);
763 797
 
764 798
 			// Hmm, they can do it on all boards, can they?
765
-			if (!empty($boards) && $boards[0] == 0)
766
-				$boards = array_keys($board_ids[$type]);
799
+			if (!empty($boards) && $boards[0] == 0) {
800
+							$boards = array_keys($board_ids[$type]);
801
+			}
767 802
 
768 803
 			// Now go through each board they can do the permission on.
769 804
 			foreach ($boards as $board_id)
770 805
 			{
771 806
 				// There aren't any posts displayed from this board.
772
-				if (!isset($board_ids[$type][$board_id]))
773
-					continue;
807
+				if (!isset($board_ids[$type][$board_id])) {
808
+									continue;
809
+				}
774 810
 
775 811
 				// Set the permission to true ;).
776
-				foreach ($board_ids[$type][$board_id] as $counter)
777
-					$context['posts'][$counter][$allowed] = true;
812
+				foreach ($board_ids[$type][$board_id] as $counter) {
813
+									$context['posts'][$counter][$allowed] = true;
814
+				}
778 815
 			}
779 816
 		}
780 817
 	}
@@ -805,8 +842,9 @@  discard block
 block discarded – undo
805 842
 	$boardsAllowed = boardsAllowedTo('view_attachments');
806 843
 
807 844
 	// Make sure we can't actually see anything...
808
-	if (empty($boardsAllowed))
809
-		$boardsAllowed = array(-1);
845
+	if (empty($boardsAllowed)) {
846
+			$boardsAllowed = array(-1);
847
+	}
810 848
 
811 849
 	require_once($sourcedir . '/Subs-List.php');
812 850
 
@@ -957,8 +995,8 @@  discard block
 block discarded – undo
957 995
 		)
958 996
 	);
959 997
 	$attachments = array();
960
-	while ($row = $smcFunc['db_fetch_assoc']($request))
961
-		$attachments[] = array(
998
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
999
+			$attachments[] = array(
962 1000
 			'id' => $row['id_attach'],
963 1001
 			'filename' => $row['filename'],
964 1002
 			'downloads' => $row['downloads'],
@@ -970,6 +1008,7 @@  discard block
 block discarded – undo
970 1008
 			'board_name' => $row['name'],
971 1009
 			'approved' => $row['approved'],
972 1010
 		);
1011
+	}
973 1012
 
974 1013
 	$smcFunc['db_free_result']($request);
975 1014
 
@@ -1024,8 +1063,9 @@  discard block
 block discarded – undo
1024 1063
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1025 1064
 
1026 1065
 	// Only the owner can see the list (if the function is enabled of course)
1027
-	if ($user_info['id'] != $memID)
1028
-		return;
1066
+	if ($user_info['id'] != $memID) {
1067
+			return;
1068
+	}
1029 1069
 
1030 1070
 	require_once($sourcedir . '/Subs-List.php');
1031 1071
 
@@ -1171,8 +1211,9 @@  discard block
 block discarded – undo
1171 1211
 	);
1172 1212
 
1173 1213
 	$topics = array();
1174
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1175
-		$topics[] = $row['id_topic'];
1214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1215
+			$topics[] = $row['id_topic'];
1216
+	}
1176 1217
 
1177 1218
 	$smcFunc['db_free_result']($request);
1178 1219
 
@@ -1192,8 +1233,9 @@  discard block
 block discarded – undo
1192 1233
 				'topics' => $topics,
1193 1234
 			)
1194 1235
 		);
1195
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1196
-			$topicsInfo[] = $row;
1236
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1237
+					$topicsInfo[] = $row;
1238
+		}
1197 1239
 		$smcFunc['db_free_result']($request);
1198 1240
 	}
1199 1241
 
@@ -1241,8 +1283,9 @@  discard block
 block discarded – undo
1241 1283
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1242 1284
 
1243 1285
 	// Is the load average too high to allow searching just now?
1244
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1245
-		fatal_lang_error('loadavg_userstats_disabled', false);
1286
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1287
+			fatal_lang_error('loadavg_userstats_disabled', false);
1288
+	}
1246 1289
 
1247 1290
 	// General user statistics.
1248 1291
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1400,11 +1443,13 @@  discard block
 block discarded – undo
1400 1443
 	}
1401 1444
 	$smcFunc['db_free_result']($result);
1402 1445
 
1403
-	if ($maxPosts > 0)
1404
-		for ($hour = 0; $hour < 24; $hour++)
1446
+	if ($maxPosts > 0) {
1447
+			for ($hour = 0;
1448
+	}
1449
+	$hour < 24; $hour++)
1405 1450
 		{
1406
-			if (!isset($context['posts_by_time'][$hour]))
1407
-				$context['posts_by_time'][$hour] = array(
1451
+			if (!isset($context['posts_by_time'][$hour])) {
1452
+							$context['posts_by_time'][$hour] = array(
1408 1453
 					'hour' => $hour,
1409 1454
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1410 1455
 					'posts' => 0,
@@ -1412,7 +1457,7 @@  discard block
 block discarded – undo
1412 1457
 					'relative_percent' => 0,
1413 1458
 					'is_last' => $hour == 23,
1414 1459
 				);
1415
-			else
1460
+			} else
1416 1461
 			{
1417 1462
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1418 1463
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1445,8 +1490,9 @@  discard block
 block discarded – undo
1445 1490
 
1446 1491
 	foreach ($subActions as $sa => $action)
1447 1492
 	{
1448
-		if (!allowedTo($action[2]))
1449
-			unset($subActions[$sa]);
1493
+		if (!allowedTo($action[2])) {
1494
+					unset($subActions[$sa]);
1495
+		}
1450 1496
 	}
1451 1497
 
1452 1498
 	// Create the tabs for the template.
@@ -1464,15 +1510,18 @@  discard block
 block discarded – undo
1464 1510
 	);
1465 1511
 
1466 1512
 	// Moderation must be on to track edits.
1467
-	if (empty($modSettings['userlog_enabled']))
1468
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1513
+	if (empty($modSettings['userlog_enabled'])) {
1514
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1515
+	}
1469 1516
 
1470 1517
 	// Group requests must be active to show it...
1471
-	if (empty($modSettings['show_group_membership']))
1472
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1518
+	if (empty($modSettings['show_group_membership'])) {
1519
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1520
+	}
1473 1521
 
1474
-	if (empty($subActions))
1475
-		fatal_lang_error('no_access', false);
1522
+	if (empty($subActions)) {
1523
+			fatal_lang_error('no_access', false);
1524
+	}
1476 1525
 
1477 1526
 	$keys = array_keys($subActions);
1478 1527
 	$default = array_shift($keys);
@@ -1485,9 +1534,10 @@  discard block
 block discarded – undo
1485 1534
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1486 1535
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1487 1536
 
1488
-	if (!empty($call))
1489
-		call_user_func($call, $memID);
1490
-}
1537
+	if (!empty($call)) {
1538
+			call_user_func($call, $memID);
1539
+	}
1540
+	}
1491 1541
 
1492 1542
 /**
1493 1543
  * Handles tracking a user's activity
@@ -1503,8 +1553,9 @@  discard block
 block discarded – undo
1503 1553
 	isAllowedTo('moderate_forum');
1504 1554
 
1505 1555
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1506
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1507
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1556
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1557
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1558
+	}
1508 1559
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1509 1560
 
1510 1561
 	// Set the options for the list component.
@@ -1670,8 +1721,9 @@  discard block
 block discarded – undo
1670 1721
 			)
1671 1722
 		);
1672 1723
 		$message_members = array();
1673
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1674
-			$message_members[] = $row['id_member'];
1724
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1725
+					$message_members[] = $row['id_member'];
1726
+		}
1675 1727
 		$smcFunc['db_free_result']($request);
1676 1728
 
1677 1729
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1686,8 +1738,9 @@  discard block
 block discarded – undo
1686 1738
 					'ip_list' => $ips,
1687 1739
 				)
1688 1740
 			);
1689
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1690
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1741
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1742
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1743
+			}
1691 1744
 			$smcFunc['db_free_result']($request);
1692 1745
 		}
1693 1746
 
@@ -1701,8 +1754,9 @@  discard block
 block discarded – undo
1701 1754
 				'ip_list' => $ips,
1702 1755
 			)
1703 1756
 		);
1704
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1705
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1757
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1758
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1759
+		}
1706 1760
 		$smcFunc['db_free_result']($request);
1707 1761
 	}
1708 1762
 }
@@ -1762,8 +1816,8 @@  discard block
 block discarded – undo
1762 1816
 		))
1763 1817
 	);
1764 1818
 	$error_messages = array();
1765
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1766
-		$error_messages[] = array(
1819
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1820
+			$error_messages[] = array(
1767 1821
 			'ip' => inet_dtop($row['ip']),
1768 1822
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1769 1823
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1771,6 +1825,7 @@  discard block
 block discarded – undo
1771 1825
 			'time' => timeformat($row['log_time']),
1772 1826
 			'timestamp' => forum_time(true, $row['log_time']),
1773 1827
 		);
1828
+	}
1774 1829
 	$smcFunc['db_free_result']($request);
1775 1830
 
1776 1831
 	return $error_messages;
@@ -1833,8 +1888,8 @@  discard block
 block discarded – undo
1833 1888
 		))
1834 1889
 	);
1835 1890
 	$messages = array();
1836
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1837
-		$messages[] = array(
1891
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1892
+			$messages[] = array(
1838 1893
 			'ip' => inet_dtop($row['poster_ip']),
1839 1894
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1840 1895
 			'board' => array(
@@ -1847,6 +1902,7 @@  discard block
 block discarded – undo
1847 1902
 			'time' => timeformat($row['poster_time']),
1848 1903
 			'timestamp' => forum_time(true, $row['poster_time'])
1849 1904
 		);
1905
+	}
1850 1906
 	$smcFunc['db_free_result']($request);
1851 1907
 
1852 1908
 	return $messages;
@@ -1873,19 +1929,20 @@  discard block
 block discarded – undo
1873 1929
 		$context['sub_template'] = 'trackIP';
1874 1930
 		$context['page_title'] = $txt['profile'];
1875 1931
 		$context['base_url'] = $scripturl . '?action=trackip';
1876
-	}
1877
-	else
1932
+	} else
1878 1933
 	{
1879 1934
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1880 1935
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1881 1936
 	}
1882 1937
 
1883 1938
 	// Searching?
1884
-	if (isset($_REQUEST['searchip']))
1885
-		$context['ip'] = trim($_REQUEST['searchip']);
1939
+	if (isset($_REQUEST['searchip'])) {
1940
+			$context['ip'] = trim($_REQUEST['searchip']);
1941
+	}
1886 1942
 
1887
-	if (isValidIP($context['ip']) === false)
1888
-		fatal_lang_error('invalid_tracking_ip', false);
1943
+	if (isValidIP($context['ip']) === false) {
1944
+			fatal_lang_error('invalid_tracking_ip', false);
1945
+	}
1889 1946
 
1890 1947
 	//mysql didn't support like search with varbinary
1891 1948
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1893,8 +1950,9 @@  discard block
 block discarded – undo
1893 1950
 	$ip_var = $context['ip'];
1894 1951
 	$ip_string = '= {inet:ip_address}';
1895 1952
 
1896
-	if (empty($context['tracking_area']))
1897
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1953
+	if (empty($context['tracking_area'])) {
1954
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1955
+	}
1898 1956
 
1899 1957
 	$request = $smcFunc['db_query']('', '
1900 1958
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1905,8 +1963,9 @@  discard block
 block discarded – undo
1905 1963
 		)
1906 1964
 	);
1907 1965
 	$context['ips'] = array();
1908
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1909
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1968
+	}
1910 1969
 	$smcFunc['db_free_result']($request);
1911 1970
 
1912 1971
 	ksort($context['ips']);
@@ -2135,8 +2194,9 @@  discard block
 block discarded – undo
2135 2194
 		foreach ($context['whois_servers'] as $whois)
2136 2195
 		{
2137 2196
 			// Strip off the "decimal point" and anything following...
2138
-			if (in_array((int) $context['ip'], $whois['range']))
2139
-				$context['auto_whois_server'] = $whois;
2197
+			if (in_array((int) $context['ip'], $whois['range'])) {
2198
+							$context['auto_whois_server'] = $whois;
2199
+			}
2140 2200
 		}
2141 2201
 	}
2142 2202
 }
@@ -2153,10 +2213,11 @@  discard block
 block discarded – undo
2153 2213
 	// Gonna want this for the list.
2154 2214
 	require_once($sourcedir . '/Subs-List.php');
2155 2215
 
2156
-	if ($memID == 0)
2157
-		$context['base_url'] = $scripturl . '?action=trackip';
2158
-	else
2159
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2216
+	if ($memID == 0) {
2217
+			$context['base_url'] = $scripturl . '?action=trackip';
2218
+	} else {
2219
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2220
+	}
2160 2221
 
2161 2222
 	// Start with the user messages.
2162 2223
 	$listOptions = array(
@@ -2266,12 +2327,13 @@  discard block
 block discarded – undo
2266 2327
 		)
2267 2328
 	);
2268 2329
 	$logins = array();
2269
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2270
-		$logins[] = array(
2330
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2331
+			$logins[] = array(
2271 2332
 			'time' => timeformat($row['time']),
2272 2333
 			'ip' => inet_dtop($row['ip']),
2273 2334
 			'ip2' => inet_dtop($row['ip2']),
2274 2335
 		);
2336
+	}
2275 2337
 	$smcFunc['db_free_result']($request);
2276 2338
 
2277 2339
 	return $logins;
@@ -2296,11 +2358,12 @@  discard block
 block discarded – undo
2296 2358
 		)
2297 2359
 	);
2298 2360
 	$context['custom_field_titles'] = array();
2299
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2300
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2361
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2362
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2301 2363
 			'title' => $row['field_name'],
2302 2364
 			'parse_bbc' => $row['bbc'],
2303 2365
 		);
2366
+	}
2304 2367
 	$smcFunc['db_free_result']($request);
2305 2368
 
2306 2369
 	// Set the options for the error lists.
@@ -2439,19 +2502,22 @@  discard block
 block discarded – undo
2439 2502
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2440 2503
 	{
2441 2504
 		$extra = smf_json_decode($row['extra'], true);
2442
-		if (!empty($extra['applicator']))
2443
-			$members[] = $extra['applicator'];
2505
+		if (!empty($extra['applicator'])) {
2506
+					$members[] = $extra['applicator'];
2507
+		}
2444 2508
 
2445 2509
 		// Work out what the name of the action is.
2446
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2447
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2448
-		elseif (isset($txt[$row['action']]))
2449
-			$action_text = $txt[$row['action']];
2510
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2511
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2512
+		} elseif (isset($txt[$row['action']])) {
2513
+					$action_text = $txt[$row['action']];
2514
+		}
2450 2515
 		// Custom field?
2451
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2452
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2453
-		else
2454
-			$action_text = $row['action'];
2516
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2517
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2518
+		} else {
2519
+					$action_text = $row['action'];
2520
+		}
2455 2521
 
2456 2522
 		// Parse BBC?
2457 2523
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2483,13 +2549,15 @@  discard block
 block discarded – undo
2483 2549
 			)
2484 2550
 		);
2485 2551
 		$members = array();
2486
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2487
-			$members[$row['id_member']] = $row['real_name'];
2552
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2553
+					$members[$row['id_member']] = $row['real_name'];
2554
+		}
2488 2555
 		$smcFunc['db_free_result']($request);
2489 2556
 
2490
-		foreach ($edits as $key => $value)
2491
-			if (isset($members[$value['id_member']]))
2557
+		foreach ($edits as $key => $value) {
2558
+					if (isset($members[$value['id_member']]))
2492 2559
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2560
+		}
2493 2561
 	}
2494 2562
 
2495 2563
 	return $edits;
@@ -2690,10 +2758,11 @@  discard block
 block discarded – undo
2690 2758
 	$context['board'] = $board;
2691 2759
 
2692 2760
 	// Determine which groups this user is in.
2693
-	if (empty($user_profile[$memID]['additional_groups']))
2694
-		$curGroups = array();
2695
-	else
2696
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2761
+	if (empty($user_profile[$memID]['additional_groups'])) {
2762
+			$curGroups = array();
2763
+	} else {
2764
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2765
+	}
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_group'];
2698 2767
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2699 2768
 
@@ -2713,28 +2782,30 @@  discard block
 block discarded – undo
2713 2782
 	$context['no_access_boards'] = array();
2714 2783
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2715 2784
 	{
2716
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2717
-			$context['no_access_boards'][] = array(
2785
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2786
+					$context['no_access_boards'][] = array(
2718 2787
 				'id' => $row['id_board'],
2719 2788
 				'name' => $row['name'],
2720 2789
 				'is_last' => false,
2721 2790
 			);
2722
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2723
-			$context['boards'][$row['id_board']] = array(
2791
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2792
+					$context['boards'][$row['id_board']] = array(
2724 2793
 				'id' => $row['id_board'],
2725 2794
 				'name' => $row['name'],
2726 2795
 				'selected' => $board == $row['id_board'],
2727 2796
 				'profile' => $row['id_profile'],
2728 2797
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2729 2798
 			);
2799
+		}
2730 2800
 	}
2731 2801
 	$smcFunc['db_free_result']($request);
2732 2802
 
2733 2803
 	require_once($sourcedir . '/Subs-Boards.php');
2734 2804
 	sortBoards($context['boards']);
2735 2805
 
2736
-	if (!empty($context['no_access_boards']))
2737
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2806
+	if (!empty($context['no_access_boards'])) {
2807
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2808
+	}
2738 2809
 
2739 2810
 	$context['member']['permissions'] = array(
2740 2811
 		'general' => array(),
@@ -2743,8 +2814,9 @@  discard block
 block discarded – undo
2743 2814
 
2744 2815
 	// If you're an admin we know you can do everything, we might as well leave.
2745 2816
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2746
-	if ($context['member']['has_all_permissions'])
2747
-		return;
2817
+	if ($context['member']['has_all_permissions']) {
2818
+			return;
2819
+	}
2748 2820
 
2749 2821
 	$denied = array();
2750 2822
 
@@ -2763,21 +2835,24 @@  discard block
 block discarded – undo
2763 2835
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2764 2836
 	{
2765 2837
 		// We don't know about this permission, it doesn't exist :P.
2766
-		if (!isset($txt['permissionname_' . $row['permission']]))
2767
-			continue;
2838
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2839
+					continue;
2840
+		}
2768 2841
 
2769
-		if (empty($row['add_deny']))
2770
-			$denied[] = $row['permission'];
2842
+		if (empty($row['add_deny'])) {
2843
+					$denied[] = $row['permission'];
2844
+		}
2771 2845
 
2772 2846
 		// Permissions that end with _own or _any consist of two parts.
2773
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2774
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2775
-		else
2776
-			$name = $txt['permissionname_' . $row['permission']];
2847
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2848
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2849
+		} else {
2850
+					$name = $txt['permissionname_' . $row['permission']];
2851
+		}
2777 2852
 
2778 2853
 		// Add this permission if it doesn't exist yet.
2779
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2780
-			$context['member']['permissions']['general'][$row['permission']] = array(
2854
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2855
+					$context['member']['permissions']['general'][$row['permission']] = array(
2781 2856
 				'id' => $row['permission'],
2782 2857
 				'groups' => array(
2783 2858
 					'allowed' => array(),
@@ -2787,6 +2862,7 @@  discard block
 block discarded – undo
2787 2862
 				'is_denied' => false,
2788 2863
 				'is_global' => true,
2789 2864
 			);
2865
+		}
2790 2866
 
2791 2867
 		// Add the membergroup to either the denied or the allowed groups.
2792 2868
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2820,18 +2896,20 @@  discard block
 block discarded – undo
2820 2896
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2821 2897
 	{
2822 2898
 		// We don't know about this permission, it doesn't exist :P.
2823
-		if (!isset($txt['permissionname_' . $row['permission']]))
2824
-			continue;
2899
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2900
+					continue;
2901
+		}
2825 2902
 
2826 2903
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2827
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2828
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2829
-		else
2830
-			$name = $txt['permissionname_' . $row['permission']];
2904
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2905
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2906
+		} else {
2907
+					$name = $txt['permissionname_' . $row['permission']];
2908
+		}
2831 2909
 
2832 2910
 		// Create the structure for this permission.
2833
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2834
-			$context['member']['permissions']['board'][$row['permission']] = array(
2911
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2912
+					$context['member']['permissions']['board'][$row['permission']] = array(
2835 2913
 				'id' => $row['permission'],
2836 2914
 				'groups' => array(
2837 2915
 					'allowed' => array(),
@@ -2841,6 +2919,7 @@  discard block
 block discarded – undo
2841 2919
 				'is_denied' => false,
2842 2920
 				'is_global' => empty($board),
2843 2921
 			);
2922
+		}
2844 2923
 
2845 2924
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2846 2925
 
@@ -2859,8 +2938,9 @@  discard block
 block discarded – undo
2859 2938
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2860 2939
 
2861 2940
 	// Firstly, can we actually even be here?
2862
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2863
-		fatal_lang_error('no_access', false);
2941
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2942
+			fatal_lang_error('no_access', false);
2943
+	}
2864 2944
 
2865 2945
 	// Make sure things which are disabled stay disabled.
2866 2946
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2947,9 +3027,10 @@  discard block
 block discarded – undo
2947 3027
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2948 3028
 	);
2949 3029
 	$context['current_level'] = 0;
2950
-	foreach ($context['level_effects'] as $limit => $dummy)
2951
-		if ($context['member']['warning'] >= $limit)
3030
+	foreach ($context['level_effects'] as $limit => $dummy) {
3031
+			if ($context['member']['warning'] >= $limit)
2952 3032
 			$context['current_level'] = $limit;
2953
-}
3033
+	}
3034
+	}
2954 3035
 
2955 3036
 ?>
2956 3037
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/QueryString.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
  * Validates a IPv6 address. returns true if it is ipv6.
326 326
  *
327 327
  * @param string $ip The ip address to be validated
328
- * @return boolean Whether the specified IP is a valid IPv6 address
328
+ * @return false|string Whether the specified IP is a valid IPv6 address
329 329
  */
330 330
 function isValidIPv6($ip)
331 331
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -426,8 +426,8 @@
 block discarded – undo
426 426
 */
427 427
 function matchIPtoCIDR($ip_address, $cidr_address)
428 428
 {
429
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
429
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
431 431
 }
432 432
 
433 433
 /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 function isValidIPv6($ip)
331 331
 {
332 332
 	//looking for :
333
-	if (strpos($ip , ':') === false )
333
+	if (strpos($ip, ':') === false)
334 334
 		return false;
335 335
 
336 336
 	//check valid address
@@ -662,15 +662,15 @@  discard block
 block discarded – undo
662 662
 	{
663 663
 		// Let's do something special for session ids!
664 664
 		if (defined('SID') && SID != '')
665
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
665
+			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
666 666
 			{
667 667
 				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
668 668
 			}, $buffer);
669 669
 		else
670
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
670
+			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
671 671
 			{
672 672
 				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
673
-			}, $buffer );
673
+			}, $buffer);
674 674
 	}
675 675
 
676 676
 	// Return the changed buffer.
Please login to merge, or discard this patch.
Braces   +184 added lines, -130 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,29 +201,34 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193
-		elseif (strpos($_REQUEST['topic'], '.') !== false)
194
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
208
+		elseif (strpos($_REQUEST['topic'], '.') !== false) {
209
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
210
+		}
195 211
 
196 212
 		$topic = (int) $_REQUEST['topic'];
197 213
 
198 214
 		// Now make sure the online log gets the right number.
199 215
 		$_GET['topic'] = $topic;
216
+	} else {
217
+			$topic = 0;
200 218
 	}
201
-	else
202
-		$topic = 0;
203 219
 
204 220
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
205
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
206
-		$_REQUEST['start'] = 0;
221
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
222
+			$_REQUEST['start'] = 0;
223
+	}
207 224
 
208 225
 	// The action needs to be a string and not an array or anything else
209
-	if (isset($_REQUEST['action']))
210
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
211
-	if (isset($_GET['action']))
212
-		$_GET['action'] = (string) $_GET['action'];
226
+	if (isset($_REQUEST['action'])) {
227
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
228
+	}
229
+	if (isset($_GET['action'])) {
230
+			$_GET['action'] = (string) $_GET['action'];
231
+	}
213 232
 
214 233
 	// Some mail providers like to encode semicolons in activation URLs...
215 234
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -235,29 +254,33 @@  discard block
 block discarded – undo
235 254
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
236 255
 
237 256
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
238
-	if (!isset($modSettings['proxy_ip_header']))
239
-		$modSettings['proxy_ip_header'] = 'autodetect';
257
+	if (!isset($modSettings['proxy_ip_header'])) {
258
+			$modSettings['proxy_ip_header'] = 'autodetect';
259
+	}
240 260
 
241 261
 	// Which headers are we going to check for Reverse Proxy IP headers?
242
-	if ($modSettings['proxy_ip_header'] == 'disabled')
243
-		$reverseIPheaders = array();
244
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
245
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
246
-	else
247
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
262
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
263
+			$reverseIPheaders = array();
264
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
265
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
266
+	} else {
267
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
268
+	}
248 269
 
249 270
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
250 271
 	foreach ($reverseIPheaders as $proxyIPheader)
251 272
 	{
252 273
 		// Ignore if this is not set.
253
-		if (!isset($_SERVER[$proxyIPheader]))
254
-			continue;
274
+		if (!isset($_SERVER[$proxyIPheader])) {
275
+					continue;
276
+		}
255 277
 
256 278
 		if (!empty($modSettings['proxy_ip_servers']))
257 279
 		{
258
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
259
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
280
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
281
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
260 282
 					continue;
283
+			}
261 284
 		}
262 285
 
263 286
 		// If there are commas, get the last one.. probably.
@@ -277,8 +300,9 @@  discard block
 block discarded – undo
277 300
 
278 301
 						// Just incase we have a legacy IPv4 address.
279 302
 						// @ TODO: Convert to IPv6.
280
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
281
-							continue;
303
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
304
+													continue;
305
+						}
282 306
 					}
283 307
 
284 308
 					continue;
@@ -290,36 +314,40 @@  discard block
 block discarded – undo
290 314
 			}
291 315
 		}
292 316
 		// Otherwise just use the only one.
293
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
294
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
295
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
317
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
318
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
319
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
296 320
 		{
297 321
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
298 322
 
299 323
 			// Just incase we have a legacy IPv4 address.
300 324
 			// @ TODO: Convert to IPv6.
301
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
302
-				continue;
325
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
326
+							continue;
327
+			}
303 328
 		}
304 329
 	}
305 330
 
306 331
 	// Make sure we know the URL of the current request.
307
-	if (empty($_SERVER['REQUEST_URI']))
308
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
309
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
310
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
311
-	else
312
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
332
+	if (empty($_SERVER['REQUEST_URI'])) {
333
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
334
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
335
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
336
+	} else {
337
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
338
+	}
313 339
 
314 340
 	// And make sure HTTP_USER_AGENT is set.
315 341
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
316 342
 
317 343
 	// Some final checking.
318
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
319
-		$_SERVER['BAN_CHECK_IP'] = '';
320
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
321
-		$_SERVER['REMOTE_ADDR'] = '';
322
-}
344
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
345
+			$_SERVER['BAN_CHECK_IP'] = '';
346
+	}
347
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
348
+			$_SERVER['REMOTE_ADDR'] = '';
349
+	}
350
+	}
323 351
 
324 352
 /**
325 353
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -330,8 +358,9 @@  discard block
 block discarded – undo
330 358
 function isValidIPv6($ip)
331 359
 {
332 360
 	//looking for :
333
-	if (strpos($ip , ':') === false )
334
-		return false;
361
+	if (strpos($ip , ':') === false ) {
362
+			return false;
363
+	}
335 364
 
336 365
 	//check valid address
337 366
 	return inet_pton($ip);
@@ -348,15 +377,17 @@  discard block
 block discarded – undo
348 377
 	static $expanded = array();
349 378
 
350 379
 	// Check if we have done this already.
351
-	if (isset($expanded[$ip]))
352
-		return $expanded[$ip];
380
+	if (isset($expanded[$ip])) {
381
+			return $expanded[$ip];
382
+	}
353 383
 
354 384
 	// Expand the IP out.
355 385
 	$expanded_ip = explode(':', expandIPv6($ip));
356 386
 
357 387
 	$new_ip = array();
358
-	foreach ($expanded_ip as $int)
359
-		$new_ip[] = hexdec($int);
388
+	foreach ($expanded_ip as $int) {
389
+			$new_ip[] = hexdec($int);
390
+	}
360 391
 
361 392
 	// Save this incase of repeated use.
362 393
 	$expanded[$ip] = $new_ip;
@@ -376,8 +407,9 @@  discard block
 block discarded – undo
376 407
 	static $converted = array();
377 408
 
378 409
 	// Check if we have done this already.
379
-	if (isset($converted[$addr]))
380
-		return $converted[$addr];
410
+	if (isset($converted[$addr])) {
411
+			return $converted[$addr];
412
+	}
381 413
 
382 414
 	// Check if there are segments missing, insert if necessary.
383 415
 	if (strpos($addr, '::') !== false)
@@ -387,18 +419,20 @@  discard block
 block discarded – undo
387 419
 		$part[1] = explode(':', $part[1]);
388 420
 		$missing = array();
389 421
 
390
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
391
-			array_push($missing, '0000');
422
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
423
+					array_push($missing, '0000');
424
+		}
392 425
 
393 426
 		$part = array_merge($part[0], $missing, $part[1]);
427
+	} else {
428
+			$part = explode(':', $addr);
394 429
 	}
395
-	else
396
-		$part = explode(':', $addr);
397 430
 
398 431
 	// Pad each segment until it has 4 digits.
399
-	foreach ($part as &$p)
400
-		while (strlen($p) < 4)
432
+	foreach ($part as &$p) {
433
+			while (strlen($p) < 4)
401 434
 			$p = '0' . $p;
435
+	}
402 436
 
403 437
 	unset($p);
404 438
 
@@ -409,11 +443,12 @@  discard block
 block discarded – undo
409 443
 	$converted[$addr] = $result;
410 444
 
411 445
 	// Quick check to make sure the length is as expected.
412
-	if (!$strict_check || strlen($result) == 39)
413
-		return $result;
414
-	else
415
-		return false;
416
-}
446
+	if (!$strict_check || strlen($result) == 39) {
447
+			return $result;
448
+	} else {
449
+			return false;
450
+	}
451
+	}
417 452
 
418 453
 
419 454
 /**
@@ -444,15 +479,17 @@  discard block
 block discarded – undo
444 479
 {
445 480
 	global $smcFunc;
446 481
 
447
-	if (!is_array($var))
448
-		return $smcFunc['db_escape_string']($var);
482
+	if (!is_array($var)) {
483
+			return $smcFunc['db_escape_string']($var);
484
+	}
449 485
 
450 486
 	// Reindex the array with slashes.
451 487
 	$new_var = array();
452 488
 
453 489
 	// Add slashes to every element, even the indexes!
454
-	foreach ($var as $k => $v)
455
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
490
+	foreach ($var as $k => $v) {
491
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
492
+	}
456 493
 
457 494
 	return $new_var;
458 495
 }
@@ -472,12 +509,14 @@  discard block
 block discarded – undo
472 509
 {
473 510
 	global $smcFunc;
474 511
 
475
-	if (!is_array($var))
476
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
512
+	if (!is_array($var)) {
513
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
514
+	}
477 515
 
478 516
 	// Add the htmlspecialchars to every element.
479
-	foreach ($var as $k => $v)
480
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
517
+	foreach ($var as $k => $v) {
518
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
519
+	}
481 520
 
482 521
 	return $var;
483 522
 }
@@ -495,15 +534,17 @@  discard block
 block discarded – undo
495 534
  */
496 535
 function urldecode__recursive($var, $level = 0)
497 536
 {
498
-	if (!is_array($var))
499
-		return urldecode($var);
537
+	if (!is_array($var)) {
538
+			return urldecode($var);
539
+	}
500 540
 
501 541
 	// Reindex the array...
502 542
 	$new_var = array();
503 543
 
504 544
 	// Add the htmlspecialchars to every element.
505
-	foreach ($var as $k => $v)
506
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
545
+	foreach ($var as $k => $v) {
546
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
547
+	}
507 548
 
508 549
 	return $new_var;
509 550
 }
@@ -521,15 +562,17 @@  discard block
 block discarded – undo
521 562
 {
522 563
 	global $smcFunc;
523 564
 
524
-	if (!is_array($var))
525
-		return $smcFunc['db_unescape_string']($var);
565
+	if (!is_array($var)) {
566
+			return $smcFunc['db_unescape_string']($var);
567
+	}
526 568
 
527 569
 	// Reindex the array without slashes, this time.
528 570
 	$new_var = array();
529 571
 
530 572
 	// Strip the slashes from every element.
531
-	foreach ($var as $k => $v)
532
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
573
+	foreach ($var as $k => $v) {
574
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
575
+	}
533 576
 
534 577
 	return $new_var;
535 578
 }
@@ -547,15 +590,17 @@  discard block
 block discarded – undo
547 590
  */
548 591
 function stripslashes__recursive($var, $level = 0)
549 592
 {
550
-	if (!is_array($var))
551
-		return stripslashes($var);
593
+	if (!is_array($var)) {
594
+			return stripslashes($var);
595
+	}
552 596
 
553 597
 	// Reindex the array without slashes, this time.
554 598
 	$new_var = array();
555 599
 
556 600
 	// Strip the slashes from every element.
557
-	foreach ($var as $k => $v)
558
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
601
+	foreach ($var as $k => $v) {
602
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
603
+	}
559 604
 
560 605
 	return $new_var;
561 606
 }
@@ -576,12 +621,14 @@  discard block
 block discarded – undo
576 621
 	global $smcFunc;
577 622
 
578 623
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
579
-	if (!is_array($var))
580
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
624
+	if (!is_array($var)) {
625
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
626
+	}
581 627
 
582 628
 	// Go through all the elements and remove the whitespace.
583
-	foreach ($var as $k => $v)
584
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
629
+	foreach ($var as $k => $v) {
630
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
631
+	}
585 632
 
586 633
 	return $var;
587 634
 }
@@ -646,30 +693,37 @@  discard block
 block discarded – undo
646 693
 	global $scripturl, $modSettings, $context;
647 694
 
648 695
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
649
-	if ($scripturl == '' || !defined('SID'))
650
-		return $buffer;
696
+	if ($scripturl == '' || !defined('SID')) {
697
+			return $buffer;
698
+	}
651 699
 
652 700
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
653 701
 	// @todo smflib
654
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
655
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
702
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
703
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
704
+	}
656 705
 	// Debugging templates, are we?
657
-	elseif (isset($_GET['debug']))
658
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
706
+	elseif (isset($_GET['debug'])) {
707
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
708
+	}
659 709
 
660 710
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
661 711
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
662 712
 	{
663 713
 		// Let's do something special for session ids!
664
-		if (defined('SID') && SID != '')
665
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
714
+		if (defined('SID') && SID != '') {
715
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
666 716
 			{
667
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
717
+				global $scripturl;
718
+		}
719
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
668 720
 			}, $buffer);
669
-		else
670
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
721
+		else {
722
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
671 723
 			{
672
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
724
+				global $scripturl;
725
+		}
726
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
673 727
 			}, $buffer );
674 728
 	}
675 729
 
Please login to merge, or discard this patch.
Sources/RemoveTopic.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1491,7 +1491,7 @@
 block discarded – undo
1491 1491
 
1492 1492
 /**
1493 1493
  * Try to determine if the topic has already been deleted by another user.
1494
- * @return bool False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1494
+ * @return boolean|null False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1495 1495
  */
1496 1496
 function removeDeleteConcurrence()
1497 1497
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -398,7 +398,7 @@
 block discarded – undo
398 398
 	}
399 399
 	$smcFunc['db_free_result']($request);
400 400
 
401
-	if($updateBoardCount)
401
+	if ($updateBoardCount)
402 402
 	{
403 403
 		// Decrease the posts/topics...
404 404
 		foreach ($adjustBoards as $stats)
Please login to merge, or discard this patch.
Braces   +267 added lines, -200 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -820,6 +855,7 @@  discard block
 block discarded – undo
820 855
 				),
821 856
 				array('id_topic')
822 857
 			);
858
+		}
823 859
 
824 860
 		// Capture the ID of the new topic...
825 861
 		$topicID = empty($id_recycle_topic) ? $smcFunc['db_insert_id']('{db_prefix}topics', 'id_topic') : $id_recycle_topic;
@@ -857,22 +893,24 @@  discard block
 block discarded – undo
857 893
 			);
858 894
 
859 895
 			// Mark recycled topic as read.
860
-			if (!$user_info['is_guest'])
861
-				$smcFunc['db_insert']('replace',
896
+			if (!$user_info['is_guest']) {
897
+							$smcFunc['db_insert']('replace',
862 898
 					'{db_prefix}log_topics',
863 899
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
864 900
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
865 901
 					array('id_topic', 'id_member')
866 902
 				);
903
+			}
867 904
 
868 905
 			// Mark recycle board as seen, if it was marked as seen before.
869
-			if (!empty($isRead) && !$user_info['is_guest'])
870
-				$smcFunc['db_insert']('replace',
906
+			if (!empty($isRead) && !$user_info['is_guest']) {
907
+							$smcFunc['db_insert']('replace',
871 908
 					'{db_prefix}log_boards',
872 909
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
873 910
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
874 911
 					array('id_board', 'id_member')
875 912
 				);
913
+			}
876 914
 
877 915
 			// Add one topic and post to the recycle bin board.
878 916
 			$smcFunc['db_query']('', '
@@ -890,8 +928,8 @@  discard block
 block discarded – undo
890 928
 			);
891 929
 
892 930
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
893
-			if (!empty($id_recycle_topic))
894
-				$smcFunc['db_query']('', '
931
+			if (!empty($id_recycle_topic)) {
932
+							$smcFunc['db_query']('', '
895 933
 					UPDATE {db_prefix}topics
896 934
 					SET num_replies = num_replies + 1' .
897 935
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -902,6 +940,7 @@  discard block
 block discarded – undo
902 940
 						'id_merged_msg' => $message,
903 941
 					)
904 942
 				);
943
+			}
905 944
 
906 945
 			// Make sure this message isn't getting deleted later on.
907 946
 			$recycle = true;
@@ -911,8 +950,8 @@  discard block
 block discarded – undo
911 950
 		}
912 951
 
913 952
 		// If it wasn't approved don't keep it in the queue.
914
-		if (!$row['approved'])
915
-			$smcFunc['db_query']('', '
953
+		if (!$row['approved']) {
954
+					$smcFunc['db_query']('', '
916 955
 				DELETE FROM {db_prefix}approval_queue
917 956
 				WHERE id_msg = {int:id_msg}
918 957
 					AND id_attach = {int:id_attach}',
@@ -921,6 +960,7 @@  discard block
 block discarded – undo
921 960
 					'id_attach' => 0,
922 961
 				)
923 962
 			);
963
+		}
924 964
 	}
925 965
 
926 966
 	$smcFunc['db_query']('', '
@@ -938,8 +978,9 @@  discard block
 block discarded – undo
938 978
 
939 979
 	// If the poster was registered and the board this message was on incremented
940 980
 	// the member's posts when it was posted, decrease his or her post count.
941
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
942
-		updateMemberData($row['id_member'], array('posts' => '-'));
981
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
982
+			updateMemberData($row['id_member'], array('posts' => '-'));
983
+	}
943 984
 
944 985
 	// Only remove posts if they're not recycled.
945 986
 	if (!$recycle)
@@ -947,8 +988,9 @@  discard block
 block discarded – undo
947 988
 		// Callback for search APIs to do their thing
948 989
 		require_once($sourcedir . '/Search.php');
949 990
 		$searchAPI = findSearchAPI();
950
-		if ($searchAPI->supportsMethod('postRemoved'))
951
-			$searchAPI->postRemoved($message);
991
+		if ($searchAPI->supportsMethod('postRemoved')) {
992
+					$searchAPI->postRemoved($message);
993
+		}
952 994
 
953 995
 		// Remove the message!
954 996
 		$smcFunc['db_query']('', '
@@ -963,8 +1005,8 @@  discard block
 block discarded – undo
963 1005
 		{
964 1006
 			$customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true);
965 1007
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
966
-			if (!empty($words))
967
-				$smcFunc['db_query']('', '
1008
+			if (!empty($words)) {
1009
+							$smcFunc['db_query']('', '
968 1010
 					DELETE FROM {db_prefix}log_search_words
969 1011
 					WHERE id_word IN ({array_int:word_list})
970 1012
 						AND id_msg = {int:id_msg}',
@@ -973,6 +1015,7 @@  discard block
 block discarded – undo
973 1015
 						'id_msg' => $message,
974 1016
 					)
975 1017
 				);
1018
+			}
976 1019
 		}
977 1020
 
978 1021
 		// Delete attachment(s) if they exist.
@@ -996,10 +1039,11 @@  discard block
 block discarded – undo
996 1039
 
997 1040
 	// And now to update the last message of each board we messed with.
998 1041
 	require_once($sourcedir . '/Subs-Post.php');
999
-	if ($recycle)
1000
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1001
-	else
1002
-		updateLastMessages($row['id_board']);
1042
+	if ($recycle) {
1043
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1044
+	} else {
1045
+			updateLastMessages($row['id_board']);
1046
+	}
1003 1047
 
1004 1048
 	// Close any moderation reports for this message.
1005 1049
 	$smcFunc['db_query']('', '
@@ -1032,8 +1076,9 @@  discard block
 block discarded – undo
1032 1076
 	checkSession('get');
1033 1077
 
1034 1078
 	// Is recycled board enabled?
1035
-	if (empty($modSettings['recycle_enable']))
1036
-		fatal_lang_error('restored_disabled', 'critical');
1079
+	if (empty($modSettings['recycle_enable'])) {
1080
+			fatal_lang_error('restored_disabled', 'critical');
1081
+	}
1037 1082
 
1038 1083
 	// Can we be in here?
1039 1084
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1048,8 +1093,9 @@  discard block
 block discarded – undo
1048 1093
 	if (!empty($_REQUEST['msgs']))
1049 1094
 	{
1050 1095
 		$msgs = explode(',', $_REQUEST['msgs']);
1051
-		foreach ($msgs as $k => $msg)
1052
-			$msgs[$k] = (int) $msg;
1096
+		foreach ($msgs as $k => $msg) {
1097
+					$msgs[$k] = (int) $msg;
1098
+		}
1053 1099
 
1054 1100
 		// Get the id_previous_board and id_previous_topic.
1055 1101
 		$request = $smcFunc['db_query']('', '
@@ -1083,8 +1129,8 @@  discard block
 block discarded – undo
1083 1129
 			}
1084 1130
 
1085 1131
 			$previous_topics[] = $row['id_previous_topic'];
1086
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1087
-				$actioned_messages[$row['id_previous_topic']] = array(
1132
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1133
+							$actioned_messages[$row['id_previous_topic']] = array(
1088 1134
 					'msgs' => array(),
1089 1135
 					'count_posts' => $row['count_posts'],
1090 1136
 					'subject' => $row['subject'],
@@ -1094,17 +1140,20 @@  discard block
 block discarded – undo
1094 1140
 					'current_board' => $row['id_board'],
1095 1141
 					'members' => array(),
1096 1142
 				);
1143
+			}
1097 1144
 
1098 1145
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1099
-			if ($row['id_member'])
1100
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1146
+			if ($row['id_member']) {
1147
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1148
+			}
1101 1149
 		}
1102 1150
 		$smcFunc['db_free_result']($request);
1103 1151
 
1104 1152
 		// Check for topics we are going to fully restore.
1105
-		foreach ($actioned_messages as $topic => $data)
1106
-			if (in_array($topic, $topics_to_restore))
1153
+		foreach ($actioned_messages as $topic => $data) {
1154
+					if (in_array($topic, $topics_to_restore))
1107 1155
 				unset($actioned_messages[$topic]);
1156
+		}
1108 1157
 
1109 1158
 		// Load any previous topics to check they exist.
1110 1159
 		if (!empty($previous_topics))
@@ -1119,11 +1168,12 @@  discard block
 block discarded – undo
1119 1168
 				)
1120 1169
 			);
1121 1170
 			$previous_topics = array();
1122
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1123
-				$previous_topics[$row['id_topic']] = array(
1171
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1172
+							$previous_topics[$row['id_topic']] = array(
1124 1173
 					'board' => $row['id_board'],
1125 1174
 					'subject' => $row['subject'],
1126 1175
 				);
1176
+			}
1127 1177
 			$smcFunc['db_free_result']($request);
1128 1178
 		}
1129 1179
 
@@ -1145,11 +1195,11 @@  discard block
 block discarded – undo
1145 1195
 				// Log em.
1146 1196
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1147 1197
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1148
-			}
1149
-			else
1198
+			} else
1150 1199
 			{
1151
-				foreach ($data['msgs'] as $msg)
1152
-					$unfound_messages[$msg['id']] = $msg['subject'];
1200
+				foreach ($data['msgs'] as $msg) {
1201
+									$unfound_messages[$msg['id']] = $msg['subject'];
1202
+				}
1153 1203
 			}
1154 1204
 		}
1155 1205
 	}
@@ -1158,8 +1208,9 @@  discard block
 block discarded – undo
1158 1208
 	if (!empty($_REQUEST['topics']))
1159 1209
 	{
1160 1210
 		$topics = explode(',', $_REQUEST['topics']);
1161
-		foreach ($topics as $id)
1162
-			$topics_to_restore[] = (int) $id;
1211
+		foreach ($topics as $id) {
1212
+					$topics_to_restore[] = (int) $id;
1213
+		}
1163 1214
 	}
1164 1215
 
1165 1216
 	if (!empty($topics_to_restore))
@@ -1213,8 +1264,9 @@  discard block
 block discarded – undo
1213 1264
 					)
1214 1265
 				);
1215 1266
 
1216
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1217
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1267
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1268
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1269
+				}
1218 1270
 				$smcFunc['db_free_result']($request2);
1219 1271
 			}
1220 1272
 
@@ -1225,8 +1277,9 @@  discard block
 block discarded – undo
1225 1277
 	}
1226 1278
 
1227 1279
 	// Didn't find some things?
1228
-	if (!empty($unfound_messages))
1229
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1280
+	if (!empty($unfound_messages)) {
1281
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1282
+	}
1230 1283
 
1231 1284
 	// Just send them to the index if they get here.
1232 1285
 	redirectexit();
@@ -1246,12 +1299,14 @@  discard block
 block discarded – undo
1246 1299
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1247 1300
 
1248 1301
 	// Is it an array?
1249
-	if (!is_array($msgs))
1250
-		$msgs = array($msgs);
1302
+	if (!is_array($msgs)) {
1303
+			$msgs = array($msgs);
1304
+	}
1251 1305
 
1252 1306
 	// Lets make sure they are int.
1253
-	foreach ($msgs as $key => $msg)
1254
-		$msgs[$key] = (int) $msg;
1307
+	foreach ($msgs as $key => $msg) {
1308
+			$msgs[$key] = (int) $msg;
1309
+	}
1255 1310
 
1256 1311
 	// Get the source information.
1257 1312
 	$request = $smcFunc['db_query']('', '
@@ -1294,8 +1349,9 @@  discard block
 block discarded – undo
1294 1349
 			)
1295 1350
 		);
1296 1351
 
1297
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1298
-			updateMemberData($row['id_member'], array('posts' => '+'));
1352
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1353
+					updateMemberData($row['id_member'], array('posts' => '+'));
1354
+		}
1299 1355
 	}
1300 1356
 
1301 1357
 	// Time to move the messages.
@@ -1331,13 +1387,15 @@  discard block
 block discarded – undo
1331 1387
 	);
1332 1388
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1333 1389
 	{
1334
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1335
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1390
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1391
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1392
+		}
1336 1393
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1337
-		if (!$row['approved'])
1338
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1339
-		else
1340
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1394
+		if (!$row['approved']) {
1395
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1396
+		} else {
1397
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1398
+		}
1341 1399
 	}
1342 1400
 	$smcFunc['db_free_result']($request);
1343 1401
 
@@ -1396,13 +1454,15 @@  discard block
 block discarded – undo
1396 1454
 		);
1397 1455
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1398 1456
 		{
1399
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1400
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1457
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1458
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1459
+			}
1401 1460
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1402
-			if (!$row['approved'])
1403
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1404
-			else
1405
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1461
+			if (!$row['approved']) {
1462
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1463
+			} else {
1464
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1465
+			}
1406 1466
 		}
1407 1467
 		$smcFunc['db_free_result']($request);
1408 1468
 
@@ -1466,10 +1526,12 @@  discard block
 block discarded – undo
1466 1526
 
1467 1527
 	// Subject cache?
1468 1528
 	$cache_updates = array();
1469
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1470
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1471
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1472
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1529
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1530
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1531
+	}
1532
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1533
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1534
+	}
1473 1535
 
1474 1536
 	if (!empty($cache_updates))
1475 1537
 	{
@@ -1481,8 +1543,9 @@  discard block
 block discarded – undo
1481 1543
 				'first_messages' => $cache_updates,
1482 1544
 			)
1483 1545
 		);
1484
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1485
-			updateStats('subject', $row['id_topic'], $row['subject']);
1546
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1547
+					updateStats('subject', $row['id_topic'], $row['subject']);
1548
+		}
1486 1549
 		$smcFunc['db_free_result']($request);
1487 1550
 	}
1488 1551
 
@@ -1498,22 +1561,26 @@  discard block
 block discarded – undo
1498 1561
 	global $modSettings, $board, $scripturl, $context;
1499 1562
 
1500 1563
 	// No recycle no need to go further
1501
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1502
-		return false;
1564
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1565
+			return false;
1566
+	}
1503 1567
 
1504 1568
 	// If it's confirmed go on and delete (from recycle)
1505
-	if (isset($_GET['confirm_delete']))
1506
-		return true;
1569
+	if (isset($_GET['confirm_delete'])) {
1570
+			return true;
1571
+	}
1507 1572
 
1508
-	if (empty($board))
1509
-		return false;
1573
+	if (empty($board)) {
1574
+			return false;
1575
+	}
1510 1576
 
1511
-	if ($modSettings['recycle_board'] != $board)
1512
-		return true;
1513
-	elseif (isset($_REQUEST['msg']))
1514
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1515
-	else
1516
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1577
+	if ($modSettings['recycle_board'] != $board) {
1578
+			return true;
1579
+	} elseif (isset($_REQUEST['msg'])) {
1580
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1581
+	} else {
1582
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1583
+	}
1517 1584
 
1518 1585
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1519 1586
 }
Please login to merge, or discard this patch.