Completed
Branch release-2.1 (4c82a0)
by Rick
15:44
created
Sources/Load.php 4 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2185,9 +2185,9 @@  discard block
 block discarded – undo
2185 2185
  *
2186 2186
  * @uses the template_include() function to include the file.
2187 2187
  * @param string $template_name The name of the template to load
2188
- * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2188
+ * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load
2189 2189
  * @param bool $fatal If true, dies with an error message if the template cannot be found
2190
- * @return boolean Whether or not the template was loaded
2190
+ * @return boolean|null Whether or not the template was loaded
2191 2191
  */
2192 2192
 function loadTemplate($template_name, $style_sheets = array(), $fatal = true)
2193 2193
 {
@@ -2374,7 +2374,7 @@  discard block
 block discarded – undo
2374 2374
  * - all code added with this function is added to the same <style> tag so do make sure your css is valid!
2375 2375
  *
2376 2376
  * @param string $css Some css code
2377
- * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2377
+ * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified
2378 2378
  */
2379 2379
 function addInlineCss($css)
2380 2380
 {
@@ -2390,7 +2390,7 @@  discard block
 block discarded – undo
2390 2390
 /**
2391 2391
  * Add a Javascript file for output later
2392 2392
 
2393
- * @param string $filename The name of the file to load
2393
+ * @param string $fileName The name of the file to load
2394 2394
  * @param array $params An array of parameter info
2395 2395
  * Keys are the following:
2396 2396
  * 	- ['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
@@ -2487,7 +2487,7 @@  discard block
 block discarded – undo
2487 2487
  *
2488 2488
  * @param string $javascript Some JS code
2489 2489
  * @param bool $defer Whether the script should load in <head> or before the closing <html> tag
2490
- * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2490
+ * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified
2491 2491
  */
2492 2492
 function addInlineJavascript($javascript, $defer = false)
2493 2493
 {
@@ -2717,7 +2717,7 @@  discard block
 block discarded – undo
2717 2717
  *
2718 2718
  * @param bool $use_cache Whether or not to use the cache
2719 2719
  * @param bool $favor_utf8 Whether or not to favor UTF-8 files
2720
- * @return array An array of information about available languages
2720
+ * @return string An array of information about available languages
2721 2721
  */
2722 2722
 function getLanguages($use_cache = true, $favor_utf8 = true)
2723 2723
 {
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
 
67 67
 	// Set a list of common functions.
68 68
 	$ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);';
69
-	$ent_check = empty($modSettings['disableEntityCheck']) ? function ($string)
69
+	$ent_check = empty($modSettings['disableEntityCheck']) ? function($string)
70 70
 		{
71 71
 			$string = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $string);
72 72
 			return $string;
73
-		} : function ($string)
73
+		} : function($string)
74 74
 		{
75 75
 			return $string;
76 76
 		};
77
-	$fix_utf8mb4 = function ($string) use ($utf8)
77
+	$fix_utf8mb4 = function($string) use ($utf8)
78 78
 	{
79 79
 		if (!$utf8)
80 80
 			return $string;
@@ -92,21 +92,21 @@  discard block
 block discarded – undo
92 92
 			}
93 93
 			elseif ($ord < 224)
94 94
 			{
95
-				$new_string .= $string[$i] . $string[$i+1];
95
+				$new_string .= $string[$i] . $string[$i + 1];
96 96
 				$i += 2;
97 97
 			}
98 98
 			elseif ($ord < 240)
99 99
 			{
100
-				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
100
+				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
101 101
 				$i += 3;
102 102
 			}
103 103
 			elseif ($ord < 248)
104 104
 			{
105 105
 				// Magic happens.
106 106
 				$val = (ord($string[$i]) & 0x07) << 18;
107
-				$val += (ord($string[$i+1]) & 0x3F) << 12;
108
-				$val += (ord($string[$i+2]) & 0x3F) << 6;
109
-				$val += (ord($string[$i+3]) & 0x3F);
107
+				$val += (ord($string[$i + 1]) & 0x3F) << 12;
108
+				$val += (ord($string[$i + 2]) & 0x3F) << 6;
109
+				$val += (ord($string[$i + 3]) & 0x3F);
110 110
 				$new_string .= '&#' . $val . ';';
111 111
 				$i += 4;
112 112
 			}
@@ -119,24 +119,24 @@  discard block
 block discarded – undo
119 119
 
120 120
 	// global array of anonymous helper functions, used mostly to properly handle multi byte strings
121 121
 	$smcFunc += array(
122
-		'entity_fix' => function ($string)
122
+		'entity_fix' => function($string)
123 123
 		{
124 124
 			$num = $string[0] === 'x' ? hexdec(substr($string, 1)) : (int) $string;
125 125
 			return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? '' : '&#' . $num . ';';
126 126
 		},
127
-		'htmlspecialchars' => function ($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4)
127
+		'htmlspecialchars' => function($string, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1') use ($ent_check, $utf8, $fix_utf8mb4)
128 128
 		{
129 129
 			return $fix_utf8mb4($ent_check(htmlspecialchars($string, $quote_style, $utf8 ? 'UTF-8' : $charset)));
130 130
 		},
131
-		'htmltrim' => function ($string) use ($utf8, $space_chars, $ent_check)
131
+		'htmltrim' => function($string) use ($utf8, $space_chars, $ent_check)
132 132
 		{
133 133
 			return preg_replace('~^(?:[ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+|(?:[ \t\n\r\x0B\x00' . $space_chars . ']|&nbsp;)+$~' . ($utf8 ? 'u' : ''), '', $ent_check($string));
134 134
 		},
135
-		'strlen' => function ($string) use ($ent_list, $utf8, $ent_check)
135
+		'strlen' => function($string) use ($ent_list, $utf8, $ent_check)
136 136
 		{
137 137
 			return strlen(preg_replace('~' . $ent_list . ($utf8 ? '|.~u' : '~'), '_', $ent_check($string)));
138 138
 		},
139
-		'strpos' => function ($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings)
139
+		'strpos' => function($haystack, $needle, $offset = 0) use ($utf8, $ent_check, $modSettings)
140 140
 		{
141 141
 			$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);
142 142
 
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
 				return false;
162 162
 			}
163 163
 		},
164
-		'substr' => function ($string, $start, $length = null) use ($utf8, $ent_check, $modSettings)
164
+		'substr' => function($string, $start, $length = null) use ($utf8, $ent_check, $modSettings)
165 165
 		{
166 166
 			$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);
167 167
 			return $length === null ? implode('', array_slice($ent_arr, $start)) : implode('', array_slice($ent_arr, $start, $length));
168 168
 		},
169
-		'strtolower' => $utf8 ? function ($string) use ($sourcedir)
169
+		'strtolower' => $utf8 ? function($string) use ($sourcedir)
170 170
 		{
171 171
 			if (!function_exists('mb_strtolower'))
172 172
 			{
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
 			return mb_strtolower($string, 'UTF-8');
178 178
 		} : 'strtolower',
179
-		'strtoupper' => $utf8 ? function ($string)
179
+		'strtoupper' => $utf8 ? function($string)
180 180
 		{
181 181
 			global $sourcedir;
182 182
 
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
 		'truncate' => function($string, $length) use ($utf8, $ent_check, $ent_list, &$smcFunc)
192 192
 		{
193 193
 			$string = $ent_check($string);
194
-			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
194
+			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
195 195
 			$string = $matches[0];
196 196
 			while (strlen($string) > $length)
197
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
197
+				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
198 198
 			return $string;
199 199
 		},
200
-		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
200
+		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
201 201
 		{
202 202
 			return $smcFunc['strtoupper']($smcFunc['substr']($string, 0, 1)) . $smcFunc['substr']($string, 1);
203 203
 		} : 'ucfirst',
204
-		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
204
+		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
205 205
 		{
206 206
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
207 207
 			for ($i = 0, $n = count($words); $i < $n; $i += 2)
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 		else
598 598
 		{
599 599
 			// !!! Compatibility.
600
-			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
600
+			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
601 601
 		}
602 602
 	}
603 603
 	// If the user is a guest, initialize all the critical user settings.
@@ -1397,7 +1397,7 @@  discard block
 block discarded – undo
1397 1397
 		'name' => $profile['real_name'],
1398 1398
 		'id' => $profile['id_member'],
1399 1399
 		'href' => $scripturl . '?action=profile;u=' . $profile['id_member'],
1400
-		'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>',
1400
+		'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>',
1401 1401
 		'email' => $profile['email_address'],
1402 1402
 		'show_email' => !$user_info['is_guest'] && ($user_info['id'] == $profile['id_member'] || allowedTo('moderate_forum')),
1403 1403
 		'registered' => empty($profile['date_registered']) ? $txt['not_applicable'] : timeformat($profile['date_registered']),
@@ -1407,9 +1407,9 @@  discard block
 block discarded – undo
1407 1407
 	// If the set isn't minimal then load the monstrous array.
1408 1408
 	if ($context['loadMemberContext_set'] != 'minimal')
1409 1409
 		$memberContext[$user] += array(
1410
-			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
1411
-			'name_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['real_name'] .'</span>',
1412
-			'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>',
1410
+			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
1411
+			'name_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['real_name'] . '</span>',
1412
+			'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>',
1413 1413
 			'is_buddy' => $profile['buddy'],
1414 1414
 			'is_reverse_buddy' => in_array($user_info['id'], $buddy_list),
1415 1415
 			'buddies' => $buddy_list,
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
 		if (!empty($image))
1479 1479
 			$memberContext[$user]['avatar'] = array(
1480 1480
 				'name' => $profile['avatar'],
1481
-				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1481
+				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1482 1482
 				'href' => $image,
1483 1483
 				'url' => $image,
1484 1484
 			);
@@ -3351,7 +3351,7 @@  discard block
 block discarded – undo
3351 3351
 	$port = 0;
3352 3352
 
3353 3353
 	// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
3354
-	if(strpos($server,'/') !== false)
3354
+	if (strpos($server, '/') !== false)
3355 3355
 		$host = $server;
3356 3356
 	else
3357 3357
 	{
Please login to merge, or discard this patch.
Braces   +835 added lines, -627 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.
@@ -24,12 +25,13 @@  discard block
 block discarded – undo
24 25
 	global $modSettings, $boarddir, $smcFunc, $txt, $db_character_set, $sourcedir, $context;
25 26
 
26 27
 	// Most database systems have not set UTF-8 as their default input charset.
27
-	if (!empty($db_character_set))
28
-		$smcFunc['db_query']('set_character_set', '
28
+	if (!empty($db_character_set)) {
29
+			$smcFunc['db_query']('set_character_set', '
29 30
 			SET NAMES ' . $db_character_set,
30 31
 			array(
31 32
 			)
32 33
 		);
34
+	}
33 35
 
34 36
 	// Try to load it from the cache first; it'll never get cached if the setting is off.
35 37
 	if (($modSettings = cache_get_data('modSettings', 90)) == null)
@@ -41,24 +43,31 @@  discard block
 block discarded – undo
41 43
 			)
42 44
 		);
43 45
 		$modSettings = array();
44
-		if (!$request)
45
-			display_db_error();
46
-		while ($row = $smcFunc['db_fetch_row']($request))
47
-			$modSettings[$row[0]] = $row[1];
46
+		if (!$request) {
47
+					display_db_error();
48
+		}
49
+		while ($row = $smcFunc['db_fetch_row']($request)) {
50
+					$modSettings[$row[0]] = $row[1];
51
+		}
48 52
 		$smcFunc['db_free_result']($request);
49 53
 
50 54
 		// Do a few things to protect against missing settings or settings with invalid values...
51
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
52
-			$modSettings['defaultMaxTopics'] = 20;
53
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
54
-			$modSettings['defaultMaxMessages'] = 15;
55
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
56
-			$modSettings['defaultMaxMembers'] = 30;
57
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
58
-			$modSettings['defaultMaxListItems'] = 15;
55
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
56
+					$modSettings['defaultMaxTopics'] = 20;
57
+		}
58
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
59
+					$modSettings['defaultMaxMessages'] = 15;
60
+		}
61
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
62
+					$modSettings['defaultMaxMembers'] = 30;
63
+		}
64
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
65
+					$modSettings['defaultMaxListItems'] = 15;
66
+		}
59 67
 
60
-		if (!empty($modSettings['cache_enable']))
61
-			cache_put_data('modSettings', $modSettings, 90);
68
+		if (!empty($modSettings['cache_enable'])) {
69
+					cache_put_data('modSettings', $modSettings, 90);
70
+		}
62 71
 	}
63 72
 
64 73
 	// UTF-8 ?
@@ -76,8 +85,9 @@  discard block
 block discarded – undo
76 85
 		};
77 86
 	$fix_utf8mb4 = function ($string) use ($utf8)
78 87
 	{
79
-		if (!$utf8)
80
-			return $string;
88
+		if (!$utf8) {
89
+					return $string;
90
+		}
81 91
 
82 92
 		$i = 0;
83 93
 		$len = strlen($string);
@@ -89,18 +99,15 @@  discard block
 block discarded – undo
89 99
 			{
90 100
 				$new_string .= $string[$i];
91 101
 				$i++;
92
-			}
93
-			elseif ($ord < 224)
102
+			} elseif ($ord < 224)
94 103
 			{
95 104
 				$new_string .= $string[$i] . $string[$i+1];
96 105
 				$i += 2;
97
-			}
98
-			elseif ($ord < 240)
106
+			} elseif ($ord < 240)
99 107
 			{
100 108
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
101 109
 				$i += 3;
102
-			}
103
-			elseif ($ord < 248)
110
+			} elseif ($ord < 248)
104 111
 			{
105 112
 				// Magic happens.
106 113
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -144,8 +151,7 @@  discard block
 block discarded – undo
144 151
 			{
145 152
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
146 153
 				return is_int($result) ? $result + $offset : false;
147
-			}
148
-			else
154
+			} else
149 155
 			{
150 156
 				$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);
151 157
 				$needle_size = count($needle_arr);
@@ -154,8 +160,9 @@  discard block
 block discarded – undo
154 160
 				while ((int) $result === $result)
155 161
 				{
156 162
 					$offset += $result;
157
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
158
-						return $offset;
163
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
164
+											return $offset;
165
+					}
159 166
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
160 167
 				}
161 168
 				return false;
@@ -193,8 +200,9 @@  discard block
 block discarded – undo
193 200
 			$string = $ent_check($string);
194 201
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
195 202
 			$string = $matches[0];
196
-			while (strlen($string) > $length)
197
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
203
+			while (strlen($string) > $length) {
204
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
205
+			}
198 206
 			return $string;
199 207
 		},
200 208
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -204,15 +212,17 @@  discard block
 block discarded – undo
204 212
 		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
205 213
 		{
206 214
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
207
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
208
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
215
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
216
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
217
+			}
209 218
 			return implode('', $words);
210 219
 		} : 'ucwords',
211 220
 	);
212 221
 
213 222
 	// Setting the timezone is a requirement for some functions.
214
-	if (isset($modSettings['default_timezone']))
215
-		date_default_timezone_set($modSettings['default_timezone']);
223
+	if (isset($modSettings['default_timezone'])) {
224
+			date_default_timezone_set($modSettings['default_timezone']);
225
+	}
216 226
 
217 227
 	// Check the load averages?
218 228
 	if (!empty($modSettings['loadavg_enable']))
@@ -220,22 +230,26 @@  discard block
 block discarded – undo
220 230
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
221 231
 		{
222 232
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
223
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
224
-				$modSettings['load_average'] = (float) $matches[1];
225
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
226
-				$modSettings['load_average'] = (float) $matches[1];
227
-			else
228
-				unset($modSettings['load_average']);
233
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
234
+							$modSettings['load_average'] = (float) $matches[1];
235
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
236
+							$modSettings['load_average'] = (float) $matches[1];
237
+			} else {
238
+							unset($modSettings['load_average']);
239
+			}
229 240
 
230
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
231
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
241
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
242
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
243
+			}
232 244
 		}
233 245
 
234
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
235
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
246
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
247
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
248
+		}
236 249
 
237
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
238
-			display_loadavg_error();
250
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
251
+					display_loadavg_error();
252
+		}
239 253
 	}
240 254
 
241 255
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -256,8 +270,9 @@  discard block
 block discarded – undo
256 270
 	if (defined('SMF_INTEGRATION_SETTINGS'))
257 271
 	{
258 272
 		$integration_settings = json_decode(SMF_INTEGRATION_SETTINGS, true);
259
-		foreach ($integration_settings as $hook => $function)
260
-			add_integration_function($hook, $function, '', false);
273
+		foreach ($integration_settings as $hook => $function) {
274
+					add_integration_function($hook, $function, '', false);
275
+		}
261 276
 	}
262 277
 
263 278
 	// Any files to pre include?
@@ -267,8 +282,9 @@  discard block
 block discarded – undo
267 282
 		foreach ($pre_includes as $include)
268 283
 		{
269 284
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
270
-			if (file_exists($include))
271
-				require_once($include);
285
+			if (file_exists($include)) {
286
+							require_once($include);
287
+			}
272 288
 		}
273 289
 	}
274 290
 
@@ -369,27 +385,28 @@  discard block
 block discarded – undo
369 385
 				break;
370 386
 			}
371 387
 		}
388
+	} else {
389
+			$id_member = 0;
372 390
 	}
373
-	else
374
-		$id_member = 0;
375 391
 
376 392
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
377 393
 	{
378 394
 		$cookie_data = json_decode($_COOKIE[$cookiename], true);
379 395
 
380
-		if (is_null($cookie_data))
381
-			$cookie_data = @unserialize($_COOKIE[$cookiename]);
396
+		if (is_null($cookie_data)) {
397
+					$cookie_data = @unserialize($_COOKIE[$cookiename]);
398
+		}
382 399
 
383 400
 		list ($id_member, $password) = $cookie_data;
384 401
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
385
-	}
386
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
402
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
387 403
 	{
388 404
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
389 405
 		$cookie_data = json_decode($_SESSION['login_' . $cookiename]);
390 406
 
391
-		if (is_null($cookie_data))
392
-			$cookie_data = @unserialize($_SESSION['login_' . $cookiename]);
407
+		if (is_null($cookie_data)) {
408
+					$cookie_data = @unserialize($_SESSION['login_' . $cookiename]);
409
+		}
393 410
 
394 411
 		list ($id_member, $password, $login_span) = $cookie_data;
395 412
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -414,30 +431,34 @@  discard block
 block discarded – undo
414 431
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
415 432
 			$smcFunc['db_free_result']($request);
416 433
 
417
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
418
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
434
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
435
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
436
+			}
419 437
 
420
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
421
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
438
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
439
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
440
+			}
422 441
 		}
423 442
 
424 443
 		// Did we find 'im?  If not, junk it.
425 444
 		if (!empty($user_settings))
426 445
 		{
427 446
 			// As much as the password should be right, we can assume the integration set things up.
428
-			if (!empty($already_verified) && $already_verified === true)
429
-				$check = true;
447
+			if (!empty($already_verified) && $already_verified === true) {
448
+							$check = true;
449
+			}
430 450
 			// SHA-512 hash should be 128 characters long.
431
-			elseif (strlen($password) == 128)
432
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
433
-			else
434
-				$check = false;
451
+			elseif (strlen($password) == 128) {
452
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
453
+			} else {
454
+							$check = false;
455
+			}
435 456
 
436 457
 			// Wrong password or not activated - either way, you're going nowhere.
437 458
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
459
+		} else {
460
+					$id_member = 0;
438 461
 		}
439
-		else
440
-			$id_member = 0;
441 462
 
442 463
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
443 464
 		if (!$id_member)
@@ -459,13 +480,15 @@  discard block
 block discarded – undo
459 480
 				{
460 481
 					$tfa_data = json_decode($_COOKIE[$tfacookie]);
461 482
 
462
-					if (is_null($tfa_data))
463
-						$tfa_data = @unserialize($_COOKIE[$tfacookie]);
483
+					if (is_null($tfa_data)) {
484
+											$tfa_data = @unserialize($_COOKIE[$tfacookie]);
485
+					}
464 486
 
465 487
 					list ($tfamember, $tfasecret) = $tfa_data;
466 488
 
467
-					if ((int) $tfamember != $id_member)
468
-						$tfasecret = null;
489
+					if ((int) $tfamember != $id_member) {
490
+											$tfasecret = null;
491
+					}
469 492
 				}
470 493
 
471 494
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -485,10 +508,12 @@  discard block
 block discarded – undo
485 508
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
486 509
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
487 510
 		{
488
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
511
+			if ($modSettings['tfa_mode'] == 2) {
512
+				//only do this if we are just forcing SOME membergroups
489 513
 			{
490 514
 				//Build an array of ALL user membergroups.
491 515
 				$full_groups = array($user_settings['id_group']);
516
+			}
492 517
 				if (!empty($user_settings['additional_groups']))
493 518
 				{
494 519
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -508,15 +533,17 @@  discard block
 block discarded – undo
508 533
 				);
509 534
 				$row = $smcFunc['db_fetch_assoc']($request);
510 535
 				$smcFunc['db_free_result']($request);
536
+			} else {
537
+							$row['total'] = 1;
511 538
 			}
512
-			else
513
-				$row['total'] = 1; //simplifies logics in the next "if"
539
+			//simplifies logics in the next "if"
514 540
 
515 541
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
516 542
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
517 543
 
518
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
519
-				redirectexit('action=profile;area=tfasetup;forced');
544
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
545
+							redirectexit('action=profile;area=tfasetup;forced');
546
+			}
520 547
 		}
521 548
 	}
522 549
 
@@ -553,33 +580,37 @@  discard block
 block discarded – undo
553 580
 				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']));
554 581
 				$user_settings['last_login'] = time();
555 582
 
556
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
557
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
583
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
584
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
585
+				}
558 586
 
559
-				if (!empty($modSettings['cache_enable']))
560
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
587
+				if (!empty($modSettings['cache_enable'])) {
588
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
589
+				}
561 590
 			}
591
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
592
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
562 593
 		}
563
-		elseif (empty($_SESSION['id_msg_last_visit']))
564
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
565 594
 
566 595
 		$username = $user_settings['member_name'];
567 596
 
568
-		if (empty($user_settings['additional_groups']))
569
-			$user_info = array(
597
+		if (empty($user_settings['additional_groups'])) {
598
+					$user_info = array(
570 599
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
571 600
 			);
572
-		else
573
-			$user_info = array(
601
+		} else {
602
+					$user_info = array(
574 603
 				'groups' => array_merge(
575 604
 					array($user_settings['id_group'], $user_settings['id_post_group']),
576 605
 					explode(',', $user_settings['additional_groups'])
577 606
 				)
578 607
 			);
608
+		}
579 609
 
580 610
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
581
-		foreach ($user_info['groups'] as $k => $v)
582
-			$user_info['groups'][$k] = (int) $v;
611
+		foreach ($user_info['groups'] as $k => $v) {
612
+					$user_info['groups'][$k] = (int) $v;
613
+		}
583 614
 
584 615
 		// This is a logged in user, so definitely not a spider.
585 616
 		$user_info['possibly_robot'] = false;
@@ -593,8 +624,7 @@  discard block
 block discarded – undo
593 624
 			$time_system = new DateTime('now', $tz_system);
594 625
 			$time_user = new DateTime('now', $tz_user);
595 626
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
596
-		}
597
-		else
627
+		} else
598 628
 		{
599 629
 			// !!! Compatibility.
600 630
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -608,16 +638,18 @@  discard block
 block discarded – undo
608 638
 		$user_info = array('groups' => array(-1));
609 639
 		$user_settings = array();
610 640
 
611
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
612
-			$_COOKIE[$cookiename] = '';
641
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
642
+					$_COOKIE[$cookiename] = '';
643
+		}
613 644
 
614 645
 		// Expire the 2FA cookie
615 646
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
616 647
 		{
617 648
 			$tfa_data = json_decode($_COOKIE[$cookiename . '_tfa'], true);
618 649
 
619
-			if (is_null($tfa_data))
620
-				$tfa_data = @unserialize($_COOKIE[$cookiename . '_tfa']);
650
+			if (is_null($tfa_data)) {
651
+							$tfa_data = @unserialize($_COOKIE[$cookiename . '_tfa']);
652
+			}
621 653
 
622 654
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
623 655
 
@@ -629,19 +661,20 @@  discard block
 block discarded – undo
629 661
 		}
630 662
 
631 663
 		// Create a login token if it doesn't exist yet.
632
-		if (!isset($_SESSION['token']['post-login']))
633
-			createToken('login');
634
-		else
635
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
664
+		if (!isset($_SESSION['token']['post-login'])) {
665
+					createToken('login');
666
+		} else {
667
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
668
+		}
636 669
 
637 670
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
638 671
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
639 672
 		{
640 673
 			require_once($sourcedir . '/ManageSearchEngines.php');
641 674
 			$user_info['possibly_robot'] = SpiderCheck();
675
+		} elseif (!empty($modSettings['spider_mode'])) {
676
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
642 677
 		}
643
-		elseif (!empty($modSettings['spider_mode']))
644
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
645 678
 		// If we haven't turned on proper spider hunts then have a guess!
646 679
 		else
647 680
 		{
@@ -689,8 +722,9 @@  discard block
 block discarded – undo
689 722
 	$user_info['groups'] = array_unique($user_info['groups']);
690 723
 
691 724
 	// 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.
692
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
693
-		unset($user_info['ignoreboards'][$tmp]);
725
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
726
+			unset($user_info['ignoreboards'][$tmp]);
727
+	}
694 728
 
695 729
 	// Allow the user to change their language.
696 730
 	if (!empty($modSettings['userLanguage']))
@@ -703,31 +737,36 @@  discard block
 block discarded – undo
703 737
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
704 738
 
705 739
 			// Make it permanent for memmbers.
706
-			if (!empty($user_info['id']))
707
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
708
-			else
709
-				$_SESSION['language'] = $user_info['language'];
740
+			if (!empty($user_info['id'])) {
741
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
742
+			} else {
743
+							$_SESSION['language'] = $user_info['language'];
744
+			}
745
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
746
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
710 747
 		}
711
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
712
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
713 748
 	}
714 749
 
715 750
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
716
-	if ($user_info['is_admin'])
717
-		$user_info['query_see_board'] = '1=1';
751
+	if ($user_info['is_admin']) {
752
+			$user_info['query_see_board'] = '1=1';
753
+	}
718 754
 	// Otherwise just the groups in $user_info['groups'].
719
-	else
720
-		$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'] : '') . ')';
755
+	else {
756
+			$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'] : '') . ')';
757
+	}
721 758
 
722 759
 	// Build the list of boards they WANT to see.
723 760
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
724 761
 
725 762
 	// If they aren't ignoring any boards then they want to see all the boards they can see
726
-	if (empty($user_info['ignoreboards']))
727
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
763
+	if (empty($user_info['ignoreboards'])) {
764
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
765
+	}
728 766
 	// Ok I guess they don't want to see all the boards
729
-	else
730
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
767
+	else {
768
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
769
+	}
731 770
 
732 771
 	call_integration_hook('integrate_user_info');
733 772
 }
@@ -785,9 +824,9 @@  discard block
 block discarded – undo
785 824
 		}
786 825
 
787 826
 		// Remember redirection is the key to avoiding fallout from your bosses.
788
-		if (!empty($topic))
789
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
790
-		else
827
+		if (!empty($topic)) {
828
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
829
+		} else
791 830
 		{
792 831
 			loadPermissions();
793 832
 			loadTheme();
@@ -805,10 +844,11 @@  discard block
 block discarded – undo
805 844
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
806 845
 	{
807 846
 		// @todo SLOW?
808
-		if (!empty($topic))
809
-			$temp = cache_get_data('topic_board-' . $topic, 120);
810
-		else
811
-			$temp = cache_get_data('board-' . $board, 120);
847
+		if (!empty($topic)) {
848
+					$temp = cache_get_data('topic_board-' . $topic, 120);
849
+		} else {
850
+					$temp = cache_get_data('board-' . $board, 120);
851
+		}
812 852
 
813 853
 		if (!empty($temp))
814 854
 		{
@@ -846,8 +886,9 @@  discard block
 block discarded – undo
846 886
 			$row = $smcFunc['db_fetch_assoc']($request);
847 887
 
848 888
 			// Set the current board.
849
-			if (!empty($row['id_board']))
850
-				$board = $row['id_board'];
889
+			if (!empty($row['id_board'])) {
890
+							$board = $row['id_board'];
891
+			}
851 892
 
852 893
 			// Basic operating information. (globals... :/)
853 894
 			$board_info = array(
@@ -883,21 +924,23 @@  discard block
 block discarded – undo
883 924
 
884 925
 			do
885 926
 			{
886
-				if (!empty($row['id_moderator']))
887
-					$board_info['moderators'][$row['id_moderator']] = array(
927
+				if (!empty($row['id_moderator'])) {
928
+									$board_info['moderators'][$row['id_moderator']] = array(
888 929
 						'id' => $row['id_moderator'],
889 930
 						'name' => $row['real_name'],
890 931
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
891 932
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
892 933
 					);
934
+				}
893 935
 
894
-				if (!empty($row['id_moderator_group']))
895
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
936
+				if (!empty($row['id_moderator_group'])) {
937
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
896 938
 						'id' => $row['id_moderator_group'],
897 939
 						'name' => $row['group_name'],
898 940
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
899 941
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
900 942
 					);
943
+				}
901 944
 			}
902 945
 			while ($row = $smcFunc['db_fetch_assoc']($request));
903 946
 
@@ -929,12 +972,12 @@  discard block
 block discarded – undo
929 972
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
930 973
 			{
931 974
 				// @todo SLOW?
932
-				if (!empty($topic))
933
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
975
+				if (!empty($topic)) {
976
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
977
+				}
934 978
 				cache_put_data('board-' . $board, $board_info, 120);
935 979
 			}
936
-		}
937
-		else
980
+		} else
938 981
 		{
939 982
 			// Otherwise the topic is invalid, there are no moderators, etc.
940 983
 			$board_info = array(
@@ -948,8 +991,9 @@  discard block
 block discarded – undo
948 991
 		$smcFunc['db_free_result']($request);
949 992
 	}
950 993
 
951
-	if (!empty($topic))
952
-		$_GET['board'] = (int) $board;
994
+	if (!empty($topic)) {
995
+			$_GET['board'] = (int) $board;
996
+	}
953 997
 
954 998
 	if (!empty($board))
955 999
 	{
@@ -959,10 +1003,12 @@  discard block
 block discarded – undo
959 1003
 		// Now check if the user is a moderator.
960 1004
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
961 1005
 
962
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
963
-			$board_info['error'] = 'access';
964
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
965
-			$board_info['error'] = 'access';
1006
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1007
+					$board_info['error'] = 'access';
1008
+		}
1009
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1010
+					$board_info['error'] = 'access';
1011
+		}
966 1012
 
967 1013
 		// Build up the linktree.
968 1014
 		$context['linktree'] = array_merge(
@@ -985,8 +1031,9 @@  discard block
 block discarded – undo
985 1031
 	$context['current_board'] = $board;
986 1032
 
987 1033
 	// No posting in redirection boards!
988
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
989
-		$board_info['error'] == 'post_in_redirect';
1034
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1035
+			$board_info['error'] == 'post_in_redirect';
1036
+	}
990 1037
 
991 1038
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
992 1039
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1012,24 +1059,23 @@  discard block
 block discarded – undo
1012 1059
 			ob_end_clean();
1013 1060
 			header('HTTP/1.1 403 Forbidden');
1014 1061
 			die;
1015
-		}
1016
-		elseif ($board_info['error'] == 'post_in_redirect')
1062
+		} elseif ($board_info['error'] == 'post_in_redirect')
1017 1063
 		{
1018 1064
 			// Slightly different error message here...
1019 1065
 			fatal_lang_error('cannot_post_redirect', false);
1020
-		}
1021
-		elseif ($user_info['is_guest'])
1066
+		} elseif ($user_info['is_guest'])
1022 1067
 		{
1023 1068
 			loadLanguage('Errors');
1024 1069
 			is_not_guest($txt['topic_gone']);
1070
+		} else {
1071
+					fatal_lang_error('topic_gone', false);
1025 1072
 		}
