Completed
Branch release-2.1 (3c29ac)
by Mathias
08:54
created
Sources/Load.php 4 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2238,9 +2238,9 @@  discard block
 block discarded – undo
2238 2238
  *
2239 2239
  * @uses the template_include() function to include the file.
2240 2240
  * @param string $template_name The name of the template to load
2241
- * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2241
+ * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2242 2242
  * @param bool $fatal If true, dies with an error message if the template cannot be found
2243
- * @return boolean Whether or not the template was loaded
2243
+ * @return boolean|null Whether or not the template was loaded
2244 2244
  */
2245 2245
 function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
2246 2246
 {
@@ -2424,7 +2424,7 @@  discard block
 block discarded – undo
2424 2424
  * - all code added with this function is added to the same <style> tag so do make sure your css is valid!
2425 2425
  *
2426 2426
  * @param string $css Some css code
2427
- * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2427
+ * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2428 2428
  */
2429 2429
 function addInlineCss($css)
2430 2430
 {
@@ -2440,7 +2440,7 @@  discard block
 block discarded – undo
2440 2440
 /**
2441 2441
  * Add a Javascript file for output later
2442 2442
 
2443
- * @param string $filename The name of the file to load
2443
+ * @param string $fileName The name of the file to load
2444 2444
  * @param array $params An array of parameter info
2445 2445
  * Keys are the following:
2446 2446
  * 	- ['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
@@ -2538,7 +2538,7 @@  discard block
 block discarded – undo
2538 2538
  *
2539 2539
  * @param string $javascript Some JS code
2540 2540
  * @param bool $defer Whether the script should load in <head> or before the closing <html> tag
2541
- * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2541
+ * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2542 2542
  */
2543 2543
 function addInlineJavaScript($javascript, $defer = false)
2544 2544
 {
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -2439,7 +2439,6 @@
 block discarded – undo
2439 2439
 
2440 2440
 /**
2441 2441
  * Add a Javascript file for output later
2442
-
2443 2442
  * @param string $filename The name of the file to load
2444 2443
  * @param array $params An array of parameter info
2445 2444
  * Keys are the following:
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -73,15 +73,15 @@  discard block
 block discarded – undo
73 73
 
74 74
 	// Set a list of common functions.
75 75
 	$ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);';
76
-	$ent_check = empty($modSettings['disableEntityCheck']) ? function ($string)
76
+	$ent_check = empty($modSettings['disableEntityCheck']) ? function($string)
77 77
 		{
78 78
 			$string = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $string);
79 79
 			return $string;
80
-		} : function ($string)
80
+		} : function($string)
81 81
 		{
82 82
 			return $string;
83 83
 		};
84
-	$fix_utf8mb4 = function ($string) use ($utf8)
84
+	$fix_utf8mb4 = function($string) use ($utf8)
85 85
 	{
86 86
 		if (!$utf8)
87 87
 			return $string;
@@ -99,21 +99,21 @@  discard block
 block discarded – undo
99 99
 			}
100 100
 			elseif ($ord < 224)
101 101
 			{
102
-				$new_string .= $string[$i] . $string[$i+1];
102
+				$new_string .= $string[$i] . $string[$i + 1];
103 103
 				$i += 2;
104 104
 			}
105 105
 			elseif ($ord < 240)
106 106
 			{
107
-				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
107
+				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
108 108
 				$i += 3;
109 109
 			}
110 110
 			elseif ($ord < 248)
111 111
 			{
112 112
 				// Magic happens.
113 113
 				$val = (ord($string[$i]) & 0x07) << 18;
114
-				$val += (ord($string[$i+1]) & 0x3F) << 12;
115
-				$val += (ord($string[$i+2]) & 0x3F) << 6;
116
-				$val += (ord($string[$i+3]) & 0x3F);
114
+				$val += (ord($string[$i + 1]) & 0x3F) << 12;
115
+				$val += (ord($string[$i + 2]) & 0x3F) << 6;
116
+				$val += (ord($string[$i + 3]) & 0x3F);
117 117
 				$new_string .= '&#' . $val . ';';
118 118
 				$i += 4;
119 119
 			}
@@ -126,24 +126,24 @@  discard block
 block discarded – undo
126 126
 
127 127
 	// global array of anonymous helper functions, used mostly to properly handle multi byte strings
128 128
 	$smcFunc += array(
129
-		'entity_fix' => function ($string)
129
+		'entity_fix' => function($string)
130 130
 		{
131 131
 			$num = $string[0] === 'x' ? hexdec(substr($string, 1)) : (int) $string;
132 132
 			return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? '' : '&#' . $num . ';';
133 133
 		},
134
-		'htmlspecialchars' => function ($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4)
134
+		'htmlspecialchars' => function($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4)
135 135
 		{
136 136
 			return $fix_utf8mb4($ent_check(htmlspecialchars($string, $quote_style, $utf8 ? 'UTF-8' : $charset)));
137 137
 		},
138
-		'htmltrim' => function ($string) use ($utf8, $space_chars, $ent_check)
138
+		'htmltrim' => function($string) use ($utf8, $space_chars, $ent_check)
139 139
 		{
140 140
 			return preg_replace('~^(?:[ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+|(?:[ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+$~' . ($utf8 ? 'u' : ''), '', $ent_check($string));
141 141
 		},
142
-		'strlen' => function ($string) use ($ent_list, $utf8, $ent_check)
142
+		'strlen' => function($string) use ($ent_list, $utf8, $ent_check)
143 143
 		{
144 144
 			return strlen(preg_replace('~' . $ent_list . ($utf8 ? '|.~u' : '~'), '_', $ent_check($string)));
145 145
 		},
146
-		'strpos' => function ($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings)
146
+		'strpos' => function($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings)
147 147
 		{
148 148
 			$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);
149 149
 
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
 				return false;
169 169
 			}
170 170
 		},
171
-		'substr' => function ($string, $start, $length = null) use ($utf8, $ent_check, $modSettings)
171
+		'substr' => function($string, $start, $length = null) use ($utf8, $ent_check, $modSettings)
172 172
 		{
173 173
 			$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);
174 174
 			return $length === null ? implode('', array_slice($ent_arr, $start)) : implode('', array_slice($ent_arr, $start, $length));
175 175
 		},
176
-		'strtolower' => $utf8 ? function ($string) use ($sourcedir)
176
+		'strtolower' => $utf8 ? function($string) use ($sourcedir)
177 177
 		{
178 178
 			if (!function_exists('mb_strtolower'))
179 179
 			{
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
 			return mb_strtolower($string, 'UTF-8');
185 185
 		} : 'strtolower',
186
-		'strtoupper' => $utf8 ? function ($string)
186
+		'strtoupper' => $utf8 ? function($string)
187 187
 		{
188 188
 			global $sourcedir;
189 189
 
@@ -198,17 +198,17 @@  discard block
 block discarded – undo
198 198
 		'truncate' => function($string, $length) use ($utf8, $ent_check, $ent_list, &$smcFunc)
199 199
 		{
200 200
 			$string = $ent_check($string);
201
-			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
201
+			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
202 202
 			$string = $matches[0];
203 203
 			while (strlen($string) > $length)
204
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
204
+				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
205 205
 			return $string;
206 206
 		},
207
-		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
207
+		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
208 208
 		{
209 209
 			return $smcFunc['strtoupper']($smcFunc['substr']($string, 0, 1)) . $smcFunc['substr']($string, 1);
210 210
 		} : 'ucfirst',
211
-		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
211
+		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
212 212
 		{
213 213
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
214 214
 			for ($i = 0, $n = count($words); $i < $n; $i += 2)
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 		else
608 608
 		{
609 609
 			// !!! Compatibility.
610
-			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
610
+			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
611 611
 		}
612 612
 	}
613 613
 	// If the user is a guest, initialize all the critical user settings.
@@ -1262,9 +1262,9 @@  discard block
 block discarded – undo
1262 1262
 			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1263 1263
 				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1264 1264
 
1265
-			if ( isset($row['member_ip']) )
1265
+			if (isset($row['member_ip']))
1266 1266
 				$row['member_ip'] = inet_dtop($row['member_ip']);
1267
-			if ( isset($row['member_ip2']) )
1267
+			if (isset($row['member_ip2']))
1268 1268
 				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1269 1269
 			$new_loaded_ids[] = $row['id_member'];
1270 1270
 			$loaded_ids[] = $row['id_member'];
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
 		'name' => $profile['real_name'],
1413 1413
 		'id' => $profile['id_member'],
1414 1414
 		'href' => $scripturl . '?action=profile;u=' . $profile['id_member'],
1415
-		'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>',
1415
+		'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>',
1416 1416
 		'email' => $profile['email_address'],
1417 1417
 		'show_email' => !$user_info['is_guest'] && ($user_info['id'] == $profile['id_member'] || allowedTo('moderate_forum')),
1418 1418
 		'registered' => empty($profile['date_registered']) ? $txt['not_applicable'] : timeformat($profile['date_registered']),
@@ -1427,9 +1427,9 @@  discard block
 block discarded – undo
1427 1427
 			$loadedLanguages = getLanguages();
1428 1428
 
1429 1429
 		$memberContext[$user] += array(
1430
-			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
1431
-			'name_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['real_name'] .'</span>',
1432
-			'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>',
1430
+			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
1431
+			'name_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['real_name'] . '</span>',
1432
+			'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 1433
 			'is_buddy' => $profile['buddy'],
1434 1434
 			'is_reverse_buddy' => in_array($user_info['id'], $buddy_list),
1435 1435
 			'buddies' => $buddy_list,
@@ -1499,7 +1499,7 @@  discard block
 block discarded – undo
1499 1499
 		if (!empty($image))
1500 1500
 			$memberContext[$user]['avatar'] = array(
1501 1501
 				'name' => $profile['avatar'],
1502
-				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1502
+				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1503 1503
 				'href' => $image,
1504 1504
 				'url' => $image,
1505 1505
 			);
@@ -2826,7 +2826,7 @@  discard block
 block discarded – undo
2826 2826
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2827 2827
 
2828 2828
 					// Get the line we need.
2829
-					$fp = @fopen($language_dir .'/'. $entry);
2829
+					$fp = @fopen($language_dir . '/' . $entry);
2830 2830
 
2831 2831
 					// Yay!
2832 2832
 					if ($fp)
@@ -3476,7 +3476,7 @@  discard block
 block discarded – undo
3476 3476
 	$port = 0;
3477 3477
 
3478 3478
 	// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
3479
-	if(strpos($server,'/') !== false)
3479
+	if (strpos($server, '/') !== false)
3480 3480
 		$host = $server;
3481 3481
 	else
3482 3482
 	{
Please login to merge, or discard this patch.
Braces   +860 added lines, -648 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
 	// Try to load it from the cache first; it'll never get cached if the setting is off.
37 39
 	if (($modSettings = cache_get_data('modSettings', 90)) == null)
@@ -43,27 +45,35 @@  discard block
 block discarded – undo
43 45
 			)
44 46
 		);
45 47
 		$modSettings = array();
46
-		if (!$request)
47
-			display_db_error();
48
-		while ($row = $smcFunc['db_fetch_row']($request))
49
-			$modSettings[$row[0]] = $row[1];
48
+		if (!$request) {
49
+					display_db_error();
50
+		}
51
+		while ($row = $smcFunc['db_fetch_row']($request)) {
52
+					$modSettings[$row[0]] = $row[1];
53
+		}
50 54
 		$smcFunc['db_free_result']($request);
51 55
 
52 56
 		// Do a few things to protect against missing settings or settings with invalid values...
53
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
54
-			$modSettings['defaultMaxTopics'] = 20;
55
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
56
-			$modSettings['defaultMaxMessages'] = 15;
57
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
58
-			$modSettings['defaultMaxMembers'] = 30;
59
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
60
-			$modSettings['defaultMaxListItems'] = 15;
57
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
58
+					$modSettings['defaultMaxTopics'] = 20;
59
+		}
60
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
61
+					$modSettings['defaultMaxMessages'] = 15;
62
+		}
63
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
64
+					$modSettings['defaultMaxMembers'] = 30;
65
+		}
66
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
67
+					$modSettings['defaultMaxListItems'] = 15;
68
+		}
61 69
 
62
-		if (!is_array($modSettings['attachmentUploadDir']))
63
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
70
+		if (!is_array($modSettings['attachmentUploadDir'])) {
71
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
72
+		}
64 73
 
65
-		if (!empty($cache_enable))
66
-			cache_put_data('modSettings', $modSettings, 90);
74
+		if (!empty($cache_enable)) {
75
+					cache_put_data('modSettings', $modSettings, 90);
76
+		}
67 77
 	}
68 78
 
69 79
 	$modSettings['cache_enable'] = $cache_enable;
@@ -83,8 +93,9 @@  discard block
 block discarded – undo
83 93
 		};
84 94
 	$fix_utf8mb4 = function ($string) use ($utf8)
85 95
 	{
86
-		if (!$utf8)
87
-			return $string;
96
+		if (!$utf8) {
97
+					return $string;
98
+		}
88 99
 
89 100
 		$i = 0;
90 101
 		$len = strlen($string);
@@ -96,18 +107,15 @@  discard block
 block discarded – undo
96 107
 			{
97 108
 				$new_string .= $string[$i];
98 109
 				$i++;
99
-			}
100
-			elseif ($ord < 224)
110
+			} elseif ($ord < 224)
101 111
 			{
102 112
 				$new_string .= $string[$i] . $string[$i+1];
103 113
 				$i += 2;
104
-			}
105
-			elseif ($ord < 240)
114
+			} elseif ($ord < 240)
106 115
 			{
107 116
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
108 117
 				$i += 3;
109
-			}
110
-			elseif ($ord < 248)
118
+			} elseif ($ord < 248)
111 119
 			{
112 120
 				// Magic happens.
113 121
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -151,8 +159,7 @@  discard block
 block discarded – undo
151 159
 			{
152 160
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
153 161
 				return is_int($result) ? $result + $offset : false;
154
-			}
155
-			else
162
+			} else
156 163
 			{
157 164
 				$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);
158 165
 				$needle_size = count($needle_arr);
@@ -161,8 +168,9 @@  discard block
 block discarded – undo
161 168
 				while ((int) $result === $result)
162 169
 				{
163 170
 					$offset += $result;
164
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
165
-						return $offset;
171
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
172
+											return $offset;
173
+					}
166 174
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
167 175
 				}
168 176
 				return false;
@@ -200,8 +208,9 @@  discard block
 block discarded – undo
200 208
 			$string = $ent_check($string);
201 209
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
202 210
 			$string = $matches[0];
203
-			while (strlen($string) > $length)
204
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
211
+			while (strlen($string) > $length) {
212
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
213
+			}
205 214
 			return $string;
206 215
 		},
207 216
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -211,15 +220,17 @@  discard block
 block discarded – undo
211 220
 		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
212 221
 		{
213 222
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
214
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
215
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
223
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
224
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
225
+			}
216 226
 			return implode('', $words);
217 227
 		} : 'ucwords',
218 228
 	);
219 229
 
220 230
 	// Setting the timezone is a requirement for some functions.
221
-	if (isset($modSettings['default_timezone']))
222
-		date_default_timezone_set($modSettings['default_timezone']);
231
+	if (isset($modSettings['default_timezone'])) {
232
+			date_default_timezone_set($modSettings['default_timezone']);
233
+	}
223 234
 
224 235
 	// Check the load averages?
225 236
 	if (!empty($modSettings['loadavg_enable']))
@@ -227,22 +238,26 @@  discard block
 block discarded – undo
227 238
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
228 239
 		{
229 240
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
230
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
231
-				$modSettings['load_average'] = (float) $matches[1];
232
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
233
-				$modSettings['load_average'] = (float) $matches[1];
234
-			else
235
-				unset($modSettings['load_average']);
241
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
242
+							$modSettings['load_average'] = (float) $matches[1];
243
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
244
+							$modSettings['load_average'] = (float) $matches[1];
245
+			} else {
246
+							unset($modSettings['load_average']);
247
+			}
236 248
 
237
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
238
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
249
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
250
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
251
+			}
239 252
 		}
240 253
 
241
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
242
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
254
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
255
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
256
+		}
243 257
 
244
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
245
-			display_loadavg_error();
258
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
259
+					display_loadavg_error();
260
+		}
246 261
 	}
247 262
 
248 263
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -263,8 +278,9 @@  discard block
 block discarded – undo
263 278
 	if (defined('SMF_INTEGRATION_SETTINGS'))
264 279
 	{
265 280
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
266
-		foreach ($integration_settings as $hook => $function)
267
-			add_integration_function($hook, $function, '', false);
281
+		foreach ($integration_settings as $hook => $function) {
282
+					add_integration_function($hook, $function, '', false);
283
+		}
268 284
 	}
269 285
 
270 286
 	// Any files to pre include?
@@ -274,8 +290,9 @@  discard block
 block discarded – undo
274 290
 		foreach ($pre_includes as $include)
275 291
 		{
276 292
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
277
-			if (file_exists($include))
278
-				require_once($include);
293
+			if (file_exists($include)) {
294
+							require_once($include);
295
+			}
279 296
 		}
280 297
 	}
281 298
 
@@ -379,27 +396,28 @@  discard block
 block discarded – undo
379 396
 				break;
380 397
 			}
381 398
 		}
399
+	} else {
400
+			$id_member = 0;
382 401
 	}
383
-	else
384
-		$id_member = 0;
385 402
 
386 403
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
387 404
 	{
388 405
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
389 406
 
390
-		if (empty($cookie_data))
391
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
407
+		if (empty($cookie_data)) {
408
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
409
+		}
392 410
 
393 411
 		list ($id_member, $password) = $cookie_data;
394 412
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
395
-	}
396
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
413
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
397 414
 	{
398 415
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
399 416
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
400 417
 
401
-		if (empty($cookie_data))
402
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
418
+		if (empty($cookie_data)) {
419
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
420
+		}
403 421
 
404 422
 		list ($id_member, $password, $login_span) = $cookie_data;
405 423
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -424,30 +442,34 @@  discard block
 block discarded – undo
424 442
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
425 443
 			$smcFunc['db_free_result']($request);
426 444
 
427
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
428
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
445
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
446
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
447
+			}
429 448
 
430
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
431
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
449
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
450
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
451
+			}
432 452
 		}
433 453
 
434 454
 		// Did we find 'im?  If not, junk it.
435 455
 		if (!empty($user_settings))
436 456
 		{
437 457
 			// As much as the password should be right, we can assume the integration set things up.
438
-			if (!empty($already_verified) && $already_verified === true)
439
-				$check = true;
458
+			if (!empty($already_verified) && $already_verified === true) {
459
+							$check = true;
460
+			}
440 461
 			// SHA-512 hash should be 128 characters long.
441
-			elseif (strlen($password) == 128)
442
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
443
-			else
444
-				$check = false;
462
+			elseif (strlen($password) == 128) {
463
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
+			} else {
465
+							$check = false;
466
+			}
445 467
 
446 468
 			// Wrong password or not activated - either way, you're going nowhere.
447 469
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
470
+		} else {
471
+					$id_member = 0;
448 472
 		}
449
-		else
450
-			$id_member = 0;
451 473
 
452 474
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
453 475
 		if (!$id_member)
@@ -469,13 +491,15 @@  discard block
 block discarded – undo
469 491
 				{
470 492
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
471 493
 
472
-					if (is_null($tfa_data))
473
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
494
+					if (is_null($tfa_data)) {
495
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
496
+					}
474 497
 
475 498
 					list ($tfamember, $tfasecret) = $tfa_data;
476 499
 
477
-					if ((int) $tfamember != $id_member)
478
-						$tfasecret = null;
500
+					if ((int) $tfamember != $id_member) {
501
+											$tfasecret = null;
502
+					}
479 503
 				}
480 504
 
481 505
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -495,10 +519,12 @@  discard block
 block discarded – undo
495 519
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
496 520
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
497 521
 		{
498
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
522
+			if ($modSettings['tfa_mode'] == 2) {
523
+				//only do this if we are just forcing SOME membergroups
499 524
 			{
500 525
 				//Build an array of ALL user membergroups.
501 526
 				$full_groups = array($user_settings['id_group']);
527
+			}
502 528
 				if (!empty($user_settings['additional_groups']))
503 529
 				{
504 530
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -518,15 +544,17 @@  discard block
 block discarded – undo
518 544
 				);
519 545
 				$row = $smcFunc['db_fetch_assoc']($request);
520 546
 				$smcFunc['db_free_result']($request);
547
+			} else {
548
+							$row['total'] = 1;
521 549
 			}
522
-			else
523
-				$row['total'] = 1; //simplifies logics in the next "if"
550
+			//simplifies logics in the next "if"
524 551
 
525 552
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
526 553
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
527 554
 
528
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
529
-				redirectexit('action=profile;area=tfasetup;forced');
555
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
556
+							redirectexit('action=profile;area=tfasetup;forced');
557
+			}
530 558
 		}
531 559
 	}
532 560
 
@@ -563,33 +591,37 @@  discard block
 block discarded – undo
563 591
 				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']));
564 592
 				$user_settings['last_login'] = time();
565 593
 
566
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
567
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
594
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
595
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
596
+				}
568 597
 
569
-				if (!empty($modSettings['cache_enable']))
570
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
598
+				if (!empty($modSettings['cache_enable'])) {
599
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
600
+				}
571 601
 			}
602
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
603
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
572 604
 		}
573
-		elseif (empty($_SESSION['id_msg_last_visit']))
574
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
575 605
 
576 606
 		$username = $user_settings['member_name'];
577 607
 
578
-		if (empty($user_settings['additional_groups']))
579
-			$user_info = array(
608
+		if (empty($user_settings['additional_groups'])) {
609
+					$user_info = array(
580 610
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
581 611
 			);
582
-		else
583
-			$user_info = array(
612
+		} else {
613
+					$user_info = array(
584 614
 				'groups' => array_merge(
585 615
 					array($user_settings['id_group'], $user_settings['id_post_group']),
586 616
 					explode(',', $user_settings['additional_groups'])
587 617
 				)
588 618
 			);
619
+		}
589 620
 
590 621
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
591
-		foreach ($user_info['groups'] as $k => $v)
592
-			$user_info['groups'][$k] = (int) $v;
622
+		foreach ($user_info['groups'] as $k => $v) {
623
+					$user_info['groups'][$k] = (int) $v;
624
+		}
593 625
 
594 626
 		// This is a logged in user, so definitely not a spider.
595 627
 		$user_info['possibly_robot'] = false;
@@ -603,8 +635,7 @@  discard block
 block discarded – undo
603 635
 			$time_system = new DateTime('now', $tz_system);
604 636
 			$time_user = new DateTime('now', $tz_user);
605 637
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
606
-		}
607
-		else
638
+		} else
608 639
 		{
609 640
 			// !!! Compatibility.
610 641
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -618,16 +649,18 @@  discard block
 block discarded – undo
618 649
 		$user_info = array('groups' => array(-1));
619 650
 		$user_settings = array();
620 651
 
621
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
622
-			$_COOKIE[$cookiename] = '';
652
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
653
+					$_COOKIE[$cookiename] = '';
654
+		}
623 655
 
624 656
 		// Expire the 2FA cookie
625 657
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
626 658
 		{
627 659
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
628 660
 
629
-			if (is_null($tfa_data))
630
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
661
+			if (is_null($tfa_data)) {
662
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
663
+			}
631 664
 
632 665
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
633 666
 
@@ -639,19 +672,20 @@  discard block
 block discarded – undo
639 672
 		}
640 673
 
641 674
 		// Create a login token if it doesn't exist yet.
642
-		if (!isset($_SESSION['token']['post-login']))
643
-			createToken('login');
644
-		else
645
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
675
+		if (!isset($_SESSION['token']['post-login'])) {
676
+					createToken('login');
677
+		} else {
678
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
679
+		}
646 680
 
647 681
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
648 682
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
649 683
 		{
650 684
 			require_once($sourcedir . '/ManageSearchEngines.php');
651 685
 			$user_info['possibly_robot'] = SpiderCheck();
686
+		} elseif (!empty($modSettings['spider_mode'])) {
687
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
652 688
 		}
653
-		elseif (!empty($modSettings['spider_mode']))
654
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
655 689
 		// If we haven't turned on proper spider hunts then have a guess!
656 690
 		else
657 691
 		{
@@ -699,8 +733,9 @@  discard block
 block discarded – undo
699 733
 	$user_info['groups'] = array_unique($user_info['groups']);
700 734
 
701 735
 	// 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.
702
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
703
-		unset($user_info['ignoreboards'][$tmp]);
736
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
737
+			unset($user_info['ignoreboards'][$tmp]);
738
+	}
704 739
 
705 740
 	// Allow the user to change their language.
706 741
 	if (!empty($modSettings['userLanguage']))
@@ -713,31 +748,36 @@  discard block
 block discarded – undo
713 748
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
714 749
 
715 750
 			// Make it permanent for members.
716
-			if (!empty($user_info['id']))
717
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
718
-			else
719
-				$_SESSION['language'] = $user_info['language'];
751
+			if (!empty($user_info['id'])) {
752
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
753
+			} else {
754
+							$_SESSION['language'] = $user_info['language'];
755
+			}
756
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
757
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
720 758
 		}
721
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
722
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
723 759
 	}
724 760
 
725 761
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
726
-	if ($user_info['is_admin'])
727
-		$user_info['query_see_board'] = '1=1';
762
+	if ($user_info['is_admin']) {
763
+			$user_info['query_see_board'] = '1=1';
764
+	}
728 765
 	// Otherwise just the groups in $user_info['groups'].
729
-	else
730
-		$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'] : '') . ')';
766
+	else {
767
+			$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'] : '') . ')';
768
+	}
731 769
 
732 770
 	// Build the list of boards they WANT to see.
733 771
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
734 772
 
735 773
 	// If they aren't ignoring any boards then they want to see all the boards they can see
736
-	if (empty($user_info['ignoreboards']))
737
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
774
+	if (empty($user_info['ignoreboards'])) {
775
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
776
+	}
738 777
 	// Ok I guess they don't want to see all the boards
739
-	else
740
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
778
+	else {
779
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
780
+	}
741 781
 
742 782
 	call_integration_hook('integrate_user_info');
743 783
 }
@@ -795,9 +835,9 @@  discard block
 block discarded – undo
795 835
 		}
796 836
 
797 837
 		// Remember redirection is the key to avoiding fallout from your bosses.
798
-		if (!empty($topic))
799
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
800
-		else
838
+		if (!empty($topic)) {
839
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
840
+		} else
801 841
 		{
802 842
 			loadPermissions();
803 843
 			loadTheme();
@@ -815,10 +855,11 @@  discard block
 block discarded – undo
815 855
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
816 856
 	{
817 857
 		// @todo SLOW?
818
-		if (!empty($topic))
819
-			$temp = cache_get_data('topic_board-' . $topic, 120);
820
-		else
821
-			$temp = cache_get_data('board-' . $board, 120);
858
+		if (!empty($topic)) {
859
+					$temp = cache_get_data('topic_board-' . $topic, 120);
860
+		} else {
861
+					$temp = cache_get_data('board-' . $board, 120);
862
+		}
822 863
 
823 864
 		if (!empty($temp))
824 865
 		{
@@ -856,8 +897,9 @@  discard block
 block discarded – undo
856 897
 			$row = $smcFunc['db_fetch_assoc']($request);
857 898
 
858 899
 			// Set the current board.
859
-			if (!empty($row['id_board']))
860
-				$board = $row['id_board'];
900
+			if (!empty($row['id_board'])) {
901
+							$board = $row['id_board'];
902
+			}
861 903
 
862 904
 			// Basic operating information. (globals... :/)
863 905
 			$board_info = array(
@@ -893,21 +935,23 @@  discard block
 block discarded – undo
893 935
 
894 936
 			do
895 937
 			{
896
-				if (!empty($row['id_moderator']))
897
-					$board_info['moderators'][$row['id_moderator']] = array(
938
+				if (!empty($row['id_moderator'])) {
939
+									$board_info['moderators'][$row['id_moderator']] = array(
898 940
 						'id' => $row['id_moderator'],
899 941
 						'name' => $row['real_name'],
900 942
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
901 943
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
902 944
 					);
945
+				}
903 946
 
904
-				if (!empty($row['id_moderator_group']))
905
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
947
+				if (!empty($row['id_moderator_group'])) {
948
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
906 949
 						'id' => $row['id_moderator_group'],
907 950
 						'name' => $row['group_name'],
908 951
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
909 952
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
910 953
 					);
954
+				}
911 955
 			}
912 956
 			while ($row = $smcFunc['db_fetch_assoc']($request));
913 957
 
@@ -939,12 +983,12 @@  discard block
 block discarded – undo
939 983
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
940 984
 			{
941 985
 				// @todo SLOW?
942
-				if (!empty($topic))
943
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
986
+				if (!empty($topic)) {
987
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
988
+				}
944 989
 				cache_put_data('board-' . $board, $board_info, 120);
945 990
 			}
946
-		}
947
-		else
991
+		} else
948 992
 		{
949 993
 			// Otherwise the topic is invalid, there are no moderators, etc.
950 994
 			$board_info = array(
@@ -958,8 +1002,9 @@  discard block
 block discarded – undo
958 1002
 		$smcFunc['db_free_result']($request);
959 1003
 	}
960 1004
 
961
-	if (!empty($topic))
962
-		$_GET['board'] = (int) $board;
1005
+	if (!empty($topic)) {
1006
+			$_GET['board'] = (int) $board;
1007
+	}
963 1008
 
964 1009
 	if (!empty($board))
965 1010
 	{
@@ -969,10 +1014,12 @@  discard block
 block discarded – undo
969 1014
 		// Now check if the user is a moderator.
970 1015
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
971 1016
 
972
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
973
-			$board_info['error'] = 'access';
974
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
975
-			$board_info['error'] = 'access';
1017
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1018
+					$board_info['error'] = 'access';
1019
+		}
1020
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1021
+					$board_info['error'] = 'access';
1022
+		}
976 1023
 
977 1024
 		// Build up the linktree.
978 1025
 		$context['linktree'] = array_merge(
@@ -995,8 +1042,9 @@  discard block
 block discarded – undo
995 1042
 	$context['current_board'] = $board;
996 1043
 
997 1044
 	// No posting in redirection boards!
998
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
999
-		$board_info['error'] == 'post_in_redirect';
1045
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1046
+			$board_info['error'] == 'post_in_redirect';
1047
+	}
1000 1048
 
1001 1049
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1002 1050
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1022,24 +1070,23 @@  discard block
 block discarded – undo
1022 1070
 			ob_end_clean();
1023 1071
 			header('HTTP/1.1 403 Forbidden');
1024 1072
 			die;
1025
-		}
1026
-		elseif ($board_info['error'] == 'post_in_redirect')
1073
+		} elseif ($board_info['error'] == 'post_in_redirect')
1027 1074
 		{
1028 1075
 			// Slightly different error message here...
1029 1076
 			fatal_lang_error('cannot_post_redirect', false);
1030
-		}
1031
-		elseif ($user_info['is_guest'])
1077
+		} elseif ($user_info['is_guest'])
1032 1078
 		{
1033 1079
 			loadLanguage('Errors');
1034 1080
 			is_not_guest($txt['topic_gone']);
1081
+		} else {
1082
+					fatal_lang_error('topic_gone', false);
1035 1083
 		}
1036
-		else
1037
-			fatal_lang_error('topic_gone', false);
1038 1084
 	}
1039 1085
 
1040
-	if ($user_info['is_mod'])
1041
-		$user_info['groups'][] = 3;
1042
-}
1086
+	if ($user_info['is_mod']) {
1087
+			$user_info['groups'][] = 3;
1088
+	}
1089
+	}
1043 1090
 
1044 1091
 /**
1045 1092
  * Load this user's permissions.
@@ -1060,8 +1107,9 @@  discard block
 block discarded – undo
1060 1107
 		asort($cache_groups);
1061 1108
 		$cache_groups = implode(',', $cache_groups);
1062 1109
 		// If it's a spider then cache it different.
1063
-		if ($user_info['possibly_robot'])
1064
-			$cache_groups .= '-spider';
1110
+		if ($user_info['possibly_robot']) {
1111
+					$cache_groups .= '-spider';
1112
+		}
1065 1113
 
1066 1114
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1067 1115
 		{
@@ -1069,9 +1117,9 @@  discard block
 block discarded – undo
1069 1117
 			banPermissions();
1070 1118
 
1071 1119
 			return;
1120
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1121
+					list ($user_info['permissions'], $removals) = $temp;
1072 1122
 		}
1073
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1074
-			list ($user_info['permissions'], $removals) = $temp;
1075 1123
 	}
1076 1124
 
1077 1125
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1093,23 +1141,26 @@  discard block
 block discarded – undo
1093 1141
 		$removals = array();
1094 1142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1095 1143
 		{
1096
-			if (empty($row['add_deny']))
1097
-				$removals[] = $row['permission'];
1098
-			else
1099
-				$user_info['permissions'][] = $row['permission'];
1144
+			if (empty($row['add_deny'])) {
1145
+							$removals[] = $row['permission'];
1146
+			} else {
1147
+							$user_info['permissions'][] = $row['permission'];
1148
+			}
1100 1149
 		}
1101 1150
 		$smcFunc['db_free_result']($request);
1102 1151
 
1103
-		if (isset($cache_groups))
1104
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1152
+		if (isset($cache_groups)) {
1153
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1154
+		}
1105 1155
 	}
1106 1156
 
1107 1157
 	// Get the board permissions.
1108 1158
 	if (!empty($board))
1109 1159
 	{
1110 1160
 		// Make sure the board (if any) has been loaded by loadBoard().
1111
-		if (!isset($board_info['profile']))
1112
-			fatal_lang_error('no_board');
1161
+		if (!isset($board_info['profile'])) {
1162
+					fatal_lang_error('no_board');
1163
+		}
1113 1164
 
1114 1165
 		$request = $smcFunc['db_query']('', '
1115 1166
 			SELECT permission, add_deny
@@ -1125,20 +1176,23 @@  discard block
 block discarded – undo
1125 1176
 		);
1126 1177
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1127 1178
 		{
1128
-			if (empty($row['add_deny']))
1129
-				$removals[] = $row['permission'];
1130
-			else
1131
-				$user_info['permissions'][] = $row['permission'];
1179
+			if (empty($row['add_deny'])) {
1180
+							$removals[] = $row['permission'];
1181
+			} else {
1182
+							$user_info['permissions'][] = $row['permission'];
1183
+			}
1132 1184
 		}
1133 1185
 		$smcFunc['db_free_result']($request);
1134 1186
 	}
1135 1187
 
1136 1188
 	// Remove all the permissions they shouldn't have ;).
1137
-	if (!empty($modSettings['permission_enable_deny']))
1138
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1189
+	if (!empty($modSettings['permission_enable_deny'])) {
1190
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1191
+	}
1139 1192
 
1140
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1141
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1193
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1194
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1195
+	}
1142 1196
 
1143 1197
 	// Banned?  Watch, don't touch..
1144 1198
 	banPermissions();
@@ -1150,17 +1204,18 @@  discard block
 block discarded – undo
1150 1204
 		{
1151 1205
 			require_once($sourcedir . '/Subs-Auth.php');
1152 1206
 			rebuildModCache();
1207
+		} else {
1208
+					$user_info['mod_cache'] = $_SESSION['mc'];
1153 1209
 		}
1154
-		else
1155
-			$user_info['mod_cache'] = $_SESSION['mc'];
1156 1210
 
1157 1211
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1158 1212
 		// For example this drastically simplifies certain changes to the profile area.
1159 1213
 		$user_info['permissions'][] = 'is_not_guest';
1160 1214
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1161 1215
 		$user_info['permissions'][] = 'profile_view_own';
1162
-		if (in_array('profile_view', $user_info['permissions']))
1163
-			$user_info['permissions'][] = 'profile_view_any';
1216
+		if (in_array('profile_view', $user_info['permissions'])) {
1217
+					$user_info['permissions'][] = 'profile_view_any';
1218
+		}
1164 1219
 	}
1165 1220
 }
1166 1221
 
@@ -1178,8 +1233,9 @@  discard block
 block discarded – undo
1178 1233
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1179 1234
 
1180 1235
 	// Can't just look for no users :P.
1181
-	if (empty($users))
1182
-		return array();
1236
+	if (empty($users)) {
1237
+			return array();
1238
+	}
1183 1239
 
1184 1240
 	// Pass the set value
1185 1241
 	$context['loadMemberContext_set'] = $set;
@@ -1194,8 +1250,9 @@  discard block
 block discarded – undo
1194 1250
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1195 1251
 		{
1196 1252
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1197
-			if ($data == null)
1198
-				continue;
1253
+			if ($data == null) {
1254
+							continue;
1255
+			}
1199 1256
 
1200 1257
 			$loaded_ids[] = $data['id_member'];
1201 1258
 			$user_profile[$data['id_member']] = $data;
@@ -1259,13 +1316,16 @@  discard block
 block discarded – undo
1259 1316
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1260 1317
 		{
1261 1318
 			// Take care of proxying avatar if required, do this here for maximum reach
1262
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1263
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1319
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1320
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1321
+			}
1264 1322
 
1265
-			if ( isset($row['member_ip']) )
1266
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1267
-			if ( isset($row['member_ip2']) )
1268
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1323
+			if ( isset($row['member_ip']) ) {
1324
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1325
+			}
1326
+			if ( isset($row['member_ip2']) ) {
1327
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1328
+			}
1269 1329
 			$new_loaded_ids[] = $row['id_member'];
1270 1330
 			$loaded_ids[] = $row['id_member'];
1271 1331
 			$row['options'] = array();
@@ -1284,8 +1344,9 @@  discard block
 block discarded – undo
1284 1344
 				'loaded_ids' => $new_loaded_ids,
1285 1345
 			)
1286 1346
 		);
1287
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1288
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1347
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1348
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1349
+		}
1289 1350
 		$smcFunc['db_free_result']($request);
1290 1351
 	}
1291 1352
 
@@ -1296,10 +1357,11 @@  discard block
 block discarded – undo
1296 1357
 	{
1297 1358
 		foreach ($loaded_ids as $a_member)
1298 1359
 		{
1299
-			if (!empty($user_profile[$a_member]['additional_groups']))
1300
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1301
-			else
1302
-				$groups = array($user_profile[$a_member]['id_group']);
1360
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1361
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1362
+			} else {
1363
+							$groups = array($user_profile[$a_member]['id_group']);
1364
+			}
1303 1365
 
1304 1366
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1305 1367
 
@@ -1312,8 +1374,9 @@  discard block
 block discarded – undo
1312 1374
 
1313 1375
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1314 1376
 	{
1315
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1316
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1377
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1378
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1379
+		}
1317 1380
 	}
1318 1381
 
1319 1382
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1339,14 +1402,17 @@  discard block
 block discarded – undo
1339 1402
 		foreach ($temp_mods as $id)
1340 1403
 		{
1341 1404
 			// By popular demand, don't show admins or global moderators as moderators.
1342
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1343
-				$user_profile[$id]['member_group'] = $row['member_group'];
1405
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1406
+							$user_profile[$id]['member_group'] = $row['member_group'];
1407
+			}
1344 1408
 
1345 1409
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1346
-			if (!empty($row['icons']))
1347
-				$user_profile[$id]['icons'] = $row['icons'];
1348
-			if (!empty($row['member_group_color']))
1349
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1410
+			if (!empty($row['icons'])) {
1411
+							$user_profile[$id]['icons'] = $row['icons'];
1412
+			}
1413
+			if (!empty($row['member_group_color'])) {
1414
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1415
+			}
1350 1416
 		}
1351 1417
 	}
1352 1418
 
@@ -1368,12 +1434,14 @@  discard block
 block discarded – undo
1368 1434
 	static $loadedLanguages = array();
1369 1435
 
1370 1436
 	// If this person's data is already loaded, skip it.
1371
-	if (isset($dataLoaded[$user]))
1372
-		return true;
1437
+	if (isset($dataLoaded[$user])) {
1438
+			return true;
1439
+	}
1373 1440
 
1374 1441
 	// We can't load guests or members not loaded by loadMemberData()!
1375
-	if ($user == 0)
1376
-		return false;
1442
+	if ($user == 0) {
1443
+			return false;
1444
+	}
1377 1445
 	if (!isset($user_profile[$user]))
1378 1446
 	{
1379 1447
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1399,12 +1467,16 @@  discard block
 block discarded – undo
1399 1467
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1400 1468
 
1401 1469
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1402
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1470
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1471
+		//icon is set and exists
1403 1472
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1404
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1473
+	} elseif (isset($profile['icons'][1])) {
1474
+		//icon is set and doesn't exist, fallback to default
1405 1475
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1406
-	else //not set, bye bye
1476
+	} else {
1477
+		//not set, bye bye
1407 1478
 		$group_icon_url = '';
1479
+	}
1408 1480
 
1409 1481
 	// These minimal values are always loaded
1410 1482
 	$memberContext[$user] = array(
@@ -1423,8 +1495,9 @@  discard block
 block discarded – undo
1423 1495
 	if ($context['loadMemberContext_set'] != 'minimal')
1424 1496
 	{
1425 1497
 		// Go the extra mile and load the user's native language name.
1426
-		if (empty($loadedLanguages))
1427
-			$loadedLanguages = getLanguages();
1498
+		if (empty($loadedLanguages)) {
1499
+					$loadedLanguages = getLanguages();
1500
+		}
1428 1501
 
1429 1502
 		$memberContext[$user] += array(
1430 1503
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
@@ -1478,31 +1551,33 @@  discard block
 block discarded – undo
1478 1551
 	{
1479 1552
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1480 1553
 		{
1481
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1482
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1483
-			else
1484
-				$image = get_gravatar_url($profile['email_address']);
1485
-		}
1486
-		else
1554
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1555
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1556
+			} else {
1557
+							$image = get_gravatar_url($profile['email_address']);
1558
+			}
1559
+		} else
1487 1560
 		{
1488 1561
 			// So it's stored in the member table?
1489 1562
 			if (!empty($profile['avatar']))
1490 1563
 			{
1491 1564
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1565
+			} elseif (!empty($profile['filename'])) {
1566
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1492 1567
 			}
1493
-			elseif (!empty($profile['filename']))
1494
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1495 1568
 			// Right... no avatar...use the default one
1496
-			else
1497
-				$image = $modSettings['avatar_url'] . '/default.png';
1569
+			else {
1570
+							$image = $modSettings['avatar_url'] . '/default.png';
1571
+			}
1498 1572
 		}
1499
-		if (!empty($image))
1500
-			$memberContext[$user]['avatar'] = array(
1573
+		if (!empty($image)) {
1574
+					$memberContext[$user]['avatar'] = array(
1501 1575
 				'name' => $profile['avatar'],
1502 1576
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1503 1577
 				'href' => $image,
1504 1578
 				'url' => $image,
1505 1579
 			);
1580
+		}
1506 1581
 	}
1507 1582
 
1508 1583
 	// Are we also loading the members custom fields into context?
@@ -1510,35 +1585,41 @@  discard block
 block discarded – undo
1510 1585
 	{
1511 1586
 		$memberContext[$user]['custom_fields'] = array();
1512 1587
 
1513
-		if (!isset($context['display_fields']))
1514
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1588
+		if (!isset($context['display_fields'])) {
1589
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1590
+		}
1515 1591
 
1516 1592
 		foreach ($context['display_fields'] as $custom)
1517 1593
 		{
1518
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1519
-				continue;
1594
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1595
+							continue;
1596
+			}
1520 1597
 
1521 1598
 			$value = $profile['options'][$custom['col_name']];
1522 1599
 
1523 1600
 			// Don't show the "disabled" option for the "gender" field.
1524
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1525
-				continue;
1601
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1602
+							continue;
1603
+			}
1526 1604
 
1527 1605
 			// BBC?
1528
-			if ($custom['bbc'])
1529
-				$value = parse_bbc($value);
1606
+			if ($custom['bbc']) {
1607
+							$value = parse_bbc($value);
1608
+			}
1530 1609
 			// ... or checkbox?
1531
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1532
-				$value = $value ? $txt['yes'] : $txt['no'];
1610
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1611
+							$value = $value ? $txt['yes'] : $txt['no'];
1612
+			}
1533 1613
 
1534 1614
 			// Enclosing the user input within some other text?
1535
-			if (!empty($custom['enclose']))
1536
-				$value = strtr($custom['enclose'], array(
1615
+			if (!empty($custom['enclose'])) {
1616
+							$value = strtr($custom['enclose'], array(
1537 1617
 					'{SCRIPTURL}' => $scripturl,
1538 1618
 					'{IMAGES_URL}' => $settings['images_url'],
1539 1619
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1540 1620
 					'{INPUT}' => $value,
1541 1621
 				));
1622
+			}
1542 1623
 
1543 1624
 			$memberContext[$user]['custom_fields'][] = array(
1544 1625
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1565,8 +1646,9 @@  discard block
 block discarded – undo
1565 1646
 	global $smcFunc, $txt, $scripturl, $settings;
1566 1647
 
1567 1648
 	// Do not waste my time...
1568
-	if (empty($users) || empty($params))
1569
-		return false;
1649
+	if (empty($users) || empty($params)) {
1650
+			return false;
1651
+	}
1570 1652
 
1571 1653
 	// Make sure it's an array.
1572 1654
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1590,31 +1672,36 @@  discard block
 block discarded – undo
1590 1672
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1591 1673
 	{
1592 1674
 		// BBC?
1593
-		if (!empty($row['bbc']))
1594
-			$row['value'] = parse_bbc($row['value']);
1675
+		if (!empty($row['bbc'])) {
1676
+					$row['value'] = parse_bbc($row['value']);
1677
+		}
1595 1678
 
1596 1679
 		// ... or checkbox?
1597
-		elseif (isset($row['type']) && $row['type'] == 'check')
1598
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1680
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1681
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1682
+		}
1599 1683
 
1600 1684
 		// Enclosing the user input within some other text?
1601
-		if (!empty($row['enclose']))
1602
-			$row['value'] = strtr($row['enclose'], array(
1685
+		if (!empty($row['enclose'])) {
1686
+					$row['value'] = strtr($row['enclose'], array(
1603 1687
 				'{SCRIPTURL}' => $scripturl,
1604 1688
 				'{IMAGES_URL}' => $settings['images_url'],
1605 1689
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1606 1690
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1607 1691
 			));
1692
+		}
1608 1693
 
1609 1694
 		// Send a simple array if there is just 1 param
1610
-		if (count($params) == 1)
1611
-			$return[$row['id_member']] = $row;
1695
+		if (count($params) == 1) {
1696
+					$return[$row['id_member']] = $row;
1697
+		}
1612 1698
 
1613 1699
 		// More than 1? knock yourself out...
1614 1700
 		else
1615 1701
 		{
1616
-			if (!isset($return[$row['id_member']]))
1617
-				$return[$row['id_member']] = array();
1702
+			if (!isset($return[$row['id_member']])) {
1703
+							$return[$row['id_member']] = array();
1704
+			}
1618 1705
 
1619 1706
 			$return[$row['id_member']][$row['variable']] = $row;
1620 1707
 		}
@@ -1648,8 +1735,9 @@  discard block
 block discarded – undo
1648 1735
 	global $context;
1649 1736
 
1650 1737
 	// Don't know any browser!
1651
-	if (empty($context['browser']))
1652
-		detectBrowser();
1738
+	if (empty($context['browser'])) {
1739
+			detectBrowser();
1740
+	}
1653 1741
 
1654 1742
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1655 1743
 }
@@ -1667,8 +1755,9 @@  discard block
 block discarded – undo
1667 1755
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1668 1756
 
1669 1757
 	// The theme was specified by parameter.
1670
-	if (!empty($id_theme))
1671
-		$id_theme = (int) $id_theme;
1758
+	if (!empty($id_theme)) {
1759
+			$id_theme = (int) $id_theme;
1760
+	}
1672 1761
 	// The theme was specified by REQUEST.
1673 1762
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1674 1763
 	{
@@ -1676,51 +1765,58 @@  discard block
 block discarded – undo
1676 1765
 		$_SESSION['id_theme'] = $id_theme;
1677 1766
 	}
1678 1767
 	// The theme was specified by REQUEST... previously.
1679
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1680
-		$id_theme = (int) $_SESSION['id_theme'];
1768
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1769
+			$id_theme = (int) $_SESSION['id_theme'];
1770
+	}
1681 1771
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1682
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1683
-		$id_theme = $user_info['theme'];
1772
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1773
+			$id_theme = $user_info['theme'];
1774
+	}
1684 1775
 	// The theme was specified by the board.
1685
-	elseif (!empty($board_info['theme']))
1686
-		$id_theme = $board_info['theme'];
1776
+	elseif (!empty($board_info['theme'])) {
1777
+			$id_theme = $board_info['theme'];
1778
+	}
1687 1779
 	// The theme is the forum's default.
1688
-	else
1689
-		$id_theme = $modSettings['theme_guests'];
1780
+	else {
1781
+			$id_theme = $modSettings['theme_guests'];
1782
+	}
1690 1783
 
1691 1784
 	// Verify the id_theme... no foul play.
1692 1785
 	// Always allow the board specific theme, if they are overriding.
1693
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1694
-		$id_theme = $board_info['theme'];
1786
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1787
+			$id_theme = $board_info['theme'];
1788
+	}
1695 1789
 	// If they have specified a particular theme to use with SSI allow it to be used.
1696
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1697
-		$id_theme = (int) $id_theme;
1698
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1790
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1791
+			$id_theme = (int) $id_theme;
1792
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1699 1793
 	{
1700 1794
 		$themes = explode(',', $modSettings['enableThemes']);
1701
-		if (!in_array($id_theme, $themes))
1702
-			$id_theme = $modSettings['theme_guests'];
1703
-		else
1795
+		if (!in_array($id_theme, $themes)) {
1796
+					$id_theme = $modSettings['theme_guests'];
1797
+		} else {
1798
+					$id_theme = (int) $id_theme;
1799
+		}
1800
+	} else {
1704 1801
 			$id_theme = (int) $id_theme;
1705 1802
 	}
1706
-	else
1707
-		$id_theme = (int) $id_theme;
1708 1803
 
1709 1804
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1710 1805
 
1711 1806
 	// Disable image proxy if we don't have SSL enabled
1712
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1713
-		$image_proxy_enabled = false;
1807
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1808
+			$image_proxy_enabled = false;
1809
+	}
1714 1810
 
1715 1811
 	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'])
1716 1812
 	{
1717 1813
 		$themeData = $temp;
1718 1814
 		$flag = true;
1815
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1816
+			$themeData = $temp + array($member => array());
1817
+	} else {
1818
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1719 1819
 	}
1720
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1721
-		$themeData = $temp + array($member => array());
1722
-	else
1723
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1724 1820
 
1725 1821
 	if (empty($flag))
1726 1822
 	{
@@ -1739,31 +1835,37 @@  discard block
 block discarded – undo
1739 1835
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1740 1836
 		{
1741 1837
 			// There are just things we shouldn't be able to change as members.
1742
-			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')))
1743
-				continue;
1838
+			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'))) {
1839
+							continue;
1840
+			}
1744 1841
 
1745 1842
 			// If this is the theme_dir of the default theme, store it.
1746
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1747
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1843
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1844
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1845
+			}
1748 1846
 
1749 1847
 			// If this isn't set yet, is a theme option, or is not the default theme..
1750
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1751
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1848
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1849
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1850
+			}
1752 1851
 		}
1753 1852
 		$smcFunc['db_free_result']($result);
1754 1853
 
1755
-		if (!empty($themeData[-1]))
1756
-			foreach ($themeData[-1] as $k => $v)
1854
+		if (!empty($themeData[-1])) {
1855
+					foreach ($themeData[-1] as $k => $v)
1757 1856
 			{
1758 1857
 				if (!isset($themeData[$member][$k]))
1759 1858
 					$themeData[$member][$k] = $v;
1859
+		}
1760 1860
 			}
1761 1861
 
1762
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1763
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1862
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1863
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1864
+		}
1764 1865
 		// Only if we didn't already load that part of the cache...
1765
-		elseif (!isset($temp))
1766
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1866
+		elseif (!isset($temp)) {
1867
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1868
+		}
1767 1869
 	}
1768 1870
 
1769 1871
 	$settings = $themeData[0];
@@ -1780,20 +1882,24 @@  discard block
 block discarded – undo
1780 1882
 	$settings['template_dirs'][] = $settings['theme_dir'];
1781 1883
 
1782 1884
 	// Based on theme (if there is one).
1783
-	if (!empty($settings['base_theme_dir']))
1784
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1885
+	if (!empty($settings['base_theme_dir'])) {
1886
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1887
+	}
1785 1888
 
1786 1889
 	// Lastly the default theme.
1787
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1788
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1890
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1891
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1892
+	}
1789 1893
 
1790
-	if (!$initialize)
1791
-		return;
1894
+	if (!$initialize) {
1895
+			return;
1896
+	}
1792 1897
 
1793 1898
 	// Check to see if we're forcing SSL
1794 1899
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1795
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1796
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1900
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1901
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1902
+	}
1797 1903
 
1798 1904
 	// Check to see if they're accessing it from the wrong place.
1799 1905
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1801,8 +1907,9 @@  discard block
 block discarded – undo
1801 1907
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1802 1908
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1803 1909
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1804
-		if ($temp != '/')
1805
-			$detected_url .= $temp;
1910
+		if ($temp != '/') {
1911
+					$detected_url .= $temp;
1912
+		}
1806 1913
 	}
1807 1914
 	if (isset($detected_url) && $detected_url != $boardurl)
1808 1915
 	{
@@ -1814,8 +1921,9 @@  discard block
 block discarded – undo
1814 1921
 			foreach ($aliases as $alias)
1815 1922
 			{
1816 1923
 				// Rip off all the boring parts, spaces, etc.
1817
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1818
-					$do_fix = true;
1924
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1925
+									$do_fix = true;
1926
+				}
1819 1927
 			}
1820 1928
 		}
1821 1929
 
@@ -1823,20 +1931,22 @@  discard block
 block discarded – undo
1823 1931
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1824 1932
 		{
1825 1933
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1826
-			if (empty($_GET))
1827
-				redirectexit('wwwRedirect');
1828
-			else
1934
+			if (empty($_GET)) {
1935
+							redirectexit('wwwRedirect');
1936
+			} else
1829 1937
 			{
1830 1938
 				list ($k, $v) = each($_GET);
1831 1939
 
1832
-				if ($k != 'wwwRedirect')
1833
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1940
+				if ($k != 'wwwRedirect') {
1941
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1942
+				}
1834 1943
 			}
1835 1944
 		}
1836 1945
 
1837 1946
 		// #3 is just a check for SSL...
1838
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1839
-			$do_fix = true;
1947
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1948
+					$do_fix = true;
1949
+		}
1840 1950
 
1841 1951
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1842 1952
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1870,8 +1980,9 @@  discard block
 block discarded – undo
1870 1980
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1871 1981
 				}
1872 1982
 			}
1873
-			foreach ($context['linktree'] as $k => $dummy)
1874
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1983
+			foreach ($context['linktree'] as $k => $dummy) {
1984
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1985
+			}
1875 1986
 		}
1876 1987
 	}
1877 1988
 	// Set up the contextual user array.
@@ -1890,16 +2001,16 @@  discard block
 block discarded – undo
1890 2001
 			'email' => $user_info['email'],
1891 2002
 			'ignoreusers' => $user_info['ignoreusers'],
1892 2003
 		);
1893
-		if (!$context['user']['is_guest'])
1894
-			$context['user']['name'] = $user_info['name'];
1895
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1896
-			$context['user']['name'] = $txt['guest_title'];
2004
+		if (!$context['user']['is_guest']) {
2005
+					$context['user']['name'] = $user_info['name'];
2006
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2007
+					$context['user']['name'] = $txt['guest_title'];
2008
+		}
1897 2009
 
1898 2010
 		// Determine the current smiley set.
1899 2011
 		$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'];
1900 2012
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1901
-	}
1902
-	else
2013
+	} else
1903 2014
 	{
1904 2015
 		$context['user'] = array(
1905 2016
 			'id' => -1,
@@ -1915,18 +2026,24 @@  discard block
 block discarded – undo
1915 2026
 	}
1916 2027
 
1917 2028
 	// Some basic information...
1918
-	if (!isset($context['html_headers']))
1919
-		$context['html_headers'] = '';
1920
-	if (!isset($context['javascript_files']))
1921
-		$context['javascript_files'] = array();
1922
-	if (!isset($context['css_files']))
1923
-		$context['css_files'] = array();
1924
-	if (!isset($context['css_header']))
1925
-		$context['css_header'] = array();
1926
-	if (!isset($context['javascript_inline']))
1927
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1928
-	if (!isset($context['javascript_vars']))
1929
-		$context['javascript_vars'] = array();
2029
+	if (!isset($context['html_headers'])) {
2030
+			$context['html_headers'] = '';
2031
+	}
2032
+	if (!isset($context['javascript_files'])) {
2033
+			$context['javascript_files'] = array();
2034
+	}
2035
+	if (!isset($context['css_files'])) {
2036
+			$context['css_files'] = array();
2037
+	}
2038
+	if (!isset($context['css_header'])) {
2039
+			$context['css_header'] = array();
2040
+	}
2041
+	if (!isset($context['javascript_inline'])) {
2042
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2043
+	}
2044
+	if (!isset($context['javascript_vars'])) {
2045
+			$context['javascript_vars'] = array();
2046
+	}
1930 2047
 
1931 2048
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1932 2049
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1938,8 +2055,9 @@  discard block
 block discarded – undo
1938 2055
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1939 2056
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1940 2057
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1941
-	if (isset($modSettings['load_average']))
1942
-		$context['load_average'] = $modSettings['load_average'];
2058
+	if (isset($modSettings['load_average'])) {
2059
+			$context['load_average'] = $modSettings['load_average'];
2060
+	}
1943 2061
 
1944 2062
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1945 2063
 	detectBrowser();
@@ -1953,8 +2071,9 @@  discard block
 block discarded – undo
1953 2071
 	// This allows sticking some HTML on the page output - useful for controls.
1954 2072
 	$context['insert_after_template'] = '';
1955 2073
 
1956
-	if (!isset($txt))
1957
-		$txt = array();
2074
+	if (!isset($txt)) {
2075
+			$txt = array();
2076
+	}
1958 2077
 
1959 2078
 	$simpleActions = array(
1960 2079
 		'findmember',
@@ -2000,9 +2119,10 @@  discard block
 block discarded – undo
2000 2119
 
2001 2120
 	// See if theres any extra param to check.
2002 2121
 	$requiresXML = false;
2003
-	foreach ($extraParams as $key => $extra)
2004
-		if (isset($_REQUEST[$extra]))
2122
+	foreach ($extraParams as $key => $extra) {
2123
+			if (isset($_REQUEST[$extra]))
2005 2124
 			$requiresXML = true;
2125
+	}
2006 2126
 
2007 2127
 	// Output is fully XML, so no need for the index template.
2008 2128
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2017,37 +2137,39 @@  discard block
 block discarded – undo
2017 2137
 	{
2018 2138
 		loadLanguage('index+Modifications');
2019 2139
 		$context['template_layers'] = array();
2020
-	}
2021
-
2022
-	else
2140
+	} else
2023 2141
 	{
2024 2142
 		// Custom templates to load, or just default?
2025
-		if (isset($settings['theme_templates']))
2026
-			$templates = explode(',', $settings['theme_templates']);
2027
-		else
2028
-			$templates = array('index');
2143
+		if (isset($settings['theme_templates'])) {
2144
+					$templates = explode(',', $settings['theme_templates']);
2145
+		} else {
2146
+					$templates = array('index');
2147
+		}
2029 2148
 
2030 2149
 		// Load each template...
2031
-		foreach ($templates as $template)
2032
-			loadTemplate($template);
2150
+		foreach ($templates as $template) {
2151
+					loadTemplate($template);
2152
+		}
2033 2153
 
2034 2154
 		// ...and attempt to load their associated language files.
2035 2155
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2036 2156
 		loadLanguage($required_files, '', false);
2037 2157
 
2038 2158
 		// Custom template layers?
2039
-		if (isset($settings['theme_layers']))
2040
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2041
-		else
2042
-			$context['template_layers'] = array('html', 'body');
2159
+		if (isset($settings['theme_layers'])) {
2160
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2161
+		} else {
2162
+					$context['template_layers'] = array('html', 'body');
2163
+		}
2043 2164
 	}
2044 2165
 
2045 2166
 	// Initialize the theme.
2046 2167
 	loadSubTemplate('init', 'ignore');
2047 2168
 
2048 2169
 	// Allow overriding the board wide time/number formats.
2049
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2050
-		$user_info['time_format'] = $txt['time_format'];
2170
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2171
+			$user_info['time_format'] = $txt['time_format'];
2172
+	}
2051 2173
 
2052 2174
 	// Set the character set from the template.
2053 2175
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2055,12 +2177,14 @@  discard block
 block discarded – undo
2055 2177
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2056 2178
 
2057 2179
 	// Guests may still need a name.
2058
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2059
-		$context['user']['name'] = $txt['guest_title'];
2180
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2181
+			$context['user']['name'] = $txt['guest_title'];
2182
+	}
2060 2183
 
2061 2184
 	// Any theme-related strings that need to be loaded?
2062
-	if (!empty($settings['require_theme_strings']))
2063
-		loadLanguage('ThemeStrings', '', false);
2185
+	if (!empty($settings['require_theme_strings'])) {
2186
+			loadLanguage('ThemeStrings', '', false);
2187
+	}
2064 2188
 
2065 2189
 	// Make a special URL for the language.
2066 2190
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2071,8 +2195,9 @@  discard block
 block discarded – undo
2071 2195
 	// Here is my luvly Responsive CSS
2072 2196
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2073 2197
 
2074
-	if ($context['right_to_left'])
2075
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2198
+	if ($context['right_to_left']) {
2199
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2200
+	}
2076 2201
 
2077 2202
 	// We allow theme variants, because we're cool.
2078 2203
 	$context['theme_variant'] = '';
@@ -2080,14 +2205,17 @@  discard block
 block discarded – undo
2080 2205
 	if (!empty($settings['theme_variants']))
2081 2206
 	{
2082 2207
 		// Overriding - for previews and that ilk.
2083
-		if (!empty($_REQUEST['variant']))
2084
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2208
+		if (!empty($_REQUEST['variant'])) {
2209
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2210
+		}
2085 2211
 		// User selection?
2086
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2087
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2212
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2213
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2214
+		}
2088 2215
 		// If not a user variant, select the default.
2089
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2090
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2216
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2217
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2218
+		}
2091 2219
 
2092 2220
 		// Do this to keep things easier in the templates.
2093 2221
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2096,20 +2224,23 @@  discard block
 block discarded – undo
2096 2224
 		if (!empty($context['theme_variant']))
2097 2225
 		{
2098 2226
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2099
-			if ($context['right_to_left'])
2100
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2227
+			if ($context['right_to_left']) {
2228
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2229
+			}
2101 2230
 		}
2102 2231
 	}
2103 2232
 
2104 2233
 	// Let's be compatible with old themes!
2105
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2106
-		$context['template_layers'] = array('main');
2234
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2235
+			$context['template_layers'] = array('main');
2236
+	}
2107 2237
 
2108 2238
 	$context['tabindex'] = 1;
2109 2239
 
2110 2240
 	// Compatibility.
2111
-	if (!isset($settings['theme_version']))
2112
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2241
+	if (!isset($settings['theme_version'])) {
2242
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2243
+	}
2113 2244
 
2114 2245
 	// Default JS variables for use in every theme
2115 2246
 	$context['javascript_vars'] = array(
@@ -2128,18 +2259,18 @@  discard block
 block discarded – undo
2128 2259
 	);
2129 2260
 
2130 2261
 	// Add the JQuery library to the list of files to load.
2131
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2132
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2133
-
2134
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2135
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2136
-
2137
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2138
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2262
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2263
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2264
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2265
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2266
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2267
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2268
+	}
2139 2269
 
2140 2270
 	// Auto loading? template_javascript() will take care of the local half of this.
2141
-	else
2142
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2271
+	else {
2272
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2273
+	}
2143 2274
 
2144 2275
 	// Queue our JQuery plugins!
2145 2276
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2162,12 +2293,12 @@  discard block
 block discarded – undo
2162 2293
 			require_once($sourcedir . '/ScheduledTasks.php');
2163 2294
 
2164 2295
 			// What to do, what to do?!
2165
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2166
-				AutoTask();
2167
-			else
2168
-				ReduceMailQueue();
2169
-		}
2170
-		else
2296
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2297
+							AutoTask();
2298
+			} else {
2299
+							ReduceMailQueue();
2300
+			}
2301
+		} else
2171 2302
 		{
2172 2303
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2173 2304
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2218,8 +2349,9 @@  discard block
 block discarded – undo
2218 2349
 		foreach ($theme_includes as $include)
2219 2350
 		{
2220 2351
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2221
-			if (file_exists($include))
2222
-				require_once($include);
2352
+			if (file_exists($include)) {
2353
+							require_once($include);
2354
+			}
2223 2355
 		}
2224 2356
 	}
2225 2357
 
@@ -2249,16 +2381,19 @@  discard block
 block discarded – undo
2249 2381
 	// Do any style sheets first, cause we're easy with those.
2250 2382
 	if (!empty($style_sheets))
2251 2383
 	{
2252
-		if (!is_array($style_sheets))
2253
-			$style_sheets = array($style_sheets);
2384
+		if (!is_array($style_sheets)) {
2385
+					$style_sheets = array($style_sheets);
2386
+		}
2254 2387
 
2255
-		foreach ($style_sheets as $sheet)
2256
-			loadCSSFile($sheet . '.css', array(), $sheet);
2388
+		foreach ($style_sheets as $sheet) {
2389
+					loadCSSFile($sheet . '.css', array(), $sheet);
2390
+		}
2257 2391
 	}
2258 2392
 
2259 2393
 	// No template to load?
2260
-	if ($template_name === false)
2261
-		return true;
2394
+	if ($template_name === false) {
2395
+			return true;
2396
+	}
2262 2397
 
2263 2398
 	$loaded = false;
2264 2399
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2273,12 +2408,14 @@  discard block
 block discarded – undo
2273 2408
 
2274 2409
 	if ($loaded)
2275 2410
 	{
2276
-		if ($db_show_debug === true)
2277
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2411
+		if ($db_show_debug === true) {
2412
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2413
+		}
2278 2414
 
2279 2415
 		// If they have specified an initialization function for this template, go ahead and call it now.
2280
-		if (function_exists('template_' . $template_name . '_init'))
2281
-			call_user_func('template_' . $template_name . '_init');
2416
+		if (function_exists('template_' . $template_name . '_init')) {
2417
+					call_user_func('template_' . $template_name . '_init');
2418
+		}
2282 2419
 	}
2283 2420
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2284 2421
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2298,13 +2435,14 @@  discard block
 block discarded – undo
2298 2435
 		loadTemplate($template_name);
2299 2436
 	}
2300 2437
 	// Cause an error otherwise.
2301
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2302
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2303
-	elseif ($fatal)
2304
-		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'));
2305
-	else
2306
-		return false;
2307
-}
2438
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2439
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2440
+	} elseif ($fatal) {
2441
+			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'));
2442
+	} else {
2443
+			return false;
2444
+	}
2445
+	}
2308 2446
 
2309 2447
 
2310 2448
 /**
@@ -2323,17 +2461,19 @@  discard block
 block discarded – undo
2323 2461
 {
2324 2462
 	global $context, $txt, $db_show_debug;
2325 2463
 
2326
-	if ($db_show_debug === true)
2327
-		$context['debug']['sub_templates'][] = $sub_template_name;
2464
+	if ($db_show_debug === true) {
2465
+			$context['debug']['sub_templates'][] = $sub_template_name;
2466
+	}
2328 2467
 
2329 2468
 	// Figure out what the template function is named.
2330 2469
 	$theme_function = 'template_' . $sub_template_name;
2331
-	if (function_exists($theme_function))
2332
-		$theme_function();
2333
-	elseif ($fatal === false)
2334
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2335
-	elseif ($fatal !== 'ignore')
2336
-		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'));
2470
+	if (function_exists($theme_function)) {
2471
+			$theme_function();
2472
+	} elseif ($fatal === false) {
2473
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2474
+	} elseif ($fatal !== 'ignore') {
2475
+			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'));
2476
+	}
2337 2477
 
2338 2478
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2339 2479
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2370,8 +2510,9 @@  discard block
 block discarded – undo
2370 2510
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2371 2511
 
2372 2512
 	// If this is an external file, automatically set this to false.
2373
-	if (!empty($params['external']))
2374
-		$params['minimize'] = false;
2513
+	if (!empty($params['external'])) {
2514
+			$params['minimize'] = false;
2515
+	}
2375 2516
 
2376 2517
 	// Account for shorthand like admin.css?alp21 filenames
2377 2518
 	$has_seed = strpos($fileName, '.css?');
@@ -2388,13 +2529,10 @@  discard block
 block discarded – undo
2388 2529
 			{
2389 2530
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2390 2531
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2532
+			} else {
2533
+							$fileUrl = false;
2391 2534
 			}
2392
-
2393
-			else
2394
-				$fileUrl = false;
2395
-		}
2396
-
2397
-		else
2535
+		} else
2398 2536
 		{
2399 2537
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2400 2538
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2409,12 +2547,14 @@  discard block
 block discarded – undo
2409 2547
 	}
2410 2548
 
2411 2549
 	// Add it to the array for use in the template
2412
-	if (!empty($fileName))
2413
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2550
+	if (!empty($fileName)) {
2551
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2552
+	}
2414 2553
 
2415
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2416
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2417
-}
2554
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2555
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2556
+	}
2557
+	}
2418 2558
 
2419 2559
 /**
2420 2560
  * Add a block of inline css code to be executed later
@@ -2431,8 +2571,9 @@  discard block
 block discarded – undo
2431 2571
 	global $context;
2432 2572
 
2433 2573
 	// Gotta add something...
2434
-	if (empty($css))
2435
-		return false;
2574
+	if (empty($css)) {
2575
+			return false;
2576
+	}
2436 2577
 
2437 2578
 	$context['css_header'][] = $css;
2438 2579
 }
@@ -2467,8 +2608,9 @@  discard block
 block discarded – undo
2467 2608
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2468 2609
 
2469 2610
 	// If this is an external file, automatically set this to false.
2470
-	if (!empty($params['external']))
2471
-		$params['minimize'] = false;
2611
+	if (!empty($params['external'])) {
2612
+			$params['minimize'] = false;
2613
+	}
2472 2614
 
2473 2615
 	// Account for shorthand like admin.js?alp21 filenames
2474 2616
 	$has_seed = strpos($fileName, '.js?');
@@ -2485,16 +2627,12 @@  discard block
 block discarded – undo
2485 2627
 			{
2486 2628
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2487 2629
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2488
-			}
2489
-
2490
-			else
2630
+			} else
2491 2631
 			{
2492 2632
 				$fileUrl = false;
2493 2633
 				$filePath = false;
2494 2634
 			}
2495
-		}
2496
-
2497
-		else
2635
+		} else
2498 2636
 		{
2499 2637
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2500 2638
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2509,9 +2647,10 @@  discard block
 block discarded – undo
2509 2647
 	}
2510 2648
 
2511 2649
 	// Add it to the array for use in the template
2512
-	if (!empty($fileName))
2513
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2514
-}
2650
+	if (!empty($fileName)) {
2651
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2652
+	}
2653
+	}
2515 2654
 
2516 2655
 /**
2517 2656
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2525,9 +2664,10 @@  discard block
 block discarded – undo
2525 2664
 {
2526 2665
 	global $context;
2527 2666
 
2528
-	if (!empty($key) && (!empty($value) || $value === '0'))
2529
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2530
-}
2667
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2668
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2669
+	}
2670
+	}
2531 2671
 
2532 2672
 /**
2533 2673
  * Add a block of inline Javascript code to be executed later
@@ -2544,8 +2684,9 @@  discard block
 block discarded – undo
2544 2684
 {
2545 2685
 	global $context;
2546 2686
 
2547
-	if (empty($javascript))
2548
-		return false;
2687
+	if (empty($javascript)) {
2688
+			return false;
2689
+	}
2549 2690
 
2550 2691
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2551 2692
 }
@@ -2566,15 +2707,18 @@  discard block
 block discarded – undo
2566 2707
 	static $already_loaded = array();
2567 2708
 
2568 2709
 	// Default to the user's language.
2569
-	if ($lang == '')
2570
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2710
+	if ($lang == '') {
2711
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2712
+	}
2571 2713
 
2572 2714
 	// Do we want the English version of language file as fallback?
2573
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2574
-		loadLanguage($template_name, 'english', false);
2715
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2716
+			loadLanguage($template_name, 'english', false);
2717
+	}
2575 2718
 
2576
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2577
-		return $lang;
2719
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2720
+			return $lang;
2721
+	}
2578 2722
 
2579 2723
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2580 2724
 	if (empty($settings['default_theme_dir']))
@@ -2585,8 +2729,9 @@  discard block
 block discarded – undo
2585 2729
 
2586 2730
 	// What theme are we in?
2587 2731
 	$theme_name = basename($settings['theme_url']);
2588
-	if (empty($theme_name))
2589
-		$theme_name = 'unknown';
2732
+	if (empty($theme_name)) {
2733
+			$theme_name = 'unknown';
2734
+	}
2590 2735
 
2591 2736
 	// For each file open it up and write it out!
2592 2737
 	foreach (explode('+', $template_name) as $template)
@@ -2665,8 +2810,9 @@  discard block
 block discarded – undo
2665 2810
 	}
2666 2811
 
2667 2812
 	// Keep track of what we're up to soldier.
2668
-	if ($db_show_debug === true)
2669
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2813
+	if ($db_show_debug === true) {
2814
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2815
+	}
2670 2816
 
2671 2817
 	// Remember what we have loaded, and in which language.
2672 2818
 	$already_loaded[$template_name] = $lang;
@@ -2712,8 +2858,9 @@  discard block
 block discarded – undo
2712 2858
 				)
2713 2859
 			);
2714 2860
 			// In the EXTREMELY unlikely event this happens, give an error message.
2715
-			if ($smcFunc['db_num_rows']($result) == 0)
2716
-				fatal_lang_error('parent_not_found', 'critical');
2861
+			if ($smcFunc['db_num_rows']($result) == 0) {
2862
+							fatal_lang_error('parent_not_found', 'critical');
2863
+			}
2717 2864
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2718 2865
 			{
2719 2866
 				if (!isset($boards[$row['id_board']]))
@@ -2730,8 +2877,8 @@  discard block
 block discarded – undo
2730 2877
 					);
2731 2878
 				}
2732 2879
 				// If a moderator exists for this board, add that moderator for all children too.
2733
-				if (!empty($row['id_moderator']))
2734
-					foreach ($boards as $id => $dummy)
2880
+				if (!empty($row['id_moderator'])) {
2881
+									foreach ($boards as $id => $dummy)
2735 2882
 					{
2736 2883
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2737 2884
 							'id' => $row['id_moderator'],
@@ -2739,11 +2886,12 @@  discard block
 block discarded – undo
2739 2886
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2740 2887
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2741 2888
 						);
2889
+				}
2742 2890
 					}
2743 2891
 
2744 2892
 				// If a moderator group exists for this board, add that moderator group for all children too
2745
-				if (!empty($row['id_moderator_group']))
2746
-					foreach ($boards as $id => $dummy)
2893
+				if (!empty($row['id_moderator_group'])) {
2894
+									foreach ($boards as $id => $dummy)
2747 2895
 					{
2748 2896
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2749 2897
 							'id' => $row['id_moderator_group'],
@@ -2751,6 +2899,7 @@  discard block
 block discarded – undo
2751 2899
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2752 2900
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2753 2901
 						);
2902
+				}
2754 2903
 					}
2755 2904
 			}
2756 2905
 			$smcFunc['db_free_result']($result);
@@ -2778,23 +2927,27 @@  discard block
 block discarded – undo
2778 2927
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2779 2928
 	{
2780 2929
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2781
-		if (empty($smcFunc['ucwords']))
2782
-			reloadSettings();
2930
+		if (empty($smcFunc['ucwords'])) {
2931
+					reloadSettings();
2932
+		}
2783 2933
 
2784 2934
 		// If we don't have our theme information yet, let's get it.
2785
-		if (empty($settings['default_theme_dir']))
2786
-			loadTheme(0, false);
2935
+		if (empty($settings['default_theme_dir'])) {
2936
+					loadTheme(0, false);
2937
+		}
2787 2938
 
2788 2939
 		// Default language directories to try.
2789 2940
 		$language_directories = array(
2790 2941
 			$settings['default_theme_dir'] . '/languages',
2791 2942
 		);
2792
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2793
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2943
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2944
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2945
+		}
2794 2946
 
2795 2947
 		// We possibly have a base theme directory.
2796
-		if (!empty($settings['base_theme_dir']))
2797
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2948
+		if (!empty($settings['base_theme_dir'])) {
2949
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2950
+		}
2798 2951
 
2799 2952
 		// Remove any duplicates.
2800 2953
 		$language_directories = array_unique($language_directories);
@@ -2808,20 +2961,21 @@  discard block
 block discarded – undo
2808 2961
 		foreach ($language_directories as $language_dir)
2809 2962
 		{
2810 2963
 			// Can't look in here... doesn't exist!
2811
-			if (!file_exists($language_dir))
2812
-				continue;
2964
+			if (!file_exists($language_dir)) {
2965
+							continue;
2966
+			}
2813 2967
 
2814 2968
 			$dir = dir($language_dir);
2815 2969
 			while ($entry = $dir->read())
2816 2970
 			{
2817 2971
 				// Look for the index language file....
2818
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2819
-					continue;
2820
-
2821
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2822
-					$langName = $langList[$matches[1]];
2972
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2973
+									continue;
2974
+				}
2823 2975
 
2824
-				else
2976
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2977
+									$langName = $langList[$matches[1]];
2978
+				} else
2825 2979
 				{
2826 2980
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2827 2981
 
@@ -2864,20 +3018,23 @@  discard block
 block discarded – undo
2864 3018
 		}
2865 3019
 
2866 3020
 		// Do we need to store the lang list?
2867
-		if (empty($langList))
2868
-			updateSettings(array('langList' => json_encode($catchLang)));
3021
+		if (empty($langList)) {
3022
+					updateSettings(array('langList' => json_encode($catchLang)));
3023
+		}
2869 3024
 
2870 3025
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2871 3026
 		if ($favor_utf8)
2872 3027
 		{
2873
-			foreach ($context['languages'] as $lang)
2874
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3028
+			foreach ($context['languages'] as $lang) {
3029
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2875 3030
 					unset($context['languages'][$lang['filename']]);
3031
+			}
2876 3032
 		}
2877 3033
 
2878 3034
 		// Let's cash in on this deal.
2879
-		if (!empty($modSettings['cache_enable']))
2880
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3035
+		if (!empty($modSettings['cache_enable'])) {
3036
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3037
+		}
2881 3038
 	}
2882 3039
 
2883 3040
 	return $context['languages'];
@@ -2900,8 +3057,9 @@  discard block
 block discarded – undo
2900 3057
 	global $modSettings, $options, $txt;
2901 3058
 	static $censor_vulgar = null, $censor_proper;
2902 3059
 
2903
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2904
-		return $text;
3060
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3061
+			return $text;
3062
+	}
2905 3063
 
2906 3064
 	// If they haven't yet been loaded, load them.
2907 3065
 	if ($censor_vulgar == null)
@@ -2929,9 +3087,9 @@  discard block
 block discarded – undo
2929 3087
 	{
2930 3088
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2931 3089
 		$text = $func($censor_vulgar, $censor_proper, $text);
3090
+	} else {
3091
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2932 3092
 	}
2933
-	else
2934
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2935 3093
 
2936 3094
 	return $text;
2937 3095
 }
@@ -2957,38 +3115,42 @@  discard block
 block discarded – undo
2957 3115
 	@ini_set('track_errors', '1');
2958 3116
 
2959 3117
 	// Don't include the file more than once, if $once is true.
2960
-	if ($once && in_array($filename, $templates))
2961
-		return;
3118
+	if ($once && in_array($filename, $templates)) {
3119
+			return;
3120
+	}
2962 3121
 	// Add this file to the include list, whether $once is true or not.
2963
-	else
2964
-		$templates[] = $filename;
3122
+	else {
3123
+			$templates[] = $filename;
3124
+	}
2965 3125
 
2966 3126
 	// Are we going to use eval?
2967 3127
 	if (empty($modSettings['disableTemplateEval']))
2968 3128
 	{
2969 3129
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2970 3130
 		$settings['current_include_filename'] = $filename;
2971
-	}
2972
-	else
3131
+	} else
2973 3132
 	{
2974 3133
 		$file_found = file_exists($filename);
2975 3134
 
2976
-		if ($once && $file_found)
2977
-			require_once($filename);
2978
-		elseif ($file_found)
2979
-			require($filename);
3135
+		if ($once && $file_found) {
3136
+					require_once($filename);
3137
+		} elseif ($file_found) {
3138
+					require($filename);
3139
+		}
2980 3140
 	}
2981 3141
 
2982 3142
 	if ($file_found !== true)
2983 3143
 	{
2984 3144
 		ob_end_clean();
2985
-		if (!empty($modSettings['enableCompressedOutput']))
2986
-			@ob_start('ob_gzhandler');
2987
-		else
2988
-			ob_start();
3145
+		if (!empty($modSettings['enableCompressedOutput'])) {
3146
+					@ob_start('ob_gzhandler');
3147
+		} else {
3148
+					ob_start();
3149
+		}
2989 3150
 
2990
-		if (isset($_GET['debug']))
2991
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3151
+		if (isset($_GET['debug'])) {
3152
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3153
+		}
2992 3154
 
2993 3155
 		// Don't cache error pages!!
2994 3156
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3007,12 +3169,13 @@  discard block
 block discarded – undo
3007 3169
 		echo '<!DOCTYPE html>
3008 3170
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3009 3171
 	<head>';
3010
-		if (isset($context['character_set']))
3011
-			echo '
3172
+		if (isset($context['character_set'])) {
3173
+					echo '
3012 3174
 		<meta charset="', $context['character_set'], '">';
3175
+		}
3013 3176
 
3014
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3015
-			echo '
3177
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3178
+					echo '
3016 3179
 		<title>', $mtitle, '</title>
3017 3180
 	</head>
3018 3181
 	<body>
@@ -3020,8 +3183,8 @@  discard block
 block discarded – undo
3020 3183
 		', $mmessage, '
3021 3184
 	</body>
3022 3185
 </html>';
3023
-		elseif (!allowedTo('admin_forum'))
3024
-			echo '
3186
+		} elseif (!allowedTo('admin_forum')) {
3187
+					echo '
3025 3188
 		<title>', $txt['template_parse_error'], '</title>
3026 3189
 	</head>
3027 3190
 	<body>
@@ -3029,15 +3192,17 @@  discard block
 block discarded – undo
3029 3192
 		', $txt['template_parse_error_message'], '
3030 3193
 	</body>
3031 3194
 </html>';
3032
-		else
3195
+		} else
3033 3196
 		{
3034 3197
 			require_once($sourcedir . '/Subs-Package.php');
3035 3198
 
3036 3199
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3037
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3038
-				$error = $php_errormsg;
3039
-			if (empty($error))
3040
-				$error = $txt['template_parse_errmsg'];
3200
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3201
+							$error = $php_errormsg;
3202
+			}
3203
+			if (empty($error)) {
3204
+							$error = $txt['template_parse_errmsg'];
3205
+			}
3041 3206
 
3042 3207
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3043 3208
 
@@ -3048,11 +3213,12 @@  discard block
 block discarded – undo
3048 3213
 		<h3>', $txt['template_parse_error'], '</h3>
3049 3214
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3050 3215
 
3051
-			if (!empty($error))
3052
-				echo '
3216
+			if (!empty($error)) {
3217
+							echo '
3053 3218
 		<hr>
3054 3219
 
3055 3220
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3221
+			}
3056 3222
 
3057 3223
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3058 3224
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3062,10 +3228,11 @@  discard block
 block discarded – undo
3062 3228
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3063 3229
 
3064 3230
 				// Fix the PHP code stuff...
3065
-				if (!isBrowser('gecko'))
3066
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3067
-				else
3068
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3231
+				if (!isBrowser('gecko')) {
3232
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3233
+				} else {
3234
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3235
+				}
3069 3236
 
3070 3237
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3071 3238
 				$j = -1;
@@ -3073,8 +3240,9 @@  discard block
 block discarded – undo
3073 3240
 				{
3074 3241
 					$j++;
3075 3242
 
3076
-					if (substr_count($line, '<br>') == 0)
3077
-						continue;
3243
+					if (substr_count($line, '<br>') == 0) {
3244
+											continue;
3245
+					}
3078 3246
 
3079 3247
 					$n = substr_count($line, '<br>');
3080 3248
 					for ($i = 0; $i < $n; $i++)
@@ -3093,38 +3261,42 @@  discard block
 block discarded – undo
3093 3261
 				// Figure out what the color coding was before...
3094 3262
 				$line = max($match[1] - 9, 1);
3095 3263
 				$last_line = '';
3096
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3097
-					if (strpos($data2[$line2], '<') !== false)
3264
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3265
+									if (strpos($data2[$line2], '<') !== false)
3098 3266
 					{
3099 3267
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3100 3268
 							$last_line = $color_match[1];
3269
+				}
3101 3270
 						break;
3102 3271
 					}
3103 3272
 
3104 3273
 				// Show the relevant lines...
3105 3274
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3106 3275
 				{
3107
-					if ($line == $match[1])
3108
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3276
+					if ($line == $match[1]) {
3277
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3278
+					}
3109 3279
 
3110 3280
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3111
-					if (isset($data2[$line]) && $data2[$line] != '')
3112
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3281
+					if (isset($data2[$line]) && $data2[$line] != '') {
3282
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3283
+					}
3113 3284
 
3114 3285
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3115 3286
 					{
3116 3287
 						$last_line = $color_match[1];
3117 3288
 						echo '</', substr($last_line, 1, 4), '>';
3289
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3290
+											$last_line = '';
3291
+					} elseif ($last_line != '' && $data2[$line] != '') {
3292
+											echo '</', substr($last_line, 1, 4), '>';
3118 3293
 					}
3119
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3120
-						$last_line = '';
3121
-					elseif ($last_line != '' && $data2[$line] != '')
3122
-						echo '</', substr($last_line, 1, 4), '>';
3123 3294
 
3124
-					if ($line == $match[1])
3125
-						echo '</pre></div><pre style="margin: 0;">';
3126
-					else
3127
-						echo "\n";
3295
+					if ($line == $match[1]) {
3296
+											echo '</pre></div><pre style="margin: 0;">';
3297
+					} else {
3298
+											echo "\n";
3299
+					}
3128 3300
 				}
3129 3301
 
3130 3302
 				echo '</pre></div>';
@@ -3148,8 +3320,9 @@  discard block
 block discarded – undo
3148 3320
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3149 3321
 
3150 3322
 	// Figure out what type of database we are using.
3151
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3152
-		$db_type = 'mysql';
3323
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3324
+			$db_type = 'mysql';
3325
+	}
3153 3326
 
3154 3327
 	// Load the file for the database.
3155 3328
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3157,8 +3330,9 @@  discard block
 block discarded – undo
3157 3330
 	$db_options = array();
3158 3331
 
3159 3332
 	// Add in the port if needed
3160
-	if (!empty($db_port))
3161
-		$db_options['port'] = $db_port;
3333
+	if (!empty($db_port)) {
3334
+			$db_options['port'] = $db_port;
3335
+	}
3162 3336
 
3163 3337
 	// 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.
3164 3338
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3177,13 +3351,15 @@  discard block
 block discarded – undo
3177 3351
 	}
3178 3352
 
3179 3353
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3180
-	if (!$db_connection)
3181
-		display_db_error();
3354
+	if (!$db_connection) {
3355
+			display_db_error();
3356
+	}
3182 3357
 
3183 3358
 	// If in SSI mode fix up the prefix.
3184
-	if (SMF == 'SSI')
3185
-		db_fix_prefix($db_prefix, $db_name);
3186
-}
3359
+	if (SMF == 'SSI') {
3360
+			db_fix_prefix($db_prefix, $db_name);
3361
+	}
3362
+	}
3187 3363
 
3188 3364
 /**
3189 3365
  * Try to retrieve a cache entry. On failure, call the appropriate function.
@@ -3201,8 +3377,9 @@  discard block
 block discarded – undo
3201 3377
 
3202 3378
 	// @todo Why are we doing this if caching is disabled?
3203 3379
 
3204
-	if (function_exists('call_integration_hook'))
3205
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3380
+	if (function_exists('call_integration_hook')) {
3381
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3382
+	}
3206 3383
 
3207 3384
 	/* Refresh the cache if either:
3208 3385
 		1. Caching is disabled.
@@ -3216,16 +3393,19 @@  discard block
 block discarded – undo
3216 3393
 		require_once($sourcedir . '/' . $file);
3217 3394
 		$cache_block = call_user_func_array($function, $params);
3218 3395
 
3219
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3220
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3396
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3397
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3398
+		}
3221 3399
 	}
3222 3400
 
3223 3401
 	// Some cached data may need a freshening up after retrieval.
3224
-	if (!empty($cache_block['post_retri_eval']))
3225
-		eval($cache_block['post_retri_eval']);
3402
+	if (!empty($cache_block['post_retri_eval'])) {
3403
+			eval($cache_block['post_retri_eval']);
3404
+	}
3226 3405
 
3227
-	if (function_exists('call_integration_hook'))
3228
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3406
+	if (function_exists('call_integration_hook')) {
3407
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3408
+	}
3229 3409
 
3230 3410
 	return $cache_block['data'];
3231 3411
 }
@@ -3253,8 +3433,9 @@  discard block
 block discarded – undo
3253 3433
 	global $cache_hits, $cache_count, $db_show_debug, $cachedir;
3254 3434
 	global $cache_accelerator, $cache_enable, $cache_memcached;
3255 3435
 
3256
-	if (empty($cache_enable))
3257
-		return;
3436
+	if (empty($cache_enable)) {
3437
+			return;
3438
+	}
3258 3439
 
3259 3440
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3260 3441
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3273,10 +3454,12 @@  discard block
 block discarded – undo
3273 3454
 			if ((function_exists('memcached_set') || function_exists('memcache_set')) && isset($cache_memcached) && trim($cache_memcached) != '')
3274 3455
 			{
3275 3456
 				// Not connected yet?
3276
-				if (empty($memcached))
3277
-					get_memcached_server();
3278
-				if (!$memcached)
3279
-					return;
3457
+				if (empty($memcached)) {
3458
+									get_memcached_server();
3459
+				}
3460
+				if (!$memcached) {
3461
+									return;
3462
+				}
3280 3463
 
3281 3464
 				memcache_set($memcached, $key, $value, 0, $ttl);
3282 3465
 			}
@@ -3286,10 +3469,11 @@  discard block
 block discarded – undo
3286 3469
 			if (function_exists('apc_store'))
3287 3470
 			{
3288 3471
 				// An extended key is needed to counteract a bug in APC.
3289
-				if ($value === null)
3290
-					apc_delete($key . 'smf');
3291
-				else
3292
-					apc_store($key . 'smf', $value, $ttl);
3472
+				if ($value === null) {
3473
+									apc_delete($key . 'smf');
3474
+				} else {
3475
+									apc_store($key . 'smf', $value, $ttl);
3476
+				}
3293 3477
 			}
3294 3478
 			break;
3295 3479
 		case 'apcu':
@@ -3297,57 +3481,65 @@  discard block
 block discarded – undo
3297 3481
 			if (function_exists('apcu_store'))
3298 3482
 			{
3299 3483
 				// Not sure if this bug exists in APCu or not?
3300
-				if ($value === null)
3301
-					apcu_delete($key . 'smf');
3302
-				else
3303
-					apcu_store($key . 'smf', $value, $ttl);
3484
+				if ($value === null) {
3485
+									apcu_delete($key . 'smf');
3486
+				} else {
3487
+									apcu_store($key . 'smf', $value, $ttl);
3488
+				}
3304 3489
 			}
3305 3490
 			break;
3306 3491
 		case 'zend':
3307 3492
 			// Zend Platform/ZPS/etc.
3308
-			if (function_exists('zend_shm_cache_store'))
3309
-				zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3310
-			elseif (function_exists('output_cache_put'))
3311
-				output_cache_put($key, $value);
3493
+			if (function_exists('zend_shm_cache_store')) {
3494
+							zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3495
+			} elseif (function_exists('output_cache_put')) {
3496
+							output_cache_put($key, $value);
3497
+			}
3312 3498
 			break;
3313 3499
 		case 'xcache':
3314 3500
 			if (function_exists('xcache_set') && ini_get('xcache.var_size') > 0)
3315 3501
 			{
3316
-				if ($value === null)
3317
-					xcache_unset($key);
3318
-				else
3319
-					xcache_set($key, $value, $ttl);
3502
+				if ($value === null) {
3503
+									xcache_unset($key);
3504
+				} else {
3505
+									xcache_set($key, $value, $ttl);
3506
+				}
3320 3507
 			}
3321 3508
 			break;
3322 3509
 		default:
3323 3510
 			// Otherwise custom cache?
3324
-			if ($value === null)
3325
-				@unlink($cachedir . '/data_' . $key . '.php');
3326
-			else
3511
+			if ($value === null) {
3512
+							@unlink($cachedir . '/data_' . $key . '.php');
3513
+			} else
3327 3514
 			{
3328 3515
 				$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
3329 3516
 
3330 3517
 				// Write out the cache file, check that the cache write was successful; all the data must be written
3331 3518
 				// If it fails due to low diskspace, or other, remove the cache file
3332
-				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
3333
-					@unlink($cachedir . '/data_' . $key . '.php');
3519
+				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data)) {
3520
+									@unlink($cachedir . '/data_' . $key . '.php');
3521
+				}
3334 3522
 			}
3335 3523
 			break;
3336 3524
 	}
3337 3525
 
3338
-	if (function_exists('call_integration_hook'))
3339
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3526
+	if (function_exists('call_integration_hook')) {
3527
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3528
+	}
3340 3529
 
3341
-	if (isset($db_show_debug) && $db_show_debug === true)
3342
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3530
+	if (isset($db_show_debug) && $db_show_debug === true) {
3531
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3532
+	}
3343 3533
 
3344 3534
 	// Invalidate the opcode cache
3345
-	if (function_exists('opcache_invalidate'))
3346
-   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3535
+	if (function_exists('opcache_invalidate')) {
3536
+	   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3537
+	}
3347 3538
 
3348
-	if (function_exists('apc_delete_file'))
3349
-   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3350
-}
3539
+	if (function_exists('apc_delete_file')) {
3540
+	   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3541
+	}
3542
+	}
3351 3543
 
3352 3544
 /**
3353 3545
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3364,8 +3556,9 @@  discard block
 block discarded – undo
3364 3556
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug, $cachedir;
3365 3557
 	global $cache_accelerator, $cache_enable, $cache_memcached;
3366 3558
 
3367
-	if (empty($cache_enable))
3368
-		return;
3559
+	if (empty($cache_enable)) {
3560
+			return;
3561
+	}
3369 3562
 
3370 3563
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3371 3564
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3384,37 +3577,42 @@  discard block
 block discarded – undo
3384 3577
 			if ((function_exists('memcache_get') || function_exists('memcached_get')) && isset($cache_memcached) && trim($cache_memcached) != '')
3385 3578
 			{
3386 3579
 				// Not connected yet?
3387
-				if (empty($memcached))
3388
-					get_memcached_server();
3580
+				if (empty($memcached)) {
3581
+									get_memcached_server();
3582
+				}
3389 3583
 				if (!$memcached)
3390 3584
 				{
3391 3585
 					$cache_misses_count = isset($cache_misses) ? $cache_misses + 1 : 1;
3392 3586
 					$value = null;
3587
+				} else {
3588
+									$value = (function_exists('memcache_get')) ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
3393 3589
 				}
3394
-				else
3395
-					$value = (function_exists('memcache_get')) ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
3396 3590
 			}
3397 3591
 			break;
3398 3592
 		case 'apc':
3399 3593
 			// This is the free APC from PECL.
3400
-			if (function_exists('apc_fetch'))
3401
-				$value = apc_fetch($key . 'smf');
3594
+			if (function_exists('apc_fetch')) {
3595
+							$value = apc_fetch($key . 'smf');
3596
+			}
3402 3597
 			break;
3403 3598
 		case 'apcu':
3404 3599
 			// APC User Cache. A continuation of the now-unsupported APC but without opcode cache
3405
-			if (function_exists('apcu_fetch'))
3406
-				$value = apcu_fetch($key . 'smf');
3600
+			if (function_exists('apcu_fetch')) {
3601
+							$value = apcu_fetch($key . 'smf');
3602
+			}
3407 3603
 			break;
3408 3604
 		case 'zend':
3409 3605
 			// Zend's pricey stuff.
3410
-			if (function_exists('zend_shm_cache_fetch'))
3411
-				$value = zend_shm_cache_fetch('SMF::' . $key);
3412
-			elseif (function_exists('output_cache_get'))
3413
-				$value = output_cache_get($key, $ttl);
3606
+			if (function_exists('zend_shm_cache_fetch')) {
3607
+							$value = zend_shm_cache_fetch('SMF::' . $key);
3608
+			} elseif (function_exists('output_cache_get')) {
3609
+							$value = output_cache_get($key, $ttl);
3610
+			}
3414 3611
 			break;
3415 3612
 		case 'xcache':
3416
-			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0)
3417
-				$value = xcache_get($key);
3613
+			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) {
3614
+							$value = xcache_get($key);
3615
+			}
3418 3616
 			break;
3419 3617
 		default:
3420 3618
 			// Otherwise it's SMF data!
@@ -3422,8 +3620,9 @@  discard block
 block discarded – undo
3422 3620
 			{
3423 3621
 				// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
3424 3622
 				// causing newer files to take effect a while later.
3425
-				if (function_exists('opcache_invalidate'))
3426
-					opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3623
+				if (function_exists('opcache_invalidate')) {
3624
+									opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3625
+				}
3427 3626
 
3428 3627
 				// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
3429 3628
 				@include($cachedir . '/data_' . $key . '.php');
@@ -3443,16 +3642,18 @@  discard block
 block discarded – undo
3443 3642
 
3444 3643
 		if (empty($value))
3445 3644
 		{
3446
-			if (!isset($cache_misses))
3447
-				$cache_misses = array();
3645
+			if (!isset($cache_misses)) {
3646
+							$cache_misses = array();
3647
+			}
3448 3648
 
3449 3649
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3450 3650
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3451 3651
 		}
3452 3652
 	}
3453 3653
 
3454
-	if (function_exists('call_integration_hook') && isset($value))
3455
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3654
+	if (function_exists('call_integration_hook') && isset($value)) {
3655
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3656
+	}
3456 3657
 
3457 3658
 	return empty($value) ? null : smf_json_decode($value, true);
3458 3659
 }
@@ -3476,9 +3677,9 @@  discard block
 block discarded – undo
3476 3677
 	$port = 0;
3477 3678
 
3478 3679
 	// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
3479
-	if(strpos($server,'/') !== false)
3480
-		$host = $server;
3481
-	else
3680
+	if(strpos($server,'/') !== false) {
3681
+			$host = $server;
3682
+	} else
3482 3683
 	{
3483 3684
 		$server = explode(':', $server);
3484 3685
 		$host = $server[0];
@@ -3493,22 +3694,26 @@  discard block
 block discarded – undo
3493 3694
 	// Don't wait too long: yes, we want the server, but we might be able to run the query faster!
3494 3695
 	if (empty($db_persist))
3495 3696
 	{
3496
-		if ($cache === 'memcached')
3497
-			$memcached = memcached_connect($host, $port);
3498
-		if ($cache === 'memcache')
3499
-			$memcached = memcache_connect($host, $port);
3500
-	}
3501
-	else
3697
+		if ($cache === 'memcached') {
3698
+					$memcached = memcached_connect($host, $port);
3699
+		}
3700
+		if ($cache === 'memcache') {
3701
+					$memcached = memcache_connect($host, $port);
3702
+		}
3703
+	} else
3502 3704
 	{
3503
-		if ($cache === 'memcached')
3504
-			$memcached = memcached_pconnect($host, $port);
3505
-		if ($cache === 'memcache')
3506
-			$memcached = memcache_pconnect($host, $port);
3705
+		if ($cache === 'memcached') {
3706
+					$memcached = memcached_pconnect($host, $port);
3707
+		}
3708
+		if ($cache === 'memcache') {
3709
+					$memcached = memcache_pconnect($host, $port);
3710
+		}
3507 3711
 	}
3508 3712
 
3509
-	if (!$memcached && $level > 0)
3510
-		get_memcached_server($level - 1);
3511
-}
3713
+	if (!$memcached && $level > 0) {
3714
+			get_memcached_server($level - 1);
3715
+	}
3716
+	}
3512 3717
 
3513 3718
 /**
3514 3719
  * Helper function to set an array of data for an user's avatar.
@@ -3526,8 +3731,9 @@  discard block
 block discarded – undo
3526 3731
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3527 3732
 
3528 3733
 	// Come on!
3529
-	if (empty($data))
3530
-		return array();
3734
+	if (empty($data)) {
3735
+			return array();
3736
+	}
3531 3737
 
3532 3738
 	// Set a nice default var.
3533 3739
 	$image = '';
@@ -3535,11 +3741,11 @@  discard block
 block discarded – undo
3535 3741
 	// Gravatar has been set as mandatory!
3536 3742
 	if (!empty($modSettings['gravatarOverride']))
3537 3743
 	{
3538
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3539
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3540
-
3541
-		else if (!empty($data['email']))
3542
-			$image = get_gravatar_url($data['email']);
3744
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3745
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3746
+		} else if (!empty($data['email'])) {
3747
+					$image = get_gravatar_url($data['email']);
3748
+		}
3543 3749
 	}
3544 3750
 
3545 3751
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3551,54 +3757,60 @@  discard block
 block discarded – undo
3551 3757
 			// Gravatar.
3552 3758
 			if (stristr($data['avatar'], 'gravatar://'))
3553 3759
 			{
3554
-				if ($data['avatar'] == 'gravatar://')
3555
-					$image = get_gravatar_url($data['email']);
3556
-
3557
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3558
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3760
+				if ($data['avatar'] == 'gravatar://') {
3761
+									$image = get_gravatar_url($data['email']);
3762
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3763
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3764
+				}
3559 3765
 			}
3560 3766
 
3561 3767
 			// External url.
3562 3768
 			else
3563 3769
 			{
3564 3770
 				// Using ssl?
3565
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3566
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3771
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3772
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3773
+				}
3567 3774
 
3568 3775
 				// Just a plain external url.
3569
-				else
3570
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3776
+				else {
3777
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3778
+				}
3571 3779
 			}
3572 3780
 		}
3573 3781
 
3574 3782
 		// Perhaps this user has an attachment as avatar...
3575
-		else if (!empty($data['filename']))
3576
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3783
+		else if (!empty($data['filename'])) {
3784
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3785
+		}
3577 3786
 
3578 3787
 		// Right... no avatar... use our default image.
3579
-		else
3580
-			$image = $modSettings['avatar_url'] . '/default.png';
3788
+		else {
3789
+					$image = $modSettings['avatar_url'] . '/default.png';
3790
+		}
3581 3791
 	}
3582 3792
 
3583 3793
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3584 3794
 
3585 3795
 	// 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.
3586
-	if (!empty($image))
3587
-		return array(
3796
+	if (!empty($image)) {
3797
+			return array(
3588 3798
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3589 3799
 			'image' => '<img class="avatar" src="' . $image . '" />',
3590 3800
 			'href' => $image,
3591 3801
 			'url' => $image,
3592 3802
 		);
3803
+	}
3593 3804
 
3594 3805
 	// Fallback to make life easier for everyone...
3595
-	else
3596
-		return array(
3806
+	else {
3807
+			return array(
3597 3808
 			'name' => '',
3598 3809
 			'image' => '',
3599 3810
 			'href' => '',
3600 3811
 			'url' => '',
3601 3812
 		);
3602
-}
3813
+	}
3814
+	}
3603 3815
 
3604 3816
 ?>
3605 3817
\ 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.
Sources/Reports.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1013,7 +1013,7 @@
 block discarded – undo
1013 1013
  * @param string $title The title of the separator
1014 1014
  * @param null|string $custom_table The ID of the custom table
1015 1015
  *
1016
- * @return void|bool Returns false if there are no tables
1016
+ * @return null|false Returns false if there are no tables
1017 1017
  */
1018 1018
 function addSeparator($title = '', $custom_table = null)
1019 1019
 {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	// Build the reports button array.
113 113
 	$context['report_buttons'] = array(
114 114
 		'generate_reports' => array('text' => 'generate_reports', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports', 'active' => true),
115
-		'print' => array('text' => 'print', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type']. ';st=print', 'custom' => 'target="_blank"'),
115
+		'print' => array('text' => 'print', 'image' => 'print.png', 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type'] . ';st=print', 'custom' => 'target="_blank"'),
116 116
 	);
117 117
 
118 118
 	// Allow mods to add additional buttons here
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	$request = $smcFunc['db_query']('', '
345 345
 		SELECT id_board, id_group
346 346
 		FROM {db_prefix}moderator_groups
347
-		WHERE ' . $board_clause .' AND ' . $group_clause,
347
+		WHERE ' . $board_clause . ' AND ' . $group_clause,
348 348
 		array(
349 349
 		)
350 350
 	);
Please login to merge, or discard this patch.
Braces   +199 added lines, -148 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
21 21
  * @version 2.1 Beta 3
22 22
  */
23 23
 
24
-if (!defined('SMF'))
24
+if (!defined('SMF')) {
25 25
 	die('No direct access...');
26
+}
26 27
 
27 28
 /**
28 29
  * Handling function for generating reports.
@@ -69,14 +70,15 @@  discard block
 block discarded – undo
69 70
 	);
70 71
 
71 72
 	$is_first = 0;
72
-	foreach ($context['report_types'] as $k => $temp)
73
-		$context['report_types'][$k] = array(
73
+	foreach ($context['report_types'] as $k => $temp) {
74
+			$context['report_types'][$k] = array(
74 75
 			'id' => $k,
75 76
 			'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $k,
76 77
 			'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
77 78
 			'function' => $temp,
78 79
 			'is_first' => $is_first++ == 0,
79 80
 		);
81
+	}
80 82
 
81 83
 	// If they haven't chosen a report type which is valid, send them off to the report type chooser!
82 84
 	if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 		$context['sub_template'] = $_REQUEST['st'];
103 105
 
104 106
 		// Are we disabling the other layers - print friendly for example?
105
-		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
106
-			$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
107
+		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null) {
108
+					$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
109
+		}
107 110
 	}
108 111
 
109 112
 	// Make the page title more descriptive.
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
 		)
152 155
 	);
153 156
 	$moderators = array();
154
-	while ($row = $smcFunc['db_fetch_assoc']($request))
155
-		$moderators[$row['id_board']][] = $row['real_name'];
157
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
158
+			$moderators[$row['id_board']][] = $row['real_name'];
159
+	}
156 160
 	$smcFunc['db_free_result']($request);
157 161
 
158 162
 	// Get every moderator gruop.
@@ -164,8 +168,9 @@  discard block
 block discarded – undo
164 168
 		)
165 169
 	);
166 170
 	$moderator_groups = array();
167
-	while ($row = $smcFunc['db_fetch_assoc']($request))
168
-		$moderator_groups[$row['id_board']][] = $row['group_name'];
171
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
172
+			$moderator_groups[$row['id_board']][] = $row['group_name'];
173
+	}
169 174
 	$smcFunc['db_free_result']($request);
170 175
 
171 176
 	// Get all the possible membergroups!
@@ -176,8 +181,9 @@  discard block
 block discarded – undo
176 181
 		)
177 182
 	);
178 183
 	$groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
180
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
186
+	}
181 187
 	$smcFunc['db_free_result']($request);
182 188
 
183 189
 	// All the fields we'll show.
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		'moderator_groups' => $txt['board_moderator_groups'],
196 202
 		'groups' => $txt['board_groups'],
197 203
 	);
198
-	if (!empty($modSettings['deny_boards_access']))
199
-		$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
204
+	if (!empty($modSettings['deny_boards_access'])) {
205
+			$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
206
+	}
200 207
 
201 208
 	// Do it in columns, it's just easier.
202 209
 	setKeys('cols');
@@ -222,8 +229,9 @@  discard block
 block discarded – undo
222 229
 		newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
223 230
 
224 231
 		$this_boardSettings = $boardSettings;
225
-		if (empty($row['redirect']))
226
-			unset($this_boardSettings['redirect']);
232
+		if (empty($row['redirect'])) {
233
+					unset($this_boardSettings['redirect']);
234
+		}
227 235
 
228 236
 		// First off, add in the side key.
229 237
 		addData($this_boardSettings);
@@ -250,10 +258,11 @@  discard block
 block discarded – undo
250 258
 		$allowedGroups = explode(',', $row['member_groups']);
251 259
 		foreach ($allowedGroups as $key => $group)
252 260
 		{
253
-			if (isset($groups[$group]))
254
-				$allowedGroups[$key] = $groups[$group];
255
-			else
256
-				unset($allowedGroups[$key]);
261
+			if (isset($groups[$group])) {
262
+							$allowedGroups[$key] = $groups[$group];
263
+			} else {
264
+							unset($allowedGroups[$key]);
265
+			}
257 266
 		}
258 267
 		$boardData['groups'] = implode(', ', $allowedGroups);
259 268
 		if (!empty($modSettings['deny_boards_access']))
@@ -261,16 +270,18 @@  discard block
 block discarded – undo
261 270
 			$disallowedGroups = explode(',', $row['deny_member_groups']);
262 271
 			foreach ($disallowedGroups as $key => $group)
263 272
 			{
264
-				if (isset($groups[$group]))
265
-					$disallowedGroups[$key] = $groups[$group];
266
-				else
267
-					unset($disallowedGroups[$key]);
273
+				if (isset($groups[$group])) {
274
+									$disallowedGroups[$key] = $groups[$group];
275
+				} else {
276
+									unset($disallowedGroups[$key]);
277
+				}
268 278
 			}
269 279
 			$boardData['disallowed_groups'] = implode(', ', $disallowedGroups);
270 280
 		}
271 281
 
272
-		if (empty($row['redirect']))
273
-			unset ($boardData['redirect']);
282
+		if (empty($row['redirect'])) {
283
+					unset ($boardData['redirect']);
284
+		}
274 285
 
275 286
 		// Next add the main data.
276 287
 		addData($boardData);
@@ -295,27 +306,31 @@  discard block
 block discarded – undo
295 306
 
296 307
 	if (isset($_REQUEST['boards']))
297 308
 	{
298
-		if (!is_array($_REQUEST['boards']))
299
-			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
300
-		foreach ($_REQUEST['boards'] as $k => $dummy)
301
-			$_REQUEST['boards'][$k] = (int) $dummy;
309
+		if (!is_array($_REQUEST['boards'])) {
310
+					$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
311
+		}
312
+		foreach ($_REQUEST['boards'] as $k => $dummy) {
313
+					$_REQUEST['boards'][$k] = (int) $dummy;
314
+		}
302 315
 
303 316
 		$board_clause = 'id_board IN ({array_int:boards})';
317
+	} else {
318
+			$board_clause = '1=1';
304 319
 	}
305
-	else
306
-		$board_clause = '1=1';
307 320
 
308 321
 	if (isset($_REQUEST['groups']))
309 322
 	{
310
-		if (!is_array($_REQUEST['groups']))
311
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
312
-		foreach ($_REQUEST['groups'] as $k => $dummy)
313
-			$_REQUEST['groups'][$k] = (int) $dummy;
323
+		if (!is_array($_REQUEST['groups'])) {
324
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
325
+		}
326
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
327
+					$_REQUEST['groups'][$k] = (int) $dummy;
328
+		}
314 329
 
315 330
 		$group_clause = 'id_group IN ({array_int:groups})';
331
+	} else {
332
+			$group_clause = '1=1';
316 333
 	}
317
-	else
318
-		$group_clause = '1=1';
319 334
 
320 335
 	// Fetch all the board names.
321 336
 	$request = $smcFunc['db_query']('', '
@@ -369,12 +384,14 @@  discard block
 block discarded – undo
369 384
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
370 385
 		)
371 386
 	);
372
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
373
-		$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
374
-	else
375
-		$member_groups = array('col' => '');
376
-	while ($row = $smcFunc['db_fetch_assoc']($request))
377
-		$member_groups[$row['id_group']] = $row['group_name'];
387
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
388
+			$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
389
+	} else {
390
+			$member_groups = array('col' => '');
391
+	}
392
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+			$member_groups[$row['id_group']] = $row['group_name'];
394
+	}
378 395
 	$smcFunc['db_free_result']($request);
379 396
 
380 397
 	// Make sure that every group is represented - plus in rows!
@@ -411,12 +428,14 @@  discard block
 block discarded – undo
411 428
 	);
412 429
 	while ($row = $smcFunc['db_fetch_assoc']($request))
413 430
 	{
414
-		if (in_array($row['permission'], $disabled_permissions))
415
-			continue;
431
+		if (in_array($row['permission'], $disabled_permissions)) {
432
+					continue;
433
+		}
416 434
 
417
-		foreach ($boards as $id => $board)
418
-			if ($board['profile'] == $row['id_profile'])
435
+		foreach ($boards as $id => $board) {
436
+					if ($board['profile'] == $row['id_profile'])
419 437
 				$board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
438
+		}
420 439
 
421 440
 		// Make sure we get every permission.
422 441
 		if (!isset($permissions[$row['permission']]))
@@ -454,8 +473,9 @@  discard block
 block discarded – undo
454 473
 			foreach ($member_groups as $id_group => $name)
455 474
 			{
456 475
 				// Don't overwrite the key column!
457
-				if ($id_group === 'col')
458
-					continue;
476
+				if ($id_group === 'col') {
477
+									continue;
478
+				}
459 479
 
460 480
 				$group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
461 481
 
@@ -477,16 +497,18 @@  discard block
 block discarded – undo
477 497
 				}
478 498
 
479 499
 				// Now actually make the data for the group look right.
480
-				if (empty($curData[$id_group]))
481
-					$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
482
-				elseif ($curData[$id_group] == 1)
483
-					$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
484
-				else
485
-					$curData[$id_group] = 'x';
500
+				if (empty($curData[$id_group])) {
501
+									$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
502
+				} elseif ($curData[$id_group] == 1) {
503
+									$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
504
+				} else {
505
+									$curData[$id_group] = 'x';
506
+				}
486 507
 
487 508
 				// Embolden those permissions different from global (makes it a lot easier!)
488
-				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
489
-					$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
509
+				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM]) {
510
+									$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
511
+				}
490 512
 			}
491 513
 
492 514
 			// Now add the data for this permission.
@@ -516,15 +538,17 @@  discard block
 block discarded – undo
516 538
 	);
517 539
 	while ($row = $smcFunc['db_fetch_assoc']($request))
518 540
 	{
519
-		if (trim($row['member_groups']) == '')
520
-			$groups = array(1);
521
-		else
522
-			$groups = array_merge(array(1), explode(',', $row['member_groups']));
541
+		if (trim($row['member_groups']) == '') {
542
+					$groups = array(1);
543
+		} else {
544
+					$groups = array_merge(array(1), explode(',', $row['member_groups']));
545
+		}
523 546
 
524
-		if (trim($row['deny_member_groups']) == '')
525
-			$denyGroups = array();
526
-		else
527
-			$denyGroups = explode(',', $row['deny_member_groups']);
547
+		if (trim($row['deny_member_groups']) == '') {
548
+					$denyGroups = array();
549
+		} else {
550
+					$denyGroups = explode(',', $row['deny_member_groups']);
551
+		}
528 552
 
529 553
 		$boards[$row['id_board']] = array(
530 554
 			'id' => $row['id_board'],
@@ -548,8 +572,9 @@  discard block
 block discarded – undo
548 572
 	);
549 573
 
550 574
 	// Add on the boards!
551
-	foreach ($boards as $board)
552
-		$mgSettings['board_' . $board['id']] = $board['name'];
575
+	foreach ($boards as $board) {
576
+			$mgSettings['board_' . $board['id']] = $board['name'];
577
+	}
553 578
 
554 579
 	// Add all the membergroup settings, plus we'll be adding in columns!
555 580
 	setKeys('cols', $mgSettings);
@@ -594,8 +619,9 @@  discard block
 block discarded – undo
594 619
 			'icons' => ''
595 620
 		),
596 621
 	);
597
-	while ($row = $smcFunc['db_fetch_assoc']($request))
598
-		$rows[] = $row;
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$rows[] = $row;
624
+	}
599 625
 	$smcFunc['db_free_result']($request);
600 626
 
601 627
 	foreach ($rows as $row)
@@ -611,8 +637,9 @@  discard block
 block discarded – undo
611 637
 		);
612 638
 
613 639
 		// Board permissions.
614
-		foreach ($boards as $board)
615
-			$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
640
+		foreach ($boards as $board) {
641
+					$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
642
+		}
616 643
 
617 644
 		addData($group);
618 645
 	}
@@ -632,16 +659,18 @@  discard block
 block discarded – undo
632 659
 
633 660
 	if (isset($_REQUEST['groups']))
634 661
 	{
635
-		if (!is_array($_REQUEST['groups']))
636
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
637
-		foreach ($_REQUEST['groups'] as $k => $dummy)
638
-			$_REQUEST['groups'][$k] = (int) $dummy;
662
+		if (!is_array($_REQUEST['groups'])) {
663
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
664
+		}
665
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
666
+					$_REQUEST['groups'][$k] = (int) $dummy;
667
+		}
639 668
 		$_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
640 669
 
641 670
 		$clause = 'id_group IN ({array_int:groups})';
671
+	} else {
672
+			$clause = 'id_group != {int:moderator_group}';
642 673
 	}
643
-	else
644
-		$clause = 'id_group != {int:moderator_group}';
645 674
 
646 675
 	// Get all the possible membergroups, except admin!
647 676
 	$request = $smcFunc['db_query']('', '
@@ -659,12 +688,14 @@  discard block
 block discarded – undo
659 688
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
660 689
 		)
661 690
 	);
662
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
663
-		$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
664
-	else
665
-		$groups = array('col' => '');
666
-	while ($row = $smcFunc['db_fetch_assoc']($request))
667
-		$groups[$row['id_group']] = $row['group_name'];
691
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
692
+			$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
693
+	} else {
694
+			$groups = array('col' => '');
695
+	}
696
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
697
+			$groups[$row['id_group']] = $row['group_name'];
698
+	}
668 699
 	$smcFunc['db_free_result']($request);
669 700
 
670 701
 	// Make sure that every group is represented!
@@ -688,8 +719,9 @@  discard block
 block discarded – undo
688 719
 		$disabled_permissions[] = 'calendar_edit_own';
689 720
 		$disabled_permissions[] = 'calendar_edit_any';
690 721
 	}
691
-	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0)
692
-		$disabled_permissions[] = 'issue_warning';
722
+	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0) {
723
+			$disabled_permissions[] = 'issue_warning';
724
+	}
693 725
 
694 726
 	call_integration_hook('integrate_reports_groupperm', array(&$disabled_permissions));
695 727
 
@@ -710,15 +742,17 @@  discard block
 block discarded – undo
710 742
 	$curData = array();
711 743
 	while ($row = $smcFunc['db_fetch_assoc']($request))
712 744
 	{
713
-		if (in_array($row['permission'], $disabled_permissions))
714
-			continue;
745
+		if (in_array($row['permission'], $disabled_permissions)) {
746
+					continue;
747
+		}
715 748
 
716 749
 		// If this is a new permission flush the last row.
717 750
 		if ($row['permission'] != $lastPermission)
718 751
 		{
719 752
 			// Send the data!
720
-			if ($lastPermission !== null)
721
-				addData($curData);
753
+			if ($lastPermission !== null) {
754
+							addData($curData);
755
+			}
722 756
 
723 757
 			// Add the permission name in the left column.
724 758
 			$curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
@@ -727,10 +761,11 @@  discard block
 block discarded – undo
727 761
 		}
728 762
 
729 763
 		// Good stuff - add the permission to the list!
730
-		if ($row['add_deny'])
731
-			$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
732
-		else
733
-			$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
764
+		if ($row['add_deny']) {
765
+					$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
766
+		} else {
767
+					$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
768
+		}
734 769
 	}
735 770
 	$smcFunc['db_free_result']($request);
736 771
 
@@ -760,8 +795,9 @@  discard block
 block discarded – undo
760 795
 		)
761 796
 	);
762 797
 	$boards = array();
763
-	while ($row = $smcFunc['db_fetch_assoc']($request))
764
-		$boards[$row['id_board']] = $row['name'];
798
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+			$boards[$row['id_board']] = $row['name'];
800
+	}
765 801
 	$smcFunc['db_free_result']($request);
766 802
 
767 803
 	// Get every moderator.
@@ -793,12 +829,14 @@  discard block
 block discarded – undo
793 829
 	while ($row = $smcFunc['db_fetch_assoc']($request))
794 830
 	{
795 831
 		// Either we don't have them as a moderator at all or at least not as a moderator of this board
796
-		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']]))
797
-			$moderators[$row['id_member']][] = $row['id_board'];
832
+		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']])) {
833
+					$moderators[$row['id_member']][] = $row['id_board'];
834
+		}
798 835
 
799 836
 		// We don't have them listed as a moderator yet
800
-		if (!array_key_exists($row['id_member'], $local_mods))
801
-			$local_mods[$row['id_member']] = $row['id_member'];
837
+		if (!array_key_exists($row['id_member'], $local_mods)) {
838
+					$local_mods[$row['id_member']] = $row['id_member'];
839
+		}
802 840
 	}
803 841
 
804 842
 	// Get a list of global moderators (i.e. members with moderation powers).
@@ -811,8 +849,9 @@  discard block
 block discarded – undo
811 849
 	$allStaff = array_unique($allStaff);
812 850
 
813 851
 	// This is a bit of a cop out - but we're protecting their forum, really!
814
-	if (count($allStaff) > 300)
815
-		fatal_lang_error('report_error_too_many_staff');
852
+	if (count($allStaff) > 300) {
853
+			fatal_lang_error('report_error_too_many_staff');
854
+	}
816 855
 
817 856
 	// Get all the possible membergroups!
818 857
 	$request = $smcFunc['db_query']('', '
@@ -822,8 +861,9 @@  discard block
 block discarded – undo
822 861
 		)
823 862
 	);
824 863
 	$groups = array(0 => $txt['full_member']);
825
-	while ($row = $smcFunc['db_fetch_assoc']($request))
826
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
864
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
865
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
866
+	}
827 867
 	$smcFunc['db_free_result']($request);
828 868
 
829 869
 	// All the fields we'll show.
@@ -864,19 +904,20 @@  discard block
 block discarded – undo
864 904
 		);
865 905
 
866 906
 		// What do they moderate?
867
-		if (in_array($row['id_member'], $global_mods))
868
-			$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
869
-		elseif (isset($moderators[$row['id_member']]))
907
+		if (in_array($row['id_member'], $global_mods)) {
908
+					$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
909
+		} elseif (isset($moderators[$row['id_member']]))
870 910
 		{
871 911
 			// Get the names
872
-			foreach ($moderators[$row['id_member']] as $board)
873
-				if (isset($boards[$board]))
912
+			foreach ($moderators[$row['id_member']] as $board) {
913
+							if (isset($boards[$board]))
874 914
 					$staffData['moderates'][] = $boards[$board];
915
+			}
875 916
 
876 917
 			$staffData['moderates'] = implode(', ', $staffData['moderates']);
918
+		} else {
919
+					$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
877 920
 		}
878
-		else
879
-			$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
880 921
 
881 922
 		// Next add the main data.
882 923
 		addData($staffData);
@@ -904,8 +945,9 @@  discard block
 block discarded – undo
904 945
 	global $context;
905 946
 
906 947
 	// Set the table count if needed.
907
-	if (empty($context['table_count']))
908
-		$context['table_count'] = 0;
948
+	if (empty($context['table_count'])) {
949
+			$context['table_count'] = 0;
950
+	}
909 951
 
910 952
 	// Create the table!
911 953
 	$context['tables'][$context['table_count']] = array(
@@ -955,16 +997,18 @@  discard block
 block discarded – undo
955 997
 	global $context;
956 998
 
957 999
 	// No tables? Create one even though we are probably already in a bad state!
958
-	if (empty($context['table_count']))
959
-		newTable();
1000
+	if (empty($context['table_count'])) {
1001
+			newTable();
1002
+	}
960 1003
 
961 1004
 	// Specific table?
962
-	if ($custom_table !== null && !isset($context['tables'][$custom_table]))
963
-		return false;
964
-	elseif ($custom_table !== null)
965
-		$table = $custom_table;
966
-	else
967
-		$table = $context['current_table'];
1005
+	if ($custom_table !== null && !isset($context['tables'][$custom_table])) {
1006
+			return false;
1007
+	} elseif ($custom_table !== null) {
1008
+			$table = $custom_table;
1009
+	} else {
1010
+			$table = $context['current_table'];
1011
+	}
968 1012
 
969 1013
 	// If we have keys, sanitise the data...
970 1014
 	if (!empty($context['keys']))
@@ -976,11 +1020,11 @@  discard block
 block discarded – undo
976 1020
 				'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
977 1021
 			);
978 1022
 			// Special "hack" the adding separators when doing data by column.
979
-			if (substr($key, 0, 5) == '#sep#')
980
-				$data[$key]['separator'] = true;
1023
+			if (substr($key, 0, 5) == '#sep#') {
1024
+							$data[$key]['separator'] = true;
1025
+			}
981 1026
 		}
982
-	}
983
-	else
1027
+	} else
984 1028
 	{
985 1029
 		$data = $inc_data;
986 1030
 		foreach ($data as $key => $value)
@@ -988,8 +1032,9 @@  discard block
 block discarded – undo
988 1032
 			$data[$key] = array(
989 1033
 				'v' => $value,
990 1034
 			);
991
-			if (substr($key, 0, 5) == '#sep#')
992
-				$data[$key]['separator'] = true;
1035
+			if (substr($key, 0, 5) == '#sep#') {
1036
+							$data[$key]['separator'] = true;
1037
+			}
993 1038
 		}
994 1039
 	}
995 1040
 
@@ -1002,8 +1047,9 @@  discard block
 block discarded – undo
1002 1047
 	// Otherwise, tricky!
1003 1048
 	else
1004 1049
 	{
1005
-		foreach ($data as $key => $item)
1006
-			$context['tables'][$table]['data'][$key][] = $item;
1050
+		foreach ($data as $key => $item) {
1051
+					$context['tables'][$table]['data'][$key][] = $item;
1052
+		}
1007 1053
 	}
1008 1054
 }
1009 1055
 
@@ -1020,16 +1066,18 @@  discard block
 block discarded – undo
1020 1066
 	global $context;
1021 1067
 
1022 1068
 	// No tables - return?
1023
-	if (empty($context['table_count']))
1024
-		return;
1069
+	if (empty($context['table_count'])) {
1070
+			return;
1071
+	}
1025 1072
 
1026 1073
 	// Specific table?
1027
-	if ($custom_table !== null && !isset($context['tables'][$table]))
1028
-		return false;
1029
-	elseif ($custom_table !== null)
1030
-		$table = $custom_table;
1031
-	else
1032
-		$table = $context['current_table'];
1074
+	if ($custom_table !== null && !isset($context['tables'][$table])) {
1075
+			return false;
1076
+	} elseif ($custom_table !== null) {
1077
+			$table = $custom_table;
1078
+	} else {
1079
+			$table = $context['current_table'];
1080
+	}
1033 1081
 
1034 1082
 	// Plumb in the separator
1035 1083
 	$context['tables'][$table]['data'][] = array(0 => array(
@@ -1050,8 +1098,9 @@  discard block
 block discarded – undo
1050 1098
 {
1051 1099
 	global $context;
1052 1100
 
1053
-	if (empty($context['tables']))
1054
-		return;
1101
+	if (empty($context['tables'])) {
1102
+			return;
1103
+	}
1055 1104
 
1056 1105
 	// Loop through each table counting up some basic values, to help with the templating.
1057 1106
 	foreach ($context['tables'] as $id => $table)
@@ -1062,12 +1111,13 @@  discard block
 block discarded – undo
1062 1111
 		$context['tables'][$id]['column_count'] = count($curElement);
1063 1112
 
1064 1113
 		// Work out the rough width - for templates like the print template. Without this we might get funny tables.
1065
-		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
1066
-			$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1067
-		elseif ($table['width']['normal'] != 'auto')
1068
-			$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1069
-		else
1070
-			$context['tables'][$id]['max_width'] = 'auto';
1114
+		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto') {
1115
+					$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1116
+		} elseif ($table['width']['normal'] != 'auto') {
1117
+					$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1118
+		} else {
1119
+					$context['tables'][$id]['max_width'] = 'auto';
1120
+		}
1071 1121
 	}
1072 1122
 }
1073 1123
 
@@ -1092,10 +1142,11 @@  discard block
 block discarded – undo
1092 1142
 	global $context;
1093 1143
 
1094 1144
 	// Do we want to use the keys of the keys as the keys? :P
1095
-	if ($reverse)
1096
-		$context['keys'] = array_flip($keys);
1097
-	else
1098
-		$context['keys'] = $keys;
1145
+	if ($reverse) {
1146
+			$context['keys'] = array_flip($keys);
1147
+	} else {
1148
+			$context['keys'] = $keys;
1149
+	}
1099 1150
 
1100 1151
 	// Rows or columns?
1101 1152
 	$context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
Please login to merge, or discard this patch.