1026
-		else
1027
-			fatal_lang_error('topic_gone', false);
1028 1073
 	}
1029 1074
 
1030
-	if ($user_info['is_mod'])
1031
-		$user_info['groups'][] = 3;
1032
-}
1075
+	if ($user_info['is_mod']) {
1076
+			$user_info['groups'][] = 3;
1077
+	}
1078
+	}
1033 1079
 
1034 1080
 /**
1035 1081
  * Load this user's permissions.
@@ -1050,8 +1096,9 @@  discard block
 block discarded – undo
1050 1096
 		asort($cache_groups);
1051 1097
 		$cache_groups = implode(',', $cache_groups);
1052 1098
 		// If it's a spider then cache it different.
1053
-		if ($user_info['possibly_robot'])
1054
-			$cache_groups .= '-spider';
1099
+		if ($user_info['possibly_robot']) {
1100
+					$cache_groups .= '-spider';
1101
+		}
1055 1102
 
1056 1103
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1057 1104
 		{
@@ -1059,9 +1106,9 @@  discard block
 block discarded – undo
1059 1106
 			banPermissions();
1060 1107
 
1061 1108
 			return;
1109
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1110
+					list ($user_info['permissions'], $removals) = $temp;
1062 1111
 		}
1063
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1064
-			list ($user_info['permissions'], $removals) = $temp;
1065 1112
 	}
1066 1113
 
1067 1114
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1083,23 +1130,26 @@  discard block
 block discarded – undo
1083 1130
 		$removals = array();
1084 1131
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1085 1132
 		{
1086
-			if (empty($row['add_deny']))
1087
-				$removals[] = $row['permission'];
1088
-			else
1089
-				$user_info['permissions'][] = $row['permission'];
1133
+			if (empty($row['add_deny'])) {
1134
+							$removals[] = $row['permission'];
1135
+			} else {
1136
+							$user_info['permissions'][] = $row['permission'];
1137
+			}
1090 1138
 		}
1091 1139
 		$smcFunc['db_free_result']($request);
1092 1140
 
1093
-		if (isset($cache_groups))
1094
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1141
+		if (isset($cache_groups)) {
1142
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1143
+		}
1095 1144
 	}
1096 1145
 
1097 1146
 	// Get the board permissions.
1098 1147
 	if (!empty($board))
1099 1148
 	{
1100 1149
 		// Make sure the board (if any) has been loaded by loadBoard().
1101
-		if (!isset($board_info['profile']))
1102
-			fatal_lang_error('no_board');
1150
+		if (!isset($board_info['profile'])) {
1151
+					fatal_lang_error('no_board');
1152
+		}
1103 1153
 
1104 1154
 		$request = $smcFunc['db_query']('', '
1105 1155
 			SELECT permission, add_deny
@@ -1115,20 +1165,23 @@  discard block
 block discarded – undo
1115 1165
 		);
1116 1166
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1117 1167
 		{
1118
-			if (empty($row['add_deny']))
1119
-				$removals[] = $row['permission'];
1120
-			else
1121
-				$user_info['permissions'][] = $row['permission'];
1168
+			if (empty($row['add_deny'])) {
1169
+							$removals[] = $row['permission'];
1170
+			} else {
1171
+							$user_info['permissions'][] = $row['permission'];
1172
+			}
1122 1173
 		}
1123 1174
 		$smcFunc['db_free_result']($request);
1124 1175
 	}
1125 1176
 
1126 1177
 	// Remove all the permissions they shouldn't have ;).
1127
-	if (!empty($modSettings['permission_enable_deny']))
1128
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1178
+	if (!empty($modSettings['permission_enable_deny'])) {
1179
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1180
+	}
1129 1181
 
1130
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1131
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1182
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1183
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1184
+	}
1132 1185
 
1133 1186
 	// Banned?  Watch, don't touch..
1134 1187
 	banPermissions();
@@ -1140,17 +1193,18 @@  discard block
 block discarded – undo
1140 1193
 		{
1141 1194
 			require_once($sourcedir . '/Subs-Auth.php');
1142 1195
 			rebuildModCache();
1196
+		} else {
1197
+					$user_info['mod_cache'] = $_SESSION['mc'];
1143 1198
 		}
1144
-		else
1145
-			$user_info['mod_cache'] = $_SESSION['mc'];
1146 1199
 
1147 1200
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1148 1201
 		// For example this drastically simplifies certain changes to the profile area.
1149 1202
 		$user_info['permissions'][] = 'is_not_guest';
1150 1203
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1151 1204
 		$user_info['permissions'][] = 'profile_view_own';
1152
-		if (in_array('profile_view', $user_info['permissions']))
1153
-			$user_info['permissions'][] = 'profile_view_any';
1205
+		if (in_array('profile_view', $user_info['permissions'])) {
1206
+					$user_info['permissions'][] = 'profile_view_any';
1207
+		}
1154 1208
 	}
1155 1209
 }
1156 1210
 
@@ -1168,8 +1222,9 @@  discard block
 block discarded – undo
1168 1222
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1169 1223
 
1170 1224
 	// Can't just look for no users :P.
1171
-	if (empty($users))
1172
-		return array();
1225
+	if (empty($users)) {
1226
+			return array();
1227
+	}
1173 1228
 
1174 1229
 	// Pass the set value
1175 1230
 	$context['loadMemberContext_set'] = $set;
@@ -1184,8 +1239,9 @@  discard block
 block discarded – undo
1184 1239
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1185 1240
 		{
1186 1241
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1187
-			if ($data == null)
1188
-				continue;
1242
+			if ($data == null) {
1243
+							continue;
1244
+			}
1189 1245
 
1190 1246
 			$loaded_ids[] = $data['id_member'];
1191 1247
 			$user_profile[$data['id_member']] = $data;
@@ -1249,8 +1305,9 @@  discard block
 block discarded – undo
1249 1305
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1250 1306
 		{
1251 1307
 			// Take care of proxying avatar if required, do this here for maximum reach
1252
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1253
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1308
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1309
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1310
+			}
1254 1311
 
1255 1312
 			$new_loaded_ids[] = $row['id_member'];
1256 1313
 			$loaded_ids[] = $row['id_member'];
@@ -1270,8 +1327,9 @@  discard block
 block discarded – undo
1270 1327
 				'loaded_ids' => $new_loaded_ids,
1271 1328
 			)
1272 1329
 		);
1273
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1274
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1330
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1331
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1332
+		}
1275 1333
 		$smcFunc['db_free_result']($request);
1276 1334
 	}
1277 1335
 
@@ -1282,10 +1340,11 @@  discard block
 block discarded – undo
1282 1340
 	{
1283 1341
 		foreach ($loaded_ids as $a_member)
1284 1342
 		{
1285
-			if (!empty($user_profile[$a_member]['additional_groups']))
1286
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1287
-			else
1288
-				$groups = array($user_profile[$a_member]['id_group']);
1343
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1344
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1345
+			} else {
1346
+							$groups = array($user_profile[$a_member]['id_group']);
1347
+			}
1289 1348
 
1290 1349
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1291 1350
 
@@ -1298,8 +1357,9 @@  discard block
 block discarded – undo
1298 1357
 
1299 1358
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1300 1359
 	{
1301
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1302
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1360
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1361
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1362
+		}
1303 1363
 	}
1304 1364
 
1305 1365
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1325,14 +1385,17 @@  discard block
 block discarded – undo
1325 1385
 		foreach ($temp_mods as $id)
1326 1386
 		{
1327 1387
 			// By popular demand, don't show admins or global moderators as moderators.
1328
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1329
-				$user_profile[$id]['member_group'] = $row['member_group'];
1388
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1389
+							$user_profile[$id]['member_group'] = $row['member_group'];
1390
+			}
1330 1391
 
1331 1392
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1332
-			if (!empty($row['icons']))
1333
-				$user_profile[$id]['icons'] = $row['icons'];
1334
-			if (!empty($row['member_group_color']))
1335
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1393
+			if (!empty($row['icons'])) {
1394
+							$user_profile[$id]['icons'] = $row['icons'];
1395
+			}
1396
+			if (!empty($row['member_group_color'])) {
1397
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1398
+			}
1336 1399
 		}
1337 1400
 	}
1338 1401
 
@@ -1353,12 +1416,14 @@  discard block
 block discarded – undo
1353 1416
 	static $dataLoaded = array();
1354 1417
 
1355 1418
 	// If this person's data is already loaded, skip it.
1356
-	if (isset($dataLoaded[$user]))
1357
-		return true;
1419
+	if (isset($dataLoaded[$user])) {
1420
+			return true;
1421
+	}
1358 1422
 
1359 1423
 	// We can't load guests or members not loaded by loadMemberData()!
1360
-	if ($user == 0)
1361
-		return false;
1424
+	if ($user == 0) {
1425
+			return false;
1426
+	}
1362 1427
 	if (!isset($user_profile[$user]))
1363 1428
 	{
1364 1429
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1384,12 +1449,16 @@  discard block
 block discarded – undo
1384 1449
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1385 1450
 
1386 1451
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1387
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1452
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1453
+		//icon is set and exists
1388 1454
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1389
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1455
+	} elseif (isset($profile['icons'][1])) {
1456
+		//icon is set and doesn't exist, fallback to default
1390 1457
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1391
-	else //not set, bye bye
1458
+	} else {
1459
+		//not set, bye bye
1392 1460
 		$group_icon_url = '';
1461
+	}
1393 1462
 
1394 1463
 	// These minimal values are always loaded
1395 1464
 	$memberContext[$user] = array(
@@ -1405,8 +1474,8 @@  discard block
 block discarded – undo
1405 1474
 	);
1406 1475
 
1407 1476
 	// If the set isn't minimal then load the monstrous array.
1408
-	if ($context['loadMemberContext_set'] != 'minimal')
1409
-		$memberContext[$user] += array(
1477
+	if ($context['loadMemberContext_set'] != 'minimal') {
1478
+			$memberContext[$user] += array(
1410 1479
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
1411 1480
 			'name_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['real_name'] .'</span>',
1412 1481
 			'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>',
@@ -1451,72 +1520,81 @@  discard block
 block discarded – undo
1451 1520
 			'local_time' => timeformat(time() + ($profile['time_offset'] - $user_info['time_offset']) * 3600, false),
1452 1521
 			'custom_fields' => array(),
1453 1522
 		);
1523
+	}
1454 1524
 
1455 1525
 	// If the set isn't minimal then load their avatar as ell.
1456 1526
 	if ($context['loadMemberContext_set'] != 'minimal')
1457 1527
 	{
1458 1528
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1459 1529
 		{
1460
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1461
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1462
-			else
1463
-				$image = get_gravatar_url($profile['email_address']);
1464
-		}
1465
-		else
1530
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1531
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1532
+			} else {
1533
+							$image = get_gravatar_url($profile['email_address']);
1534
+			}
1535
+		} else
1466 1536
 		{
1467 1537
 			// So it's stored in the member table?
1468 1538
 			if (!empty($profile['avatar']))
1469 1539
 			{
1470 1540
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1541
+			} elseif (!empty($profile['filename'])) {
1542
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1471 1543
 			}
1472
-			elseif (!empty($profile['filename']))
1473
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1474 1544
 			// Right... no avatar...use the default one
1475
-			else
1476
-				$image = $modSettings['avatar_url'] . '/default.png';
1545
+			else {
1546
+							$image = $modSettings['avatar_url'] . '/default.png';
1547
+			}
1477 1548
 		}
1478
-		if (!empty($image))
1479
-			$memberContext[$user]['avatar'] = array(
1549
+		if (!empty($image)) {
1550
+					$memberContext[$user]['avatar'] = array(
1480 1551
 				'name' => $profile['avatar'],
1481 1552
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1482 1553
 				'href' => $image,
1483 1554
 				'url' => $image,
1484 1555
 			);
1556
+		}
1485 1557
 	}
1486 1558
 
1487 1559
 	// Are we also loading the members custom fields into context?
1488 1560
 	if ($display_custom_fields && !empty($modSettings['displayFields']))
1489 1561
 	{
1490 1562
 		$memberContext[$user]['custom_fields'] = array();
1491
-		if (!isset($context['display_fields']))
1492
-			$context['display_fields'] = json_decode($modSettings['displayFields'], true);
1563
+		if (!isset($context['display_fields'])) {
1564
+					$context['display_fields'] = json_decode($modSettings['displayFields'], true);
1565
+		}
1493 1566
 
1494 1567
 		foreach ($context['display_fields'] as $custom)
1495 1568
 		{
1496
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1497
-				continue;
1569
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1570
+							continue;
1571
+			}
1498 1572
 
1499 1573
 			$value = $profile['options'][$custom['col_name']];
1500 1574
 
1501 1575
 			// Don't show the "disabled" option for the "gender" field.
1502
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1503
-				continue;
1576
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1577
+							continue;
1578
+			}
1504 1579
 
1505 1580
 			// BBC?
1506
-			if ($custom['bbc'])
1507
-				$value = parse_bbc($value);
1581
+			if ($custom['bbc']) {
1582
+							$value = parse_bbc($value);
1583
+			}
1508 1584
 			// ... or checkbox?
1509
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1510
-				$value = $value ? $txt['yes'] : $txt['no'];
1585
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1586
+							$value = $value ? $txt['yes'] : $txt['no'];
1587
+			}
1511 1588
 
1512 1589
 			// Enclosing the user input within some other text?
1513
-			if (!empty($custom['enclose']))
1514
-				$value = strtr($custom['enclose'], array(
1590
+			if (!empty($custom['enclose'])) {
1591
+							$value = strtr($custom['enclose'], array(
1515 1592
 					'{SCRIPTURL}' => $scripturl,
1516 1593
 					'{IMAGES_URL}' => $settings['images_url'],
1517 1594
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1518 1595
 					'{INPUT}' => $value,
1519 1596
 				));
1597
+			}
1520 1598
 
1521 1599
 			$memberContext[$user]['custom_fields'][] = array(
1522 1600
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1543,8 +1621,9 @@  discard block
 block discarded – undo
1543 1621
 	global $smcFunc, $txt, $scripturl, $settings;
1544 1622
 
1545 1623
 	// Do not waste my time...
1546
-	if (empty($users) || empty($params))
1547
-		return false;
1624
+	if (empty($users) || empty($params)) {
1625
+			return false;
1626
+	}
1548 1627
 
1549 1628
 	// Make sure it's an array.
1550 1629
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1568,31 +1647,36 @@  discard block
 block discarded – undo
1568 1647
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1569 1648
 	{
1570 1649
 		// BBC?
1571
-		if (!empty($row['bbc']))
1572
-			$row['value'] = parse_bbc($row['value']);
1650
+		if (!empty($row['bbc'])) {
1651
+					$row['value'] = parse_bbc($row['value']);
1652
+		}
1573 1653
 
1574 1654
 		// ... or checkbox?
1575
-		elseif (isset($row['type']) && $row['type'] == 'check')
1576
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1655
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1656
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1657
+		}
1577 1658
 
1578 1659
 		// Enclosing the user input within some other text?
1579
-		if (!empty($row['enclose']))
1580
-			$row['value'] = strtr($row['enclose'], array(
1660
+		if (!empty($row['enclose'])) {
1661
+					$row['value'] = strtr($row['enclose'], array(
1581 1662
 				'{SCRIPTURL}' => $scripturl,
1582 1663
 				'{IMAGES_URL}' => $settings['images_url'],
1583 1664
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1584 1665
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1585 1666
 			));
1667
+		}
1586 1668
 
1587 1669
 		// Send a simple array if there is just 1 param
1588
-		if (count($params) == 1)
1589
-			$return[$row['id_member']] = $row;
1670
+		if (count($params) == 1) {
1671
+					$return[$row['id_member']] = $row;
1672
+		}
1590 1673
 
1591 1674
 		// More than 1? knock yourself out...
1592 1675
 		else
1593 1676
 		{
1594
-			if (!isset($return[$row['id_member']]))
1595
-				$return[$row['id_member']] = array();
1677
+			if (!isset($return[$row['id_member']])) {
1678
+							$return[$row['id_member']] = array();
1679
+			}
1596 1680
 
1597 1681
 			$return[$row['id_member']][$row['variable']] = $row;
1598 1682
 		}
@@ -1626,8 +1710,9 @@  discard block
 block discarded – undo
1626 1710
 	global $context;
1627 1711
 
1628 1712
 	// Don't know any browser!
1629
-	if (empty($context['browser']))
1630
-		detectBrowser();
1713
+	if (empty($context['browser'])) {
1714
+			detectBrowser();
1715
+	}
1631 1716
 
1632 1717
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1633 1718
 }
@@ -1645,8 +1730,9 @@  discard block
 block discarded – undo
1645 1730
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1646 1731
 
1647 1732
 	// The theme was specified by parameter.
1648
-	if (!empty($id_theme))
1649
-		$id_theme = (int) $id_theme;
1733
+	if (!empty($id_theme)) {
1734
+			$id_theme = (int) $id_theme;
1735
+	}
1650 1736
 	// The theme was specified by REQUEST.
1651 1737
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1652 1738
 	{
@@ -1654,51 +1740,58 @@  discard block
 block discarded – undo
1654 1740
 		$_SESSION['id_theme'] = $id_theme;
1655 1741
 	}
1656 1742
 	// The theme was specified by REQUEST... previously.
1657
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1658
-		$id_theme = (int) $_SESSION['id_theme'];
1743
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1744
+			$id_theme = (int) $_SESSION['id_theme'];
1745
+	}
1659 1746
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1660
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1661
-		$id_theme = $user_info['theme'];
1747
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1748
+			$id_theme = $user_info['theme'];
1749
+	}
1662 1750
 	// The theme was specified by the board.
1663
-	elseif (!empty($board_info['theme']))
1664
-		$id_theme = $board_info['theme'];
1751
+	elseif (!empty($board_info['theme'])) {
1752
+			$id_theme = $board_info['theme'];
1753
+	}
1665 1754
 	// The theme is the forum's default.
1666
-	else
1667
-		$id_theme = $modSettings['theme_guests'];
1755
+	else {
1756
+			$id_theme = $modSettings['theme_guests'];
1757
+	}
1668 1758
 
1669 1759
 	// Verify the id_theme... no foul play.
1670 1760
 	// Always allow the board specific theme, if they are overriding.
1671
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1672
-		$id_theme = $board_info['theme'];
1761
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1762
+			$id_theme = $board_info['theme'];
1763
+	}
1673 1764
 	// If they have specified a particular theme to use with SSI allow it to be used.
1674
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1675
-		$id_theme = (int) $id_theme;
1676
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1765
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1766
+			$id_theme = (int) $id_theme;
1767
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1677 1768
 	{
1678 1769
 		$themes = explode(',', $modSettings['enableThemes']);
1679
-		if (!in_array($id_theme, $themes))
1680
-			$id_theme = $modSettings['theme_guests'];
1681
-		else
1770
+		if (!in_array($id_theme, $themes)) {
1771
+					$id_theme = $modSettings['theme_guests'];
1772
+		} else {
1773
+					$id_theme = (int) $id_theme;
1774
+		}
1775
+	} else {
1682 1776
 			$id_theme = (int) $id_theme;
1683 1777
 	}
1684
-	else
1685
-		$id_theme = (int) $id_theme;
1686 1778
 
1687 1779
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1688 1780
 
1689 1781
 	// Disable image proxy if we don't have SSL enabled
1690
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1691
-		$image_proxy_enabled = false;
1782
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1783
+			$image_proxy_enabled = false;
1784
+	}
1692 1785
 
1693 1786
 	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'])
1694 1787
 	{
1695 1788
 		$themeData = $temp;
1696 1789
 		$flag = true;
1790
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1791
+			$themeData = $temp + array($member => array());
1792
+	} else {
1793
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1697 1794
 	}
1698
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1699
-		$themeData = $temp + array($member => array());
1700
-	else
1701
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1702 1795
 
1703 1796
 	if (empty($flag))
1704 1797
 	{
@@ -1717,31 +1810,37 @@  discard block
 block discarded – undo
1717 1810
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1718 1811
 		{
1719 1812
 			// There are just things we shouldn't be able to change as members.
1720
-			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')))
1721
-				continue;
1813
+			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'))) {
1814
+							continue;
1815
+			}
1722 1816
 
1723 1817
 			// If this is the theme_dir of the default theme, store it.
1724
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1725
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1818
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1819
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1820
+			}
1726 1821
 
1727 1822
 			// If this isn't set yet, is a theme option, or is not the default theme..
1728
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1729
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1823
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1824
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1825
+			}
1730 1826
 		}
1731 1827
 		$smcFunc['db_free_result']($result);
1732 1828
 
1733
-		if (!empty($themeData[-1]))
1734
-			foreach ($themeData[-1] as $k => $v)
1829
+		if (!empty($themeData[-1])) {
1830
+					foreach ($themeData[-1] as $k => $v)
1735 1831
 			{
1736 1832
 				if (!isset($themeData[$member][$k]))
1737 1833
 					$themeData[$member][$k] = $v;
1834
+		}
1738 1835
 			}
1739 1836
 
1740
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1741
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1837
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1838
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1839
+		}
1742 1840
 		// Only if we didn't already load that part of the cache...
1743
-		elseif (!isset($temp))
1744
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1841
+		elseif (!isset($temp)) {
1842
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1843
+		}
1745 1844
 	}
1746 1845
 
1747 1846
 	$settings = $themeData[0];
@@ -1758,20 +1857,24 @@  discard block
 block discarded – undo
1758 1857
 	$settings['template_dirs'][] = $settings['theme_dir'];
1759 1858
 
1760 1859
 	// Based on theme (if there is one).
1761
-	if (!empty($settings['base_theme_dir']))
1762
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1860
+	if (!empty($settings['base_theme_dir'])) {
1861
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1862
+	}
1763 1863
 
1764 1864
 	// Lastly the default theme.
1765
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1766
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1865
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1866
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1867
+	}
1767 1868
 
1768
-	if (!$initialize)
1769
-		return;
1869
+	if (!$initialize) {
1870
+			return;
1871
+	}
1770 1872
 
1771 1873
 	// Check to see if we're forcing SSL
1772 1874
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1773
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1774
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1875
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1876
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1877
+	}
1775 1878
 
1776 1879
 	// Check to see if they're accessing it from the wrong place.
1777 1880
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1779,8 +1882,9 @@  discard block
 block discarded – undo
1779 1882
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1780 1883
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1781 1884
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1782
-		if ($temp != '/')
1783
-			$detected_url .= $temp;
1885
+		if ($temp != '/') {
1886
+					$detected_url .= $temp;
1887
+		}
1784 1888
 	}
1785 1889
 	if (isset($detected_url) && $detected_url != $boardurl)
1786 1890
 	{
@@ -1792,8 +1896,9 @@  discard block
 block discarded – undo
1792 1896
 			foreach ($aliases as $alias)
1793 1897
 			{
1794 1898
 				// Rip off all the boring parts, spaces, etc.
1795
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1796
-					$do_fix = true;
1899
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1900
+									$do_fix = true;
1901
+				}
1797 1902
 			}
1798 1903
 		}
1799 1904
 
@@ -1801,20 +1906,22 @@  discard block
 block discarded – undo
1801 1906
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1802 1907
 		{
1803 1908
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1804
-			if (empty($_GET))
1805
-				redirectexit('wwwRedirect');
1806
-			else
1909
+			if (empty($_GET)) {
1910
+							redirectexit('wwwRedirect');
1911
+			} else
1807 1912
 			{
1808 1913
 				list ($k, $v) = each($_GET);
1809 1914
 
1810
-				if ($k != 'wwwRedirect')
1811
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1915
+				if ($k != 'wwwRedirect') {
1916
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1917
+				}
1812 1918
 			}
1813 1919
 		}
1814 1920
 
1815 1921
 		// #3 is just a check for SSL...
1816
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1817
-			$do_fix = true;
1922
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1923
+					$do_fix = true;
1924
+		}
1818 1925
 
1819 1926
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1820 1927
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1848,8 +1955,9 @@  discard block
 block discarded – undo
1848 1955
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1849 1956
 				}
1850 1957
 			}
1851
-			foreach ($context['linktree'] as $k => $dummy)
1852
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1958
+			foreach ($context['linktree'] as $k => $dummy) {
1959
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1960
+			}
1853 1961
 		}
1854 1962
 	}
1855 1963
 	// Set up the contextual user array.
@@ -1868,16 +1976,16 @@  discard block
 block discarded – undo
1868 1976
 			'email' => $user_info['email'],
1869 1977
 			'ignoreusers' => $user_info['ignoreusers'],
1870 1978
 		);
1871
-		if (!$context['user']['is_guest'])
1872
-			$context['user']['name'] = $user_info['name'];
1873
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1874
-			$context['user']['name'] = $txt['guest_title'];
1979
+		if (!$context['user']['is_guest']) {
1980
+					$context['user']['name'] = $user_info['name'];
1981
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
1982
+					$context['user']['name'] = $txt['guest_title'];
1983
+		}
1875 1984
 
1876 1985
 		// Determine the current smiley set.
1877 1986
 		$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'];
1878 1987
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1879
-	}
1880
-	else
1988
+	} else
1881 1989
 	{
1882 1990
 		$context['user'] = array(
1883 1991
 			'id' => -1,
@@ -1893,18 +2001,24 @@  discard block
 block discarded – undo
1893 2001
 	}
1894 2002
 
1895 2003
 	// Some basic information...
1896
-	if (!isset($context['html_headers']))
1897
-		$context['html_headers'] = '';
1898
-	if (!isset($context['javascript_files']))
1899
-		$context['javascript_files'] = array();
1900
-	if (!isset($context['css_files']))
1901
-		$context['css_files'] = array();
1902
-	if (!isset($context['css_header']))
1903
-		$context['css_header'] = array();
1904
-	if (!isset($context['javascript_inline']))
1905
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1906
-	if (!isset($context['javascript_vars']))
1907
-		$context['javascript_vars'] = array();
2004
+	if (!isset($context['html_headers'])) {
2005
+			$context['html_headers'] = '';
2006
+	}
2007
+	if (!isset($context['javascript_files'])) {
2008
+			$context['javascript_files'] = array();
2009
+	}
2010
+	if (!isset($context['css_files'])) {
2011
+			$context['css_files'] = array();
2012
+	}
2013
+	if (!isset($context['css_header'])) {
2014
+			$context['css_header'] = array();
2015
+	}
2016
+	if (!isset($context['javascript_inline'])) {
2017
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2018
+	}
2019
+	if (!isset($context['javascript_vars'])) {
2020
+			$context['javascript_vars'] = array();
2021
+	}
1908 2022
 
1909 2023
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1910 2024
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1916,8 +2030,9 @@  discard block
 block discarded – undo
1916 2030
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1917 2031
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1918 2032
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1919
-	if (isset($modSettings['load_average']))
1920
-		$context['load_average'] = $modSettings['load_average'];
2033
+	if (isset($modSettings['load_average'])) {
2034
+			$context['load_average'] = $modSettings['load_average'];
2035
+	}
1921 2036
 
1922 2037
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1923 2038
 	detectBrowser();
@@ -1931,8 +2046,9 @@  discard block
 block discarded – undo
1931 2046
 	// This allows sticking some HTML on the page output - useful for controls.
1932 2047
 	$context['insert_after_template'] = '';
1933 2048
 
1934
-	if (!isset($txt))
1935
-		$txt = array();
2049
+	if (!isset($txt)) {
2050
+			$txt = array();
2051
+	}
1936 2052
 
1937 2053
 	$simpleActions = array(
1938 2054
 		'findmember',
@@ -1965,36 +2081,39 @@  discard block
 block discarded – undo
1965 2081
 	{
1966 2082
 		loadLanguage('index+Modifications');
1967 2083
 		$context['template_layers'] = array();
1968
-	}
1969
-	else
2084
+	} else
1970 2085
 	{
1971 2086
 		// Custom templates to load, or just default?
1972
-		if (isset($settings['theme_templates']))
1973
-			$templates = explode(',', $settings['theme_templates']);
1974
-		else
1975
-			$templates = array('index');
2087
+		if (isset($settings['theme_templates'])) {
2088
+					$templates = explode(',', $settings['theme_templates']);
2089
+		} else {
2090
+					$templates = array('index');
2091
+		}
1976 2092
 
1977 2093
 		// Load each template...
1978
-		foreach ($templates as $template)
1979
-			loadTemplate($template);
2094
+		foreach ($templates as $template) {
2095
+					loadTemplate($template);
2096
+		}
1980 2097
 
1981 2098
 		// ...and attempt to load their associated language files.
1982 2099
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
1983 2100
 		loadLanguage($required_files, '', false);
1984 2101
 
1985 2102
 		// Custom template layers?
1986
-		if (isset($settings['theme_layers']))
1987
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
1988
-		else
1989
-			$context['template_layers'] = array('html', 'body');
2103
+		if (isset($settings['theme_layers'])) {
2104
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2105
+		} else {
2106
+					$context['template_layers'] = array('html', 'body');
2107
+		}
1990 2108
 	}
1991 2109
 
1992 2110
 	// Initialize the theme.
1993 2111
 	loadSubTemplate('init', 'ignore');
1994 2112
 
1995 2113
 	// Allow overriding the board wide time/number formats.
1996
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
1997
-		$user_info['time_format'] = $txt['time_format'];
2114
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2115
+			$user_info['time_format'] = $txt['time_format'];
2116
+	}
1998 2117
 
1999 2118
 	// Set the character set from the template.
2000 2119
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2002,12 +2121,14 @@  discard block
 block discarded – undo
2002 2121
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2003 2122
 
2004 2123
 	// Guests may still need a name.
2005
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2006
-		$context['user']['name'] = $txt['guest_title'];
2124
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2125
+			$context['user']['name'] = $txt['guest_title'];
2126
+	}
2007 2127
 
2008 2128
 	// Any theme-related strings that need to be loaded?
2009
-	if (!empty($settings['require_theme_strings']))
2010
-		loadLanguage('ThemeStrings', '', false);
2129
+	if (!empty($settings['require_theme_strings'])) {
2130
+			loadLanguage('ThemeStrings', '', false);
2131
+	}
2011 2132
 
2012 2133
 	// Make a special URL for the language.
2013 2134
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2018,8 +2139,9 @@  discard block
 block discarded – undo
2018 2139
 	// Here is my luvly Responsive CSS
2019 2140
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2020 2141
 
2021
-	if ($context['right_to_left'])
2022
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2142
+	if ($context['right_to_left']) {
2143
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2144
+	}
2023 2145
 
2024 2146
 	// We allow theme variants, because we're cool.
2025 2147
 	$context['theme_variant'] = '';
@@ -2027,14 +2149,17 @@  discard block
 block discarded – undo
2027 2149
 	if (!empty($settings['theme_variants']))
2028 2150
 	{
2029 2151
 		// Overriding - for previews and that ilk.
2030
-		if (!empty($_REQUEST['variant']))
2031
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2152
+		if (!empty($_REQUEST['variant'])) {
2153
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2154
+		}
2032 2155
 		// User selection?
2033
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2034
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2156
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2157
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2158
+		}
2035 2159
 		// If not a user variant, select the default.
2036
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2037
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2160
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2161
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2162
+		}
2038 2163
 
2039 2164
 		// Do this to keep things easier in the templates.
2040 2165
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2043,20 +2168,23 @@  discard block
 block discarded – undo
2043 2168
 		if (!empty($context['theme_variant']))
2044 2169
 		{
2045 2170
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2046
-			if ($context['right_to_left'])
2047
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2171
+			if ($context['right_to_left']) {
2172
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2173
+			}
2048 2174
 		}
2049 2175
 	}
2050 2176
 
2051 2177
 	// Let's be compatible with old themes!
2052
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2053
-		$context['template_layers'] = array('main');
2178
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2179
+			$context['template_layers'] = array('main');
2180
+	}
2054 2181
 
2055 2182
 	$context['tabindex'] = 1;
2056 2183
 
2057 2184
 	// Compatibility.
2058
-	if (!isset($settings['theme_version']))
2059
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2185
+	if (!isset($settings['theme_version'])) {
2186
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2187
+	}
2060 2188
 
2061 2189
 	// Default JS variables for use in every theme
2062 2190
 	$context['javascript_vars'] = array(
@@ -2075,18 +2203,18 @@  discard block
 block discarded – undo
2075 2203
 	);
2076 2204
 
2077 2205
 	// Add the JQuery library to the list of files to load.
2078
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2079
-		loadJavascriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2080
-
2081
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2082
-		loadJavascriptFile('jquery-2.1.4.min.js', array('default_theme' => true, 'seed' => false), 'smf_jquery');
2083
-
2084
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2085
-		loadJavascriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2206
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2207
+			loadJavascriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2208
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2209
+			loadJavascriptFile('jquery-2.1.4.min.js', array('default_theme' => true, 'seed' => false), 'smf_jquery');
2210
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2211
+			loadJavascriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2212
+	}
2086 2213
 
2087 2214
 	// Auto loading? template_javascript() will take care of the local half of this.
2088
-	else
2089
-		loadJavascriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2215
+	else {
2216
+			loadJavascriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2217
+	}
2090 2218
 
2091 2219
 	// Queue our JQuery plugins!
2092 2220
 	loadJavascriptFile('smf_jquery_plugins.js', array('default_theme' => true, 'minimize' => true), 'smf_jquery_plugins');
@@ -2109,12 +2237,12 @@  discard block
 block discarded – undo
2109 2237
 			require_once($sourcedir . '/ScheduledTasks.php');
2110 2238
 
2111 2239
 			// What to do, what to do?!
2112
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2113
-				AutoTask();
2114
-			else
2115
-				ReduceMailQueue();
2116
-		}
2117
-		else
2240
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2241
+							AutoTask();
2242
+			} else {
2243
+							ReduceMailQueue();
2244
+			}
2245
+		} else
2118 2246
 		{
2119 2247
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2120 2248
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2165,8 +2293,9 @@  discard block
 block discarded – undo
2165 2293
 		foreach ($theme_includes as $include)
2166 2294
 		{
2167 2295
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2168
-			if (file_exists($include))
2169
-				require_once($include);
2296
+			if (file_exists($include)) {
2297
+							require_once($include);
2298
+			}
2170 2299
 		}
2171 2300
 	}
2172 2301
 
@@ -2196,16 +2325,19 @@  discard block
 block discarded – undo
2196 2325
 	// Do any style sheets first, cause we're easy with those.
2197 2326
 	if (!empty($style_sheets))
2198 2327
 	{
2199
-		if (!is_array($style_sheets))
2200
-			$style_sheets = array($style_sheets);
2328
+		if (!is_array($style_sheets)) {
2329
+					$style_sheets = array($style_sheets);
2330
+		}
2201 2331
 
2202
-		foreach ($style_sheets as $sheet)
2203
-			loadCSSFile($sheet . '.css', array(), $sheet);
2332
+		foreach ($style_sheets as $sheet) {
2333
+					loadCSSFile($sheet . '.css', array(), $sheet);
2334
+		}
2204 2335
 	}
2205 2336
 
2206 2337
 	// No template to load?
2207
-	if ($template_name === false)
2208
-		return true;
2338
+	if ($template_name === false) {
2339
+			return true;
2340
+	}
2209 2341
 
2210 2342
 	$loaded = false;
2211 2343
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2221,15 +2353,18 @@  discard block
 block discarded – undo
2221 2353
 	if ($loaded)
2222 2354
 	{
2223 2355
 		// For compatibility reasons, if this is the index template without new functions, include compatible stuff.
2224
-		if (substr($template_name, 0, 5) == 'index' && !function_exists('template_button_strip'))
2225
-			loadTemplate('Compat');
2356
+		if (substr($template_name, 0, 5) == 'index' && !function_exists('template_button_strip')) {
2357
+					loadTemplate('Compat');
2358
+		}
2226 2359
 
2227
-		if ($db_show_debug === true)
2228
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2360
+		if ($db_show_debug === true) {
2361
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2362
+		}
2229 2363
 
2230 2364
 		// If they have specified an initialization function for this template, go ahead and call it now.
2231
-		if (function_exists('template_' . $template_name . '_init'))
2232
-			call_user_func('template_' . $template_name . '_init');
2365
+		if (function_exists('template_' . $template_name . '_init')) {
2366
+					call_user_func('template_' . $template_name . '_init');
2367
+		}
2233 2368
 	}
2234 2369
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2235 2370
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2249,13 +2384,14 @@  discard block
 block discarded – undo
2249 2384
 		loadTemplate($template_name);
2250 2385
 	}
2251 2386
 	// Cause an error otherwise.
2252
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2253
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2254
-	elseif ($fatal)
2255
-		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'));
2256
-	else
2257
-		return false;
2258
-}
2387
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2388
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2389
+	} elseif ($fatal) {
2390
+			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'));
2391
+	} else {
2392
+			return false;
2393
+	}
2394
+	}
2259 2395
 
2260 2396
 
2261 2397
 /**
@@ -2274,17 +2410,19 @@  discard block
 block discarded – undo
2274 2410
 {
2275 2411
 	global $context, $txt, $db_show_debug;
2276 2412
 
2277
-	if ($db_show_debug === true)
2278
-		$context['debug']['sub_templates'][] = $sub_template_name;
2413
+	if ($db_show_debug === true) {
2414
+			$context['debug']['sub_templates'][] = $sub_template_name;
2415
+	}
2279 2416
 
2280 2417
 	// Figure out what the template function is named.
2281 2418
 	$theme_function = 'template_' . $sub_template_name;
2282
-	if (function_exists($theme_function))
2283
-		$theme_function();
2284
-	elseif ($fatal === false)
2285
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2286
-	elseif ($fatal !== 'ignore')
2287
-		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'));
2419
+	if (function_exists($theme_function)) {
2420
+			$theme_function();
2421
+	} elseif ($fatal === false) {
2422
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2423
+	} elseif ($fatal !== 'ignore') {
2424
+			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'));
2425
+	}
2288 2426
 
2289 2427
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2290 2428
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2320,8 +2458,9 @@  discard block
 block discarded – undo
2320 2458
 	$params['external'] = isset($params['external']) ? $params['external'] : false;
2321 2459
 
2322 2460
 	// If this is an external file, automatically set this to false.
2323
-	if (!empty($params['external']))
2324
-		$params['minimize'] = false;
2461
+	if (!empty($params['external'])) {
2462
+			$params['minimize'] = false;
2463
+	}
2325 2464
 
2326 2465
 	// Account for shorthand like admin.css?alp21 filenames
2327 2466
 	$has_seed = strpos($fileName, '.css?');
@@ -2338,13 +2477,10 @@  discard block
 block discarded – undo
2338 2477
 			{
2339 2478
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2340 2479
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2480
+			} else {
2481
+							$fileUrl = false;
2341 2482
 			}
2342
-
2343
-			else
2344
-				$fileUrl = false;
2345
-		}
2346
-
2347
-		else
2483
+		} else
2348 2484
 		{
2349 2485
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2350 2486
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2359,12 +2495,14 @@  discard block
 block discarded – undo
2359 2495
 	}
2360 2496
 
2361 2497
 	// Add it to the array for use in the template
2362
-	if (!empty($fileName))
2363
-		$context['css_files'][$id] = array('filename' => $fileUrl, 'filepath' => $filePath, 'options' => $params);
2498
+	if (!empty($fileName)) {
2499
+			$context['css_files'][$id] = array('filename' => $fileUrl, 'filepath' => $filePath, 'options' => $params);
2500
+	}
2364 2501
 
2365
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2366
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2367
-}
2502
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2503
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2504
+	}
2505
+	}
2368 2506
 
2369 2507
 /**
2370 2508
  * Add a block of inline css code to be executed later
@@ -2381,8 +2519,9 @@  discard block
 block discarded – undo
2381 2519
 	global $context;
2382 2520
 
2383 2521
 	// Gotta add something...
2384
-	if (empty($css))
2385
-		return false;
2522
+	if (empty($css)) {
2523
+			return false;
2524
+	}
2386 2525
 
2387 2526
 	$context['css_header'][] = $css;
2388 2527
 }
@@ -2416,8 +2555,9 @@  discard block
 block discarded – undo
2416 2555
 	$params['external'] = isset($params['external']) ? $params['external'] : false;
2417 2556
 
2418 2557
 	// If this is an external file, automatically set this to false.
2419
-	if (!empty($params['external']))
2420
-		$params['minimize'] = false;
2558
+	if (!empty($params['external'])) {
2559
+			$params['minimize'] = false;
2560
+	}
2421 2561
 
2422 2562
 	// Account for shorthand like admin.js?alp21 filenames
2423 2563
 	$has_seed = strpos($fileName, '.js?');
@@ -2434,16 +2574,12 @@  discard block
 block discarded – undo
2434 2574
 			{
2435 2575
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2436 2576
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2437
-			}
2438
-
2439
-			else
2577
+			} else
2440 2578
 			{
2441 2579
 				$fileUrl = false;
2442 2580
 				$filePath = false;
2443 2581
 			}
2444
-		}
2445
-
2446
-		else
2582
+		} else
2447 2583
 		{
2448 2584
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2449 2585
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2458,9 +2594,10 @@  discard block
 block discarded – undo
2458 2594
 	}
2459 2595
 
2460 2596
 	// Add it to the array for use in the template
2461
-	if (!empty($fileName))
2462
-		$context['javascript_files'][$id] = array('filename' => $fileUrl, 'filepath' => $filePath, 'options' => $params);
2463
-}
2597
+	if (!empty($fileName)) {
2598
+			$context['javascript_files'][$id] = array('filename' => $fileUrl, 'filepath' => $filePath, 'options' => $params);
2599
+	}
2600
+	}
2464 2601
 
2465 2602
 /**
2466 2603
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2474,9 +2611,10 @@  discard block
 block discarded – undo
2474 2611
 {
2475 2612
 	global $context;
2476 2613
 
2477
-	if (!empty($key) && (!empty($value) || $value === '0'))
2478
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2479
-}
2614
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2615
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2616
+	}
2617
+	}
2480 2618
 
2481 2619
 /**
2482 2620
  * Add a block of inline Javascript code to be executed later
@@ -2493,8 +2631,9 @@  discard block
 block discarded – undo
2493 2631
 {
2494 2632
 	global $context;
2495 2633
 
2496
-	if (empty($javascript))
2497
-		return false;
2634
+	if (empty($javascript)) {
2635
+			return false;
2636
+	}
2498 2637
 
2499 2638
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2500 2639
 }
@@ -2515,15 +2654,18 @@  discard block
 block discarded – undo
2515 2654
 	static $already_loaded = array();
2516 2655
 
2517 2656
 	// Default to the user's language.
2518
-	if ($lang == '')
2519
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2657
+	if ($lang == '') {
2658
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2659
+	}
2520 2660
 
2521 2661
 	// Do we want the English version of language file as fallback?
2522
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2523
-		loadLanguage($template_name, 'english', false);
2662
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2663
+			loadLanguage($template_name, 'english', false);
2664
+	}
2524 2665
 
2525
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2526
-		return $lang;
2666
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2667
+			return $lang;
2668
+	}
2527 2669
 
2528 2670
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2529 2671
 	if (empty($settings['default_theme_dir']))
@@ -2534,8 +2676,9 @@  discard block
 block discarded – undo
2534 2676
 
2535 2677
 	// What theme are we in?
2536 2678
 	$theme_name = basename($settings['theme_url']);
2537
-	if (empty($theme_name))
2538
-		$theme_name = 'unknown';
2679
+	if (empty($theme_name)) {
2680
+			$theme_name = 'unknown';
2681
+	}
2539 2682
 
2540 2683
 	// For each file open it up and write it out!
2541 2684
 	foreach (explode('+', $template_name) as $template)
@@ -2614,8 +2757,9 @@  discard block
 block discarded – undo
2614 2757
 	}
2615 2758
 
2616 2759
 	// Keep track of what we're up to soldier.
2617
-	if ($db_show_debug === true)
2618
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2760
+	if ($db_show_debug === true) {
2761
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2762
+	}
2619 2763
 
2620 2764
 	// Remember what we have loaded, and in which language.
2621 2765
 	$already_loaded[$template_name] = $lang;
@@ -2661,8 +2805,9 @@  discard block
 block discarded – undo
2661 2805
 				)
2662 2806
 			);
2663 2807
 			// In the EXTREMELY unlikely event this happens, give an error message.
2664
-			if ($smcFunc['db_num_rows']($result) == 0)
2665
-				fatal_lang_error('parent_not_found', 'critical');
2808
+			if ($smcFunc['db_num_rows']($result) == 0) {
2809
+							fatal_lang_error('parent_not_found', 'critical');
2810
+			}
2666 2811
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2667 2812
 			{
2668 2813
 				if (!isset($boards[$row['id_board']]))
@@ -2679,8 +2824,8 @@  discard block
 block discarded – undo
2679 2824
 					);
2680 2825
 				}
2681 2826
 				// If a moderator exists for this board, add that moderator for all children too.
2682
-				if (!empty($row['id_moderator']))
2683
-					foreach ($boards as $id => $dummy)
2827
+				if (!empty($row['id_moderator'])) {
2828
+									foreach ($boards as $id => $dummy)
2684 2829
 					{
2685 2830
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2686 2831
 							'id' => $row['id_moderator'],
@@ -2688,11 +2833,12 @@  discard block
 block discarded – undo
2688 2833
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2689 2834
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2690 2835
 						);
2836
+				}
2691 2837
 					}
2692 2838
 
2693 2839
 				// If a moderator group exists for this board, add that moderator group for all children too
2694
-				if (!empty($row['id_moderator_group']))
2695
-					foreach ($boards as $id => $dummy)
2840
+				if (!empty($row['id_moderator_group'])) {
2841
+									foreach ($boards as $id => $dummy)
2696 2842
 					{
2697 2843
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2698 2844
 							'id' => $row['id_moderator_group'],
@@ -2700,6 +2846,7 @@  discard block
 block discarded – undo
2700 2846
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2701 2847
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2702 2848
 						);
2849
+				}
2703 2850
 					}
2704 2851
 			}
2705 2852
 			$smcFunc['db_free_result']($result);
@@ -2727,23 +2874,27 @@  discard block
 block discarded – undo
2727 2874
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2728 2875
 	{
2729 2876
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2730
-		if (empty($smcFunc['ucwords']))
2731
-			reloadSettings();
2877
+		if (empty($smcFunc['ucwords'])) {
2878
+					reloadSettings();
2879
+		}
2732 2880
 
2733 2881
 		// If we don't have our theme information yet, let's get it.
2734
-		if (empty($settings['default_theme_dir']))
2735
-			loadTheme(0, false);
2882
+		if (empty($settings['default_theme_dir'])) {
2883
+					loadTheme(0, false);
2884
+		}
2736 2885
 
2737 2886
 		// Default language directories to try.
2738 2887
 		$language_directories = array(
2739 2888
 			$settings['default_theme_dir'] . '/languages',
2740 2889
 		);
2741
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2742
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2890
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2891
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2892
+		}
2743 2893
 
2744 2894
 		// We possibly have a base theme directory.
2745
-		if (!empty($settings['base_theme_dir']))
2746
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2895
+		if (!empty($settings['base_theme_dir'])) {
2896
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2897
+		}
2747 2898
 
2748 2899
 		// Remove any duplicates.
2749 2900
 		$language_directories = array_unique($language_directories);
@@ -2751,15 +2902,17 @@  discard block
 block discarded – undo
2751 2902
 		foreach ($language_directories as $language_dir)
2752 2903
 		{
2753 2904
 			// Can't look in here... doesn't exist!
2754
-			if (!file_exists($language_dir))
2755
-				continue;
2905
+			if (!file_exists($language_dir)) {
2906
+							continue;
2907
+			}
2756 2908
 
2757 2909
 			$dir = dir($language_dir);
2758 2910
 			while ($entry = $dir->read())
2759 2911
 			{
2760 2912
 				// Look for the index language file....
2761
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2762
-					continue;
2913
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2914
+									continue;
2915
+				}
2763 2916
 
2764 2917
 				$context['languages'][$matches[1]] = array(
2765 2918
 					'name' => $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))),
@@ -2775,14 +2928,16 @@  discard block
 block discarded – undo
2775 2928
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2776 2929
 		if ($favor_utf8)
2777 2930
 		{
2778
-			foreach ($context['languages'] as $lang)
2779
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2931
+			foreach ($context['languages'] as $lang) {
2932
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2780 2933
 					unset($context['languages'][$lang['filename']]);
2934
+			}
2781 2935
 		}
2782 2936
 
2783 2937
 		// Let's cash in on this deal.
2784
-		if (!empty($modSettings['cache_enable']))
2785
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
2938
+		if (!empty($modSettings['cache_enable'])) {
2939
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
2940
+		}
2786 2941
 	}
2787 2942
 
2788 2943
 	return $context['languages'];
@@ -2805,8 +2960,9 @@  discard block
 block discarded – undo
2805 2960
 	global $modSettings, $options, $txt;
2806 2961
 	static $censor_vulgar = null, $censor_proper;
2807 2962
 
2808
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2809
-		return $text;
2963
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
2964
+			return $text;
2965
+	}
2810 2966
 
2811 2967
 	// If they haven't yet been loaded, load them.
2812 2968
 	if ($censor_vulgar == null)
@@ -2834,9 +2990,9 @@  discard block
 block discarded – undo
2834 2990
 	{
2835 2991
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2836 2992
 		$text = $func($censor_vulgar, $censor_proper, $text);
2993
+	} else {
2994
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2837 2995
 	}
2838
-	else
2839
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2840 2996
 
2841 2997
 	return $text;
2842 2998
 }
@@ -2862,38 +3018,42 @@  discard block
 block discarded – undo
2862 3018
 	@ini_set('track_errors', '1');
2863 3019
 
2864 3020
 	// Don't include the file more than once, if $once is true.
2865
-	if ($once && in_array($filename, $templates))
2866
-		return;
3021
+	if ($once && in_array($filename, $templates)) {
3022
+			return;
3023
+	}
2867 3024
 	// Add this file to the include list, whether $once is true or not.
2868
-	else
2869
-		$templates[] = $filename;
3025
+	else {
3026
+			$templates[] = $filename;
3027
+	}
2870 3028
 
2871 3029
 	// Are we going to use eval?
2872 3030
 	if (empty($modSettings['disableTemplateEval']))
2873 3031
 	{
2874 3032
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2875 3033
 		$settings['current_include_filename'] = $filename;
2876
-	}
2877
-	else
3034
+	} else
2878 3035
 	{
2879 3036
 		$file_found = file_exists($filename);
2880 3037
 
2881
-		if ($once && $file_found)
2882
-			require_once($filename);
2883
-		elseif ($file_found)
2884
-			require($filename);
3038
+		if ($once && $file_found) {
3039
+					require_once($filename);
3040
+		} elseif ($file_found) {
3041
+					require($filename);
3042
+		}
2885 3043
 	}
2886 3044
 
2887 3045
 	if ($file_found !== true)
2888 3046
 	{
2889 3047
 		ob_end_clean();
2890
-		if (!empty($modSettings['enableCompressedOutput']))
2891
-			@ob_start('ob_gzhandler');
2892
-		else
2893
-			ob_start();
3048
+		if (!empty($modSettings['enableCompressedOutput'])) {
3049
+					@ob_start('ob_gzhandler');
3050
+		} else {
3051
+					ob_start();
3052
+		}
2894 3053
 
2895
-		if (isset($_GET['debug']))
2896
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3054
+		if (isset($_GET['debug'])) {
3055
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3056
+		}
2897 3057
 
2898 3058
 		// Don't cache error pages!!
2899 3059
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -2912,12 +3072,13 @@  discard block
 block discarded – undo
2912 3072
 		echo '<!DOCTYPE html>
2913 3073
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
2914 3074
 	<head>';
2915
-		if (isset($context['character_set']))
2916
-			echo '
3075
+		if (isset($context['character_set'])) {
3076
+					echo '
2917 3077
 		<meta charset="', $context['character_set'], '">';
3078
+		}
2918 3079
 
2919
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
2920
-			echo '
3080
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3081
+					echo '
2921 3082
 		<title>', $mtitle, '</title>
2922 3083
 	</head>
2923 3084
 	<body>
@@ -2925,8 +3086,8 @@  discard block
 block discarded – undo
2925 3086
 		', $mmessage, '
2926 3087
 	</body>
2927 3088
 </html>';
2928
-		elseif (!allowedTo('admin_forum'))
2929
-			echo '
3089
+		} elseif (!allowedTo('admin_forum')) {
3090
+					echo '
2930 3091
 		<title>', $txt['template_parse_error'], '</title>
2931 3092
 	</head>
2932 3093
 	<body>
@@ -2934,15 +3095,17 @@  discard block
 block discarded – undo
2934 3095
 		', $txt['template_parse_error_message'], '
2935 3096
 	</body>
2936 3097
 </html>';
2937
-		else
3098
+		} else
2938 3099
 		{
2939 3100
 			require_once($sourcedir . '/Subs-Package.php');
2940 3101
 
2941 3102
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
2942
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
2943
-				$error = $php_errormsg;
2944
-			if (empty($error))
2945
-				$error = $txt['template_parse_errmsg'];
3103
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3104
+							$error = $php_errormsg;
3105
+			}
3106
+			if (empty($error)) {
3107
+							$error = $txt['template_parse_errmsg'];
3108
+			}
2946 3109
 
2947 3110
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
2948 3111
 
@@ -2953,11 +3116,12 @@  discard block
 block discarded – undo
2953 3116
 		<h3>', $txt['template_parse_error'], '</h3>
2954 3117
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
2955 3118
 
2956
-			if (!empty($error))
2957
-				echo '
3119
+			if (!empty($error)) {
3120
+							echo '
2958 3121
 		<hr>
2959 3122
 
2960 3123
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3124
+			}
2961 3125
 
2962 3126
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
2963 3127
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -2967,10 +3131,11 @@  discard block
 block discarded – undo
2967 3131
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
2968 3132
 
2969 3133
 				// Fix the PHP code stuff...
2970
-				if (!isBrowser('gecko'))
2971
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
2972
-				else
2973
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3134
+				if (!isBrowser('gecko')) {
3135
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3136
+				} else {
3137
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3138
+				}
2974 3139
 
2975 3140
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
2976 3141
 				$j = -1;
@@ -2978,8 +3143,9 @@  discard block
 block discarded – undo
2978 3143
 				{
2979 3144
 					$j++;
2980 3145
 
2981
-					if (substr_count($line, '<br>') == 0)
2982
-						continue;
3146
+					if (substr_count($line, '<br>') == 0) {
3147
+											continue;
3148
+					}
2983 3149
 
2984 3150
 					$n = substr_count($line, '<br>');
2985 3151
 					for ($i = 0; $i < $n; $i++)
@@ -2998,38 +3164,42 @@  discard block
 block discarded – undo
2998 3164
 				// Figure out what the color coding was before...
2999 3165
 				$line = max($match[1] - 9, 1);
3000 3166
 				$last_line = '';
3001
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3002
-					if (strpos($data2[$line2], '<') !== false)
3167
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3168
+									if (strpos($data2[$line2], '<') !== false)
3003 3169
 					{
3004 3170
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3005 3171
 							$last_line = $color_match[1];
3172
+				}
3006 3173
 						break;
3007 3174
 					}
3008 3175
 
3009 3176
 				// Show the relevant lines...
3010 3177
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3011 3178
 				{
3012
-					if ($line == $match[1])
3013
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3179
+					if ($line == $match[1]) {
3180
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3181
+					}
3014 3182
 
3015 3183
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3016
-					if (isset($data2[$line]) && $data2[$line] != '')
3017
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3184
+					if (isset($data2[$line]) && $data2[$line] != '') {
3185
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3186
+					}
3018 3187
 
3019 3188
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3020 3189
 					{
3021 3190
 						$last_line = $color_match[1];
3022 3191
 						echo '</', substr($last_line, 1, 4), '>';
3192
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3193
+											$last_line = '';
3194
+					} elseif ($last_line != '' && $data2[$line] != '') {
3195
+											echo '</', substr($last_line, 1, 4), '>';
3023 3196
 					}
3024
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3025
-						$last_line = '';
3026
-					elseif ($last_line != '' && $data2[$line] != '')
3027
-						echo '</', substr($last_line, 1, 4), '>';
3028 3197
 
3029
-					if ($line == $match[1])
3030
-						echo '</pre></div><pre style="margin: 0;">';
3031
-					else
3032
-						echo "\n";
3198
+					if ($line == $match[1]) {
3199
+											echo '</pre></div><pre style="margin: 0;">';
3200
+					} else {
3201
+											echo "\n";
3202
+					}
3033 3203
 				}
3034 3204
 
3035 3205
 				echo '</pre></div>';
@@ -3053,8 +3223,9 @@  discard block
 block discarded – undo
3053 3223
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3054 3224
 
3055 3225
 	// Figure out what type of database we are using.
3056
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3057
-		$db_type = 'mysql';
3226
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3227
+			$db_type = 'mysql';
3228
+	}
3058 3229
 
3059 3230
 	// Load the file for the database.
3060 3231
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3062,8 +3233,9 @@  discard block
 block discarded – undo
3062 3233
 	$db_options = array();
3063 3234
 
3064 3235
 	// Add in the port if needed
3065
-	if (!empty($db_port))
3066
-		$db_options['port'] = $db_port;
3236
+	if (!empty($db_port)) {
3237
+			$db_options['port'] = $db_port;
3238
+	}
3067 3239
 
3068 3240
 	// 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.
3069 3241
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3082,13 +3254,15 @@  discard block
 block discarded – undo
3082 3254
 	}
3083 3255
 
3084 3256
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3085
-	if (!$db_connection)
3086
-		display_db_error();
3257
+	if (!$db_connection) {
3258
+			display_db_error();
3259
+	}
3087 3260
 
3088 3261
 	// If in SSI mode fix up the prefix.
3089
-	if (SMF == 'SSI')
3090
-		db_fix_prefix($db_prefix, $db_name);
3091
-}
3262
+	if (SMF == 'SSI') {
3263
+			db_fix_prefix($db_prefix, $db_name);
3264
+	}
3265
+	}
3092 3266
 
3093 3267
 /**
3094 3268
  * Try to retrieve a cache entry. On failure, call the appropriate function.
@@ -3106,8 +3280,9 @@  discard block
 block discarded – undo
3106 3280
 
3107 3281
 	// @todo Why are we doing this if caching is disabled?
3108 3282
 
3109
-	if (function_exists('call_integration_hook'))
3110
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3283
+	if (function_exists('call_integration_hook')) {
3284
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3285
+	}
3111 3286
 
3112 3287
 	/* Refresh the cache if either:
3113 3288
 		1. Caching is disabled.
@@ -3121,16 +3296,19 @@  discard block
 block discarded – undo
3121 3296
 		require_once($sourcedir . '/' . $file);
3122 3297
 		$cache_block = call_user_func_array($function, $params);
3123 3298
 
3124
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3125
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3299
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3300
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3301
+		}
3126 3302
 	}
3127 3303
 
3128 3304
 	// Some cached data may need a freshening up after retrieval.
3129
-	if (!empty($cache_block['post_retri_eval']))
3130
-		eval($cache_block['post_retri_eval']);
3305
+	if (!empty($cache_block['post_retri_eval'])) {
3306
+			eval($cache_block['post_retri_eval']);
3307
+	}
3131 3308
 
3132
-	if (function_exists('call_integration_hook'))
3133
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3309
+	if (function_exists('call_integration_hook')) {
3310
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3311
+	}
3134 3312
 
3135 3313
 	return $cache_block['data'];
3136 3314
 }
@@ -3157,8 +3335,9 @@  discard block
 block discarded – undo
3157 3335
 	global $cache_hits, $cache_count, $db_show_debug, $cachedir;
3158 3336
 	global $cache_accelerator, $cache_enable;
3159 3337
 
3160
-	if (empty($cache_enable))
3161
-		return;
3338
+	if (empty($cache_enable)) {
3339
+			return;
3340
+	}
3162 3341
 
3163 3342
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3164 3343
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3177,10 +3356,12 @@  discard block
 block discarded – undo
3177 3356
 			if (function_exists('memcached_set') || function_exists('memcache_set') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
3178 3357
 			{
3179 3358
 				// Not connected yet?
3180
-				if (empty($memcached))
3181
-					get_memcached_server();
3182
-				if (!$memcached)
3183
-					return;
3359
+				if (empty($memcached)) {
3360
+									get_memcached_server();
3361
+				}
3362
+				if (!$memcached) {
3363
+									return;
3364
+				}
3184 3365
 
3185 3366
 				memcache_set($memcached, $key, $value, 0, $ttl);
3186 3367
 			}
@@ -3190,57 +3371,65 @@  discard block
 block discarded – undo
3190 3371
 			if (function_exists('apc_store'))
3191 3372
 			{
3192 3373
 				// An extended key is needed to counteract a bug in APC.
3193
-				if ($value === null)
3194
-					apc_delete($key . 'smf');
3195
-				else
3196
-					apc_store($key . 'smf', $value, $ttl);
3374
+				if ($value === null) {
3375
+									apc_delete($key . 'smf');
3376
+				} else {
3377
+									apc_store($key . 'smf', $value, $ttl);
3378
+				}
3197 3379
 			}
3198 3380
 			break;
3199 3381
 		case 'zend':
3200 3382
 			// Zend Platform/ZPS/etc.
3201
-			if (function_exists('zend_shm_cache_store'))
3202
-				zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3203
-			elseif (function_exists('output_cache_put'))
3204
-				output_cache_put($key, $value);
3383
+			if (function_exists('zend_shm_cache_store')) {
3384
+							zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3385
+			} elseif (function_exists('output_cache_put')) {
3386
+							output_cache_put($key, $value);
3387
+			}
3205 3388
 			break;
3206 3389
 		case 'xcache':
3207 3390
 			if (function_exists('xcache_set') && ini_get('xcache.var_size') > 0)
3208 3391
 			{
3209
-				if ($value === null)
3210
-					xcache_unset($key);
3211
-				else
3212
-					xcache_set($key, $value, $ttl);
3392
+				if ($value === null) {
3393
+									xcache_unset($key);
3394
+				} else {
3395
+									xcache_set($key, $value, $ttl);
3396
+				}
3213 3397
 			}
3214 3398
 			break;
3215 3399
 		default:
3216 3400
 			// Otherwise custom cache?
3217
-			if ($value === null)
3218
-				@unlink($cachedir . '/data_' . $key . '.php');
3219
-			else
3401
+			if ($value === null) {
3402
+							@unlink($cachedir . '/data_' . $key . '.php');
3403
+			} else
3220 3404
 			{
3221 3405
 				$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
3222 3406
 
3223 3407
 				// Write out the cache file, check that the cache write was successful; all the data must be written
3224 3408
 				// If it fails due to low diskspace, or other, remove the cache file
3225
-				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
3226
-					@unlink($cachedir . '/data_' . $key . '.php');
3409
+				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data)) {
3410
+									@unlink($cachedir . '/data_' . $key . '.php');
3411
+				}
3227 3412
 			}
3228 3413
 			break;
3229 3414
 	}
3230 3415
 
3231
-	if (function_exists('call_integration_hook'))
3232
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3416
+	if (function_exists('call_integration_hook')) {
3417
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3418
+	}
3233 3419
 
3234
-	if (isset($db_show_debug) && $db_show_debug === true)
3235
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3420
+	if (isset($db_show_debug) && $db_show_debug === true) {
3421
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3422
+	}
3236 3423
 
3237 3424
 	// Invalidate the opcode cache
3238
-	if (function_exists('opcache_invalidate'))
3239
-   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3425
+	if (function_exists('opcache_invalidate')) {
3426
+	   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3427
+	}
3240 3428
 
3241
-	if (function_exists('apc_delete_file'))
3242
-   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3243
-}
3429
+	if (function_exists('apc_delete_file')) {
3430
+	   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3431
+	}
3432
+	}
3244 3433
 
3245 3434
 /**
3246 3435
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3257,8 +3446,9 @@  discard block
 block discarded – undo
3257 3446
 	global $cache_hits, $cache_count, $db_show_debug, $cachedir;
3258 3447
 	global $cache_accelerator, $cache_enable;
3259 3448
 
3260
-	if (empty($cache_enable))
3261
-		return;
3449
+	if (empty($cache_enable)) {
3450
+			return;
3451
+	}
3262 3452
 
3263 3453
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3264 3454
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3276,29 +3466,34 @@  discard block
 block discarded – undo
3276 3466
 			if ((function_exists('memcache_get') || function_exists('memcached_get')) && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
3277 3467
 			{
3278 3468
 				// Not connected yet?
3279
-				if (empty($memcached))
3280
-					get_memcached_server();
3281
-				if (!$memcached)
3282
-					return null;
3469
+				if (empty($memcached)) {
3470
+									get_memcached_server();
3471
+				}
3472
+				if (!$memcached) {
3473
+									return null;
3474
+				}
3283 3475
 
3284 3476
 				$value = (function_exists('memcache_get')) ? memcache_get($cache['connection'], $key) : memcached_get($cache['connection'], $key);
3285 3477
 			}
3286 3478
 			break;
3287 3479
 		case 'apc':
3288 3480
 			// This is the free APC from PECL.
3289
-			if (function_exists('apc_fetch'))
3290
-				$value = apc_fetch($key . 'smf');
3481
+			if (function_exists('apc_fetch')) {
3482
+							$value = apc_fetch($key . 'smf');
3483
+			}
3291 3484
 			break;
3292 3485
 		case 'zend':
3293 3486
 			// Zend's pricey stuff.
3294
-			if (function_exists('zend_shm_cache_fetch'))
3295
-				$value = zend_shm_cache_fetch('SMF::' . $key);
3296
-			elseif (function_exists('output_cache_get'))
3297
-				$value = output_cache_get($key, $ttl);
3487
+			if (function_exists('zend_shm_cache_fetch')) {
3488
+							$value = zend_shm_cache_fetch('SMF::' . $key);
3489
+			} elseif (function_exists('output_cache_get')) {
3490
+							$value = output_cache_get($key, $ttl);
3491
+			}
3298 3492
 			break;
3299 3493
 		case 'xcache':
3300
-			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0)
3301
-				$value = xcache_get($key);
3494
+			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) {
3495
+							$value = xcache_get($key);
3496
+			}
3302 3497
 			break;
3303 3498
 		default:
3304 3499
 			// Otherwise it's SMF data!
@@ -3306,8 +3501,9 @@  discard block
 block discarded – undo
3306 3501
 			{
3307 3502
 				// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
3308 3503
 				// causing newer files to take effect a while later.
3309
-				if (function_exists('opcache_invalidate'))
3310
-					opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3504
+				if (function_exists('opcache_invalidate')) {
3505
+									opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3506
+				}
3311 3507
 
3312 3508
 				// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
3313 3509
 				@include($cachedir . '/data_' . $key . '.php');
@@ -3326,8 +3522,9 @@  discard block
 block discarded – undo
3326 3522
 		$cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0;
3327 3523
 	}
3328 3524
 
3329
-	if (function_exists('call_integration_hook') && isset($value))
3330
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3525
+	if (function_exists('call_integration_hook') && isset($value)) {
3526
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3527
+	}
3331 3528
 
3332 3529
 	return empty($value) ? null : @json_decode($value, true);
3333 3530
 }
@@ -3351,9 +3548,9 @@  discard block
 block discarded – undo
3351 3548
 	$port = 0;
3352 3549
 
3353 3550
 	// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
3354
-	if(strpos($server,'/') !== false)
3355
-		$host = $server;
3356
-	else
3551
+	if(strpos($server,'/') !== false) {
3552
+			$host = $server;
3553
+	} else
3357 3554
 	{
3358 3555
 		$server = explode(':', $server);
3359 3556
 		$host = $server[0];
@@ -3368,22 +3565,26 @@  discard block
 block discarded – undo
3368 3565
 	// Don't wait too long: yes, we want the server, but we might be able to run the query faster!
3369 3566
 	if (empty($db_persist))
3370 3567
 	{
3371
-		if ($cache === 'memcached')
3372
-			$memcached = memcached_connect($host, $port);
3373
-		if ($cache === 'memcache')
3374
-			$memcached = memcache_connect($host, $port);
3375
-	}
3376
-	else
3568
+		if ($cache === 'memcached') {
3569
+					$memcached = memcached_connect($host, $port);
3570
+		}
3571
+		if ($cache === 'memcache') {
3572
+					$memcached = memcache_connect($host, $port);
3573
+		}
3574
+	} else
3377 3575
 	{
3378
-		if ($cache === 'memcached')
3379
-			$memcached = memcached_pconnect($host, $port);
3380
-		if ($cache === 'memcache')
3381
-			$memcached = memcache_pconnect($host, $port);
3576
+		if ($cache === 'memcached') {
3577
+					$memcached = memcached_pconnect($host, $port);
3578
+		}
3579
+		if ($cache === 'memcache') {
3580
+					$memcached = memcache_pconnect($host, $port);
3581
+		}
3382 3582
 	}
3383 3583
 
3384
-	if (!$memcached && $level > 0)
3385
-		get_memcached_server($level - 1);
3386
-}
3584
+	if (!$memcached && $level > 0) {
3585
+			get_memcached_server($level - 1);
3586
+	}
3587
+	}
3387 3588
 
3388 3589
 /**
3389 3590
  * Helper function to set an array of data for an user's avatar.
@@ -3401,8 +3602,9 @@  discard block
 block discarded – undo
3401 3602
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3402 3603
 
3403 3604
 	// Come on!
3404
-	if (empty($data))
3405
-		return array();
3605
+	if (empty($data)) {
3606
+			return array();
3607
+	}
3406 3608
 
3407 3609
 	// Set a nice default var.
3408 3610
 	$image = '';
@@ -3410,11 +3612,11 @@  discard block
 block discarded – undo
3410 3612
 	// Gravatar has been set as mandatory!
3411 3613
 	if (!empty($modSettings['gravatarOverride']))
3412 3614
 	{
3413
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3414
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3415
-
3416
-		else if (!empty($data['email']))
3417
-			$image = get_gravatar_url($data['email']);
3615
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3616
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3617
+		} else if (!empty($data['email'])) {
3618
+					$image = get_gravatar_url($data['email']);
3619
+		}
3418 3620
 	}
3419 3621
 
3420 3622
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3426,54 +3628,60 @@  discard block
 block discarded – undo
3426 3628
 			// Gravatar.
3427 3629
 			if (stristr($data['avatar'], 'gravatar://'))
3428 3630
 			{
3429
-				if ($data['avatar'] == 'gravatar://')
3430
-					$image = get_gravatar_url($data['email']);
3431
-
3432
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3433
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3631
+				if ($data['avatar'] == 'gravatar://') {
3632
+									$image = get_gravatar_url($data['email']);
3633
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3634
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3635
+				}
3434 3636
 			}
3435 3637
 
3436 3638
 			// External url.
3437 3639
 			else
3438 3640
 			{
3439 3641
 				// Using ssl?
3440
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3441
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3642
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3643
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3644
+				}
3442 3645
 
3443 3646
 				// Just a plain external url.
3444
-				else
3445
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3647
+				else {
3648
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3649
+				}
3446 3650
 			}
3447 3651
 		}
3448 3652
 
3449 3653
 		// Perhaps this user has an attachment as avatar...
3450
-		else if (!empty($data['filename']))
3451
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3654
+		else if (!empty($data['filename'])) {
3655
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3656
+		}
3452 3657
 
3453 3658
 		// Right... no avatar... use our default image.
3454
-		else
3455
-			$image = $modSettings['avatar_url'] . '/default.png';
3659
+		else {
3660
+					$image = $modSettings['avatar_url'] . '/default.png';
3661
+		}
3456 3662
 	}
3457 3663
 
3458 3664
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3459 3665
 
3460 3666
 	// 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.
3461
-	if (!empty($image))
3462
-		return array(
3667
+	if (!empty($image)) {
3668
+			return array(
3463 3669
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3464 3670
 			'image' => '<img class="avatar" src="' . $image . '" />',
3465 3671
 			'href' => $image,
3466 3672
 			'url' => $image,
3467 3673
 		);
3674
+	}
3468 3675
 
3469 3676
 	// Fallback to make life easier for everyone...
3470
-	else
3471
-		return array(
3677
+	else {
3678
+			return array(
3472 3679
 			'name' => '',
3473 3680
 			'image' => '',
3474 3681
 			'href' => '',
3475 3682
 			'url' => '',
3476 3683
 		);
3477
-}
3684
+	}
3685
+	}
3478 3686
 
3479 3687
 ?>
Please login to merge, or discard this patch.
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -694,7 +694,6 @@
 block discarded – undo
694 694
  * It shows as the maintain_forum admin area.
695 695
  * It is accessed from ?action=admin;area=maintain;sa=database;activity=optimize.
696 696
  * It also updates the optimize scheduled task such that the tables are not automatically optimized again too soon.
697
-
698 697
  * @uses the optimize sub template
699 698
  */
700 699
 function OptimizeTables()
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
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
  * Doesn't clean the inputs
926 926
  *
927 927
  * @param array $items_ids The items to remove
928
- * @param bool|int $group_id The ID of the group these triggers are associated with or false if deleting them from all groups
928
+ * @param integer $group_id The ID of the group these triggers are associated with or false if deleting them from all groups
929 929
  * @return bool Always returns true
930 930
  */
931 931
 function removeBanTriggers($items_ids = array(), $group_id = false)
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
  * Errors in $context['ban_errors']
1120 1120
  *
1121 1121
  * @param array $triggers The triggers to validate
1122
- * @return array An array of riggers and log info ready to be used
1122
+ * @return integer An array of riggers and log info ready to be used
1123 1123
  */
1124 1124
 function validateTriggers(&$triggers)
1125 1125
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2157,9 +2157,9 @@
 block discarded – undo
2157 2157
 
2158 2158
 	if ($low == '255.255.255.255') return 'unkown';
2159 2159
 	if ($low == $high)
2160
-	    return $low;
2160
+		return $low;
2161 2161
 	else
2162
-	    return $low . '-'.$high;
2162
+		return $low . '-'.$high;
2163 2163
 }
2164 2164
 
2165 2165
 /**
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 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
 							},
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 			}
552 552
 
553 553
 			// We come from the mod center.
554
-			elseif(isset($_GET['msg']) && !empty($_GET['msg']))
554
+			elseif (isset($_GET['msg']) && !empty($_GET['msg']))
555 555
 			{
556 556
 				$request = $smcFunc['db_query']('', '
557 557
 					SELECT poster_name, poster_ip, poster_email
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
 	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1425 1425
 		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1426 1426
 
1427
-	if(!empty($ban_info['id']))
1427
+	if (!empty($ban_info['id']))
1428 1428
 	{
1429 1429
 		// Verify the ban group exists.
1430 1430
 		$request = $smcFunc['db_query']('', '
@@ -1442,7 +1442,7 @@  discard block
 block discarded – undo
1442 1442
 		$smcFunc['db_free_result']($request);
1443 1443
 	}
1444 1444
 
1445
-	if(!empty($ban_info['name']))
1445
+	if (!empty($ban_info['name']))
1446 1446
 	{
1447 1447
 		// Make sure the name does not already exist (Of course, if it exists in the ban group we are editing, proceed.)
1448 1448
 		$request = $smcFunc['db_query']('', '
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
 	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1511 1511
 		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1512 1512
 
1513
-	if(!empty($ban_info['name']))
1513
+	if (!empty($ban_info['name']))
1514 1514
 	{
1515 1515
 		// Check whether a ban with this name already exists.
1516 1516
 		$request = $smcFunc['db_query']('', '
@@ -1789,7 +1789,7 @@  discard block
 block discarded – undo
1789 1789
 	if ($context['selected_entity'] === 'ip')
1790 1790
 	{
1791 1791
 		$listOptions['columns']['banned_entity']['data'] = array(
1792
-			'function' => function ($rowData)
1792
+			'function' => function($rowData)
1793 1793
 			{
1794 1794
 				return range2ip(
1795 1795
 					$rowData['ip_low']
@@ -1806,7 +1806,7 @@  discard block
 block discarded – undo
1806 1806
 	elseif ($context['selected_entity'] === 'hostname')
1807 1807
 	{
1808 1808
 		$listOptions['columns']['banned_entity']['data'] = array(
1809
-			'function' => function ($rowData) use ($smcFunc)
1809
+			'function' => function($rowData) use ($smcFunc)
1810 1810
 			{
1811 1811
 				return strtr($smcFunc['htmlspecialchars']($rowData['hostname']), array('%' => '*'));
1812 1812
 			},
@@ -1819,7 +1819,7 @@  discard block
 block discarded – undo
1819 1819
 	elseif ($context['selected_entity'] === 'email')
1820 1820
 	{
1821 1821
 		$listOptions['columns']['banned_entity']['data'] = array(
1822
-			'function' => function ($rowData) use ($smcFunc)
1822
+			'function' => function($rowData) use ($smcFunc)
1823 1823
 			{
1824 1824
 				return strtr($smcFunc['htmlspecialchars']($rowData['email_address']), array('%' => '*'));
1825 1825
 			},
@@ -2026,7 +2026,7 @@  discard block
 block discarded – undo
2026 2026
 					'value' => $txt['ban_log_date'],
2027 2027
 				),
2028 2028
 				'data' => array(
2029
-					'function' => function ($rowData)
2029
+					'function' => function($rowData)
2030 2030
 					{
2031 2031
 						return timeformat($rowData['log_time']);
2032 2032
 					},
@@ -2159,7 +2159,7 @@  discard block
 block discarded – undo
2159 2159
 	if ($low == $high)
2160 2160
 	    return $low;
2161 2161
 	else
2162
-	    return $low . '-'.$high;
2162
+	    return $low . '-' . $high;
2163 2163
 }
2164 2164
 
2165 2165
 /**
@@ -2275,7 +2275,7 @@  discard block
 block discarded – undo
2275 2275
 		$request = $smcFunc['db_query']('', '
2276 2276
 			SELECT mem.id_member, mem.is_activated
2277 2277
 			FROM {db_prefix}members AS mem
2278
-			WHERE ' . implode( ' OR ', $queryPart),
2278
+			WHERE ' . implode(' OR ', $queryPart),
2279 2279
 			$queryValues
2280 2280
 		);
2281 2281
 		while ($row = $smcFunc['db_fetch_assoc']($request))
Please login to merge, or discard this patch.
Braces   +270 added lines, -215 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
 						),
@@ -528,8 +536,9 @@  discard block
 block discarded – undo
528 536
 						'current_user' => (int) $_REQUEST['u'],
529 537
 					)
530 538
 				);
531
-				if ($smcFunc['db_num_rows']($request) > 0)
532
-					list ($context['ban_suggestions']['member']['id'], $context['ban_suggestions']['member']['name'], $context['ban_suggestions']['main_ip'], $context['ban_suggestions']['email']) = $smcFunc['db_fetch_row']($request);
539
+				if ($smcFunc['db_num_rows']($request) > 0) {
540
+									list ($context['ban_suggestions']['member']['id'], $context['ban_suggestions']['member']['name'], $context['ban_suggestions']['main_ip'], $context['ban_suggestions']['email']) = $smcFunc['db_fetch_row']($request);
541
+				}
533 542
 				$smcFunc['db_free_result']($request);
534 543
 
535 544
 				if (!empty($context['ban_suggestions']['member']['id']))
@@ -543,8 +552,9 @@  discard block
 block discarded – undo
543 552
 					$context['ban']['from_user'] = true;
544 553
 
545 554
 					// Would be nice if we could also ban the hostname.
546
-					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']))
547
-						$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
555
+					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'])) {
556
+											$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
557
+					}
548 558
 
549 559
 					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
550 560
 				}
@@ -562,8 +572,9 @@  discard block
 block discarded – undo
562 572
 						'message' => (int) $_REQUEST['msg'],
563 573
 					)
564 574
 				);
565
-				if ($smcFunc['db_num_rows']($request) > 0)
566
-					list ($context['ban_suggestions']['member']['name'], $context['ban_suggestions']['main_ip'], $context['ban_suggestions']['email']) = $smcFunc['db_fetch_row']($request);
575
+				if ($smcFunc['db_num_rows']($request) > 0) {
576
+									list ($context['ban_suggestions']['member']['name'], $context['ban_suggestions']['main_ip'], $context['ban_suggestions']['email']) = $smcFunc['db_fetch_row']($request);
577
+				}
567 578
 				$smcFunc['db_free_result']($request);
568 579
 
569 580
 				// Can't hurt to ban base on the guest name...
@@ -609,8 +620,9 @@  discard block
 block discarded – undo
609 620
 			'items_per_page' => $items_per_page,
610 621
 		)
611 622
 	);
612
-	if ($smcFunc['db_num_rows']($request) == 0)
613
-		fatal_lang_error('ban_not_found', false);
623
+	if ($smcFunc['db_num_rows']($request) == 0) {
624
+			fatal_lang_error('ban_not_found', false);
625
+	}
614 626
 
615 627
 	while ($row = $smcFunc['db_fetch_assoc']($request))
616 628
 	{
@@ -647,18 +659,15 @@  discard block
 block discarded – undo
647 659
 			{
648 660
 				$ban_items[$row['id_ban']]['type'] = 'ip';
649 661
 				$ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);
650
-			}
651
-			elseif (!empty($row['hostname']))
662
+			} elseif (!empty($row['hostname']))
652 663
 			{
653 664
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
654 665
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
655
-			}
656
-			elseif (!empty($row['email_address']))
666
+			} elseif (!empty($row['email_address']))
657 667
 			{
658 668
 				$ban_items[$row['id_ban']]['type'] = 'email';
659 669
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
660
-			}
661
-			elseif (!empty($row['id_member']))
670
+			} elseif (!empty($row['id_member']))
662 671
 			{
663 672
 				$ban_items[$row['id_ban']]['type'] = 'user';
664 673
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -724,9 +733,10 @@  discard block
 block discarded – undo
724 733
 	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError');
725 734
 
726 735
 	$return = array();
727
-	foreach ($search_list as $key => $callable)
728
-		if (is_callable($callable))
736
+	foreach ($search_list as $key => $callable) {
737
+			if (is_callable($callable))
729 738
 			$return[$key] = call_user_func($callable, $member_id);
739
+	}
730 740
 
731 741
 	return $return;
732 742
 }
@@ -752,8 +762,9 @@  discard block
 block discarded – undo
752 762
 			'poster_ip_regex' => '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$',
753 763
 		)
754 764
 	);
755
-	while ($row = $smcFunc['db_fetch_assoc']($request))
756
-		$message_ips[] = $row['poster_ip'];
765
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
766
+			$message_ips[] = $row['poster_ip'];
767
+	}
757 768
 	$smcFunc['db_free_result']($request);
758 769
 
759 770
 	return $message_ips;
@@ -779,8 +790,9 @@  discard block
 block discarded – undo
779 790
 			'poster_ip_regex' => '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$',
780 791
 		)
781 792
 	);
782
-	while ($row = $smcFunc['db_fetch_assoc']($request))
783
-		$error_ips[] = $row['ip'];
793
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
794
+			$error_ips[] = $row['ip'];
795
+	}
784 796
 	$smcFunc['db_free_result']($request);
785 797
 
786 798
 	return $error_ips;
@@ -821,11 +833,13 @@  discard block
 block discarded – undo
821 833
 		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
822 834
 
823 835
 		// Adding a new ban group
824
-		if (empty($_REQUEST['bg']))
825
-			$ban_group_id = insertBanGroup($ban_info);
836
+		if (empty($_REQUEST['bg'])) {
837
+					$ban_group_id = insertBanGroup($ban_info);
838
+		}
826 839
 		// Editing an existing ban group
827
-		else
828
-			$ban_group_id = updateBanGroup($ban_info);
840
+		else {
841
+					$ban_group_id = updateBanGroup($ban_info);
842
+		}
829 843
 
830 844
 		if (is_numeric($ban_group_id))
831 845
 		{
@@ -836,9 +850,10 @@  discard block
 block discarded – undo
836 850
 		$context['ban'] = $ban_info;
837 851
 	}
838 852
 
839
-	if (isset($_POST['ban_suggestions']))
840
-		// @TODO: is $_REQUEST['bi'] ever set?
853
+	if (isset($_POST['ban_suggestions'])) {
854
+			// @TODO: is $_REQUEST['bi'] ever set?
841 855
 		$saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
856
+	}
842 857
 
843 858
 	// Something went wrong somewhere... Oh well, let's go back.
844 859
 	if (!empty($context['ban_errors']))
@@ -848,8 +863,9 @@  discard block
 block discarded – undo
848 863
 		$context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
849 864
 
850 865
 		// Not strictly necessary, but it's nice
851
-		if (!empty($context['ban_suggestions']['member']['id']))
852
-			$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
866
+		if (!empty($context['ban_suggestions']['member']['id'])) {
867
+					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
868
+		}
853 869
 		return BanEdit();
854 870
 	}
855 871
 	$context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();
@@ -898,10 +914,11 @@  discard block
 block discarded – undo
898 914
 
899 915
 	foreach ($suggestions as $key => $value)
900 916
 	{
901
-		if (is_array($value))
902
-			$triggers[$key] = $value;
903
-		else
904
-			$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
917
+		if (is_array($value)) {
918
+					$triggers[$key] = $value;
919
+		} else {
920
+					$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
921
+		}
905 922
 	}
906 923
 
907 924
 	$ban_triggers = validateTriggers($triggers);
@@ -909,16 +926,18 @@  discard block
 block discarded – undo
909 926
 	// Time to save!
910 927
 	if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))
911 928
 	{
912
-		if (empty($ban_id))
913
-			addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
914
-		else
915
-			updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
929
+		if (empty($ban_id)) {
930
+					addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
931
+		} else {
932
+					updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
933
+		}
934
+	}
935
+	if (!empty($context['ban_errors'])) {
936
+			return $triggers;
937
+	} else {
938
+			return false;
939
+	}
916 940
 	}
917
-	if (!empty($context['ban_errors']))
918
-		return $triggers;
919
-	else
920
-		return false;
921
-}
922 941
 
923 942
 /**
924 943
  * This function removes a bunch of triggers based on ids
@@ -932,14 +951,17 @@  discard block
 block discarded – undo
932 951
 {
933 952
 	global $smcFunc, $scripturl;
934 953
 
935
-	if ($group_id !== false)
936
-		$group_id = (int) $group_id;
954
+	if ($group_id !== false) {
955
+			$group_id = (int) $group_id;
956
+	}
937 957
 
938
-	if (empty($group_id) && empty($items_ids))
939
-		return false;
958
+	if (empty($group_id) && empty($items_ids)) {
959
+			return false;
960
+	}
940 961
 
941
-	if (!is_array($items_ids))
942
-		$items_ids = array($items_ids);
962
+	if (!is_array($items_ids)) {
963
+			$items_ids = array($items_ids);
964
+	}
943 965
 
944 966
 	$log_info = array();
945 967
 	$ban_items = array();
@@ -977,8 +999,7 @@  discard block
 block discarded – undo
977 999
 					'bantype' => ($is_range ? 'ip_range' : 'main_ip'),
978 1000
 					'value' => $ban_items[$row['id_ban']]['ip'],
979 1001
 				);
980
-			}
981
-			elseif (!empty($row['hostname']))
1002
+			} elseif (!empty($row['hostname']))
982 1003
 			{
983 1004
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
984 1005
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
@@ -986,8 +1007,7 @@  discard block
 block discarded – undo
986 1007
 					'bantype' => 'hostname',
987 1008
 					'value' => $row['hostname'],
988 1009
 				);
989
-			}
990
-			elseif (!empty($row['email_address']))
1010
+			} elseif (!empty($row['email_address']))
991 1011
 			{
992 1012
 				$ban_items[$row['id_ban']]['type'] = 'email';
993 1013
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
@@ -995,8 +1015,7 @@  discard block
 block discarded – undo
995 1015
 					'bantype' => 'email',
996 1016
 					'value' => $ban_items[$row['id_ban']]['email'],
997 1017
 				);
998
-			}
999
-			elseif (!empty($row['id_member']))
1018
+			} elseif (!empty($row['id_member']))
1000 1019
 			{
1001 1020
 				$ban_items[$row['id_ban']]['type'] = 'user';
1002 1021
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -1029,8 +1048,7 @@  discard block
 block discarded – undo
1029 1048
 				'ban_group' => $group_id,
1030 1049
 			)
1031 1050
 		);
1032
-	}
1033
-	elseif (!empty($items_ids))
1051
+	} elseif (!empty($items_ids))
1034 1052
 	{
1035 1053
 		$smcFunc['db_query']('', '
1036 1054
 			DELETE FROM {db_prefix}ban_items
@@ -1055,13 +1073,15 @@  discard block
 block discarded – undo
1055 1073
 {
1056 1074
 	global $smcFunc;
1057 1075
 
1058
-	if (!is_array($group_ids))
1059
-		$group_ids = array($group_ids);
1076
+	if (!is_array($group_ids)) {
1077
+			$group_ids = array($group_ids);
1078
+	}
1060 1079
 
1061 1080
 	$group_ids = array_unique($group_ids);
1062 1081
 
1063
-	if (empty($group_ids))
1064
-		return false;
1082
+	if (empty($group_ids)) {
1083
+			return false;
1084
+	}
1065 1085
 
1066 1086
 	$smcFunc['db_query']('', '
1067 1087
 		DELETE FROM {db_prefix}ban_groups
@@ -1085,21 +1105,23 @@  discard block
 block discarded – undo
1085 1105
 {
1086 1106
 	global $smcFunc;
1087 1107
 
1088
-	if (empty($ids))
1089
-		$smcFunc['db_query']('truncate_table', '
1108
+	if (empty($ids)) {
1109
+			$smcFunc['db_query']('truncate_table', '
1090 1110
 			TRUNCATE {db_prefix}log_banned',
1091 1111
 			array(
1092 1112
 			)
1093 1113
 		);
1094
-	else
1114
+	} else
1095 1115
 	{
1096
-		if (!is_array($ids))
1097
-			$ids = array($ids);
1116
+		if (!is_array($ids)) {
1117
+					$ids = array($ids);
1118
+		}
1098 1119
 
1099 1120
 		$ids = array_unique($ids);
1100 1121
 
1101
-		if (empty($ids))
1102
-			return false;
1122
+		if (empty($ids)) {
1123
+					return false;
1124
+		}
1103 1125
 
1104 1126
 		$smcFunc['db_query']('', '
1105 1127
 			DELETE FROM {db_prefix}log_banned
@@ -1125,8 +1147,9 @@  discard block
 block discarded – undo
1125 1147
 {
1126 1148
 	global $context, $smcFunc;
1127 1149
 
1128
-	if (empty($triggers))
1129
-		$context['ban_erros'][] = 'ban_empty_triggers';
1150
+	if (empty($triggers)) {
1151
+			$context['ban_erros'][] = 'ban_empty_triggers';
1152
+	}
1130 1153
 
1131 1154
 	$ban_triggers = array();
1132 1155
 	$log_info = array();
@@ -1135,39 +1158,39 @@  discard block
 block discarded – undo
1135 1158
 	{
1136 1159
 		if (!empty($value))
1137 1160
 		{
1138
-			if ($key == 'member')
1139
-				continue;
1161
+			if ($key == 'member') {
1162
+							continue;
1163
+			}
1140 1164
 
1141 1165
 			if ($key == 'main_ip')
1142 1166
 			{
1143 1167
 				$value = trim($value);
1144 1168
 				$ip_parts = ip2range($value);
1145
-				if (!checkExistingTriggerIP($ip_parts, $value))
1146
-					$context['ban_erros'][] = 'invalid_ip';
1147
-				else
1169
+				if (!checkExistingTriggerIP($ip_parts, $value)) {
1170
+									$context['ban_erros'][] = 'invalid_ip';
1171
+				} else
1148 1172
 				{
1149 1173
 					$ban_triggers['main_ip'] = array(
1150 1174
 						'ip_low' => $ip_parts['low'],
1151 1175
 						'ip_high' => $ip_parts['high']
1152 1176
 					);
1153 1177
 				}
1154
-			}
1155
-			elseif ($key == 'hostname')
1178
+			} elseif ($key == 'hostname')
1156 1179
 			{
1157
-				if (preg_match('/[^\w.\-*]/', $value) == 1)
1158
-					$context['ban_erros'][] = 'invalid_hostname';
1159
-				else
1180
+				if (preg_match('/[^\w.\-*]/', $value) == 1) {
1181
+									$context['ban_erros'][] = 'invalid_hostname';
1182
+				} else
1160 1183
 				{
1161 1184
 					// Replace the * wildcard by a MySQL wildcard %.
1162 1185
 					$value = substr(str_replace('*', '%', $value), 0, 255);
1163 1186
 
1164 1187
 					$ban_triggers['hostname']['hostname'] = $value;
1165 1188
 				}
1166
-			}
1167
-			elseif ($key == 'email')
1189
+			} elseif ($key == 'email')
1168 1190
 			{
1169
-				if (preg_match('/[^\w.\-\+*@]/', $value) == 1)
1170
-					$context['ban_erros'][] = 'invalid_email';
1191
+				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) {
1192
+									$context['ban_erros'][] = 'invalid_email';
1193
+				}
1171 1194
 
1172 1195
 				// Check the user is not banning an admin.
1173 1196
 				$request = $smcFunc['db_query']('', '
@@ -1181,15 +1204,15 @@  discard block
 block discarded – undo
1181 1204
 						'email' => $value,
1182 1205
 					)
1183 1206
 				);
1184
-				if ($smcFunc['db_num_rows']($request) != 0)
1185
-					$context['ban_erros'][] = 'no_ban_admin';
1207
+				if ($smcFunc['db_num_rows']($request) != 0) {
1208
+									$context['ban_erros'][] = 'no_ban_admin';
1209
+				}
1186 1210
 				$smcFunc['db_free_result']($request);
1187 1211
 
1188 1212
 				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255);
1189 1213
 
1190 1214
 				$ban_triggers['email']['email_address'] = $value;
1191
-			}
1192
-			elseif ($key == 'user')
1215
+			} elseif ($key == 'user')
1193 1216
 			{
1194 1217
 				$user = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES));
1195 1218
 
@@ -1203,8 +1226,9 @@  discard block
 block discarded – undo
1203 1226
 						'username' => $user,
1204 1227
 					)
1205 1228
 				);
1206
-				if ($smcFunc['db_num_rows']($request) == 0)
1207
-					$context['ban_erros'][] = 'invalid_username';
1229
+				if ($smcFunc['db_num_rows']($request) == 0) {
1230
+									$context['ban_erros'][] = 'invalid_username';
1231
+				}
1208 1232
 				list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);
1209 1233
 				$smcFunc['db_free_result']($request);
1210 1234
 
@@ -1212,25 +1236,25 @@  discard block
 block discarded – undo
1212 1236
 				{
1213 1237
 					unset($value);
1214 1238
 					$context['ban_erros'][] = 'no_ban_admin';
1239
+				} else {
1240
+									$ban_triggers['user']['id_member'] = $value;
1215 1241
 				}
1216
-				else
1217
-					$ban_triggers['user']['id_member'] = $value;
1218
-			}
1219
-			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1242
+			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1220 1243
 			{
1221 1244
 				// Special case, those two are arrays themselves
1222 1245
 				$values = array_unique($value);
1223 1246
 				// Don't add the main IP again.
1224
-				if (isset($triggers['main_ip']))
1225
-					$values = array_diff($values, array($triggers['main_ip']));
1247
+				if (isset($triggers['main_ip'])) {
1248
+									$values = array_diff($values, array($triggers['main_ip']));
1249
+				}
1226 1250
 				unset($value);
1227 1251
 				foreach ($values as $val)
1228 1252
 				{
1229 1253
 					$val = trim($val);
1230 1254
 					$ip_parts = ip2range($val);
1231
-					if (!checkExistingTriggerIP($ip_parts, $val))
1232
-						$context['ban_erros'][] = 'invalid_ip';
1233
-					else
1255
+					if (!checkExistingTriggerIP($ip_parts, $val)) {
1256
+											$context['ban_erros'][] = 'invalid_ip';
1257
+					} else
1234 1258
 					{
1235 1259
 						$ban_triggers[$key][] = array(
1236 1260
 							'ip_low' => $ip_parts['low'],
@@ -1243,15 +1267,16 @@  discard block
 block discarded – undo
1243 1267
 						);
1244 1268
 					}
1245 1269
 				}
1270
+			} else {
1271
+							$context['ban_erros'][] = 'no_bantype_selected';
1246 1272
 			}
1247
-			else
1248
-				$context['ban_erros'][] = 'no_bantype_selected';
1249 1273
 
1250
-			if (isset($value) && !is_array($value))
1251
-				$log_info[] = array(
1274
+			if (isset($value) && !is_array($value)) {
1275
+							$log_info[] = array(
1252 1276
 					'value' => $value,
1253 1277
 					'bantype' => $key,
1254 1278
 				);
1279
+			}
1255 1280
 		}
1256 1281
 	}
1257 1282
 	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info);
@@ -1271,8 +1296,9 @@  discard block
 block discarded – undo
1271 1296
 {
1272 1297
 	global $smcFunc, $context;
1273 1298
 
1274
-	if (empty($group_id))
1275
-		$context['ban_errors'][] = 'ban_id_empty';
1299
+	if (empty($group_id)) {
1300
+			$context['ban_errors'][] = 'ban_id_empty';
1301
+	}
1276 1302
 
1277 1303
 	// Preset all values that are required.
1278 1304
 	$values = array(
@@ -1297,18 +1323,21 @@  discard block
 block discarded – undo
1297 1323
 	foreach ($triggers as $key => $trigger)
1298 1324
 	{
1299 1325
 		// Exceptions, exceptions, exceptions...always exceptions... :P
1300
-		if (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1301
-			foreach ($trigger as $real_trigger)
1326
+		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) {
1327
+					foreach ($trigger as $real_trigger)
1302 1328
 				$insertTriggers[] = array_merge($values, $real_trigger);
1303
-		else
1304
-			$insertTriggers[] = array_merge($values, $trigger);
1329
+		} else {
1330
+					$insertTriggers[] = array_merge($values, $trigger);
1331
+		}
1305 1332
 	}
1306 1333
 
1307
-	if (empty($insertTriggers))
1308
-		$context['ban_errors'][] = 'ban_no_triggers';
1334
+	if (empty($insertTriggers)) {
1335
+			$context['ban_errors'][] = 'ban_no_triggers';
1336
+	}
1309 1337
 
1310
-	if (!empty($context['ban_errors']))
1311
-		return false;
1338
+	if (!empty($context['ban_errors'])) {
1339
+			return false;
1340
+	}
1312 1341
 
1313 1342
 	$smcFunc['db_insert']('',
1314 1343
 		'{db_prefix}ban_items',
@@ -1336,15 +1365,19 @@  discard block
 block discarded – undo
1336 1365
 {
1337 1366
 	global $smcFunc, $context;
1338 1367
 
1339
-	if (empty($ban_item))
1340
-		$context['ban_errors'][] = 'ban_ban_item_empty';
1341
-	if (empty($group_id))
1342
-		$context['ban_errors'][] = 'ban_id_empty';
1343
-	if (empty($trigger))
1344
-		$context['ban_errors'][] = 'ban_no_triggers';
1368
+	if (empty($ban_item)) {
1369
+			$context['ban_errors'][] = 'ban_ban_item_empty';
1370
+	}
1371
+	if (empty($group_id)) {
1372
+			$context['ban_errors'][] = 'ban_id_empty';
1373
+	}
1374
+	if (empty($trigger)) {
1375
+			$context['ban_errors'][] = 'ban_no_triggers';
1376
+	}
1345 1377
 
1346
-	if (!empty($context['ban_errors']))
1347
-		return;
1378
+	if (!empty($context['ban_errors'])) {
1379
+			return;
1380
+	}
1348 1381
 
1349 1382
 	// Preset all values that are required.
1350 1383
 	$values = array(
@@ -1385,8 +1418,9 @@  discard block
 block discarded – undo
1385 1418
  */
1386 1419
 function logTriggersUpdates($logs, $new = true, $removal = false)
1387 1420
 {
1388
-	if (empty($logs))
1389
-		return;
1421
+	if (empty($logs)) {
1422
+			return;
1423
+	}
1390 1424
 
1391 1425
 	$log_name_map = array(
1392 1426
 		'main_ip' => 'ip_range',
@@ -1397,14 +1431,15 @@  discard block
 block discarded – undo
1397 1431
 	);
1398 1432
 
1399 1433
 	// Log the addion of the ban entries into the moderation log.
1400
-	foreach ($logs as $log)
1401
-		logAction('ban' . ($removal == true ? 'remove' : ''), array(
1434
+	foreach ($logs as $log) {
1435
+			logAction('ban' . ($removal == true ? 'remove' : ''), array(
1402 1436
 			$log_name_map[$log['bantype']] => $log['value'],
1403 1437
 			'new' => empty($new) ? 0 : 1,
1404 1438
 			'remove' => empty($removal) ? 0 : 1,
1405 1439
 			'type' => $log['bantype'],
1406 1440
 		));
1407
-}
1441
+	}
1442
+	}
1408 1443
 
1409 1444
 /**
1410 1445
  * Updates an existing ban group
@@ -1417,12 +1452,15 @@  discard block
 block discarded – undo
1417 1452
 {
1418 1453
 	global $smcFunc, $context;
1419 1454
 
1420
-	if (empty($ban_info['name']))
1421
-		$context['ban_errors'][] = 'ban_name_empty';
1422
-	if (empty($ban_info['id']))
1423
-		$context['ban_errors'][] = 'ban_id_empty';
1424
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1425
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1455
+	if (empty($ban_info['name'])) {
1456
+			$context['ban_errors'][] = 'ban_name_empty';
1457
+	}
1458
+	if (empty($ban_info['id'])) {
1459
+			$context['ban_errors'][] = 'ban_id_empty';
1460
+	}
1461
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1462
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1463
+	}
1426 1464
 
1427 1465
 	if(!empty($ban_info['id']))
1428 1466
 	{
@@ -1437,8 +1475,9 @@  discard block
 block discarded – undo
1437 1475
 			)
1438 1476
 		);
1439 1477
 
1440
-		if ($smcFunc['db_num_rows']($request) == 0)
1441
-			$context['ban_errors'][] = 'ban_not_found';
1478
+		if ($smcFunc['db_num_rows']($request) == 0) {
1479
+					$context['ban_errors'][] = 'ban_not_found';
1480
+		}
1442 1481
 		$smcFunc['db_free_result']($request);
1443 1482
 	}
1444 1483
 
@@ -1456,13 +1495,15 @@  discard block
 block discarded – undo
1456 1495
 				'new_ban_name' => $ban_info['name'],
1457 1496
 			)
1458 1497
 		);
1459
-		if ($smcFunc['db_num_rows']($request) != 0)
1460
-			$context['ban_errors'][] = 'ban_name_exists';
1498
+		if ($smcFunc['db_num_rows']($request) != 0) {
1499
+					$context['ban_errors'][] = 'ban_name_exists';
1500
+		}
1461 1501
 		$smcFunc['db_free_result']($request);
1462 1502
 	}
1463 1503
 
1464
-	if (!empty($context['ban_errors']))
1465
-		return;
1504
+	if (!empty($context['ban_errors'])) {
1505
+			return;
1506
+	}
1466 1507
 
1467 1508
 	$smcFunc['db_query']('', '
1468 1509
 		UPDATE {db_prefix}ban_groups
@@ -1505,10 +1546,12 @@  discard block
 block discarded – undo
1505 1546
 {
1506 1547
 	global $smcFunc, $context;
1507 1548
 
1508
-	if (empty($ban_info['name']))
1509
-		$context['ban_errors'][] = 'ban_name_empty';
1510
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1511
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1549
+	if (empty($ban_info['name'])) {
1550
+			$context['ban_errors'][] = 'ban_name_empty';
1551
+	}
1552
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1553
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1554
+	}
1512 1555
 
1513 1556
 	if(!empty($ban_info['name']))
1514 1557
 	{
@@ -1523,13 +1566,15 @@  discard block
 block discarded – undo
1523 1566
 			)
1524 1567
 		);
1525 1568
 
1526
-		if ($smcFunc['db_num_rows']($request) == 1)
1527
-			$context['ban_errors'][] = 'ban_name_exists';
1569
+		if ($smcFunc['db_num_rows']($request) == 1) {
1570
+					$context['ban_errors'][] = 'ban_name_exists';
1571
+		}
1528 1572
 		$smcFunc['db_free_result']($request);
1529 1573
 	}
1530 1574
 
1531
-	if (!empty($context['ban_errors']))
1532
-		return;
1575
+	if (!empty($context['ban_errors'])) {
1576
+			return;
1577
+	}
1533 1578
 
1534 1579
 	// Yes yes, we're ready to add now.
1535 1580
 	$smcFunc['db_insert']('',
@@ -1546,8 +1591,9 @@  discard block
 block discarded – undo
1546 1591
 	);
1547 1592
 	$ban_info['id'] = $smcFunc['db_insert_id']('{db_prefix}ban_groups', 'id_ban_group');
1548 1593
 
1549
-	if (empty($ban_info['id']))
1550
-		$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1594
+	if (empty($ban_info['id'])) {
1595
+			$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1596
+	}
1551 1597
 
1552 1598
 	return $ban_info['id'];
1553 1599
 }
@@ -1572,24 +1618,24 @@  discard block
 block discarded – undo
1572 1618
 	$ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
1573 1619
 	$ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
1574 1620
 
1575
-	if (empty($ban_group))
1576
-		fatal_lang_error('ban_not_found', false);
1621
+	if (empty($ban_group)) {
1622
+			fatal_lang_error('ban_not_found', false);
1623
+	}
1577 1624
 
1578 1625
 	if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))
1579 1626
 	{
1580 1627
 		saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
1581 1628
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1582
-	}
1583
-	elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1629
+	} elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1584 1630
 	{
1585 1631
 		// The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)
1586 1632
 		saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
1587
-		if (!empty($_POST['ban_suggestions']))
1588
-			saveTriggers($_POST['ban_suggestions'], $ban_group);
1633
+		if (!empty($_POST['ban_suggestions'])) {
1634
+					saveTriggers($_POST['ban_suggestions'], $ban_group);
1635
+		}
1589 1636
 
1590 1637
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1591
-	}
1592
-	elseif (isset($_POST['edit_trigger']))
1638
+	} elseif (isset($_POST['edit_trigger']))
1593 1639
 	{
1594 1640
 		removeBanTriggers($ban_id);
1595 1641
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
@@ -1620,8 +1666,7 @@  discard block
 block discarded – undo
1620 1666
 			),
1621 1667
 			'is_new' => true,
1622 1668
 		);
1623
-	}
1624
-	else
1669
+	} else
1625 1670
 	{
1626 1671
 		$request = $smcFunc['db_query']('', '
1627 1672
 			SELECT
@@ -1638,8 +1683,9 @@  discard block
 block discarded – undo
1638 1683
 				'ban_group' => $ban_group,
1639 1684
 			)
1640 1685
 		);
1641
-		if ($smcFunc['db_num_rows']($request) == 0)
1642
-			fatal_lang_error('ban_not_found', false);
1686
+		if ($smcFunc['db_num_rows']($request) == 0) {
1687
+					fatal_lang_error('ban_not_found', false);
1688
+		}
1643 1689
 		$row = $smcFunc['db_fetch_assoc']($request);
1644 1690
 		$smcFunc['db_free_result']($request);
1645 1691
 
@@ -1688,8 +1734,9 @@  discard block
 block discarded – undo
1688 1734
 		removeBanTriggers($_POST['remove']);
1689 1735
 
1690 1736
 		// Rehabilitate some members.
1691
-		if ($_REQUEST['entity'] == 'member')
1692
-			updateBanMembers();
1737
+		if ($_REQUEST['entity'] == 'member') {
1738
+					updateBanMembers();
1739
+		}
1693 1740
 
1694 1741
 		// Make sure the ban cache is refreshed.
1695 1742
 		updateSettings(array('banLastUpdated' => time()));
@@ -1802,8 +1849,7 @@  discard block
 block discarded – undo
1802 1849
 			'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',
1803 1850
 			'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',
1804 1851
 		);
1805
-	}
1806
-	elseif ($context['selected_entity'] === 'hostname')
1852
+	} elseif ($context['selected_entity'] === 'hostname')
1807 1853
 	{
1808 1854
 		$listOptions['columns']['banned_entity']['data'] = array(
1809 1855
 			'function' => function ($rowData) use ($smcFunc)
@@ -1815,8 +1861,7 @@  discard block
 block discarded – undo
1815 1861
 			'default' => 'bi.hostname',
1816 1862
 			'reverse' => 'bi.hostname DESC',
1817 1863
 		);
1818
-	}
1819
-	elseif ($context['selected_entity'] === 'email')
1864
+	} elseif ($context['selected_entity'] === 'email')
1820 1865
 	{
1821 1866
 		$listOptions['columns']['banned_entity']['data'] = array(
1822 1867
 			'function' => function ($rowData) use ($smcFunc)
@@ -1828,8 +1873,7 @@  discard block
 block discarded – undo
1828 1873
 			'default' => 'bi.email_address',
1829 1874
 			'reverse' => 'bi.email_address DESC',
1830 1875
 		);
1831
-	}
1832
-	elseif ($context['selected_entity'] === 'member')
1876
+	} elseif ($context['selected_entity'] === 'member')
1833 1877
 	{
1834 1878
 		$listOptions['columns']['banned_entity']['data'] = array(
1835 1879
 			'sprintf' => array(
@@ -1893,8 +1937,9 @@  discard block
 block discarded – undo
1893 1937
 		)
1894 1938
 	);
1895 1939
 	$ban_triggers = array();
1896
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1897
-		$ban_triggers[] = $row;
1940
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1941
+			$ban_triggers[] = $row;
1942
+	}
1898 1943
 	$smcFunc['db_free_result']($request);
1899 1944
 
1900 1945
 	return $ban_triggers;
@@ -1950,8 +1995,9 @@  discard block
 block discarded – undo
1950 1995
 		validateToken('admin-bl');
1951 1996
 
1952 1997
 		// 'Delete all entries' button was pressed.
1953
-		if (!empty($_POST['removeAll']))
1954
-			removeBanLogs();
1998
+		if (!empty($_POST['removeAll'])) {
1999
+					removeBanLogs();
2000
+		}
1955 2001
 		// 'Delete selection' button was pressed.
1956 2002
 		else
1957 2003
 		{
@@ -2112,8 +2158,9 @@  discard block
 block discarded – undo
2112 2158
 		)
2113 2159
 	);
2114 2160
 	$log_entries = array();
2115
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2116
-		$log_entries[] = $row;
2161
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2162
+			$log_entries[] = $row;
2163
+	}
2117 2164
 	$smcFunc['db_free_result']($request);
2118 2165
 
2119 2166
 	return $log_entries;
@@ -2155,12 +2202,15 @@  discard block
 block discarded – undo
2155 2202
 	$low = inet_dtop($low);
2156 2203
 	$high = inet_dtop($high);
2157 2204
 
2158
-	if ($low == '255.255.255.255') return 'unkown';
2159
-	if ($low == $high)
2160
-	    return $low;
2161
-	else
2162
-	    return $low . '-'.$high;
2163
-}
2205
+	if ($low == '255.255.255.255') {
2206
+		return 'unkown';
2207
+	}
2208
+	if ($low == $high) {
2209
+		    return $low;
2210
+	} else {
2211
+		    return $low . '-'.$high;
2212
+	}
2213
+	}
2164 2214
 
2165 2215
 /**
2166 2216
  * Checks whether a given IP range already exists in the trigger list.
@@ -2236,15 +2286,17 @@  discard block
 block discarded – undo
2236 2286
 	$memberEmailWild = array();
2237 2287
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2238 2288
 	{
2239
-		if ($row['id_member'])
2240
-			$memberIDs[$row['id_member']] = $row['id_member'];
2289
+		if ($row['id_member']) {
2290
+					$memberIDs[$row['id_member']] = $row['id_member'];
2291
+		}
2241 2292
 		if ($row['email_address'])
2242 2293
 		{
2243 2294
 			// Does it have a wildcard - if so we can't do a IN on it.
2244
-			if (strpos($row['email_address'], '%') !== false)
2245
-				$memberEmailWild[$row['email_address']] = $row['email_address'];
2246
-			else
2247
-				$memberEmails[$row['email_address']] = $row['email_address'];
2295
+			if (strpos($row['email_address'], '%') !== false) {
2296
+							$memberEmailWild[$row['email_address']] = $row['email_address'];
2297
+			} else {
2298
+							$memberEmails[$row['email_address']] = $row['email_address'];
2299
+			}
2248 2300
 		}
2249 2301
 	}
2250 2302
 	$smcFunc['db_free_result']($request);
@@ -2295,14 +2347,15 @@  discard block
 block discarded – undo
2295 2347
 	}
2296 2348
 
2297 2349
 	// We welcome our new members in the realm of the banned.
2298
-	if (!empty($newMembers))
2299
-		$smcFunc['db_query']('', '
2350
+	if (!empty($newMembers)) {
2351
+			$smcFunc['db_query']('', '
2300 2352
 			DELETE FROM {db_prefix}log_online
2301 2353
 			WHERE id_member IN ({array_int:new_banned_members})',
2302 2354
 			array(
2303 2355
 				'new_banned_members' => $newMembers,
2304 2356
 			)
2305 2357
 		);
2358
+	}
2306 2359
 
2307 2360
 	// Find members that are wrongfully marked as banned.
2308 2361
 	$request = $smcFunc['db_query']('', '
@@ -2329,9 +2382,10 @@  discard block
 block discarded – undo
2329 2382
 	}
2330 2383
 	$smcFunc['db_free_result']($request);
2331 2384
 
2332
-	if (!empty($updates))
2333
-		foreach ($updates as $newStatus => $members)
2385
+	if (!empty($updates)) {
2386
+			foreach ($updates as $newStatus => $members)
2334 2387
 			updateMemberData($members, array('is_activated' => $newStatus));
2388
+	}
2335 2389
 
2336 2390
 	// Update the latest member and our total members as banning may change them.
2337 2391
 	updateStats('member');
@@ -2357,8 +2411,9 @@  discard block
 block discarded – undo
2357 2411
 			'current_user' => $id,
2358 2412
 		)
2359 2413
 	);
2360
-	if ($smcFunc['db_num_rows']($request) > 0)
2361
-		list ($suggestions['member']['id'], $suggestions['member']['name'], $suggestions['main_ip'], $suggestions['email']) = $smcFunc['db_fetch_row']($request);
2414
+	if ($smcFunc['db_num_rows']($request) > 0) {
2415
+			list ($suggestions['member']['id'], $suggestions['member']['name'], $suggestions['main_ip'], $suggestions['email']) = $smcFunc['db_fetch_row']($request);
2416
+	}
2362 2417
 	$smcFunc['db_free_result']($request);
2363 2418
 
2364 2419
 	return $suggestions;
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 = @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
@@ -4065,7 +4065,7 @@
 block discarded – undo
4065 4065
  *
4066 4066
  * @param int $pmID The ID of the PM
4067 4067
  * @param string $validFor Which folders this is valud for - can be 'inbox', 'outbox' or 'in_or_outbox'
4068
- * @return boolean Whether the PM is accessible in that folder for the current user
4068
+ * @return boolean|null Whether the PM is accessible in that folder for the current user
4069 4069
  */
4070 4070
 function isAccessiblePM($pmID, $validFor = 'in_or_outbox')
4071 4071
 {
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 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) ? '' : '
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 					)
845 845
 				);
846 846
 
847
-				while($row2 = $smcFunc['db_fetch_assoc']($request2))
847
+				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
848 848
 				{
849 849
 					$l_id = $row2['id_label'];
850 850
 					if (isset($context['labels'][$l_id]))
@@ -1622,7 +1622,7 @@  discard block
 block discarded – undo
1622 1622
 					)
1623 1623
 				);
1624 1624
 
1625
-				while($row2 = $smcFunc['db_fetch_assoc']($request2))
1625
+				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1626 1626
 				{
1627 1627
 					$l_id = $row2['id_label'];
1628 1628
 					if (isset($context['labels'][$l_id]))
@@ -2037,7 +2037,7 @@  discard block
 block discarded – undo
2037 2037
 
2038 2038
 	if (!isset($_REQUEST['xml']))
2039 2039
 	{
2040
-		$context['menu_data_' . $context['pm_menu_id']]['current_area'] = 'send';		$context['sub_template'] = 'send';
2040
+		$context['menu_data_' . $context['pm_menu_id']]['current_area'] = 'send'; $context['sub_template'] = 'send';
2041 2041
 		loadJavascriptFile('PersonalMessage.js', array('default_theme' => true, 'defer' => false), 'smf_pms');
2042 2042
 		loadJavascriptFile('suggest.js', array('default_theme' => true, 'defer' => false), 'smf_suggest');
2043 2043
 	}
@@ -3718,7 +3718,7 @@  discard block
 block discarded – undo
3718 3718
 	// Editing a specific one?
3719 3719
 	if (isset($_GET['add']))
3720 3720
 	{
3721
-		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']])? (int) $_GET['rid'] : 0;
3721
+		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0;
3722 3722
 		$context['sub_template'] = 'add_rule';
3723 3723
 
3724 3724
 		// Current rule information...
@@ -3759,7 +3759,7 @@  discard block
 block discarded – undo
3759 3759
 	elseif (isset($_GET['save']))
3760 3760
 	{
3761 3761
 		checkSession();
3762
-		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']])? (int) $_GET['rid'] : 0;
3762
+		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0;
3763 3763
 
3764 3764
 		// Name is easy!
3765 3765
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
Please login to merge, or discard this patch.
Braces   +636 added lines, -473 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
 			}
@@ -826,8 +852,9 @@  discard block
 block discarded – undo
826 852
 		$context['message_unread'] = array();
827 853
 		while ($row = $smcFunc['db_fetch_assoc']($request))
828 854
 		{
829
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
830
-				$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>';
855
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
856
+							$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>';
857
+			}
831 858
 
832 859
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
833 860
 			{
@@ -847,8 +874,9 @@  discard block
 block discarded – undo
847 874
 				while($row2 = $smcFunc['db_fetch_assoc']($request2))
848 875
 				{
849 876
 					$l_id = $row2['id_label'];
850
-					if (isset($context['labels'][$l_id]))
851
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
877
+					if (isset($context['labels'][$l_id])) {
878
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
879
+					}
852 880
 				}
853 881
 
854 882
 				$smcFunc['db_free_result']($request2);
@@ -865,9 +893,10 @@  discard block
 block discarded – undo
865 893
 		// Make sure we don't load unnecessary data.
866 894
 		if ($context['display_mode'] == 1)
867 895
 		{
868
-			foreach ($posters as $k => $v)
869
-				if (!in_array($k, $display_pms))
896
+			foreach ($posters as $k => $v) {
897
+							if (!in_array($k, $display_pms))
870 898
 					unset($posters[$k]);
899
+			}
871 900
 		}
872 901
 
873 902
 		// Load any users....
@@ -878,8 +907,9 @@  discard block
 block discarded – undo
878 907
 		{
879 908
 			// Get the order right.
880 909
 			$orderBy = array();
881
-			foreach (array_reverse($pms) as $pm)
882
-				$orderBy[] = 'pm.id_pm = ' . $pm;
910
+			foreach (array_reverse($pms) as $pm) {
911
+							$orderBy[] = 'pm.id_pm = ' . $pm;
912
+			}
883 913
 
884 914
 			// Seperate query for these bits!
885 915
 			$subjects_request = $smcFunc['db_query']('', '
@@ -925,9 +955,9 @@  discard block
 block discarded – undo
925 955
 			// Allow mods to add additional buttons here
926 956
 			call_integration_hook('integrate_conversation_buttons');
927 957
 		}
958
+	} else {
959
+			$messages_request = false;
928 960
 	}
929
-	else
930
-		$messages_request = false;
931 961
 
932 962
 	$context['can_send_pm'] = allowedTo('pm_send');
933 963
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -938,11 +968,13 @@  discard block
 block discarded – undo
938 968
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
939 969
 	{
940 970
 		// If the display mode is "old sk00l" do them all...
941
-		if ($context['display_mode'] == 0)
942
-			markMessages(null, $context['current_label_id']);
971
+		if ($context['display_mode'] == 0) {
972
+					markMessages(null, $context['current_label_id']);
973
+		}
943 974
 		// Otherwise do just the current one!
944
-		elseif (!empty($context['current_pm']))
945
-			markMessages($display_pms, $context['current_label_id']);
975
+		elseif (!empty($context['current_pm'])) {
976
+					markMessages($display_pms, $context['current_label_id']);
977
+		}
946 978
 	}
947 979
 }
948 980
 
@@ -960,8 +992,9 @@  discard block
 block discarded – undo
960 992
 
961 993
 	// Count the current message number....
962 994
 	static $counter = null;
963
-	if ($counter === null || $reset)
964
-		$counter = $context['start'];
995
+	if ($counter === null || $reset) {
996
+			$counter = $context['start'];
997
+	}
965 998
 
966 999
 	static $temp_pm_selected = null;
967 1000
 	if ($temp_pm_selected === null)
@@ -1006,19 +1039,22 @@  discard block
 block discarded – undo
1006 1039
 	}
1007 1040
 
1008 1041
 	// Bail if it's false, ie. no messages.
1009
-	if ($messages_request == false)
1010
-		return false;
1042
+	if ($messages_request == false) {
1043
+			return false;
1044
+	}
1011 1045
 
1012 1046
 	// Reset the data?
1013
-	if ($reset == true)
1014
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1047
+	if ($reset == true) {
1048
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1049
+	}
1015 1050
 
1016 1051
 	// Get the next one... bail if anything goes wrong.
1017 1052
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1018 1053
 	if (!$message)
1019 1054
 	{
1020
-		if ($type != 'subject')
1021
-			$smcFunc['db_free_result']($messages_request);
1055
+		if ($type != 'subject') {
1056
+					$smcFunc['db_free_result']($messages_request);
1057
+		}
1022 1058
 
1023 1059
 		return false;
1024 1060
 	}
@@ -1038,8 +1074,7 @@  discard block
 block discarded – undo
1038 1074
 		$memberContext[$message['id_member_from']]['email'] = '';
1039 1075
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1040 1076
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1041
-	}
1042
-	else
1077
+	} else
1043 1078
 	{
1044 1079
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1045 1080
 		$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'])));
@@ -1080,12 +1115,13 @@  discard block
 block discarded – undo
1080 1115
 	$counter++;
1081 1116
 
1082 1117
 	// Any custom profile fields?
1083
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1084
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1118
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1119
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1085 1120
 			switch ($custom['placement'])
1086 1121
 			{
1087 1122
 				case 1:
1088 1123
 					$output['custom_fields']['icons'][] = $custom;
1124
+	}
1089 1125
 					break;
1090 1126
 				case 2:
1091 1127
 					$output['custom_fields']['above_signature'][] = $custom;
@@ -1128,22 +1164,28 @@  discard block
 block discarded – undo
1128 1164
 			$context['search_params'][$k] = $v;
1129 1165
 		}
1130 1166
 	}
1131
-	if (isset($_REQUEST['search']))
1132
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1167
+	if (isset($_REQUEST['search'])) {
1168
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1169
+	}
1133 1170
 
1134
-	if (isset($context['search_params']['search']))
1135
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1136
-	if (isset($context['search_params']['userspec']))
1137
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1171
+	if (isset($context['search_params']['search'])) {
1172
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1173
+	}
1174
+	if (isset($context['search_params']['userspec'])) {
1175
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1176
+	}
1138 1177
 
1139
-	if (!empty($context['search_params']['searchtype']))
1140
-		$context['search_params']['searchtype'] = 2;
1178
+	if (!empty($context['search_params']['searchtype'])) {
1179
+			$context['search_params']['searchtype'] = 2;
1180
+	}
1141 1181
 
1142
-	if (!empty($context['search_params']['minage']))
1143
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1182
+	if (!empty($context['search_params']['minage'])) {
1183
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1184
+	}
1144 1185
 
1145
-	if (!empty($context['search_params']['maxage']))
1146
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1186
+	if (!empty($context['search_params']['maxage'])) {
1187
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1188
+	}
1147 1189
 
1148 1190
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1149 1191
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1170,8 +1212,9 @@  discard block
 block discarded – undo
1170 1212
 		$context['search_errors']['messages'] = array();
1171 1213
 		foreach ($context['search_errors'] as $search_error => $dummy)
1172 1214
 		{
1173
-			if ($search_error == 'messages')
1174
-				continue;
1215
+			if ($search_error == 'messages') {
1216
+							continue;
1217
+			}
1175 1218
 
1176 1219
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1177 1220
 		}
@@ -1193,8 +1236,9 @@  discard block
 block discarded – undo
1193 1236
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1194 1237
 	global $memberContext, $smcFunc;
1195 1238
 
1196
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1197
-		fatal_lang_error('loadavg_search_disabled', false);
1239
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1240
+			fatal_lang_error('loadavg_search_disabled', false);
1241
+	}
1198 1242
 
1199 1243
 	/**
1200 1244
 	 * @todo For the moment force the folder to the inbox.
@@ -1223,35 +1267,40 @@  discard block
 block discarded – undo
1223 1267
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1224 1268
 
1225 1269
 	// Store whether simple search was used (needed if the user wants to do another query).
1226
-	if (!isset($search_params['advanced']))
1227
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1270
+	if (!isset($search_params['advanced'])) {
1271
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1272
+	}
1228 1273
 
1229 1274
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1230
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1231
-		$search_params['searchtype'] = 2;
1275
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1276
+			$search_params['searchtype'] = 2;
1277
+	}
1232 1278
 
1233 1279
 	// Minimum age of messages. Default to zero (don't set param in that case).
1234
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1235
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1280
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1281
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1282
+	}
1236 1283
 
1237 1284
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1238
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1239
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1285
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1286
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1287
+	}
1240 1288
 
1241 1289
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1242 1290
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1243 1291
 
1244 1292
 	// Default the user name to a wildcard matching every user (*).
1245
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1246
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1293
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1294
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1295
+	}
1247 1296
 
1248 1297
 	// This will be full of all kinds of parameters!
1249 1298
 	$searchq_parameters = array();
1250 1299
 
1251 1300
 	// If there's no specific user, then don't mention it in the main query.
1252
-	if (empty($search_params['userspec']))
1253
-		$userQuery = '';
1254
-	else
1301
+	if (empty($search_params['userspec'])) {
1302
+			$userQuery = '';
1303
+	} else
1255 1304
 	{
1256 1305
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1257 1306
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1263,8 +1312,9 @@  discard block
 block discarded – undo
1263 1312
 		{
1264 1313
 			$possible_users[$k] = trim($possible_users[$k]);
1265 1314
 
1266
-			if (strlen($possible_users[$k]) == 0)
1267
-				unset($possible_users[$k]);
1315
+			if (strlen($possible_users[$k]) == 0) {
1316
+							unset($possible_users[$k]);
1317
+			}
1268 1318
 		}
1269 1319
 
1270 1320
 		if (!empty($possible_users))
@@ -1276,8 +1326,9 @@  discard block
 block discarded – undo
1276 1326
 			{
1277 1327
 				$where_params['name_' . $k] = $v;
1278 1328
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1279
-				if (!isset($where_params['real_name']))
1280
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1329
+				if (!isset($where_params['real_name'])) {
1330
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1331
+				}
1281 1332
 			}
1282 1333
 
1283 1334
 			// Who matches those criteria?
@@ -1290,28 +1341,28 @@  discard block
 block discarded – undo
1290 1341
 			);
1291 1342
 
1292 1343
 			// Simply do nothing if there're too many members matching the criteria.
1293
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1294
-				$userQuery = '';
1295
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1344
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1345
+							$userQuery = '';
1346
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1296 1347
 			{
1297 1348
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1298 1349
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1299 1350
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1300
-			}
1301
-			else
1351
+			} else
1302 1352
 			{
1303 1353
 				$memberlist = array();
1304
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1305
-					$memberlist[] = $row['id_member'];
1354
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1355
+									$memberlist[] = $row['id_member'];
1356
+				}
1306 1357
 				$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})))';
1307 1358
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1308 1359
 				$searchq_parameters['member_list'] = $memberlist;
1309 1360
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1310 1361
 			}
1311 1362
 			$smcFunc['db_free_result']($request);
1363
+		} else {
1364
+					$userQuery = '';
1312 1365
 		}
1313
-		else
1314
-			$userQuery = '';
1315 1366
 	}
1316 1367
 
1317 1368
 	// Setup the sorting variables...
@@ -1319,8 +1370,9 @@  discard block
 block discarded – undo
1319 1370
 	$sort_columns = array(
1320 1371
 		'pm.id_pm',
1321 1372
 	);
1322
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1323
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1373
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1374
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1375
+	}
1324 1376
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1325 1377
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1326 1378
 
@@ -1330,24 +1382,27 @@  discard block
 block discarded – undo
1330 1382
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1331 1383
 	{
1332 1384
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1333
-		if (isset($search_params['labels']))
1334
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1385
+		if (isset($search_params['labels'])) {
1386
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1387
+		}
1335 1388
 
1336 1389
 		// Assuming we have some labels - make them all integers.
1337 1390
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1338 1391
 		{
1339
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1340
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1392
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1393
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1394
+			}
1395
+		} else {
1396
+					$_REQUEST['searchlabel'] = array();
1341 1397
 		}
1342
-		else
1343
-			$_REQUEST['searchlabel'] = array();
1344 1398
 
1345 1399
 		// Now that everything is cleaned up a bit, make the labels a param.
1346 1400
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1347 1401
 
1348 1402
 		// No labels selected? That must be an error!
1349
-		if (empty($_REQUEST['searchlabel']))
1350
-			$context['search_errors']['no_labels_selected'] = true;
1403
+		if (empty($_REQUEST['searchlabel'])) {
1404
+					$context['search_errors']['no_labels_selected'] = true;
1405
+		}
1351 1406
 		// Otherwise prepare the query!
1352 1407
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1353 1408
 		{
@@ -1370,8 +1425,7 @@  discard block
 block discarded – undo
1370 1425
 					// Not searching the inbox - PM must be labeled
1371 1426
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1372 1427
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1373
-				}
1374
-				else
1428
+				} else
1375 1429
 				{
1376 1430
 					// Searching the inbox - PM doesn't have to be labeled
1377 1431
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1386,8 +1440,9 @@  discard block
 block discarded – undo
1386 1440
 	// What are we actually searching for?
1387 1441
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1388 1442
 	// If we ain't got nothing - we should error!
1389
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1390
-		$context['search_errors']['invalid_search_string'] = true;
1443
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1444
+			$context['search_errors']['invalid_search_string'] = true;
1445
+	}
1391 1446
 
1392 1447
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1393 1448
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1400,12 +1455,14 @@  discard block
 block discarded – undo
1400 1455
 	$excludedWords = array();
1401 1456
 
1402 1457
 	// .. first, we check for things like -"some words", but not "-some words".
1403
-	foreach ($matches[1] as $index => $word)
1404
-		if ($word == '-')
1458
+	foreach ($matches[1] as $index => $word) {
1459
+			if ($word == '-')
1405 1460
 		{
1406 1461
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1407
-			if (strlen($word) > 0)
1408
-				$excludedWords[] = $word;
1462
+	}
1463
+			if (strlen($word) > 0) {
1464
+							$excludedWords[] = $word;
1465
+			}
1409 1466
 			unset($searchArray[$index]);
1410 1467
 		}
1411 1468
 
@@ -1415,8 +1472,9 @@  discard block
 block discarded – undo
1415 1472
 		if (strpos(trim($word), '-') === 0)
1416 1473
 		{
1417 1474
 			$word = substr($smcFunc['strtolower']($word), 1);
1418
-			if (strlen($word) > 0)
1419
-				$excludedWords[] = $word;
1475
+			if (strlen($word) > 0) {
1476
+							$excludedWords[] = $word;
1477
+			}
1420 1478
 			unset($tempSearch[$index]);
1421 1479
 		}
1422 1480
 	}
@@ -1427,9 +1485,9 @@  discard block
 block discarded – undo
1427 1485
 	foreach ($searchArray as $index => $value)
1428 1486
 	{
1429 1487
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1430
-		if ($searchArray[$index] == '')
1431
-			unset($searchArray[$index]);
1432
-		else
1488
+		if ($searchArray[$index] == '') {
1489
+					unset($searchArray[$index]);
1490
+		} else
1433 1491
 		{
1434 1492
 			// Sort out entities first.
1435 1493
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1439,27 +1497,32 @@  discard block
 block discarded – undo
1439 1497
 
1440 1498
 	// Create an array of replacements for highlighting.
1441 1499
 	$context['mark'] = array();
1442
-	foreach ($searchArray as $word)
1443
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1500
+	foreach ($searchArray as $word) {
1501
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1502
+	}
1444 1503
 
1445 1504
 	// This contains *everything*
1446 1505
 	$searchWords = array_merge($searchArray, $excludedWords);
1447 1506
 
1448 1507
 	// Make sure at least one word is being searched for.
1449
-	if (empty($searchArray))
1450
-		$context['search_errors']['invalid_search_string'] = true;
1508
+	if (empty($searchArray)) {
1509
+			$context['search_errors']['invalid_search_string'] = true;
1510
+	}
1451 1511
 
1452 1512
 	// Sort out the search query so the user can edit it - if they want.
1453 1513
 	$context['search_params'] = $search_params;
1454
-	if (isset($context['search_params']['search']))
1455
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1456
-	if (isset($context['search_params']['userspec']))
1457
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1514
+	if (isset($context['search_params']['search'])) {
1515
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1516
+	}
1517
+	if (isset($context['search_params']['userspec'])) {
1518
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1519
+	}
1458 1520
 
1459 1521
 	// Now we have all the parameters, combine them together for pagination and the like...
1460 1522
 	$context['params'] = array();
1461
-	foreach ($search_params as $k => $v)
1462
-		$context['params'][] = $k . '|\'|' . $v;
1523
+	foreach ($search_params as $k => $v) {
1524
+			$context['params'][] = $k . '|\'|' . $v;
1525
+	}
1463 1526
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1464 1527
 
1465 1528
 	// Compile the subject query part.
@@ -1467,26 +1530,31 @@  discard block
 block discarded – undo
1467 1530
 
1468 1531
 	foreach ($searchWords as $index => $word)
1469 1532
 	{
1470
-		if ($word == '')
1471
-			continue;
1533
+		if ($word == '') {
1534
+					continue;
1535
+		}
1472 1536
 
1473
-		if ($search_params['subject_only'])
1474
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1475
-		else
1476
-			$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 . '})';
1537
+		if ($search_params['subject_only']) {
1538
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1539
+		} else {
1540
+					$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 . '})';
1541
+		}
1477 1542
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1478 1543
 	}
1479 1544
 
1480 1545
 	$searchQuery = ' 1=1';
1481
-	if (!empty($andQueryParts))
1482
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1546
+	if (!empty($andQueryParts)) {
1547
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1548
+	}
1483 1549
 
1484 1550
 	// Age limits?
1485 1551
 	$timeQuery = '';
1486
-	if (!empty($search_params['minage']))
1487
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1488
-	if (!empty($search_params['maxage']))
1489
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1552
+	if (!empty($search_params['minage'])) {
1553
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1554
+	}
1555
+	if (!empty($search_params['maxage'])) {
1556
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1557
+	}
1490 1558
 
1491 1559
 	// If we have errors - return back to the first screen...
1492 1560
 	if (!empty($context['search_errors']))
@@ -1572,8 +1640,9 @@  discard block
 block discarded – undo
1572 1640
 			)
1573 1641
 		);
1574 1642
 		$real_pm_ids = array();
1575
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1576
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1644
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1645
+		}
1577 1646
 		$smcFunc['db_free_result']($request);
1578 1647
 	}
1579 1648
 
@@ -1603,8 +1672,9 @@  discard block
 block discarded – undo
1603 1672
 		);
1604 1673
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1605 1674
 		{
1606
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1607
-				$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>';
1675
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1676
+							$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>';
1677
+			}
1608 1678
 
1609 1679
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1610 1680
 			{
@@ -1625,12 +1695,14 @@  discard block
 block discarded – undo
1625 1695
 				while($row2 = $smcFunc['db_fetch_assoc']($request2))
1626 1696
 				{
1627 1697
 					$l_id = $row2['id_label'];
1628
-					if (isset($context['labels'][$l_id]))
1629
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1698
+					if (isset($context['labels'][$l_id])) {
1699
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1700
+					}
1630 1701
 
1631 1702
 					// Here we find the first label on a message - for linking to posts in results
1632
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1633
-						$context['first_label'][$row['id_pm']] = $l_id;
1703
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1704
+											$context['first_label'][$row['id_pm']] = $l_id;
1705
+					}
1634 1706
 				}
1635 1707
 
1636 1708
 				$smcFunc['db_free_result']($request2);
@@ -1757,8 +1829,9 @@  discard block
 block discarded – undo
1757 1829
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1758 1830
 		$smcFunc['db_free_result']($request);
1759 1831
 
1760
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1761
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1832
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1833
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1834
+		}
1762 1835
 	}
1763 1836
 
1764 1837
 	// Quoting/Replying to a message?
@@ -1767,8 +1840,9 @@  discard block
 block discarded – undo
1767 1840
 		$pmsg = (int) $_REQUEST['pmsg'];
1768 1841
 
1769 1842
 		// Make sure this is yours.
1770
-		if (!isAccessiblePM($pmsg))
1771
-			fatal_lang_error('no_access', false);
1843
+		if (!isAccessiblePM($pmsg)) {
1844
+					fatal_lang_error('no_access', false);
1845
+		}
1772 1846
 
1773 1847
 		// Work out whether this is one you've received?
1774 1848
 		$request = $smcFunc['db_query']('', '
@@ -1805,8 +1879,9 @@  discard block
 block discarded – undo
1805 1879
 				'id_pm' => $pmsg,
1806 1880
 			)
1807 1881
 		);
1808
-		if ($smcFunc['db_num_rows']($request) == 0)
1809
-			fatal_lang_error('pm_not_yours', false);
1882
+		if ($smcFunc['db_num_rows']($request) == 0) {
1883
+					fatal_lang_error('pm_not_yours', false);
1884
+		}
1810 1885
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1811 1886
 		$smcFunc['db_free_result']($request);
1812 1887
 
@@ -1817,9 +1892,9 @@  discard block
 block discarded – undo
1817 1892
 		// Add 'Re: ' to it....
1818 1893
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1819 1894
 		{
1820
-			if ($language === $user_info['language'])
1821
-				$context['response_prefix'] = $txt['response_prefix'];
1822
-			else
1895
+			if ($language === $user_info['language']) {
1896
+							$context['response_prefix'] = $txt['response_prefix'];
1897
+			} else
1823 1898
 			{
1824 1899
 				loadLanguage('index', $language, false);
1825 1900
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1828,22 +1903,25 @@  discard block
 block discarded – undo
1828 1903
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1829 1904
 		}
1830 1905
 		$form_subject = $row_quoted['subject'];
1831
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1832
-			$form_subject = $context['response_prefix'] . $form_subject;
1906
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1907
+					$form_subject = $context['response_prefix'] . $form_subject;
1908
+		}
1833 1909
 
1834 1910
 		if (isset($_REQUEST['quote']))
1835 1911
 		{
1836 1912
 			// Remove any nested quotes and <br>...
1837 1913
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1838
-			if (!empty($modSettings['removeNestedQuotes']))
1839
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1840
-			if (empty($row_quoted['id_member']))
1841
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1842
-			else
1843
-				$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]';
1914
+			if (!empty($modSettings['removeNestedQuotes'])) {
1915
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1916
+			}
1917
+			if (empty($row_quoted['id_member'])) {
1918
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1919
+			} else {
1920
+							$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]';
1921
+			}
1922
+		} else {
1923
+					$form_message = '';
1844 1924
 		}
1845
-		else
1846
-			$form_message = '';
1847 1925
 
1848 1926
 		// Do the BBC thang on the message.
1849 1927
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1864,8 +1942,7 @@  discard block
 block discarded – undo
1864 1942
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1865 1943
 			'body' => $row_quoted['body']
1866 1944
 		);
1867
-	}
1868
-	else
1945
+	} else
1869 1946
 	{
1870 1947
 		$context['quoted_message'] = false;
1871 1948
 		$form_subject = '';
@@ -1884,11 +1961,12 @@  discard block
 block discarded – undo
1884 1961
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1885 1962
 		{
1886 1963
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1887
-			if ($row_quoted['id_member'] != $user_info['id'])
1888
-				$context['recipients']['to'][] = array(
1964
+			if ($row_quoted['id_member'] != $user_info['id']) {
1965
+							$context['recipients']['to'][] = array(
1889 1966
 					'id' => $row_quoted['id_member'],
1890 1967
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1891 1968
 				);
1969
+			}
1892 1970
 
1893 1971
 			// Now to get the others.
1894 1972
 			$request = $smcFunc['db_query']('', '
@@ -1904,18 +1982,19 @@  discard block
 block discarded – undo
1904 1982
 					'not_bcc' => 0,
1905 1983
 				)
1906 1984
 			);
1907
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1908
-				$context['recipients']['to'][] = array(
1985
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1986
+							$context['recipients']['to'][] = array(
1909 1987
 					'id' => $row['id_member'],
1910 1988
 					'name' => $row['real_name'],
1911 1989
 				);
1990
+			}
1912 1991
 			$smcFunc['db_free_result']($request);
1913
-		}
1914
-		else
1992
+		} else
1915 1993
 		{
1916 1994
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1917
-			foreach ($_REQUEST['u'] as $key => $uID)
1918
-				$_REQUEST['u'][$key] = (int) $uID;
1995
+			foreach ($_REQUEST['u'] as $key => $uID) {
1996
+							$_REQUEST['u'][$key] = (int) $uID;
1997
+			}
1919 1998
 
1920 1999
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1921 2000
 
@@ -1929,22 +2008,24 @@  discard block
 block discarded – undo
1929 2008
 					'limit' => count($_REQUEST['u']),
1930 2009
 				)
1931 2010
 			);
1932
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1933
-				$context['recipients']['to'][] = array(
2011
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2012
+							$context['recipients']['to'][] = array(
1934 2013
 					'id' => $row['id_member'],
1935 2014
 					'name' => $row['real_name'],
1936 2015
 				);
2016
+			}
1937 2017
 			$smcFunc['db_free_result']($request);
1938 2018
 		}
1939 2019
 
1940 2020
 		// Get a literal name list in case the user has JavaScript disabled.
1941 2021
 		$names = array();
1942
-		foreach ($context['recipients']['to'] as $to)
1943
-			$names[] = $to['name'];
2022
+		foreach ($context['recipients']['to'] as $to) {
2023
+					$names[] = $to['name'];
2024
+		}
1944 2025
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2026
+	} else {
2027
+			$context['to_value'] = '';
1945 2028
 	}
1946
-	else
1947
-		$context['to_value'] = '';
1948 2029
 
1949 2030
 	// Set the defaults...
1950 2031
 	$context['subject'] = $form_subject;
@@ -2014,8 +2095,9 @@  discard block
 block discarded – undo
2014 2095
 
2015 2096
 	// validate with loadMemberData()
2016 2097
 	$memberResult = loadMemberData($user_info['id'], false);
2017
-	if (!$memberResult)
2018
-		fatal_lang_error('not_a_user', false);
2098
+	if (!$memberResult) {
2099
+			fatal_lang_error('not_a_user', false);
2100
+	}
2019 2101
 	list ($memID) = $memberResult;
2020 2102
 
2021 2103
 	// drafts is where the functions reside
@@ -2040,9 +2122,9 @@  discard block
 block discarded – undo
2040 2122
 		$context['menu_data_' . $context['pm_menu_id']]['current_area'] = 'send';		$context['sub_template'] = 'send';
2041 2123
 		loadJavascriptFile('PersonalMessage.js', array('default_theme' => true, 'defer' => false), 'smf_pms');
2042 2124
 		loadJavascriptFile('suggest.js', array('default_theme' => true, 'defer' => false), 'smf_suggest');
2125
+	} else {
2126
+			$context['sub_template'] = 'pm';
2043 2127
 	}
2044
-	else
2045
-		$context['sub_template'] = 'pm';
2046 2128
 
2047 2129
 	$context['page_title'] = $txt['send_message'];
2048 2130
 
@@ -2103,10 +2185,11 @@  discard block
 block discarded – undo
2103 2185
 		);
2104 2186
 		if ($smcFunc['db_num_rows']($request) == 0)
2105 2187
 		{
2106
-			if (!isset($_REQUEST['xml']))
2107
-				fatal_lang_error('pm_not_yours', false);
2108
-			else
2109
-				$error_types[] = 'pm_not_yours';
2188
+			if (!isset($_REQUEST['xml'])) {
2189
+							fatal_lang_error('pm_not_yours', false);
2190
+			} else {
2191
+							$error_types[] = 'pm_not_yours';
2192
+			}
2110 2193
 		}
2111 2194
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2112 2195
 		$smcFunc['db_free_result']($request);
@@ -2153,14 +2236,16 @@  discard block
 block discarded – undo
2153 2236
 		$context['post_error'][$error_type] = true;
2154 2237
 		if (isset($txt['error_' . $error_type]))
2155 2238
 		{
2156
-			if ($error_type == 'long_message')
2157
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2239
+			if ($error_type == 'long_message') {
2240
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2241
+			}
2158 2242
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2159 2243
 		}
2160 2244
 
2161 2245
 		// If it's not a minor error flag it as such.
2162
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2163
-			$context['error_type'] = 'serious';
2246
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2247
+					$context['error_type'] = 'serious';
2248
+		}
2164 2249
 	}
2165 2250
 
2166 2251
 	// We need to load the editor once more.
@@ -2218,8 +2303,9 @@  discard block
 block discarded – undo
2218 2303
 	require_once($sourcedir . '/Subs-Auth.php');
2219 2304
 
2220 2305
 	// PM Drafts enabled and needed?
2221
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2222
-		require_once($sourcedir . '/Drafts.php');
2306
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2307
+			require_once($sourcedir . '/Drafts.php');
2308
+	}
2223 2309
 
2224 2310
 	loadLanguage('PersonalMessage', '', false);
2225 2311
 
@@ -2249,24 +2335,27 @@  discard block
 block discarded – undo
2249 2335
 
2250 2336
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2251 2337
 		{
2252
-			if (!isset($_REQUEST['xml']))
2253
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2254
-			else
2255
-				$post_errors[] = 'pm_too_many_per_hour';
2338
+			if (!isset($_REQUEST['xml'])) {
2339
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2340
+			} else {
2341
+							$post_errors[] = 'pm_too_many_per_hour';
2342
+			}
2256 2343
 		}
2257 2344
 	}
2258 2345
 
2259 2346
 	// If your session timed out, show an error, but do allow to re-submit.
2260
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2261
-		$post_errors[] = 'session_timeout';
2347
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2348
+			$post_errors[] = 'session_timeout';
2349
+	}
2262 2350
 
2263 2351
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2264 2352
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2265 2353
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2266 2354
 
2267 2355
 	// Route the input from the 'u' parameter to the 'to'-list.
2268
-	if (!empty($_POST['u']))
2269
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2356
+	if (!empty($_POST['u'])) {
2357
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2358
+	}
2270 2359
 
2271 2360
 	// Construct the list of recipients.
2272 2361
 	$recipientList = array();
@@ -2278,8 +2367,9 @@  discard block
 block discarded – undo
2278 2367
 		$recipientList[$recipientType] = array();
2279 2368
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2280 2369
 		{
2281
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2282
-				$recipientList[$recipientType][] = (int) $recipient;
2370
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2371
+							$recipientList[$recipientType][] = (int) $recipient;
2372
+			}
2283 2373
 		}
2284 2374
 
2285 2375
 		// Are there also literal names set?
@@ -2293,10 +2383,11 @@  discard block
 block discarded – undo
2293 2383
 
2294 2384
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2295 2385
 			{
2296
-				if (strlen(trim($recipient)) > 0)
2297
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2298
-				else
2299
-					unset($namedRecipientList[$recipientType][$index]);
2386
+				if (strlen(trim($recipient)) > 0) {
2387
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2388
+				} else {
2389
+									unset($namedRecipientList[$recipientType][$index]);
2390
+				}
2300 2391
 			}
2301 2392
 
2302 2393
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2326,8 +2417,9 @@  discard block
 block discarded – undo
2326 2417
 		}
2327 2418
 
2328 2419
 		// Selected a recipient to be deleted? Remove them now.
2329
-		if (!empty($_POST['delete_recipient']))
2330
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2420
+		if (!empty($_POST['delete_recipient'])) {
2421
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2422
+		}
2331 2423
 
2332 2424
 		// Make sure we don't include the same name twice
2333 2425
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2337,8 +2429,9 @@  discard block
 block discarded – undo
2337 2429
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2338 2430
 
2339 2431
 	// Check if there's at least one recipient.
2340
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2341
-		$post_errors[] = 'no_to';
2432
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2433
+			$post_errors[] = 'no_to';
2434
+	}
2342 2435
 
2343 2436
 	// Make sure that we remove the members who did get it from the screen.
2344 2437
 	if (!$is_recipient_change)
@@ -2352,28 +2445,31 @@  discard block
 block discarded – undo
2352 2445
 				// Since we already have a post error, remove the previous one.
2353 2446
 				$post_errors = array_diff($post_errors, array('no_to'));
2354 2447
 
2355
-				foreach ($namesNotFound[$recipientType] as $name)
2356
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2448
+				foreach ($namesNotFound[$recipientType] as $name) {
2449
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2450
+				}
2357 2451
 			}
2358 2452
 		}
2359 2453
 	}
2360 2454
 
2361 2455
 	// Did they make any mistakes?
2362
-	if ($_REQUEST['subject'] == '')
2363
-		$post_errors[] = 'no_subject';
2364
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2365
-		$post_errors[] = 'no_message';
2366
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2367
-		$post_errors[] = 'long_message';
2368
-	else
2456
+	if ($_REQUEST['subject'] == '') {
2457
+			$post_errors[] = 'no_subject';
2458
+	}
2459
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2460
+			$post_errors[] = 'no_message';
2461
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2462
+			$post_errors[] = 'long_message';
2463
+	} else
2369 2464
 	{
2370 2465
 		// Preparse the message.
2371 2466
 		$message = $_REQUEST['message'];
2372 2467
 		preparsecode($message);
2373 2468
 
2374 2469
 		// Make sure there's still some content left without the tags.
2375
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2376
-			$post_errors[] = 'no_message';
2470
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2471
+					$post_errors[] = 'no_message';
2472
+		}
2377 2473
 	}
2378 2474
 
2379 2475
 	// Wrong verification code?
@@ -2385,13 +2481,15 @@  discard block
 block discarded – undo
2385 2481
 		);
2386 2482
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2387 2483
 
2388
-		if (is_array($context['require_verification']))
2389
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2484
+		if (is_array($context['require_verification'])) {
2485
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2486
+		}
2390 2487
 	}
2391 2488
 
2392 2489
 	// If they did, give a chance to make ammends.
2393
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2394
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2490
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2491
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2492
+	}
2395 2493
 
2396 2494
 	// Want to take a second glance before you send?
2397 2495
 	if (isset($_REQUEST['preview']))
@@ -2422,8 +2520,9 @@  discard block
 block discarded – undo
2422 2520
 		foreach ($namesNotFound as $recipientType => $names)
2423 2521
 		{
2424 2522
 			$post_errors[] = 'bad_' . $recipientType;
2425
-			foreach ($names as $name)
2426
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2523
+			foreach ($names as $name) {
2524
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2525
+			}
2427 2526
 		}
2428 2527
 
2429 2528
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2453,13 +2552,14 @@  discard block
 block discarded – undo
2453 2552
 	checkSubmitOnce('check');
2454 2553
 
2455 2554
 	// Do the actual sending of the PM.
2456
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2457
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2458
-	else
2459
-		$context['send_log'] = array(
2555
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2556
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2557
+	} else {
2558
+			$context['send_log'] = array(
2460 2559
 			'sent' => array(),
2461 2560
 			'failed' => array()
2462 2561
 		);
2562
+	}
2463 2563
 
2464 2564
 	// Mark the message as "replied to".
2465 2565
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2477,11 +2577,12 @@  discard block
 block discarded – undo
2477 2577
 	}
2478 2578
 
2479 2579
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2480
-	if (!empty($context['send_log']['failed']))
2481
-		return messagePostError($post_errors, $namesNotFound, array(
2580
+	if (!empty($context['send_log']['failed'])) {
2581
+			return messagePostError($post_errors, $namesNotFound, array(
2482 2582
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2483 2583
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2484 2584
 		));
2585
+	}
2485 2586
 
2486 2587
 	// Message sent successfully?
2487 2588
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2489,8 +2590,9 @@  discard block
 block discarded – undo
2489 2590
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2490 2591
 
2491 2592
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2492
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2493
-			DeleteDraft($_POST['id_pm_draft']);
2593
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2594
+					DeleteDraft($_POST['id_pm_draft']);
2595
+		}
2494 2596
 	}
2495 2597
 
2496 2598
 	// Go back to the where they sent from, if possible...
@@ -2505,24 +2607,28 @@  discard block
 block discarded – undo
2505 2607
 
2506 2608
 	checkSession('request');
2507 2609
 
2508
-	if (isset($_REQUEST['del_selected']))
2509
-		$_REQUEST['pm_action'] = 'delete';
2610
+	if (isset($_REQUEST['del_selected'])) {
2611
+			$_REQUEST['pm_action'] = 'delete';
2612
+	}
2510 2613
 
2511 2614
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2512 2615
 	{
2513
-		foreach ($_REQUEST['pms'] as $pm)
2514
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2616
+		foreach ($_REQUEST['pms'] as $pm) {
2617
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2618
+		}
2515 2619
 	}
2516 2620
 
2517
-	if (empty($_REQUEST['pm_actions']))
2518
-		redirectexit($context['current_label_redirect']);
2621
+	if (empty($_REQUEST['pm_actions'])) {
2622
+			redirectexit($context['current_label_redirect']);
2623
+	}
2519 2624
 
2520 2625
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2521 2626
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2522 2627
 	{
2523 2628
 		$id_pms = array();
2524
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2525
-			$id_pms[] = (int) $pm;
2629
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2630
+					$id_pms[] = (int) $pm;
2631
+		}
2526 2632
 
2527 2633
 		$request = $smcFunc['db_query']('', '
2528 2634
 			SELECT id_pm_head, id_pm
@@ -2533,8 +2639,9 @@  discard block
 block discarded – undo
2533 2639
 			)
2534 2640
 		);
2535 2641
 		$pm_heads = array();
2536
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2537
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2642
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2643
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2644
+		}
2538 2645
 		$smcFunc['db_free_result']($request);
2539 2646
 
2540 2647
 		$request = $smcFunc['db_query']('', '
@@ -2548,8 +2655,9 @@  discard block
 block discarded – undo
2548 2655
 		// Copy the action from the single to PM to the others.
2549 2656
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2550 2657
 		{
2551
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2552
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2658
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2659
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2660
+			}
2553 2661
 		}
2554 2662
 		$smcFunc['db_free_result']($request);
2555 2663
 	}
@@ -2561,22 +2669,21 @@  discard block
 block discarded – undo
2561 2669
 	$labels = array();
2562 2670
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2563 2671
 	{
2564
-		if ($action === 'delete')
2565
-			$to_delete[] = (int) $pm;
2566
-		else
2672
+		if ($action === 'delete') {
2673
+					$to_delete[] = (int) $pm;
2674
+		} else
2567 2675
 		{
2568 2676
 			if (substr($action, 0, 4) == 'add_')
2569 2677
 			{
2570 2678
 				$type = 'add';
2571 2679
 				$action = substr($action, 4);
2572
-			}
2573
-			elseif (substr($action, 0, 4) == 'rem_')
2680
+			} elseif (substr($action, 0, 4) == 'rem_')
2574 2681
 			{
2575 2682
 				$type = 'rem';
2576 2683
 				$action = substr($action, 4);
2684
+			} else {
2685
+							$type = 'unk';
2577 2686
 			}
2578
-			else
2579
-				$type = 'unk';
2580 2687
 
2581 2688
 			if ($action == '-1' || (int) $action > 0)
2582 2689
 			{
@@ -2587,8 +2694,9 @@  discard block
 block discarded – undo
2587 2694
 	}
2588 2695
 
2589 2696
 	// Deleting, it looks like?
2590
-	if (!empty($to_delete))
2591
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2697
+	if (!empty($to_delete)) {
2698
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2699
+	}
2592 2700
 
2593 2701
 	// Are we labeling anything?
2594 2702
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2656,8 +2764,7 @@  discard block
 block discarded – undo
2656 2764
 				}
2657 2765
 
2658 2766
 				$smcFunc['db_free_result']($request2);
2659
-			}
2660
-			elseif ($type == 'rem')
2767
+			} elseif ($type == 'rem')
2661 2768
 			{
2662 2769
 				// If we're removing from the inbox, see if we have at least one other label.
2663 2770
 				// This query is faster than the one above
@@ -2689,21 +2796,25 @@  discard block
 block discarded – undo
2689 2796
 			if ($to_label[$row['id_pm']] != '-1')
2690 2797
 			{
2691 2798
 				// If this label is in the list and we're not adding it, remove it
2692
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2693
-					unset($labels[$to_label[$row['id_pm']]]);
2694
-				else if ($type !== 'rem')
2695
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2799
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2800
+									unset($labels[$to_label[$row['id_pm']]]);
2801
+				} else if ($type !== 'rem') {
2802
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2803
+				}
2696 2804
 			}
2697 2805
 
2698 2806
 			// Removing all labels or just removing the inbox label
2699
-			if ($type == 'rem' && empty($labels))
2700
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2807
+			if ($type == 'rem' && empty($labels)) {
2808
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2809
+			}
2701 2810
 			// Adding new labels, but removing inbox and applying new ones
2702
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2703
-				$in_inbox = 0;
2811
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2812
+							$in_inbox = 0;
2813
+			}
2704 2814
 			// Just adding it to the inbox
2705
-			else
2706
-				$in_inbox = 1;
2815
+			else {
2816
+							$in_inbox = 1;
2817
+			}
2707 2818
 
2708 2819
 			// Are we adding it to or removing it from the inbox?
2709 2820
 			if ($in_inbox != $row['in_inbox'])
@@ -2745,8 +2856,9 @@  discard block
 block discarded – undo
2745 2856
 			if (!empty($labels_to_apply))
2746 2857
 			{
2747 2858
 				$inserts = array();
2748
-				foreach ($labels_to_apply as $label)
2749
-					$inserts[] = array($row['id_pm'], $label);
2859
+				foreach ($labels_to_apply as $label) {
2860
+									$inserts[] = array($row['id_pm'], $label);
2861
+				}
2750 2862
 
2751 2863
 				$smcFunc['db_insert']('',
2752 2864
 					'{db_prefix}pm_labeled_messages',
@@ -2790,11 +2902,13 @@  discard block
 block discarded – undo
2790 2902
 	checkSession('get');
2791 2903
 
2792 2904
 	// If all then delete all messages the user has.
2793
-	if ($_REQUEST['f'] == 'all')
2794
-		deleteMessages(null, null);
2905
+	if ($_REQUEST['f'] == 'all') {
2906
+			deleteMessages(null, null);
2907
+	}
2795 2908
 	// Otherwise just the selected folder.
2796
-	else
2797
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2909
+	else {
2910
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2911
+	}
2798 2912
 
2799 2913
 	// Done... all gone.
2800 2914
 	redirectexit($context['current_label_redirect']);
@@ -2831,8 +2945,9 @@  discard block
 block discarded – undo
2831 2945
 				'msgtime' => $deleteTime,
2832 2946
 			)
2833 2947
 		);
2834
-		while ($row = $smcFunc['db_fetch_row']($request))
2835
-			$toDelete[] = $row[0];
2948
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2949
+					$toDelete[] = $row[0];
2950
+		}
2836 2951
 		$smcFunc['db_free_result']($request);
2837 2952
 
2838 2953
 		// Select all messages in their inbox older than $deleteTime.
@@ -2849,8 +2964,9 @@  discard block
 block discarded – undo
2849 2964
 				'msgtime' => $deleteTime,
2850 2965
 			)
2851 2966
 		);
2852
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2853
-			$toDelete[] = $row['id_pm'];
2967
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2968
+					$toDelete[] = $row['id_pm'];
2969
+		}
2854 2970
 		$smcFunc['db_free_result']($request);
2855 2971
 
2856 2972
 		// Delete the actual messages.
@@ -2881,26 +2997,29 @@  discard block
 block discarded – undo
2881 2997
 {
2882 2998
 	global $user_info, $smcFunc;
2883 2999
 
2884
-	if ($owner === null)
2885
-		$owner = array($user_info['id']);
2886
-	elseif (empty($owner))
2887
-		return;
2888
-	elseif (!is_array($owner))
2889
-		$owner = array($owner);
3000
+	if ($owner === null) {
3001
+			$owner = array($user_info['id']);
3002
+	} elseif (empty($owner)) {
3003
+			return;
3004
+	} elseif (!is_array($owner)) {
3005
+			$owner = array($owner);
3006
+	}
2890 3007
 
2891 3008
 	if ($personal_messages !== null)
2892 3009
 	{
2893
-		if (empty($personal_messages) || !is_array($personal_messages))
2894
-			return;
3010
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3011
+					return;
3012
+		}
2895 3013
 
2896
-		foreach ($personal_messages as $index => $delete_id)
2897
-			$personal_messages[$index] = (int) $delete_id;
3014
+		foreach ($personal_messages as $index => $delete_id) {
3015
+					$personal_messages[$index] = (int) $delete_id;
3016
+		}
2898 3017
 
2899 3018
 		$where = '
2900 3019
 				AND id_pm IN ({array_int:pm_list})';
3020
+	} else {
3021
+			$where = '';
2901 3022
 	}
2902
-	else
2903
-		$where = '';
2904 3023
 
2905 3024
 	if ($folder == 'sent' || $folder === null)
2906 3025
 	{
@@ -2935,17 +3054,19 @@  discard block
 block discarded – undo
2935 3054
 		// ...And update the statistics accordingly - now including unread messages!.
2936 3055
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2937 3056
 		{
2938
-			if ($row['is_read'])
2939
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2940
-			else
2941
-				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']));
3057
+			if ($row['is_read']) {
3058
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3059
+			} else {
3060
+							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
+			}
2942 3062
 
2943 3063
 			// If this is the current member we need to make their message count correct.
2944 3064
 			if ($user_info['id'] == $row['id_member'])
2945 3065
 			{
2946 3066
 				$user_info['messages'] -= $row['num_deleted_messages'];
2947
-				if (!($row['is_read']))
2948
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3067
+				if (!($row['is_read'])) {
3068
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3069
+				}
2949 3070
 			}
2950 3071
 		}
2951 3072
 		$smcFunc['db_free_result']($request);
@@ -3013,8 +3134,9 @@  discard block
 block discarded – undo
3013 3134
 		)
3014 3135
 	);
3015 3136
 	$remove_pms = array();
3016
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3017
-		$remove_pms[] = $row['sender'];
3137
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3138
+			$remove_pms[] = $row['sender'];
3139
+	}
3018 3140
 	$smcFunc['db_free_result']($request);
3019 3141
 
3020 3142
 	if (!empty($remove_pms))
@@ -3059,8 +3181,9 @@  discard block
 block discarded – undo
3059 3181
 {
3060 3182
 	global $user_info, $context, $smcFunc;
3061 3183
 
3062
-	if ($owner === null)
3063
-		$owner = $user_info['id'];
3184
+	if ($owner === null) {
3185
+			$owner = $user_info['id'];
3186
+	}
3064 3187
 
3065 3188
 	$in_inbox = '';
3066 3189
 
@@ -3084,8 +3207,7 @@  discard block
 block discarded – undo
3084 3207
 		}
3085 3208
 
3086 3209
 		$smcFunc['db_free_result']($get_messages);
3087
-	}
3088
-	elseif ($label = '-1')
3210
+	} elseif ($label = '-1')
3089 3211
 	{
3090 3212
 		// Marking all PMs in your inbox read
3091 3213
 		$in_inbox = '
@@ -3110,8 +3232,9 @@  discard block
 block discarded – undo
3110 3232
 	{
3111 3233
 		if ($owner == $user_info['id'])
3112 3234
 		{
3113
-			foreach ($context['labels'] as $label)
3114
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3235
+			foreach ($context['labels'] as $label) {
3236
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3237
+			}
3115 3238
 		}
3116 3239
 
3117 3240
 		$result = $smcFunc['db_query']('', '
@@ -3131,8 +3254,9 @@  discard block
 block discarded – undo
3131 3254
 		{
3132 3255
 			$total_unread += $row['num'];
3133 3256
 
3134
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3135
-				continue;
3257
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3258
+							continue;
3259
+			}
3136 3260
 
3137 3261
 			$this_labels = array();
3138 3262
 
@@ -3156,11 +3280,13 @@  discard block
 block discarded – undo
3156 3280
 
3157 3281
 			$smcFunc['db_free_result']($result2);
3158 3282
 
3159
-			foreach ($this_labels as $this_label)
3160
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3283
+			foreach ($this_labels as $this_label) {
3284
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3285
+			}
3161 3286
 
3162
-			if ($row['in_inbox'] == 1)
3163
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3287
+			if ($row['in_inbox'] == 1) {
3288
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3289
+			}
3164 3290
 		}
3165 3291
 		$smcFunc['db_free_result']($result);
3166 3292
 
@@ -3169,8 +3295,9 @@  discard block
 block discarded – undo
3169 3295
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3170 3296
 
3171 3297
 		// If it was for the current member, reflect this in the $user_info array too.
3172
-		if ($owner == $user_info['id'])
3173
-			$user_info['unread_messages'] = $total_unread;
3298
+		if ($owner == $user_info['id']) {
3299
+					$user_info['unread_messages'] = $total_unread;
3300
+		}
3174 3301
 	}
3175 3302
 }
3176 3303
 
@@ -3198,8 +3325,9 @@  discard block
 block discarded – undo
3198 3325
 	// Add all existing labels to the array to save, slashing them as necessary...
3199 3326
 	foreach ($context['labels'] as $label)
3200 3327
 	{
3201
-		if ($label['id'] != -1)
3202
-			$the_labels[$label['id']] = $label['name'];
3328
+		if ($label['id'] != -1) {
3329
+					$the_labels[$label['id']] = $label['name'];
3330
+		}
3203 3331
 	}
3204 3332
 
3205 3333
 	if (isset($_POST[$context['session_var']]))
@@ -3218,8 +3346,9 @@  discard block
 block discarded – undo
3218 3346
 		{
3219 3347
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3220 3348
 
3221
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3222
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3349
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3350
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3351
+			}
3223 3352
 			if ($_POST['label'] != '')
3224 3353
 			{
3225 3354
 				$the_labels[] = $_POST['label'];
@@ -3240,24 +3369,25 @@  discard block
 block discarded – undo
3240 3369
 		{
3241 3370
 			foreach ($the_labels as $id => $name)
3242 3371
 			{
3243
-				if ($id == -1)
3244
-					continue;
3245
-				elseif (isset($_POST['label_name'][$id]))
3372
+				if ($id == -1) {
3373
+									continue;
3374
+				} elseif (isset($_POST['label_name'][$id]))
3246 3375
 				{
3247 3376
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3248 3377
 
3249
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3250
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3378
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3379
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3380
+					}
3251 3381
 					if ($_POST['label_name'][$id] != '')
3252 3382
 					{
3253 3383
 						// Changing the name of this label?
3254
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3255
-							$label_updates[$id] = $_POST['label_name'][$id];
3384
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3385
+													$label_updates[$id] = $_POST['label_name'][$id];
3386
+						}
3256 3387
 
3257 3388
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3258 3389
 
3259
-					}
3260
-					else
3390
+					} else
3261 3391
 					{
3262 3392
 						unset($the_labels[(int) $id]);
3263 3393
 						$labels_to_remove[] = $id;
@@ -3271,8 +3401,9 @@  discard block
 block discarded – undo
3271 3401
 		if (!empty($labels_to_add))
3272 3402
 		{
3273 3403
 			$inserts = array();
3274
-			foreach ($labels_to_add AS $label)
3275
-				$inserts[] = array($user_info['id'], $label);
3404
+			foreach ($labels_to_add AS $label) {
3405
+							$inserts[] = array($user_info['id'], $label);
3406
+			}
3276 3407
 
3277 3408
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3278 3409
 		}
@@ -3362,8 +3493,9 @@  discard block
 block discarded – undo
3362 3493
 				// Each action...
3363 3494
 				foreach ($rule['actions'] as $k2 => $action)
3364 3495
 				{
3365
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3366
-						continue;
3496
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3497
+											continue;
3498
+					}
3367 3499
 
3368 3500
 					$rule_changes[] = $rule['id'];
3369 3501
 
@@ -3378,8 +3510,8 @@  discard block
 block discarded – undo
3378 3510
 		{
3379 3511
 			$rule_changes = array_unique($rule_changes);
3380 3512
 			// Update/delete as appropriate.
3381
-			foreach ($rule_changes as $k => $id)
3382
-				if (!empty($context['rules'][$id]['actions']))
3513
+			foreach ($rule_changes as $k => $id) {
3514
+							if (!empty($context['rules'][$id]['actions']))
3383 3515
 				{
3384 3516
 					$smcFunc['db_query']('', '
3385 3517
 						UPDATE {db_prefix}pm_rules
@@ -3392,12 +3524,13 @@  discard block
 block discarded – undo
3392 3524
 							'actions' => json_encode($context['rules'][$id]['actions']),
3393 3525
 						)
3394 3526
 					);
3527
+			}
3395 3528
 					unset($rule_changes[$k]);
3396 3529
 				}
3397 3530
 
3398 3531
 			// Anything left here means it's lost all actions...
3399
-			if (!empty($rule_changes))
3400
-				$smcFunc['db_query']('', '
3532
+			if (!empty($rule_changes)) {
3533
+							$smcFunc['db_query']('', '
3401 3534
 					DELETE FROM {db_prefix}pm_rules
3402 3535
 					WHERE id_rule IN ({array_int:rule_list})
3403 3536
 							AND id_member = {int:current_member}',
@@ -3406,6 +3539,7 @@  discard block
 block discarded – undo
3406 3539
 						'rule_list' => $rule_changes,
3407 3540
 					)
3408 3541
 				);
3542
+			}
3409 3543
 		}
3410 3544
 
3411 3545
 		// Make sure we're not caching this!
@@ -3475,8 +3609,9 @@  discard block
 block discarded – undo
3475 3609
 		// Save the fields.
3476 3610
 		saveProfileFields();
3477 3611
 
3478
-		if (!empty($profile_vars))
3479
-			updateMemberData($user_info['id'], $profile_vars);
3612
+		if (!empty($profile_vars)) {
3613
+					updateMemberData($user_info['id'], $profile_vars);
3614
+		}
3480 3615
 	}
3481 3616
 
3482 3617
 	setupProfileContext(
@@ -3501,13 +3636,15 @@  discard block
 block discarded – undo
3501 3636
 	global $user_info, $language, $modSettings, $smcFunc;
3502 3637
 
3503 3638
 	// Check that this feature is even enabled!
3504
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3505
-		fatal_lang_error('no_access', false);
3639
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3640
+			fatal_lang_error('no_access', false);
3641
+	}
3506 3642
 
3507 3643
 	$pmsg = (int) $_REQUEST['pmsg'];
3508 3644
 
3509
-	if (!isAccessiblePM($pmsg, 'inbox'))
3510
-		fatal_lang_error('no_access', false);
3645
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3646
+			fatal_lang_error('no_access', false);
3647
+	}
3511 3648
 
3512 3649
 	$context['pm_id'] = $pmsg;
3513 3650
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3529,8 +3666,9 @@  discard block
 block discarded – undo
3529 3666
 			)
3530 3667
 		);
3531 3668
 		$context['admins'] = array();
3532
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3533
-			$context['admins'][$row['id_member']] = $row['real_name'];
3669
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3670
+					$context['admins'][$row['id_member']] = $row['real_name'];
3671
+		}
3534 3672
 		$smcFunc['db_free_result']($request);
3535 3673
 
3536 3674
 		// How many admins in total?
@@ -3559,8 +3697,9 @@  discard block
 block discarded – undo
3559 3697
 			)
3560 3698
 		);
3561 3699
 		// Can only be a hacker here!
3562
-		if ($smcFunc['db_num_rows']($request) == 0)
3563
-			fatal_lang_error('no_access', false);
3700
+		if ($smcFunc['db_num_rows']($request) == 0) {
3701
+					fatal_lang_error('no_access', false);
3702
+		}
3564 3703
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3565 3704
 		$smcFunc['db_free_result']($request);
3566 3705
 
@@ -3584,15 +3723,17 @@  discard block
 block discarded – undo
3584 3723
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3585 3724
 		{
3586 3725
 			// If it's hidden still don't reveal their names - privacy after all ;)
3587
-			if ($row['bcc'])
3588
-				$hidden_recipients++;
3589
-			else
3590
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3726
+			if ($row['bcc']) {
3727
+							$hidden_recipients++;
3728
+			} else {
3729
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3730
+			}
3591 3731
 		}
3592 3732
 		$smcFunc['db_free_result']($request);
3593 3733
 
3594
-		if ($hidden_recipients)
3595
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3734
+		if ($hidden_recipients) {
3735
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3736
+		}
3596 3737
 
3597 3738
 		// Now let's get out and loop through the admins.
3598 3739
 		$request = $smcFunc['db_query']('', '
@@ -3608,8 +3749,9 @@  discard block
 block discarded – undo
3608 3749
 		);
3609 3750
 
3610 3751
 		// Maybe we shouldn't advertise this?
3611
-		if ($smcFunc['db_num_rows']($request) == 0)
3612
-			fatal_lang_error('no_access', false);
3752
+		if ($smcFunc['db_num_rows']($request) == 0) {
3753
+					fatal_lang_error('no_access', false);
3754
+		}
3613 3755
 
3614 3756
 		$memberFromName = un_htmlspecialchars($memberFromName);
3615 3757
 
@@ -3628,8 +3770,9 @@  discard block
 block discarded – undo
3628 3770
 				// Make the body.
3629 3771
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3630 3772
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3631
-				if (!empty($recipients))
3632
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3773
+				if (!empty($recipients)) {
3774
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3775
+				}
3633 3776
 				$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]';
3634 3777
 
3635 3778
 				// Plonk it in the array ;)
@@ -3649,12 +3792,14 @@  discard block
 block discarded – undo
3649 3792
 		$smcFunc['db_free_result']($request);
3650 3793
 
3651 3794
 		// Send a different email for each language.
3652
-		foreach ($messagesToSend as $lang => $message)
3653
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3795
+		foreach ($messagesToSend as $lang => $message) {
3796
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3797
+		}
3654 3798
 
3655 3799
 		// Give the user their own language back!
3656
-		if (!empty($modSettings['userLanguage']))
3657
-			loadLanguage('PersonalMessage', '', false);
3800
+		if (!empty($modSettings['userLanguage'])) {
3801
+					loadLanguage('PersonalMessage', '', false);
3802
+		}
3658 3803
 
3659 3804
 		// Leave them with a template.
3660 3805
 		$context['sub_template'] = 'report_message_complete';
@@ -3700,8 +3845,9 @@  discard block
 block discarded – undo
3700 3845
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3701 3846
 	{
3702 3847
 		// Hide hidden groups!
3703
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3704
-			continue;
3848
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3849
+					continue;
3850
+		}
3705 3851
 
3706 3852
 		$context['groups'][$row['id_group']] = $row['group_name'];
3707 3853
 	}
@@ -3727,9 +3873,10 @@  discard block
 block discarded – undo
3727 3873
 			$context['rule'] = $context['rules'][$context['rid']];
3728 3874
 			$members = array();
3729 3875
 			// Need to get member names!
3730
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3731
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3876
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3877
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3732 3878
 					$members[(int) $criteria['v']] = $k;
3879
+			}
3733 3880
 
3734 3881
 			if (!empty($members))
3735 3882
 			{
@@ -3741,19 +3888,20 @@  discard block
 block discarded – undo
3741 3888
 						'member_list' => array_keys($members),
3742 3889
 					)
3743 3890
 				);
3744
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3745
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3891
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3892
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3893
+				}
3746 3894
 				$smcFunc['db_free_result']($request);
3747 3895
 			}
3748
-		}
3749
-		else
3750
-			$context['rule'] = array(
3896
+		} else {
3897
+					$context['rule'] = array(
3751 3898
 				'id' => '',
3752 3899
 				'name' => '',
3753 3900
 				'criteria' => array(),
3754 3901
 				'actions' => array(),
3755 3902
 				'logic' => 'and',
3756 3903
 			);
3904
+		}
3757 3905
 	}
3758 3906
 	// Saving?
3759 3907
 	elseif (isset($_GET['save']))
@@ -3763,22 +3911,25 @@  discard block
 block discarded – undo
3763 3911
 
3764 3912
 		// Name is easy!
3765 3913
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3766
-		if (empty($ruleName))
3767
-			fatal_lang_error('pm_rule_no_name', false);
3914
+		if (empty($ruleName)) {
3915
+					fatal_lang_error('pm_rule_no_name', false);
3916
+		}
3768 3917
 
3769 3918
 		// Sanity check...
3770
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3771
-			fatal_lang_error('pm_rule_no_criteria', false);
3919
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3920
+					fatal_lang_error('pm_rule_no_criteria', false);
3921
+		}
3772 3922
 
3773 3923
 		// Let's do the criteria first - it's also hardest!
3774 3924
 		$criteria = array();
3775 3925
 		foreach ($_POST['ruletype'] as $ind => $type)
3776 3926
 		{
3777 3927
 			// Check everything is here...
3778
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3779
-				continue;
3780
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3781
-				continue;
3928
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3929
+							continue;
3930
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3931
+							continue;
3932
+			}
3782 3933
 
3783 3934
 			// Members need to be found.
3784 3935
 			if ($type == 'mid')
@@ -3802,13 +3953,13 @@  discard block
 block discarded – undo
3802 3953
 				$smcFunc['db_free_result']($request);
3803 3954
 
3804 3955
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3956
+			} elseif ($type == 'bud') {
3957
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3958
+			} elseif ($type == 'gid') {
3959
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3960
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3961
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3805 3962
 			}
3806
-			elseif ($type == 'bud')
3807
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3808
-			elseif ($type == 'gid')
3809
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3810
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3811
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3812 3963
 		}
3813 3964
 
3814 3965
 		// Also do the actions!
@@ -3818,26 +3969,29 @@  discard block
 block discarded – undo
3818 3969
 		foreach ($_POST['acttype'] as $ind => $type)
3819 3970
 		{
3820 3971
 			// Picking a valid label?
3821
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3822
-				continue;
3972
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3973
+							continue;
3974
+			}
3823 3975
 
3824 3976
 			// Record what we're doing.
3825
-			if ($type == 'del')
3826
-				$doDelete = 1;
3827
-			elseif ($type == 'lab')
3828
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3977
+			if ($type == 'del') {
3978
+							$doDelete = 1;
3979
+			} elseif ($type == 'lab') {
3980
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3981
+			}
3829 3982
 		}
3830 3983
 
3831
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3832
-			fatal_lang_error('pm_rule_no_criteria', false);
3984
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3985
+					fatal_lang_error('pm_rule_no_criteria', false);
3986
+		}
3833 3987
 
3834 3988
 		// What are we storing?
3835 3989
 		$criteria = json_encode($criteria);
3836 3990
 		$actions = json_encode($actions);
3837 3991
 
3838 3992
 		// Create the rule?
3839
-		if (empty($context['rid']))
3840
-			$smcFunc['db_insert']('',
3993
+		if (empty($context['rid'])) {
3994
+					$smcFunc['db_insert']('',
3841 3995
 				'{db_prefix}pm_rules',
3842 3996
 				array(
3843 3997
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3848,8 +4002,8 @@  discard block
 block discarded – undo
3848 4002
 				),
3849 4003
 				array('id_rule')
3850 4004
 			);
3851
-		else
3852
-			$smcFunc['db_query']('', '
4005
+		} else {
4006
+					$smcFunc['db_query']('', '
3853 4007
 				UPDATE {db_prefix}pm_rules
3854 4008
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3855 4009
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3865,6 +4019,7 @@  discard block
 block discarded – undo
3865 4019
 					'actions' => $actions,
3866 4020
 				)
3867 4021
 			);
4022
+		}
3868 4023
 
3869 4024
 		redirectexit('action=pm;sa=manrules');
3870 4025
 	}
@@ -3873,11 +4028,12 @@  discard block
 block discarded – undo
3873 4028
 	{
3874 4029
 		checkSession();
3875 4030
 		$toDelete = array();
3876
-		foreach ($_POST['delrule'] as $k => $v)
3877
-			$toDelete[] = (int) $k;
4031
+		foreach ($_POST['delrule'] as $k => $v) {
4032
+					$toDelete[] = (int) $k;
4033
+		}
3878 4034
 
3879
-		if (!empty($toDelete))
3880
-			$smcFunc['db_query']('', '
4035
+		if (!empty($toDelete)) {
4036
+					$smcFunc['db_query']('', '
3881 4037
 				DELETE FROM {db_prefix}pm_rules
3882 4038
 				WHERE id_rule IN ({array_int:delete_list})
3883 4039
 					AND id_member = {int:current_member}',
@@ -3886,6 +4042,7 @@  discard block
 block discarded – undo
3886 4042
 					'delete_list' => $toDelete,
3887 4043
 				)
3888 4044
 			);
4045
+		}
3889 4046
 
3890 4047
 		redirectexit('action=pm;sa=manrules');
3891 4048
 	}
@@ -3904,8 +4061,9 @@  discard block
 block discarded – undo
3904 4061
 	loadRules();
3905 4062
 
3906 4063
 	// No rules?
3907
-	if (empty($context['rules']))
3908
-		return;
4064
+	if (empty($context['rules'])) {
4065
+			return;
4066
+	}
3909 4067
 
3910 4068
 	// Just unread ones?
3911 4069
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3935,8 +4093,9 @@  discard block
 block discarded – undo
3935 4093
 			// Loop through all the criteria hoping to make a match.
3936 4094
 			foreach ($rule['criteria'] as $criterium)
3937 4095
 			{
3938
-				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))
3939
-					$match = true;
4096
+				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)) {
4097
+									$match = true;
4098
+				}
3940 4099
 				// If we're adding and one criteria don't match then we stop!
3941 4100
 				elseif ($rule['logic'] == 'and')
3942 4101
 				{
@@ -3948,17 +4107,18 @@  discard block
 block discarded – undo
3948 4107
 			// If we have a match the rule must be true - act!
3949 4108
 			if ($match)
3950 4109
 			{
3951
-				if ($rule['delete'])
3952
-					$actions['deletes'][] = $row['id_pm'];
3953
-				else
4110
+				if ($rule['delete']) {
4111
+									$actions['deletes'][] = $row['id_pm'];
4112
+				} else
3954 4113
 				{
3955 4114
 					foreach ($rule['actions'] as $ruleAction)
3956 4115
 					{
3957 4116
 						if ($ruleAction['t'] == 'lab')
3958 4117
 						{
3959 4118
 							// Get a basic pot started!
3960
-							if (!isset($actions['labels'][$row['id_pm']]))
3961
-								$actions['labels'][$row['id_pm']] = array();
4119
+							if (!isset($actions['labels'][$row['id_pm']])) {
4120
+															$actions['labels'][$row['id_pm']] = array();
4121
+							}
3962 4122
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3963 4123
 						}
3964 4124
 					}
@@ -3969,8 +4129,9 @@  discard block
 block discarded – undo
3969 4129
 	$smcFunc['db_free_result']($request);
3970 4130
 
3971 4131
 	// Deletes are easy!
3972
-	if (!empty($actions['deletes']))
3973
-		deleteMessages($actions['deletes']);
4132
+	if (!empty($actions['deletes'])) {
4133
+			deleteMessages($actions['deletes']);
4134
+	}
3974 4135
 
3975 4136
 	// Relabel?
3976 4137
 	if (!empty($actions['labels']))
@@ -3997,8 +4158,7 @@  discard block
 block discarded – undo
3997 4158
 								'current_member' => $user_info['id'],
3998 4159
 							)
3999 4160
 						);
4000
-					}
4001
-					else
4161
+					} else
4002 4162
 					{
4003 4163
 						$realLabels[] = $label['id'];
4004 4164
 					}
@@ -4007,8 +4167,9 @@  discard block
 block discarded – undo
4007 4167
 
4008 4168
 			$inserts = array();
4009 4169
 			// Now we insert the label info
4010
-			foreach ($realLabels as $a_label)
4011
-				$inserts[] = array($pm, $a_label);
4170
+			foreach ($realLabels as $a_label) {
4171
+							$inserts[] = array($pm, $a_label);
4172
+			}
4012 4173
 
4013 4174
 			$smcFunc['db_insert']('ignore',
4014 4175
 				'{db_prefix}pm_labeled_messages',
@@ -4029,8 +4190,9 @@  discard block
 block discarded – undo
4029 4190
 {
4030 4191
 	global $user_info, $context, $smcFunc;
4031 4192
 
4032
-	if (isset($context['rules']) && !$reload)
4033
-		return;
4193
+	if (isset($context['rules']) && !$reload) {
4194
+			return;
4195
+	}
4034 4196
 
4035 4197
 	$request = $smcFunc['db_query']('', '
4036 4198
 		SELECT
@@ -4054,8 +4216,9 @@  discard block
 block discarded – undo
4054 4216
 			'logic' => $row['is_or'] ? 'or' : 'and',
4055 4217
 		);
4056 4218
 
4057
-		if ($row['delete_pm'])
4058
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4219
+		if ($row['delete_pm']) {
4220
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4221
+		}
4059 4222
 	}
4060 4223
 	$smcFunc['db_free_result']($request);
4061 4224
 }
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" style="margin-left: 4ex;">[<a href="' . $scripturl . '?action=helpadmin;help=secret_why_blank" onclick="return reqOverlayDiv(this.href);">' . $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_other',
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_other',
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_other_any', 'profile_other_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_other_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('default_theme' => true, 'defer' => false), 'smf_spellcheck');
3079
+	if ($context['show_spellchecking']) {
3080
+			loadJavascriptFile('spellcheck.js', array('default_theme' => true, '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,16 +4257,15 @@  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
 ?>
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
@@ -2610,7 +2610,7 @@
 block discarded – undo
2610 2610
  * @param int $start Which item to start with (for pagination purposes)
2611 2611
  * @param int $items_per_page How many items to show on each page
2612 2612
  * @param string $sort A string indicating how to sort the results
2613
- * @param int $memID The ID of the member
2613
+ * @param string $memID The ID of the member
2614 2614
  * @return array An array of information about the user's group requests
2615 2615
  */
2616 2616
 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']) ? @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.
@@ -1672,8 +1723,9 @@  discard block
 block discarded – undo
1672 1723
 			)
1673 1724
 		);
1674 1725
 		$message_members = array();
1675
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1676
-			$message_members[] = $row['id_member'];
1726
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1727
+					$message_members[] = $row['id_member'];
1728
+		}
1677 1729
 		$smcFunc['db_free_result']($request);
1678 1730
 
1679 1731
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1688,8 +1740,9 @@  discard block
 block discarded – undo
1688 1740
 					'ip_list' => $ips,
1689 1741
 				)
1690 1742
 			);
1691
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1692
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1743
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1744
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1745
+			}
1693 1746
 			$smcFunc['db_free_result']($request);
1694 1747
 		}
1695 1748
 
@@ -1703,8 +1756,9 @@  discard block
 block discarded – undo
1703 1756
 				'ip_list' => $ips,
1704 1757
 			)
1705 1758
 		);
1706
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1707
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1759
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1760
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1761
+		}
1708 1762
 		$smcFunc['db_free_result']($request);
1709 1763
 	}
1710 1764
 }
@@ -1764,8 +1818,8 @@  discard block
 block discarded – undo
1764 1818
 		))
1765 1819
 	);
1766 1820
 	$error_messages = array();
1767
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1768
-		$error_messages[] = array(
1821
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1822
+			$error_messages[] = array(
1769 1823
 			'ip' => $row['ip'],
1770 1824
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1771 1825
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1773,6 +1827,7 @@  discard block
 block discarded – undo
1773 1827
 			'time' => timeformat($row['log_time']),
1774 1828
 			'timestamp' => forum_time(true, $row['log_time']),
1775 1829
 		);
1830
+	}
1776 1831
 	$smcFunc['db_free_result']($request);
1777 1832
 
1778 1833
 	return $error_messages;
@@ -1835,8 +1890,8 @@  discard block
 block discarded – undo
1835 1890
 		))
1836 1891
 	);
1837 1892
 	$messages = array();
1838
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1839
-		$messages[] = array(
1893
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1894
+			$messages[] = array(
1840 1895
 			'ip' => $row['poster_ip'],
1841 1896
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1842 1897
 			'board' => array(
@@ -1849,6 +1904,7 @@  discard block
 block discarded – undo
1849 1904
 			'time' => timeformat($row['poster_time']),
1850 1905
 			'timestamp' => forum_time(true, $row['poster_time'])
1851 1906
 		);
1907
+	}
1852 1908
 	$smcFunc['db_free_result']($request);
1853 1909
 
1854 1910
 	return $messages;
@@ -1875,25 +1931,27 @@  discard block
 block discarded – undo
1875 1931
 		$context['sub_template'] = 'trackIP';
1876 1932
 		$context['page_title'] = $txt['profile'];
1877 1933
 		$context['base_url'] = $scripturl . '?action=trackip';
1878
-	}
1879
-	else
1934
+	} else
1880 1935
 	{
1881 1936
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1882 1937
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1883 1938
 	}
1884 1939
 
1885 1940
 	// Searching?
1886
-	if (isset($_REQUEST['searchip']))
1887
-		$context['ip'] = trim($_REQUEST['searchip']);
1941
+	if (isset($_REQUEST['searchip'])) {
1942
+			$context['ip'] = trim($_REQUEST['searchip']);
1943
+	}
1888 1944
 
1889
-	if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
1890
-		fatal_lang_error('invalid_tracking_ip', false);
1945
+	if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false) {
1946
+			fatal_lang_error('invalid_tracking_ip', false);
1947
+	}
1891 1948
 
1892 1949
 	$ip_var = str_replace('*', '%', $context['ip']);
1893 1950
 	$ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
1894 1951
 
1895
-	if (empty($context['tracking_area']))
1896
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1952
+	if (empty($context['tracking_area'])) {
1953
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1954
+	}
1897 1955
 
1898 1956
 	$request = $smcFunc['db_query']('', '
1899 1957
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1904,8 +1962,9 @@  discard block
 block discarded – undo
1904 1962
 		)
1905 1963
 	);
1906 1964
 	$context['ips'] = array();
1907
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1908
-		$context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1965
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1966
+			$context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1967
+	}
1909 1968
 	$smcFunc['db_free_result']($request);
1910 1969
 
1911 1970
 	ksort($context['ips']);
@@ -2138,8 +2197,9 @@  discard block
 block discarded – undo
2138 2197
 		foreach ($context['whois_servers'] as $whois)
2139 2198
 		{
2140 2199
 			// Strip off the "decimal point" and anything following...
2141
-			if (in_array((int) $context['ip'], $whois['range']))
2142
-				$context['auto_whois_server'] = $whois;
2200
+			if (in_array((int) $context['ip'], $whois['range'])) {
2201
+							$context['auto_whois_server'] = $whois;
2202
+			}
2143 2203
 		}
2144 2204
 	}
2145 2205
 }
@@ -2156,10 +2216,11 @@  discard block
 block discarded – undo
2156 2216
 	// Gonna want this for the list.
2157 2217
 	require_once($sourcedir . '/Subs-List.php');
2158 2218
 
2159
-	if ($memID == 0)
2160
-		$context['base_url'] = $scripturl . '?action=trackip';
2161
-	else
2162
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2219
+	if ($memID == 0) {
2220
+			$context['base_url'] = $scripturl . '?action=trackip';
2221
+	} else {
2222
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2223
+	}
2163 2224
 
2164 2225
 	// Start with the user messages.
2165 2226
 	$listOptions = array(
@@ -2271,12 +2332,13 @@  discard block
 block discarded – undo
2271 2332
 		)
2272 2333
 	);
2273 2334
 	$logins = array();
2274
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2275
-		$logins[] = array(
2335
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2336
+			$logins[] = array(
2276 2337
 			'time' => timeformat($row['time']),
2277 2338
 			'ip' => $row['ip'],
2278 2339
 			'ip2' => $row['ip2'],
2279 2340
 		);
2341
+	}
2280 2342
 	$smcFunc['db_free_result']($request);
2281 2343
 
2282 2344
 	return $logins;
@@ -2301,11 +2363,12 @@  discard block
 block discarded – undo
2301 2363
 		)
2302 2364
 	);
2303 2365
 	$context['custom_field_titles'] = array();
2304
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2305
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2366
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2367
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2306 2368
 			'title' => $row['field_name'],
2307 2369
 			'parse_bbc' => $row['bbc'],
2308 2370
 		);
2371
+	}
2309 2372
 	$smcFunc['db_free_result']($request);
2310 2373
 
2311 2374
 	// Set the options for the error lists.
@@ -2444,19 +2507,22 @@  discard block
 block discarded – undo
2444 2507
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2445 2508
 	{
2446 2509
 		$extra = @json_decode($row['extra'], true);
2447
-		if (!empty($extra['applicator']))
2448
-			$members[] = $extra['applicator'];
2510
+		if (!empty($extra['applicator'])) {
2511
+					$members[] = $extra['applicator'];
2512
+		}
2449 2513
 
2450 2514
 		// Work out what the name of the action is.
2451
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2452
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2453
-		elseif (isset($txt[$row['action']]))
2454
-			$action_text = $txt[$row['action']];
2515
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2516
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2517
+		} elseif (isset($txt[$row['action']])) {
2518
+					$action_text = $txt[$row['action']];
2519
+		}
2455 2520
 		// Custom field?
2456
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2457
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2458
-		else
2459
-			$action_text = $row['action'];
2521
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2522
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2523
+		} else {
2524
+					$action_text = $row['action'];
2525
+		}
2460 2526
 
2461 2527
 		// Parse BBC?
2462 2528
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2488,13 +2554,15 @@  discard block
 block discarded – undo
2488 2554
 			)
2489 2555
 		);
2490 2556
 		$members = array();
2491
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2492
-			$members[$row['id_member']] = $row['real_name'];
2557
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2558
+					$members[$row['id_member']] = $row['real_name'];
2559
+		}
2493 2560
 		$smcFunc['db_free_result']($request);
2494 2561
 
2495
-		foreach ($edits as $key => $value)
2496
-			if (isset($members[$value['id_member']]))
2562
+		foreach ($edits as $key => $value) {
2563
+					if (isset($members[$value['id_member']]))
2497 2564
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2565
+		}
2498 2566
 	}
2499 2567
 
2500 2568
 	return $edits;
@@ -2695,10 +2763,11 @@  discard block
 block discarded – undo
2695 2763
 	$context['board'] = $board;
2696 2764
 
2697 2765
 	// Determine which groups this user is in.
2698
-	if (empty($user_profile[$memID]['additional_groups']))
2699
-		$curGroups = array();
2700
-	else
2701
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2766
+	if (empty($user_profile[$memID]['additional_groups'])) {
2767
+			$curGroups = array();
2768
+	} else {
2769
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2770
+	}
2702 2771
 	$curGroups[] = $user_profile[$memID]['id_group'];
2703 2772
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2704 2773
 
@@ -2718,28 +2787,30 @@  discard block
 block discarded – undo
2718 2787
 	$context['no_access_boards'] = array();
2719 2788
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2720 2789
 	{
2721
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2722
-			$context['no_access_boards'][] = array(
2790
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2791
+					$context['no_access_boards'][] = array(
2723 2792
 				'id' => $row['id_board'],
2724 2793
 				'name' => $row['name'],
2725 2794
 				'is_last' => false,
2726 2795
 			);
2727
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2728
-			$context['boards'][$row['id_board']] = array(
2796
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2797
+					$context['boards'][$row['id_board']] = array(
2729 2798
 				'id' => $row['id_board'],
2730 2799
 				'name' => $row['name'],
2731 2800
 				'selected' => $board == $row['id_board'],
2732 2801
 				'profile' => $row['id_profile'],
2733 2802
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2734 2803
 			);
2804
+		}
2735 2805
 	}
2736 2806
 	$smcFunc['db_free_result']($request);
2737 2807
 
2738 2808
 	require_once($sourcedir . '/Subs-Boards.php');
2739 2809
 	sortBoards($context['boards']);
2740 2810
 
2741
-	if (!empty($context['no_access_boards']))
2742
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2811
+	if (!empty($context['no_access_boards'])) {
2812
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2813
+	}
2743 2814
 
2744 2815
 	$context['member']['permissions'] = array(
2745 2816
 		'general' => array(),
@@ -2748,8 +2819,9 @@  discard block
 block discarded – undo
2748 2819
 
2749 2820
 	// If you're an admin we know you can do everything, we might as well leave.
2750 2821
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2751
-	if ($context['member']['has_all_permissions'])
2752
-		return;
2822
+	if ($context['member']['has_all_permissions']) {
2823
+			return;
2824
+	}
2753 2825
 
2754 2826
 	$denied = array();
2755 2827
 
@@ -2768,21 +2840,24 @@  discard block
 block discarded – undo
2768 2840
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2769 2841
 	{
2770 2842
 		// We don't know about this permission, it doesn't exist :P.
2771
-		if (!isset($txt['permissionname_' . $row['permission']]))
2772
-			continue;
2843
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2844
+					continue;
2845
+		}
2773 2846
 
2774
-		if (empty($row['add_deny']))
2775
-			$denied[] = $row['permission'];
2847
+		if (empty($row['add_deny'])) {
2848
+					$denied[] = $row['permission'];
2849
+		}
2776 2850
 
2777 2851
 		// Permissions that end with _own or _any consist of two parts.
2778
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2779
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2780
-		else
2781
-			$name = $txt['permissionname_' . $row['permission']];
2852
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2853
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2854
+		} else {
2855
+					$name = $txt['permissionname_' . $row['permission']];
2856
+		}
2782 2857
 
2783 2858
 		// Add this permission if it doesn't exist yet.
2784
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2785
-			$context['member']['permissions']['general'][$row['permission']] = array(
2859
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2860
+					$context['member']['permissions']['general'][$row['permission']] = array(
2786 2861
 				'id' => $row['permission'],
2787 2862
 				'groups' => array(
2788 2863
 					'allowed' => array(),
@@ -2792,6 +2867,7 @@  discard block
 block discarded – undo
2792 2867
 				'is_denied' => false,
2793 2868
 				'is_global' => true,
2794 2869
 			);
2870
+		}
2795 2871
 
2796 2872
 		// Add the membergroup to either the denied or the allowed groups.
2797 2873
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2825,18 +2901,20 @@  discard block
 block discarded – undo
2825 2901
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2826 2902
 	{
2827 2903
 		// We don't know about this permission, it doesn't exist :P.
2828
-		if (!isset($txt['permissionname_' . $row['permission']]))
2829
-			continue;
2904
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2905
+					continue;
2906
+		}
2830 2907
 
2831 2908
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2832
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2833
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2834
-		else
2835
-			$name = $txt['permissionname_' . $row['permission']];
2909
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2910
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2911
+		} else {
2912
+					$name = $txt['permissionname_' . $row['permission']];
2913
+		}
2836 2914
 
2837 2915
 		// Create the structure for this permission.
2838
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2839
-			$context['member']['permissions']['board'][$row['permission']] = array(
2916
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2917
+					$context['member']['permissions']['board'][$row['permission']] = array(
2840 2918
 				'id' => $row['permission'],
2841 2919
 				'groups' => array(
2842 2920
 					'allowed' => array(),
@@ -2846,6 +2924,7 @@  discard block
 block discarded – undo
2846 2924
 				'is_denied' => false,
2847 2925
 				'is_global' => empty($board),
2848 2926
 			);
2927
+		}
2849 2928
 
2850 2929
 		$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'];
2851 2930
 
@@ -2864,8 +2943,9 @@  discard block
 block discarded – undo
2864 2943
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2865 2944
 
2866 2945
 	// Firstly, can we actually even be here?
2867
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2868
-		fatal_lang_error('no_access', false);
2946
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2947
+			fatal_lang_error('no_access', false);
2948
+	}
2869 2949
 
2870 2950
 	// Make sure things which are disabled stay disabled.
2871 2951
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2952,9 +3032,10 @@  discard block
 block discarded – undo
2952 3032
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2953 3033
 	);
2954 3034
 	$context['current_level'] = 0;
2955
-	foreach ($context['level_effects'] as $limit => $dummy)
2956
-		if ($context['member']['warning'] >= $limit)
3035
+	foreach ($context['level_effects'] as $limit => $dummy) {
3036
+			if ($context['member']['warning'] >= $limit)
2957 3037
 			$context['current_level'] = $limit;
2958
-}
3038
+	}
3039
+	}
2959 3040
 
2960 3041
 ?>
2961 3042
\ 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
@@ -321,7 +321,7 @@
 block discarded – undo
321 321
  * Validates a IPv6 address. returns true if it is ipv6.
322 322
  *
323 323
  * @param string $ip The ip address to be validated
324
- * @return boolean Whether the specified IP is a valid IPv6 address
324
+ * @return false|string Whether the specified IP is a valid IPv6 address
325 325
  */
326 326
 function isValidIPv6($ip)
327 327
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -422,8 +422,8 @@
 block discarded – undo
422 422
 */
423 423
 function matchIPtoCIDR($ip_address, $cidr_address)
424 424
 {
425
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
426
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
425
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
426
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
427 427
 }
428 428
 
429 429
 /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 function isValidIPv6($ip)
327 327
 {
328 328
 	//looking for :
329
-	if (strpos($ip , ':') === false )
329
+	if (strpos($ip, ':') === false)
330 330
 		return false;
331 331
 	
332 332
 	//check valid address
@@ -658,15 +658,15 @@  discard block
 block discarded – undo
658 658
 	{
659 659
 		// Let's do something special for session ids!
660 660
 		if (defined('SID') && SID != '')
661
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
661
+			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
662 662
 			{
663 663
 				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
664 664
 			}, $buffer);
665 665
 		else
666
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
666
+			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
667 667
 			{
668 668
 				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
669
-			}, $buffer );
669
+			}, $buffer);
670 670
 	}
671 671
 
672 672
 	// Return the changed buffer.
Please login to merge, or discard this patch.
Braces   +181 added lines, -128 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,25 +254,28 @@  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
 		if (isset($modSettings['proxy_ip_servers']))
253 274
 		{
254
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
255
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
275
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
276
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
256 277
 					continue;
278
+			}
257 279
 		}
258 280
 
259 281
 		// If there are commas, get the last one.. probably.
@@ -273,8 +295,9 @@  discard block
 block discarded – undo
273 295
 
274 296
 						// Just incase we have a legacy IPv4 address.
275 297
 						// @ TODO: Convert to IPv6.
276
-						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)
277
-							continue;
298
+						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) {
299
+													continue;
300
+						}
278 301
 					}
279 302
 
280 303
 					continue;
@@ -286,36 +309,40 @@  discard block
 block discarded – undo
286 309
 			}
287 310
 		}
288 311
 		// Otherwise just use the only one.
289
-		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)
290
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
291
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
312
+		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) {
313
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
314
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
292 315
 		{
293 316
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
294 317
 
295 318
 			// Just incase we have a legacy IPv4 address.
296 319
 			// @ TODO: Convert to IPv6.
297
-			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)
298
-				continue;
320
+			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) {
321
+							continue;
322
+			}
299 323
 		}
300 324
 	}
301 325
 
302 326
 	// Make sure we know the URL of the current request.
303
-	if (empty($_SERVER['REQUEST_URI']))
304
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
305
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
306
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
307
-	else
308
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
327
+	if (empty($_SERVER['REQUEST_URI'])) {
328
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
329
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
330
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
331
+	} else {
332
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
333
+	}
309 334
 
310 335
 	// And make sure HTTP_USER_AGENT is set.
311 336
 	$_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)) : '';
312 337
 
313 338
 	// Some final checking.
314
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
315
-		$_SERVER['BAN_CHECK_IP'] = '';
316
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
317
-		$_SERVER['REMOTE_ADDR'] = '';
318
-}
339
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
340
+			$_SERVER['BAN_CHECK_IP'] = '';
341
+	}
342
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
343
+			$_SERVER['REMOTE_ADDR'] = '';
344
+	}
345
+	}
319 346
 
320 347
 /**
321 348
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -326,8 +353,9 @@  discard block
 block discarded – undo
326 353
 function isValidIPv6($ip)
327 354
 {
328 355
 	//looking for :
329
-	if (strpos($ip , ':') === false )
330
-		return false;
356
+	if (strpos($ip , ':') === false ) {
357
+			return false;
358
+	}
331 359
 	
332 360
 	//check valid address
333 361
 	return inet_pton($ip);
@@ -344,15 +372,17 @@  discard block
 block discarded – undo
344 372
 	static $expanded = array();
345 373
 
346 374
 	// Check if we have done this already.
347
-	if (isset($expanded[$ip]))
348
-		return $expanded[$ip];
375
+	if (isset($expanded[$ip])) {
376
+			return $expanded[$ip];
377
+	}
349 378
 
350 379
 	// Expand the IP out.
351 380
 	$expanded_ip = explode(':', expandIPv6($ip));
352 381
 
353 382
 	$new_ip = array();
354
-	foreach ($expanded_ip as $int)
355
-		$new_ip[] = hexdec($int);
383
+	foreach ($expanded_ip as $int) {
384
+			$new_ip[] = hexdec($int);
385
+	}
356 386
 
357 387
 	// Save this incase of repeated use.
358 388
 	$expanded[$ip] = $new_ip;
@@ -372,8 +402,9 @@  discard block
 block discarded – undo
372 402
 	static $converted = array();
373 403
 
374 404
 	// Check if we have done this already.
375
-	if (isset($converted[$addr]))
376
-		return $converted[$addr];
405
+	if (isset($converted[$addr])) {
406
+			return $converted[$addr];
407
+	}
377 408
 
378 409
 	// Check if there are segments missing, insert if necessary.
379 410
 	if (strpos($addr, '::') !== false)
@@ -383,18 +414,20 @@  discard block
 block discarded – undo
383 414
 		$part[1] = explode(':', $part[1]);
384 415
 		$missing = array();
385 416
 
386
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
387
-			array_push($missing, '0000');
417
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
418
+					array_push($missing, '0000');
419
+		}
388 420
 
389 421
 		$part = array_merge($part[0], $missing, $part[1]);
422
+	} else {
423
+			$part = explode(':', $addr);
390 424
 	}
391
-	else
392
-		$part = explode(':', $addr);
393 425
 
394 426
 	// Pad each segment until it has 4 digits.
395
-	foreach ($part as &$p)
396
-		while (strlen($p) < 4)
427
+	foreach ($part as &$p) {
428
+			while (strlen($p) < 4)
397 429
 			$p = '0' . $p;
430
+	}
398 431
 
399 432
 	unset($p);
400 433
 
@@ -405,11 +438,12 @@  discard block
 block discarded – undo
405 438
 	$converted[$addr] = $result;
406 439
 
407 440
 	// Quick check to make sure the length is as expected.
408
-	if (!$strict_check || strlen($result) == 39)
409
-		return $result;
410
-	else
411
-		return false;
412
-}
441
+	if (!$strict_check || strlen($result) == 39) {
442
+			return $result;
443
+	} else {
444
+			return false;
445
+	}
446
+	}
413 447
 
414 448
 
415 449
 /**
@@ -440,15 +474,17 @@  discard block
 block discarded – undo
440 474
 {
441 475
 	global $smcFunc;
442 476
 
443
-	if (!is_array($var))
444
-		return $smcFunc['db_escape_string']($var);
477
+	if (!is_array($var)) {
478
+			return $smcFunc['db_escape_string']($var);
479
+	}
445 480
 
446 481
 	// Reindex the array with slashes.
447 482
 	$new_var = array();
448 483
 
449 484
 	// Add slashes to every element, even the indexes!
450
-	foreach ($var as $k => $v)
451
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
485
+	foreach ($var as $k => $v) {
486
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
487
+	}
452 488
 
453 489
 	return $new_var;
454 490
 }
@@ -468,12 +504,14 @@  discard block
 block discarded – undo
468 504
 {
469 505
 	global $smcFunc;
470 506
 
471
-	if (!is_array($var))
472
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
507
+	if (!is_array($var)) {
508
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
509
+	}
473 510
 
474 511
 	// Add the htmlspecialchars to every element.
475
-	foreach ($var as $k => $v)
476
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
512
+	foreach ($var as $k => $v) {
513
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
514
+	}
477 515
 
478 516
 	return $var;
479 517
 }
@@ -491,15 +529,17 @@  discard block
 block discarded – undo
491 529
  */
492 530
 function urldecode__recursive($var, $level = 0)
493 531
 {
494
-	if (!is_array($var))
495
-		return urldecode($var);
532
+	if (!is_array($var)) {
533
+			return urldecode($var);
534
+	}
496 535
 
497 536
 	// Reindex the array...
498 537
 	$new_var = array();
499 538
 
500 539
 	// Add the htmlspecialchars to every element.
501
-	foreach ($var as $k => $v)
502
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
540
+	foreach ($var as $k => $v) {
541
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
542
+	}
503 543
 
504 544
 	return $new_var;
505 545
 }
@@ -517,15 +557,17 @@  discard block
 block discarded – undo
517 557
 {
518 558
 	global $smcFunc;
519 559
 
520
-	if (!is_array($var))
521
-		return $smcFunc['db_unescape_string']($var);
560
+	if (!is_array($var)) {
561
+			return $smcFunc['db_unescape_string']($var);
562
+	}
522 563
 
523 564
 	// Reindex the array without slashes, this time.
524 565
 	$new_var = array();
525 566
 
526 567
 	// Strip the slashes from every element.
527
-	foreach ($var as $k => $v)
528
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
568
+	foreach ($var as $k => $v) {
569
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
570
+	}
529 571
 
530 572
 	return $new_var;
531 573
 }
@@ -543,15 +585,17 @@  discard block
 block discarded – undo
543 585
  */
544 586
 function stripslashes__recursive($var, $level = 0)
545 587
 {
546
-	if (!is_array($var))
547
-		return stripslashes($var);
588
+	if (!is_array($var)) {
589
+			return stripslashes($var);
590
+	}
548 591
 
549 592
 	// Reindex the array without slashes, this time.
550 593
 	$new_var = array();
551 594
 
552 595
 	// Strip the slashes from every element.
553
-	foreach ($var as $k => $v)
554
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
596
+	foreach ($var as $k => $v) {
597
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
598
+	}
555 599
 
556 600
 	return $new_var;
557 601
 }
@@ -572,12 +616,14 @@  discard block
 block discarded – undo
572 616
 	global $smcFunc;
573 617
 
574 618
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
575
-	if (!is_array($var))
576
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
619
+	if (!is_array($var)) {
620
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
621
+	}
577 622
 
578 623
 	// Go through all the elements and remove the whitespace.
579
-	foreach ($var as $k => $v)
580
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
624
+	foreach ($var as $k => $v) {
625
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
626
+	}
581 627
 
582 628
 	return $var;
583 629
 }
@@ -642,30 +688,37 @@  discard block
 block discarded – undo
642 688
 	global $scripturl, $modSettings, $context;
643 689
 
644 690
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
645
-	if ($scripturl == '' || !defined('SID'))
646
-		return $buffer;
691
+	if ($scripturl == '' || !defined('SID')) {
692
+			return $buffer;
693
+	}
647 694
 
648 695
 	// 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.
649 696
 	// @todo smflib
650
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
651
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
697
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
698
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
699
+	}
652 700
 	// Debugging templates, are we?
653
-	elseif (isset($_GET['debug']))
654
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
701
+	elseif (isset($_GET['debug'])) {
702
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
703
+	}
655 704
 
656 705
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
657 706
 	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']))
658 707
 	{
659 708
 		// Let's do something special for session ids!
660
-		if (defined('SID') && SID != '')
661
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
709
+		if (defined('SID') && SID != '') {
710
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
662 711
 			{
663
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
712
+				global $scripturl;
713
+		}
714
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
664 715
 			}, $buffer);
665
-		else
666
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
716
+		else {
717
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function ($m)
667 718
 			{
668
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
719
+				global $scripturl;
720
+		}
721
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
669 722
 			}, $buffer );
670 723
 	}
671 724
 
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 = 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', 'lang' => true, 'url' => $scripturl . '?action=admin;area=reports', 'active' => true),
115
-		'print' => array('text' => 'print', 'image' => 'print.png', 'lang' => true, 'url' => $scripturl . '?action=admin;area=reports;rt=' . $context['report_type']. ';st=print', 'custom' => 'target="_blank"'),
115
+		'print' => array('text' => 'print', 'image' => 'print.png', 'lang' => true, '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.