Completed
Push — release-2.1 ( aa21c4...a79db9 )
by Colin
19:42 queued 09:42
created
Sources/QueryString.php 1 patch
Braces   +184 added lines, -130 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * 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'], $_REQUEST['page_id']) = explode('.', $_REQUEST['topic']);
208
+		elseif (strpos($_REQUEST['topic'], '.') !== false) {
209
+					list ($_REQUEST['topic'], $_REQUEST['start'], $_REQUEST['page_id']) = explode('.', $_REQUEST['topic']);
210
+		}
195 211
 
196 212
 		$topic = (int) $_REQUEST['topic'];
197 213
 
198 214
 		// Now make sure the online log gets the right number.
199 215
 		$_GET['topic'] = $topic;
216
+	} else {
217
+			$topic = 0;
200 218
 	}
201
-	else
202
-		$topic = 0;
203 219
 
204 220
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
205
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
206
-		$_REQUEST['start'] = 0;
221
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
222
+			$_REQUEST['start'] = 0;
223
+	}
207 224
 
208 225
 	// The action needs to be a string and not an array or anything else
209
-	if (isset($_REQUEST['action']))
210
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
211
-	if (isset($_GET['action']))
212
-		$_GET['action'] = (string) $_GET['action'];
226
+	if (isset($_REQUEST['action'])) {
227
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
228
+	}
229
+	if (isset($_GET['action'])) {
230
+			$_GET['action'] = (string) $_GET['action'];
231
+	}
213 232
 
214 233
 	// Some mail providers like to encode semicolons in activation URLs...
215 234
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -235,29 +254,33 @@  discard block
 block discarded – undo
235 254
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
236 255
 
237 256
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
238
-	if (!isset($modSettings['proxy_ip_header']))
239
-		$modSettings['proxy_ip_header'] = 'autodetect';
257
+	if (!isset($modSettings['proxy_ip_header'])) {
258
+			$modSettings['proxy_ip_header'] = 'autodetect';
259
+	}
240 260
 
241 261
 	// Which headers are we going to check for Reverse Proxy IP headers?
242
-	if ($modSettings['proxy_ip_header'] == 'disabled')
243
-		$reverseIPheaders = array();
244
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
245
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
246
-	else
247
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
262
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
263
+			$reverseIPheaders = array();
264
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
265
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
266
+	} else {
267
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
268
+	}
248 269
 
249 270
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
250 271
 	foreach ($reverseIPheaders as $proxyIPheader)
251 272
 	{
252 273
 		// Ignore if this is not set.
253
-		if (!isset($_SERVER[$proxyIPheader]))
254
-			continue;
274
+		if (!isset($_SERVER[$proxyIPheader])) {
275
+					continue;
276
+		}
255 277
 
256 278
 		if (!empty($modSettings['proxy_ip_servers']))
257 279
 		{
258
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
259
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
280
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
281
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
260 282
 					continue;
283
+			}
261 284
 		}
262 285
 
263 286
 		// If there are commas, get the last one.. probably.
@@ -277,8 +300,9 @@  discard block
 block discarded – undo
277 300
 
278 301
 						// Just incase we have a legacy IPv4 address.
279 302
 						// @ TODO: Convert to IPv6.
280
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
281
-							continue;
303
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
304
+													continue;
305
+						}
282 306
 					}
283 307
 
284 308
 					continue;
@@ -290,36 +314,40 @@  discard block
 block discarded – undo
290 314
 			}
291 315
 		}
292 316
 		// Otherwise just use the only one.
293
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
294
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
295
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
317
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
318
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
319
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
296 320
 		{
297 321
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
298 322
 
299 323
 			// Just incase we have a legacy IPv4 address.
300 324
 			// @ TODO: Convert to IPv6.
301
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
302
-				continue;
325
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
326
+							continue;
327
+			}
303 328
 		}
304 329
 	}
305 330
 
306 331
 	// Make sure we know the URL of the current request.
307
-	if (empty($_SERVER['REQUEST_URI']))
308
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
309
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
310
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
311
-	else
312
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
332
+	if (empty($_SERVER['REQUEST_URI'])) {
333
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
334
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
335
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
336
+	} else {
337
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
338
+	}
313 339
 
314 340
 	// And make sure HTTP_USER_AGENT is set.
315 341
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
316 342
 
317 343
 	// Some final checking.
318
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
319
-		$_SERVER['BAN_CHECK_IP'] = '';
320
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
321
-		$_SERVER['REMOTE_ADDR'] = '';
322
-}
344
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
345
+			$_SERVER['BAN_CHECK_IP'] = '';
346
+	}
347
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
348
+			$_SERVER['REMOTE_ADDR'] = '';
349
+	}
350
+	}
323 351
 
324 352
 /**
325 353
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -330,8 +358,9 @@  discard block
 block discarded – undo
330 358
 function isValidIPv6($ip)
331 359
 {
332 360
 	//looking for :
333
-	if (strpos($ip, ':') === false)
334
-		return false;
361
+	if (strpos($ip, ':') === false) {
362
+			return false;
363
+	}
335 364
 
336 365
 	//check valid address
337 366
 	return inet_pton($ip);
@@ -348,15 +377,17 @@  discard block
 block discarded – undo
348 377
 	static $expanded = array();
349 378
 
350 379
 	// Check if we have done this already.
351
-	if (isset($expanded[$ip]))
352
-		return $expanded[$ip];
380
+	if (isset($expanded[$ip])) {
381
+			return $expanded[$ip];
382
+	}
353 383
 
354 384
 	// Expand the IP out.
355 385
 	$expanded_ip = explode(':', expandIPv6($ip));
356 386
 
357 387
 	$new_ip = array();
358
-	foreach ($expanded_ip as $int)
359
-		$new_ip[] = hexdec($int);
388
+	foreach ($expanded_ip as $int) {
389
+			$new_ip[] = hexdec($int);
390
+	}
360 391
 
361 392
 	// Save this incase of repeated use.
362 393
 	$expanded[$ip] = $new_ip;
@@ -376,8 +407,9 @@  discard block
 block discarded – undo
376 407
 	static $converted = array();
377 408
 
378 409
 	// Check if we have done this already.
379
-	if (isset($converted[$addr]))
380
-		return $converted[$addr];
410
+	if (isset($converted[$addr])) {
411
+			return $converted[$addr];
412
+	}
381 413
 
382 414
 	// Check if there are segments missing, insert if necessary.
383 415
 	if (strpos($addr, '::') !== false)
@@ -387,18 +419,20 @@  discard block
 block discarded – undo
387 419
 		$part[1] = explode(':', $part[1]);
388 420
 		$missing = array();
389 421
 
390
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
391
-			array_push($missing, '0000');
422
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
423
+					array_push($missing, '0000');
424
+		}
392 425
 
393 426
 		$part = array_merge($part[0], $missing, $part[1]);
427
+	} else {
428
+			$part = explode(':', $addr);
394 429
 	}
395
-	else
396
-		$part = explode(':', $addr);
397 430
 
398 431
 	// Pad each segment until it has 4 digits.
399
-	foreach ($part as &$p)
400
-		while (strlen($p) < 4)
432
+	foreach ($part as &$p) {
433
+			while (strlen($p) < 4)
401 434
 			$p = '0' . $p;
435
+	}
402 436
 
403 437
 	unset($p);
404 438
 
@@ -409,11 +443,12 @@  discard block
 block discarded – undo
409 443
 	$converted[$addr] = $result;
410 444
 
411 445
 	// Quick check to make sure the length is as expected.
412
-	if (!$strict_check || strlen($result) == 39)
413
-		return $result;
414
-	else
415
-		return false;
416
-}
446
+	if (!$strict_check || strlen($result) == 39) {
447
+			return $result;
448
+	} else {
449
+			return false;
450
+	}
451
+	}
417 452
 
418 453
 
419 454
 /**
@@ -444,15 +479,17 @@  discard block
 block discarded – undo
444 479
 {
445 480
 	global $smcFunc;
446 481
 
447
-	if (!is_array($var))
448
-		return $smcFunc['db_escape_string']($var);
482
+	if (!is_array($var)) {
483
+			return $smcFunc['db_escape_string']($var);
484
+	}
449 485
 
450 486
 	// Reindex the array with slashes.
451 487
 	$new_var = array();
452 488
 
453 489
 	// Add slashes to every element, even the indexes!
454
-	foreach ($var as $k => $v)
455
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
490
+	foreach ($var as $k => $v) {
491
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
492
+	}
456 493
 
457 494
 	return $new_var;
458 495
 }
@@ -472,12 +509,14 @@  discard block
 block discarded – undo
472 509
 {
473 510
 	global $smcFunc;
474 511
 
475
-	if (!is_array($var))
476
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
512
+	if (!is_array($var)) {
513
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
514
+	}
477 515
 
478 516
 	// Add the htmlspecialchars to every element.
479
-	foreach ($var as $k => $v)
480
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
517
+	foreach ($var as $k => $v) {
518
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
519
+	}
481 520
 
482 521
 	return $var;
483 522
 }
@@ -495,15 +534,17 @@  discard block
 block discarded – undo
495 534
  */
496 535
 function urldecode__recursive($var, $level = 0)
497 536
 {
498
-	if (!is_array($var))
499
-		return urldecode($var);
537
+	if (!is_array($var)) {
538
+			return urldecode($var);
539
+	}
500 540
 
501 541
 	// Reindex the array...
502 542
 	$new_var = array();
503 543
 
504 544
 	// Add the htmlspecialchars to every element.
505
-	foreach ($var as $k => $v)
506
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
545
+	foreach ($var as $k => $v) {
546
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
547
+	}
507 548
 
508 549
 	return $new_var;
509 550
 }
@@ -521,15 +562,17 @@  discard block
 block discarded – undo
521 562
 {
522 563
 	global $smcFunc;
523 564
 
524
-	if (!is_array($var))
525
-		return $smcFunc['db_unescape_string']($var);
565
+	if (!is_array($var)) {
566
+			return $smcFunc['db_unescape_string']($var);
567
+	}
526 568
 
527 569
 	// Reindex the array without slashes, this time.
528 570
 	$new_var = array();
529 571
 
530 572
 	// Strip the slashes from every element.
531
-	foreach ($var as $k => $v)
532
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
573
+	foreach ($var as $k => $v) {
574
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
575
+	}
533 576
 
534 577
 	return $new_var;
535 578
 }
@@ -547,15 +590,17 @@  discard block
 block discarded – undo
547 590
  */
548 591
 function stripslashes__recursive($var, $level = 0)
549 592
 {
550
-	if (!is_array($var))
551
-		return stripslashes($var);
593
+	if (!is_array($var)) {
594
+			return stripslashes($var);
595
+	}
552 596
 
553 597
 	// Reindex the array without slashes, this time.
554 598
 	$new_var = array();
555 599
 
556 600
 	// Strip the slashes from every element.
557
-	foreach ($var as $k => $v)
558
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
601
+	foreach ($var as $k => $v) {
602
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
603
+	}
559 604
 
560 605
 	return $new_var;
561 606
 }
@@ -576,12 +621,14 @@  discard block
 block discarded – undo
576 621
 	global $smcFunc;
577 622
 
578 623
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
579
-	if (!is_array($var))
580
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
624
+	if (!is_array($var)) {
625
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
626
+	}
581 627
 
582 628
 	// Go through all the elements and remove the whitespace.
583
-	foreach ($var as $k => $v)
584
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
629
+	foreach ($var as $k => $v) {
630
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
631
+	}
585 632
 
586 633
 	return $var;
587 634
 }
@@ -646,30 +693,37 @@  discard block
 block discarded – undo
646 693
 	global $scripturl, $modSettings, $context;
647 694
 
648 695
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
649
-	if ($scripturl == '' || !defined('SID'))
650
-		return $buffer;
696
+	if ($scripturl == '' || !defined('SID')) {
697
+			return $buffer;
698
+	}
651 699
 
652 700
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
653 701
 	// @todo smflib
654
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
655
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
702
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
703
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
704
+	}
656 705
 	// Debugging templates, are we?
657
-	elseif (isset($_GET['debug']))
658
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
706
+	elseif (isset($_GET['debug'])) {
707
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
708
+	}
659 709
 
660 710
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
661 711
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
662 712
 	{
663 713
 		// Let's do something special for session ids!
664
-		if (defined('SID') && SID != '')
665
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
714
+		if (defined('SID') && SID != '') {
715
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
666 716
 			{
667
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
717
+				global $scripturl;
718
+		}
719
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
668 720
 			}, $buffer);
669
-		else
670
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
721
+		else {
722
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
671 723
 			{
672
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
724
+				global $scripturl;
725
+		}
726
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
673 727
 			}, $buffer);
674 728
 	}
675 729
 
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1315 added lines, -979 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,20 +572,25 @@  discard block
 block discarded – undo
555 572
 	$start = (int) $start;
556 573
 	$start_invalid = $start < 0;
557 574
 	
558
-	if (!empty($options['low_id']))
559
-		$low_id = $options['low_id'];
560
-	if (!empty($options['max_id']))
561
-		$max_id = $options['max_id'];
575
+	if (!empty($options['low_id'])) {
576
+			$low_id = $options['low_id'];
577
+	}
578
+	if (!empty($options['max_id'])) {
579
+			$max_id = $options['max_id'];
580
+	}
562 581
 
563 582
 	// Make sure $start is a proper variable - not less than 0.
564
-	if ($start_invalid)
565
-		$start = 0;
583
+	if ($start_invalid) {
584
+			$start = 0;
585
+	}
566 586
 	// Not greater than the upper bound.
567
-	elseif ($start >= $max_value)
568
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
587
+	elseif ($start >= $max_value) {
588
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
589
+	}
569 590
 	// And it has to be a multiple of $num_per_page!
570
-	else
571
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
591
+	else {
592
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
593
+	}
572 594
 
573 595
 	$context['current_page'] = $start / $num_per_page;
574 596
 
@@ -596,101 +618,115 @@  discard block
 block discarded – undo
596 618
 	if (empty($modSettings['compactTopicPagesEnable']))
597 619
 	{
598 620
 		// Show the left arrow.
599
-		if (empty($low_id))
600
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
601
-		else
602
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
621
+		if (empty($low_id)) {
622
+					$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
623
+		} else {
624
+					$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
625
+		}
603 626
 		
604 627
 		// Show all the pages.
605 628
 		$display_page = 1;
606
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
607
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
629
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
630
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		}
608 632
 
609 633
 		// Show the right arrow.
610 634
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
611 635
 		if ($start != $counter - $max_value && !$start_invalid){
612
-			if (empty($max_id))
613
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
614
-			else
615
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
636
+			if (empty($max_id)) {
637
+							$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
638
+			} else {
639
+							$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
640
+			}
616 641
 		}
617 642
 			
618
-	}
619
-	else
643
+	} else
620 644
 	{
621 645
 		// If they didn't enter an odd value, pretend they did.
622 646
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
623 647
 
624 648
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
625
-		if (!empty($start) && $show_prevnext)
626
-			if (empty($low_id))
649
+		if (!empty($start) && $show_prevnext) {
650
+					if (empty($low_id))
627 651
 				$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-			else
629
-				$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
630
-		else
631
-			$pageindex .= '';
652
+		} else {
653
+							$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
654
+			}
655
+		else {
656
+					$pageindex .= '';
657
+		}
632 658
 
633 659
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
634
-		if ($start > $num_per_page * $PageContiguous)
635
-			$pageindex .= sprintf($base_link, 0, '1');
660
+		if ($start > $num_per_page * $PageContiguous) {
661
+					$pageindex .= sprintf($base_link, 0, '1');
662
+		}
636 663
 
637 664
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
638
-		if ($start > $num_per_page * ($PageContiguous + 1))
639
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
665
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
666
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
640 667
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
641 668
 				'{FIRST_PAGE}' => $num_per_page,
642 669
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
643 670
 				'{PER_PAGE}' => $num_per_page,
644 671
 			));
672
+		}
645 673
 
646 674
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
647
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
648
-			if ($start >= $num_per_page * $nCont)
675
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
676
+					if ($start >= $num_per_page * $nCont)
649 677
 			{
650 678
 				$tmpStart = $start - $num_per_page * $nCont;
651
-				if($nCont != 1 || empty($low_id))
652
-					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
653
-				else
654
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
679
+		}
680
+				if($nCont != 1 || empty($low_id)) {
681
+									$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
682
+				} else {
683
+									$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
684
+				}
655 685
 			}
656 686
 
657 687
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
688
+		if (!$start_invalid) {
689
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
690
+		} else {
691
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
692
+		}
662 693
 
663 694
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 695
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
696
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
697
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 698
 			{
668 699
 				$tmpStart = $start + $num_per_page * $nCont;
669
-				if($nCont != 1 || empty($max_id))
670
-					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
671
-				else
672
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
700
+		}
701
+				if($nCont != 1 || empty($max_id)) {
702
+									$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
703
+				} else {
704
+									$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
705
+				}
673 706
 			}
674 707
 
675 708
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
676
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
677
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
709
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
710
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678 711
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
679 712
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
680 713
 				'{LAST_PAGE}' => $tmpMaxPages,
681 714
 				'{PER_PAGE}' => $num_per_page,
682 715
 			));
716
+		}
683 717
 
684 718
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
685
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
686
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
719
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
720
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
721
+		}
687 722
 
688 723
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
689
-		if ($start != $tmpMaxPages && $show_prevnext)
690
-			if (empty($max_id))
724
+		if ($start != $tmpMaxPages && $show_prevnext) {
725
+					if (empty($max_id))
691 726
 				$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
692
-			else
693
-				$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
727
+		} else {
728
+							$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
729
+			}
694 730
 	}
695 731
 	$pageindex .= $settings['page_index']['extra_after'];
696 732
 
@@ -716,8 +752,9 @@  discard block
 block discarded – undo
716 752
 	if ($decimal_separator === null)
717 753
 	{
718 754
 		// Not set for whatever reason?
719
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
720
-			return $number;
755
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
756
+					return $number;
757
+		}
721 758
 
722 759
 		// Cache these each load...
723 760
 		$thousands_separator = $matches[1];
@@ -749,17 +786,20 @@  discard block
 block discarded – undo
749 786
 	static $non_twelve_hour;
750 787
 
751 788
 	// Offset the time.
752
-	if (!$offset_type)
753
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
789
+	if (!$offset_type) {
790
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
791
+	}
754 792
 	// Just the forum offset?
755
-	elseif ($offset_type == 'forum')
756
-		$time = $log_time + $modSettings['time_offset'] * 3600;
757
-	else
758
-		$time = $log_time;
793
+	elseif ($offset_type == 'forum') {
794
+			$time = $log_time + $modSettings['time_offset'] * 3600;
795
+	} else {
796
+			$time = $log_time;
797
+	}
759 798
 
760 799
 	// We can't have a negative date (on Windows, at least.)
761
-	if ($log_time < 0)
762
-		$log_time = 0;
800
+	if ($log_time < 0) {
801
+			$log_time = 0;
802
+	}
763 803
 
764 804
 	// Today and Yesterday?
765 805
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -776,46 +816,53 @@  discard block
 block discarded – undo
776 816
 		{
777 817
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
778 818
 			$today_fmt = $h . ':%M' . $s . ' %p';
819
+		} else {
820
+					$today_fmt = '%H:%M' . $s;
779 821
 		}
780
-		else
781
-			$today_fmt = '%H:%M' . $s;
782 822
 
783 823
 		// Same day of the year, same year.... Today!
784
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
785
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
825
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
826
+		}
786 827
 
787 828
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
788
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
789
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
829
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
830
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
831
+		}
790 832
 	}
791 833
 
792 834
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
793 835
 
794 836
 	if (setlocale(LC_TIME, $txt['lang_locale']))
795 837
 	{
796
-		if (!isset($non_twelve_hour))
797
-			$non_twelve_hour = trim(strftime('%p')) === '';
798
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
799
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
838
+		if (!isset($non_twelve_hour)) {
839
+					$non_twelve_hour = trim(strftime('%p')) === '';
840
+		}
841
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
842
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
843
+		}
800 844
 
801
-		foreach (array('%a', '%A', '%b', '%B') as $token)
802
-			if (strpos($str, $token) !== false)
845
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
846
+					if (strpos($str, $token) !== false)
803 847
 				$str = str_replace($token, strftime($token, $time), $str);
804
-	}
805
-	else
848
+		}
849
+	} else
806 850
 	{
807 851
 		// Do-it-yourself time localization.  Fun.
808
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
809
-			if (strpos($str, $token) !== false)
852
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
853
+					if (strpos($str, $token) !== false)
810 854
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
855
+		}
811 856
 
812
-		if (strpos($str, '%p') !== false)
813
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
857
+		if (strpos($str, '%p') !== false) {
858
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
859
+		}
814 860
 	}
815 861
 
816 862
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
817
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
818
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
863
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
864
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
865
+	}
819 866
 
820 867
 	// Format any other characters..
821 868
 	return strftime($str, $time);
@@ -837,16 +884,19 @@  discard block
 block discarded – undo
837 884
 	static $translation = array();
838 885
 
839 886
 	// Determine the character set... Default to UTF-8
840
-	if (empty($context['character_set']))
841
-		$charset = 'UTF-8';
887
+	if (empty($context['character_set'])) {
888
+			$charset = 'UTF-8';
889
+	}
842 890
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
843
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
844
-		$charset = 'ISO-8859-1';
845
-	else
846
-		$charset = $context['character_set'];
891
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
892
+			$charset = 'ISO-8859-1';
893
+	} else {
894
+			$charset = $context['character_set'];
895
+	}
847 896
 
848
-	if (empty($translation))
849
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
897
+	if (empty($translation)) {
898
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
899
+	}
850 900
 
851 901
 	return strtr($string, $translation);
852 902
 }
@@ -868,8 +918,9 @@  discard block
 block discarded – undo
868 918
 	global $smcFunc;
869 919
 
870 920
 	// It was already short enough!
871
-	if ($smcFunc['strlen']($subject) <= $len)
872
-		return $subject;
921
+	if ($smcFunc['strlen']($subject) <= $len) {
922
+			return $subject;
923
+	}
873 924
 
874 925
 	// Shorten it by the length it was too long, and strip off junk from the end.
875 926
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -888,10 +939,11 @@  discard block
 block discarded – undo
888 939
 {
889 940
 	global $user_info, $modSettings;
890 941
 
891
-	if ($timestamp === null)
892
-		$timestamp = time();
893
-	elseif ($timestamp == 0)
894
-		return 0;
942
+	if ($timestamp === null) {
943
+			$timestamp = time();
944
+	} elseif ($timestamp == 0) {
945
+			return 0;
946
+	}
895 947
 
896 948
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
897 949
 }
@@ -920,8 +972,9 @@  discard block
 block discarded – undo
920 972
 		$array[$i] = $array[$j];
921 973
 		$array[$j] = $temp;
922 974
 
923
-		for ($i = 1; $p[$i] == 0; $i++)
924
-			$p[$i] = 1;
975
+		for ($i = 1; $p[$i] == 0; $i++) {
976
+					$p[$i] = 1;
977
+		}
925 978
 
926 979
 		$orders[] = $array;
927 980
 	}
@@ -953,12 +1006,14 @@  discard block
 block discarded – undo
953 1006
 	static $disabled;
954 1007
 
955 1008
 	// Don't waste cycles
956
-	if ($message === '')
957
-		return '';
1009
+	if ($message === '') {
1010
+			return '';
1011
+	}
958 1012
 
959 1013
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
960
-	if (!isset($context['utf8']))
961
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1014
+	if (!isset($context['utf8'])) {
1015
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1016
+	}
962 1017
 
963 1018
 	// Clean up any cut/paste issues we may have
964 1019
 	$message = sanitizeMSCutPaste($message);
@@ -970,13 +1025,15 @@  discard block
 block discarded – undo
970 1025
 		return $message;
971 1026
 	}
972 1027
 
973
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
974
-		$smileys = (bool) $smileys;
1028
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1029
+			$smileys = (bool) $smileys;
1030
+	}
975 1031
 
976 1032
 	if (empty($modSettings['enableBBC']) && $message !== false)
977 1033
 	{
978
-		if ($smileys === true)
979
-			parsesmileys($message);
1034
+		if ($smileys === true) {
1035
+					parsesmileys($message);
1036
+		}
980 1037
 
981 1038
 		return $message;
982 1039
 	}
@@ -989,8 +1046,9 @@  discard block
 block discarded – undo
989 1046
 	}
990 1047
 
991 1048
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
992
-	if (!empty($modSettings['autoLinkUrls']))
993
-		set_tld_regex();
1049
+	if (!empty($modSettings['autoLinkUrls'])) {
1050
+			set_tld_regex();
1051
+	}
994 1052
 
995 1053
 	// Allow mods access before entering the main parse_bbc loop
996 1054
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1004,12 +1062,14 @@  discard block
 block discarded – undo
1004 1062
 
1005 1063
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1006 1064
 
1007
-			foreach ($temp as $tag)
1008
-				$disabled[trim($tag)] = true;
1065
+			foreach ($temp as $tag) {
1066
+							$disabled[trim($tag)] = true;
1067
+			}
1009 1068
 		}
1010 1069
 
1011
-		if (empty($modSettings['enableEmbeddedFlash']))
1012
-			$disabled['flash'] = true;
1070
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1071
+					$disabled['flash'] = true;
1072
+		}
1013 1073
 
1014 1074
 		/* The following bbc are formatted as an array, with keys as follows:
1015 1075
 
@@ -1130,8 +1190,9 @@  discard block
 block discarded – undo
1130 1190
 					$returnContext = '';
1131 1191
 
1132 1192
 					// BBC or the entire attachments feature is disabled
1133
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1134
-						return $data;
1193
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1194
+											return $data;
1195
+					}
1135 1196
 
1136 1197
 					// Save the attach ID.
1137 1198
 					$attachID = $data;
@@ -1142,8 +1203,9 @@  discard block
 block discarded – undo
1142 1203
 					$currentAttachment = parseAttachBBC($attachID);
1143 1204
 
1144 1205
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1145
-					if (is_string($currentAttachment))
1146
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1206
+					if (is_string($currentAttachment)) {
1207
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1208
+					}
1147 1209
 
1148 1210
 					if (!empty($currentAttachment['is_image']))
1149 1211
 					{
@@ -1159,15 +1221,17 @@  discard block
 block discarded – undo
1159 1221
 							$height = ' height="' . $currentAttachment['height'] . '"';
1160 1222
 						}
1161 1223
 
1162
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1163
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1164
-						else
1165
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1224
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1225
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1226
+						} else {
1227
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1228
+						}
1166 1229
 					}
1167 1230
 
1168 1231
 					// No image. Show a link.
1169
-					else
1170
-						$returnContext .= $currentAttachment['link'];
1232
+					else {
1233
+											$returnContext .= $currentAttachment['link'];
1234
+					}
1171 1235
 
1172 1236
 					// Gotta append what we just did.
1173 1237
 					$data = $returnContext;
@@ -1198,8 +1262,9 @@  discard block
 block discarded – undo
1198 1262
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1199 1263
 						{
1200 1264
 							// Do PHP code coloring?
1201
-							if ($php_parts[$php_i] != '&lt;?php')
1202
-								continue;
1265
+							if ($php_parts[$php_i] != '&lt;?php') {
1266
+															continue;
1267
+							}
1203 1268
 
1204 1269
 							$php_string = '';
1205 1270
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1215,8 +1280,9 @@  discard block
 block discarded – undo
1215 1280
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1216 1281
 
1217 1282
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1218
-						if ($context['browser']['is_opera'])
1219
-							$data .= '&nbsp;';
1283
+						if ($context['browser']['is_opera']) {
1284
+													$data .= '&nbsp;';
1285
+						}
1220 1286
 					}
1221 1287
 				},
1222 1288
 				'block_level' => true,
@@ -1235,8 +1301,9 @@  discard block
 block discarded – undo
1235 1301
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1236 1302
 						{
1237 1303
 							// Do PHP code coloring?
1238
-							if ($php_parts[$php_i] != '&lt;?php')
1239
-								continue;
1304
+							if ($php_parts[$php_i] != '&lt;?php') {
1305
+															continue;
1306
+							}
1240 1307
 
1241 1308
 							$php_string = '';
1242 1309
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1252,8 +1319,9 @@  discard block
 block discarded – undo
1252 1319
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1253 1320
 
1254 1321
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1255
-						if ($context['browser']['is_opera'])
1256
-							$data[0] .= '&nbsp;';
1322
+						if ($context['browser']['is_opera']) {
1323
+													$data[0] .= '&nbsp;';
1324
+						}
1257 1325
 					}
1258 1326
 				},
1259 1327
 				'block_level' => true,
@@ -1291,11 +1359,13 @@  discard block
 block discarded – undo
1291 1359
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1292 1360
 				'validate' => function (&$tag, &$data, $disabled)
1293 1361
 				{
1294
-					if (isset($disabled['url']))
1295
-						$tag['content'] = '$1';
1362
+					if (isset($disabled['url'])) {
1363
+											$tag['content'] = '$1';
1364
+					}
1296 1365
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1297
-					if (empty($scheme))
1298
-						$data[0] = '//' . ltrim($data[0], ':/');
1366
+					if (empty($scheme)) {
1367
+											$data[0] = '//' . ltrim($data[0], ':/');
1368
+					}
1299 1369
 				},
1300 1370
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1301 1371
 			),
@@ -1309,10 +1379,11 @@  discard block
 block discarded – undo
1309 1379
 				{
1310 1380
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1311 1381
 
1312
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1313
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1314
-					else
1315
-						$css = '';
1382
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1383
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1384
+					} else {
1385
+											$css = '';
1386
+					}
1316 1387
 
1317 1388
 					$data = $class . $css;
1318 1389
 				},
@@ -1362,14 +1433,16 @@  discard block
 block discarded – undo
1362 1433
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1363 1434
 					if ($image_proxy_enabled)
1364 1435
 					{
1365
-						if (empty($scheme))
1366
-							$data = 'http://' . ltrim($data, ':/');
1436
+						if (empty($scheme)) {
1437
+													$data = 'http://' . ltrim($data, ':/');
1438
+						}
1367 1439
 
1368
-						if ($scheme != 'https')
1369
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1440
+						if ($scheme != 'https') {
1441
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1442
+						}
1443
+					} elseif (empty($scheme)) {
1444
+											$data = '//' . ltrim($data, ':/');
1370 1445
 					}
1371
-					elseif (empty($scheme))
1372
-						$data = '//' . ltrim($data, ':/');
1373 1446
 				},
1374 1447
 				'disabled_content' => '($1)',
1375 1448
 			),
@@ -1385,14 +1458,16 @@  discard block
 block discarded – undo
1385 1458
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1386 1459
 					if ($image_proxy_enabled)
1387 1460
 					{
1388
-						if (empty($scheme))
1389
-							$data = 'http://' . ltrim($data, ':/');
1461
+						if (empty($scheme)) {
1462
+													$data = 'http://' . ltrim($data, ':/');
1463
+						}
1390 1464
 
1391
-						if ($scheme != 'https')
1392
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1465
+						if ($scheme != 'https') {
1466
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1467
+						}
1468
+					} elseif (empty($scheme)) {
1469
+											$data = '//' . ltrim($data, ':/');
1393 1470
 					}
1394
-					elseif (empty($scheme))
1395
-						$data = '//' . ltrim($data, ':/');
1396 1471
 				},
1397 1472
 				'disabled_content' => '($1)',
1398 1473
 			),
@@ -1404,8 +1479,9 @@  discard block
 block discarded – undo
1404 1479
 				{
1405 1480
 					$data = strtr($data, array('<br>' => ''));
1406 1481
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1407
-					if (empty($scheme))
1408
-						$data = '//' . ltrim($data, ':/');
1482
+					if (empty($scheme)) {
1483
+											$data = '//' . ltrim($data, ':/');
1484
+					}
1409 1485
 				},
1410 1486
 			),
1411 1487
 			array(
@@ -1416,13 +1492,14 @@  discard block
 block discarded – undo
1416 1492
 				'after' => '</a>',
1417 1493
 				'validate' => function (&$tag, &$data, $disabled)
1418 1494
 				{
1419
-					if (substr($data, 0, 1) == '#')
1420
-						$data = '#post_' . substr($data, 1);
1421
-					else
1495
+					if (substr($data, 0, 1) == '#') {
1496
+											$data = '#post_' . substr($data, 1);
1497
+					} else
1422 1498
 					{
1423 1499
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1424
-						if (empty($scheme))
1425
-							$data = '//' . ltrim($data, ':/');
1500
+						if (empty($scheme)) {
1501
+													$data = '//' . ltrim($data, ':/');
1502
+						}
1426 1503
 					}
1427 1504
 				},
1428 1505
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1500,8 +1577,9 @@  discard block
 block discarded – undo
1500 1577
 					{
1501 1578
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1502 1579
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1503
-						if ($add_begin)
1504
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1580
+						if ($add_begin) {
1581
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1582
+						}
1505 1583
 					}
1506 1584
 				},
1507 1585
 				'block_level' => false,
@@ -1632,10 +1710,11 @@  discard block
 block discarded – undo
1632 1710
 				'content' => '$1',
1633 1711
 				'validate' => function (&$tag, &$data, $disabled)
1634 1712
 				{
1635
-					if (is_numeric($data))
1636
-						$data = timeformat($data);
1637
-					else
1638
-						$tag['content'] = '[time]$1[/time]';
1713
+					if (is_numeric($data)) {
1714
+											$data = timeformat($data);
1715
+					} else {
1716
+											$tag['content'] = '[time]$1[/time]';
1717
+					}
1639 1718
 				},
1640 1719
 			),
1641 1720
 			array(
@@ -1662,8 +1741,9 @@  discard block
 block discarded – undo
1662 1741
 				{
1663 1742
 					$data = strtr($data, array('<br>' => ''));
1664 1743
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1665
-					if (empty($scheme))
1666
-						$data = '//' . ltrim($data, ':/');
1744
+					if (empty($scheme)) {
1745
+											$data = '//' . ltrim($data, ':/');
1746
+					}
1667 1747
 				},
1668 1748
 			),
1669 1749
 			array(
@@ -1675,8 +1755,9 @@  discard block
 block discarded – undo
1675 1755
 				'validate' => function (&$tag, &$data, $disabled)
1676 1756
 				{
1677 1757
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1678
-					if (empty($scheme))
1679
-						$data = '//' . ltrim($data, ':/');
1758
+					if (empty($scheme)) {
1759
+											$data = '//' . ltrim($data, ':/');
1760
+					}
1680 1761
 				},
1681 1762
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1682 1763
 				'disabled_after' => ' ($1)',
@@ -1696,8 +1777,9 @@  discard block
 block discarded – undo
1696 1777
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1697 1778
 		if ($message === false)
1698 1779
 		{
1699
-			if (isset($temp_bbc))
1700
-				$bbc_codes = $temp_bbc;
1780
+			if (isset($temp_bbc)) {
1781
+							$bbc_codes = $temp_bbc;
1782
+			}
1701 1783
 			usort($codes, function ($a, $b) {
1702 1784
 				return strcmp($a['tag'], $b['tag']);
1703 1785
 			});
@@ -1717,8 +1799,9 @@  discard block
 block discarded – undo
1717 1799
 		);
1718 1800
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1719 1801
 		{
1720
-			foreach ($itemcodes as $c => $dummy)
1721
-				$bbc_codes[$c] = array();
1802
+			foreach ($itemcodes as $c => $dummy) {
1803
+							$bbc_codes[$c] = array();
1804
+			}
1722 1805
 		}
1723 1806
 
1724 1807
 		// Shhhh!
@@ -1739,12 +1822,14 @@  discard block
 block discarded – undo
1739 1822
 		foreach ($codes as $code)
1740 1823
 		{
1741 1824
 			// Make it easier to process parameters later
1742
-			if (!empty($code['parameters']))
1743
-				ksort($code['parameters'], SORT_STRING);
1825
+			if (!empty($code['parameters'])) {
1826
+							ksort($code['parameters'], SORT_STRING);
1827
+			}
1744 1828
 
1745 1829
 			// If we are not doing every tag only do ones we are interested in.
1746
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1747
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1830
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1831
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1832
+			}
1748 1833
 		}
1749 1834
 		$codes = null;
1750 1835
 	}
@@ -1755,8 +1840,9 @@  discard block
 block discarded – undo
1755 1840
 		// It's likely this will change if the message is modified.
1756 1841
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1757 1842
 
1758
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1759
-			return $temp;
1843
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1844
+					return $temp;
1845
+		}
1760 1846
 
1761 1847
 		$cache_t = microtime();
1762 1848
 	}
@@ -1788,8 +1874,9 @@  discard block
 block discarded – undo
1788 1874
 		$disabled['flash'] = true;
1789 1875
 
1790 1876
 		// @todo Change maybe?
1791
-		if (!isset($_GET['images']))
1792
-			$disabled['img'] = true;
1877
+		if (!isset($_GET['images'])) {
1878
+					$disabled['img'] = true;
1879
+		}
1793 1880
 
1794 1881
 		// @todo Interface/setting to add more?
1795 1882
 	}
@@ -1813,8 +1900,9 @@  discard block
 block discarded – undo
1813 1900
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1814 1901
 
1815 1902
 		// Failsafe.
1816
-		if ($pos === false || $last_pos > $pos)
1817
-			$pos = strlen($message) + 1;
1903
+		if ($pos === false || $last_pos > $pos) {
1904
+					$pos = strlen($message) + 1;
1905
+		}
1818 1906
 
1819 1907
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1820 1908
 		if ($last_pos < $pos - 1)
@@ -1833,8 +1921,9 @@  discard block
 block discarded – undo
1833 1921
 
1834 1922
 				// <br> should be empty.
1835 1923
 				$empty_tags = array('br', 'hr');
1836
-				foreach ($empty_tags as $tag)
1837
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1924
+				foreach ($empty_tags as $tag) {
1925
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1926
+				}
1838 1927
 
1839 1928
 				// b, u, i, s, pre... basic tags.
1840 1929
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1843,8 +1932,9 @@  discard block
 block discarded – undo
1843 1932
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1844 1933
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1845 1934
 
1846
-					if ($diff > 0)
1847
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1935
+					if ($diff > 0) {
1936
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1937
+					}
1848 1938
 				}
1849 1939
 
1850 1940
 				// Do <img ...> - with security... action= -> action-.
@@ -1857,8 +1947,9 @@  discard block
 block discarded – undo
1857 1947
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1858 1948
 
1859 1949
 						// Remove action= from the URL - no funny business, now.
1860
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1861
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1950
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1951
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1952
+						}
1862 1953
 
1863 1954
 						// Check if the image is larger than allowed.
1864 1955
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1879,9 +1970,9 @@  discard block
 block discarded – undo
1879 1970
 
1880 1971
 							// Set the new image tag.
1881 1972
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1973
+						} else {
1974
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1882 1975
 						}
1883
-						else
1884
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1885 1976
 					}
1886 1977
 
1887 1978
 					$data = strtr($data, $replaces);
@@ -1894,16 +1985,18 @@  discard block
 block discarded – undo
1894 1985
 				$no_autolink_area = false;
1895 1986
 				if (!empty($open_tags))
1896 1987
 				{
1897
-					foreach ($open_tags as $open_tag)
1898
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1988
+					foreach ($open_tags as $open_tag) {
1989
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1899 1990
 							$no_autolink_area = true;
1991
+					}
1900 1992
 				}
1901 1993
 
1902 1994
 				// Don't go backwards.
1903 1995
 				// @todo Don't think is the real solution....
1904 1996
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1905
-				if ($pos < $lastAutoPos)
1906
-					$no_autolink_area = true;
1997
+				if ($pos < $lastAutoPos) {
1998
+									$no_autolink_area = true;
1999
+				}
1907 2000
 				$lastAutoPos = $pos;
1908 2001
 
1909 2002
 				if (!$no_autolink_area)
@@ -2012,17 +2105,19 @@  discard block
 block discarded – undo
2012 2105
 							if ($scheme == 'mailto')
2013 2106
 							{
2014 2107
 								$email_address = str_replace('mailto:', '', $url);
2015
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2016
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2017
-								else
2018
-									return $url;
2108
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2109
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2110
+								} else {
2111
+																	return $url;
2112
+								}
2019 2113
 							}
2020 2114
 
2021 2115
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2022
-							if (empty($scheme))
2023
-								$fullUrl = '//' . ltrim($url, ':/');
2024
-							else
2025
-								$fullUrl = $url;
2116
+							if (empty($scheme)) {
2117
+															$fullUrl = '//' . ltrim($url, ':/');
2118
+							} else {
2119
+															$fullUrl = $url;
2120
+							}
2026 2121
 
2027 2122
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2028 2123
 						}, $data);
@@ -2071,16 +2166,18 @@  discard block
 block discarded – undo
2071 2166
 		}
2072 2167
 
2073 2168
 		// Are we there yet?  Are we there yet?
2074
-		if ($pos >= strlen($message) - 1)
2075
-			break;
2169
+		if ($pos >= strlen($message) - 1) {
2170
+					break;
2171
+		}
2076 2172
 
2077 2173
 		$tags = strtolower($message[$pos + 1]);
2078 2174
 
2079 2175
 		if ($tags == '/' && !empty($open_tags))
2080 2176
 		{
2081 2177
 			$pos2 = strpos($message, ']', $pos + 1);
2082
-			if ($pos2 == $pos + 2)
2083
-				continue;
2178
+			if ($pos2 == $pos + 2) {
2179
+							continue;
2180
+			}
2084 2181
 
2085 2182
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2086 2183
 
@@ -2090,8 +2187,9 @@  discard block
 block discarded – undo
2090 2187
 			do
2091 2188
 			{
2092 2189
 				$tag = array_pop($open_tags);
2093
-				if (!$tag)
2094
-					break;
2190
+				if (!$tag) {
2191
+									break;
2192
+				}
2095 2193
 
2096 2194
 				if (!empty($tag['block_level']))
2097 2195
 				{
@@ -2105,10 +2203,11 @@  discard block
 block discarded – undo
2105 2203
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2106 2204
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2107 2205
 					{
2108
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2109
-							if ($temp['tag'] == $look_for)
2206
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2207
+													if ($temp['tag'] == $look_for)
2110 2208
 							{
2111 2209
 								$block_level = !empty($temp['block_level']);
2210
+						}
2112 2211
 								break;
2113 2212
 							}
2114 2213
 					}
@@ -2130,15 +2229,15 @@  discard block
 block discarded – undo
2130 2229
 			{
2131 2230
 				$open_tags = $to_close;
2132 2231
 				continue;
2133
-			}
2134
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2232
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2135 2233
 			{
2136 2234
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2137 2235
 				{
2138
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2139
-						if ($temp['tag'] == $look_for)
2236
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2237
+											if ($temp['tag'] == $look_for)
2140 2238
 						{
2141 2239
 							$block_level = !empty($temp['block_level']);
2240
+					}
2142 2241
 							break;
2143 2242
 						}
2144 2243
 				}
@@ -2146,8 +2245,9 @@  discard block
 block discarded – undo
2146 2245
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2147 2246
 				if (!$block_level)
2148 2247
 				{
2149
-					foreach ($to_close as $tag)
2150
-						array_push($open_tags, $tag);
2248
+					foreach ($to_close as $tag) {
2249
+											array_push($open_tags, $tag);
2250
+					}
2151 2251
 					continue;
2152 2252
 				}
2153 2253
 			}
@@ -2160,14 +2260,17 @@  discard block
 block discarded – undo
2160 2260
 
2161 2261
 				// See the comment at the end of the big loop - just eating whitespace ;).
2162 2262
 				$whitespace_regex = '';
2163
-				if (!empty($tag['block_level']))
2164
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2263
+				if (!empty($tag['block_level'])) {
2264
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2265
+				}
2165 2266
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2166
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2167
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2267
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2268
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2269
+				}
2168 2270
 
2169
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2170
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2271
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2272
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2273
+				}
2171 2274
 			}
2172 2275
 
2173 2276
 			if (!empty($to_close))
@@ -2180,8 +2283,9 @@  discard block
 block discarded – undo
2180 2283
 		}
2181 2284
 
2182 2285
 		// No tags for this character, so just keep going (fastest possible course.)
2183
-		if (!isset($bbc_codes[$tags]))
2184
-			continue;
2286
+		if (!isset($bbc_codes[$tags])) {
2287
+					continue;
2288
+		}
2185 2289
 
2186 2290
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2187 2291
 		$tag = null;
@@ -2190,44 +2294,52 @@  discard block
 block discarded – undo
2190 2294
 			$pt_strlen = strlen($possible['tag']);
2191 2295
 
2192 2296
 			// Not a match?
2193
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2194
-				continue;
2297
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2298
+							continue;
2299
+			}
2195 2300
 
2196 2301
 			$next_c = $message[$pos + 1 + $pt_strlen];
2197 2302
 
2198 2303
 			// A test validation?
2199
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2200
-				continue;
2304
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2305
+							continue;
2306
+			}
2201 2307
 			// Do we want parameters?
2202 2308
 			elseif (!empty($possible['parameters']))
2203 2309
 			{
2204
-				if ($next_c != ' ')
2205
-					continue;
2206
-			}
2207
-			elseif (isset($possible['type']))
2310
+				if ($next_c != ' ') {
2311
+									continue;
2312
+				}
2313
+			} elseif (isset($possible['type']))
2208 2314
 			{
2209 2315
 				// Do we need an equal sign?
2210
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2211
-					continue;
2316
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2317
+									continue;
2318
+				}
2212 2319
 				// Maybe we just want a /...
2213
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2214
-					continue;
2320
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2321
+									continue;
2322
+				}
2215 2323
 				// An immediate ]?
2216
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2217
-					continue;
2324
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2325
+									continue;
2326
+				}
2218 2327
 			}
2219 2328
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2220
-			elseif ($next_c != ']')
2221
-				continue;
2329
+			elseif ($next_c != ']') {
2330
+							continue;
2331
+			}
2222 2332
 
2223 2333
 			// Check allowed tree?
2224
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2225
-				continue;
2226
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2227
-				continue;
2334
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2335
+							continue;
2336
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2337
+							continue;
2338
+			}
2228 2339
 			// If this is in the list of disallowed child tags, don't parse it.
2229
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2230
-				continue;
2340
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2341
+							continue;
2342
+			}
2231 2343
 
2232 2344
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2233 2345
 
@@ -2239,8 +2351,9 @@  discard block
 block discarded – undo
2239 2351
 				foreach ($open_tags as $open_quote)
2240 2352
 				{
2241 2353
 					// Every parent quote this quote has flips the styling
2242
-					if ($open_quote['tag'] == 'quote')
2243
-						$quote_alt = !$quote_alt;
2354
+					if ($open_quote['tag'] == 'quote') {
2355
+											$quote_alt = !$quote_alt;
2356
+					}
2244 2357
 				}
2245 2358
 				// Add a class to the quote to style alternating blockquotes
2246 2359
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2251,8 +2364,9 @@  discard block
 block discarded – undo
2251 2364
 			{
2252 2365
 				// Build a regular expression for each parameter for the current tag.
2253 2366
 				$preg = array();
2254
-				foreach ($possible['parameters'] as $p => $info)
2255
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2367
+				foreach ($possible['parameters'] as $p => $info) {
2368
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2369
+				}
2256 2370
 
2257 2371
 				// Extract the string that potentially holds our parameters.
2258 2372
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2272,24 +2386,27 @@  discard block
 block discarded – undo
2272 2386
 
2273 2387
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2274 2388
 
2275
-					if ($match)
2276
-						$blob_counter = count($blobs) + 1;
2389
+					if ($match) {
2390
+											$blob_counter = count($blobs) + 1;
2391
+					}
2277 2392
 				}
2278 2393
 
2279 2394
 				// Didn't match our parameter list, try the next possible.
2280
-				if (!$match)
2281
-					continue;
2395
+				if (!$match) {
2396
+									continue;
2397
+				}
2282 2398
 
2283 2399
 				$params = array();
2284 2400
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2285 2401
 				{
2286 2402
 					$key = strtok(ltrim($matches[$i]), '=');
2287
-					if (isset($possible['parameters'][$key]['value']))
2288
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2289
-					elseif (isset($possible['parameters'][$key]['validate']))
2290
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2291
-					else
2292
-						$params['{' . $key . '}'] = $matches[$i + 1];
2403
+					if (isset($possible['parameters'][$key]['value'])) {
2404
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2405
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2406
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2407
+					} else {
2408
+											$params['{' . $key . '}'] = $matches[$i + 1];
2409
+					}
2293 2410
 
2294 2411
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2295 2412
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2297,23 +2414,26 @@  discard block
 block discarded – undo
2297 2414
 
2298 2415
 				foreach ($possible['parameters'] as $p => $info)
2299 2416
 				{
2300
-					if (!isset($params['{' . $p . '}']))
2301
-						$params['{' . $p . '}'] = '';
2417
+					if (!isset($params['{' . $p . '}'])) {
2418
+											$params['{' . $p . '}'] = '';
2419
+					}
2302 2420
 				}
2303 2421
 
2304 2422
 				$tag = $possible;
2305 2423
 
2306 2424
 				// Put the parameters into the string.
2307
-				if (isset($tag['before']))
2308
-					$tag['before'] = strtr($tag['before'], $params);
2309
-				if (isset($tag['after']))
2310
-					$tag['after'] = strtr($tag['after'], $params);
2311
-				if (isset($tag['content']))
2312
-					$tag['content'] = strtr($tag['content'], $params);
2425
+				if (isset($tag['before'])) {
2426
+									$tag['before'] = strtr($tag['before'], $params);
2427
+				}
2428
+				if (isset($tag['after'])) {
2429
+									$tag['after'] = strtr($tag['after'], $params);
2430
+				}
2431
+				if (isset($tag['content'])) {
2432
+									$tag['content'] = strtr($tag['content'], $params);
2433
+				}
2313 2434
 
2314 2435
 				$pos1 += strlen($given_param_string);
2315
-			}
2316
-			else
2436
+			} else
2317 2437
 			{
2318 2438
 				$tag = $possible;
2319 2439
 				$params = array();
@@ -2324,8 +2444,9 @@  discard block
 block discarded – undo
2324 2444
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2325 2445
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2326 2446
 		{
2327
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2328
-				continue;
2447
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2448
+							continue;
2449
+			}
2329 2450
 
2330 2451
 			$tag = $itemcodes[$message[$pos + 1]];
2331 2452
 
@@ -2346,9 +2467,9 @@  discard block
 block discarded – undo
2346 2467
 			{
2347 2468
 				array_pop($open_tags);
2348 2469
 				$code = '</li>';
2470
+			} else {
2471
+							$code = '';
2349 2472
 			}
2350
-			else
2351
-				$code = '';
2352 2473
 
2353 2474
 			// Now we open a new tag.
2354 2475
 			$open_tags[] = array(
@@ -2395,12 +2516,14 @@  discard block
 block discarded – undo
2395 2516
 		}
2396 2517
 
2397 2518
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2398
-		if ($tag === null)
2399
-			continue;
2519
+		if ($tag === null) {
2520
+					continue;
2521
+		}
2400 2522
 
2401 2523
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2402
-		if (isset($inside['disallow_children']))
2403
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2524
+		if (isset($inside['disallow_children'])) {
2525
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2526
+		}
2404 2527
 
2405 2528
 		// Is this tag disabled?
2406 2529
 		if (isset($disabled[$tag['tag']]))
@@ -2410,14 +2533,13 @@  discard block
 block discarded – undo
2410 2533
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2411 2534
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2412 2535
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2413
-			}
2414
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2536
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2415 2537
 			{
2416 2538
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2417 2539
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2540
+			} else {
2541
+							$tag['content'] = $tag['disabled_content'];
2418 2542
 			}
2419
-			else
2420
-				$tag['content'] = $tag['disabled_content'];
2421 2543
 		}
2422 2544
 
2423 2545
 		// we use this a lot
@@ -2427,8 +2549,9 @@  discard block
 block discarded – undo
2427 2549
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2428 2550
 		{
2429 2551
 			$n = count($open_tags) - 1;
2430
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2431
-				$n--;
2552
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2553
+							$n--;
2554
+			}
2432 2555
 
2433 2556
 			// Close all the non block level tags so this tag isn't surrounded by them.
2434 2557
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2440,12 +2563,15 @@  discard block
 block discarded – undo
2440 2563
 
2441 2564
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2442 2565
 				$whitespace_regex = '';
2443
-				if (!empty($tag['block_level']))
2444
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2445
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2446
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2447
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2448
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2566
+				if (!empty($tag['block_level'])) {
2567
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2568
+				}
2569
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2570
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2571
+				}
2572
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2573
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2574
+				}
2449 2575
 
2450 2576
 				array_pop($open_tags);
2451 2577
 			}
@@ -2463,16 +2589,19 @@  discard block
 block discarded – undo
2463 2589
 		elseif ($tag['type'] == 'unparsed_content')
2464 2590
 		{
2465 2591
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2466
-			if ($pos2 === false)
2467
-				continue;
2592
+			if ($pos2 === false) {
2593
+							continue;
2594
+			}
2468 2595
 
2469 2596
 			$data = substr($message, $pos1, $pos2 - $pos1);
2470 2597
 
2471
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2472
-				$data = substr($data, 4);
2598
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2599
+							$data = substr($data, 4);
2600
+			}
2473 2601
 
2474
-			if (isset($tag['validate']))
2475
-				$tag['validate']($tag, $data, $disabled, $params);
2602
+			if (isset($tag['validate'])) {
2603
+							$tag['validate']($tag, $data, $disabled, $params);
2604
+			}
2476 2605
 
2477 2606
 			$code = strtr($tag['content'], array('$1' => $data));
2478 2607
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2488,34 +2617,40 @@  discard block
 block discarded – undo
2488 2617
 			if (isset($tag['quoted']))
2489 2618
 			{
2490 2619
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2491
-				if ($tag['quoted'] != 'optional' && !$quoted)
2492
-					continue;
2620
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2621
+									continue;
2622
+				}
2493 2623
 
2494
-				if ($quoted)
2495
-					$pos1 += 6;
2624
+				if ($quoted) {
2625
+									$pos1 += 6;
2626
+				}
2627
+			} else {
2628
+							$quoted = false;
2496 2629
 			}
2497
-			else
2498
-				$quoted = false;
2499 2630
 
2500 2631
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2501
-			if ($pos2 === false)
2502
-				continue;
2632
+			if ($pos2 === false) {
2633
+							continue;
2634
+			}
2503 2635
 
2504 2636
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2505
-			if ($pos3 === false)
2506
-				continue;
2637
+			if ($pos3 === false) {
2638
+							continue;
2639
+			}
2507 2640
 
2508 2641
 			$data = array(
2509 2642
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2510 2643
 				substr($message, $pos1, $pos2 - $pos1)
2511 2644
 			);
2512 2645
 
2513
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2514
-				$data[0] = substr($data[0], 4);
2646
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2647
+							$data[0] = substr($data[0], 4);
2648
+			}
2515 2649
 
2516 2650
 			// Validation for my parking, please!
2517
-			if (isset($tag['validate']))
2518
-				$tag['validate']($tag, $data, $disabled, $params);
2651
+			if (isset($tag['validate'])) {
2652
+							$tag['validate']($tag, $data, $disabled, $params);
2653
+			}
2519 2654
 
2520 2655
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2521 2656
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2532,23 +2667,27 @@  discard block
 block discarded – undo
2532 2667
 		elseif ($tag['type'] == 'unparsed_commas_content')
2533 2668
 		{
2534 2669
 			$pos2 = strpos($message, ']', $pos1);
2535
-			if ($pos2 === false)
2536
-				continue;
2670
+			if ($pos2 === false) {
2671
+							continue;
2672
+			}
2537 2673
 
2538 2674
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2539
-			if ($pos3 === false)
2540
-				continue;
2675
+			if ($pos3 === false) {
2676
+							continue;
2677
+			}
2541 2678
 
2542 2679
 			// We want $1 to be the content, and the rest to be csv.
2543 2680
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2544 2681
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2545 2682
 
2546
-			if (isset($tag['validate']))
2547
-				$tag['validate']($tag, $data, $disabled, $params);
2683
+			if (isset($tag['validate'])) {
2684
+							$tag['validate']($tag, $data, $disabled, $params);
2685
+			}
2548 2686
 
2549 2687
 			$code = $tag['content'];
2550
-			foreach ($data as $k => $d)
2551
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2688
+			foreach ($data as $k => $d) {
2689
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2690
+			}
2552 2691
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2553 2692
 			$pos += strlen($code) - 1 + 2;
2554 2693
 		}
@@ -2556,24 +2695,28 @@  discard block
 block discarded – undo
2556 2695
 		elseif ($tag['type'] == 'unparsed_commas')
2557 2696
 		{
2558 2697
 			$pos2 = strpos($message, ']', $pos1);
2559
-			if ($pos2 === false)
2560
-				continue;
2698
+			if ($pos2 === false) {
2699
+							continue;
2700
+			}
2561 2701
 
2562 2702
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2563 2703
 
2564
-			if (isset($tag['validate']))
2565
-				$tag['validate']($tag, $data, $disabled, $params);
2704
+			if (isset($tag['validate'])) {
2705
+							$tag['validate']($tag, $data, $disabled, $params);
2706
+			}
2566 2707
 
2567 2708
 			// Fix after, for disabled code mainly.
2568
-			foreach ($data as $k => $d)
2569
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2709
+			foreach ($data as $k => $d) {
2710
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2711
+			}
2570 2712
 
2571 2713
 			$open_tags[] = $tag;
2572 2714
 
2573 2715
 			// Replace them out, $1, $2, $3, $4, etc.
2574 2716
 			$code = $tag['before'];
2575
-			foreach ($data as $k => $d)
2576
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2717
+			foreach ($data as $k => $d) {
2718
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2719
+			}
2577 2720
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2578 2721
 			$pos += strlen($code) - 1 + 2;
2579 2722
 		}
@@ -2584,28 +2727,33 @@  discard block
 block discarded – undo
2584 2727
 			if (isset($tag['quoted']))
2585 2728
 			{
2586 2729
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2587
-				if ($tag['quoted'] != 'optional' && !$quoted)
2588
-					continue;
2730
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2731
+									continue;
2732
+				}
2589 2733
 
2590
-				if ($quoted)
2591
-					$pos1 += 6;
2734
+				if ($quoted) {
2735
+									$pos1 += 6;
2736
+				}
2737
+			} else {
2738
+							$quoted = false;
2592 2739
 			}
2593
-			else
2594
-				$quoted = false;
2595 2740
 
2596 2741
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2597
-			if ($pos2 === false)
2598
-				continue;
2742
+			if ($pos2 === false) {
2743
+							continue;
2744
+			}
2599 2745
 
2600 2746
 			$data = substr($message, $pos1, $pos2 - $pos1);
2601 2747
 
2602 2748
 			// Validation for my parking, please!
2603
-			if (isset($tag['validate']))
2604
-				$tag['validate']($tag, $data, $disabled, $params);
2749
+			if (isset($tag['validate'])) {
2750
+							$tag['validate']($tag, $data, $disabled, $params);
2751
+			}
2605 2752
 
2606 2753
 			// For parsed content, we must recurse to avoid security problems.
2607
-			if ($tag['type'] != 'unparsed_equals')
2608
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2754
+			if ($tag['type'] != 'unparsed_equals') {
2755
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2756
+			}
2609 2757
 
2610 2758
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2611 2759
 
@@ -2617,34 +2765,40 @@  discard block
 block discarded – undo
2617 2765
 		}
2618 2766
 
2619 2767
 		// If this is block level, eat any breaks after it.
2620
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2621
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2768
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2769
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2770
+		}
2622 2771
 
2623 2772
 		// Are we trimming outside this tag?
2624
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2625
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2773
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2774
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2775
+		}
2626 2776
 	}
2627 2777
 
2628 2778
 	// Close any remaining tags.
2629
-	while ($tag = array_pop($open_tags))
2630
-		$message .= "\n" . $tag['after'] . "\n";
2779
+	while ($tag = array_pop($open_tags)) {
2780
+			$message .= "\n" . $tag['after'] . "\n";
2781
+	}
2631 2782
 
2632 2783
 	// Parse the smileys within the parts where it can be done safely.
2633 2784
 	if ($smileys === true)
2634 2785
 	{
2635 2786
 		$message_parts = explode("\n", $message);
2636
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2637
-			parsesmileys($message_parts[$i]);
2787
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2788
+					parsesmileys($message_parts[$i]);
2789
+		}
2638 2790
 
2639 2791
 		$message = implode('', $message_parts);
2640 2792
 	}
2641 2793
 
2642 2794
 	// No smileys, just get rid of the markers.
2643
-	else
2644
-		$message = strtr($message, array("\n" => ''));
2795
+	else {
2796
+			$message = strtr($message, array("\n" => ''));
2797
+	}
2645 2798
 
2646
-	if ($message !== '' && $message[0] === ' ')
2647
-		$message = '&nbsp;' . substr($message, 1);
2799
+	if ($message !== '' && $message[0] === ' ') {
2800
+			$message = '&nbsp;' . substr($message, 1);
2801
+	}
2648 2802
 
2649 2803
 	// Cleanup whitespace.
2650 2804
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2653,15 +2807,16 @@  discard block
 block discarded – undo
2653 2807
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2654 2808
 
2655 2809
 	// Cache the output if it took some time...
2656
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2657
-		cache_put_data($cache_key, $message, 240);
2810
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2811
+			cache_put_data($cache_key, $message, 240);
2812
+	}
2658 2813
 
2659 2814
 	// If this was a force parse revert if needed.
2660 2815
 	if (!empty($parse_tags))
2661 2816
 	{
2662
-		if (empty($temp_bbc))
2663
-			$bbc_codes = array();
2664
-		else
2817
+		if (empty($temp_bbc)) {
2818
+					$bbc_codes = array();
2819
+		} else
2665 2820
 		{
2666 2821
 			$bbc_codes = $temp_bbc;
2667 2822
 			unset($temp_bbc);
@@ -2688,8 +2843,9 @@  discard block
 block discarded – undo
2688 2843
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2689 2844
 
2690 2845
 	// No smiley set at all?!
2691
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2692
-		return;
2846
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2847
+			return;
2848
+	}
2693 2849
 
2694 2850
 	// If smileyPregSearch hasn't been set, do it now.
2695 2851
 	if (empty($smileyPregSearch))
@@ -2700,8 +2856,7 @@  discard block
 block discarded – undo
2700 2856
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2701 2857
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2702 2858
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2703
-		}
2704
-		else
2859
+		} else
2705 2860
 		{
2706 2861
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2707 2862
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2725,9 +2880,9 @@  discard block
 block discarded – undo
2725 2880
 				$smcFunc['db_free_result']($result);
2726 2881
 
2727 2882
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2883
+			} else {
2884
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2728 2885
 			}
2729
-			else
2730
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2731 2886
 		}
2732 2887
 
2733 2888
 		// The non-breaking-space is a complex thing...
@@ -2804,35 +2959,41 @@  discard block
 block discarded – undo
2804 2959
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2805 2960
 
2806 2961
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2807
-	if (!empty($context['flush_mail']))
2808
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2962
+	if (!empty($context['flush_mail'])) {
2963
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2809 2964
 		AddMailQueue(true);
2965
+	}
2810 2966
 
2811 2967
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2812 2968
 
2813
-	if ($add)
2814
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2969
+	if ($add) {
2970
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2971
+	}
2815 2972
 
2816 2973
 	// Put the session ID in.
2817
-	if (defined('SID') && SID != '')
2818
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2974
+	if (defined('SID') && SID != '') {
2975
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2976
+	}
2819 2977
 	// Keep that debug in their for template debugging!
2820
-	elseif (isset($_GET['debug']))
2821
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2978
+	elseif (isset($_GET['debug'])) {
2979
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2980
+	}
2822 2981
 
2823 2982
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2824 2983
 	{
2825
-		if (defined('SID') && SID != '')
2826
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2984
+		if (defined('SID') && SID != '') {
2985
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2827 2986
 				function ($m) use ($scripturl)
2828 2987
 				{
2829 2988
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2989
+		}
2830 2990
 				}, $setLocation);
2831
-		else
2832
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2991
+		else {
2992
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2833 2993
 				function ($m) use ($scripturl)
2834 2994
 				{
2835 2995
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2996
+		}
2836 2997
 				}, $setLocation);
2837 2998
 	}
2838 2999
 
@@ -2843,8 +3004,9 @@  discard block
 block discarded – undo
2843 3004
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2844 3005
 
2845 3006
 	// Debugging.
2846
-	if (isset($db_show_debug) && $db_show_debug === true)
2847
-		$_SESSION['debug_redirect'] = $db_cache;
3007
+	if (isset($db_show_debug) && $db_show_debug === true) {
3008
+			$_SESSION['debug_redirect'] = $db_cache;
3009
+	}
2848 3010
 
2849 3011
 	obExit(false);
2850 3012
 }
@@ -2863,51 +3025,60 @@  discard block
 block discarded – undo
2863 3025
 
2864 3026
 	// Attempt to prevent a recursive loop.
2865 3027
 	++$level;
2866
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2867
-		exit;
2868
-	if ($from_fatal_error)
2869
-		$has_fatal_error = true;
3028
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3029
+			exit;
3030
+	}
3031
+	if ($from_fatal_error) {
3032
+			$has_fatal_error = true;
3033
+	}
2870 3034
 
2871 3035
 	// Clear out the stat cache.
2872 3036
 	trackStats();
2873 3037
 
2874 3038
 	// If we have mail to send, send it.
2875
-	if (!empty($context['flush_mail']))
2876
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3039
+	if (!empty($context['flush_mail'])) {
3040
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2877 3041
 		AddMailQueue(true);
3042
+	}
2878 3043
 
2879 3044
 	$do_header = $header === null ? !$header_done : $header;
2880
-	if ($do_footer === null)
2881
-		$do_footer = $do_header;
3045
+	if ($do_footer === null) {
3046
+			$do_footer = $do_header;
3047
+	}
2882 3048
 
2883 3049
 	// Has the template/header been done yet?
2884 3050
 	if ($do_header)
2885 3051
 	{
2886 3052
 		// Was the page title set last minute? Also update the HTML safe one.
2887
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2888
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3053
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3054
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3055
+		}
2889 3056
 
2890 3057
 		// Start up the session URL fixer.
2891 3058
 		ob_start('ob_sessrewrite');
2892 3059
 
2893
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2894
-			$buffers = explode(',', $settings['output_buffers']);
2895
-		elseif (!empty($settings['output_buffers']))
2896
-			$buffers = $settings['output_buffers'];
2897
-		else
2898
-			$buffers = array();
3060
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3061
+					$buffers = explode(',', $settings['output_buffers']);
3062
+		} elseif (!empty($settings['output_buffers'])) {
3063
+					$buffers = $settings['output_buffers'];
3064
+		} else {
3065
+					$buffers = array();
3066
+		}
2899 3067
 
2900
-		if (isset($modSettings['integrate_buffer']))
2901
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3068
+		if (isset($modSettings['integrate_buffer'])) {
3069
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3070
+		}
2902 3071
 
2903
-		if (!empty($buffers))
2904
-			foreach ($buffers as $function)
3072
+		if (!empty($buffers)) {
3073
+					foreach ($buffers as $function)
2905 3074
 			{
2906 3075
 				$call = call_helper($function, true);
3076
+		}
2907 3077
 
2908 3078
 				// Is it valid?
2909
-				if (!empty($call))
2910
-					ob_start($call);
3079
+				if (!empty($call)) {
3080
+									ob_start($call);
3081
+				}
2911 3082
 			}
2912 3083
 
2913 3084
 		// Display the screen in the logical order.
@@ -2919,8 +3090,9 @@  discard block
 block discarded – undo
2919 3090
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2920 3091
 
2921 3092
 		// Anything special to put out?
2922
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2923
-			echo $context['insert_after_template'];
3093
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3094
+					echo $context['insert_after_template'];
3095
+		}
2924 3096
 
2925 3097
 		// Just so we don't get caught in an endless loop of errors from the footer...
2926 3098
 		if (!$footer_done)
@@ -2929,14 +3101,16 @@  discard block
 block discarded – undo
2929 3101
 			template_footer();
2930 3102
 
2931 3103
 			// (since this is just debugging... it's okay that it's after </html>.)
2932
-			if (!isset($_REQUEST['xml']))
2933
-				displayDebug();
3104
+			if (!isset($_REQUEST['xml'])) {
3105
+							displayDebug();
3106
+			}
2934 3107
 		}
2935 3108
 	}
2936 3109
 
2937 3110
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2938
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2939
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3111
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3112
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3113
+	}
2940 3114
 
2941 3115
 	// For session check verification.... don't switch browsers...
2942 3116
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2945,9 +3119,10 @@  discard block
 block discarded – undo
2945 3119
 	call_integration_hook('integrate_exit', array($do_footer));
2946 3120
 
2947 3121
 	// Don't exit if we're coming from index.php; that will pass through normally.
2948
-	if (!$from_index)
2949
-		exit;
2950
-}
3122
+	if (!$from_index) {
3123
+			exit;
3124
+	}
3125
+	}
2951 3126
 
2952 3127
 /**
2953 3128
  * Get the size of a specified image with better error handling.
@@ -2966,8 +3141,9 @@  discard block
 block discarded – undo
2966 3141
 	$url = str_replace(' ', '%20', $url);
2967 3142
 
2968 3143
 	// Can we pull this from the cache... please please?
2969
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2970
-		return $temp;
3144
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3145
+			return $temp;
3146
+	}
2971 3147
 	$t = microtime();
2972 3148
 
2973 3149
 	// Get the host to pester...
@@ -2977,12 +3153,10 @@  discard block
 block discarded – undo
2977 3153
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2978 3154
 	{
2979 3155
 		return false;
2980
-	}
2981
-	elseif (!isset($match[1]))
3156
+	} elseif (!isset($match[1]))
2982 3157
 	{
2983 3158
 		$size = @getimagesize($url);
2984
-	}
2985
-	else
3159
+	} else
2986 3160
 	{
2987 3161
 		// Try to connect to the server... give it half a second.
2988 3162
 		$temp = 0;
@@ -3021,12 +3195,14 @@  discard block
 block discarded – undo
3021 3195
 	}
3022 3196
 
3023 3197
 	// If we didn't get it, we failed.
3024
-	if (!isset($size))
3025
-		$size = false;
3198
+	if (!isset($size)) {
3199
+			$size = false;
3200
+	}
3026 3201
 
3027 3202
 	// If this took a long time, we may never have to do it again, but then again we might...
3028
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3029
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3203
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3204
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3205
+	}
3030 3206
 
3031 3207
 	// Didn't work.
3032 3208
 	return $size;
@@ -3044,8 +3220,9 @@  discard block
 block discarded – undo
3044 3220
 
3045 3221
 	// Under SSI this function can be called more then once.  That can cause some problems.
3046 3222
 	//   So only run the function once unless we are forced to run it again.
3047
-	if ($loaded && !$forceload)
3048
-		return;
3223
+	if ($loaded && !$forceload) {
3224
+			return;
3225
+	}
3049 3226
 
3050 3227
 	$loaded = true;
3051 3228
 
@@ -3057,14 +3234,16 @@  discard block
 block discarded – undo
3057 3234
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3058 3235
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3059 3236
 	{
3060
-		if (trim($context['news_lines'][$i]) == '')
3061
-			continue;
3237
+		if (trim($context['news_lines'][$i]) == '') {
3238
+					continue;
3239
+		}
3062 3240
 
3063 3241
 		// Clean it up for presentation ;).
3064 3242
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3065 3243
 	}
3066
-	if (!empty($context['news_lines']))
3067
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3244
+	if (!empty($context['news_lines'])) {
3245
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3246
+	}
3068 3247
 
3069 3248
 	if (!$user_info['is_guest'])
3070 3249
 	{
@@ -3073,40 +3252,48 @@  discard block
 block discarded – undo
3073 3252
 		$context['user']['alerts'] = &$user_info['alerts'];
3074 3253
 
3075 3254
 		// Personal message popup...
3076
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3077
-			$context['user']['popup_messages'] = true;
3078
-		else
3079
-			$context['user']['popup_messages'] = false;
3255
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3256
+					$context['user']['popup_messages'] = true;
3257
+		} else {
3258
+					$context['user']['popup_messages'] = false;
3259
+		}
3080 3260
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3081 3261
 
3082
-		if (allowedTo('moderate_forum'))
3083
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3262
+		if (allowedTo('moderate_forum')) {
3263
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3264
+		}
3084 3265
 
3085 3266
 		$context['user']['avatar'] = array();
3086 3267
 
3087 3268
 		// Check for gravatar first since we might be forcing them...
3088 3269
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3089 3270
 		{
3090
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3091
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3092
-			else
3093
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3271
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3272
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3273
+			} else {
3274
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3275
+			}
3094 3276
 		}
3095 3277
 		// Uploaded?
3096
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3097
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3278
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3279
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3280
+		}
3098 3281
 		// Full URL?
3099
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3100
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3282
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3283
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3284
+		}
3101 3285
 		// Otherwise we assume it's server stored.
3102
-		elseif ($user_info['avatar']['url'] != '')
3103
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3286
+		elseif ($user_info['avatar']['url'] != '') {
3287
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3288
+		}
3104 3289
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3105
-		else
3106
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3290
+		else {
3291
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3292
+		}
3107 3293
 
3108
-		if (!empty($context['user']['avatar']))
3109
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3294
+		if (!empty($context['user']['avatar'])) {
3295
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3296
+		}
3110 3297
 
3111 3298
 		// Figure out how long they've been logged in.
3112 3299
 		$context['user']['total_time_logged_in'] = array(
@@ -3114,8 +3301,7 @@  discard block
 block discarded – undo
3114 3301
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3115 3302
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3116 3303
 		);
3117
-	}
3118
-	else
3304
+	} else
3119 3305
 	{
3120 3306
 		$context['user']['messages'] = 0;
3121 3307
 		$context['user']['unread_messages'] = 0;
@@ -3123,12 +3309,14 @@  discard block
 block discarded – undo
3123 3309
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3124 3310
 		$context['user']['popup_messages'] = false;
3125 3311
 
3126
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3127
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3312
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3313
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3314
+		}
3128 3315
 
3129 3316
 		// If we've upgraded recently, go easy on the passwords.
3130
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3131
-			$context['disable_login_hashing'] = true;
3317
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3318
+					$context['disable_login_hashing'] = true;
3319
+		}
3132 3320
 	}
3133 3321
 
3134 3322
 	// Setup the main menu items.
@@ -3141,8 +3329,8 @@  discard block
 block discarded – undo
3141 3329
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3142 3330
 
3143 3331
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3144
-	if ($context['show_pm_popup'])
3145
-		addInlineJavaScript('
3332
+	if ($context['show_pm_popup']) {
3333
+			addInlineJavaScript('
3146 3334
 		jQuery(document).ready(function($) {
3147 3335
 			new smc_Popup({
3148 3336
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3150,15 +3338,17 @@  discard block
 block discarded – undo
3150 3338
 				icon_class: \'generic_icons mail_new\'
3151 3339
 			});
3152 3340
 		});');
3341
+	}
3153 3342
 
3154 3343
 	// Add a generic "Are you sure?" confirmation message.
3155 3344
 	addInlineJavaScript('
3156 3345
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3157 3346
 
3158 3347
 	// Now add the capping code for avatars.
3159
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3160
-		addInlineCss('
3348
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3349
+			addInlineCss('
3161 3350
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3351
+	}
3162 3352
 
3163 3353
 	// This looks weird, but it's because BoardIndex.php references the variable.
3164 3354
 	$context['common_stats']['latest_member'] = array(
@@ -3175,11 +3365,13 @@  discard block
 block discarded – undo
3175 3365
 	);
3176 3366
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3177 3367
 
3178
-	if (empty($settings['theme_version']))
3179
-		addJavaScriptVar('smf_scripturl', $scripturl);
3368
+	if (empty($settings['theme_version'])) {
3369
+			addJavaScriptVar('smf_scripturl', $scripturl);
3370
+	}
3180 3371
 
3181
-	if (!isset($context['page_title']))
3182
-		$context['page_title'] = '';
3372
+	if (!isset($context['page_title'])) {
3373
+			$context['page_title'] = '';
3374
+	}
3183 3375
 
3184 3376
 	// Set some specific vars.
3185 3377
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3189,21 +3381,23 @@  discard block
 block discarded – undo
3189 3381
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3190 3382
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3191 3383
 
3192
-	if (!empty($context['meta_keywords']))
3193
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3384
+	if (!empty($context['meta_keywords'])) {
3385
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3386
+	}
3194 3387
 
3195
-	if (!empty($context['canonical_url']))
3196
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3388
+	if (!empty($context['canonical_url'])) {
3389
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3390
+	}
3197 3391
 
3198
-	if (!empty($settings['og_image']))
3199
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3392
+	if (!empty($settings['og_image'])) {
3393
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3394
+	}
3200 3395
 
3201 3396
 	if (!empty($context['meta_description']))
3202 3397
 	{
3203 3398
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3204 3399
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3205
-	}
3206
-	else
3400
+	} else
3207 3401
 	{
3208 3402
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3209 3403
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3228,8 +3422,9 @@  discard block
 block discarded – undo
3228 3422
 	$memory_needed = memoryReturnBytes($needed);
3229 3423
 
3230 3424
 	// should we account for how much is currently being used?
3231
-	if ($in_use)
3232
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3425
+	if ($in_use) {
3426
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3427
+	}
3233 3428
 
3234 3429
 	// if more is needed, request it
3235 3430
 	if ($memory_current < $memory_needed)
@@ -3252,8 +3447,9 @@  discard block
 block discarded – undo
3252 3447
  */
3253 3448
 function memoryReturnBytes($val)
3254 3449
 {
3255
-	if (is_integer($val))
3256
-		return $val;
3450
+	if (is_integer($val)) {
3451
+			return $val;
3452
+	}
3257 3453
 
3258 3454
 	// Separate the number from the designator
3259 3455
 	$val = trim($val);
@@ -3289,10 +3485,11 @@  discard block
 block discarded – undo
3289 3485
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3290 3486
 
3291 3487
 		// Are we debugging the template/html content?
3292
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3293
-			header('Content-Type: application/xhtml+xml');
3294
-		elseif (!isset($_REQUEST['xml']))
3295
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3488
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3489
+					header('Content-Type: application/xhtml+xml');
3490
+		} elseif (!isset($_REQUEST['xml'])) {
3491
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3492
+		}
3296 3493
 	}
3297 3494
 
3298 3495
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3301,8 +3498,9 @@  discard block
 block discarded – undo
3301 3498
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3302 3499
 	{
3303 3500
 		$position = array_search('body', $context['template_layers']);
3304
-		if ($position === false)
3305
-			$position = array_search('main', $context['template_layers']);
3501
+		if ($position === false) {
3502
+					$position = array_search('main', $context['template_layers']);
3503
+		}
3306 3504
 
3307 3505
 		if ($position !== false)
3308 3506
 		{
@@ -3330,23 +3528,25 @@  discard block
 block discarded – undo
3330 3528
 
3331 3529
 			foreach ($securityFiles as $i => $securityFile)
3332 3530
 			{
3333
-				if (!file_exists($boarddir . '/' . $securityFile))
3334
-					unset($securityFiles[$i]);
3531
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3532
+									unset($securityFiles[$i]);
3533
+				}
3335 3534
 			}
3336 3535
 
3337 3536
 			// We are already checking so many files...just few more doesn't make any difference! :P
3338
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3339
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3340
-
3341
-			else
3342
-				$path = $modSettings['attachmentUploadDir'];
3537
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3538
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3539
+			} else {
3540
+							$path = $modSettings['attachmentUploadDir'];
3541
+			}
3343 3542
 
3344 3543
 			secureDirectory($path, true);
3345 3544
 			secureDirectory($cachedir);
3346 3545
 
3347 3546
 			// If agreement is enabled, at least the english version shall exists
3348
-			if ($modSettings['requireAgreement'])
3349
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3547
+			if ($modSettings['requireAgreement']) {
3548
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3549
+			}
3350 3550
 
3351 3551
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3352 3552
 			{
@@ -3361,18 +3561,21 @@  discard block
 block discarded – undo
3361 3561
 					echo '
3362 3562
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3363 3563
 
3364
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3365
-						echo '
3564
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3565
+											echo '
3366 3566
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3567
+					}
3367 3568
 				}
3368 3569
 
3369
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3370
-					echo '
3570
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3571
+									echo '
3371 3572
 				<strong>', $txt['cache_writable'], '</strong><br>';
3573
+				}
3372 3574
 
3373
-				if (!empty($agreement))
3374
-					echo '
3575
+				if (!empty($agreement)) {
3576
+									echo '
3375 3577
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3578
+				}
3376 3579
 
3377 3580
 				echo '
3378 3581
 			</p>
@@ -3387,16 +3590,18 @@  discard block
 block discarded – undo
3387 3590
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3388 3591
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3389 3592
 
3390
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3391
-				echo '
3593
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3594
+							echo '
3392 3595
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3596
+			}
3393 3597
 
3394
-			if (!empty($_SESSION['ban']['expire_time']))
3395
-				echo '
3598
+			if (!empty($_SESSION['ban']['expire_time'])) {
3599
+							echo '
3396 3600
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3397
-			else
3398
-				echo '
3601
+			} else {
3602
+							echo '
3399 3603
 					<div>', $txt['your_ban_expires_never'], '</div>';
3604
+			}
3400 3605
 
3401 3606
 			echo '
3402 3607
 				</div>';
@@ -3412,8 +3617,9 @@  discard block
 block discarded – undo
3412 3617
 	global $forum_copyright, $software_year, $forum_version;
3413 3618
 
3414 3619
 	// Don't display copyright for things like SSI.
3415
-	if (!isset($forum_version) || !isset($software_year))
3416
-		return;
3620
+	if (!isset($forum_version) || !isset($software_year)) {
3621
+			return;
3622
+	}
3417 3623
 
3418 3624
 	// Put in the version...
3419 3625
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3431,9 +3637,10 @@  discard block
 block discarded – undo
3431 3637
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3432 3638
 	$context['load_queries'] = $db_count;
3433 3639
 
3434
-	foreach (array_reverse($context['template_layers']) as $layer)
3435
-		loadSubTemplate($layer . '_below', true);
3436
-}
3640
+	foreach (array_reverse($context['template_layers']) as $layer) {
3641
+			loadSubTemplate($layer . '_below', true);
3642
+	}
3643
+	}
3437 3644
 
3438 3645
 /**
3439 3646
  * Output the Javascript files
@@ -3464,8 +3671,7 @@  discard block
 block discarded – undo
3464 3671
 			{
3465 3672
 				echo '
3466 3673
 		var ', $key, ';';
3467
-			}
3468
-			else
3674
+			} else
3469 3675
 			{
3470 3676
 				echo '
3471 3677
 		var ', $key, ' = ', $value, ';';
@@ -3480,26 +3686,27 @@  discard block
 block discarded – undo
3480 3686
 	foreach ($context['javascript_files'] as $id => $js_file)
3481 3687
 	{
3482 3688
 		// Last minute call! allow theme authors to disable single files.
3483
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3484
-			continue;
3689
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3690
+					continue;
3691
+		}
3485 3692
 
3486 3693
 		// By default all files don't get minimized unless the file explicitly says so!
3487 3694
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3488 3695
 		{
3489
-			if ($do_deferred && !empty($js_file['options']['defer']))
3490
-				$toMinifyDefer[] = $js_file;
3491
-
3492
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3493
-				$toMinify[] = $js_file;
3696
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3697
+							$toMinifyDefer[] = $js_file;
3698
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3699
+							$toMinify[] = $js_file;
3700
+			}
3494 3701
 
3495 3702
 			// Grab a random seed.
3496
-			if (!isset($minSeed))
3497
-				$minSeed = $js_file['options']['seed'];
3498
-		}
3499
-
3500
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3501
-			echo '
3703
+			if (!isset($minSeed)) {
3704
+							$minSeed = $js_file['options']['seed'];
3705
+			}
3706
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3707
+					echo '
3502 3708
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3709
+		}
3503 3710
 	}
3504 3711
 
3505 3712
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3507,14 +3714,14 @@  discard block
 block discarded – undo
3507 3714
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3508 3715
 
3509 3716
 		// Minify process couldn't work, print each individual files.
3510
-		if (!empty($result) && is_array($result))
3511
-			foreach ($result as $minFailedFile)
3717
+		if (!empty($result) && is_array($result)) {
3718
+					foreach ($result as $minFailedFile)
3512 3719
 				echo '
3513 3720
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3514
-
3515
-		else
3516
-			echo '
3721
+		} else {
3722
+					echo '
3517 3723
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3724
+		}
3518 3725
 	}
3519 3726
 
3520 3727
 	// Inline JavaScript - Actually useful some times!
@@ -3525,8 +3732,9 @@  discard block
 block discarded – undo
3525 3732
 			echo '
3526 3733
 <script>';
3527 3734
 
3528
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3529
-				echo $js_code;
3735
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3736
+							echo $js_code;
3737
+			}
3530 3738
 
3531 3739
 			echo '
3532 3740
 </script>';
@@ -3537,8 +3745,9 @@  discard block
 block discarded – undo
3537 3745
 			echo '
3538 3746
 	<script>';
3539 3747
 
3540
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3541
-				echo $js_code;
3748
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3749
+							echo $js_code;
3750
+			}
3542 3751
 
3543 3752
 			echo '
3544 3753
 	</script>';
@@ -3563,8 +3772,9 @@  discard block
 block discarded – undo
3563 3772
 	foreach ($context['css_files'] as $id => $file)
3564 3773
 	{
3565 3774
 		// Last minute call! allow theme authors to disable single files.
3566
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3567
-			continue;
3775
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3776
+					continue;
3777
+		}
3568 3778
 
3569 3779
 		// By default all files don't get minimized unless the file explicitly says so!
3570 3780
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3572,12 +3782,12 @@  discard block
 block discarded – undo
3572 3782
 			$toMinify[] = $file;
3573 3783
 
3574 3784
 			// Grab a random seed.
3575
-			if (!isset($minSeed))
3576
-				$minSeed = $file['options']['seed'];
3785
+			if (!isset($minSeed)) {
3786
+							$minSeed = $file['options']['seed'];
3787
+			}
3788
+		} else {
3789
+					$normal[] = $file['fileUrl'];
3577 3790
 		}
3578
-
3579
-		else
3580
-			$normal[] = $file['fileUrl'];
3581 3791
 	}
3582 3792
 
3583 3793
 	if (!empty($toMinify))
@@ -3585,28 +3795,30 @@  discard block
 block discarded – undo
3585 3795
 		$result = custMinify($toMinify, 'css');
3586 3796
 
3587 3797
 		// Minify process couldn't work, print each individual files.
3588
-		if (!empty($result) && is_array($result))
3589
-			foreach ($result as $minFailedFile)
3798
+		if (!empty($result) && is_array($result)) {
3799
+					foreach ($result as $minFailedFile)
3590 3800
 				echo '
3591 3801
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3592
-
3593
-		else
3594
-			echo '
3802
+		} else {
3803
+					echo '
3595 3804
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3805
+		}
3596 3806
 	}
3597 3807
 
3598 3808
 	// Print the rest after the minified files.
3599
-	if (!empty($normal))
3600
-		foreach ($normal as $nf)
3809
+	if (!empty($normal)) {
3810
+			foreach ($normal as $nf)
3601 3811
 			echo '
3602 3812
 	<link rel="stylesheet" href="', $nf ,'">';
3813
+	}
3603 3814
 
3604 3815
 	if ($db_show_debug === true)
3605 3816
 	{
3606 3817
 		// Try to keep only what's useful.
3607 3818
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3608
-		foreach ($context['css_files'] as $file)
3609
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3819
+		foreach ($context['css_files'] as $file) {
3820
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3821
+		}
3610 3822
 	}
3611 3823
 
3612 3824
 	if (!empty($context['css_header']))
@@ -3614,9 +3826,10 @@  discard block
 block discarded – undo
3614 3826
 		echo '
3615 3827
 	<style>';
3616 3828
 
3617
-		foreach ($context['css_header'] as $css)
3618
-			echo $css .'
3829
+		foreach ($context['css_header'] as $css) {
3830
+					echo $css .'
3619 3831
 	';
3832
+		}
3620 3833
 
3621 3834
 		echo'
3622 3835
 	</style>';
@@ -3640,15 +3853,17 @@  discard block
 block discarded – undo
3640 3853
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3641 3854
 	$data = !empty($data) ? $data : false;
3642 3855
 
3643
-	if (empty($type) || empty($data))
3644
-		return false;
3856
+	if (empty($type) || empty($data)) {
3857
+			return false;
3858
+	}
3645 3859
 
3646 3860
 	// Did we already did this?
3647 3861
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3648 3862
 
3649 3863
 	// Already done?
3650
-	if (!empty($toCache))
3651
-		return true;
3864
+	if (!empty($toCache)) {
3865
+			return true;
3866
+	}
3652 3867
 
3653 3868
 	// No namespaces, sorry!
3654 3869
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3730,8 +3945,9 @@  discard block
 block discarded – undo
3730 3945
 	global $modSettings, $smcFunc;
3731 3946
 
3732 3947
 	// Just make up a nice hash...
3733
-	if ($new)
3734
-		return sha1(md5($filename . time()) . mt_rand());
3948
+	if ($new) {
3949
+			return sha1(md5($filename . time()) . mt_rand());
3950
+	}
3735 3951
 
3736 3952
 	// Just make sure that attachment id is only a int
3737 3953
 	$attachment_id = (int) $attachment_id;
@@ -3748,23 +3964,25 @@  discard block
 block discarded – undo
3748 3964
 				'id_attach' => $attachment_id,
3749 3965
 			));
3750 3966
 
3751
-		if ($smcFunc['db_num_rows']($request) === 0)
3752
-			return false;
3967
+		if ($smcFunc['db_num_rows']($request) === 0) {
3968
+					return false;
3969
+		}
3753 3970
 
3754 3971
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3755 3972
 		$smcFunc['db_free_result']($request);
3756 3973
 	}
3757 3974
 
3758 3975
 	// Still no hash? mmm...
3759
-	if (empty($file_hash))
3760
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3976
+	if (empty($file_hash)) {
3977
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3978
+	}
3761 3979
 
3762 3980
 	// Are we using multiple directories?
3763
-	if (is_array($modSettings['attachmentUploadDir']))
3764
-		$path = $modSettings['attachmentUploadDir'][$dir];
3765
-
3766
-	else
3767
-		$path = $modSettings['attachmentUploadDir'];
3981
+	if (is_array($modSettings['attachmentUploadDir'])) {
3982
+			$path = $modSettings['attachmentUploadDir'][$dir];
3983
+	} else {
3984
+			$path = $modSettings['attachmentUploadDir'];
3985
+	}
3768 3986
 
3769 3987
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3770 3988
 }
@@ -3779,8 +3997,9 @@  discard block
 block discarded – undo
3779 3997
 function ip2range($fullip)
3780 3998
 {
3781 3999
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3782
-	if ($fullip == 'unknown')
3783
-		$fullip = '255.255.255.255';
4000
+	if ($fullip == 'unknown') {
4001
+			$fullip = '255.255.255.255';
4002
+	}
3784 4003
 
3785 4004
 	$ip_parts = explode('-', $fullip);
3786 4005
 	$ip_array = array();
@@ -3804,10 +4023,11 @@  discard block
 block discarded – undo
3804 4023
 		$ip_array['low'] = $ip_parts[0];
3805 4024
 		$ip_array['high'] = $ip_parts[1];
3806 4025
 		return $ip_array;
3807
-	}
3808
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4026
+	} elseif (count($ip_parts) == 2) {
4027
+		// if ip 22.22.*-22.22.*
3809 4028
 	{
3810 4029
 		$valid_low = isValidIP($ip_parts[0]);
4030
+	}
3811 4031
 		$valid_high = isValidIP($ip_parts[1]);
3812 4032
 		$count = 0;
3813 4033
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3822,7 +4042,9 @@  discard block
 block discarded – undo
3822 4042
 				$ip_parts[0] .= $mode . $min;
3823 4043
 				$valid_low = isValidIP($ip_parts[0]);
3824 4044
 				$count++;
3825
-				if ($count > 9) break;
4045
+				if ($count > 9) {
4046
+					break;
4047
+				}
3826 4048
 			}
3827 4049
 		}
3828 4050
 
@@ -3836,7 +4058,9 @@  discard block
 block discarded – undo
3836 4058
 				$ip_parts[1] .= $mode . $max;
3837 4059
 				$valid_high = isValidIP($ip_parts[1]);
3838 4060
 				$count++;
3839
-				if ($count > 9) break;
4061
+				if ($count > 9) {
4062
+					break;
4063
+				}
3840 4064
 			}
3841 4065
 		}
3842 4066
 
@@ -3861,46 +4085,54 @@  discard block
 block discarded – undo
3861 4085
 {
3862 4086
 	global $modSettings;
3863 4087
 
3864
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3865
-		return $host;
4088
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4089
+			return $host;
4090
+	}
3866 4091
 	$t = microtime();
3867 4092
 
3868 4093
 	// Try the Linux host command, perhaps?
3869 4094
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3870 4095
 	{
3871
-		if (!isset($modSettings['host_to_dis']))
3872
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3873
-		else
3874
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4096
+		if (!isset($modSettings['host_to_dis'])) {
4097
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4098
+		} else {
4099
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4100
+		}
3875 4101
 
3876 4102
 		// Did host say it didn't find anything?
3877
-		if (strpos($test, 'not found') !== false)
3878
-			$host = '';
4103
+		if (strpos($test, 'not found') !== false) {
4104
+					$host = '';
4105
+		}
3879 4106
 		// Invalid server option?
3880
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3881
-			updateSettings(array('host_to_dis' => 1));
4107
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4108
+					updateSettings(array('host_to_dis' => 1));
4109
+		}
3882 4110
 		// Maybe it found something, after all?
3883
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3884
-			$host = $match[1];
4111
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4112
+					$host = $match[1];
4113
+		}
3885 4114
 	}
3886 4115
 
3887 4116
 	// This is nslookup; usually only Windows, but possibly some Unix?
3888 4117
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3889 4118
 	{
3890 4119
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3891
-		if (strpos($test, 'Non-existent domain') !== false)
3892
-			$host = '';
3893
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3894
-			$host = $match[1];
4120
+		if (strpos($test, 'Non-existent domain') !== false) {
4121
+					$host = '';
4122
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4123
+					$host = $match[1];
4124
+		}
3895 4125
 	}
3896 4126
 
3897 4127
 	// This is the last try :/.
3898
-	if (!isset($host) || $host === false)
3899
-		$host = @gethostbyaddr($ip);
4128
+	if (!isset($host) || $host === false) {
4129
+			$host = @gethostbyaddr($ip);
4130
+	}
3900 4131
 
3901 4132
 	// It took a long time, so let's cache it!
3902
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3903
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4133
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4134
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4135
+	}
3904 4136
 
3905 4137
 	return $host;
3906 4138
 }
@@ -3936,20 +4168,21 @@  discard block
 block discarded – undo
3936 4168
 			{
3937 4169
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3938 4170
 				$total = 0;
3939
-				for ($i = 0; $i < $max_chars; $i++)
3940
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4171
+				for ($i = 0; $i < $max_chars; $i++) {
4172
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4173
+				}
3941 4174
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3942 4175
 			}
3943 4176
 		}
3944 4177
 		return array_unique($returned_ints);
3945
-	}
3946
-	else
4178
+	} else
3947 4179
 	{
3948 4180
 		// Trim characters before and after and add slashes for database insertion.
3949 4181
 		$returned_words = array();
3950
-		foreach ($words as $word)
3951
-			if (($word = trim($word, '-_\'')) !== '')
4182
+		foreach ($words as $word) {
4183
+					if (($word = trim($word, '-_\'')) !== '')
3952 4184
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4185
+		}
3953 4186
 
3954 4187
 		// Filter out all words that occur more than once.
3955 4188
 		return array_unique($returned_words);
@@ -3971,16 +4204,18 @@  discard block
 block discarded – undo
3971 4204
 	global $settings, $txt;
3972 4205
 
3973 4206
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3974
-	if (function_exists('template_create_button') && !$force_use)
3975
-		return template_create_button($name, $alt, $label = '', $custom = '');
4207
+	if (function_exists('template_create_button') && !$force_use) {
4208
+			return template_create_button($name, $alt, $label = '', $custom = '');
4209
+	}
3976 4210
 
3977
-	if (!$settings['use_image_buttons'])
3978
-		return $txt[$alt];
3979
-	elseif (!empty($settings['use_buttons']))
3980
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3981
-	else
3982
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3983
-}
4211
+	if (!$settings['use_image_buttons']) {
4212
+			return $txt[$alt];
4213
+	} elseif (!empty($settings['use_buttons'])) {
4214
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4215
+	} else {
4216
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4217
+	}
4218
+	}
3984 4219
 
3985 4220
 /**
3986 4221
  * Sets up all of the top menu buttons
@@ -4023,9 +4258,10 @@  discard block
 block discarded – undo
4023 4258
 	var user_menus = new smc_PopupMenu();
4024 4259
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4025 4260
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4026
-		if ($context['allow_pm'])
4027
-			addInlineJavaScript('
4261
+		if ($context['allow_pm']) {
4262
+					addInlineJavaScript('
4028 4263
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4264
+		}
4029 4265
 
4030 4266
 		if (!empty($modSettings['enable_ajax_alerts']))
4031 4267
 		{
@@ -4185,88 +4421,96 @@  discard block
 block discarded – undo
4185 4421
 
4186 4422
 		// Now we put the buttons in the context so the theme can use them.
4187 4423
 		$menu_buttons = array();
4188
-		foreach ($buttons as $act => $button)
4189
-			if (!empty($button['show']))
4424
+		foreach ($buttons as $act => $button) {
4425
+					if (!empty($button['show']))
4190 4426
 			{
4191 4427
 				$button['active_button'] = false;
4428
+		}
4192 4429
 
4193 4430
 				// This button needs some action.
4194
-				if (isset($button['action_hook']))
4195
-					$needs_action_hook = true;
4431
+				if (isset($button['action_hook'])) {
4432
+									$needs_action_hook = true;
4433
+				}
4196 4434
 
4197 4435
 				// Make sure the last button truly is the last button.
4198 4436
 				if (!empty($button['is_last']))
4199 4437
 				{
4200
-					if (isset($last_button))
4201
-						unset($menu_buttons[$last_button]['is_last']);
4438
+					if (isset($last_button)) {
4439
+											unset($menu_buttons[$last_button]['is_last']);
4440
+					}
4202 4441
 					$last_button = $act;
4203 4442
 				}
4204 4443
 
4205 4444
 				// Go through the sub buttons if there are any.
4206
-				if (!empty($button['sub_buttons']))
4207
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4445
+				if (!empty($button['sub_buttons'])) {
4446
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4208 4447
 					{
4209 4448
 						if (empty($subbutton['show']))
4210 4449
 							unset($button['sub_buttons'][$key]);
4450
+				}
4211 4451
 
4212 4452
 						// 2nd level sub buttons next...
4213 4453
 						if (!empty($subbutton['sub_buttons']))
4214 4454
 						{
4215 4455
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4216 4456
 							{
4217
-								if (empty($sub_button2['show']))
4218
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4457
+								if (empty($sub_button2['show'])) {
4458
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4459
+								}
4219 4460
 							}
4220 4461
 						}
4221 4462
 					}
4222 4463
 
4223 4464
 				// Does this button have its own icon?
4224
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4225
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4226
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4227
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4228
-				elseif (isset($button['icon']))
4229
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4230
-				else
4231
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4465
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4466
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4467
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4468
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4469
+				} elseif (isset($button['icon'])) {
4470
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4471
+				} else {
4472
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4473
+				}
4232 4474
 
4233 4475
 				$menu_buttons[$act] = $button;
4234 4476
 			}
4235 4477
 
4236
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4237
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4478
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4479
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4480
+		}
4238 4481
 	}
4239 4482
 
4240 4483
 	$context['menu_buttons'] = $menu_buttons;
4241 4484
 
4242 4485
 	// Logging out requires the session id in the url.
4243
-	if (isset($context['menu_buttons']['logout']))
4244
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4486
+	if (isset($context['menu_buttons']['logout'])) {
4487
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4488
+	}
4245 4489
 
4246 4490
 	// Figure out which action we are doing so we can set the active tab.
4247 4491
 	// Default to home.
4248 4492
 	$current_action = 'home';
4249 4493
 
4250
-	if (isset($context['menu_buttons'][$context['current_action']]))
4251
-		$current_action = $context['current_action'];
4252
-	elseif ($context['current_action'] == 'search2')
4253
-		$current_action = 'search';
4254
-	elseif ($context['current_action'] == 'theme')
4255
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4256
-	elseif ($context['current_action'] == 'register2')
4257
-		$current_action = 'register';
4258
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4259
-		$current_action = 'login';
4260
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4261
-		$current_action = 'moderate';
4494
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4495
+			$current_action = $context['current_action'];
4496
+	} elseif ($context['current_action'] == 'search2') {
4497
+			$current_action = 'search';
4498
+	} elseif ($context['current_action'] == 'theme') {
4499
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4500
+	} elseif ($context['current_action'] == 'register2') {
4501
+			$current_action = 'register';
4502
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4503
+			$current_action = 'login';
4504
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4505
+			$current_action = 'moderate';
4506
+	}
4262 4507
 
4263 4508
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4264 4509
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4265 4510
 	{
4266 4511
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4267 4512
 		$context[$current_action] = true;
4268
-	}
4269
-	elseif ($context['current_action'] == 'pm')
4513
+	} elseif ($context['current_action'] == 'pm')
4270 4514
 	{
4271 4515
 		$current_action = 'self_pm';
4272 4516
 		$context['self_pm'] = true;
@@ -4309,12 +4553,14 @@  discard block
 block discarded – undo
4309 4553
 	}
4310 4554
 
4311 4555
 	// Not all actions are simple.
4312
-	if (!empty($needs_action_hook))
4313
-		call_integration_hook('integrate_current_action', array(&$current_action));
4556
+	if (!empty($needs_action_hook)) {
4557
+			call_integration_hook('integrate_current_action', array(&$current_action));
4558
+	}
4314 4559
 
4315
-	if (isset($context['menu_buttons'][$current_action]))
4316
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4317
-}
4560
+	if (isset($context['menu_buttons'][$current_action])) {
4561
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4562
+	}
4563
+	}
4318 4564
 
4319 4565
 /**
4320 4566
  * Generate a random seed and ensure it's stored in settings.
@@ -4338,30 +4584,35 @@  discard block
 block discarded – undo
4338 4584
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4339 4585
 	global $context, $txt;
4340 4586
 
4341
-	if ($db_show_debug === true)
4342
-		$context['debug']['hooks'][] = $hook;
4587
+	if ($db_show_debug === true) {
4588
+			$context['debug']['hooks'][] = $hook;
4589
+	}
4343 4590
 
4344 4591
 	// Need to have some control.
4345
-	if (!isset($context['instances']))
4346
-		$context['instances'] = array();
4592
+	if (!isset($context['instances'])) {
4593
+			$context['instances'] = array();
4594
+	}
4347 4595
 
4348 4596
 	$results = array();
4349
-	if (empty($modSettings[$hook]))
4350
-		return $results;
4597
+	if (empty($modSettings[$hook])) {
4598
+			return $results;
4599
+	}
4351 4600
 
4352 4601
 	$functions = explode(',', $modSettings[$hook]);
4353 4602
 	// Loop through each function.
4354 4603
 	foreach ($functions as $function)
4355 4604
 	{
4356 4605
 		// Hook has been marked as "disabled". Skip it!
4357
-		if (strpos($function, '!') !== false)
4358
-			continue;
4606
+		if (strpos($function, '!') !== false) {
4607
+					continue;
4608
+		}
4359 4609
 
4360 4610
 		$call = call_helper($function, true);
4361 4611
 
4362 4612
 		// Is it valid?
4363
-		if (!empty($call))
4364
-			$results[$function] = call_user_func_array($call, $parameters);
4613
+		if (!empty($call)) {
4614
+					$results[$function] = call_user_func_array($call, $parameters);
4615
+		}
4365 4616
 
4366 4617
 		// Whatever it was suppose to call, it failed :(
4367 4618
 		elseif (!empty($function))
@@ -4377,8 +4628,9 @@  discard block
 block discarded – undo
4377 4628
 			}
4378 4629
 
4379 4630
 			// "Assume" the file resides on $boarddir somewhere...
4380
-			else
4381
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4631
+			else {
4632
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4633
+			}
4382 4634
 		}
4383 4635
 	}
4384 4636
 
@@ -4400,12 +4652,14 @@  discard block
 block discarded – undo
4400 4652
 	global $smcFunc, $modSettings;
4401 4653
 
4402 4654
 	// Any objects?
4403
-	if ($object)
4404
-		$function = $function . '#';
4655
+	if ($object) {
4656
+			$function = $function . '#';
4657
+	}
4405 4658
 
4406 4659
 	// Any files  to load?
4407
-	if (!empty($file) && is_string($file))
4408
-		$function = $file . (!empty($function) ? '|' . $function : '');
4660
+	if (!empty($file) && is_string($file)) {
4661
+			$function = $file . (!empty($function) ? '|' . $function : '');
4662
+	}
4409 4663
 
4410 4664
 	// Get the correct string.
4411 4665
 	$integration_call = $function;
@@ -4427,13 +4681,14 @@  discard block
 block discarded – undo
4427 4681
 		if (!empty($current_functions))
4428 4682
 		{
4429 4683
 			$current_functions = explode(',', $current_functions);
4430
-			if (in_array($integration_call, $current_functions))
4431
-				return;
4684
+			if (in_array($integration_call, $current_functions)) {
4685
+							return;
4686
+			}
4432 4687
 
4433 4688
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4689
+		} else {
4690
+					$permanent_functions = array($integration_call);
4434 4691
 		}
4435
-		else
4436
-			$permanent_functions = array($integration_call);
4437 4692
 
4438 4693
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4439 4694
 	}
@@ -4442,8 +4697,9 @@  discard block
 block discarded – undo
4442 4697
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4443 4698
 
4444 4699
 	// Do nothing, if it's already there.
4445
-	if (in_array($integration_call, $functions))
4446
-		return;
4700
+	if (in_array($integration_call, $functions)) {
4701
+			return;
4702
+	}
4447 4703
 
4448 4704
 	$functions[] = $integration_call;
4449 4705
 	$modSettings[$hook] = implode(',', $functions);
@@ -4466,12 +4722,14 @@  discard block
 block discarded – undo
4466 4722
 	global $smcFunc, $modSettings;
4467 4723
 
4468 4724
 	// Any objects?
4469
-	if ($object)
4470
-		$function = $function . '#';
4725
+	if ($object) {
4726
+			$function = $function . '#';
4727
+	}
4471 4728
 
4472 4729
 	// Any files  to load?
4473
-	if (!empty($file) && is_string($file))
4474
-		$function = $file . '|' . $function;
4730
+	if (!empty($file) && is_string($file)) {
4731
+			$function = $file . '|' . $function;
4732
+	}
4475 4733
 
4476 4734
 	// Get the correct string.
4477 4735
 	$integration_call = $function;
@@ -4492,16 +4750,18 @@  discard block
 block discarded – undo
4492 4750
 	{
4493 4751
 		$current_functions = explode(',', $current_functions);
4494 4752
 
4495
-		if (in_array($integration_call, $current_functions))
4496
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4753
+		if (in_array($integration_call, $current_functions)) {
4754
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4755
+		}
4497 4756
 	}
4498 4757
 
4499 4758
 	// Turn the function list into something usable.
4500 4759
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4501 4760
 
4502 4761
 	// You can only remove it if it's available.
4503
-	if (!in_array($integration_call, $functions))
4504
-		return;
4762
+	if (!in_array($integration_call, $functions)) {
4763
+			return;
4764
+	}
4505 4765
 
4506 4766
 	$functions = array_diff($functions, array($integration_call));
4507 4767
 	$modSettings[$hook] = implode(',', $functions);
@@ -4522,17 +4782,20 @@  discard block
 block discarded – undo
4522 4782
 	global $context, $smcFunc, $txt, $db_show_debug;
4523 4783
 
4524 4784
 	// Really?
4525
-	if (empty($string))
4526
-		return false;
4785
+	if (empty($string)) {
4786
+			return false;
4787
+	}
4527 4788
 
4528 4789
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4529 4790
 	// A closure? should be a callable one.
4530
-	if (is_array($string) || $string instanceof Closure)
4531
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4791
+	if (is_array($string) || $string instanceof Closure) {
4792
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4793
+	}
4532 4794
 
4533 4795
 	// No full objects, sorry! pass a method or a property instead!
4534
-	if (is_object($string))
4535
-		return false;
4796
+	if (is_object($string)) {
4797
+			return false;
4798
+	}
4536 4799
 
4537 4800
 	// Stay vitaminized my friends...
4538 4801
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4541,8 +4804,9 @@  discard block
 block discarded – undo
4541 4804
 	$string = load_file($string);
4542 4805
 
4543 4806
 	// Loaded file failed
4544
-	if (empty($string))
4545
-		return false;
4807
+	if (empty($string)) {
4808
+			return false;
4809
+	}
4546 4810
 
4547 4811
 	// Found a method.
4548 4812
 	if (strpos($string, '::') !== false)
@@ -4563,8 +4827,9 @@  discard block
 block discarded – undo
4563 4827
 				// Add another one to the list.
4564 4828
 				if ($db_show_debug === true)
4565 4829
 				{
4566
-					if (!isset($context['debug']['instances']))
4567
-						$context['debug']['instances'] = array();
4830
+					if (!isset($context['debug']['instances'])) {
4831
+											$context['debug']['instances'] = array();
4832
+					}
4568 4833
 
4569 4834
 					$context['debug']['instances'][$class] = $class;
4570 4835
 				}
@@ -4574,13 +4839,15 @@  discard block
 block discarded – undo
4574 4839
 		}
4575 4840
 
4576 4841
 		// Right then. This is a call to a static method.
4577
-		else
4578
-			$func = array($class, $method);
4842
+		else {
4843
+					$func = array($class, $method);
4844
+		}
4579 4845
 	}
4580 4846
 
4581 4847
 	// Nope! just a plain regular function.
4582
-	else
4583
-		$func = $string;
4848
+	else {
4849
+			$func = $string;
4850
+	}
4584 4851
 
4585 4852
 	// Right, we got what we need, time to do some checks.
4586 4853
 	if (!is_callable($func, false, $callable_name))
@@ -4596,17 +4863,18 @@  discard block
 block discarded – undo
4596 4863
 	else
4597 4864
 	{
4598 4865
 		// What are we gonna do about it?
4599
-		if ($return)
4600
-			return $func;
4866
+		if ($return) {
4867
+					return $func;
4868
+		}
4601 4869
 
4602 4870
 		// If this is a plain function, avoid the heat of calling call_user_func().
4603 4871
 		else
4604 4872
 		{
4605
-			if (is_array($func))
4606
-				call_user_func($func);
4607
-
4608
-			else
4609
-				$func();
4873
+			if (is_array($func)) {
4874
+							call_user_func($func);
4875
+			} else {
4876
+							$func();
4877
+			}
4610 4878
 		}
4611 4879
 	}
4612 4880
 }
@@ -4623,31 +4891,34 @@  discard block
 block discarded – undo
4623 4891
 {
4624 4892
 	global $sourcedir, $txt, $boarddir, $settings;
4625 4893
 
4626
-	if (empty($string))
4627
-		return false;
4894
+	if (empty($string)) {
4895
+			return false;
4896
+	}
4628 4897
 
4629 4898
 	if (strpos($string, '|') !== false)
4630 4899
 	{
4631 4900
 		list ($file, $string) = explode('|', $string);
4632 4901
 
4633 4902
 		// Match the wildcards to their regular vars.
4634
-		if (empty($settings['theme_dir']))
4635
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4636
-
4637
-		else
4638
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4903
+		if (empty($settings['theme_dir'])) {
4904
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4905
+		} else {
4906
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4907
+		}
4639 4908
 
4640 4909
 		// Load the file if it can be loaded.
4641
-		if (file_exists($absPath))
4642
-			require_once($absPath);
4910
+		if (file_exists($absPath)) {
4911
+					require_once($absPath);
4912
+		}
4643 4913
 
4644 4914
 		// No? try a fallback to $sourcedir
4645 4915
 		else
4646 4916
 		{
4647 4917
 			$absPath = $sourcedir .'/'. $file;
4648 4918
 
4649
-			if (file_exists($absPath))
4650
-				require_once($absPath);
4919
+			if (file_exists($absPath)) {
4920
+							require_once($absPath);
4921
+			}
4651 4922
 
4652 4923
 			// Sorry, can't do much for you at this point.
4653 4924
 			else
@@ -4674,8 +4945,9 @@  discard block
 block discarded – undo
4674 4945
 	global $user_info, $smcFunc;
4675 4946
 
4676 4947
 	// Make sure we have something to work with.
4677
-	if (empty($topic))
4678
-		return array();
4948
+	if (empty($topic)) {
4949
+			return array();
4950
+	}
4679 4951
 
4680 4952
 
4681 4953
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4698,8 +4970,9 @@  discard block
 block discarded – undo
4698 4970
 				'topic' => $topic,
4699 4971
 			)
4700 4972
 		);
4701
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4702
-			$temp[] = (int) $row['content_id'];
4973
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4974
+					$temp[] = (int) $row['content_id'];
4975
+		}
4703 4976
 
4704 4977
 		cache_put_data($cache_key, $temp, $ttl);
4705 4978
 	}
@@ -4720,8 +4993,9 @@  discard block
 block discarded – undo
4720 4993
 {
4721 4994
 	global $context;
4722 4995
 
4723
-	if (empty($string))
4724
-		return $string;
4996
+	if (empty($string)) {
4997
+			return $string;
4998
+	}
4725 4999
 
4726 5000
 	// UTF-8 occurences of MS special characters
4727 5001
 	$findchars_utf8 = array(
@@ -4762,10 +5036,11 @@  discard block
 block discarded – undo
4762 5036
 		'--',	// &mdash;
4763 5037
 	);
4764 5038
 
4765
-	if ($context['utf8'])
4766
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4767
-	else
4768
-		$string = str_replace($findchars_iso, $replacechars, $string);
5039
+	if ($context['utf8']) {
5040
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5041
+	} else {
5042
+			$string = str_replace($findchars_iso, $replacechars, $string);
5043
+	}
4769 5044
 
4770 5045
 	return $string;
4771 5046
 }
@@ -4784,49 +5059,59 @@  discard block
 block discarded – undo
4784 5059
 {
4785 5060
 	global $context;
4786 5061
 
4787
-	if (!isset($matches[2]))
4788
-		return '';
5062
+	if (!isset($matches[2])) {
5063
+			return '';
5064
+	}
4789 5065
 
4790 5066
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4791 5067
 
4792 5068
 	// remove left to right / right to left overrides
4793
-	if ($num === 0x202D || $num === 0x202E)
4794
-		return '';
5069
+	if ($num === 0x202D || $num === 0x202E) {
5070
+			return '';
5071
+	}
4795 5072
 
4796 5073
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4797
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4798
-		return '&#' . $num . ';';
5074
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5075
+			return '&#' . $num . ';';
5076
+	}
4799 5077
 
4800 5078
 	if (empty($context['utf8']))
4801 5079
 	{
4802 5080
 		// no control characters
4803
-		if ($num < 0x20)
4804
-			return '';
5081
+		if ($num < 0x20) {
5082
+					return '';
5083
+		}
4805 5084
 		// text is text
4806
-		elseif ($num < 0x80)
4807
-			return chr($num);
5085
+		elseif ($num < 0x80) {
5086
+					return chr($num);
5087
+		}
4808 5088
 		// all others get html-ised
4809
-		else
4810
-			return '&#' . $matches[2] . ';';
4811
-	}
4812
-	else
5089
+		else {
5090
+					return '&#' . $matches[2] . ';';
5091
+		}
5092
+	} else
4813 5093
 	{
4814 5094
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4815 5095
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4816
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4817
-			return '';
5096
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5097
+					return '';
5098
+		}
4818 5099
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4819
-		elseif ($num < 0x80)
4820
-			return chr($num);
5100
+		elseif ($num < 0x80) {
5101
+					return chr($num);
5102
+		}
4821 5103
 		// <0x800 (2048)
4822
-		elseif ($num < 0x800)
4823
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5104
+		elseif ($num < 0x800) {
5105
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5106
+		}
4824 5107
 		// < 0x10000 (65536)
4825
-		elseif ($num < 0x10000)
4826
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5108
+		elseif ($num < 0x10000) {
5109
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5110
+		}
4827 5111
 		// <= 0x10FFFF (1114111)
4828
-		else
4829
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5112
+		else {
5113
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5114
+		}
4830 5115
 	}
4831 5116
 }
4832 5117
 
@@ -4842,28 +5127,34 @@  discard block
 block discarded – undo
4842 5127
  */
4843 5128
 function fixchar__callback($matches)
4844 5129
 {
4845
-	if (!isset($matches[1]))
4846
-		return '';
5130
+	if (!isset($matches[1])) {
5131
+			return '';
5132
+	}
4847 5133
 
4848 5134
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4849 5135
 
4850 5136
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4851 5137
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4852
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4853
-		return '';
5138
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5139
+			return '';
5140
+	}
4854 5141
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4855
-	elseif ($num < 0x80)
4856
-		return chr($num);
5142
+	elseif ($num < 0x80) {
5143
+			return chr($num);
5144
+	}
4857 5145
 	// <0x800 (2048)
4858
-	elseif ($num < 0x800)
4859
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5146
+	elseif ($num < 0x800) {
5147
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5148
+	}
4860 5149
 	// < 0x10000 (65536)
4861
-	elseif ($num < 0x10000)
4862
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5150
+	elseif ($num < 0x10000) {
5151
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5152
+	}
4863 5153
 	// <= 0x10FFFF (1114111)
4864
-	else
4865
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4866
-}
5154
+	else {
5155
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5156
+	}
5157
+	}
4867 5158
 
4868 5159
 /**
4869 5160
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4876,17 +5167,19 @@  discard block
 block discarded – undo
4876 5167
  */
4877 5168
 function entity_fix__callback($matches)
4878 5169
 {
4879
-	if (!isset($matches[2]))
4880
-		return '';
5170
+	if (!isset($matches[2])) {
5171
+			return '';
5172
+	}
4881 5173
 
4882 5174
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4883 5175
 
4884 5176
 	// we don't allow control characters, characters out of range, byte markers, etc
4885
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4886
-		return '';
4887
-	else
4888
-		return '&#' . $num . ';';
4889
-}
5177
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5178
+			return '';
5179
+	} else {
5180
+			return '&#' . $num . ';';
5181
+	}
5182
+	}
4890 5183
 
4891 5184
 /**
4892 5185
  * Return a Gravatar URL based on
@@ -4910,18 +5203,23 @@  discard block
 block discarded – undo
4910 5203
 		$ratings = array('G', 'PG', 'R', 'X');
4911 5204
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4912 5205
 		$url_params = array();
4913
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4914
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4915
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4916
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4917
-		if (!empty($modSettings['avatar_max_width_external']))
4918
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4919
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4920
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5206
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5207
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5208
+		}
5209
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5210
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5211
+		}
5212
+		if (!empty($modSettings['avatar_max_width_external'])) {
5213
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5214
+		}
5215
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5216
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4921 5217
 				$size_string = $modSettings['avatar_max_height_external'];
5218
+		}
4922 5219
 
4923
-		if (!empty($size_string))
4924
-			$url_params[] = 's=' . $size_string;
5220
+		if (!empty($size_string)) {
5221
+					$url_params[] = 's=' . $size_string;
5222
+		}
4925 5223
 	}
4926 5224
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4927 5225
 
@@ -4940,22 +5238,26 @@  discard block
 block discarded – undo
4940 5238
 	static $timezones = null, $lastwhen = null;
4941 5239
 
4942 5240
 	// No point doing this over if we already did it once
4943
-	if (!empty($timezones) && $when == $lastwhen)
4944
-		return $timezones;
4945
-	else
4946
-		$lastwhen = $when;
5241
+	if (!empty($timezones) && $when == $lastwhen) {
5242
+			return $timezones;
5243
+	} else {
5244
+			$lastwhen = $when;
5245
+	}
4947 5246
 
4948 5247
 	// Parseable datetime string?
4949
-	if (is_int($timestamp = strtotime($when)))
4950
-		$when = $timestamp;
5248
+	if (is_int($timestamp = strtotime($when))) {
5249
+			$when = $timestamp;
5250
+	}
4951 5251
 
4952 5252
 	// A Unix timestamp?
4953
-	elseif (is_numeric($when))
4954
-		$when = intval($when);
5253
+	elseif (is_numeric($when)) {
5254
+			$when = intval($when);
5255
+	}
4955 5256
 
4956 5257
 	// Invalid value? Just get current Unix timestamp.
4957
-	else
4958
-		$when = time();
5258
+	else {
5259
+			$when = time();
5260
+	}
4959 5261
 
4960 5262
 	// We'll need these too
4961 5263
 	$date_when = date_create('@' . $when);
@@ -5019,8 +5321,9 @@  discard block
 block discarded – undo
5019 5321
 	foreach ($priority_countries as $country)
5020 5322
 	{
5021 5323
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5022
-		if (!empty($country_tzids))
5023
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5324
+		if (!empty($country_tzids)) {
5325
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5326
+		}
5024 5327
 	}
5025 5328
 
5026 5329
 	// Process the preferred timezones first, then the rest.
@@ -5030,8 +5333,9 @@  discard block
 block discarded – undo
5030 5333
 	foreach ($tzids as $tzid)
5031 5334
 	{
5032 5335
 		// We don't want UTC right now
5033
-		if ($tzid == 'UTC')
5034
-			continue;
5336
+		if ($tzid == 'UTC') {
5337
+					continue;
5338
+		}
5035 5339
 
5036 5340
 		$tz = timezone_open($tzid);
5037 5341
 
@@ -5046,12 +5350,14 @@  discard block
 block discarded – undo
5046 5350
 		$tzgeo = timezone_location_get($tz);
5047 5351
 
5048 5352
 		// Don't overwrite our preferred tzids
5049
-		if (empty($zones[$tzkey]['tzid']))
5050
-			$zones[$tzkey]['tzid'] = $tzid;
5353
+		if (empty($zones[$tzkey]['tzid'])) {
5354
+					$zones[$tzkey]['tzid'] = $tzid;
5355
+		}
5051 5356
 
5052 5357
 		// A time zone from a prioritized country?
5053
-		if (in_array($tzid, $priority_tzids))
5054
-			$priority_zones[$tzkey] = true;
5358
+		if (in_array($tzid, $priority_tzids)) {
5359
+					$priority_zones[$tzkey] = true;
5360
+		}
5055 5361
 
5056 5362
 		// Keep track of the location and offset for this tzid
5057 5363
 		$tzid_parts = explode('/', $tzid);
@@ -5072,15 +5378,17 @@  discard block
 block discarded – undo
5072 5378
 
5073 5379
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5074 5380
 
5075
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5076
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5077
-		else
5078
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5381
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5382
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5383
+		} else {
5384
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5385
+		}
5079 5386
 
5080
-		if (isset($priority_zones[$tzkey]))
5081
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5082
-		else
5083
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5387
+		if (isset($priority_zones[$tzkey])) {
5388
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5389
+		} else {
5390
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5391
+		}
5084 5392
 	}
5085 5393
 
5086 5394
 	$timezones = array_merge(
@@ -5134,9 +5442,9 @@  discard block
 block discarded – undo
5134 5442
 			'Indian/Kerguelen' => 'TFT',
5135 5443
 		);
5136 5444
 
5137
-		if (!empty($missing_tz_abbrs[$tzid]))
5138
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5139
-		else
5445
+		if (!empty($missing_tz_abbrs[$tzid])) {
5446
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5447
+		} else
5140 5448
 		{
5141 5449
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5142 5450
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5164,8 +5472,9 @@  discard block
 block discarded – undo
5164 5472
  */
5165 5473
 function inet_ptod($ip_address)
5166 5474
 {
5167
-	if (!isValidIP($ip_address))
5168
-		return $ip_address;
5475
+	if (!isValidIP($ip_address)) {
5476
+			return $ip_address;
5477
+	}
5169 5478
 
5170 5479
 	$bin = inet_pton($ip_address);
5171 5480
 	return $bin;
@@ -5177,13 +5486,15 @@  discard block
 block discarded – undo
5177 5486
  */
5178 5487
 function inet_dtop($bin)
5179 5488
 {
5180
-	if(empty($bin))
5181
-		return '';
5489
+	if(empty($bin)) {
5490
+			return '';
5491
+	}
5182 5492
 
5183 5493
 	global $db_type;
5184 5494
 
5185
-	if ($db_type == 'postgresql')
5186
-		return $bin;
5495
+	if ($db_type == 'postgresql') {
5496
+			return $bin;
5497
+	}
5187 5498
 
5188 5499
 	$ip_address = inet_ntop($bin);
5189 5500
 
@@ -5208,26 +5519,32 @@  discard block
 block discarded – undo
5208 5519
  */
5209 5520
 function _safe_serialize($value)
5210 5521
 {
5211
-	if(is_null($value))
5212
-		return 'N;';
5522
+	if(is_null($value)) {
5523
+			return 'N;';
5524
+	}
5213 5525
 
5214
-	if(is_bool($value))
5215
-		return 'b:'. (int) $value .';';
5526
+	if(is_bool($value)) {
5527
+			return 'b:'. (int) $value .';';
5528
+	}
5216 5529
 
5217
-	if(is_int($value))
5218
-		return 'i:'. $value .';';
5530
+	if(is_int($value)) {
5531
+			return 'i:'. $value .';';
5532
+	}
5219 5533
 
5220
-	if(is_float($value))
5221
-		return 'd:'. str_replace(',', '.', $value) .';';
5534
+	if(is_float($value)) {
5535
+			return 'd:'. str_replace(',', '.', $value) .';';
5536
+	}
5222 5537
 
5223
-	if(is_string($value))
5224
-		return 's:'. strlen($value) .':"'. $value .'";';
5538
+	if(is_string($value)) {
5539
+			return 's:'. strlen($value) .':"'. $value .'";';
5540
+	}
5225 5541
 
5226 5542
 	if(is_array($value))
5227 5543
 	{
5228 5544
 		$out = '';
5229
-		foreach($value as $k => $v)
5230
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5545
+		foreach($value as $k => $v) {
5546
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5547
+		}
5231 5548
 
5232 5549
 		return 'a:'. count($value) .':{'. $out .'}';
5233 5550
 	}
@@ -5253,8 +5570,9 @@  discard block
 block discarded – undo
5253 5570
 
5254 5571
 	$out = _safe_serialize($value);
5255 5572
 
5256
-	if (isset($mbIntEnc))
5257
-		mb_internal_encoding($mbIntEnc);
5573
+	if (isset($mbIntEnc)) {
5574
+			mb_internal_encoding($mbIntEnc);
5575
+	}
5258 5576
 
5259 5577
 	return $out;
5260 5578
 }
@@ -5271,8 +5589,9 @@  discard block
 block discarded – undo
5271 5589
 function _safe_unserialize($str)
5272 5590
 {
5273 5591
 	// Input  is not a string.
5274
-	if(empty($str) || !is_string($str))
5275
-		return false;
5592
+	if(empty($str) || !is_string($str)) {
5593
+			return false;
5594
+	}
5276 5595
 
5277 5596
 	$stack = array();
5278 5597
 	$expected = array();
@@ -5288,43 +5607,38 @@  discard block
 block discarded – undo
5288 5607
 	while($state != 1)
5289 5608
 	{
5290 5609
 		$type = isset($str[0]) ? $str[0] : '';
5291
-		if($type == '}')
5292
-			$str = substr($str, 1);
5293
-
5294
-		else if($type == 'N' && $str[1] == ';')
5610
+		if($type == '}') {
5611
+					$str = substr($str, 1);
5612
+		} else if($type == 'N' && $str[1] == ';')
5295 5613
 		{
5296 5614
 			$value = null;
5297 5615
 			$str = substr($str, 2);
5298
-		}
5299
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5616
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5300 5617
 		{
5301 5618
 			$value = $matches[1] == '1' ? true : false;
5302 5619
 			$str = substr($str, 4);
5303
-		}
5304
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5620
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5305 5621
 		{
5306 5622
 			$value = (int)$matches[1];
5307 5623
 			$str = $matches[2];
5308
-		}
5309
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5624
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5310 5625
 		{
5311 5626
 			$value = (float)$matches[1];
5312 5627
 			$str = $matches[3];
5313
-		}
5314
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5628
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5315 5629
 		{
5316 5630
 			$value = substr($matches[2], 0, (int)$matches[1]);
5317 5631
 			$str = substr($matches[2], (int)$matches[1] + 2);
5318
-		}
5319
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5632
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5320 5633
 		{
5321 5634
 			$expectedLength = (int)$matches[1];
5322 5635
 			$str = $matches[2];
5323 5636
 		}
5324 5637
 
5325 5638
 		// Object or unknown/malformed type.
5326
-		else
5327
-			return false;
5639
+		else {
5640
+					return false;
5641
+		}
5328 5642
 
5329 5643
 		switch($state)
5330 5644
 		{
@@ -5352,8 +5666,9 @@  discard block
 block discarded – undo
5352 5666
 				if($type == '}')
5353 5667
 				{
5354 5668
 					// Array size is less than expected.
5355
-					if(count($list) < end($expected))
5356
-						return false;
5669
+					if(count($list) < end($expected)) {
5670
+											return false;
5671
+					}
5357 5672
 
5358 5673
 					unset($list);
5359 5674
 					$list = &$stack[count($stack)-1];
@@ -5362,8 +5677,9 @@  discard block
 block discarded – undo
5362 5677
 					// Go to terminal state if we're at the end of the root array.
5363 5678
 					array_pop($expected);
5364 5679
 
5365
-					if(count($expected) == 0)
5366
-						$state = 1;
5680
+					if(count($expected) == 0) {
5681
+											$state = 1;
5682
+					}
5367 5683
 
5368 5684
 					break;
5369 5685
 				}
@@ -5371,8 +5687,9 @@  discard block
 block discarded – undo
5371 5687
 				if($type == 'i' || $type == 's')
5372 5688
 				{
5373 5689
 					// Array size exceeds expected length.
5374
-					if(count($list) >= end($expected))
5375
-						return false;
5690
+					if(count($list) >= end($expected)) {
5691
+											return false;
5692
+					}
5376 5693
 
5377 5694
 					$key = $value;
5378 5695
 					$state = 3;
@@ -5406,8 +5723,9 @@  discard block
 block discarded – undo
5406 5723
 	}
5407 5724
 
5408 5725
 	// Trailing data in input.
5409
-	if(!empty($str))
5410
-		return false;
5726
+	if(!empty($str)) {
5727
+			return false;
5728
+	}
5411 5729
 
5412 5730
 	return $data;
5413 5731
 }
@@ -5430,8 +5748,9 @@  discard block
 block discarded – undo
5430 5748
 
5431 5749
 	$out = _safe_unserialize($str);
5432 5750
 
5433
-	if (isset($mbIntEnc))
5434
-		mb_internal_encoding($mbIntEnc);
5751
+	if (isset($mbIntEnc)) {
5752
+			mb_internal_encoding($mbIntEnc);
5753
+	}
5435 5754
 
5436 5755
 	return $out;
5437 5756
 }
@@ -5446,12 +5765,14 @@  discard block
 block discarded – undo
5446 5765
 function smf_chmod($file, $value = 0)
5447 5766
 {
5448 5767
 	// No file? no checks!
5449
-	if (empty($file))
5450
-		return false;
5768
+	if (empty($file)) {
5769
+			return false;
5770
+	}
5451 5771
 
5452 5772
 	// Already writable?
5453
-	if (is_writable($file))
5454
-		return true;
5773
+	if (is_writable($file)) {
5774
+			return true;
5775
+	}
5455 5776
 
5456 5777
 	// Do we have a file or a dir?
5457 5778
 	$isDir = is_dir($file);
@@ -5467,10 +5788,9 @@  discard block
 block discarded – undo
5467 5788
 		{
5468 5789
 			$isWritable = true;
5469 5790
 			break;
5791
+		} else {
5792
+					@chmod($file, $val);
5470 5793
 		}
5471
-
5472
-		else
5473
-			@chmod($file, $val);
5474 5794
 	}
5475 5795
 
5476 5796
 	return $isWritable;
@@ -5489,8 +5809,9 @@  discard block
 block discarded – undo
5489 5809
 	global $txt;
5490 5810
 
5491 5811
 	// Come on...
5492
-	if (empty($json) || !is_string($json))
5493
-		return array();
5812
+	if (empty($json) || !is_string($json)) {
5813
+			return array();
5814
+	}
5494 5815
 
5495 5816
 	$returnArray = @json_decode($json, $returnAsArray);
5496 5817
 
@@ -5528,11 +5849,11 @@  discard block
 block discarded – undo
5528 5849
 		$jsonDebug = $jsonDebug[0];
5529 5850
 		loadLanguage('Errors');
5530 5851
 
5531
-		if (!empty($jsonDebug))
5532
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5533
-
5534
-		else
5535
-			log_error($txt['json_'. $jsonError], 'critical');
5852
+		if (!empty($jsonDebug)) {
5853
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5854
+		} else {
5855
+					log_error($txt['json_'. $jsonError], 'critical');
5856
+		}
5536 5857
 
5537 5858
 		// Everyone expects an array.
5538 5859
 		return array();
@@ -5562,8 +5883,9 @@  discard block
 block discarded – undo
5562 5883
 	global $db_show_debug, $modSettings;
5563 5884
 
5564 5885
 	// Defensive programming anyone?
5565
-	if (empty($data))
5566
-		return false;
5886
+	if (empty($data)) {
5887
+			return false;
5888
+	}
5567 5889
 
5568 5890
 	// Don't need extra stuff...
5569 5891
 	$db_show_debug = false;
@@ -5571,11 +5893,11 @@  discard block
 block discarded – undo
5571 5893
 	// Kill anything else.
5572 5894
 	ob_end_clean();
5573 5895
 
5574
-	if (!empty($modSettings['CompressedOutput']))
5575
-		@ob_start('ob_gzhandler');
5576
-
5577
-	else
5578
-		ob_start();
5896
+	if (!empty($modSettings['CompressedOutput'])) {
5897
+			@ob_start('ob_gzhandler');
5898
+	} else {
5899
+			ob_start();
5900
+	}
5579 5901
 
5580 5902
 	// Set the header.
5581 5903
 	header($type);
@@ -5607,8 +5929,9 @@  discard block
 block discarded – undo
5607 5929
 	static $done = false;
5608 5930
 
5609 5931
 	// If we don't need to do anything, don't
5610
-	if (!$update && $done)
5611
-		return;
5932
+	if (!$update && $done) {
5933
+			return;
5934
+	}
5612 5935
 
5613 5936
 	// Should we get a new copy of the official list of TLDs?
5614 5937
 	if ($update)
@@ -5629,10 +5952,11 @@  discard block
 block discarded – undo
5629 5952
 		// Clean $tlds and convert it to an array
5630 5953
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5631 5954
 			$line = trim($line);
5632
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5633
-				return false;
5634
-			else
5635
-				return true;
5955
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5956
+							return false;
5957
+			} else {
5958
+							return true;
5959
+			}
5636 5960
 		});
5637 5961
 
5638 5962
 		// Convert Punycode to Unicode
@@ -5686,8 +6010,9 @@  discard block
 block discarded – undo
5686 6010
 						$idx += $digit * $w;
5687 6011
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5688 6012
 
5689
-						if ($digit < $t)
5690
-							break;
6013
+						if ($digit < $t) {
6014
+													break;
6015
+						}
5691 6016
 
5692 6017
 						$w = (int) ($w * ($base - $t));
5693 6018
 					}
@@ -5696,8 +6021,9 @@  discard block
 block discarded – undo
5696 6021
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5697 6022
 					$delta += intval($delta / ($deco_len + 1));
5698 6023
 
5699
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5700
-						$delta = intval($delta / ($base - $tmin));
6024
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6025
+											$delta = intval($delta / ($base - $tmin));
6026
+					}
5701 6027
 
5702 6028
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5703 6029
 					$is_first = false;
@@ -5706,8 +6032,9 @@  discard block
 block discarded – undo
5706 6032
 
5707 6033
 					if ($deco_len > 0)
5708 6034
 					{
5709
-						for ($i = $deco_len; $i > $idx; $i--)
5710
-							$decoded[$i] = $decoded[($i - 1)];
6035
+						for ($i = $deco_len; $i > $idx; $i--) {
6036
+													$decoded[$i] = $decoded[($i - 1)];
6037
+						}
5711 6038
 					}
5712 6039
 					$decoded[$idx++] = $char;
5713 6040
 				}
@@ -5715,24 +6042,29 @@  discard block
 block discarded – undo
5715 6042
 				foreach ($decoded as $k => $v)
5716 6043
 				{
5717 6044
 					// 7bit are transferred literally
5718
-					if ($v < 128)
5719
-						$output .= chr($v);
6045
+					if ($v < 128) {
6046
+											$output .= chr($v);
6047
+					}
5720 6048
 
5721 6049
 					// 2 bytes
5722
-					elseif ($v < (1 << 11))
5723
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6050
+					elseif ($v < (1 << 11)) {
6051
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6052
+					}
5724 6053
 
5725 6054
 					// 3 bytes
5726
-					elseif ($v < (1 << 16))
5727
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6055
+					elseif ($v < (1 << 16)) {
6056
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6057
+					}
5728 6058
 
5729 6059
 					// 4 bytes
5730
-					elseif ($v < (1 << 21))
5731
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6060
+					elseif ($v < (1 << 21)) {
6061
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6062
+					}
5732 6063
 
5733 6064
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5734
-					else
5735
-						$output .= $safe_char;
6065
+					else {
6066
+											$output .= $safe_char;
6067
+					}
5736 6068
 				}
5737 6069
 
5738 6070
 				$output_parts[] = $output;
@@ -5827,8 +6159,7 @@  discard block
 block discarded – undo
5827 6159
 
5828 6160
 		$strlen = 'mb_strlen';
5829 6161
 		$substr = 'mb_substr';
5830
-	}
5831
-	else
6162
+	} else
5832 6163
 	{
5833 6164
 		$strlen = $smcFunc['strlen'];
5834 6165
 		$substr = $smcFunc['substr'];
@@ -5842,20 +6173,21 @@  discard block
 block discarded – undo
5842 6173
 
5843 6174
 		$first = $substr($string, 0, 1);
5844 6175
 
5845
-		if (empty($index[$first]))
5846
-			$index[$first] = array();
6176
+		if (empty($index[$first])) {
6177
+					$index[$first] = array();
6178
+		}
5847 6179
 
5848 6180
 		if ($strlen($string) > 1)
5849 6181
 		{
5850 6182
 			// Sanity check on recursion
5851
-			if ($depth > 99)
5852
-				$index[$first][$substr($string, 1)] = '';
5853
-
5854
-			else
5855
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6183
+			if ($depth > 99) {
6184
+							$index[$first][$substr($string, 1)] = '';
6185
+			} else {
6186
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6187
+			}
6188
+		} else {
6189
+					$index[$first][''] = '';
5856 6190
 		}
5857
-		else
5858
-			$index[$first][''] = '';
5859 6191
 
5860 6192
 		$depth--;
5861 6193
 		return $index;
@@ -5878,9 +6210,9 @@  discard block
 block discarded – undo
5878 6210
 			$key_regex = preg_quote($key, $delim);
5879 6211
 			$new_key = $key;
5880 6212
 
5881
-			if (empty($value))
5882
-				$sub_regex = '';
5883
-			else
6213
+			if (empty($value)) {
6214
+							$sub_regex = '';
6215
+			} else
5884 6216
 			{
5885 6217
 				$sub_regex = $index_to_regex($value, $delim);
5886 6218
 
@@ -5888,22 +6220,22 @@  discard block
 block discarded – undo
5888 6220
 				{
5889 6221
 					$new_key_array = explode('(?'.'>', $sub_regex);
5890 6222
 					$new_key .= $new_key_array[0];
6223
+				} else {
6224
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5891 6225
 				}
5892
-				else
5893
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5894 6226
 			}
5895 6227
 
5896
-			if ($depth > 1)
5897
-				$regex[$new_key] = $key_regex . $sub_regex;
5898
-			else
6228
+			if ($depth > 1) {
6229
+							$regex[$new_key] = $key_regex . $sub_regex;
6230
+			} else
5899 6231
 			{
5900 6232
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5901 6233
 				{
5902 6234
 					$regex[$new_key] = $key_regex . $sub_regex;
5903 6235
 					unset($index[$key]);
6236
+				} else {
6237
+									break;
5904 6238
 				}
5905
-				else
5906
-					break;
5907 6239
 			}
5908 6240
 		}
5909 6241
 
@@ -5912,10 +6244,11 @@  discard block
 block discarded – undo
5912 6244
 			$l1 = $strlen($k1);
5913 6245
 			$l2 = $strlen($k2);
5914 6246
 
5915
-			if ($l1 == $l2)
5916
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5917
-			else
5918
-				return $l1 > $l2 ? -1 : 1;
6247
+			if ($l1 == $l2) {
6248
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6249
+			} else {
6250
+							return $l1 > $l2 ? -1 : 1;
6251
+			}
5919 6252
 		});
5920 6253
 
5921 6254
 		$depth--;
@@ -5926,15 +6259,18 @@  discard block
 block discarded – undo
5926 6259
 	$index = array();
5927 6260
 	$regexes = array();
5928 6261
 
5929
-	foreach ($strings as $string)
5930
-		$index = $add_string_to_index($string, $index);
6262
+	foreach ($strings as $string) {
6263
+			$index = $add_string_to_index($string, $index);
6264
+	}
5931 6265
 
5932
-	while (!empty($index))
5933
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6266
+	while (!empty($index)) {
6267
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6268
+	}
5934 6269
 
5935 6270
 	// Restore PHP's internal character encoding to whatever it was originally
5936
-	if (!empty($current_encoding))
5937
-		mb_internal_encoding($current_encoding);
6271
+	if (!empty($current_encoding)) {
6272
+			mb_internal_encoding($current_encoding);
6273
+	}
5938 6274
 
5939 6275
 	return $regexes;
5940 6276
 }
Please login to merge, or discard this patch.
Sources/Profile-View.php 1 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 4
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']) || substr($context['member']['birthdate'], 0, 4) < 1002)
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -582,10 +612,11 @@  discard block
 block discarded – undo
582 612
 
583 613
 	$range_limit = '';
584 614
 
585
-	if ($context['is_topics'])
586
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
587
-	else
588
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
615
+	if ($context['is_topics']) {
616
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
617
+	} else {
618
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
619
+	}
589 620
 
590 621
 	$maxIndex = $maxPerPage;
591 622
 
@@ -611,9 +642,9 @@  discard block
 block discarded – undo
611 642
 		{
612 643
 			$margin *= 5;
613 644
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
645
+		} else {
646
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
614 647
 		}
615
-		else
616
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
617 648
 	}
618 649
 
619 650
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 					'max' => $maxIndex,
646 677
 				)
647 678
 			);
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			$request = $smcFunc['db_query']('', '
652 682
 				SELECT
@@ -675,8 +705,9 @@  discard block
 block discarded – undo
675 705
 		}
676 706
 
677 707
 		// Make sure we quit this loop.
678
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
679
-			break;
708
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
709
+					break;
710
+		}
680 711
 		$looped = true;
681 712
 		$range_limit = '';
682 713
 	}
@@ -720,19 +751,21 @@  discard block
 block discarded – undo
720 751
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
721 752
 		);
722 753
 
723
-		if ($user_info['id'] == $row['id_member_started'])
724
-			$board_ids['own'][$row['id_board']][] = $counter;
754
+		if ($user_info['id'] == $row['id_member_started']) {
755
+					$board_ids['own'][$row['id_board']][] = $counter;
756
+		}
725 757
 		$board_ids['any'][$row['id_board']][] = $counter;
726 758
 	}
727 759
 	$smcFunc['db_free_result']($request);
728 760
 
729 761
 	// All posts were retrieved in reverse order, get them right again.
730
-	if ($reverse)
731
-		$context['posts'] = array_reverse($context['posts'], true);
762
+	if ($reverse) {
763
+			$context['posts'] = array_reverse($context['posts'], true);
764
+	}
732 765
 
733 766
 	// These are all the permissions that are different from board to board..
734
-	if ($context['is_topics'])
735
-		$permissions = array(
767
+	if ($context['is_topics']) {
768
+			$permissions = array(
736 769
 			'own' => array(
737 770
 				'post_reply_own' => 'can_reply',
738 771
 			),
@@ -740,8 +773,8 @@  discard block
 block discarded – undo
740 773
 				'post_reply_any' => 'can_reply',
741 774
 			)
742 775
 		);
743
-	else
744
-		$permissions = array(
776
+	} else {
777
+			$permissions = array(
745 778
 			'own' => array(
746 779
 				'post_reply_own' => 'can_reply',
747 780
 				'delete_own' => 'can_delete',
@@ -751,6 +784,7 @@  discard block
 block discarded – undo
751 784
 				'delete_any' => 'can_delete',
752 785
 			)
753 786
 		);
787
+	}
754 788
 
755 789
 	// For every permission in the own/any lists...
756 790
 	foreach ($permissions as $type => $list)
@@ -761,19 +795,22 @@  discard block
 block discarded – undo
761 795
 			$boards = boardsAllowedTo($permission);
762 796
 
763 797
 			// Hmm, they can do it on all boards, can they?
764
-			if (!empty($boards) && $boards[0] == 0)
765
-				$boards = array_keys($board_ids[$type]);
798
+			if (!empty($boards) && $boards[0] == 0) {
799
+							$boards = array_keys($board_ids[$type]);
800
+			}
766 801
 
767 802
 			// Now go through each board they can do the permission on.
768 803
 			foreach ($boards as $board_id)
769 804
 			{
770 805
 				// There aren't any posts displayed from this board.
771
-				if (!isset($board_ids[$type][$board_id]))
772
-					continue;
806
+				if (!isset($board_ids[$type][$board_id])) {
807
+									continue;
808
+				}
773 809
 
774 810
 				// Set the permission to true ;).
775
-				foreach ($board_ids[$type][$board_id] as $counter)
776
-					$context['posts'][$counter][$allowed] = true;
811
+				foreach ($board_ids[$type][$board_id] as $counter) {
812
+									$context['posts'][$counter][$allowed] = true;
813
+				}
777 814
 			}
778 815
 		}
779 816
 	}
@@ -804,8 +841,9 @@  discard block
 block discarded – undo
804 841
 	$boardsAllowed = boardsAllowedTo('view_attachments');
805 842
 
806 843
 	// Make sure we can't actually see anything...
807
-	if (empty($boardsAllowed))
808
-		$boardsAllowed = array(-1);
844
+	if (empty($boardsAllowed)) {
845
+			$boardsAllowed = array(-1);
846
+	}
809 847
 
810 848
 	require_once($sourcedir . '/Subs-List.php');
811 849
 
@@ -956,8 +994,8 @@  discard block
 block discarded – undo
956 994
 		)
957 995
 	);
958 996
 	$attachments = array();
959
-	while ($row = $smcFunc['db_fetch_assoc']($request))
960
-		$attachments[] = array(
997
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
998
+			$attachments[] = array(
961 999
 			'id' => $row['id_attach'],
962 1000
 			'filename' => $row['filename'],
963 1001
 			'downloads' => $row['downloads'],
@@ -969,6 +1007,7 @@  discard block
 block discarded – undo
969 1007
 			'board_name' => $row['name'],
970 1008
 			'approved' => $row['approved'],
971 1009
 		);
1010
+	}
972 1011
 
973 1012
 	$smcFunc['db_free_result']($request);
974 1013
 
@@ -1023,8 +1062,9 @@  discard block
 block discarded – undo
1023 1062
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1024 1063
 
1025 1064
 	// Only the owner can see the list (if the function is enabled of course)
1026
-	if ($user_info['id'] != $memID)
1027
-		return;
1065
+	if ($user_info['id'] != $memID) {
1066
+			return;
1067
+	}
1028 1068
 
1029 1069
 	require_once($sourcedir . '/Subs-List.php');
1030 1070
 
@@ -1170,8 +1210,9 @@  discard block
 block discarded – undo
1170 1210
 	);
1171 1211
 
1172 1212
 	$topics = array();
1173
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1174
-		$topics[] = $row['id_topic'];
1213
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1214
+			$topics[] = $row['id_topic'];
1215
+	}
1175 1216
 
1176 1217
 	$smcFunc['db_free_result']($request);
1177 1218
 
@@ -1191,8 +1232,9 @@  discard block
 block discarded – undo
1191 1232
 				'topics' => $topics,
1192 1233
 			)
1193 1234
 		);
1194
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1195
-			$topicsInfo[] = $row;
1235
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1236
+					$topicsInfo[] = $row;
1237
+		}
1196 1238
 		$smcFunc['db_free_result']($request);
1197 1239
 	}
1198 1240
 
@@ -1240,8 +1282,9 @@  discard block
 block discarded – undo
1240 1282
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1241 1283
 
1242 1284
 	// Is the load average too high to allow searching just now?
1243
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1244
-		fatal_lang_error('loadavg_userstats_disabled', false);
1285
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1286
+			fatal_lang_error('loadavg_userstats_disabled', false);
1287
+	}
1245 1288
 
1246 1289
 	// General user statistics.
1247 1290
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1399,11 +1442,13 @@  discard block
 block discarded – undo
1399 1442
 	}
1400 1443
 	$smcFunc['db_free_result']($result);
1401 1444
 
1402
-	if ($maxPosts > 0)
1403
-		for ($hour = 0; $hour < 24; $hour++)
1445
+	if ($maxPosts > 0) {
1446
+			for ($hour = 0;
1447
+	}
1448
+	$hour < 24; $hour++)
1404 1449
 		{
1405
-			if (!isset($context['posts_by_time'][$hour]))
1406
-				$context['posts_by_time'][$hour] = array(
1450
+			if (!isset($context['posts_by_time'][$hour])) {
1451
+							$context['posts_by_time'][$hour] = array(
1407 1452
 					'hour' => $hour,
1408 1453
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1409 1454
 					'posts' => 0,
@@ -1411,7 +1456,7 @@  discard block
 block discarded – undo
1411 1456
 					'relative_percent' => 0,
1412 1457
 					'is_last' => $hour == 23,
1413 1458
 				);
1414
-			else
1459
+			} else
1415 1460
 			{
1416 1461
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1417 1462
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1444,8 +1489,9 @@  discard block
 block discarded – undo
1444 1489
 
1445 1490
 	foreach ($subActions as $sa => $action)
1446 1491
 	{
1447
-		if (!allowedTo($action[2]))
1448
-			unset($subActions[$sa]);
1492
+		if (!allowedTo($action[2])) {
1493
+					unset($subActions[$sa]);
1494
+		}
1449 1495
 	}
1450 1496
 
1451 1497
 	// Create the tabs for the template.
@@ -1463,15 +1509,18 @@  discard block
 block discarded – undo
1463 1509
 	);
1464 1510
 
1465 1511
 	// Moderation must be on to track edits.
1466
-	if (empty($modSettings['userlog_enabled']))
1467
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1512
+	if (empty($modSettings['userlog_enabled'])) {
1513
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1514
+	}
1468 1515
 
1469 1516
 	// Group requests must be active to show it...
1470
-	if (empty($modSettings['show_group_membership']))
1471
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1517
+	if (empty($modSettings['show_group_membership'])) {
1518
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1519
+	}
1472 1520
 
1473
-	if (empty($subActions))
1474
-		fatal_lang_error('no_access', false);
1521
+	if (empty($subActions)) {
1522
+			fatal_lang_error('no_access', false);
1523
+	}
1475 1524
 
1476 1525
 	$keys = array_keys($subActions);
1477 1526
 	$default = array_shift($keys);
@@ -1484,9 +1533,10 @@  discard block
 block discarded – undo
1484 1533
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1485 1534
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1486 1535
 
1487
-	if (!empty($call))
1488
-		call_user_func($call, $memID);
1489
-}
1536
+	if (!empty($call)) {
1537
+			call_user_func($call, $memID);
1538
+	}
1539
+	}
1490 1540
 
1491 1541
 /**
1492 1542
  * Handles tracking a user's activity
@@ -1502,8 +1552,9 @@  discard block
 block discarded – undo
1502 1552
 	isAllowedTo('moderate_forum');
1503 1553
 
1504 1554
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1505
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1506
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1555
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1556
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1557
+	}
1507 1558
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1508 1559
 
1509 1560
 	// Set the options for the list component.
@@ -1669,8 +1720,9 @@  discard block
 block discarded – undo
1669 1720
 			)
1670 1721
 		);
1671 1722
 		$message_members = array();
1672
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1673
-			$message_members[] = $row['id_member'];
1723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1724
+					$message_members[] = $row['id_member'];
1725
+		}
1674 1726
 		$smcFunc['db_free_result']($request);
1675 1727
 
1676 1728
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1685,8 +1737,9 @@  discard block
 block discarded – undo
1685 1737
 					'ip_list' => $ips,
1686 1738
 				)
1687 1739
 			);
1688
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1689
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1740
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1741
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1742
+			}
1690 1743
 			$smcFunc['db_free_result']($request);
1691 1744
 		}
1692 1745
 
@@ -1700,8 +1753,9 @@  discard block
 block discarded – undo
1700 1753
 				'ip_list' => $ips,
1701 1754
 			)
1702 1755
 		);
1703
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1704
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1756
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1757
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1758
+		}
1705 1759
 		$smcFunc['db_free_result']($request);
1706 1760
 	}
1707 1761
 }
@@ -1761,8 +1815,8 @@  discard block
 block discarded – undo
1761 1815
 		))
1762 1816
 	);
1763 1817
 	$error_messages = array();
1764
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1765
-		$error_messages[] = array(
1818
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1819
+			$error_messages[] = array(
1766 1820
 			'ip' => inet_dtop($row['ip']),
1767 1821
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1768 1822
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1770,6 +1824,7 @@  discard block
 block discarded – undo
1770 1824
 			'time' => timeformat($row['log_time']),
1771 1825
 			'timestamp' => forum_time(true, $row['log_time']),
1772 1826
 		);
1827
+	}
1773 1828
 	$smcFunc['db_free_result']($request);
1774 1829
 
1775 1830
 	return $error_messages;
@@ -1832,8 +1887,8 @@  discard block
 block discarded – undo
1832 1887
 		))
1833 1888
 	);
1834 1889
 	$messages = array();
1835
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1836
-		$messages[] = array(
1890
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1891
+			$messages[] = array(
1837 1892
 			'ip' => inet_dtop($row['poster_ip']),
1838 1893
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1839 1894
 			'board' => array(
@@ -1846,6 +1901,7 @@  discard block
 block discarded – undo
1846 1901
 			'time' => timeformat($row['poster_time']),
1847 1902
 			'timestamp' => forum_time(true, $row['poster_time'])
1848 1903
 		);
1904
+	}
1849 1905
 	$smcFunc['db_free_result']($request);
1850 1906
 
1851 1907
 	return $messages;
@@ -1872,19 +1928,20 @@  discard block
 block discarded – undo
1872 1928
 		$context['sub_template'] = 'trackIP';
1873 1929
 		$context['page_title'] = $txt['profile'];
1874 1930
 		$context['base_url'] = $scripturl . '?action=trackip';
1875
-	}
1876
-	else
1931
+	} else
1877 1932
 	{
1878 1933
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1879 1934
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1880 1935
 	}
1881 1936
 
1882 1937
 	// Searching?
1883
-	if (isset($_REQUEST['searchip']))
1884
-		$context['ip'] = trim($_REQUEST['searchip']);
1938
+	if (isset($_REQUEST['searchip'])) {
1939
+			$context['ip'] = trim($_REQUEST['searchip']);
1940
+	}
1885 1941
 
1886
-	if (isValidIP($context['ip']) === false)
1887
-		fatal_lang_error('invalid_tracking_ip', false);
1942
+	if (isValidIP($context['ip']) === false) {
1943
+			fatal_lang_error('invalid_tracking_ip', false);
1944
+	}
1888 1945
 
1889 1946
 	//mysql didn't support like search with varbinary
1890 1947
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1892,8 +1949,9 @@  discard block
 block discarded – undo
1892 1949
 	$ip_var = $context['ip'];
1893 1950
 	$ip_string = '= {inet: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'][inet_dtop($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'][inet_dtop($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']);
@@ -2134,8 +2193,9 @@  discard block
 block discarded – undo
2134 2193
 		foreach ($context['whois_servers'] as $whois)
2135 2194
 		{
2136 2195
 			// Strip off the "decimal point" and anything following...
2137
-			if (in_array((int) $context['ip'], $whois['range']))
2138
-				$context['auto_whois_server'] = $whois;
2196
+			if (in_array((int) $context['ip'], $whois['range'])) {
2197
+							$context['auto_whois_server'] = $whois;
2198
+			}
2139 2199
 		}
2140 2200
 	}
2141 2201
 }
@@ -2152,10 +2212,11 @@  discard block
 block discarded – undo
2152 2212
 	// Gonna want this for the list.
2153 2213
 	require_once($sourcedir . '/Subs-List.php');
2154 2214
 
2155
-	if ($memID == 0)
2156
-		$context['base_url'] = $scripturl . '?action=trackip';
2157
-	else
2158
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2215
+	if ($memID == 0) {
2216
+			$context['base_url'] = $scripturl . '?action=trackip';
2217
+	} else {
2218
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2219
+	}
2159 2220
 
2160 2221
 	// Start with the user messages.
2161 2222
 	$listOptions = array(
@@ -2265,12 +2326,13 @@  discard block
 block discarded – undo
2265 2326
 		)
2266 2327
 	);
2267 2328
 	$logins = array();
2268
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2269
-		$logins[] = array(
2329
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2330
+			$logins[] = array(
2270 2331
 			'time' => timeformat($row['time']),
2271 2332
 			'ip' => inet_dtop($row['ip']),
2272 2333
 			'ip2' => inet_dtop($row['ip2']),
2273 2334
 		);
2335
+	}
2274 2336
 	$smcFunc['db_free_result']($request);
2275 2337
 
2276 2338
 	return $logins;
@@ -2295,11 +2357,12 @@  discard block
 block discarded – undo
2295 2357
 		)
2296 2358
 	);
2297 2359
 	$context['custom_field_titles'] = array();
2298
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2299
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2360
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2361
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2300 2362
 			'title' => $row['field_name'],
2301 2363
 			'parse_bbc' => $row['bbc'],
2302 2364
 		);
2365
+	}
2303 2366
 	$smcFunc['db_free_result']($request);
2304 2367
 
2305 2368
 	// Set the options for the error lists.
@@ -2438,19 +2501,22 @@  discard block
 block discarded – undo
2438 2501
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2439 2502
 	{
2440 2503
 		$extra = smf_json_decode($row['extra'], true);
2441
-		if (!empty($extra['applicator']))
2442
-			$members[] = $extra['applicator'];
2504
+		if (!empty($extra['applicator'])) {
2505
+					$members[] = $extra['applicator'];
2506
+		}
2443 2507
 
2444 2508
 		// Work out what the name of the action is.
2445
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2446
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2447
-		elseif (isset($txt[$row['action']]))
2448
-			$action_text = $txt[$row['action']];
2509
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2510
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2511
+		} elseif (isset($txt[$row['action']])) {
2512
+					$action_text = $txt[$row['action']];
2513
+		}
2449 2514
 		// Custom field?
2450
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2451
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2452
-		else
2453
-			$action_text = $row['action'];
2515
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2516
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2517
+		} else {
2518
+					$action_text = $row['action'];
2519
+		}
2454 2520
 
2455 2521
 		// Parse BBC?
2456 2522
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2482,13 +2548,15 @@  discard block
 block discarded – undo
2482 2548
 			)
2483 2549
 		);
2484 2550
 		$members = array();
2485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2486
-			$members[$row['id_member']] = $row['real_name'];
2551
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2552
+					$members[$row['id_member']] = $row['real_name'];
2553
+		}
2487 2554
 		$smcFunc['db_free_result']($request);
2488 2555
 
2489
-		foreach ($edits as $key => $value)
2490
-			if (isset($members[$value['id_member']]))
2556
+		foreach ($edits as $key => $value) {
2557
+					if (isset($members[$value['id_member']]))
2491 2558
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2559
+		}
2492 2560
 	}
2493 2561
 
2494 2562
 	return $edits;
@@ -2689,10 +2757,11 @@  discard block
 block discarded – undo
2689 2757
 	$context['board'] = $board;
2690 2758
 
2691 2759
 	// Determine which groups this user is in.
2692
-	if (empty($user_profile[$memID]['additional_groups']))
2693
-		$curGroups = array();
2694
-	else
2695
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2760
+	if (empty($user_profile[$memID]['additional_groups'])) {
2761
+			$curGroups = array();
2762
+	} else {
2763
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2764
+	}
2696 2765
 	$curGroups[] = $user_profile[$memID]['id_group'];
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2698 2767
 
@@ -2712,28 +2781,30 @@  discard block
 block discarded – undo
2712 2781
 	$context['no_access_boards'] = array();
2713 2782
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2714 2783
 	{
2715
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2716
-			$context['no_access_boards'][] = array(
2784
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2785
+					$context['no_access_boards'][] = array(
2717 2786
 				'id' => $row['id_board'],
2718 2787
 				'name' => $row['name'],
2719 2788
 				'is_last' => false,
2720 2789
 			);
2721
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2722
-			$context['boards'][$row['id_board']] = array(
2790
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2791
+					$context['boards'][$row['id_board']] = array(
2723 2792
 				'id' => $row['id_board'],
2724 2793
 				'name' => $row['name'],
2725 2794
 				'selected' => $board == $row['id_board'],
2726 2795
 				'profile' => $row['id_profile'],
2727 2796
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2728 2797
 			);
2798
+		}
2729 2799
 	}
2730 2800
 	$smcFunc['db_free_result']($request);
2731 2801
 
2732 2802
 	require_once($sourcedir . '/Subs-Boards.php');
2733 2803
 	sortBoards($context['boards']);
2734 2804
 
2735
-	if (!empty($context['no_access_boards']))
2736
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2805
+	if (!empty($context['no_access_boards'])) {
2806
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2807
+	}
2737 2808
 
2738 2809
 	$context['member']['permissions'] = array(
2739 2810
 		'general' => array(),
@@ -2742,8 +2813,9 @@  discard block
 block discarded – undo
2742 2813
 
2743 2814
 	// If you're an admin we know you can do everything, we might as well leave.
2744 2815
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2745
-	if ($context['member']['has_all_permissions'])
2746
-		return;
2816
+	if ($context['member']['has_all_permissions']) {
2817
+			return;
2818
+	}
2747 2819
 
2748 2820
 	$denied = array();
2749 2821
 
@@ -2762,21 +2834,24 @@  discard block
 block discarded – undo
2762 2834
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2763 2835
 	{
2764 2836
 		// We don't know about this permission, it doesn't exist :P.
2765
-		if (!isset($txt['permissionname_' . $row['permission']]))
2766
-			continue;
2837
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2838
+					continue;
2839
+		}
2767 2840
 
2768
-		if (empty($row['add_deny']))
2769
-			$denied[] = $row['permission'];
2841
+		if (empty($row['add_deny'])) {
2842
+					$denied[] = $row['permission'];
2843
+		}
2770 2844
 
2771 2845
 		// Permissions that end with _own or _any consist of two parts.
2772
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2773
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2774
-		else
2775
-			$name = $txt['permissionname_' . $row['permission']];
2846
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2847
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2848
+		} else {
2849
+					$name = $txt['permissionname_' . $row['permission']];
2850
+		}
2776 2851
 
2777 2852
 		// Add this permission if it doesn't exist yet.
2778
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2779
-			$context['member']['permissions']['general'][$row['permission']] = array(
2853
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2854
+					$context['member']['permissions']['general'][$row['permission']] = array(
2780 2855
 				'id' => $row['permission'],
2781 2856
 				'groups' => array(
2782 2857
 					'allowed' => array(),
@@ -2786,6 +2861,7 @@  discard block
 block discarded – undo
2786 2861
 				'is_denied' => false,
2787 2862
 				'is_global' => true,
2788 2863
 			);
2864
+		}
2789 2865
 
2790 2866
 		// Add the membergroup to either the denied or the allowed groups.
2791 2867
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2819,18 +2895,20 @@  discard block
 block discarded – undo
2819 2895
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2820 2896
 	{
2821 2897
 		// We don't know about this permission, it doesn't exist :P.
2822
-		if (!isset($txt['permissionname_' . $row['permission']]))
2823
-			continue;
2898
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2899
+					continue;
2900
+		}
2824 2901
 
2825 2902
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2826
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2827
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2828
-		else
2829
-			$name = $txt['permissionname_' . $row['permission']];
2903
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2904
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2905
+		} else {
2906
+					$name = $txt['permissionname_' . $row['permission']];
2907
+		}
2830 2908
 
2831 2909
 		// Create the structure for this permission.
2832
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2833
-			$context['member']['permissions']['board'][$row['permission']] = array(
2910
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2911
+					$context['member']['permissions']['board'][$row['permission']] = array(
2834 2912
 				'id' => $row['permission'],
2835 2913
 				'groups' => array(
2836 2914
 					'allowed' => array(),
@@ -2840,6 +2918,7 @@  discard block
 block discarded – undo
2840 2918
 				'is_denied' => false,
2841 2919
 				'is_global' => empty($board),
2842 2920
 			);
2921
+		}
2843 2922
 
2844 2923
 		$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'];
2845 2924
 
@@ -2858,8 +2937,9 @@  discard block
 block discarded – undo
2858 2937
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2859 2938
 
2860 2939
 	// Firstly, can we actually even be here?
2861
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2862
-		fatal_lang_error('no_access', false);
2940
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2941
+			fatal_lang_error('no_access', false);
2942
+	}
2863 2943
 
2864 2944
 	// Make sure things which are disabled stay disabled.
2865 2945
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2946,9 +3026,10 @@  discard block
 block discarded – undo
2946 3026
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2947 3027
 	);
2948 3028
 	$context['current_level'] = 0;
2949
-	foreach ($context['level_effects'] as $limit => $dummy)
2950
-		if ($context['member']['warning'] >= $limit)
3029
+	foreach ($context['level_effects'] as $limit => $dummy) {
3030
+			if ($context['member']['warning'] >= $limit)
2951 3031
 			$context['current_level'] = $limit;
2952
-}
3032
+	}
3033
+	}
2953 3034
 
2954 3035
 ?>
2955 3036
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +219 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -61,11 +62,13 @@  discard block
 block discarded – undo
61 62
 			'db_mb4' => true,
62 63
 			'db_ping' => 'pg_ping',
63 64
 		);
65
+	}
64 66
 
65
-	if (!empty($db_options['persist']))
66
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
-	else
68
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	if (!empty($db_options['persist'])) {
68
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	} else {
70
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
71
+	}
69 72
 
70 73
 	// Something's wrong, show an error if its fatal (which we assume it is)
71 74
 	if (!$connection)
@@ -73,8 +76,7 @@  discard block
 block discarded – undo
73 76
 		if (!empty($db_options['non_fatal']))
74 77
 		{
75 78
 			return null;
76
-		}
77
-		else
79
+		} else
78 80
 		{
79 81
 			display_db_error();
80 82
 		}
@@ -125,35 +127,42 @@  discard block
 block discarded – undo
125 127
 
126 128
 	list ($values, $connection) = $db_callback;
127 129
 
128
-	if ($matches[1] === 'db_prefix')
129
-		return $db_prefix;
130
+	if ($matches[1] === 'db_prefix') {
131
+			return $db_prefix;
132
+	}
130 133
 
131 134
 	if (!empty($user_info))
132 135
 	{
133
-		foreach (array_keys($user_info) as $key)
134
-			if (strpos($key, 'query_') !== false && $key === $matches[1])
136
+		foreach (array_keys($user_info) as $key) {
137
+					if (strpos($key, 'query_') !== false && $key === $matches[1])
135 138
 				return $user_info[$matches[1]];
139
+		}
136 140
 	}
137 141
 
138
-	if ($matches[1] === 'empty')
139
-		return '\'\'';
142
+	if ($matches[1] === 'empty') {
143
+			return '\'\'';
144
+	}
140 145
 
141
-	if (!isset($matches[2]))
142
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	if (!isset($matches[2])) {
147
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
148
+	}
143 149
 
144
-	if ($matches[1] === 'literal')
145
-		return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	if ($matches[1] === 'literal') {
151
+			return '\'' . pg_escape_string($matches[2]) . '\'';
152
+	}
146 153
 
147
-	if (!isset($values[$matches[2]]))
148
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
154
+	if (!isset($values[$matches[2]])) {
155
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
156
+	}
149 157
 
150 158
 	$replacement = $values[$matches[2]];
151 159
 
152 160
 	switch ($matches[1])
153 161
 	{
154 162
 		case 'int':
155
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
156
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
164
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
165
+			}
157 166
 			return (string) (int) $replacement;
158 167
 		break;
159 168
 
@@ -165,65 +174,73 @@  discard block
 block discarded – undo
165 174
 		case 'array_int':
166 175
 			if (is_array($replacement))
167 176
 			{
168
-				if (empty($replacement))
169
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				if (empty($replacement)) {
178
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179
+				}
170 180
 
171 181
 				foreach ($replacement as $key => $value)
172 182
 				{
173
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
174
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
184
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
185
+					}
175 186
 
176 187
 					$replacement[$key] = (string) (int) $value;
177 188
 				}
178 189
 
179 190
 				return implode(', ', $replacement);
191
+			} else {
192
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 193
 			}
181
-			else
182
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183 194
 
184 195
 		break;
185 196
 
186 197
 		case 'array_string':
187 198
 			if (is_array($replacement))
188 199
 			{
189
-				if (empty($replacement))
190
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				if (empty($replacement)) {
201
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
202
+				}
191 203
 
192
-				foreach ($replacement as $key => $value)
193
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				foreach ($replacement as $key => $value) {
205
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
206
+				}
194 207
 
195 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 211
 			}
197
-			else
198
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
199 212
 		break;
200 213
 
201 214
 		case 'date':
202
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
203
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
204
-			else
205
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
216
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
217
+			} else {
218
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+			}
206 220
 		break;
207 221
 
208 222
 		case 'time':
209
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
210
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
211
-			else
212
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
224
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
225
+			} else {
226
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+			}
213 228
 		break;
214 229
 
215 230
 		case 'datetime':
216
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
217
-				return 'to_timestamp('.
231
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
232
+							return 'to_timestamp('.
218 233
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
219 234
 					',\'YYYY-MM-DD HH24:MI:SS\')';
220
-			else
221
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
222 238
 		break;
223 239
 
224 240
 		case 'float':
225
-			if (!is_numeric($replacement))
226
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (!is_numeric($replacement)) {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+			}
227 244
 			return (string) (float) $replacement;
228 245
 		break;
229 246
 
@@ -236,31 +253,36 @@  discard block
 block discarded – undo
236 253
 		break;
237 254
 
238 255
 		case 'inet':
239
-			if ($replacement == 'null' || $replacement == '')
240
-				return 'null';
241
-			if (inet_pton($replacement) === false)
242
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
256
+			if ($replacement == 'null' || $replacement == '') {
257
+							return 'null';
258
+			}
259
+			if (inet_pton($replacement) === false) {
260
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+			}
243 262
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
244 263
 
245 264
 		case 'array_inet':
246 265
 			if (is_array($replacement))
247 266
 			{
248
-				if (empty($replacement))
249
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+				if (empty($replacement)) {
268
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+				}
250 270
 
251 271
 				foreach ($replacement as $key => $value)
252 272
 				{
253
-					if ($replacement == 'null' || $replacement == '')
254
-						$replacement[$key] = 'null';
255
-					if (!isValidIP($value))
256
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+					if ($replacement == 'null' || $replacement == '') {
274
+											$replacement[$key] = 'null';
275
+					}
276
+					if (!isValidIP($value)) {
277
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+					}
257 279
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
258 280
 				}
259 281
 
260 282
 				return implode(', ', $replacement);
283
+			} else {
284
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261 285
 			}
262
-			else
263
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
264 286
 		break;
265 287
 
266 288
 		default:
@@ -354,14 +376,16 @@  discard block
 block discarded – undo
354 376
 		),
355 377
 	);
356 378
 
357
-	if (isset($replacements[$identifier]))
358
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
379
+	if (isset($replacements[$identifier])) {
380
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
381
+	}
359 382
 
360 383
 	// Limits need to be a little different.
361 384
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
362 385
 
363
-	if (trim($db_string) == '')
364
-		return false;
386
+	if (trim($db_string) == '') {
387
+			return false;
388
+	}
365 389
 
366 390
 	// Comments that are allowed in a query are preg_removed.
367 391
 	static $allowed_comments_from = array(
@@ -381,8 +405,9 @@  discard block
 block discarded – undo
381 405
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
382 406
 	$db_replace_result = 0;
383 407
 
384
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
385
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
408
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
409
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
410
+	}
386 411
 
387 412
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
388 413
 	{
@@ -403,8 +428,9 @@  discard block
 block discarded – undo
403 428
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
404 429
 
405 430
 		// Initialize $db_cache if not already initialized.
406
-		if (!isset($db_cache))
407
-			$db_cache = array();
431
+		if (!isset($db_cache)) {
432
+					$db_cache = array();
433
+		}
408 434
 
409 435
 		if (!empty($_SESSION['debug_redirect']))
410 436
 		{
@@ -430,17 +456,18 @@  discard block
 block discarded – undo
430 456
 		while (true)
431 457
 		{
432 458
 			$pos = strpos($db_string, '\'', $pos + 1);
433
-			if ($pos === false)
434
-				break;
459
+			if ($pos === false) {
460
+							break;
461
+			}
435 462
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
436 463
 
437 464
 			while (true)
438 465
 			{
439 466
 				$pos1 = strpos($db_string, '\'', $pos + 1);
440 467
 				$pos2 = strpos($db_string, '\\', $pos + 1);
441
-				if ($pos1 === false)
442
-					break;
443
-				elseif ($pos2 === false || $pos2 > $pos1)
468
+				if ($pos1 === false) {
469
+									break;
470
+				} elseif ($pos2 === false || $pos2 > $pos1)
444 471
 				{
445 472
 					$pos = $pos1;
446 473
 					break;
@@ -456,16 +483,19 @@  discard block
 block discarded – undo
456 483
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
457 484
 
458 485
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
459
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
460
-			$fail = true;
486
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
487
+					$fail = true;
488
+		}
461 489
 		// Trying to change passwords, slow us down, or something?
462
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
463
-			$fail = true;
464
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
465
-			$fail = true;
490
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
491
+					$fail = true;
492
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
493
+					$fail = true;
494
+		}
466 495
 
467
-		if (!empty($fail) && function_exists('log_error'))
468
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
496
+		if (!empty($fail) && function_exists('log_error')) {
497
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
498
+		}
469 499
 	}
470 500
 
471 501
 	// Set optimize stuff
@@ -484,18 +514,21 @@  discard block
 block discarded – undo
484 514
 
485 515
 		$db_string = $query_hints_set . $db_string;
486 516
 		
487
-		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...')
488
-			$db_cache[$db_count]['q'] = "\t\t" . $db_string;
517
+		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') {
518
+					$db_cache[$db_count]['q'] = "\t\t" . $db_string;
519
+		}
489 520
 	}
490 521
 
491 522
 	$db_last_result = @pg_query($connection, $db_string);
492 523
 
493
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
494
-		$db_last_result = smf_db_error($db_string, $connection);
524
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
525
+			$db_last_result = smf_db_error($db_string, $connection);
526
+	}
495 527
 
496 528
 	// Debugging.
497
-	if (isset($db_show_debug) && $db_show_debug === true)
498
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
529
+	if (isset($db_show_debug) && $db_show_debug === true) {
530
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
531
+	}
499 532
 
500 533
 	return $db_last_result;
501 534
 }
@@ -508,10 +541,11 @@  discard block
 block discarded – undo
508 541
 {
509 542
 	global $db_last_result, $db_replace_result;
510 543
 
511
-	if ($db_replace_result)
512
-		return $db_replace_result;
513
-	elseif ($result === null && !$db_last_result)
514
-		return 0;
544
+	if ($db_replace_result) {
545
+			return $db_replace_result;
546
+	} elseif ($result === null && !$db_last_result) {
547
+			return 0;
548
+	}
515 549
 
516 550
 	return pg_affected_rows($result === null ? $db_last_result : $result);
517 551
 }
@@ -535,8 +569,9 @@  discard block
 block discarded – undo
535 569
 		array(
536 570
 		)
537 571
 	);
538
-	if (!$request)
539
-		return false;
572
+	if (!$request) {
573
+			return false;
574
+	}
540 575
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
541 576
 	$smcFunc['db_free_result']($request);
542 577
 
@@ -557,12 +592,13 @@  discard block
 block discarded – undo
557 592
 	// Decide which connection to use
558 593
 	$connection = $connection === null ? $db_connection : $connection;
559 594
 
560
-	if ($type == 'begin')
561
-		return @pg_query($connection, 'BEGIN');
562
-	elseif ($type == 'rollback')
563
-		return @pg_query($connection, 'ROLLBACK');
564
-	elseif ($type == 'commit')
565
-		return @pg_query($connection, 'COMMIT');
595
+	if ($type == 'begin') {
596
+			return @pg_query($connection, 'BEGIN');
597
+	} elseif ($type == 'rollback') {
598
+			return @pg_query($connection, 'ROLLBACK');
599
+	} elseif ($type == 'commit') {
600
+			return @pg_query($connection, 'COMMIT');
601
+	}
566 602
 
567 603
 	return false;
568 604
 }
@@ -590,19 +626,22 @@  discard block
 block discarded – undo
590 626
 	$query_error = @pg_last_error($connection);
591 627
 
592 628
 	// Log the error.
593
-	if (function_exists('log_error'))
594
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
629
+	if (function_exists('log_error')) {
630
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
631
+	}
595 632
 
596 633
 	// Nothing's defined yet... just die with it.
597
-	if (empty($context) || empty($txt))
598
-		die($query_error);
634
+	if (empty($context) || empty($txt)) {
635
+			die($query_error);
636
+	}
599 637
 
600 638
 	// Show an error message, if possible.
601 639
 	$context['error_title'] = $txt['database_error'];
602
-	if (allowedTo('admin_forum'))
603
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
604
-	else
605
-		$context['error_message'] = $txt['try_again'];
640
+	if (allowedTo('admin_forum')) {
641
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
642
+	} else {
643
+			$context['error_message'] = $txt['try_again'];
644
+	}
606 645
 
607 646
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
608 647
 	{
@@ -624,12 +663,14 @@  discard block
 block discarded – undo
624 663
 {
625 664
 	global $db_row_count;
626 665
 
627
-	if ($counter !== false)
628
-		return pg_fetch_row($request, $counter);
666
+	if ($counter !== false) {
667
+			return pg_fetch_row($request, $counter);
668
+	}
629 669
 
630 670
 	// Reset the row counter...
631
-	if (!isset($db_row_count[(int) $request]))
632
-		$db_row_count[(int) $request] = 0;
671
+	if (!isset($db_row_count[(int) $request])) {
672
+			$db_row_count[(int) $request] = 0;
673
+	}
633 674
 
634 675
 	// Return the right row.
635 676
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -646,12 +687,14 @@  discard block
 block discarded – undo
646 687
 {
647 688
 	global $db_row_count;
648 689
 
649
-	if ($counter !== false)
650
-		return pg_fetch_assoc($request, $counter);
690
+	if ($counter !== false) {
691
+			return pg_fetch_assoc($request, $counter);
692
+	}
651 693
 
652 694
 	// Reset the row counter...
653
-	if (!isset($db_row_count[(int) $request]))
654
-		$db_row_count[(int) $request] = 0;
695
+	if (!isset($db_row_count[(int) $request])) {
696
+			$db_row_count[(int) $request] = 0;
697
+	}
655 698
 
656 699
 	// Return the right row.
657 700
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -704,11 +747,13 @@  discard block
 block discarded – undo
704 747
 
705 748
 	$replace = '';
706 749
 
707
-	if (empty($data))
708
-		return;
750
+	if (empty($data)) {
751
+			return;
752
+	}
709 753
 
710
-	if (!is_array($data[array_rand($data)]))
711
-		$data = array($data);
754
+	if (!is_array($data[array_rand($data)])) {
755
+			$data = array($data);
756
+	}
712 757
 
713 758
 	// Replace the prefix holder with the actual prefix.
714 759
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -727,11 +772,13 @@  discard block
 block discarded – undo
727 772
 			//pg 9.5 got replace support
728 773
 			$pg_version = $smcFunc['db_get_version']();
729 774
 			// if we got a Beta Version
730
-			if (stripos($pg_version, 'beta') !== false)
731
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
775
+			if (stripos($pg_version, 'beta') !== false) {
776
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
777
+			}
732 778
 			// or RC
733
-			if (stripos($pg_version, 'rc') !== false)
734
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
779
+			if (stripos($pg_version, 'rc') !== false) {
780
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
781
+			}
735 782
 
736 783
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
737 784
 		}
@@ -750,8 +797,7 @@  discard block
 block discarded – undo
750 797
 					$key_str .= ($count_pk > 0 ? ',' : '');
751 798
 					$key_str .= $columnName;
752 799
 					$count_pk++;
753
-				}
754
-				else //normal field
800
+				} else //normal field
755 801
 				{
756 802
 					$col_str .= ($count > 0 ? ',' : '');
757 803
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -759,20 +805,21 @@  discard block
 block discarded – undo
759 805
 				}
760 806
 			}
761 807
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
762
-		}
763
-		else
808
+		} else
764 809
 		{
765 810
 			foreach ($columns as $columnName => $type)
766 811
 			{
767 812
 				// Are we restricting the length?
768
-				if (strpos($type, 'string-') !== false)
769
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
770
-				else
771
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
813
+				if (strpos($type, 'string-') !== false) {
814
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
815
+				} else {
816
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
817
+				}
772 818
 
773 819
 				// A key? That's what we were looking for.
774
-				if (in_array($columnName, $keys))
775
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
820
+				if (in_array($columnName, $keys)) {
821
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
822
+				}
776 823
 				$count++;
777 824
 			}
778 825
 
@@ -808,10 +855,11 @@  discard block
 block discarded – undo
808 855
 		foreach ($columns as $columnName => $type)
809 856
 		{
810 857
 			// Are we restricting the length?
811
-			if (strpos($type, 'string-') !== false)
812
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
813
-			else
814
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
858
+			if (strpos($type, 'string-') !== false) {
859
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
860
+			} else {
861
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
862
+			}
815 863
 		}
816 864
 		$insertData = substr($insertData, 0, -2) . ')';
817 865
 
@@ -820,8 +868,9 @@  discard block
 block discarded – undo
820 868
 
821 869
 		// Here's where the variables are injected to the query.
822 870
 		$insertRows = array();
823
-		foreach ($data as $dataRow)
824
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
871
+		foreach ($data as $dataRow) {
872
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
873
+		}
825 874
 
826 875
 		// Do the insert.
827 876
 		$request = $smcFunc['db_query']('', '
@@ -838,19 +887,21 @@  discard block
 block discarded – undo
838 887
 
839 888
 		if ($with_returning && $request !== false)
840 889
 		{
841
-			if ($returnmode === 2)
842
-				$return_var = array();
890
+			if ($returnmode === 2) {
891
+							$return_var = array();
892
+			}
843 893
 
844 894
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
845 895
 			{
846
-				if (is_numeric($row[0])) // try to emulate mysql limitation
896
+				if (is_numeric($row[0])) {
897
+					// try to emulate mysql limitation
847 898
 				{
848 899
 					if ($returnmode === 1)
849 900
 						$return_var = $row[0];
850
-					elseif ($returnmode === 2)
851
-						$return_var[] = $row[0];
852
-				}
853
-				else
901
+				} elseif ($returnmode === 2) {
902
+											$return_var[] = $row[0];
903
+					}
904
+				} else
854 905
 				{
855 906
 					$with_returning = false;
856 907
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -859,9 +910,10 @@  discard block
 block discarded – undo
859 910
 		}
860 911
 	}
861 912
 
862
-	if ($with_returning && !empty($return_var))
863
-		return $return_var;
864
-}
913
+	if ($with_returning && !empty($return_var)) {
914
+			return $return_var;
915
+	}
916
+	}
865 917
 
866 918
 /**
867 919
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -898,8 +950,9 @@  discard block
 block discarded – undo
898 950
  */
899 951
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
900 952
 {
901
-	if (empty($log_message))
902
-		$log_message = $error_message;
953
+	if (empty($log_message)) {
954
+			$log_message = $error_message;
955
+	}
903 956
 
904 957
 	foreach (debug_backtrace() as $step)
905 958
 	{
@@ -918,12 +971,14 @@  discard block
 block discarded – undo
918 971
 	}
919 972
 
920 973
 	// A special case - we want the file and line numbers for debugging.
921
-	if ($error_type == 'return')
922
-		return array($file, $line);
974
+	if ($error_type == 'return') {
975
+			return array($file, $line);
976
+	}
923 977
 
924 978
 	// Is always a critical error.
925
-	if (function_exists('log_error'))
926
-		log_error($log_message, 'critical', $file, $line);
979
+	if (function_exists('log_error')) {
980
+			log_error($log_message, 'critical', $file, $line);
981
+	}
927 982
 
928 983
 	if (function_exists('fatal_error'))
929 984
 	{
@@ -931,12 +986,12 @@  discard block
 block discarded – undo
931 986
 
932 987
 		// Cannot continue...
933 988
 		exit;
989
+	} elseif ($error_type) {
990
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
991
+	} else {
992
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
993
+	}
934 994
 	}
935
-	elseif ($error_type)
936
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
937
-	else
938
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
939
-}
940 995
 
941 996
 /**
942 997
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -953,10 +1008,11 @@  discard block
 block discarded – undo
953 1008
 		'\\' => '\\\\',
954 1009
 	);
955 1010
 
956
-	if ($translate_human_wildcards)
957
-		$replacements += array(
1011
+	if ($translate_human_wildcards) {
1012
+			$replacements += array(
958 1013
 			'*' => '%',
959 1014
 		);
1015
+	}
960 1016
 
961 1017
 	return strtr($string, $replacements);
962 1018
 }
Please login to merge, or discard this patch.
Sources/ManageCalendar.php 1 patch
Braces   +37 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main controlling function doesn't have much to do... yet.
@@ -43,8 +44,7 @@  discard block
 block discarded – undo
43 44
 			'settings' => 'ModifyCalendarSettings'
44 45
 		);
45 46
 		$default = 'holidays';
46
-	}
47
-	else
47
+	} else
48 48
 	{
49 49
 		$subActions = array(
50 50
 			'settings' => 'ModifyCalendarSettings'
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 		'help' => 'calendar',
61 61
 		'description' => $txt['calendar_settings_desc'],
62 62
 	);
63
-	if (!empty($modSettings['cal_enabled']))
64
-		$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
63
+	if (!empty($modSettings['cal_enabled'])) {
64
+			$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
65 65
 			'holidays' => array(
66 66
 				'description' => $txt['manage_holidays_desc'],
67 67
 			),
@@ -69,6 +69,7 @@  discard block
 block discarded – undo
69 69
 				'description' => $txt['calendar_settings_desc'],
70 70
 			),
71 71
 		);
72
+	}
72 73
 
73 74
 	call_integration_hook('integrate_manage_calendar', array(&$subActions));
74 75
 
@@ -88,8 +89,9 @@  discard block
 block discarded – undo
88 89
 		checkSession();
89 90
 		validateToken('admin-mc');
90 91
 
91
-		foreach ($_REQUEST['holiday'] as $id => $value)
92
-			$_REQUEST['holiday'][$id] = (int) $id;
92
+		foreach ($_REQUEST['holiday'] as $id => $value) {
93
+					$_REQUEST['holiday'][$id] = (int) $id;
94
+		}
93 95
 
94 96
 		// Now the IDs are "safe" do the delete...
95 97
 		require_once($sourcedir . '/Subs-Calendar.php');
@@ -209,8 +211,9 @@  discard block
 block discarded – undo
209 211
 	$context['sub_template'] = 'edit_holiday';
210 212
 
211 213
 	// Cast this for safety...
212
-	if (isset($_REQUEST['holiday']))
213
-		$_REQUEST['holiday'] = (int) $_REQUEST['holiday'];
214
+	if (isset($_REQUEST['holiday'])) {
215
+			$_REQUEST['holiday'] = (int) $_REQUEST['holiday'];
216
+	}
214 217
 
215 218
 	// Submitting?
216 219
 	if (isset($_POST[$context['session_var']]) && (isset($_REQUEST['delete']) || $_REQUEST['title'] != ''))
@@ -221,19 +224,19 @@  discard block
 block discarded – undo
221 224
 		$_REQUEST['title'] =  $smcFunc['substr']($_REQUEST['title'], 0, 60);
222 225
 		$_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0;
223 226
 
224
-		if (isset($_REQUEST['delete']))
225
-			$smcFunc['db_query']('', '
227
+		if (isset($_REQUEST['delete'])) {
228
+					$smcFunc['db_query']('', '
226 229
 				DELETE FROM {db_prefix}calendar_holidays
227 230
 				WHERE id_holiday = {int:selected_holiday}',
228 231
 				array(
229 232
 					'selected_holiday' => $_REQUEST['holiday'],
230 233
 				)
231 234
 			);
232
-		else
235
+		} else
233 236
 		{
234 237
 			$date = strftime($_REQUEST['year'] <= 1004 ? '1004-%m-%d' : '%Y-%m-%d', mktime(0, 0, 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['year']));
235
-			if (isset($_REQUEST['edit']))
236
-				$smcFunc['db_query']('', '
238
+			if (isset($_REQUEST['edit'])) {
239
+							$smcFunc['db_query']('', '
237 240
 					UPDATE {db_prefix}calendar_holidays
238 241
 					SET event_date = {date:holiday_date}, title = {string:holiday_title}
239 242
 					WHERE id_holiday = {int:selected_holiday}',
@@ -243,8 +246,8 @@  discard block
 block discarded – undo
243 246
 						'holiday_title' => $_REQUEST['title'],
244 247
 					)
245 248
 				);
246
-			else
247
-				$smcFunc['db_insert']('',
249
+			} else {
250
+							$smcFunc['db_insert']('',
248 251
 					'{db_prefix}calendar_holidays',
249 252
 					array(
250 253
 						'event_date' => 'date', 'title' => 'string-60',
@@ -254,6 +257,7 @@  discard block
 block discarded – undo
254 257
 					),
255 258
 					array('id_holiday')
256 259
 				);
260
+			}
257 261
 		}
258 262
 
259 263
 		updateSettings(array(
@@ -265,14 +269,15 @@  discard block
 block discarded – undo
265 269
 	}
266 270
 
267 271
 	// Default states...
268
-	if ($context['is_new'])
269
-		$context['holiday'] = array(
272
+	if ($context['is_new']) {
273
+			$context['holiday'] = array(
270 274
 			'id' => 0,
271 275
 			'day' => date('d'),
272 276
 			'month' => date('m'),
273 277
 			'year' => '0000',
274 278
 			'title' => ''
275 279
 		);
280
+	}
276 281
 	// If it's not new load the data.
277 282
 	else
278 283
 	{
@@ -285,14 +290,15 @@  discard block
 block discarded – undo
285 290
 				'selected_holiday' => $_REQUEST['holiday'],
286 291
 			)
287 292
 		);
288
-		while ($row = $smcFunc['db_fetch_assoc']($request))
289
-			$context['holiday'] = array(
293
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
294
+					$context['holiday'] = array(
290 295
 				'id' => $row['id_holiday'],
291 296
 				'day' => $row['day'],
292 297
 				'month' => $row['month'],
293 298
 				'year' => $row['year'] <= 4 ? 0 : $row['year'],
294 299
 				'title' => $row['title']
295 300
 			);
301
+		}
296 302
 		$smcFunc['db_free_result']($request);
297 303
 	}
298 304
 
@@ -319,16 +325,17 @@  discard block
 block discarded – undo
319 325
 		array(
320 326
 		)
321 327
 	);
322
-	while ($row = $smcFunc['db_fetch_assoc']($request))
323
-		$boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
328
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
329
+			$boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
330
+	}
324 331
 	$smcFunc['db_free_result']($request);
325 332
 
326 333
 	require_once($sourcedir . '/Subs-Boards.php');
327 334
 	sortBoards($boards);
328 335
 
329 336
 	// Look, all the calendar settings - of which there are many!
330
-	if (!empty($modSettings['cal_enabled']))
331
-		$config_vars = array(
337
+	if (!empty($modSettings['cal_enabled'])) {
338
+			$config_vars = array(
332 339
 				array('check', 'cal_enabled'),
333 340
 			'',
334 341
 				// All the permissions:
@@ -371,14 +378,16 @@  discard block
 block discarded – undo
371 378
 				array('check', 'cal_short_days'),
372 379
 				array('check', 'cal_short_months'),
373 380
 		);
374
-	else
375
-		$config_vars = array(
381
+	} else {
382
+			$config_vars = array(
376 383
 			array('check', 'cal_enabled'),
377 384
 		);
385
+	}
378 386
 
379 387
 	call_integration_hook('integrate_modify_calendar_settings', array(&$config_vars));
380
-	if ($return_config)
381
-		return $config_vars;
388
+	if ($return_config) {
389
+			return $config_vars;
390
+	}
382 391
 
383 392
 	// Get the settings template fired up.
384 393
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +694 added lines, -518 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * 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 = '1004-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '1004-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
112
+					}
113
+				} else {
114
+									$value = '1004-01-01';
110 115
 				}
111
-				else
112
-					$value = '1004-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]) : '1004-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '1004-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
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	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))
975
-		fatal_lang_error('no_access', false);
1021
+	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)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,48 +1238,49 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196
-			if ($row['field_length'])
1197
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1260
+			if ($row['field_length']) {
1261
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1262
+			}
1198 1263
 
1199 1264
 			// Any masks?
1200 1265
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1201 1266
 			{
1202 1267
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1203 1268
 				{
1204
-					if ($returnErrors)
1205
-						$errors[] = 'custom_field_mail_fail';
1206
-
1207
-					else
1208
-						$value = '';
1209
-				}
1210
-				elseif ($row['mask'] == 'number')
1269
+					if ($returnErrors) {
1270
+											$errors[] = 'custom_field_mail_fail';
1271
+					} else {
1272
+											$value = '';
1273
+					}
1274
+				} elseif ($row['mask'] == 'number')
1211 1275
 				{
1212 1276
 					$value = (int) $value;
1213
-				}
1214
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1277
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1215 1278
 				{
1216
-					if ($returnErrors)
1217
-						$errors[] = 'custom_field_regex_fail';
1218
-
1219
-					else
1220
-						$value = '';
1279
+					if ($returnErrors) {
1280
+											$errors[] = 'custom_field_regex_fail';
1281
+					} else {
1282
+											$value = '';
1283
+					}
1221 1284
 				}
1222 1285
 			}
1223 1286
 		}
@@ -1243,8 +1306,9 @@  discard block
 block discarded – undo
1243 1306
 
1244 1307
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1245 1308
 
1246
-	if (!empty($hook_errors) && is_array($hook_errors))
1247
-		$errors = array_merge($errors, $hook_errors);
1309
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1310
+			$errors = array_merge($errors, $hook_errors);
1311
+	}
1248 1312
 
1249 1313
 	// Make those changes!
1250 1314
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1262,9 +1326,10 @@  discard block
 block discarded – undo
1262 1326
 		}
1263 1327
 	}
1264 1328
 
1265
-	if ($returnErrors)
1266
-		return $errors;
1267
-}
1329
+	if ($returnErrors) {
1330
+			return $errors;
1331
+	}
1332
+	}
1268 1333
 
1269 1334
 /**
1270 1335
  * Show all the users buddies, as well as a add/delete interface.
@@ -1276,8 +1341,9 @@  discard block
 block discarded – undo
1276 1341
 	global $context, $txt, $modSettings;
1277 1342
 
1278 1343
 	// Do a quick check to ensure people aren't getting here illegally!
1279
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1280
-		fatal_lang_error('no_access', false);
1344
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1345
+			fatal_lang_error('no_access', false);
1346
+	}
1281 1347
 
1282 1348
 	// Can we email the user direct?
1283 1349
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1307,9 +1373,10 @@  discard block
 block discarded – undo
1307 1373
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1308 1374
 	$call = call_helper($subActions[$context['list_area']][0], true);
1309 1375
 
1310
-	if (!empty($call))
1311
-		call_user_func($call, $memID);
1312
-}
1376
+	if (!empty($call)) {
1377
+			call_user_func($call, $memID);
1378
+	}
1379
+	}
1313 1380
 
1314 1381
 /**
1315 1382
  * Show all the users buddies, as well as a add/delete interface.
@@ -1323,9 +1390,10 @@  discard block
 block discarded – undo
1323 1390
 
1324 1391
 	// For making changes!
1325 1392
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1326
-	foreach ($buddiesArray as $k => $dummy)
1327
-		if ($dummy == '')
1393
+	foreach ($buddiesArray as $k => $dummy) {
1394
+			if ($dummy == '')
1328 1395
 			unset($buddiesArray[$k]);
1396
+	}
1329 1397
 
1330 1398
 	// Removing a buddy?
1331 1399
 	if (isset($_GET['remove']))
@@ -1337,10 +1405,11 @@  discard block
 block discarded – undo
1337 1405
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1338 1406
 
1339 1407
 		// Heh, I'm lazy, do it the easy way...
1340
-		foreach ($buddiesArray as $key => $buddy)
1341
-			if ($buddy == (int) $_GET['remove'])
1408
+		foreach ($buddiesArray as $key => $buddy) {
1409
+					if ($buddy == (int) $_GET['remove'])
1342 1410
 			{
1343 1411
 				unset($buddiesArray[$key]);
1412
+		}
1344 1413
 				$_SESSION['prf-save'] = true;
1345 1414
 			}
1346 1415
 
@@ -1350,8 +1419,7 @@  discard block
 block discarded – undo
1350 1419
 
1351 1420
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1352 1421
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1353
-	}
1354
-	elseif (isset($_POST['new_buddy']))
1422
+	} elseif (isset($_POST['new_buddy']))
1355 1423
 	{
1356 1424
 		checkSession();
1357 1425
 
@@ -1364,8 +1432,9 @@  discard block
 block discarded – undo
1364 1432
 		{
1365 1433
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1366 1434
 
1367
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1368
-				unset($new_buddies[$k]);
1435
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1436
+							unset($new_buddies[$k]);
1437
+			}
1369 1438
 		}
1370 1439
 
1371 1440
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1385,16 +1454,18 @@  discard block
 block discarded – undo
1385 1454
 				)
1386 1455
 			);
1387 1456
 
1388
-			if ($smcFunc['db_num_rows']($request) != 0)
1389
-				$_SESSION['prf-save'] = true;
1457
+			if ($smcFunc['db_num_rows']($request) != 0) {
1458
+							$_SESSION['prf-save'] = true;
1459
+			}
1390 1460
 
1391 1461
 			// Add the new member to the buddies array.
1392 1462
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1393 1463
 			{
1394
-				if (in_array($row['id_member'], $buddiesArray))
1395
-					continue;
1396
-				else
1397
-					$buddiesArray[] = (int) $row['id_member'];
1464
+				if (in_array($row['id_member'], $buddiesArray)) {
1465
+									continue;
1466
+				} else {
1467
+									$buddiesArray[] = (int) $row['id_member'];
1468
+				}
1398 1469
 			}
1399 1470
 			$smcFunc['db_free_result']($request);
1400 1471
 
@@ -1424,18 +1495,20 @@  discard block
 block discarded – undo
1424 1495
 
1425 1496
 	$context['custom_pf'] = array();
1426 1497
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1427
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1428
-		if (!isset($disabled_fields[$row['col_name']]))
1498
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1499
+			if (!isset($disabled_fields[$row['col_name']]))
1429 1500
 			$context['custom_pf'][$row['col_name']] = array(
1430 1501
 				'label' => $row['field_name'],
1431 1502
 				'type' => $row['field_type'],
1432 1503
 				'bbc' => !empty($row['bbc']),
1433 1504
 				'enclose' => $row['enclose'],
1434 1505
 			);
1506
+	}
1435 1507
 
1436 1508
 	// Gotta disable the gender option.
1437
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1438
-		unset($context['custom_pf']['cust_gender']);
1509
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1510
+			unset($context['custom_pf']['cust_gender']);
1511
+	}
1439 1512
 
1440 1513
 	$smcFunc['db_free_result']($request);
1441 1514
 
@@ -1452,8 +1525,9 @@  discard block
 block discarded – undo
1452 1525
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1453 1526
 			)
1454 1527
 		);
1455
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1456
-			$buddies[] = $row['id_member'];
1528
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1529
+					$buddies[] = $row['id_member'];
1530
+		}
1457 1531
 		$smcFunc['db_free_result']($result);
1458 1532
 	}
1459 1533
 
@@ -1481,30 +1555,32 @@  discard block
 block discarded – undo
1481 1555
 					continue;
1482 1556
 				}
1483 1557
 
1484
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1485
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1486
-
1487
-				elseif ($column['type'] == 'check')
1488
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1558
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1559
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1560
+				} elseif ($column['type'] == 'check') {
1561
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				}
1489 1563
 
1490 1564
 				// Enclosing the user input within some other text?
1491
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1492
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1565
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1566
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1493 1567
 						'{SCRIPTURL}' => $scripturl,
1494 1568
 						'{IMAGES_URL}' => $settings['images_url'],
1495 1569
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1496 1570
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1497 1571
 					));
1572
+				}
1498 1573
 			}
1499 1574
 		}
1500 1575
 	}
1501 1576
 
1502 1577
 	if (isset($_SESSION['prf-save']))
1503 1578
 	{
1504
-		if ($_SESSION['prf-save'] === true)
1505
-			$context['saved_successful'] = true;
1506
-		else
1507
-			$context['saved_failed'] = $_SESSION['prf-save'];
1579
+		if ($_SESSION['prf-save'] === true) {
1580
+					$context['saved_successful'] = true;
1581
+		} else {
1582
+					$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		}
1508 1584
 
1509 1585
 		unset($_SESSION['prf-save']);
1510 1586
 	}
@@ -1524,9 +1600,10 @@  discard block
 block discarded – undo
1524 1600
 
1525 1601
 	// For making changes!
1526 1602
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1527
-	foreach ($ignoreArray as $k => $dummy)
1528
-		if ($dummy == '')
1603
+	foreach ($ignoreArray as $k => $dummy) {
1604
+			if ($dummy == '')
1529 1605
 			unset($ignoreArray[$k]);
1606
+	}
1530 1607
 
1531 1608
 	// Removing a member from the ignore list?
1532 1609
 	if (isset($_GET['remove']))
@@ -1536,10 +1613,11 @@  discard block
 block discarded – undo
1536 1613
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1537 1614
 
1538 1615
 		// Heh, I'm lazy, do it the easy way...
1539
-		foreach ($ignoreArray as $key => $id_remove)
1540
-			if ($id_remove == (int) $_GET['remove'])
1616
+		foreach ($ignoreArray as $key => $id_remove) {
1617
+					if ($id_remove == (int) $_GET['remove'])
1541 1618
 			{
1542 1619
 				unset($ignoreArray[$key]);
1620
+		}
1543 1621
 				$_SESSION['prf-save'] = true;
1544 1622
 			}
1545 1623
 
@@ -1549,8 +1627,7 @@  discard block
 block discarded – undo
1549 1627
 
1550 1628
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1551 1629
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1552
-	}
1553
-	elseif (isset($_POST['new_ignore']))
1630
+	} elseif (isset($_POST['new_ignore']))
1554 1631
 	{
1555 1632
 		checkSession();
1556 1633
 		// Prepare the string for extraction...
@@ -1562,8 +1639,9 @@  discard block
 block discarded – undo
1562 1639
 		{
1563 1640
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1564 1641
 
1565
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1566
-				unset($new_entries[$k]);
1642
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1643
+							unset($new_entries[$k]);
1644
+			}
1567 1645
 		}
1568 1646
 
1569 1647
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1581,16 +1659,18 @@  discard block
 block discarded – undo
1581 1659
 				)
1582 1660
 			);
1583 1661
 
1584
-			if ($smcFunc['db_num_rows']($request) != 0)
1585
-				$_SESSION['prf-save'] = true;
1662
+			if ($smcFunc['db_num_rows']($request) != 0) {
1663
+							$_SESSION['prf-save'] = true;
1664
+			}
1586 1665
 
1587 1666
 			// Add the new member to the buddies array.
1588 1667
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1589 1668
 			{
1590
-				if (in_array($row['id_member'], $ignoreArray))
1591
-					continue;
1592
-				else
1593
-					$ignoreArray[] = (int) $row['id_member'];
1669
+				if (in_array($row['id_member'], $ignoreArray)) {
1670
+									continue;
1671
+				} else {
1672
+									$ignoreArray[] = (int) $row['id_member'];
1673
+				}
1594 1674
 			}
1595 1675
 			$smcFunc['db_free_result']($request);
1596 1676
 
@@ -1619,8 +1699,9 @@  discard block
 block discarded – undo
1619 1699
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1620 1700
 			)
1621 1701
 		);
1622
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1623
-			$ignored[] = $row['id_member'];
1702
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1703
+					$ignored[] = $row['id_member'];
1704
+		}
1624 1705
 		$smcFunc['db_free_result']($result);
1625 1706
 	}
1626 1707
 
@@ -1639,10 +1720,11 @@  discard block
 block discarded – undo
1639 1720
 
1640 1721
 	if (isset($_SESSION['prf-save']))
1641 1722
 	{
1642
-		if ($_SESSION['prf-save'] === true)
1643
-			$context['saved_successful'] = true;
1644
-		else
1645
-			$context['saved_failed'] = $_SESSION['prf-save'];
1723
+		if ($_SESSION['prf-save'] === true) {
1724
+					$context['saved_successful'] = true;
1725
+		} else {
1726
+					$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		}
1646 1728
 
1647 1729
 		unset($_SESSION['prf-save']);
1648 1730
 	}
@@ -1658,8 +1740,9 @@  discard block
 block discarded – undo
1658 1740
 	global $context, $txt;
1659 1741
 
1660 1742
 	loadThemeOptions($memID);
1661
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1662
-		loadCustomFields($memID, 'account');
1743
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1744
+			loadCustomFields($memID, 'account');
1745
+	}
1663 1746
 
1664 1747
 	$context['sub_template'] = 'edit_options';
1665 1748
 	$context['page_desc'] = $txt['account_info'];
@@ -1686,8 +1769,9 @@  discard block
 block discarded – undo
1686 1769
 	global $context, $txt;
1687 1770
 
1688 1771
 	loadThemeOptions($memID);
1689
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1690
-		loadCustomFields($memID, 'forumprofile');
1772
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1773
+			loadCustomFields($memID, 'forumprofile');
1774
+	}
1691 1775
 
1692 1776
 	$context['sub_template'] = 'edit_options';
1693 1777
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1720,18 +1804,21 @@  discard block
 block discarded – undo
1720 1804
 	$dirs = array();
1721 1805
 	$files = array();
1722 1806
 
1723
-	if (!$dir)
1724
-		return array();
1807
+	if (!$dir) {
1808
+			return array();
1809
+	}
1725 1810
 
1726 1811
 	while ($line = $dir->read())
1727 1812
 	{
1728
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1729
-			continue;
1813
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1814
+					continue;
1815
+		}
1730 1816
 
1731
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1732
-			$dirs[] = $line;
1733
-		else
1734
-			$files[] = $line;
1817
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1818
+					$dirs[] = $line;
1819
+		} else {
1820
+					$files[] = $line;
1821
+		}
1735 1822
 	}
1736 1823
 	$dir->close();
1737 1824
 
@@ -1752,14 +1839,15 @@  discard block
 block discarded – undo
1752 1839
 	foreach ($dirs as $line)
1753 1840
 	{
1754 1841
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1755
-		if (!empty($tmp))
1756
-			$result[] = array(
1842
+		if (!empty($tmp)) {
1843
+					$result[] = array(
1757 1844
 				'filename' => $smcFunc['htmlspecialchars']($line),
1758 1845
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1759 1846
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1760 1847
 				'is_dir' => true,
1761 1848
 				'files' => $tmp
1762 1849
 		);
1850
+		}
1763 1851
 		unset($tmp);
1764 1852
 	}
1765 1853
 
@@ -1769,8 +1857,9 @@  discard block
 block discarded – undo
1769 1857
 		$extension = substr(strrchr($line, '.'), 1);
1770 1858
 
1771 1859
 		// Make sure it is an image.
1772
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1773
-			continue;
1860
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1861
+					continue;
1862
+		}
1774 1863
 
1775 1864
 		$result[] = array(
1776 1865
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1778,8 +1867,9 @@  discard block
 block discarded – undo
1778 1867
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1779 1868
 			'is_dir' => false
1780 1869
 		);
1781
-		if ($level == 1)
1782
-			$context['avatar_list'][] = $directory . '/' . $line;
1870
+		if ($level == 1) {
1871
+					$context['avatar_list'][] = $directory . '/' . $line;
1872
+		}
1783 1873
 	}
1784 1874
 
1785 1875
 	return $result;
@@ -1798,8 +1888,9 @@  discard block
 block discarded – undo
1798 1888
 	loadSubTemplate('options');
1799 1889
 
1800 1890
 	loadThemeOptions($memID);
1801
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1802
-		loadCustomFields($memID, 'theme');
1891
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1892
+			loadCustomFields($memID, 'theme');
1893
+	}
1803 1894
 
1804 1895
 	$context['sub_template'] = 'edit_options';
1805 1896
 	$context['page_desc'] = $txt['theme_info'];
@@ -1853,16 +1944,19 @@  discard block
 block discarded – undo
1853 1944
 {
1854 1945
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1855 1946
 
1856
-	if (!isset($context['token_check']))
1857
-		$context['token_check'] = 'profile-nt' . $memID;
1947
+	if (!isset($context['token_check'])) {
1948
+			$context['token_check'] = 'profile-nt' . $memID;
1949
+	}
1858 1950
 
1859 1951
 	is_not_guest();
1860
-	if (!$context['user']['is_owner'])
1861
-		isAllowedTo('profile_extra_any');
1952
+	if (!$context['user']['is_owner']) {
1953
+			isAllowedTo('profile_extra_any');
1954
+	}
1862 1955
 
1863 1956
 	// Set the post action if we're coming from the profile...
1864
-	if (!isset($context['action']))
1865
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1957
+	if (!isset($context['action'])) {
1958
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1959
+	}
1866 1960
 
1867 1961
 	// What options are set
1868 1962
 	loadThemeOptions($memID);
@@ -1949,28 +2043,34 @@  discard block
 block discarded – undo
1949 2043
 	);
1950 2044
 
1951 2045
 	// There are certain things that are disabled at the group level.
1952
-	if (empty($modSettings['cal_enabled']))
1953
-		unset($alert_types['calendar']);
2046
+	if (empty($modSettings['cal_enabled'])) {
2047
+			unset($alert_types['calendar']);
2048
+	}
1954 2049
 
1955 2050
 	// Disable paid subscriptions at group level if they're disabled
1956
-	if (empty($modSettings['paid_enabled']))
1957
-		unset($alert_types['paidsubs']);
2051
+	if (empty($modSettings['paid_enabled'])) {
2052
+			unset($alert_types['paidsubs']);
2053
+	}
1958 2054
 
1959 2055
 	// Disable membergroup requests at group level if they're disabled
1960
-	if (empty($modSettings['show_group_membership']))
1961
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2056
+	if (empty($modSettings['show_group_membership'])) {
2057
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2058
+	}
1962 2059
 
1963 2060
 	// Disable mentions if they're disabled
1964
-	if (empty($modSettings['enable_mentions']))
1965
-		unset($alert_types['msg']['msg_mention']);
2061
+	if (empty($modSettings['enable_mentions'])) {
2062
+			unset($alert_types['msg']['msg_mention']);
2063
+	}
1966 2064
 
1967 2065
 	// Disable likes if they're disabled
1968
-	if (empty($modSettings['enable_likes']))
1969
-		unset($alert_types['msg']['msg_like']);
2066
+	if (empty($modSettings['enable_likes'])) {
2067
+			unset($alert_types['msg']['msg_like']);
2068
+	}
1970 2069
 
1971 2070
 	// Disable buddy requests if they're disabled
1972
-	if (empty($modSettings['enable_buddylist']))
1973
-		unset($alert_types['members']['buddy_request']);
2071
+	if (empty($modSettings['enable_buddylist'])) {
2072
+			unset($alert_types['members']['buddy_request']);
2073
+	}
1974 2074
 
1975 2075
 	// Now, now, we could pass this through global but we should really get into the habit of
1976 2076
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -1998,15 +2098,17 @@  discard block
 block discarded – undo
1998 2098
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
1999 2099
 		}
2000 2100
 
2001
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2002
-			unset($alert_types['members']['request_group']);
2101
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2102
+					unset($alert_types['members']['request_group']);
2103
+		}
2003 2104
 
2004 2105
 		foreach ($alert_types as $group => $items)
2005 2106
 		{
2006 2107
 			foreach ($items as $alert_key => $alert_value)
2007 2108
 			{
2008
-				if (!isset($alert_value['permission']))
2009
-					continue;
2109
+				if (!isset($alert_value['permission'])) {
2110
+									continue;
2111
+				}
2010 2112
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2011 2113
 				{
2012 2114
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2014,12 +2116,14 @@  discard block
 block discarded – undo
2014 2116
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2015 2117
 				}
2016 2118
 
2017
-				if (!$perms_cache[$alert_value['permission']['name']])
2018
-					unset ($alert_types[$group][$alert_key]);
2119
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2120
+									unset ($alert_types[$group][$alert_key]);
2121
+				}
2019 2122
 			}
2020 2123
 
2021
-			if (empty($alert_types[$group]))
2022
-				unset ($alert_types[$group]);
2124
+			if (empty($alert_types[$group])) {
2125
+							unset ($alert_types[$group]);
2126
+			}
2023 2127
 		}
2024 2128
 	}
2025 2129
 
@@ -2051,9 +2155,9 @@  discard block
 block discarded – undo
2051 2155
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2052 2156
 						break;
2053 2157
 					case 'select':
2054
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2055
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2056
-						else
2158
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2159
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2160
+						} else
2057 2161
 						{
2058 2162
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2059 2163
 							$keys = array_keys($this_option['opts']);
@@ -2073,23 +2177,28 @@  discard block
 block discarded – undo
2073 2177
 				$this_value = 0;
2074 2178
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2075 2179
 				{
2076
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2077
-						$this_value |= $bitvalue;
2180
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2181
+											$this_value |= $bitvalue;
2182
+					}
2183
+				}
2184
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2185
+									$update_prefs[$item_key] = $this_value;
2078 2186
 				}
2079
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2080
-					$update_prefs[$item_key] = $this_value;
2081 2187
 			}
2082 2188
 		}
2083 2189
 
2084
-		if (!empty($_POST['opt_alert_timeout']))
2085
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2190
+		if (!empty($_POST['opt_alert_timeout'])) {
2191
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2192
+		}
2086 2193
 
2087
-		if (!empty($_POST['notify_announcements']))
2088
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2194
+		if (!empty($_POST['notify_announcements'])) {
2195
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2196
+		}
2089 2197
 
2090 2198
 		setNotifyPrefs((int) $memID, $update_prefs);
2091
-		foreach ($update_prefs as $pref => $value)
2092
-			$context['alert_prefs'][$pref] = $value;
2199
+		foreach ($update_prefs as $pref => $value) {
2200
+					$context['alert_prefs'][$pref] = $value;
2201
+		}
2093 2202
 
2094 2203
 		makeNotificationChanges($memID);
2095 2204
 
@@ -2119,8 +2228,9 @@  discard block
 block discarded – undo
2119 2228
 
2120 2229
 	// Now we're all set up.
2121 2230
 	is_not_guest();
2122
-	if (!$context['user']['is_owner'])
2123
-		fatal_error('no_access');
2231
+	if (!$context['user']['is_owner']) {
2232
+			fatal_error('no_access');
2233
+	}
2124 2234
 
2125 2235
 	checkSession('get');
2126 2236
 
@@ -2152,8 +2262,9 @@  discard block
 block discarded – undo
2152 2262
 {
2153 2263
 	global $smcFunc;
2154 2264
 
2155
-	if (empty($toMark) || empty($memID))
2156
-		return false;
2265
+	if (empty($toMark) || empty($memID)) {
2266
+			return false;
2267
+	}
2157 2268
 
2158 2269
 	$toMark = (array) $toMark;
2159 2270
 
@@ -2187,8 +2298,9 @@  discard block
 block discarded – undo
2187 2298
 {
2188 2299
 	global $smcFunc;
2189 2300
 
2190
-	if (empty($toDelete))
2191
-		return false;
2301
+	if (empty($toDelete)) {
2302
+			return false;
2303
+	}
2192 2304
 
2193 2305
 	$toDelete = (array) $toDelete;
2194 2306
 
@@ -2223,8 +2335,9 @@  discard block
 block discarded – undo
2223 2335
 {
2224 2336
 	global $smcFunc;
2225 2337
 
2226
-	if (empty($memID))
2227
-		return false;
2338
+	if (empty($memID)) {
2339
+			return false;
2340
+	}
2228 2341
 
2229 2342
 	$request = $smcFunc['db_query']('', '
2230 2343
 		SELECT id_alert
@@ -2301,8 +2414,9 @@  discard block
 block discarded – undo
2301 2414
 					{
2302 2415
 						$link = $topic['link'];
2303 2416
 
2304
-						if ($topic['new'])
2305
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2417
+						if ($topic['new']) {
2418
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2419
+						}
2306 2420
 
2307 2421
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2308 2422
 
@@ -2453,8 +2567,9 @@  discard block
 block discarded – undo
2453 2567
 					{
2454 2568
 						$link = $board['link'];
2455 2569
 
2456
-						if ($board['new'])
2457
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2570
+						if ($board['new']) {
2571
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2572
+						}
2458 2573
 
2459 2574
 						return $link;
2460 2575
 					},
@@ -2654,8 +2769,8 @@  discard block
 block discarded – undo
2654 2769
 		)
2655 2770
 	);
2656 2771
 	$notification_boards = array();
2657
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2658
-		$notification_boards[] = array(
2772
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2773
+			$notification_boards[] = array(
2659 2774
 			'id' => $row['id_board'],
2660 2775
 			'name' => $row['name'],
2661 2776
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2663,6 +2778,7 @@  discard block
 block discarded – undo
2663 2778
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2664 2779
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2665 2780
 		);
2781
+	}
2666 2782
 	$smcFunc['db_free_result']($request);
2667 2783
 
2668 2784
 	return $notification_boards;
@@ -2677,17 +2793,18 @@  discard block
 block discarded – undo
2677 2793
 {
2678 2794
 	global $context, $options, $cur_profile, $smcFunc;
2679 2795
 
2680
-	if (isset($_POST['default_options']))
2681
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2796
+	if (isset($_POST['default_options'])) {
2797
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2798
+	}
2682 2799
 
2683 2800
 	if ($context['user']['is_owner'])
2684 2801
 	{
2685 2802
 		$context['member']['options'] = $options;
2686
-		if (isset($_POST['options']) && is_array($_POST['options']))
2687
-			foreach ($_POST['options'] as $k => $v)
2803
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2804
+					foreach ($_POST['options'] as $k => $v)
2688 2805
 				$context['member']['options'][$k] = $v;
2689
-	}
2690
-	else
2806
+		}
2807
+	} else
2691 2808
 	{
2692 2809
 		$request = $smcFunc['db_query']('', '
2693 2810
 			SELECT id_member, variable, value
@@ -2708,8 +2825,9 @@  discard block
 block discarded – undo
2708 2825
 				continue;
2709 2826
 			}
2710 2827
 
2711
-			if (isset($_POST['options'][$row['variable']]))
2712
-				$row['value'] = $_POST['options'][$row['variable']];
2828
+			if (isset($_POST['options'][$row['variable']])) {
2829
+							$row['value'] = $_POST['options'][$row['variable']];
2830
+			}
2713 2831
 			$context['member']['options'][$row['variable']] = $row['value'];
2714 2832
 		}
2715 2833
 		$smcFunc['db_free_result']($request);
@@ -2717,8 +2835,9 @@  discard block
 block discarded – undo
2717 2835
 		// Load up the default theme options for any missing.
2718 2836
 		foreach ($temp as $k => $v)
2719 2837
 		{
2720
-			if (!isset($context['member']['options'][$k]))
2721
-				$context['member']['options'][$k] = $v;
2838
+			if (!isset($context['member']['options'][$k])) {
2839
+							$context['member']['options'][$k] = $v;
2840
+			}
2722 2841
 		}
2723 2842
 	}
2724 2843
 }
@@ -2733,8 +2852,9 @@  discard block
 block discarded – undo
2733 2852
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2734 2853
 
2735 2854
 	// Have the admins enabled this option?
2736
-	if (empty($modSettings['allow_ignore_boards']))
2737
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2855
+	if (empty($modSettings['allow_ignore_boards'])) {
2856
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2857
+	}
2738 2858
 
2739 2859
 	// Find all the boards this user is allowed to see.
2740 2860
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2754,12 +2874,13 @@  discard block
 block discarded – undo
2754 2874
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2755 2875
 	{
2756 2876
 		// This category hasn't been set up yet..
2757
-		if (!isset($context['categories'][$row['id_cat']]))
2758
-			$context['categories'][$row['id_cat']] = array(
2877
+		if (!isset($context['categories'][$row['id_cat']])) {
2878
+					$context['categories'][$row['id_cat']] = array(
2759 2879
 				'id' => $row['id_cat'],
2760 2880
 				'name' => $row['cat_name'],
2761 2881
 				'boards' => array()
2762 2882
 			);
2883
+		}
2763 2884
 
2764 2885
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2765 2886
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2789,18 +2910,20 @@  discard block
 block discarded – undo
2789 2910
 	}
2790 2911
 
2791 2912
 	$max_boards = ceil(count($temp_boards) / 2);
2792
-	if ($max_boards == 1)
2793
-		$max_boards = 2;
2913
+	if ($max_boards == 1) {
2914
+			$max_boards = 2;
2915
+	}
2794 2916
 
2795 2917
 	// Now, alternate them so they can be shown left and right ;).
2796 2918
 	$context['board_columns'] = array();
2797 2919
 	for ($i = 0; $i < $max_boards; $i++)
2798 2920
 	{
2799 2921
 		$context['board_columns'][] = $temp_boards[$i];
2800
-		if (isset($temp_boards[$i + $max_boards]))
2801
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2802
-		else
2803
-			$context['board_columns'][] = array();
2922
+		if (isset($temp_boards[$i + $max_boards])) {
2923
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2924
+		} else {
2925
+					$context['board_columns'][] = array();
2926
+		}
2804 2927
 	}
2805 2928
 
2806 2929
 	loadThemeOptions($memID);
@@ -2869,8 +2992,9 @@  discard block
 block discarded – undo
2869 2992
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2870 2993
 	{
2871 2994
 		// We should skip the administrator group if they don't have the admin_forum permission!
2872
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2873
-			continue;
2995
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
2996
+					continue;
2997
+		}
2874 2998
 
2875 2999
 		$context['member_groups'][$row['id_group']] = array(
2876 3000
 			'id' => $row['id_group'],
@@ -2916,16 +3040,17 @@  discard block
 block discarded – undo
2916 3040
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2917 3041
 	// Warning message for signature image limits?
2918 3042
 	$context['signature_warning'] = '';
2919
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2920
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2921
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2922
-		$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']);
3043
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3044
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3045
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3046
+			$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
+	}
2923 3048
 
2924 3049
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2925 3050
 
2926
-	if (empty($context['do_preview']))
2927
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2928
-	else
3051
+	if (empty($context['do_preview'])) {
3052
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3053
+	} else
2929 3054
 	{
2930 3055
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2931 3056
 		$validation = profileValidateSignature($signature);
@@ -2935,8 +3060,9 @@  discard block
 block discarded – undo
2935 3060
 			$context['post_errors'] = array();
2936 3061
 		}
2937 3062
 		$context['post_errors'][] = 'signature_not_yet_saved';
2938
-		if ($validation !== true && $validation !== false)
2939
-			$context['post_errors'][] = $validation;
3063
+		if ($validation !== true && $validation !== false) {
3064
+					$context['post_errors'][] = $validation;
3065
+		}
2940 3066
 
2941 3067
 		censorText($context['member']['signature']);
2942 3068
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2946,8 +3072,9 @@  discard block
 block discarded – undo
2946 3072
 	}
2947 3073
 
2948 3074
 	// Load the spell checker?
2949
-	if ($context['show_spellchecking'])
2950
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3075
+	if ($context['show_spellchecking']) {
3076
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3077
+	}
2951 3078
 
2952 3079
 	return true;
2953 3080
 }
@@ -2981,8 +3108,7 @@  discard block
 block discarded – undo
2981 3108
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2982 3109
 		);
2983 3110
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2984
-	}
2985
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3111
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2986 3112
 	{
2987 3113
 		$context['member']['avatar'] += array(
2988 3114
 			'choice' => 'upload',
@@ -2992,33 +3118,34 @@  discard block
 block discarded – undo
2992 3118
 		$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'];
2993 3119
 	}
2994 3120
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
2995
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
2996
-		$context['member']['avatar'] += array(
3121
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3122
+			$context['member']['avatar'] += array(
2997 3123
 			'choice' => 'external',
2998 3124
 			'server_pic' => 'blank.png',
2999 3125
 			'external' => $cur_profile['avatar_original']
3000 3126
 		);
3001
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3002
-		$context['member']['avatar'] += array(
3127
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3128
+			$context['member']['avatar'] += array(
3003 3129
 			'choice' => 'server_stored',
3004 3130
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3005 3131
 			'external' => 'http://'
3006 3132
 		);
3007
-	else
3008
-		$context['member']['avatar'] += array(
3133
+	} else {
3134
+			$context['member']['avatar'] += array(
3009 3135
 			'choice' => 'none',
3010 3136
 			'server_pic' => 'blank.png',
3011 3137
 			'external' => 'http://'
3012 3138
 		);
3139
+	}
3013 3140
 
3014 3141
 	// Get a list of all the avatars.
3015 3142
 	if ($context['member']['avatar']['allow_server_stored'])
3016 3143
 	{
3017 3144
 		$context['avatar_list'] = array();
3018 3145
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3146
+	} else {
3147
+			$context['avatars'] = array();
3019 3148
 	}
3020
-	else
3021
-		$context['avatars'] = array();
3022 3149
 
3023 3150
 	// Second level selected avatar...
3024 3151
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3047,19 +3174,22 @@  discard block
 block discarded – undo
3047 3174
 			)
3048 3175
 		);
3049 3176
 		$protected_groups = array(1);
3050
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3051
-			$protected_groups[] = $row['id_group'];
3177
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3178
+					$protected_groups[] = $row['id_group'];
3179
+		}
3052 3180
 		$smcFunc['db_free_result']($request);
3053 3181
 
3054 3182
 		$protected_groups = array_unique($protected_groups);
3055 3183
 	}
3056 3184
 
3057 3185
 	// The account page allows the change of your id_group - but not to a protected group!
3058
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3059
-		$value = (int) $value;
3186
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3187
+			$value = (int) $value;
3188
+	}
3060 3189
 	// ... otherwise it's the old group sir.
3061
-	else
3062
-		$value = $old_profile['id_group'];
3190
+	else {
3191
+			$value = $old_profile['id_group'];
3192
+	}
3063 3193
 
3064 3194
 	// Find the additional membergroups (if any)
3065 3195
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3068,16 +3198,18 @@  discard block
 block discarded – undo
3068 3198
 		foreach ($_POST['additional_groups'] as $group_id)
3069 3199
 		{
3070 3200
 			$group_id = (int) $group_id;
3071
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3072
-				$additional_groups[] = $group_id;
3201
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3202
+							$additional_groups[] = $group_id;
3203
+			}
3073 3204
 		}
3074 3205
 
3075 3206
 		// Put the protected groups back in there if you don't have permission to take them away.
3076 3207
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3077 3208
 		foreach ($old_additional_groups as $group_id)
3078 3209
 		{
3079
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3080
-				$additional_groups[] = $group_id;
3210
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3211
+							$additional_groups[] = $group_id;
3212
+			}
3081 3213
 		}
3082 3214
 
3083 3215
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3109,18 +3241,20 @@  discard block
 block discarded – undo
3109 3241
 			list ($another) = $smcFunc['db_fetch_row']($request);
3110 3242
 			$smcFunc['db_free_result']($request);
3111 3243
 
3112
-			if (empty($another))
3113
-				fatal_lang_error('at_least_one_admin', 'critical');
3244
+			if (empty($another)) {
3245
+							fatal_lang_error('at_least_one_admin', 'critical');
3246
+			}
3114 3247
 		}
3115 3248
 	}
3116 3249
 
3117 3250
 	// If we are changing group status, update permission cache as necessary.
3118 3251
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3119 3252
 	{
3120
-		if ($context['user']['is_owner'])
3121
-			$_SESSION['mc']['time'] = 0;
3122
-		else
3123
-			updateSettings(array('settings_updated' => time()));
3253
+		if ($context['user']['is_owner']) {
3254
+					$_SESSION['mc']['time'] = 0;
3255
+		} else {
3256
+					updateSettings(array('settings_updated' => time()));
3257
+		}
3124 3258
 	}
3125 3259
 
3126 3260
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3141,8 +3275,9 @@  discard block
 block discarded – undo
3141 3275
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3142 3276
 
3143 3277
 	$memID = $context['id_member'];
3144
-	if (empty($memID) && !empty($context['password_auth_failed']))
3145
-		return false;
3278
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3279
+			return false;
3280
+	}
3146 3281
 
3147 3282
 	require_once($sourcedir . '/ManageAttachments.php');
3148 3283
 
@@ -3153,8 +3288,9 @@  discard block
 block discarded – undo
3153 3288
 	$downloadedExternalAvatar = false;
3154 3289
 	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']))
3155 3290
 	{
3156
-		if (!is_writable($uploadDir))
3157
-			fatal_lang_error('attachments_no_write', 'critical');
3291
+		if (!is_writable($uploadDir)) {
3292
+					fatal_lang_error('attachments_no_write', 'critical');
3293
+		}
3158 3294
 
3159 3295
 		require_once($sourcedir . '/Subs-Package.php');
3160 3296
 
@@ -3198,19 +3334,18 @@  discard block
 block discarded – undo
3198 3334
 
3199 3335
 		// Get rid of their old avatar. (if uploaded.)
3200 3336
 		removeAttachments(array('id_member' => $memID));
3201
-	}
3202
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3337
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3203 3338
 	{
3204 3339
 		// 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.
3205
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3206
-			$profile_vars['avatar'] = 'gravatar://';
3207
-		else
3208
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3340
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3341
+					$profile_vars['avatar'] = 'gravatar://';
3342
+		} else {
3343
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3344
+		}
3209 3345
 
3210 3346
 		// Get rid of their old avatar. (if uploaded.)
3211 3347
 		removeAttachments(array('id_member' => $memID));
3212
-	}
3213
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3348
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3214 3349
 	{
3215 3350
 		// We need these clean...
3216 3351
 		$cur_profile['id_attach'] = 0;
@@ -3222,11 +3357,13 @@  discard block
 block discarded – undo
3222 3357
 
3223 3358
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3224 3359
 
3225
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3226
-			$profile_vars['avatar'] = '';
3360
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3361
+					$profile_vars['avatar'] = '';
3362
+		}
3227 3363
 		// Trying to make us do something we'll regret?
3228
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3229
-			return 'bad_avatar_invalid_url';
3364
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3365
+					return 'bad_avatar_invalid_url';
3366
+		}
3230 3367
 		// Should we check dimensions?
3231 3368
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3232 3369
 		{
@@ -3236,9 +3373,9 @@  discard block
 block discarded – undo
3236 3373
 			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']))))
3237 3374
 			{
3238 3375
 				// Houston, we have a problem. The avatar is too large!!
3239
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3240
-					return 'bad_avatar_too_large';
3241
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3376
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3377
+									return 'bad_avatar_too_large';
3378
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3242 3379
 				{
3243 3380
 					// @todo remove this if appropriate
3244 3381
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3248,26 +3385,27 @@  discard block
 block discarded – undo
3248 3385
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3249 3386
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3250 3387
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3388
+					} else {
3389
+											return 'bad_avatar';
3251 3390
 					}
3252
-					else
3253
-						return 'bad_avatar';
3254 3391
 				}
3255 3392
 			}
3256 3393
 		}
3257
-	}
3258
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3394
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3259 3395
 	{
3260 3396
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3261 3397
 		{
3262 3398
 			// Get the dimensions of the image.
3263 3399
 			if (!$downloadedExternalAvatar)
3264 3400
 			{
3265
-				if (!is_writable($uploadDir))
3266
-					fatal_lang_error('attachments_no_write', 'critical');
3401
+				if (!is_writable($uploadDir)) {
3402
+									fatal_lang_error('attachments_no_write', 'critical');
3403
+				}
3267 3404
 
3268 3405
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3269
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3270
-					fatal_lang_error('attach_timeout', 'critical');
3406
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3407
+									fatal_lang_error('attach_timeout', 'critical');
3408
+				}
3271 3409
 
3272 3410
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3273 3411
 			}
@@ -3380,17 +3518,19 @@  discard block
 block discarded – undo
3380 3518
 			$profile_vars['avatar'] = '';
3381 3519
 
3382 3520
 			// Delete any temporary file.
3383
-			if (file_exists($_FILES['attachment']['tmp_name']))
3384
-				@unlink($_FILES['attachment']['tmp_name']);
3521
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3522
+							@unlink($_FILES['attachment']['tmp_name']);
3523
+			}
3385 3524
 		}
3386 3525
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3387
-		else
3526
+		else {
3527
+					$profile_vars['avatar'] = '';
3528
+		}
3529
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3530
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3531
+	} else {
3388 3532
 			$profile_vars['avatar'] = '';
3389 3533
 	}
3390
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3391
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3392
-	else
3393
-		$profile_vars['avatar'] = '';
3394 3534
 
3395 3535
 	// Setup the profile variables so it shows things right on display!
3396 3536
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3438,9 +3578,9 @@  discard block
 block discarded – undo
3438 3578
 		$smiley_parsed = $unparsed_signature;
3439 3579
 		parsesmileys($smiley_parsed);
3440 3580
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3441
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3442
-			return 'signature_allow_smileys';
3443
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3581
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3582
+					return 'signature_allow_smileys';
3583
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3444 3584
 		{
3445 3585
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3446 3586
 			return 'signature_max_smileys';
@@ -3453,14 +3593,15 @@  discard block
 block discarded – undo
3453 3593
 			{
3454 3594
 				$limit_broke = 0;
3455 3595
 				// Attempt to allow all sizes of abuse, so to speak.
3456
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3457
-					$limit_broke = $sig_limits[7] . 'px';
3458
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3459
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3460
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3461
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3462
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3463
-					$limit_broke = 'large';
3596
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3597
+									$limit_broke = $sig_limits[7] . 'px';
3598
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3599
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3600
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3601
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3602
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3603
+									$limit_broke = 'large';
3604
+				}
3464 3605
 
3465 3606
 				if ($limit_broke)
3466 3607
 				{
@@ -3502,24 +3643,26 @@  discard block
 block discarded – undo
3502 3643
 					$width = -1; $height = -1;
3503 3644
 
3504 3645
 					// Does it have predefined restraints? Width first.
3505
-					if ($matches[6][$key])
3506
-						$matches[2][$key] = $matches[6][$key];
3646
+					if ($matches[6][$key]) {
3647
+											$matches[2][$key] = $matches[6][$key];
3648
+					}
3507 3649
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3508 3650
 					{
3509 3651
 						$width = $sig_limits[5];
3510 3652
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3653
+					} elseif ($matches[2][$key]) {
3654
+											$width = $matches[2][$key];
3511 3655
 					}
3512
-					elseif ($matches[2][$key])
3513
-						$width = $matches[2][$key];
3514 3656
 					// ... and height.
3515 3657
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3516 3658
 					{
3517 3659
 						$height = $sig_limits[6];
3518
-						if ($width != -1)
3519
-							$width = $width * ($height / $matches[4][$key]);
3660
+						if ($width != -1) {
3661
+													$width = $width * ($height / $matches[4][$key]);
3662
+						}
3663
+					} elseif ($matches[4][$key]) {
3664
+											$height = $matches[4][$key];
3520 3665
 					}
3521
-					elseif ($matches[4][$key])
3522
-						$height = $matches[4][$key];
3523 3666
 
3524 3667
 					// If the dimensions are still not fixed - we need to check the actual image.
3525 3668
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3537,21 +3680,24 @@  discard block
 block discarded – undo
3537 3680
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3538 3681
 							{
3539 3682
 								$height = $sig_limits[6];
3540
-								if ($width == -1)
3541
-									$width = $sizes[0];
3683
+								if ($width == -1) {
3684
+																	$width = $sizes[0];
3685
+								}
3542 3686
 								$width = $width * ($height / $sizes[1]);
3687
+							} elseif ($width != -1) {
3688
+															$height = $sizes[1];
3543 3689
 							}
3544
-							elseif ($width != -1)
3545
-								$height = $sizes[1];
3546 3690
 						}
3547 3691
 					}
3548 3692
 
3549 3693
 					// Did we come up with some changes? If so remake the string.
3550
-					if ($width != -1 || $height != -1)
3551
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3694
+					if ($width != -1 || $height != -1) {
3695
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					}
3697
+				}
3698
+				if (!empty($replaces)) {
3699
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3552 3700
 				}
3553
-				if (!empty($replaces))
3554
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3555 3701
 			}
3556 3702
 		}
3557 3703
 
@@ -3595,10 +3741,12 @@  discard block
 block discarded – undo
3595 3741
 	$email = strtr($email, array('&#039;' => '\''));
3596 3742
 
3597 3743
 	// Check the name and email for validity.
3598
-	if (trim($email) == '')
3599
-		return 'no_email';
3600
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3601
-		return 'bad_email';
3744
+	if (trim($email) == '') {
3745
+			return 'no_email';
3746
+	}
3747
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3748
+			return 'bad_email';
3749
+	}
3602 3750
 
3603 3751
 	// Email addresses should be and stay unique.
3604 3752
 	$request = $smcFunc['db_query']('', '
@@ -3613,8 +3761,9 @@  discard block
 block discarded – undo
3613 3761
 		)
3614 3762
 	);
3615 3763
 
3616
-	if ($smcFunc['db_num_rows']($request) > 0)
3617
-		return 'email_taken';
3764
+	if ($smcFunc['db_num_rows']($request) > 0) {
3765
+			return 'email_taken';
3766
+	}
3618 3767
 	$smcFunc['db_free_result']($request);
3619 3768
 
3620 3769
 	return true;
@@ -3627,8 +3776,9 @@  discard block
 block discarded – undo
3627 3776
 {
3628 3777
 	global $modSettings, $context, $cur_profile;
3629 3778
 
3630
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3631
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3779
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3780
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	}
3632 3782
 
3633 3783
 	loadUserSettings();
3634 3784
 	writeLog();
@@ -3644,8 +3794,9 @@  discard block
 block discarded – undo
3644 3794
 	require_once($sourcedir . '/Subs-Post.php');
3645 3795
 
3646 3796
 	// Shouldn't happen but just in case.
3647
-	if (empty($profile_vars['email_address']))
3648
-		return;
3797
+	if (empty($profile_vars['email_address'])) {
3798
+			return;
3799
+	}
3649 3800
 
3650 3801
 	$replacements = array(
3651 3802
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3668,8 +3819,9 @@  discard block
 block discarded – undo
3668 3819
 	$_SESSION['log_time'] = 0;
3669 3820
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3670 3821
 
3671
-	if (isset($_COOKIE[$cookiename]))
3672
-		$_COOKIE[$cookiename] = '';
3822
+	if (isset($_COOKIE[$cookiename])) {
3823
+			$_COOKIE[$cookiename] = '';
3824
+	}
3673 3825
 
3674 3826
 	loadUserSettings();
3675 3827
 
@@ -3702,11 +3854,13 @@  discard block
 block discarded – undo
3702 3854
 	$groups[] = $curMember['id_group'];
3703 3855
 
3704 3856
 	// Ensure the query doesn't croak!
3705
-	if (empty($groups))
3706
-		$groups = array(0);
3857
+	if (empty($groups)) {
3858
+			$groups = array(0);
3859
+	}
3707 3860
 	// Just to be sure...
3708
-	foreach ($groups as $k => $v)
3709
-		$groups[$k] = (int) $v;
3861
+	foreach ($groups as $k => $v) {
3862
+			$groups[$k] = (int) $v;
3863
+	}
3710 3864
 
3711 3865
 	// Get all the membergroups they can join.
3712 3866
 	$request = $smcFunc['db_query']('', '
@@ -3736,12 +3890,14 @@  discard block
 block discarded – undo
3736 3890
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3737 3891
 	{
3738 3892
 		// Can they edit their primary group?
3739
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3740
-			$context['can_edit_primary'] = true;
3893
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3894
+					$context['can_edit_primary'] = true;
3895
+		}
3741 3896
 
3742 3897
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3743
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3744
-			continue;
3898
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3899
+					continue;
3900
+		}
3745 3901
 
3746 3902
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3747 3903
 			'id' => $row['id_group'],
@@ -3770,13 +3926,15 @@  discard block
 block discarded – undo
3770 3926
 	);
3771 3927
 
3772 3928
 	// No changing primary one unless you have enough groups!
3773
-	if (count($context['groups']['member']) < 2)
3774
-		$context['can_edit_primary'] = false;
3929
+	if (count($context['groups']['member']) < 2) {
3930
+			$context['can_edit_primary'] = false;
3931
+	}
3775 3932
 
3776 3933
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3777
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3778
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3779
-}
3934
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3935
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3936
+	}
3937
+	}
3780 3938
 
3781 3939
 /**
3782 3940
  * This function actually makes all the group changes
@@ -3791,10 +3949,12 @@  discard block
 block discarded – undo
3791 3949
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3792 3950
 
3793 3951
 	// Let's be extra cautious...
3794
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3795
-		isAllowedTo('manage_membergroups');
3796
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3797
-		fatal_lang_error('no_access', false);
3952
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3953
+			isAllowedTo('manage_membergroups');
3954
+	}
3955
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3956
+			fatal_lang_error('no_access', false);
3957
+	}
3798 3958
 
3799 3959
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3800 3960
 
@@ -3813,8 +3973,9 @@  discard block
 block discarded – undo
3813 3973
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3814 3974
 
3815 3975
 	// Sanity check!!
3816
-	if ($group_id == 1)
3817
-		isAllowedTo('admin_forum');
3976
+	if ($group_id == 1) {
3977
+			isAllowedTo('admin_forum');
3978
+	}
3818 3979
 	// Protected groups too!
3819 3980
 	else
3820 3981
 	{
@@ -3831,8 +3992,9 @@  discard block
 block discarded – undo
3831 3992
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3832 3993
 		$smcFunc['db_free_result']($request);
3833 3994
 
3834
-		if ($is_protected == 1)
3835
-			isAllowedTo('admin_forum');
3995
+		if ($is_protected == 1) {
3996
+					isAllowedTo('admin_forum');
3997
+		}
3836 3998
 	}
3837 3999
 
3838 4000
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3854,36 +4016,43 @@  discard block
 block discarded – undo
3854 4016
 			$group_name = $row['group_name'];
3855 4017
 
3856 4018
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3857
-			if ($changeType == 'request' && $row['group_type'] != 2)
3858
-				fatal_lang_error('no_access', false);
4019
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4020
+							fatal_lang_error('no_access', false);
4021
+			}
3859 4022
 			// What about leaving a requestable group we are not a member of?
3860
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3861
-				fatal_lang_error('no_access', false);
3862
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3863
-				fatal_lang_error('no_access', false);
4023
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4024
+							fatal_lang_error('no_access', false);
4025
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4026
+							fatal_lang_error('no_access', false);
4027
+			}
3864 4028
 
3865 4029
 			// We can't change the primary group if this is hidden!
3866
-			if ($row['hidden'] == 2)
3867
-				$canChangePrimary = false;
4030
+			if ($row['hidden'] == 2) {
4031
+							$canChangePrimary = false;
4032
+			}
3868 4033
 		}
3869 4034
 
3870 4035
 		// If this is their old primary, can we change it?
3871
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3872
-			$canChangePrimary = 1;
4036
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4037
+					$canChangePrimary = 1;
4038
+		}
3873 4039
 
3874 4040
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3875
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3876
-			$canChangePrimary = false;
4041
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4042
+					$canChangePrimary = false;
4043
+		}
3877 4044
 
3878 4045
 		// If this is the one we are acting on, can we even act?
3879
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3880
-			$canChangePrimary = false;
4046
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4047
+					$canChangePrimary = false;
4048
+		}
3881 4049
 	}
3882 4050
 	$smcFunc['db_free_result']($request);
3883 4051
 
3884 4052
 	// Didn't find the target?
3885
-	if (!$foundTarget)
3886
-		fatal_lang_error('no_access', false);
4053
+	if (!$foundTarget) {
4054
+			fatal_lang_error('no_access', false);
4055
+	}
3887 4056
 
3888 4057
 	// Final security check, don't allow users to promote themselves to admin.
3889 4058
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3903,8 +4072,9 @@  discard block
 block discarded – undo
3903 4072
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3904 4073
 		$smcFunc['db_free_result']($request);
3905 4074
 
3906
-		if ($disallow)
3907
-			isAllowedTo('admin_forum');
4075
+		if ($disallow) {
4076
+					isAllowedTo('admin_forum');
4077
+		}
3908 4078
 	}
3909 4079
 
3910 4080
 	// If we're requesting, add the note then return.
@@ -3922,8 +4092,9 @@  discard block
 block discarded – undo
3922 4092
 				'status_open' => 0,
3923 4093
 			)
3924 4094
 		);
3925
-		if ($smcFunc['db_num_rows']($request) != 0)
3926
-			fatal_lang_error('profile_error_already_requested_group');
4095
+		if ($smcFunc['db_num_rows']($request) != 0) {
4096
+					fatal_lang_error('profile_error_already_requested_group');
4097
+		}
3927 4098
 		$smcFunc['db_free_result']($request);
3928 4099
 
3929 4100
 		// Log the request.
@@ -3957,10 +4128,11 @@  discard block
 block discarded – undo
3957 4128
 		// Are we leaving?
3958 4129
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3959 4130
 		{
3960
-			if ($old_profile['id_group'] == $group_id)
3961
-				$newPrimary = 0;
3962
-			else
3963
-				unset($addGroups[$group_id]);
4131
+			if ($old_profile['id_group'] == $group_id) {
4132
+							$newPrimary = 0;
4133
+			} else {
4134
+							unset($addGroups[$group_id]);
4135
+			}
3964 4136
 		}
3965 4137
 		// ... if not, must be joining.
3966 4138
 		else
@@ -3968,36 +4140,42 @@  discard block
 block discarded – undo
3968 4140
 			// Can we change the primary, and do we want to?
3969 4141
 			if ($canChangePrimary)
3970 4142
 			{
3971
-				if ($old_profile['id_group'] != 0)
3972
-					$addGroups[$old_profile['id_group']] = -1;
4143
+				if ($old_profile['id_group'] != 0) {
4144
+									$addGroups[$old_profile['id_group']] = -1;
4145
+				}
3973 4146
 				$newPrimary = $group_id;
3974 4147
 			}
3975 4148
 			// Otherwise it's an additional group...
3976
-			else
3977
-				$addGroups[$group_id] = -1;
4149
+			else {
4150
+							$addGroups[$group_id] = -1;
4151
+			}
3978 4152
 		}
3979 4153
 	}
3980 4154
 	// Finally, we must be setting the primary.
3981 4155
 	elseif ($canChangePrimary)
3982 4156
 	{
3983
-		if ($old_profile['id_group'] != 0)
3984
-			$addGroups[$old_profile['id_group']] = -1;
3985
-		if (isset($addGroups[$group_id]))
3986
-			unset($addGroups[$group_id]);
4157
+		if ($old_profile['id_group'] != 0) {
4158
+					$addGroups[$old_profile['id_group']] = -1;
4159
+		}
4160
+		if (isset($addGroups[$group_id])) {
4161
+					unset($addGroups[$group_id]);
4162
+		}
3987 4163
 		$newPrimary = $group_id;
3988 4164
 	}
3989 4165
 
3990 4166
 	// Finally, we can make the changes!
3991
-	foreach ($addGroups as $id => $dummy)
3992
-		if (empty($id))
4167
+	foreach ($addGroups as $id => $dummy) {
4168
+			if (empty($id))
3993 4169
 			unset($addGroups[$id]);
4170
+	}
3994 4171
 	$addGroups = implode(',', array_flip($addGroups));
3995 4172
 
3996 4173
 	// Ensure that we don't cache permissions if the group is changing.
3997
-	if ($context['user']['is_owner'])
3998
-		$_SESSION['mc']['time'] = 0;
3999
-	else
4000
-		updateSettings(array('settings_updated' => time()));
4174
+	if ($context['user']['is_owner']) {
4175
+			$_SESSION['mc']['time'] = 0;
4176
+	} else {
4177
+			updateSettings(array('settings_updated' => time()));
4178
+	}
4001 4179
 
4002 4180
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4003 4181
 
@@ -4020,8 +4198,9 @@  discard block
 block discarded – undo
4020 4198
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4021 4199
 	{
4022 4200
 		// Check to ensure we're forcing SSL for authentication
4023
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4024
-			fatal_lang_error('login_ssl_required');
4201
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4202
+					fatal_lang_error('login_ssl_required');
4203
+		}
4025 4204
 
4026 4205
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4027 4206
 		// we do not want too much AJAX to confuse them.
@@ -4058,8 +4237,7 @@  discard block
 block discarded – undo
4058 4237
 				$context['sub_template'] = 'tfasetup_backup';
4059 4238
 
4060 4239
 				return;
4061
-			}
4062
-			else
4240
+			} else
4063 4241
 			{
4064 4242
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4065 4243
 				$context['tfa_error'] = !$valid_code;
@@ -4067,8 +4245,7 @@  discard block
 block discarded – undo
4067 4245
 				$context['tfa_pass_value'] = $_POST['passwd'];
4068 4246
 				$context['tfa_value'] = $_POST['tfa_code'];
4069 4247
 			}
4070
-		}
4071
-		else
4248
+		} else
4072 4249
 		{
4073 4250
 			$totp = new \TOTP\Auth();
4074 4251
 			$secret = $totp->generateCode();
@@ -4078,17 +4255,16 @@  discard block
 block discarded – undo
4078 4255
 		}
4079 4256
 
4080 4257
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4081
-	}
4082
-	elseif (isset($_REQUEST['disable']))
4258
+	} elseif (isset($_REQUEST['disable']))
4083 4259
 	{
4084 4260
 		updateMemberData($memID, array(
4085 4261
 			'tfa_secret' => '',
4086 4262
 			'tfa_backup' => '',
4087 4263
 		));
4088 4264
 		redirectexit('action=profile;area=account;u=' . $memID);
4265
+	} else {
4266
+			redirectexit('action=profile;area=account;u=' . $memID);
4267
+	}
4089 4268
 	}
4090
-	else
4091
-		redirectexit('action=profile;area=account;u=' . $memID);
4092
-}
4093 4269
 
4094 4270
 ?>
4095 4271
\ No newline at end of file
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +881 added lines, -647 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,9 +290,9 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			//Clear out warnings at the start of each step
@@ -323,17 +338,18 @@  discard block
 block discarded – undo
323 338
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 339
 		if (!empty($command_line))
325 340
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
341
+			if (function_exists('debug_print_backtrace')) {
342
+							debug_print_backtrace();
343
+			}
328 344
 
329 345
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
330 346
 			flush();
331 347
 			die();
332 348
 		}
333 349
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
350
+		if (!isset($_GET['xml'])) {
351
+					template_upgrade_above();
352
+		} else
337 353
 		{
338 354
 			header('Content-Type: text/xml; charset=UTF-8');
339 355
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,25 +371,29 @@  discard block
 block discarded – undo
355 371
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 372
 
357 373
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
374
+			if (!empty($upcontext['query_string'])) {
375
+							$upcontext['form_url'] .= $upcontext['query_string'];
376
+			}
360 377
 
361 378
 			// Call the appropriate subtemplate
362
-			if (is_callable('template_' . $upcontext['sub_template']))
363
-				call_user_func('template_' . $upcontext['sub_template']);
364
-			else
365
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
379
+			if (is_callable('template_' . $upcontext['sub_template'])) {
380
+							call_user_func('template_' . $upcontext['sub_template']);
381
+			} else {
382
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
383
+			}
366 384
 		}
367 385
 
368 386
 		// Was there an error?
369
-		if (!empty($upcontext['forced_error_message']))
370
-			echo $upcontext['forced_error_message'];
387
+		if (!empty($upcontext['forced_error_message'])) {
388
+					echo $upcontext['forced_error_message'];
389
+		}
371 390
 
372 391
 		// Show the footer.
373
-		if (!isset($_GET['xml']))
374
-			template_upgrade_below();
375
-		else
376
-			template_xml_below();
392
+		if (!isset($_GET['xml'])) {
393
+					template_upgrade_below();
394
+		} else {
395
+					template_xml_below();
396
+		}
377 397
 	}
378 398
 
379 399
 
@@ -385,15 +405,19 @@  discard block
 block discarded – undo
385 405
 		$seconds = intval($active % 60);
386 406
 
387 407
 		$totalTime = '';
388
-		if ($hours > 0)
389
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
390
-		if ($minutes > 0)
391
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
392
-		if ($seconds > 0)
393
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
408
+		if ($hours > 0) {
409
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
410
+		}
411
+		if ($minutes > 0) {
412
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
413
+		}
414
+		if ($seconds > 0) {
415
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
416
+		}
394 417
 
395
-		if (!empty($totalTime))
396
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		if (!empty($totalTime)) {
419
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
420
+		}
397 421
 	}
398 422
 
399 423
 	// Bang - gone!
@@ -406,8 +430,9 @@  discard block
 block discarded – undo
406 430
 	global $upgradeurl, $upcontext, $command_line;
407 431
 
408 432
 	// Command line users can't be redirected.
409
-	if ($command_line)
410
-		upgradeExit(true);
433
+	if ($command_line) {
434
+			upgradeExit(true);
435
+	}
411 436
 
412 437
 	// Are we providing the core info?
413 438
 	if ($addForm)
@@ -433,12 +458,14 @@  discard block
 block discarded – undo
433 458
 	define('SMF', 1);
434 459
 
435 460
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
461
+	if (@ini_get('session.save_handler') == 'user') {
462
+			@ini_set('session.save_handler', 'files');
463
+	}
438 464
 	@session_start();
439 465
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
466
+	if (empty($smcFunc)) {
467
+			$smcFunc = array();
468
+	}
442 469
 
443 470
 	// We need this for authentication and some upgrade code
444 471
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -450,32 +477,36 @@  discard block
 block discarded – undo
450 477
 	initialize_inputs();
451 478
 
452 479
 	// Get the database going!
453
-	if (empty($db_type) || $db_type == 'mysqli')
454
-		$db_type = 'mysql';
480
+	if (empty($db_type) || $db_type == 'mysqli') {
481
+			$db_type = 'mysql';
482
+	}
455 483
 
456 484
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
457 485
 	{
458 486
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
459 487
 
460 488
 		// Make the connection...
461
-		if (empty($db_connection))
462
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
463
-		else
464
-			// If we've returned here, ping/reconnect to be safe
489
+		if (empty($db_connection)) {
490
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
491
+		} else {
492
+					// If we've returned here, ping/reconnect to be safe
465 493
 			$smcFunc['db_ping']($db_connection);
494
+		}
466 495
 
467 496
 		// Oh dear god!!
468
-		if ($db_connection === null)
469
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
497
+		if ($db_connection === null) {
498
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
499
+		}
470 500
 
471
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
472
-			$smcFunc['db_query']('', '
501
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
502
+					$smcFunc['db_query']('', '
473 503
 			SET NAMES {string:db_character_set}',
474 504
 			array(
475 505
 				'db_error_skip' => true,
476 506
 				'db_character_set' => $db_character_set,
477 507
 			)
478 508
 		);
509
+		}
479 510
 
480 511
 		// Load the modSettings data...
481 512
 		$request = $smcFunc['db_query']('', '
@@ -486,11 +517,11 @@  discard block
 block discarded – undo
486 517
 			)
487 518
 		);
488 519
 		$modSettings = array();
489
-		while ($row = $smcFunc['db_fetch_assoc']($request))
490
-			$modSettings[$row['variable']] = $row['value'];
520
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
521
+					$modSettings[$row['variable']] = $row['value'];
522
+		}
491 523
 		$smcFunc['db_free_result']($request);
492
-	}
493
-	else
524
+	} else
494 525
 	{
495 526
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
496 527
 	}
@@ -504,9 +535,10 @@  discard block
 block discarded – undo
504 535
 		cleanRequest();
505 536
 	}
506 537
 
507
-	if (!isset($_GET['substep']))
508
-		$_GET['substep'] = 0;
509
-}
538
+	if (!isset($_GET['substep'])) {
539
+			$_GET['substep'] = 0;
540
+	}
541
+	}
510 542
 
511 543
 function initialize_inputs()
512 544
 {
@@ -536,8 +568,9 @@  discard block
 block discarded – undo
536 568
 		$dh = opendir(dirname(__FILE__));
537 569
 		while ($file = readdir($dh))
538 570
 		{
539
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
540
-				@unlink(dirname(__FILE__) . '/' . $file);
571
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
572
+							@unlink(dirname(__FILE__) . '/' . $file);
573
+			}
541 574
 		}
542 575
 		closedir($dh);
543 576
 
@@ -566,8 +599,9 @@  discard block
 block discarded – undo
566 599
 	$temp = 'upgrade_php?step';
567 600
 	while (strlen($temp) > 4)
568 601
 	{
569
-		if (isset($_GET[$temp]))
570
-			unset($_GET[$temp]);
602
+		if (isset($_GET[$temp])) {
603
+					unset($_GET[$temp]);
604
+		}
571 605
 		$temp = substr($temp, 1);
572 606
 	}
573 607
 
@@ -594,32 +628,39 @@  discard block
 block discarded – undo
594 628
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
595 629
 
596 630
 	// Need legacy scripts?
597
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
598
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
599
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
600
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
601
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
602
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
631
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
632
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
633
+	}
634
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
635
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
636
+	}
637
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
638
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
639
+	}
603 640
 
604 641
 	// We don't need "-utf8" files anymore...
605 642
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
606 643
 
607 644
 	// This needs to exist!
608
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
609
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
610
-	else
611
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
645
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
646
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
647
+	} else {
648
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
649
+	}
612 650
 
613
-	if (!$check)
614
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
651
+	if (!$check) {
652
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
615 653
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
654
+	}
616 655
 
617 656
 	// Do they meet the install requirements?
618
-	if (!php_version_check())
619
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
657
+	if (!php_version_check()) {
658
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
659
+	}
620 660
 
621
-	if (!db_version_check())
622
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
661
+	if (!db_version_check()) {
662
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
663
+	}
623 664
 
624 665
 	// Do some checks to make sure they have proper privileges
625 666
 	db_extend('packages');
@@ -634,14 +675,16 @@  discard block
 block discarded – undo
634 675
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
635 676
 
636 677
 	// Sorry... we need CREATE, ALTER and DROP
637
-	if (!$create || !$alter || !$drop)
638
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
678
+	if (!$create || !$alter || !$drop) {
679
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
680
+	}
639 681
 
640 682
 	// Do a quick version spot check.
641 683
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
642 684
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
643
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
644
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
685
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
686
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
687
+	}
645 688
 
646 689
 	// What absolutely needs to be writable?
647 690
 	$writable_files = array(
@@ -663,12 +706,13 @@  discard block
 block discarded – undo
663 706
 	quickFileWritable($custom_av_dir);
664 707
 
665 708
 	// Are we good now?
666
-	if (!is_writable($custom_av_dir))
667
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
668
-	elseif ($need_settings_update)
709
+	if (!is_writable($custom_av_dir)) {
710
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
711
+	} elseif ($need_settings_update)
669 712
 	{
670
-		if (!function_exists('cache_put_data'))
671
-			require_once($sourcedir . '/Load.php');
713
+		if (!function_exists('cache_put_data')) {
714
+					require_once($sourcedir . '/Load.php');
715
+		}
672 716
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
673 717
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
674 718
 	}
@@ -677,28 +721,33 @@  discard block
 block discarded – undo
677 721
 
678 722
 	// Check the cache directory.
679 723
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
680
-	if (!file_exists($cachedir_temp))
681
-		@mkdir($cachedir_temp);
682
-	if (!file_exists($cachedir_temp))
683
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
684
-
685
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
686
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
687
-	elseif (!isset($_GET['skiplang']))
724
+	if (!file_exists($cachedir_temp)) {
725
+			@mkdir($cachedir_temp);
726
+	}
727
+	if (!file_exists($cachedir_temp)) {
728
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
729
+	}
730
+
731
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
732
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
733
+	} elseif (!isset($_GET['skiplang']))
688 734
 	{
689 735
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
690 736
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
691 737
 
692
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
693
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
738
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
739
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
740
+		}
694 741
 	}
695 742
 
696
-	if (!makeFilesWritable($writable_files))
697
-		return false;
743
+	if (!makeFilesWritable($writable_files)) {
744
+			return false;
745
+	}
698 746
 
699 747
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
700
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
701
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
748
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
749
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
750
+	}
702 751
 
703 752
 	// Upgrade the agreement.
704 753
 	elseif (isset($modSettings['agreement']))
@@ -709,8 +758,8 @@  discard block
 block discarded – undo
709 758
 	}
710 759
 
711 760
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
712
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
713
-		$upcontext['warning'] = '
761
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
762
+			$upcontext['warning'] = '
714 763
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
715 764
 			<ul>
716 765
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -718,19 +767,23 @@  discard block
 block discarded – undo
718 767
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
719 768
 			</ul>
720 769
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
770
+	}
721 771
 
722 772
 	// Confirm mbstring is loaded...
723
-	if (!extension_loaded('mbstring'))
724
-		return throw_error($txt['install_no_mbstring']);
773
+	if (!extension_loaded('mbstring')) {
774
+			return throw_error($txt['install_no_mbstring']);
775
+	}
725 776
 
726 777
 	// Check for https stream support.
727 778
 	$supported_streams = stream_get_wrappers();
728
-	if (!in_array('https', $supported_streams))
729
-		$upcontext['custom_warning'] = $txt['install_no_https'];
779
+	if (!in_array('https', $supported_streams)) {
780
+			$upcontext['custom_warning'] = $txt['install_no_https'];
781
+	}
730 782
 
731 783
 	// Either we're logged in or we're going to present the login.
732
-	if (checkLogin())
733
-		return true;
784
+	if (checkLogin()) {
785
+			return true;
786
+	}
734 787
 
735 788
 	$upcontext += createToken('login');
736 789
 
@@ -744,15 +797,17 @@  discard block
 block discarded – undo
744 797
 	global $smcFunc, $db_type, $support_js;
745 798
 
746 799
 	// Don't bother if the security is disabled.
747
-	if ($disable_security)
748
-		return true;
800
+	if ($disable_security) {
801
+			return true;
802
+	}
749 803
 
750 804
 	// Are we trying to login?
751 805
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
752 806
 	{
753 807
 		// If we've disabled security pick a suitable name!
754
-		if (empty($_POST['user']))
755
-			$_POST['user'] = 'Administrator';
808
+		if (empty($_POST['user'])) {
809
+					$_POST['user'] = 'Administrator';
810
+		}
756 811
 
757 812
 		// Before 2.0 these column names were different!
758 813
 		$oldDB = false;
@@ -767,16 +822,17 @@  discard block
 block discarded – undo
767 822
 					'db_error_skip' => true,
768 823
 				)
769 824
 			);
770
-			if ($smcFunc['db_num_rows']($request) != 0)
771
-				$oldDB = true;
825
+			if ($smcFunc['db_num_rows']($request) != 0) {
826
+							$oldDB = true;
827
+			}
772 828
 			$smcFunc['db_free_result']($request);
773 829
 		}
774 830
 
775 831
 		// Get what we believe to be their details.
776 832
 		if (!$disable_security)
777 833
 		{
778
-			if ($oldDB)
779
-				$request = $smcFunc['db_query']('', '
834
+			if ($oldDB) {
835
+							$request = $smcFunc['db_query']('', '
780 836
 					SELECT id_member, memberName AS member_name, passwd, id_group,
781 837
 					additionalGroups AS additional_groups, lngfile
782 838
 					FROM {db_prefix}members
@@ -786,8 +842,8 @@  discard block
 block discarded – undo
786 842
 						'db_error_skip' => true,
787 843
 					)
788 844
 				);
789
-			else
790
-				$request = $smcFunc['db_query']('', '
845
+			} else {
846
+							$request = $smcFunc['db_query']('', '
791 847
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
792 848
 					FROM {db_prefix}members
793 849
 					WHERE member_name = {string:member_name}',
@@ -796,6 +852,7 @@  discard block
 block discarded – undo
796 852
 						'db_error_skip' => true,
797 853
 					)
798 854
 				);
855
+			}
799 856
 			if ($smcFunc['db_num_rows']($request) != 0)
800 857
 			{
801 858
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -803,16 +860,17 @@  discard block
 block discarded – undo
803 860
 				$groups = explode(',', $addGroups);
804 861
 				$groups[] = $id_group;
805 862
 
806
-				foreach ($groups as $k => $v)
807
-					$groups[$k] = (int) $v;
863
+				foreach ($groups as $k => $v) {
864
+									$groups[$k] = (int) $v;
865
+				}
808 866
 
809 867
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
810 868
 
811 869
 				// We don't use "-utf8" anymore...
812 870
 				$user_language = str_ireplace('-utf8', '', $user_language);
871
+			} else {
872
+							$upcontext['username_incorrect'] = true;
813 873
 			}
814
-			else
815
-				$upcontext['username_incorrect'] = true;
816 874
 			$smcFunc['db_free_result']($request);
817 875
 		}
818 876
 		$upcontext['username'] = $_POST['user'];
@@ -822,13 +880,14 @@  discard block
 block discarded – undo
822 880
 		{
823 881
 			$upcontext['upgrade_status']['js'] = 1;
824 882
 			$support_js = 1;
883
+		} else {
884
+					$support_js = 0;
825 885
 		}
826
-		else
827
-			$support_js = 0;
828 886
 
829 887
 		// Note down the version we are coming from.
830
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
831
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
888
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
889
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
890
+		}
832 891
 
833 892
 		// Didn't get anywhere?
834 893
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -862,15 +921,15 @@  discard block
 block discarded – undo
862 921
 							'db_error_skip' => true,
863 922
 						)
864 923
 					);
865
-					if ($smcFunc['db_num_rows']($request) == 0)
866
-						return throw_error('You need to be an admin to perform an upgrade!');
924
+					if ($smcFunc['db_num_rows']($request) == 0) {
925
+											return throw_error('You need to be an admin to perform an upgrade!');
926
+					}
867 927
 					$smcFunc['db_free_result']($request);
868 928
 				}
869 929
 
870 930
 				$upcontext['user']['id'] = $id_member;
871 931
 				$upcontext['user']['name'] = $name;
872
-			}
873
-			else
932
+			} else
874 933
 			{
875 934
 				$upcontext['user']['id'] = 1;
876 935
 				$upcontext['user']['name'] = 'Administrator';
@@ -886,11 +945,11 @@  discard block
 block discarded – undo
886 945
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
887 946
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
888 947
 
889
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
890
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
891
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
892
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
893
-				else
948
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
949
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
950
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
951
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
952
+				} else
894 953
 				{
895 954
 					// Set this as the new language.
896 955
 					$upcontext['language'] = $user_language;
@@ -934,8 +993,9 @@  discard block
 block discarded – undo
934 993
 	unset($member_columns);
935 994
 
936 995
 	// If we've not submitted then we're done.
937
-	if (empty($_POST['upcont']))
938
-		return false;
996
+	if (empty($_POST['upcont'])) {
997
+			return false;
998
+	}
939 999
 
940 1000
 	// Firstly, if they're enabling SM stat collection just do it.
941 1001
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -955,16 +1015,17 @@  discard block
 block discarded – undo
955 1015
 				fwrite($fp, $out);
956 1016
 
957 1017
 				$return_data = '';
958
-				while (!feof($fp))
959
-					$return_data .= fgets($fp, 128);
1018
+				while (!feof($fp)) {
1019
+									$return_data .= fgets($fp, 128);
1020
+				}
960 1021
 
961 1022
 				fclose($fp);
962 1023
 
963 1024
 				// Get the unique site ID.
964 1025
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
965 1026
 
966
-				if (!empty($ID[1]))
967
-					$smcFunc['db_insert']('replace',
1027
+				if (!empty($ID[1])) {
1028
+									$smcFunc['db_insert']('replace',
968 1029
 						$db_prefix . 'settings',
969 1030
 						array('variable' => 'string', 'value' => 'string'),
970 1031
 						array(
@@ -973,9 +1034,9 @@  discard block
 block discarded – undo
973 1034
 						),
974 1035
 						array('variable')
975 1036
 					);
1037
+				}
976 1038
 			}
977
-		}
978
-		else
1039
+		} else
979 1040
 		{
980 1041
 			$smcFunc['db_insert']('replace',
981 1042
 				$db_prefix . 'settings',
@@ -986,8 +1047,8 @@  discard block
 block discarded – undo
986 1047
 		}
987 1048
 	}
988 1049
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
989
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
990
-		$smcFunc['db_query']('', '
1050
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1051
+			$smcFunc['db_query']('', '
991 1052
 			DELETE FROM {db_prefix}settings
992 1053
 			WHERE variable = {string:enable_sm_stats}',
993 1054
 			array(
@@ -995,6 +1056,7 @@  discard block
 block discarded – undo
995 1056
 				'db_error_skip' => true,
996 1057
 			)
997 1058
 		);
1059
+	}
998 1060
 
999 1061
 	// Deleting old karma stuff?
1000 1062
 	if (!empty($_POST['delete_karma']))
@@ -1009,20 +1071,22 @@  discard block
 block discarded – undo
1009 1071
 		);
1010 1072
 
1011 1073
 		// Cleaning up old karma member settings.
1012
-		if ($upcontext['karma_installed']['good'])
1013
-			$smcFunc['db_query']('', '
1074
+		if ($upcontext['karma_installed']['good']) {
1075
+					$smcFunc['db_query']('', '
1014 1076
 				ALTER TABLE {db_prefix}members
1015 1077
 				DROP karma_good',
1016 1078
 				array()
1017 1079
 			);
1080
+		}
1018 1081
 
1019 1082
 		// Does karma bad was enable?
1020
-		if ($upcontext['karma_installed']['bad'])
1021
-			$smcFunc['db_query']('', '
1083
+		if ($upcontext['karma_installed']['bad']) {
1084
+					$smcFunc['db_query']('', '
1022 1085
 				ALTER TABLE {db_prefix}members
1023 1086
 				DROP karma_bad',
1024 1087
 				array()
1025 1088
 			);
1089
+		}
1026 1090
 
1027 1091
 		// Cleaning up old karma permissions.
1028 1092
 		$smcFunc['db_query']('', '
@@ -1035,26 +1099,29 @@  discard block
 block discarded – undo
1035 1099
 	}
1036 1100
 
1037 1101
 	// Emptying the error log?
1038
-	if (!empty($_POST['empty_error']))
1039
-		$smcFunc['db_query']('truncate_table', '
1102
+	if (!empty($_POST['empty_error'])) {
1103
+			$smcFunc['db_query']('truncate_table', '
1040 1104
 			TRUNCATE {db_prefix}log_errors',
1041 1105
 			array(
1042 1106
 			)
1043 1107
 		);
1108
+	}
1044 1109
 
1045 1110
 	$changes = array();
1046 1111
 
1047 1112
 	// Add proxy settings.
1048
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1049
-		$changes += array(
1113
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1114
+			$changes += array(
1050 1115
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1051 1116
 			'image_proxy_maxsize' => 5190,
1052 1117
 			'image_proxy_enabled' => 0,
1053 1118
 		);
1119
+	}
1054 1120
 
1055 1121
 	// If we're overriding the language follow it through.
1056
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1057
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1122
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1123
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1124
+	}
1058 1125
 
1059 1126
 	if (!empty($_POST['maint']))
1060 1127
 	{
@@ -1066,30 +1133,34 @@  discard block
 block discarded – undo
1066 1133
 		{
1067 1134
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1068 1135
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1069
-		}
1070
-		else
1136
+		} else
1071 1137
 		{
1072 1138
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1073 1139
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1074 1140
 		}
1075 1141
 	}
1076 1142
 
1077
-	if ($command_line)
1078
-		echo ' * Updating Settings.php...';
1143
+	if ($command_line) {
1144
+			echo ' * Updating Settings.php...';
1145
+	}
1079 1146
 
1080 1147
 	// Fix some old paths.
1081
-	if (substr($boarddir, 0, 1) == '.')
1082
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1148
+	if (substr($boarddir, 0, 1) == '.') {
1149
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1150
+	}
1083 1151
 
1084
-	if (substr($sourcedir, 0, 1) == '.')
1085
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1152
+	if (substr($sourcedir, 0, 1) == '.') {
1153
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1154
+	}
1086 1155
 
1087
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1088
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1156
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1157
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1158
+	}
1089 1159
 
1090 1160
 	// Not had the database type added before?
1091
-	if (empty($db_type))
1092
-		$changes['db_type'] = 'mysql';
1161
+	if (empty($db_type)) {
1162
+			$changes['db_type'] = 'mysql';
1163
+	}
1093 1164
 
1094 1165
 	// If they have a "host:port" setup for the host, split that into separate values
1095 1166
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1100,32 +1171,36 @@  discard block
 block discarded – undo
1100 1171
 		$changes['db_server'] = '\'' . $db_server . '\'';
1101 1172
 
1102 1173
 		// Only set this if we're not using the default port
1103
-		if ($db_port != ini_get('mysqli.default_port'))
1104
-			$changes['db_port'] = (int) $db_port;
1105
-	}
1106
-	elseif (!empty($db_port))
1174
+		if ($db_port != ini_get('mysqli.default_port')) {
1175
+					$changes['db_port'] = (int) $db_port;
1176
+		}
1177
+	} elseif (!empty($db_port))
1107 1178
 	{
1108 1179
 		// If db_port is set and is the same as the default, set it to ''
1109 1180
 		if ($db_type == 'mysql')
1110 1181
 		{
1111
-			if ($db_port == ini_get('mysqli.default_port'))
1112
-				$changes['db_port'] = '\'\'';
1113
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1114
-				$changes['db_port'] = '\'\'';
1182
+			if ($db_port == ini_get('mysqli.default_port')) {
1183
+							$changes['db_port'] = '\'\'';
1184
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1185
+							$changes['db_port'] = '\'\'';
1186
+			}
1115 1187
 		}
1116 1188
 	}
1117 1189
 
1118 1190
 	// Maybe we haven't had this option yet?
1119
-	if (empty($packagesdir))
1120
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1191
+	if (empty($packagesdir)) {
1192
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1193
+	}
1121 1194
 
1122 1195
 	// Add support for $tasksdir var.
1123
-	if (empty($tasksdir))
1124
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1196
+	if (empty($tasksdir)) {
1197
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1198
+	}
1125 1199
 
1126 1200
 	// Make sure we fix the language as well.
1127
-	if (stristr($language, '-utf8'))
1128
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1201
+	if (stristr($language, '-utf8')) {
1202
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1203
+	}
1129 1204
 
1130 1205
 	// @todo Maybe change the cookie name if going to 1.1, too?
1131 1206
 
@@ -1133,8 +1208,9 @@  discard block
 block discarded – undo
1133 1208
 	require_once($sourcedir . '/Subs-Admin.php');
1134 1209
 	updateSettingsFile($changes);
1135 1210
 
1136
-	if ($command_line)
1137
-		echo ' Successful.' . "\n";
1211
+	if ($command_line) {
1212
+			echo ' Successful.' . "\n";
1213
+	}
1138 1214
 
1139 1215
 	// Are we doing debug?
1140 1216
 	if (isset($_POST['debug']))
@@ -1144,8 +1220,9 @@  discard block
 block discarded – undo
1144 1220
 	}
1145 1221
 
1146 1222
 	// If we're not backing up then jump one.
1147
-	if (empty($_POST['backup']))
1148
-		$upcontext['current_step']++;
1223
+	if (empty($_POST['backup'])) {
1224
+			$upcontext['current_step']++;
1225
+	}
1149 1226
 
1150 1227
 	// If we've got here then let's proceed to the next step!
1151 1228
 	return true;
@@ -1160,8 +1237,9 @@  discard block
 block discarded – undo
1160 1237
 	$upcontext['page_title'] = 'Backup Database';
1161 1238
 
1162 1239
 	// Done it already - js wise?
1163
-	if (!empty($_POST['backup_done']))
1164
-		return true;
1240
+	if (!empty($_POST['backup_done'])) {
1241
+			return true;
1242
+	}
1165 1243
 
1166 1244
 	// Some useful stuff here.
1167 1245
 	db_extend();
@@ -1175,9 +1253,10 @@  discard block
 block discarded – undo
1175 1253
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1176 1254
 
1177 1255
 	$table_names = array();
1178
-	foreach ($tables as $table)
1179
-		if (substr($table, 0, 7) !== 'backup_')
1256
+	foreach ($tables as $table) {
1257
+			if (substr($table, 0, 7) !== 'backup_')
1180 1258
 			$table_names[] = $table;
1259
+	}
1181 1260
 
1182 1261
 	$upcontext['table_count'] = count($table_names);
1183 1262
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1187,12 +1266,14 @@  discard block
 block discarded – undo
1187 1266
 	$file_steps = $upcontext['table_count'];
1188 1267
 
1189 1268
 	// What ones have we already done?
1190
-	foreach ($table_names as $id => $table)
1191
-		if ($id < $_GET['substep'])
1269
+	foreach ($table_names as $id => $table) {
1270
+			if ($id < $_GET['substep'])
1192 1271
 			$upcontext['previous_tables'][] = $table;
1272
+	}
1193 1273
 
1194
-	if ($command_line)
1195
-		echo 'Backing Up Tables.';
1274
+	if ($command_line) {
1275
+			echo 'Backing Up Tables.';
1276
+	}
1196 1277
 
1197 1278
 	// If we don't support javascript we backup here.
1198 1279
 	if (!$support_js || isset($_GET['xml']))
@@ -1211,8 +1292,9 @@  discard block
 block discarded – undo
1211 1292
 			backupTable($table_names[$substep]);
1212 1293
 
1213 1294
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1214
-			if (isset($_GET['xml']))
1215
-				return upgradeExit();
1295
+			if (isset($_GET['xml'])) {
1296
+							return upgradeExit();
1297
+			}
1216 1298
 		}
1217 1299
 
1218 1300
 		if ($command_line)
@@ -1245,9 +1327,10 @@  discard block
 block discarded – undo
1245 1327
 
1246 1328
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1247 1329
 
1248
-	if ($command_line)
1249
-		echo ' done.';
1250
-}
1330
+	if ($command_line) {
1331
+			echo ' done.';
1332
+	}
1333
+	}
1251 1334
 
1252 1335
 // Step 2: Everything.
1253 1336
 function DatabaseChanges()
@@ -1256,8 +1339,9 @@  discard block
 block discarded – undo
1256 1339
 	global $upcontext, $support_js, $db_type;
1257 1340
 
1258 1341
 	// Have we just completed this?
1259
-	if (!empty($_POST['database_done']))
1260
-		return true;
1342
+	if (!empty($_POST['database_done'])) {
1343
+			return true;
1344
+	}
1261 1345
 
1262 1346
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1263 1347
 	$upcontext['page_title'] = 'Database Changes';
@@ -1272,15 +1356,16 @@  discard block
 block discarded – undo
1272 1356
 	);
1273 1357
 
1274 1358
 	// How many files are there in total?
1275
-	if (isset($_GET['filecount']))
1276
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1277
-	else
1359
+	if (isset($_GET['filecount'])) {
1360
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1361
+	} else
1278 1362
 	{
1279 1363
 		$upcontext['file_count'] = 0;
1280 1364
 		foreach ($files as $file)
1281 1365
 		{
1282
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1283
-				$upcontext['file_count']++;
1366
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1367
+							$upcontext['file_count']++;
1368
+			}
1284 1369
 		}
1285 1370
 	}
1286 1371
 
@@ -1290,9 +1375,9 @@  discard block
 block discarded – undo
1290 1375
 	$upcontext['cur_file_num'] = 0;
1291 1376
 	foreach ($files as $file)
1292 1377
 	{
1293
-		if ($did_not_do)
1294
-			$did_not_do--;
1295
-		else
1378
+		if ($did_not_do) {
1379
+					$did_not_do--;
1380
+		} else
1296 1381
 		{
1297 1382
 			$upcontext['cur_file_num']++;
1298 1383
 			$upcontext['cur_file_name'] = $file[0];
@@ -1319,12 +1404,13 @@  discard block
 block discarded – undo
1319 1404
 					// Flag to move on to the next.
1320 1405
 					$upcontext['completed_step'] = true;
1321 1406
 					// Did we complete the whole file?
1322
-					if ($nextFile)
1323
-						$upcontext['current_debug_item_num'] = -1;
1407
+					if ($nextFile) {
1408
+											$upcontext['current_debug_item_num'] = -1;
1409
+					}
1324 1410
 					return upgradeExit();
1411
+				} elseif ($support_js) {
1412
+									break;
1325 1413
 				}
1326
-				elseif ($support_js)
1327
-					break;
1328 1414
 			}
1329 1415
 			// Set the progress bar to be right as if we had - even if we hadn't...
1330 1416
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1349,8 +1435,9 @@  discard block
 block discarded – undo
1349 1435
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1350 1436
 
1351 1437
 	// Now it's nice to have some of the basic SMF source files.
1352
-	if (!isset($_GET['ssi']) && !$command_line)
1353
-		redirectLocation('&ssi=1');
1438
+	if (!isset($_GET['ssi']) && !$command_line) {
1439
+			redirectLocation('&ssi=1');
1440
+	}
1354 1441
 
1355 1442
 	$upcontext['sub_template'] = 'upgrade_complete';
1356 1443
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1366,14 +1453,16 @@  discard block
 block discarded – undo
1366 1453
 	// Are we in maintenance mode?
1367 1454
 	if (isset($upcontext['user']['main']))
1368 1455
 	{
1369
-		if ($command_line)
1370
-			echo ' * ';
1456
+		if ($command_line) {
1457
+					echo ' * ';
1458
+		}
1371 1459
 		$upcontext['removed_maintenance'] = true;
1372 1460
 		$changes['maintenance'] = $upcontext['user']['main'];
1373 1461
 	}
1374 1462
 	// Otherwise if somehow we are in 2 let's go to 1.
1375
-	elseif (!empty($maintenance) && $maintenance == 2)
1376
-		$changes['maintenance'] = 1;
1463
+	elseif (!empty($maintenance) && $maintenance == 2) {
1464
+			$changes['maintenance'] = 1;
1465
+	}
1377 1466
 
1378 1467
 	// Wipe this out...
1379 1468
 	$upcontext['user'] = array();
@@ -1388,9 +1477,9 @@  discard block
 block discarded – undo
1388 1477
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1389 1478
 
1390 1479
 	// Now is the perfect time to fetch the SM files.
1391
-	if ($command_line)
1392
-		cli_scheduled_fetchSMfiles();
1393
-	else
1480
+	if ($command_line) {
1481
+			cli_scheduled_fetchSMfiles();
1482
+	} else
1394 1483
 	{
1395 1484
 		require_once($sourcedir . '/ScheduledTasks.php');
1396 1485
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1398,8 +1487,9 @@  discard block
 block discarded – undo
1398 1487
 	}
1399 1488
 
1400 1489
 	// Log what we've done.
1401
-	if (empty($user_info['id']))
1402
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1490
+	if (empty($user_info['id'])) {
1491
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1492
+	}
1403 1493
 
1404 1494
 	// Log the action manually, so CLI still works.
1405 1495
 	$smcFunc['db_insert']('',
@@ -1418,8 +1508,9 @@  discard block
 block discarded – undo
1418 1508
 
1419 1509
 	// Save the current database version.
1420 1510
 	$server_version = $smcFunc['db_server_info']();
1421
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1422
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1511
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1512
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1513
+	}
1423 1514
 
1424 1515
 	if ($command_line)
1425 1516
 	{
@@ -1431,8 +1522,9 @@  discard block
 block discarded – undo
1431 1522
 
1432 1523
 	// Make sure it says we're done.
1433 1524
 	$upcontext['overall_percent'] = 100;
1434
-	if (isset($upcontext['step_progress']))
1435
-		unset($upcontext['step_progress']);
1525
+	if (isset($upcontext['step_progress'])) {
1526
+			unset($upcontext['step_progress']);
1527
+	}
1436 1528
 
1437 1529
 	$_GET['substep'] = 0;
1438 1530
 	return false;
@@ -1443,8 +1535,9 @@  discard block
 block discarded – undo
1443 1535
 {
1444 1536
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1445 1537
 
1446
-	if (empty($modSettings['time_format']))
1447
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1538
+	if (empty($modSettings['time_format'])) {
1539
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1540
+	}
1448 1541
 
1449 1542
 	// What files do we want to get
1450 1543
 	$request = $smcFunc['db_query']('', '
@@ -1478,8 +1571,9 @@  discard block
 block discarded – undo
1478 1571
 		$file_data = fetch_web_data($url);
1479 1572
 
1480 1573
 		// If we got an error - give up - the site might be down.
1481
-		if ($file_data === false)
1482
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1574
+		if ($file_data === false) {
1575
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1576
+		}
1483 1577
 
1484 1578
 		// Save the file to the database.
1485 1579
 		$smcFunc['db_query']('substring', '
@@ -1521,8 +1615,9 @@  discard block
 block discarded – undo
1521 1615
 	$themeData = array();
1522 1616
 	foreach ($values as $variable => $value)
1523 1617
 	{
1524
-		if (!isset($value) || $value === null)
1525
-			$value = 0;
1618
+		if (!isset($value) || $value === null) {
1619
+					$value = 0;
1620
+		}
1526 1621
 
1527 1622
 		$themeData[] = array(0, 1, $variable, $value);
1528 1623
 	}
@@ -1551,8 +1646,9 @@  discard block
 block discarded – undo
1551 1646
 
1552 1647
 	foreach ($values as $variable => $value)
1553 1648
 	{
1554
-		if (empty($modSettings[$value[0]]))
1555
-			continue;
1649
+		if (empty($modSettings[$value[0]])) {
1650
+					continue;
1651
+		}
1556 1652
 
1557 1653
 		$smcFunc['db_query']('', '
1558 1654
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1638,19 +1734,21 @@  discard block
 block discarded – undo
1638 1734
 	set_error_handler(
1639 1735
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1640 1736
 		{
1641
-			if ($support_js)
1642
-				return true;
1643
-			else
1644
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1737
+			if ($support_js) {
1738
+							return true;
1739
+			} else {
1740
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1741
+			}
1645 1742
 		}
1646 1743
 	);
1647 1744
 
1648 1745
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1649 1746
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1650
-	if ($db_type == 'mysql')
1651
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1652
-	else
1653
-		$db_collation = '';
1747
+	if ($db_type == 'mysql') {
1748
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1749
+	} else {
1750
+			$db_collation = '';
1751
+	}
1654 1752
 
1655 1753
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1656 1754
 
@@ -1662,8 +1760,9 @@  discard block
 block discarded – undo
1662 1760
 	$last_step = '';
1663 1761
 
1664 1762
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1665
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1666
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1763
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1764
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1765
+	}
1667 1766
 
1668 1767
 	// Count the total number of steps within this file - for progress.
1669 1768
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1683,15 +1782,18 @@  discard block
 block discarded – undo
1683 1782
 		$do_current = $substep >= $_GET['substep'];
1684 1783
 
1685 1784
 		// Get rid of any comments in the beginning of the line...
1686
-		if (substr(trim($line), 0, 2) === '/*')
1687
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1785
+		if (substr(trim($line), 0, 2) === '/*') {
1786
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1787
+		}
1688 1788
 
1689 1789
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1690
-		if ($is_debug && !$support_js && $command_line)
1691
-			flush();
1790
+		if ($is_debug && !$support_js && $command_line) {
1791
+					flush();
1792
+		}
1692 1793
 
1693
-		if (trim($line) === '')
1694
-			continue;
1794
+		if (trim($line) === '') {
1795
+					continue;
1796
+		}
1695 1797
 
1696 1798
 		if (trim(substr($line, 0, 3)) === '---')
1697 1799
 		{
@@ -1701,8 +1803,9 @@  discard block
 block discarded – undo
1701 1803
 			if (trim($current_data) != '' && $type !== '}')
1702 1804
 			{
1703 1805
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1704
-				if ($command_line)
1705
-					echo $upcontext['error_message'];
1806
+				if ($command_line) {
1807
+									echo $upcontext['error_message'];
1808
+				}
1706 1809
 			}
1707 1810
 
1708 1811
 			if ($type == ' ')
@@ -1720,17 +1823,18 @@  discard block
 block discarded – undo
1720 1823
 				if ($do_current)
1721 1824
 				{
1722 1825
 					$upcontext['actioned_items'][] = $last_step;
1723
-					if ($command_line)
1724
-						echo ' * ';
1826
+					if ($command_line) {
1827
+											echo ' * ';
1828
+					}
1725 1829
 				}
1726
-			}
1727
-			elseif ($type == '#')
1830
+			} elseif ($type == '#')
1728 1831
 			{
1729 1832
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1730 1833
 
1731 1834
 				$upcontext['current_debug_item_num']++;
1732
-				if (trim($line) != '---#')
1733
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1835
+				if (trim($line) != '---#') {
1836
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1837
+				}
1734 1838
 
1735 1839
 				// Have we already done something?
1736 1840
 				if (isset($_GET['xml']) && $done_something)
@@ -1741,34 +1845,36 @@  discard block
 block discarded – undo
1741 1845
 
1742 1846
 				if ($do_current)
1743 1847
 				{
1744
-					if (trim($line) == '---#' && $command_line)
1745
-						echo ' done.', $endl;
1746
-					elseif ($command_line)
1747
-						echo ' +++ ', rtrim(substr($line, 4));
1748
-					elseif (trim($line) != '---#')
1848
+					if (trim($line) == '---#' && $command_line) {
1849
+											echo ' done.', $endl;
1850
+					} elseif ($command_line) {
1851
+											echo ' +++ ', rtrim(substr($line, 4));
1852
+					} elseif (trim($line) != '---#')
1749 1853
 					{
1750
-						if ($is_debug)
1751
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1854
+						if ($is_debug) {
1855
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1856
+						}
1752 1857
 					}
1753 1858
 				}
1754 1859
 
1755 1860
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1756 1861
 				{
1757
-					if ($command_line)
1758
-						echo ' * ';
1759
-					else
1760
-						$upcontext['actioned_items'][] = $last_step;
1862
+					if ($command_line) {
1863
+											echo ' * ';
1864
+					} else {
1865
+											$upcontext['actioned_items'][] = $last_step;
1866
+					}
1761 1867
 				}
1762 1868
 
1763 1869
 				// Small step - only if we're actually doing stuff.
1764
-				if ($do_current)
1765
-					nextSubstep(++$substep);
1766
-				else
1767
-					$substep++;
1768
-			}
1769
-			elseif ($type == '{')
1770
-				$current_type = 'code';
1771
-			elseif ($type == '}')
1870
+				if ($do_current) {
1871
+									nextSubstep(++$substep);
1872
+				} else {
1873
+									$substep++;
1874
+				}
1875
+			} elseif ($type == '{') {
1876
+							$current_type = 'code';
1877
+			} elseif ($type == '}')
1772 1878
 			{
1773 1879
 				$current_type = 'sql';
1774 1880
 
@@ -1781,8 +1887,9 @@  discard block
 block discarded – undo
1781 1887
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1782 1888
 				{
1783 1889
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1784
-					if ($command_line)
1785
-						echo $upcontext['error_message'];
1890
+					if ($command_line) {
1891
+											echo $upcontext['error_message'];
1892
+					}
1786 1893
 				}
1787 1894
 
1788 1895
 				// Done with code!
@@ -1862,8 +1969,9 @@  discard block
 block discarded – undo
1862 1969
 	$db_unbuffered = false;
1863 1970
 
1864 1971
 	// Failure?!
1865
-	if ($result !== false)
1866
-		return $result;
1972
+	if ($result !== false) {
1973
+			return $result;
1974
+	}
1867 1975
 
1868 1976
 	$db_error_message = $smcFunc['db_error']($db_connection);
1869 1977
 	// If MySQL we do something more clever.
@@ -1891,54 +1999,61 @@  discard block
 block discarded – undo
1891 1999
 			{
1892 2000
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1893 2001
 				$result = mysqli_query($db_connection, $string);
1894
-				if ($result !== false)
1895
-					return $result;
2002
+				if ($result !== false) {
2003
+									return $result;
2004
+				}
1896 2005
 			}
1897
-		}
1898
-		elseif ($mysqli_errno == 2013)
2006
+		} elseif ($mysqli_errno == 2013)
1899 2007
 		{
1900 2008
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1901 2009
 			mysqli_select_db($db_connection, $db_name);
1902 2010
 			if ($db_connection)
1903 2011
 			{
1904 2012
 				$result = mysqli_query($db_connection, $string);
1905
-				if ($result !== false)
1906
-					return $result;
2013
+				if ($result !== false) {
2014
+									return $result;
2015
+				}
1907 2016
 			}
1908 2017
 		}
1909 2018
 		// Duplicate column name... should be okay ;).
1910
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1911
-			return false;
2019
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2020
+					return false;
2021
+		}
1912 2022
 		// Duplicate insert... make sure it's the proper type of query ;).
1913
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1914
-			return false;
2023
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2024
+					return false;
2025
+		}
1915 2026
 		// Creating an index on a non-existent column.
1916
-		elseif ($mysqli_errno == 1072)
1917
-			return false;
1918
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1919
-			return false;
2027
+		elseif ($mysqli_errno == 1072) {
2028
+					return false;
2029
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2030
+					return false;
2031
+		}
1920 2032
 	}
1921 2033
 	// If a table already exists don't go potty.
1922 2034
 	else
1923 2035
 	{
1924 2036
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1925 2037
 		{
1926
-			if (strpos($db_error_message, 'exist') !== false)
1927
-				return true;
1928
-		}
1929
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2038
+			if (strpos($db_error_message, 'exist') !== false) {
2039
+							return true;
2040
+			}
2041
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1930 2042
 		{
1931
-			if (strpos($db_error_message, 'duplicate') !== false)
1932
-				return true;
2043
+			if (strpos($db_error_message, 'duplicate') !== false) {
2044
+							return true;
2045
+			}
1933 2046
 		}
1934 2047
 	}
1935 2048
 
1936 2049
 	// Get the query string so we pass everything.
1937 2050
 	$query_string = '';
1938
-	foreach ($_GET as $k => $v)
1939
-		$query_string .= ';' . $k . '=' . $v;
1940
-	if (strlen($query_string) != 0)
1941
-		$query_string = '?' . substr($query_string, 1);
2051
+	foreach ($_GET as $k => $v) {
2052
+			$query_string .= ';' . $k . '=' . $v;
2053
+	}
2054
+	if (strlen($query_string) != 0) {
2055
+			$query_string = '?' . substr($query_string, 1);
2056
+	}
1942 2057
 
1943 2058
 	if ($command_line)
1944 2059
 	{
@@ -1993,16 +2108,18 @@  discard block
 block discarded – undo
1993 2108
 			{
1994 2109
 				$found |= 1;
1995 2110
 				// Do some checks on the data if we have it set.
1996
-				if (isset($change['col_type']))
1997
-					$found &= $change['col_type'] === $column['type'];
1998
-				if (isset($change['null_allowed']))
1999
-					$found &= $column['null'] == $change['null_allowed'];
2000
-				if (isset($change['default']))
2001
-					$found &= $change['default'] === $column['default'];
2111
+				if (isset($change['col_type'])) {
2112
+									$found &= $change['col_type'] === $column['type'];
2113
+				}
2114
+				if (isset($change['null_allowed'])) {
2115
+									$found &= $column['null'] == $change['null_allowed'];
2116
+				}
2117
+				if (isset($change['default'])) {
2118
+									$found &= $change['default'] === $column['default'];
2119
+				}
2002 2120
 			}
2003 2121
 		}
2004
-	}
2005
-	elseif ($change['type'] === 'index')
2122
+	} elseif ($change['type'] === 'index')
2006 2123
 	{
2007 2124
 		$request = upgrade_query('
2008 2125
 			SHOW INDEX
@@ -2011,9 +2128,10 @@  discard block
 block discarded – undo
2011 2128
 		{
2012 2129
 			$cur_index = array();
2013 2130
 
2014
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2015
-				if ($row['Key_name'] === $change['name'])
2131
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2132
+							if ($row['Key_name'] === $change['name'])
2016 2133
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2134
+			}
2017 2135
 
2018 2136
 			ksort($cur_index, SORT_NUMERIC);
2019 2137
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2023,14 +2141,17 @@  discard block
 block discarded – undo
2023 2141
 	}
2024 2142
 
2025 2143
 	// If we're trying to add and it's added, we're done.
2026
-	if ($found && in_array($change['method'], array('add', 'change')))
2027
-		return true;
2144
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2145
+			return true;
2146
+	}
2028 2147
 	// Otherwise if we're removing and it wasn't found we're also done.
2029
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2030
-		return true;
2148
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2149
+			return true;
2150
+	}
2031 2151
 	// Otherwise is it just a test?
2032
-	elseif ($is_test)
2033
-		return false;
2152
+	elseif ($is_test) {
2153
+			return false;
2154
+	}
2034 2155
 
2035 2156
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2036 2157
 	$running = false;
@@ -2041,8 +2162,9 @@  discard block
 block discarded – undo
2041 2162
 			SHOW FULL PROCESSLIST');
2042 2163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2043 2164
 		{
2044
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2045
-				$found = true;
2165
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2166
+							$found = true;
2167
+			}
2046 2168
 		}
2047 2169
 
2048 2170
 		// Can't find it? Then we need to run it fools!
@@ -2054,8 +2176,9 @@  discard block
 block discarded – undo
2054 2176
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2055 2177
 				' . $change['text'], true) !== false;
2056 2178
 
2057
-			if (!$success)
2058
-				return false;
2179
+			if (!$success) {
2180
+							return false;
2181
+			}
2059 2182
 
2060 2183
 			// Return
2061 2184
 			$running = true;
@@ -2097,8 +2220,9 @@  discard block
 block discarded – undo
2097 2220
 			'db_error_skip' => true,
2098 2221
 		)
2099 2222
 	);
2100
-	if ($smcFunc['db_num_rows']($request) === 0)
2101
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2223
+	if ($smcFunc['db_num_rows']($request) === 0) {
2224
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2225
+	}
2102 2226
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2103 2227
 	$smcFunc['db_free_result']($request);
2104 2228
 
@@ -2120,18 +2244,19 @@  discard block
 block discarded – undo
2120 2244
 			)
2121 2245
 		);
2122 2246
 		// No results? Just forget it all together.
2123
-		if ($smcFunc['db_num_rows']($request) === 0)
2124
-			unset($table_row['Collation']);
2125
-		else
2126
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2247
+		if ($smcFunc['db_num_rows']($request) === 0) {
2248
+					unset($table_row['Collation']);
2249
+		} else {
2250
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2251
+		}
2127 2252
 		$smcFunc['db_free_result']($request);
2128 2253
 	}
2129 2254
 
2130 2255
 	if ($column_fix)
2131 2256
 	{
2132 2257
 		// Make sure there are no NULL's left.
2133
-		if ($null_fix)
2134
-			$smcFunc['db_query']('', '
2258
+		if ($null_fix) {
2259
+					$smcFunc['db_query']('', '
2135 2260
 				UPDATE {db_prefix}' . $change['table'] . '
2136 2261
 				SET ' . $change['column'] . ' = {string:default}
2137 2262
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2140,6 +2265,7 @@  discard block
 block discarded – undo
2140 2265
 					'db_error_skip' => true,
2141 2266
 				)
2142 2267
 			);
2268
+		}
2143 2269
 
2144 2270
 		// Do the actual alteration.
2145 2271
 		$smcFunc['db_query']('', '
@@ -2168,8 +2294,9 @@  discard block
 block discarded – undo
2168 2294
 	}
2169 2295
 
2170 2296
 	// Not a column we need to check on?
2171
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2172
-		return;
2297
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2298
+			return;
2299
+	}
2173 2300
 
2174 2301
 	// Break it up you (six|seven).
2175 2302
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2188,13 +2315,13 @@  discard block
 block discarded – undo
2188 2315
 				'new_name' => $temp[2],
2189 2316
 		));
2190 2317
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2191
-		if ($smcFunc['db_num_rows'] != 1)
2192
-			return;
2318
+		if ($smcFunc['db_num_rows'] != 1) {
2319
+					return;
2320
+		}
2193 2321
 
2194 2322
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2195 2323
 		$smcFunc['db_free_result']($request);
2196
-	}
2197
-	else
2324
+	} else
2198 2325
 	{
2199 2326
 		// Do this the old fashion, sure method way.
2200 2327
 		$request = $smcFunc['db_query']('', '
@@ -2205,21 +2332,24 @@  discard block
 block discarded – undo
2205 2332
 		));
2206 2333
 		// Mayday!
2207 2334
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2208
-		if ($smcFunc['db_num_rows'] == 0)
2209
-			return;
2335
+		if ($smcFunc['db_num_rows'] == 0) {
2336
+					return;
2337
+		}
2210 2338
 
2211 2339
 		// Oh where, oh where has my little field gone. Oh where can it be...
2212
-		while ($row = $smcFunc['db_query']($request))
2213
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2340
+		while ($row = $smcFunc['db_query']($request)) {
2341
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2214 2342
 			{
2215 2343
 				$current_type = $row['Type'];
2344
+		}
2216 2345
 				break;
2217 2346
 			}
2218 2347
 	}
2219 2348
 
2220 2349
 	// If this doesn't match, the column may of been altered for a reason.
2221
-	if (trim($current_type) != trim($temp[3]))
2222
-		$temp[3] = $current_type;
2350
+	if (trim($current_type) != trim($temp[3])) {
2351
+			$temp[3] = $current_type;
2352
+	}
2223 2353
 
2224 2354
 	// Piece this back together.
2225 2355
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2231,8 +2361,9 @@  discard block
 block discarded – undo
2231 2361
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2232 2362
 	global $step_progress, $is_debug, $upcontext;
2233 2363
 
2234
-	if ($_GET['substep'] < $substep)
2235
-		$_GET['substep'] = $substep;
2364
+	if ($_GET['substep'] < $substep) {
2365
+			$_GET['substep'] = $substep;
2366
+	}
2236 2367
 
2237 2368
 	if ($command_line)
2238 2369
 	{
@@ -2245,29 +2376,33 @@  discard block
 block discarded – undo
2245 2376
 	}
2246 2377
 
2247 2378
 	@set_time_limit(300);
2248
-	if (function_exists('apache_reset_timeout'))
2249
-		@apache_reset_timeout();
2379
+	if (function_exists('apache_reset_timeout')) {
2380
+			@apache_reset_timeout();
2381
+	}
2250 2382
 
2251
-	if (time() - $start_time <= $timeLimitThreshold)
2252
-		return;
2383
+	if (time() - $start_time <= $timeLimitThreshold) {
2384
+			return;
2385
+	}
2253 2386
 
2254 2387
 	// Do we have some custom step progress stuff?
2255 2388
 	if (!empty($step_progress))
2256 2389
 	{
2257 2390
 		$upcontext['substep_progress'] = 0;
2258 2391
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2259
-		if ($step_progress['current'] > $step_progress['total'])
2260
-			$upcontext['substep_progress'] = 99.9;
2261
-		else
2262
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2392
+		if ($step_progress['current'] > $step_progress['total']) {
2393
+					$upcontext['substep_progress'] = 99.9;
2394
+		} else {
2395
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2396
+		}
2263 2397
 
2264 2398
 		// Make it nicely rounded.
2265 2399
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2266 2400
 	}
2267 2401
 
2268 2402
 	// If this is XML we just exit right away!
2269
-	if (isset($_GET['xml']))
2270
-		return upgradeExit();
2403
+	if (isset($_GET['xml'])) {
2404
+			return upgradeExit();
2405
+	}
2271 2406
 
2272 2407
 	// We're going to pause after this!
2273 2408
 	$upcontext['pause'] = true;
@@ -2275,13 +2410,15 @@  discard block
 block discarded – undo
2275 2410
 	$upcontext['query_string'] = '';
2276 2411
 	foreach ($_GET as $k => $v)
2277 2412
 	{
2278
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2279
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2413
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2414
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2415
+		}
2280 2416
 	}
2281 2417
 
2282 2418
 	// Custom warning?
2283
-	if (!empty($custom_warning))
2284
-		$upcontext['custom_warning'] = $custom_warning;
2419
+	if (!empty($custom_warning)) {
2420
+			$upcontext['custom_warning'] = $custom_warning;
2421
+	}
2285 2422
 
2286 2423
 	upgradeExit();
2287 2424
 }
@@ -2296,25 +2433,26 @@  discard block
 block discarded – undo
2296 2433
 	ob_implicit_flush(true);
2297 2434
 	@set_time_limit(600);
2298 2435
 
2299
-	if (!isset($_SERVER['argv']))
2300
-		$_SERVER['argv'] = array();
2436
+	if (!isset($_SERVER['argv'])) {
2437
+			$_SERVER['argv'] = array();
2438
+	}
2301 2439
 	$_GET['maint'] = 1;
2302 2440
 
2303 2441
 	foreach ($_SERVER['argv'] as $i => $arg)
2304 2442
 	{
2305
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2306
-			$_GET['lang'] = $match[1];
2307
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2308
-			continue;
2309
-		elseif ($arg == '--no-maintenance')
2310
-			$_GET['maint'] = 0;
2311
-		elseif ($arg == '--debug')
2312
-			$is_debug = true;
2313
-		elseif ($arg == '--backup')
2314
-			$_POST['backup'] = 1;
2315
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2316
-			$_GET['conv'] = 1;
2317
-		elseif ($i != 0)
2443
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2444
+					$_GET['lang'] = $match[1];
2445
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2446
+					continue;
2447
+		} elseif ($arg == '--no-maintenance') {
2448
+					$_GET['maint'] = 0;
2449
+		} elseif ($arg == '--debug') {
2450
+					$is_debug = true;
2451
+		} elseif ($arg == '--backup') {
2452
+					$_POST['backup'] = 1;
2453
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2454
+					$_GET['conv'] = 1;
2455
+		} elseif ($i != 0)
2318 2456
 		{
2319 2457
 			echo 'SMF Command-line Upgrader
2320 2458
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2328,10 +2466,12 @@  discard block
 block discarded – undo
2328 2466
 		}
2329 2467
 	}
2330 2468
 
2331
-	if (!php_version_check())
2332
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2333
-	if (!db_version_check())
2334
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2469
+	if (!php_version_check()) {
2470
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2471
+	}
2472
+	if (!db_version_check()) {
2473
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2474
+	}
2335 2475
 
2336 2476
 	// Do some checks to make sure they have proper privileges
2337 2477
 	db_extend('packages');
@@ -2346,34 +2486,39 @@  discard block
 block discarded – undo
2346 2486
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2347 2487
 
2348 2488
 	// Sorry... we need CREATE, ALTER and DROP
2349
-	if (!$create || !$alter || !$drop)
2350
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2489
+	if (!$create || !$alter || !$drop) {
2490
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2491
+	}
2351 2492
 
2352 2493
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2353 2494
 		&& @file_exists($sourcedir . '/QueryString.php')
2354 2495
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2355
-	if (!$check && !isset($modSettings['smfVersion']))
2356
-		print_error('Error: Some files are missing or out-of-date.', true);
2496
+	if (!$check && !isset($modSettings['smfVersion'])) {
2497
+			print_error('Error: Some files are missing or out-of-date.', true);
2498
+	}
2357 2499
 
2358 2500
 	// Do a quick version spot check.
2359 2501
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2360 2502
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2361
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2362
-		print_error('Error: Some files have not yet been updated properly.');
2503
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2504
+			print_error('Error: Some files have not yet been updated properly.');
2505
+	}
2363 2506
 
2364 2507
 	// Make sure Settings.php is writable.
2365 2508
 		quickFileWritable($boarddir . '/Settings.php');
2366
-	if (!is_writable($boarddir . '/Settings.php'))
2367
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2509
+	if (!is_writable($boarddir . '/Settings.php')) {
2510
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2511
+	}
2368 2512
 
2369 2513
 	// Make sure Settings_bak.php is writable.
2370 2514
 		quickFileWritable($boarddir . '/Settings_bak.php');
2371
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2372
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2515
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2516
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2517
+	}
2373 2518
 
2374
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2375
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2376
-	elseif (isset($modSettings['agreement']))
2519
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2520
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2521
+	} elseif (isset($modSettings['agreement']))
2377 2522
 	{
2378 2523
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2379 2524
 		fwrite($fp, $modSettings['agreement']);
@@ -2383,31 +2528,36 @@  discard block
 block discarded – undo
2383 2528
 	// Make sure Themes is writable.
2384 2529
 	quickFileWritable($modSettings['theme_dir']);
2385 2530
 
2386
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2387
-		print_error('Error: Unable to obtain write access to "Themes".');
2531
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2532
+			print_error('Error: Unable to obtain write access to "Themes".');
2533
+	}
2388 2534
 
2389 2535
 	// Make sure cache directory exists and is writable!
2390 2536
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2391
-	if (!file_exists($cachedir_temp))
2392
-		@mkdir($cachedir_temp);
2537
+	if (!file_exists($cachedir_temp)) {
2538
+			@mkdir($cachedir_temp);
2539
+	}
2393 2540
 
2394 2541
 	// Make sure the cache temp dir is writable.
2395 2542
 	quickFileWritable($cachedir_temp);
2396 2543
 
2397
-	if (!is_writable($cachedir_temp))
2398
-		print_error('Error: Unable to obtain write access to "cache".', true);
2544
+	if (!is_writable($cachedir_temp)) {
2545
+			print_error('Error: Unable to obtain write access to "cache".', true);
2546
+	}
2399 2547
 
2400
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2401
-		print_error('Error: Unable to find language files!', true);
2402
-	else
2548
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2549
+			print_error('Error: Unable to find language files!', true);
2550
+	} else
2403 2551
 	{
2404 2552
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2405 2553
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2406 2554
 
2407
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2408
-			print_error('Error: Language files out of date.', true);
2409
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2410
-			print_error('Error: Install language is missing for selected language.', true);
2555
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2556
+					print_error('Error: Language files out of date.', true);
2557
+		}
2558
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2559
+					print_error('Error: Install language is missing for selected language.', true);
2560
+		}
2411 2561
 
2412 2562
 		// Otherwise include it!
2413 2563
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2426,8 +2576,9 @@  discard block
 block discarded – undo
2426 2576
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2427 2577
 
2428 2578
 	// Done it already?
2429
-	if (!empty($_POST['utf8_done']))
2430
-		return true;
2579
+	if (!empty($_POST['utf8_done'])) {
2580
+			return true;
2581
+	}
2431 2582
 
2432 2583
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2433 2584
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2440,8 +2591,7 @@  discard block
 block discarded – undo
2440 2591
 		);
2441 2592
 
2442 2593
 		return true;
2443
-	}
2444
-	else
2594
+	} else
2445 2595
 	{
2446 2596
 		$upcontext['page_title'] = 'Converting to UTF8';
2447 2597
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2485,8 +2635,9 @@  discard block
 block discarded – undo
2485 2635
 			)
2486 2636
 		);
2487 2637
 		$db_charsets = array();
2488
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2489
-			$db_charsets[] = $row['Charset'];
2638
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2639
+					$db_charsets[] = $row['Charset'];
2640
+		}
2490 2641
 
2491 2642
 		$smcFunc['db_free_result']($request);
2492 2643
 
@@ -2522,13 +2673,15 @@  discard block
 block discarded – undo
2522 2673
 		// If there's a fulltext index, we need to drop it first...
2523 2674
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2524 2675
 		{
2525
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2526
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2676
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2677
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2527 2678
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2679
+			}
2528 2680
 			$smcFunc['db_free_result']($request);
2529 2681
 
2530
-			if (isset($upcontext['fulltext_index']))
2531
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2682
+			if (isset($upcontext['fulltext_index'])) {
2683
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2684
+			}
2532 2685
 		}
2533 2686
 
2534 2687
 		// Drop it and make a note...
@@ -2718,8 +2871,9 @@  discard block
 block discarded – undo
2718 2871
 			$replace = '%field%';
2719 2872
 
2720 2873
 			// Build a huge REPLACE statement...
2721
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2722
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2874
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2875
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2876
+			}
2723 2877
 		}
2724 2878
 
2725 2879
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2729,9 +2883,10 @@  discard block
 block discarded – undo
2729 2883
 		$upcontext['table_count'] = count($queryTables);
2730 2884
 
2731 2885
 		// What ones have we already done?
2732
-		foreach ($queryTables as $id => $table)
2733
-			if ($id < $_GET['substep'])
2886
+		foreach ($queryTables as $id => $table) {
2887
+					if ($id < $_GET['substep'])
2734 2888
 				$upcontext['previous_tables'][] = $table;
2889
+		}
2735 2890
 
2736 2891
 		$upcontext['cur_table_num'] = $_GET['substep'];
2737 2892
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2768,8 +2923,9 @@  discard block
 block discarded – undo
2768 2923
 			nextSubstep($substep);
2769 2924
 
2770 2925
 			// Just to make sure it doesn't time out.
2771
-			if (function_exists('apache_reset_timeout'))
2772
-				@apache_reset_timeout();
2926
+			if (function_exists('apache_reset_timeout')) {
2927
+							@apache_reset_timeout();
2928
+			}
2773 2929
 
2774 2930
 			$table_charsets = array();
2775 2931
 
@@ -2792,8 +2948,9 @@  discard block
 block discarded – undo
2792 2948
 
2793 2949
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2794 2950
 						if ($charset != 'utf8') {
2795
-							if (!isset($table_charsets[$charset]))
2796
-								$table_charsets[$charset] = array();
2951
+							if (!isset($table_charsets[$charset])) {
2952
+															$table_charsets[$charset] = array();
2953
+							}
2797 2954
 
2798 2955
 							$table_charsets[$charset][] = $column_info;
2799 2956
 						}
@@ -2834,10 +2991,11 @@  discard block
 block discarded – undo
2834 2991
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2835 2992
 				{
2836 2993
 					$update = '';
2837
-					foreach ($table_charsets as $charset => $columns)
2838
-						foreach ($columns as $column)
2994
+					foreach ($table_charsets as $charset => $columns) {
2995
+											foreach ($columns as $column)
2839 2996
 							$update .= '
2840 2997
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2998
+					}
2841 2999
 
2842 3000
 					$smcFunc['db_query']('', '
2843 3001
 						UPDATE {raw:table_name}
@@ -2862,8 +3020,9 @@  discard block
 block discarded – undo
2862 3020
 			// Now do the actual conversion (if still needed).
2863 3021
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2864 3022
 			{
2865
-				if ($command_line)
2866
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3023
+				if ($command_line) {
3024
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3025
+				}
2867 3026
 
2868 3027
 				$smcFunc['db_query']('', '
2869 3028
 					ALTER TABLE {raw:table_name}
@@ -2873,12 +3032,14 @@  discard block
 block discarded – undo
2873 3032
 					)
2874 3033
 				);
2875 3034
 
2876
-				if ($command_line)
2877
-					echo " done.\n";
3035
+				if ($command_line) {
3036
+									echo " done.\n";
3037
+				}
2878 3038
 			}
2879 3039
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2880
-			if (isset($_GET['xml']))
2881
-				return upgradeExit();
3040
+			if (isset($_GET['xml'])) {
3041
+							return upgradeExit();
3042
+			}
2882 3043
 		}
2883 3044
 
2884 3045
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2907,8 +3068,8 @@  discard block
 block discarded – undo
2907 3068
 		);
2908 3069
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2909 3070
 		{
2910
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
2911
-				$smcFunc['db_query']('', '
3071
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3072
+							$smcFunc['db_query']('', '
2912 3073
 					UPDATE {db_prefix}log_actions
2913 3074
 					SET extra = {string:extra}
2914 3075
 					WHERE id_action = {int:current_action}',
@@ -2917,6 +3078,7 @@  discard block
 block discarded – undo
2917 3078
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2918 3079
 					)
2919 3080
 				);
3081
+			}
2920 3082
 		}
2921 3083
 		$smcFunc['db_free_result']($request);
2922 3084
 
@@ -2938,15 +3100,17 @@  discard block
 block discarded – undo
2938 3100
 	// First thing's first - did we already do this?
2939 3101
 	if (!empty($modSettings['json_done']))
2940 3102
 	{
2941
-		if ($command_line)
2942
-			return DeleteUpgrade();
2943
-		else
2944
-			return true;
3103
+		if ($command_line) {
3104
+					return DeleteUpgrade();
3105
+		} else {
3106
+					return true;
3107
+		}
2945 3108
 	}
2946 3109
 
2947 3110
 	// Done it already - js wise?
2948
-	if (!empty($_POST['json_done']))
2949
-		return true;
3111
+	if (!empty($_POST['json_done'])) {
3112
+			return true;
3113
+	}
2950 3114
 
2951 3115
 	// List of tables affected by this function
2952 3116
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2978,12 +3142,14 @@  discard block
 block discarded – undo
2978 3142
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2979 3143
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2980 3144
 
2981
-	foreach ($keys as $id => $table)
2982
-		if ($id < $_GET['substep'])
3145
+	foreach ($keys as $id => $table) {
3146
+			if ($id < $_GET['substep'])
2983 3147
 			$upcontext['previous_tables'][] = $table;
3148
+	}
2984 3149
 
2985
-	if ($command_line)
2986
-		echo 'Converting data from serialize() to json_encode().';
3150
+	if ($command_line) {
3151
+			echo 'Converting data from serialize() to json_encode().';
3152
+	}
2987 3153
 
2988 3154
 	if (!$support_js || isset($_GET['xml']))
2989 3155
 	{
@@ -3023,8 +3189,9 @@  discard block
 block discarded – undo
3023 3189
 
3024 3190
 				// Loop through and fix these...
3025 3191
 				$new_settings = array();
3026
-				if ($command_line)
3027
-					echo "\n" . 'Fixing some settings...';
3192
+				if ($command_line) {
3193
+									echo "\n" . 'Fixing some settings...';
3194
+				}
3028 3195
 
3029 3196
 				foreach ($serialized_settings as $var)
3030 3197
 				{
@@ -3032,22 +3199,24 @@  discard block
 block discarded – undo
3032 3199
 					{
3033 3200
 						// Attempt to unserialize the setting
3034 3201
 						$temp = @safe_unserialize($modSettings[$var]);
3035
-						if (!$temp && $command_line)
3036
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3037
-						elseif ($temp !== false)
3038
-							$new_settings[$var] = json_encode($temp);
3202
+						if (!$temp && $command_line) {
3203
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3204
+						} elseif ($temp !== false) {
3205
+													$new_settings[$var] = json_encode($temp);
3206
+						}
3039 3207
 					}
3040 3208
 				}
3041 3209
 
3042 3210
 				// Update everything at once
3043
-				if (!function_exists('cache_put_data'))
3044
-					require_once($sourcedir . '/Load.php');
3211
+				if (!function_exists('cache_put_data')) {
3212
+									require_once($sourcedir . '/Load.php');
3213
+				}
3045 3214
 				updateSettings($new_settings, true);
3046 3215
 
3047
-				if ($command_line)
3048
-					echo ' done.';
3049
-			}
3050
-			elseif ($table == 'themes')
3216
+				if ($command_line) {
3217
+									echo ' done.';
3218
+				}
3219
+			} elseif ($table == 'themes')
3051 3220
 			{
3052 3221
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3053 3222
 				$query = $smcFunc['db_query']('', '
@@ -3066,10 +3235,11 @@  discard block
 block discarded – undo
3066 3235
 
3067 3236
 						if ($command_line)
3068 3237
 						{
3069
-							if ($temp === false)
3070
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3071
-							else
3072
-								echo "\n" . 'Fixing admin preferences...';
3238
+							if ($temp === false) {
3239
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3240
+							} else {
3241
+															echo "\n" . 'Fixing admin preferences...';
3242
+							}
3073 3243
 						}
3074 3244
 
3075 3245
 						if ($temp !== false)
@@ -3091,15 +3261,15 @@  discard block
 block discarded – undo
3091 3261
 								)
3092 3262
 							);
3093 3263
 
3094
-							if ($command_line)
3095
-								echo ' done.';
3264
+							if ($command_line) {
3265
+															echo ' done.';
3266
+							}
3096 3267
 						}
3097 3268
 					}
3098 3269
 
3099 3270
 					$smcFunc['db_free_result']($query);
3100 3271
 				}
3101
-			}
3102
-			else
3272
+			} else
3103 3273
 			{
3104 3274
 				// First item is always the key...
3105 3275
 				$key = $info[0];
@@ -3110,8 +3280,7 @@  discard block
 block discarded – undo
3110 3280
 				{
3111 3281
 					$col_select = $info[1];
3112 3282
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3113
-				}
3114
-				else
3283
+				} else
3115 3284
 				{
3116 3285
 					$col_select = implode(', ', $info);
3117 3286
 				}
@@ -3144,8 +3313,7 @@  discard block
 block discarded – undo
3144 3313
 								if ($temp === false && $command_line)
3145 3314
 								{
3146 3315
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3147
-								}
3148
-								else
3316
+								} else
3149 3317
 								{
3150 3318
 									$row[$col] = json_encode($temp);
3151 3319
 
@@ -3170,16 +3338,18 @@  discard block
 block discarded – undo
3170 3338
 						}
3171 3339
 					}
3172 3340
 
3173
-					if ($command_line)
3174
-						echo ' done.';
3341
+					if ($command_line) {
3342
+											echo ' done.';
3343
+					}
3175 3344
 
3176 3345
 					// Free up some memory...
3177 3346
 					$smcFunc['db_free_result']($query);
3178 3347
 				}
3179 3348
 			}
3180 3349
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3181
-			if (isset($_GET['xml']))
3182
-				return upgradeExit();
3350
+			if (isset($_GET['xml'])) {
3351
+							return upgradeExit();
3352
+			}
3183 3353
 		}
3184 3354
 
3185 3355
 		if ($command_line)
@@ -3194,8 +3364,9 @@  discard block
 block discarded – undo
3194 3364
 
3195 3365
 		$_GET['substep'] = 0;
3196 3366
 		// Make sure we move on!
3197
-		if ($command_line)
3198
-			return DeleteUpgrade();
3367
+		if ($command_line) {
3368
+					return DeleteUpgrade();
3369
+		}
3199 3370
 
3200 3371
 		return true;
3201 3372
 	}
@@ -3215,14 +3386,16 @@  discard block
 block discarded – undo
3215 3386
 	global $upcontext, $txt, $settings;
3216 3387
 
3217 3388
 	// Don't call me twice!
3218
-	if (!empty($upcontext['chmod_called']))
3219
-		return;
3389
+	if (!empty($upcontext['chmod_called'])) {
3390
+			return;
3391
+	}
3220 3392
 
3221 3393
 	$upcontext['chmod_called'] = true;
3222 3394
 
3223 3395
 	// Nothing?
3224
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3225
-		return;
3396
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3397
+			return;
3398
+	}
3226 3399
 
3227 3400
 	// Was it a problem with Windows?
3228 3401
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3254,11 +3427,12 @@  discard block
 block discarded – undo
3254 3427
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3255 3428
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3256 3429
 
3257
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3258
-		echo '
3430
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3431
+			echo '
3259 3432
 					content.write(\'<hr>\n\t\t\t\');
3260 3433
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3261 3434
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3435
+	}
3262 3436
 
3263 3437
 	echo '
3264 3438
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3266,17 +3440,19 @@  discard block
 block discarded – undo
3266 3440
 				}
3267 3441
 			</script>';
3268 3442
 
3269
-	if (!empty($upcontext['chmod']['ftp_error']))
3270
-		echo '
3443
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3444
+			echo '
3271 3445
 			<div class="error_message red">
3272 3446
 				The following error was encountered when trying to connect:<br><br>
3273 3447
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3274 3448
 			</div>
3275 3449
 			<br>';
3450
+	}
3276 3451
 
3277
-	if (empty($upcontext['chmod_in_form']))
3278
-		echo '
3452
+	if (empty($upcontext['chmod_in_form'])) {
3453
+			echo '
3279 3454
 	<form action="', $upcontext['form_url'], '" method="post">';
3455
+	}
3280 3456
 
3281 3457
 	echo '
3282 3458
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3311,10 +3487,11 @@  discard block
 block discarded – undo
3311 3487
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3312 3488
 	</div>';
3313 3489
 
3314
-	if (empty($upcontext['chmod_in_form']))
3315
-		echo '
3490
+	if (empty($upcontext['chmod_in_form'])) {
3491
+			echo '
3316 3492
 	</form>';
3317
-}
3493
+	}
3494
+	}
3318 3495
 
3319 3496
 function template_upgrade_above()
3320 3497
 {
@@ -3374,9 +3551,10 @@  discard block
 block discarded – undo
3374 3551
 				<h2>', $txt['upgrade_progress'], '</h2>
3375 3552
 				<ul>';
3376 3553
 
3377
-	foreach ($upcontext['steps'] as $num => $step)
3378
-		echo '
3554
+	foreach ($upcontext['steps'] as $num => $step) {
3555
+			echo '
3379 3556
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3557
+	}
3380 3558
 
3381 3559
 	echo '
3382 3560
 					</ul>
@@ -3389,8 +3567,8 @@  discard block
 block discarded – undo
3389 3567
 				</div>
3390 3568
 			</div>';
3391 3569
 
3392
-	if (isset($upcontext['step_progress']))
3393
-		echo '
3570
+	if (isset($upcontext['step_progress'])) {
3571
+			echo '
3394 3572
 				<br>
3395 3573
 				<br>
3396 3574
 				<div id="progress_bar_step">
@@ -3399,6 +3577,7 @@  discard block
 block discarded – undo
3399 3577
 						<span>', $txt['upgrade_step_progress'], '</span>
3400 3578
 					</div>
3401 3579
 				</div>';
3580
+	}
3402 3581
 
3403 3582
 	echo '
3404 3583
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3429,32 +3608,36 @@  discard block
 block discarded – undo
3429 3608
 {
3430 3609
 	global $upcontext, $txt;
3431 3610
 
3432
-	if (!empty($upcontext['pause']))
3433
-		echo '
3611
+	if (!empty($upcontext['pause'])) {
3612
+			echo '
3434 3613
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3435 3614
 
3436 3615
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3437 3616
 								<h3>
3438 3617
 									', $txt['upgrade_paused_overload'], '
3439 3618
 								</h3>';
3619
+	}
3440 3620
 
3441
-	if (!empty($upcontext['custom_warning']))
3442
-		echo '
3621
+	if (!empty($upcontext['custom_warning'])) {
3622
+			echo '
3443 3623
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3444 3624
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3445 3625
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3446 3626
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3447 3627
 								</div>';
3628
+	}
3448 3629
 
3449 3630
 	echo '
3450 3631
 								<div class="righttext" style="margin: 1ex;">';
3451 3632
 
3452
-	if (!empty($upcontext['continue']))
3453
-		echo '
3633
+	if (!empty($upcontext['continue'])) {
3634
+			echo '
3454 3635
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3455
-	if (!empty($upcontext['skip']))
3456
-		echo '
3636
+	}
3637
+	if (!empty($upcontext['skip'])) {
3638
+			echo '
3457 3639
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3640
+	}
3458 3641
 
3459 3642
 	echo '
3460 3643
 								</div>
@@ -3504,11 +3687,12 @@  discard block
 block discarded – undo
3504 3687
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3505 3688
 	<smf>';
3506 3689
 
3507
-	if (!empty($upcontext['get_data']))
3508
-		foreach ($upcontext['get_data'] as $k => $v)
3690
+	if (!empty($upcontext['get_data'])) {
3691
+			foreach ($upcontext['get_data'] as $k => $v)
3509 3692
 			echo '
3510 3693
 		<get key="', $k, '">', $v, '</get>';
3511
-}
3694
+	}
3695
+	}
3512 3696
 
3513 3697
 function template_xml_below()
3514 3698
 {
@@ -3549,8 +3733,8 @@  discard block
 block discarded – undo
3549 3733
 	template_chmod();
3550 3734
 
3551 3735
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3552
-	if ($upcontext['is_large_forum'])
3553
-		echo '
3736
+	if ($upcontext['is_large_forum']) {
3737
+			echo '
3554 3738
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3555 3739
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3556 3740
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3558,10 +3742,11 @@  discard block
 block discarded – undo
3558 3742
 				', $txt['upgrade_warning_lots_data'], '
3559 3743
 			</div>
3560 3744
 		</div>';
3745
+	}
3561 3746
 
3562 3747
 	// A warning message?
3563
-	if (!empty($upcontext['warning']))
3564
-		echo '
3748
+	if (!empty($upcontext['warning'])) {
3749
+			echo '
3565 3750
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3566 3751
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3567 3752
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3569,6 +3754,7 @@  discard block
 block discarded – undo
3569 3754
 				', $upcontext['warning'], '
3570 3755
 			</div>
3571 3756
 		</div>';
3757
+	}
3572 3758
 
3573 3759
 	// Paths are incorrect?
3574 3760
 	echo '
@@ -3584,20 +3770,22 @@  discard block
 block discarded – undo
3584 3770
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3585 3771
 	{
3586 3772
 		$ago = time() - $upcontext['started'];
3587
-		if ($ago < 60)
3588
-			$ago = $ago . ' seconds';
3589
-		elseif ($ago < 3600)
3590
-			$ago = (int) ($ago / 60) . ' minutes';
3591
-		else
3592
-			$ago = (int) ($ago / 3600) . ' hours';
3773
+		if ($ago < 60) {
3774
+					$ago = $ago . ' seconds';
3775
+		} elseif ($ago < 3600) {
3776
+					$ago = (int) ($ago / 60) . ' minutes';
3777
+		} else {
3778
+					$ago = (int) ($ago / 3600) . ' hours';
3779
+		}
3593 3780
 
3594 3781
 		$active = time() - $upcontext['updated'];
3595
-		if ($active < 60)
3596
-			$updated = $active . ' seconds';
3597
-		elseif ($active < 3600)
3598
-			$updated = (int) ($active / 60) . ' minutes';
3599
-		else
3600
-			$updated = (int) ($active / 3600) . ' hours';
3782
+		if ($active < 60) {
3783
+					$updated = $active . ' seconds';
3784
+		} elseif ($active < 3600) {
3785
+					$updated = (int) ($active / 60) . ' minutes';
3786
+		} else {
3787
+					$updated = (int) ($active / 3600) . ' hours';
3788
+		}
3601 3789
 
3602 3790
 		echo '
3603 3791
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3606,16 +3794,18 @@  discard block
 block discarded – undo
3606 3794
 			<div style="padding-left: 6ex;">
3607 3795
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3608 3796
 
3609
-		if ($active < 600)
3610
-			echo '
3797
+		if ($active < 600) {
3798
+					echo '
3611 3799
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3800
+		}
3612 3801
 
3613
-		if ($active > $upcontext['inactive_timeout'])
3614
-			echo '
3802
+		if ($active > $upcontext['inactive_timeout']) {
3803
+					echo '
3615 3804
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3616
-		else
3617
-			echo '
3805
+		} else {
3806
+					echo '
3618 3807
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3808
+		}
3619 3809
 
3620 3810
 		echo '
3621 3811
 			</div>
@@ -3631,9 +3821,10 @@  discard block
 block discarded – undo
3631 3821
 					<td>
3632 3822
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3633 3823
 
3634
-	if (!empty($upcontext['username_incorrect']))
3635
-		echo '
3824
+	if (!empty($upcontext['username_incorrect'])) {
3825
+			echo '
3636 3826
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3827
+	}
3637 3828
 
3638 3829
 	echo '
3639 3830
 					</td>
@@ -3644,9 +3835,10 @@  discard block
 block discarded – undo
3644 3835
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3645 3836
 						<input type="hidden" name="hash_passwrd" value="">';
3646 3837
 
3647
-	if (!empty($upcontext['password_failed']))
3648
-		echo '
3838
+	if (!empty($upcontext['password_failed'])) {
3839
+			echo '
3649 3840
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3841
+	}
3650 3842
 
3651 3843
 	echo '
3652 3844
 					</td>
@@ -3717,8 +3909,8 @@  discard block
 block discarded – undo
3717 3909
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3718 3910
 
3719 3911
 	// Warning message?
3720
-	if (!empty($upcontext['upgrade_options_warning']))
3721
-		echo '
3912
+	if (!empty($upcontext['upgrade_options_warning'])) {
3913
+			echo '
3722 3914
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3723 3915
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3724 3916
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3726,6 +3918,7 @@  discard block
 block discarded – undo
3726 3918
 				', $upcontext['upgrade_options_warning'], '
3727 3919
 			</div>
3728 3920
 		</div>';
3921
+	}
3729 3922
 
3730 3923
 	echo '
3731 3924
 				<table>
@@ -3768,8 +3961,8 @@  discard block
 block discarded – undo
3768 3961
 						</td>
3769 3962
 					</tr>';
3770 3963
 
3771
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3772
-		echo '
3964
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3965
+			echo '
3773 3966
 					<tr valign="top">
3774 3967
 						<td width="2%">
3775 3968
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3778,6 +3971,7 @@  discard block
 block discarded – undo
3778 3971
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3779 3972
 						</td>
3780 3973
 					</tr>';
3974
+	}
3781 3975
 
3782 3976
 	echo '
3783 3977
 					<tr valign="top">
@@ -3815,10 +4009,11 @@  discard block
 block discarded – undo
3815 4009
 			</div>';
3816 4010
 
3817 4011
 	// Dont any tables so far?
3818
-	if (!empty($upcontext['previous_tables']))
3819
-		foreach ($upcontext['previous_tables'] as $table)
4012
+	if (!empty($upcontext['previous_tables'])) {
4013
+			foreach ($upcontext['previous_tables'] as $table)
3820 4014
 			echo '
3821 4015
 			<br>Completed Table: &quot;', $table, '&quot;.';
4016
+	}
3822 4017
 
3823 4018
 	echo '
3824 4019
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3855,12 +4050,13 @@  discard block
 block discarded – undo
3855 4050
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3856 4051
 
3857 4052
 		// If debug flood the screen.
3858
-		if ($is_debug)
3859
-			echo '
4053
+		if ($is_debug) {
4054
+					echo '
3860 4055
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3861 4056
 
3862 4057
 				if (document.getElementById(\'debug_section\').scrollHeight)
3863 4058
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4059
+		}
3864 4060
 
3865 4061
 		echo '
3866 4062
 				// Get the next update...
@@ -3893,8 +4089,9 @@  discard block
 block discarded – undo
3893 4089
 {
3894 4090
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3895 4091
 
3896
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3897
-		$is_debug = true;
4092
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4093
+			$is_debug = true;
4094
+	}
3898 4095
 
3899 4096
 	echo '
3900 4097
 		<h3>Executing database changes</h3>
@@ -3909,8 +4106,9 @@  discard block
 block discarded – undo
3909 4106
 	{
3910 4107
 		foreach ($upcontext['actioned_items'] as $num => $item)
3911 4108
 		{
3912
-			if ($num != 0)
3913
-				echo ' Successful!';
4109
+			if ($num != 0) {
4110
+							echo ' Successful!';
4111
+			}
3914 4112
 			echo '<br>' . $item;
3915 4113
 		}
3916 4114
 		if (!empty($upcontext['changes_complete']))
@@ -3923,28 +4121,32 @@  discard block
 block discarded – undo
3923 4121
 				$seconds = intval($active % 60);
3924 4122
 
3925 4123
 				$totalTime = '';
3926
-				if ($hours > 0)
3927
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3928
-				if ($minutes > 0)
3929
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3930
-				if ($seconds > 0)
3931
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4124
+				if ($hours > 0) {
4125
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4126
+				}
4127
+				if ($minutes > 0) {
4128
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4129
+				}
4130
+				if ($seconds > 0) {
4131
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4132
+				}
3932 4133
 			}
3933 4134
 
3934
-			if ($is_debug && !empty($totalTime))
3935
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3936
-			else
3937
-				echo ' Successful!<br><br>';
4135
+			if ($is_debug && !empty($totalTime)) {
4136
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4137
+			} else {
4138
+							echo ' Successful!<br><br>';
4139
+			}
3938 4140
 
3939 4141
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3940 4142
 		}
3941
-	}
3942
-	else
4143
+	} else
3943 4144
 	{
3944 4145
 		// Tell them how many files we have in total.
3945
-		if ($upcontext['file_count'] > 1)
3946
-			echo '
4146
+		if ($upcontext['file_count'] > 1) {
4147
+					echo '
3947 4148
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4149
+		}
3948 4150
 
3949 4151
 		echo '
3950 4152
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3960,19 +4162,23 @@  discard block
 block discarded – undo
3960 4162
 				$seconds = intval($active % 60);
3961 4163
 
3962 4164
 				$totalTime = '';
3963
-				if ($hours > 0)
3964
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3965
-				if ($minutes > 0)
3966
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3967
-				if ($seconds > 0)
3968
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4165
+				if ($hours > 0) {
4166
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4167
+				}
4168
+				if ($minutes > 0) {
4169
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4170
+				}
4171
+				if ($seconds > 0) {
4172
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4173
+				}
3969 4174
 			}
3970 4175
 
3971 4176
 			echo '
3972 4177
 			<br><span id="upgradeCompleted">';
3973 4178
 
3974
-			if (!empty($totalTime))
3975
-				echo 'Completed in ', $totalTime, '<br>';
4179
+			if (!empty($totalTime)) {
4180
+							echo 'Completed in ', $totalTime, '<br>';
4181
+			}
3976 4182
 
3977 4183
 			echo '</span>
3978 4184
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4009,9 +4215,10 @@  discard block
 block discarded – undo
4009 4215
 			var getData = "";
4010 4216
 			var debugItems = ', $upcontext['debug_items'], ';';
4011 4217
 
4012
-		if ($is_debug)
4013
-			echo '
4218
+		if ($is_debug) {
4219
+					echo '
4014 4220
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4221
+		}
4015 4222
 
4016 4223
 		echo '
4017 4224
 			function getNextItem()
@@ -4051,9 +4258,10 @@  discard block
 block discarded – undo
4051 4258
 						document.getElementById("error_block").style.display = "";
4052 4259
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4053 4260
 
4054
-	if ($is_debug)
4055
-		echo '
4261
+	if ($is_debug) {
4262
+			echo '
4056 4263
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4264
+	}
4057 4265
 
4058 4266
 	echo '
4059 4267
 					}
@@ -4074,9 +4282,10 @@  discard block
 block discarded – undo
4074 4282
 						document.getElementById("error_block").style.display = "";
4075 4283
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4076 4284
 
4077
-	if ($is_debug)
4078
-		echo '
4285
+	if ($is_debug) {
4286
+			echo '
4079 4287
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4288
+	}
4080 4289
 
4081 4290
 	echo '
4082 4291
 					}
@@ -4135,8 +4344,8 @@  discard block
 block discarded – undo
4135 4344
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4136 4345
 				{';
4137 4346
 
4138
-		if ($is_debug)
4139
-			echo '
4347
+		if ($is_debug) {
4348
+					echo '
4140 4349
 					document.getElementById(\'debug_section\').style.display = "none";
4141 4350
 
4142 4351
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4154,6 +4363,7 @@  discard block
 block discarded – undo
4154 4363
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4155 4364
 
4156 4365
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4366
+		}
4157 4367
 
4158 4368
 		echo '
4159 4369
 
@@ -4161,9 +4371,10 @@  discard block
 block discarded – undo
4161 4371
 					document.getElementById(\'contbutt\').disabled = 0;
4162 4372
 					document.getElementById(\'database_done\').value = 1;';
4163 4373
 
4164
-		if ($upcontext['file_count'] > 1)
4165
-			echo '
4374
+		if ($upcontext['file_count'] > 1) {
4375
+					echo '
4166 4376
 					document.getElementById(\'info1\').style.display = "none";';
4377
+		}
4167 4378
 
4168 4379
 		echo '
4169 4380
 					document.getElementById(\'info2\').style.display = "none";
@@ -4176,9 +4387,10 @@  discard block
 block discarded – undo
4176 4387
 					lastItem = 0;
4177 4388
 					prevFile = curFile;';
4178 4389
 
4179
-		if ($is_debug)
4180
-			echo '
4390
+		if ($is_debug) {
4391
+					echo '
4181 4392
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4393
+		}
4182 4394
 
4183 4395
 		echo '
4184 4396
 					getNextItem();
@@ -4186,8 +4398,8 @@  discard block
 block discarded – undo
4186 4398
 				}';
4187 4399
 
4188 4400
 		// If debug scroll the screen.
4189
-		if ($is_debug)
4190
-			echo '
4401
+		if ($is_debug) {
4402
+					echo '
4191 4403
 				if (iLastSubStepProgress == -1)
4192 4404
 				{
4193 4405
 					// Give it consistent dots.
@@ -4206,6 +4418,7 @@  discard block
 block discarded – undo
4206 4418
 
4207 4419
 				if (document.getElementById(\'debug_section\').scrollHeight)
4208 4420
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4421
+		}
4209 4422
 
4210 4423
 		echo '
4211 4424
 				// Update the page.
@@ -4266,9 +4479,10 @@  discard block
 block discarded – undo
4266 4479
 			}';
4267 4480
 
4268 4481
 		// Start things off assuming we've not errored.
4269
-		if (empty($upcontext['error_message']))
4270
-			echo '
4482
+		if (empty($upcontext['error_message'])) {
4483
+					echo '
4271 4484
 			getNextItem();';
4485
+		}
4272 4486
 
4273 4487
 		echo '
4274 4488
 		//# sourceURL=dynamicScript-dbch.js
@@ -4286,18 +4500,21 @@  discard block
 block discarded – undo
4286 4500
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4287 4501
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4288 4502
 
4289
-	if (!empty($upcontext['error_message']))
4290
-		echo '
4503
+	if (!empty($upcontext['error_message'])) {
4504
+			echo '
4291 4505
 	<error>', $upcontext['error_message'], '</error>';
4506
+	}
4292 4507
 
4293
-	if (!empty($upcontext['error_string']))
4294
-		echo '
4508
+	if (!empty($upcontext['error_string'])) {
4509
+			echo '
4295 4510
 	<sql>', $upcontext['error_string'], '</sql>';
4511
+	}
4296 4512
 
4297
-	if ($is_debug)
4298
-		echo '
4513
+	if ($is_debug) {
4514
+			echo '
4299 4515
 	<curtime>', time(), '</curtime>';
4300
-}
4516
+	}
4517
+	}
4301 4518
 
4302 4519
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4303 4520
 function template_convert_utf8()
@@ -4316,18 +4533,20 @@  discard block
 block discarded – undo
4316 4533
 			</div>';
4317 4534
 
4318 4535
 	// Done any tables so far?
4319
-	if (!empty($upcontext['previous_tables']))
4320
-		foreach ($upcontext['previous_tables'] as $table)
4536
+	if (!empty($upcontext['previous_tables'])) {
4537
+			foreach ($upcontext['previous_tables'] as $table)
4321 4538
 			echo '
4322 4539
 			<br>Completed Table: &quot;', $table, '&quot;.';
4540
+	}
4323 4541
 
4324 4542
 	echo '
4325 4543
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4326 4544
 
4327 4545
 	// If we dropped their index, let's let them know
4328
-	if ($upcontext['dropping_index'])
4329
-		echo '
4546
+	if ($upcontext['dropping_index']) {
4547
+			echo '
4330 4548
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4549
+	}
4331 4550
 
4332 4551
 	// Completion notification
4333 4552
 	echo '
@@ -4364,12 +4583,13 @@  discard block
 block discarded – undo
4364 4583
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4365 4584
 
4366 4585
 		// If debug flood the screen.
4367
-		if ($is_debug)
4368
-			echo '
4586
+		if ($is_debug) {
4587
+					echo '
4369 4588
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4370 4589
 
4371 4590
 				if (document.getElementById(\'debug_section\').scrollHeight)
4372 4591
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4592
+		}
4373 4593
 
4374 4594
 		echo '
4375 4595
 				// Get the next update...
@@ -4417,19 +4637,21 @@  discard block
 block discarded – undo
4417 4637
 			</div>';
4418 4638
 
4419 4639
 	// Dont any tables so far?
4420
-	if (!empty($upcontext['previous_tables']))
4421
-		foreach ($upcontext['previous_tables'] as $table)
4640
+	if (!empty($upcontext['previous_tables'])) {
4641
+			foreach ($upcontext['previous_tables'] as $table)
4422 4642
 			echo '
4423 4643
 			<br>Completed Table: &quot;', $table, '&quot;.';
4644
+	}
4424 4645
 
4425 4646
 	echo '
4426 4647
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4427 4648
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4428 4649
 
4429 4650
 	// Try to make sure substep was reset.
4430
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4431
-		echo '
4651
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4652
+			echo '
4432 4653
 			<input type="hidden" name="substep" id="substep" value="0">';
4654
+	}
4433 4655
 
4434 4656
 	// Continue please!
4435 4657
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4462,12 +4684,13 @@  discard block
 block discarded – undo
4462 4684
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4463 4685
 
4464 4686
 		// If debug flood the screen.
4465
-		if ($is_debug)
4466
-			echo '
4687
+		if ($is_debug) {
4688
+					echo '
4467 4689
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4468 4690
 
4469 4691
 				if (document.getElementById(\'debug_section\').scrollHeight)
4470 4692
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4693
+		}
4471 4694
 
4472 4695
 		echo '
4473 4696
 				// Get the next update...
@@ -4503,8 +4726,8 @@  discard block
 block discarded – undo
4503 4726
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4504 4727
 	<form action="', $boardurl, '/index.php">';
4505 4728
 
4506
-	if (!empty($upcontext['can_delete_script']))
4507
-		echo '
4729
+	if (!empty($upcontext['can_delete_script'])) {
4730
+			echo '
4508 4731
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4509 4732
 			<script>
4510 4733
 				function doTheDelete(theCheck)
@@ -4516,6 +4739,7 @@  discard block
 block discarded – undo
4516 4739
 				}
4517 4740
 			</script>
4518 4741
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4742
+	}
4519 4743
 
4520 4744
 	$active = time() - $upcontext['started'];
4521 4745
 	$hours = floor($active / 3600);
@@ -4525,16 +4749,20 @@  discard block
 block discarded – undo
4525 4749
 	if ($is_debug)
4526 4750
 	{
4527 4751
 		$totalTime = '';
4528
-		if ($hours > 0)
4529
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4530
-		if ($minutes > 0)
4531
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4532
-		if ($seconds > 0)
4533
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4752
+		if ($hours > 0) {
4753
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4754
+		}
4755
+		if ($minutes > 0) {
4756
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4757
+		}
4758
+		if ($seconds > 0) {
4759
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4760
+		}
4534 4761
 	}
4535 4762
 
4536
-	if ($is_debug && !empty($totalTime))
4537
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4763
+	if ($is_debug && !empty($totalTime)) {
4764
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4765
+	}
4538 4766
 
4539 4767
 	echo '<br>
4540 4768
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4561,8 +4789,9 @@  discard block
 block discarded – undo
4561 4789
 
4562 4790
 	$current_substep = $_GET['substep'];
4563 4791
 
4564
-	if (empty($_GET['a']))
4565
-		$_GET['a'] = 0;
4792
+	if (empty($_GET['a'])) {
4793
+			$_GET['a'] = 0;
4794
+	}
4566 4795
 	$step_progress['name'] = 'Converting ips';
4567 4796
 	$step_progress['current'] = $_GET['a'];
4568 4797
 
@@ -4605,16 +4834,19 @@  discard block
 block discarded – undo
4605 4834
 				'empty' => '',
4606 4835
 				'limit' => $limit,
4607 4836
 		));
4608
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4609
-			$arIp[] = $row[$oldCol];
4837
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4838
+					$arIp[] = $row[$oldCol];
4839
+		}
4610 4840
 		$smcFunc['db_free_result']($request);
4611 4841
 
4612 4842
 		// Special case, null ip could keep us in a loop.
4613
-		if (is_null($arIp[0]))
4614
-			unset($arIp[0]);
4843
+		if (is_null($arIp[0])) {
4844
+					unset($arIp[0]);
4845
+		}
4615 4846
 
4616
-		if (empty($arIp))
4617
-			$is_done = true;
4847
+		if (empty($arIp)) {
4848
+					$is_done = true;
4849
+		}
4618 4850
 
4619 4851
 		$updates = array();
4620 4852
 		$cases = array();
@@ -4623,16 +4855,18 @@  discard block
 block discarded – undo
4623 4855
 		{
4624 4856
 			$arIp[$i] = trim($arIp[$i]);
4625 4857
 
4626
-			if (empty($arIp[$i]))
4627
-				continue;
4858
+			if (empty($arIp[$i])) {
4859
+							continue;
4860
+			}
4628 4861
 
4629 4862
 			$updates['ip' . $i] = $arIp[$i];
4630 4863
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4631 4864
 
4632 4865
 			if ($setSize > 0 && $i % $setSize === 0)
4633 4866
 			{
4634
-				if (count($updates) == 1)
4635
-					continue;
4867
+				if (count($updates) == 1) {
4868
+									continue;
4869
+				}
4636 4870
 
4637 4871
 				$updates['whereSet'] = array_values($updates);
4638 4872
 				$smcFunc['db_query']('', '
@@ -4666,8 +4900,7 @@  discard block
 block discarded – undo
4666 4900
 							'ip' => $ip
4667 4901
 					));
4668 4902
 				}
4669
-			}
4670
-			else
4903
+			} else
4671 4904
 			{
4672 4905
 				$updates['whereSet'] = array_values($updates);
4673 4906
 				$smcFunc['db_query']('', '
@@ -4681,9 +4914,9 @@  discard block
 block discarded – undo
4681 4914
 					$updates
4682 4915
 				);
4683 4916
 			}
4917
+		} else {
4918
+					$is_done = true;
4684 4919
 		}
4685
-		else
4686
-			$is_done = true;
4687 4920
 
4688 4921
 		$_GET['a'] += $limit;
4689 4922
 		$step_progress['current'] = $_GET['a'];
@@ -4709,10 +4942,11 @@  discard block
 block discarded – undo
4709 4942
 
4710 4943
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4711 4944
 
4712
-	if (isset($columns[$column]))
4713
-		return $columns[$column];
4714
-	else
4715
-		return null;
4716
-}
4945
+	if (isset($columns[$column])) {
4946
+			return $columns[$column];
4947
+	} else {
4948
+			return null;
4949
+	}
4950
+	}
4717 4951
 
4718 4952
 ?>
4719 4953
\ No newline at end of file
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +444 added lines, -330 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting.
154 160
 	error_reporting(E_ALL);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -237,10 +246,11 @@  discard block
 block discarded – undo
237 246
 	{
238 247
 		// Get PHP's default timezone, if set
239 248
 		$ini_tz = ini_get('date.timezone');
240
-		if (!empty($ini_tz))
241
-			$timezone_id = $ini_tz;
242
-		else
243
-			$timezone_id = '';
249
+		if (!empty($ini_tz)) {
250
+					$timezone_id = $ini_tz;
251
+		} else {
252
+					$timezone_id = '';
253
+		}
244 254
 
245 255
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
246 256
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -270,8 +280,9 @@  discard block
 block discarded – undo
270 280
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
271 281
 		while ($entry = $dir->read())
272 282
 		{
273
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
274
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
283
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
284
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
285
+			}
275 286
 		}
276 287
 		$dir->close();
277 288
 	}
@@ -306,10 +317,11 @@  discard block
 block discarded – undo
306 317
 	}
307 318
 
308 319
 	// Override the language file?
309
-	if (isset($_GET['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
311
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
312
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	if (isset($_GET['lang_file'])) {
321
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
322
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
323
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
324
+	}
313 325
 
314 326
 	// Make sure it exists, if it doesn't reset it.
315 327
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -318,8 +330,9 @@  discard block
 block discarded – undo
318 330
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
319 331
 
320 332
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
321
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
322
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
333
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
334
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
335
+		}
323 336
 	}
324 337
 
325 338
 	// And now include the actual language file itself.
@@ -332,15 +345,18 @@  discard block
 block discarded – undo
332 345
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
333 346
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
334 347
 
335
-	if (empty($sourcedir))
336
-		$sourcedir = dirname(__FILE__) . '/Sources';
348
+	if (empty($sourcedir)) {
349
+			$sourcedir = dirname(__FILE__) . '/Sources';
350
+	}
337 351
 
338 352
 	// Need this to check whether we need the database password.
339 353
 	require(dirname(__FILE__) . '/Settings.php');
340
-	if (!defined('SMF'))
341
-		define('SMF', 1);
342
-	if (empty($smcFunc))
343
-		$smcFunc = array();
354
+	if (!defined('SMF')) {
355
+			define('SMF', 1);
356
+	}
357
+	if (empty($smcFunc)) {
358
+			$smcFunc = array();
359
+	}
344 360
 
345 361
 	$modSettings['disableQueryCheck'] = true;
346 362
 
@@ -348,8 +364,9 @@  discard block
 block discarded – undo
348 364
 	if (!$db_connection)
349 365
 	{
350 366
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
351
-		if (version_compare(PHP_VERSION, '5', '<'))
352
-			require_once($sourcedir . '/Subs-Compat.php');
367
+		if (version_compare(PHP_VERSION, '5', '<')) {
368
+					require_once($sourcedir . '/Subs-Compat.php');
369
+		}
353 370
 
354 371
 		$db_options = array('persist' => $db_persist);
355 372
 		$port = '';
@@ -360,19 +377,20 @@  discard block
 block discarded – undo
360 377
 			if ($db_type == 'mysql')
361 378
 			{
362 379
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
363
-			}
364
-			elseif ($db_type == 'postgresql')
380
+			} elseif ($db_type == 'postgresql')
365 381
 			{
366 382
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
367 383
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
368 384
 			}
369 385
 		}
370 386
 
371
-		if (!empty($port))
372
-			$db_options['port'] = $port;
387
+		if (!empty($port)) {
388
+					$db_options['port'] = $port;
389
+		}
373 390
 
374
-		if (!$db_connection)
375
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
391
+		if (!$db_connection) {
392
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
393
+		}
376 394
 	}
377 395
 }
378 396
 
@@ -400,8 +418,9 @@  discard block
 block discarded – undo
400 418
 		// @todo REMOVE THIS!!
401 419
 		else
402 420
 		{
403
-			if (function_exists('doStep' . $_GET['step']))
404
-				call_user_func('doStep' . $_GET['step']);
421
+			if (function_exists('doStep' . $_GET['step'])) {
422
+							call_user_func('doStep' . $_GET['step']);
423
+			}
405 424
 		}
406 425
 		// Show the footer.
407 426
 		template_install_below();
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 	$incontext['sub_template'] = 'welcome_message';
420 439
 
421 440
 	// Done the submission?
422
-	if (isset($_POST['contbutt']))
423
-		return true;
441
+	if (isset($_POST['contbutt'])) {
442
+			return true;
443
+	}
424 444
 
425 445
 	// See if we think they have already installed it?
426 446
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -428,14 +448,17 @@  discard block
 block discarded – undo
428 448
 		$probably_installed = 0;
429 449
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
430 450
 		{
431
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
432
-				$probably_installed++;
433
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
434
-				$probably_installed++;
451
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
452
+							$probably_installed++;
453
+			}
454
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
455
+							$probably_installed++;
456
+			}
435 457
 		}
436 458
 
437
-		if ($probably_installed == 2)
438
-			$incontext['warning'] = $txt['error_already_installed'];
459
+		if ($probably_installed == 2) {
460
+					$incontext['warning'] = $txt['error_already_installed'];
461
+		}
439 462
 	}
440 463
 
441 464
 	// Is some database support even compiled in?
@@ -450,45 +473,54 @@  discard block
 block discarded – undo
450 473
 				$databases[$key]['supported'] = false;
451 474
 				$notFoundSQLFile = true;
452 475
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
476
+			} else {
477
+							$incontext['supported_databases'][] = $db;
453 478
 			}
454
-			else
455
-				$incontext['supported_databases'][] = $db;
456 479
 		}
457 480
 	}
458 481
 
459 482
 	// Check the PHP version.
460
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
461
-		$error = 'error_php_too_low';
483
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
484
+			$error = 'error_php_too_low';
485
+	}
462 486
 	// Make sure we have a supported database
463
-	elseif (empty($incontext['supported_databases']))
464
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
487
+	elseif (empty($incontext['supported_databases'])) {
488
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
489
+	}
465 490
 	// How about session support?  Some crazy sysadmin remove it?
466
-	elseif (!function_exists('session_start'))
467
-		$error = 'error_session_missing';
491
+	elseif (!function_exists('session_start')) {
492
+			$error = 'error_session_missing';
493
+	}
468 494
 	// Make sure they uploaded all the files.
469
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
470
-		$error = 'error_missing_files';
495
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
496
+			$error = 'error_missing_files';
497
+	}
471 498
 	// Very simple check on the session.save_path for Windows.
472 499
 	// @todo Move this down later if they don't use database-driven sessions?
473
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
474
-		$error = 'error_session_save_path';
500
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
501
+			$error = 'error_session_save_path';
502
+	}
475 503
 
476 504
 	// Since each of the three messages would look the same, anyway...
477
-	if (isset($error))
478
-		$incontext['error'] = $txt[$error];
505
+	if (isset($error)) {
506
+			$incontext['error'] = $txt[$error];
507
+	}
479 508
 
480 509
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
481
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
482
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
510
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
511
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
512
+	}
483 513
 
484 514
 	// Confirm mbstring is loaded...
485
-	if (!extension_loaded('mbstring'))
486
-		$incontext['error'] = $txt['install_no_mbstring'];
515
+	if (!extension_loaded('mbstring')) {
516
+			$incontext['error'] = $txt['install_no_mbstring'];
517
+	}
487 518
 
488 519
 	// Check for https stream support.
489 520
 	$supported_streams = stream_get_wrappers();
490
-	if (!in_array('https', $supported_streams))
491
-		$incontext['warning'] = $txt['install_no_https'];
521
+	if (!in_array('https', $supported_streams)) {
522
+			$incontext['warning'] = $txt['install_no_https'];
523
+	}
492 524
 
493 525
 	return false;
494 526
 }
@@ -514,12 +546,14 @@  discard block
 block discarded – undo
514 546
 		'db_last_error.php',
515 547
 	);
516 548
 
517
-	foreach ($incontext['detected_languages'] as $lang => $temp)
518
-		$extra_files[] = 'Themes/default/languages/' . $lang;
549
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
550
+			$extra_files[] = 'Themes/default/languages/' . $lang;
551
+	}
519 552
 
520 553
 	// With mod_security installed, we could attempt to fix it with .htaccess.
521
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
522
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
554
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
555
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
556
+	}
523 557
 
524 558
 	$failed_files = array();
525 559
 
@@ -535,12 +569,14 @@  discard block
 block discarded – undo
535 569
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
536 570
 
537 571
 				// Well, 755 hopefully worked... if not, try 777.
538
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
539
-					$failed_files[] = $file;
572
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
573
+									$failed_files[] = $file;
574
+				}
540 575
 			}
541 576
 		}
542
-		foreach ($extra_files as $file)
543
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
577
+		foreach ($extra_files as $file) {
578
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
579
+		}
544 580
 	}
545 581
 	// Windows is trickier.  Let's try opening for r+...
546 582
 	else
@@ -550,30 +586,35 @@  discard block
 block discarded – undo
550 586
 		foreach ($writable_files as $file)
551 587
 		{
552 588
 			// Folders can't be opened for write... but the index.php in them can ;)
553
-			if (is_dir(dirname(__FILE__) . '/' . $file))
554
-				$file .= '/index.php';
589
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
590
+							$file .= '/index.php';
591
+			}
555 592
 
556 593
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
557 594
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
558 595
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
559 596
 
560 597
 			// Hmm, okay, try just for write in that case...
561
-			if (!is_resource($fp))
562
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
598
+			if (!is_resource($fp)) {
599
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
600
+			}
563 601
 
564
-			if (!is_resource($fp))
565
-				$failed_files[] = $file;
602
+			if (!is_resource($fp)) {
603
+							$failed_files[] = $file;
604
+			}
566 605
 
567 606
 			@fclose($fp);
568 607
 		}
569
-		foreach ($extra_files as $file)
570
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
608
+		foreach ($extra_files as $file) {
609
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
610
+		}
571 611
 	}
572 612
 
573 613
 	$failure = count($failed_files) >= 1;
574 614
 
575
-	if (!isset($_SERVER))
576
-		return !$failure;
615
+	if (!isset($_SERVER)) {
616
+			return !$failure;
617
+	}
577 618
 
578 619
 	// Put the list into context.
579 620
 	$incontext['failed_files'] = $failed_files;
@@ -621,19 +662,23 @@  discard block
 block discarded – undo
621 662
 
622 663
 		if (!isset($ftp) || $ftp->error !== false)
623 664
 		{
624
-			if (!isset($ftp))
625
-				$ftp = new ftp_connection(null);
665
+			if (!isset($ftp)) {
666
+							$ftp = new ftp_connection(null);
667
+			}
626 668
 			// Save the error so we can mess with listing...
627
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
628
-				$incontext['ftp_errors'][] = $ftp->last_message;
669
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
670
+							$incontext['ftp_errors'][] = $ftp->last_message;
671
+			}
629 672
 
630 673
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
631 674
 
632
-			if (empty($_POST['ftp_path']) && $found_path)
633
-				$_POST['ftp_path'] = $detect_path;
675
+			if (empty($_POST['ftp_path']) && $found_path) {
676
+							$_POST['ftp_path'] = $detect_path;
677
+			}
634 678
 
635
-			if (!isset($_POST['ftp_username']))
636
-				$_POST['ftp_username'] = $username;
679
+			if (!isset($_POST['ftp_username'])) {
680
+							$_POST['ftp_username'] = $username;
681
+			}
637 682
 
638 683
 			// Set the username etc, into context.
639 684
 			$incontext['ftp'] = array(
@@ -645,8 +690,7 @@  discard block
 block discarded – undo
645 690
 			);
646 691
 
647 692
 			return false;
648
-		}
649
-		else
693
+		} else
650 694
 		{
651 695
 			$_SESSION['installer_temp_ftp'] = array(
652 696
 				'server' => $_POST['ftp_server'],
@@ -660,10 +704,12 @@  discard block
 block discarded – undo
660 704
 
661 705
 			foreach ($failed_files as $file)
662 706
 			{
663
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
664
-					$ftp->chmod($file, 0755);
665
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
666
-					$ftp->chmod($file, 0777);
707
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
708
+									$ftp->chmod($file, 0755);
709
+				}
710
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
711
+									$ftp->chmod($file, 0777);
712
+				}
667 713
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
668 714
 				{
669 715
 					$failed_files_updated[] = $file;
@@ -719,15 +765,17 @@  discard block
 block discarded – undo
719 765
 
720 766
 			if (!$foundOne)
721 767
 			{
722
-				if (isset($db['default_host']))
723
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
768
+				if (isset($db['default_host'])) {
769
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
770
+				}
724 771
 				if (isset($db['default_user']))
725 772
 				{
726 773
 					$incontext['db']['user'] = ini_get($db['default_user']);
727 774
 					$incontext['db']['name'] = ini_get($db['default_user']);
728 775
 				}
729
-				if (isset($db['default_password']))
730
-					$incontext['db']['pass'] = ini_get($db['default_password']);
776
+				if (isset($db['default_password'])) {
777
+									$incontext['db']['pass'] = ini_get($db['default_password']);
778
+				}
731 779
 
732 780
 				// For simplicity and less confusion, leave the port blank by default
733 781
 				$incontext['db']['port'] = '';
@@ -746,10 +794,10 @@  discard block
 block discarded – undo
746 794
 		$incontext['db']['server'] = $_POST['db_server'];
747 795
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
748 796
 
749
-		if (!empty($_POST['db_port']))
750
-			$incontext['db']['port'] = $_POST['db_port'];
751
-	}
752
-	else
797
+		if (!empty($_POST['db_port'])) {
798
+					$incontext['db']['port'] = $_POST['db_port'];
799
+		}
800
+	} else
753 801
 	{
754 802
 		$incontext['db']['prefix'] = 'smf_';
755 803
 	}
@@ -785,10 +833,11 @@  discard block
 block discarded – undo
785 833
 		if (!empty($_POST['db_port']))
786 834
 		{
787 835
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
788
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
789
-				$vars['db_port'] = (int) $_POST['db_port'];
790
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
791
-				$vars['db_port'] = (int) $_POST['db_port'];
836
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
837
+							$vars['db_port'] = (int) $_POST['db_port'];
838
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
839
+							$vars['db_port'] = (int) $_POST['db_port'];
840
+			}
792 841
 		}
793 842
 
794 843
 		// God I hope it saved!
@@ -801,8 +850,9 @@  discard block
 block discarded – undo
801 850
 		// Make sure it works.
802 851
 		require(dirname(__FILE__) . '/Settings.php');
803 852
 
804
-		if (empty($sourcedir))
805
-			$sourcedir = dirname(__FILE__) . '/Sources';
853
+		if (empty($sourcedir)) {
854
+					$sourcedir = dirname(__FILE__) . '/Sources';
855
+		}
806 856
 
807 857
 		// Better find the database file!
808 858
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -812,18 +862,21 @@  discard block
 block discarded – undo
812 862
 		}
813 863
 
814 864
 		// Now include it for database functions!
815
-		if (!defined('SMF'))
816
-			define('SMF', 1);
865
+		if (!defined('SMF')) {
866
+					define('SMF', 1);
867
+		}
817 868
 
818 869
 		$modSettings['disableQueryCheck'] = true;
819
-		if (empty($smcFunc))
820
-			$smcFunc = array();
870
+		if (empty($smcFunc)) {
871
+					$smcFunc = array();
872
+		}
821 873
 
822 874
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
823 875
 
824 876
 		// What - running PHP4? The shame!
825
-		if (version_compare(PHP_VERSION, '5', '<'))
826
-			require_once($sourcedir . '/Subs-Compat.php');
877
+		if (version_compare(PHP_VERSION, '5', '<')) {
878
+					require_once($sourcedir . '/Subs-Compat.php');
879
+		}
827 880
 
828 881
 		// Attempt a connection.
829 882
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -911,12 +964,14 @@  discard block
 block discarded – undo
911 964
 	$incontext['page_title'] = $txt['install_settings'];
912 965
 
913 966
 	// Let's see if we got the database type correct.
914
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
915
-		$db_type = $_POST['db_type'];
967
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
968
+			$db_type = $_POST['db_type'];
969
+	}
916 970
 
917 971
 	// Else we'd better be able to get the connection.
918
-	else
919
-		load_database();
972
+	else {
973
+			load_database();
974
+	}
920 975
 
921 976
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
922 977
 
@@ -936,12 +991,14 @@  discard block
 block discarded – undo
936 991
 	// Submitting?
937 992
 	if (isset($_POST['boardurl']))
938 993
 	{
939
-		if (substr($_POST['boardurl'], -10) == '/index.php')
940
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
941
-		elseif (substr($_POST['boardurl'], -1) == '/')
942
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
943
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
944
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
994
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
995
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
996
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
997
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
998
+		}
999
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1000
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1001
+		}
945 1002
 
946 1003
 		// Save these variables.
947 1004
 		$vars = array(
@@ -980,10 +1037,10 @@  discard block
 block discarded – undo
980 1037
 			{
981 1038
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
982 1039
 				return false;
983
-			}
984
-			else
985
-				// Set the character set here.
1040
+			} else {
1041
+							// Set the character set here.
986 1042
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1043
+			}
987 1044
 		}
988 1045
 
989 1046
 		// Good, skip on.
@@ -1003,8 +1060,9 @@  discard block
 block discarded – undo
1003 1060
 	$incontext['continue'] = 1;
1004 1061
 
1005 1062
 	// Already done?
1006
-	if (isset($_POST['pop_done']))
1007
-		return true;
1063
+	if (isset($_POST['pop_done'])) {
1064
+			return true;
1065
+	}
1008 1066
 
1009 1067
 	// Reload settings.
1010 1068
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1022,8 +1080,9 @@  discard block
 block discarded – undo
1022 1080
 	$modSettings = array();
1023 1081
 	if ($result !== false)
1024 1082
 	{
1025
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1026
-			$modSettings[$row['variable']] = $row['value'];
1083
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1084
+					$modSettings[$row['variable']] = $row['value'];
1085
+		}
1027 1086
 		$smcFunc['db_free_result']($result);
1028 1087
 
1029 1088
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1036,20 +1095,22 @@  discard block
 block discarded – undo
1036 1095
 	$modSettings['disableQueryCheck'] = true;
1037 1096
 
1038 1097
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1039
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1040
-		$smcFunc['db_query']('', '
1098
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1099
+			$smcFunc['db_query']('', '
1041 1100
 			SET NAMES {string:utf8}',
1042 1101
 			array(
1043 1102
 				'db_error_skip' => true,
1044 1103
 				'utf8' => 'utf8',
1045 1104
 			)
1046 1105
 		);
1106
+	}
1047 1107
 
1048 1108
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1049
-	if (substr(__DIR__, -1) == '\\')
1050
-		$attachdir = __DIR__ . 'attachments';
1051
-	else
1052
-		$attachdir = __DIR__ . '/attachments';
1109
+	if (substr(__DIR__, -1) == '\\') {
1110
+			$attachdir = __DIR__ . 'attachments';
1111
+	} else {
1112
+			$attachdir = __DIR__ . '/attachments';
1113
+	}
1053 1114
 
1054 1115
 	$replaces = array(
1055 1116
 		'{$db_prefix}' => $db_prefix,
@@ -1066,8 +1127,9 @@  discard block
 block discarded – undo
1066 1127
 
1067 1128
 	foreach ($txt as $key => $value)
1068 1129
 	{
1069
-		if (substr($key, 0, 8) == 'default_')
1070
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1130
+		if (substr($key, 0, 8) == 'default_') {
1131
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1132
+		}
1071 1133
 	}
1072 1134
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1073 1135
 
@@ -1082,8 +1144,9 @@  discard block
 block discarded – undo
1082 1144
 
1083 1145
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1084 1146
 		{
1085
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1086
-				$engines[] = $row['Engine'];
1147
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1148
+							$engines[] = $row['Engine'];
1149
+			}
1087 1150
 		}
1088 1151
 
1089 1152
 		// Done with this now
@@ -1107,8 +1170,7 @@  discard block
 block discarded – undo
1107 1170
 			$replaces['START TRANSACTION;'] = '';
1108 1171
 			$replaces['COMMIT;'] = '';
1109 1172
 		}
1110
-	}
1111
-	else
1173
+	} else
1112 1174
 	{
1113 1175
 		$has_innodb = false;
1114 1176
 	}
@@ -1130,21 +1192,24 @@  discard block
 block discarded – undo
1130 1192
 	foreach ($sql_lines as $count => $line)
1131 1193
 	{
1132 1194
 		// No comments allowed!
1133
-		if (substr(trim($line), 0, 1) != '#')
1134
-			$current_statement .= "\n" . rtrim($line);
1195
+		if (substr(trim($line), 0, 1) != '#') {
1196
+					$current_statement .= "\n" . rtrim($line);
1197
+		}
1135 1198
 
1136 1199
 		// Is this the end of the query string?
1137
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1138
-			continue;
1200
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1201
+					continue;
1202
+		}
1139 1203
 
1140 1204
 		// Does this table already exist?  If so, don't insert more data into it!
1141 1205
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1142 1206
 		{
1143 1207
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1144
-			if (!empty($matches[0]))
1145
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1146
-			else
1147
-				$incontext['sql_results']['insert_dups']++;
1208
+			if (!empty($matches[0])) {
1209
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1210
+			} else {
1211
+							$incontext['sql_results']['insert_dups']++;
1212
+			}
1148 1213
 
1149 1214
 			$current_statement = '';
1150 1215
 			continue;
@@ -1153,8 +1218,9 @@  discard block
 block discarded – undo
1153 1218
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1154 1219
 		{
1155 1220
 			// Use the appropriate function based on the DB type
1156
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1157
-				$db_errorno = $db_type . '_errno';
1221
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1222
+							$db_errorno = $db_type . '_errno';
1223
+			}
1158 1224
 
1159 1225
 			// Error 1050: Table already exists!
1160 1226
 			// @todo Needs to be made better!
@@ -1169,18 +1235,18 @@  discard block
 block discarded – undo
1169 1235
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1170 1236
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1171 1237
 			}
1172
-		}
1173
-		else
1238
+		} else
1174 1239
 		{
1175
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1176
-				$incontext['sql_results']['tables']++;
1177
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1240
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1241
+							$incontext['sql_results']['tables']++;
1242
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1178 1243
 			{
1179 1244
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1180
-				if (!empty($matches[0]))
1181
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1182
-				else
1183
-					$incontext['sql_results']['inserts']++;
1245
+				if (!empty($matches[0])) {
1246
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1247
+				} else {
1248
+									$incontext['sql_results']['inserts']++;
1249
+				}
1184 1250
 			}
1185 1251
 		}
1186 1252
 
@@ -1193,15 +1259,17 @@  discard block
 block discarded – undo
1193 1259
 	// Sort out the context for the SQL.
1194 1260
 	foreach ($incontext['sql_results'] as $key => $number)
1195 1261
 	{
1196
-		if ($number == 0)
1197
-			unset($incontext['sql_results'][$key]);
1198
-		else
1199
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1262
+		if ($number == 0) {
1263
+					unset($incontext['sql_results'][$key]);
1264
+		} else {
1265
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1266
+		}
1200 1267
 	}
1201 1268
 
1202 1269
 	// Make sure UTF will be used globally.
1203
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1204
-		$newSettings[] = array('global_character_set', 'UTF-8');
1270
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1271
+			$newSettings[] = array('global_character_set', 'UTF-8');
1272
+	}
1205 1273
 
1206 1274
 	// Maybe we can auto-detect better cookie settings?
1207 1275
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1212,16 +1280,20 @@  discard block
 block discarded – undo
1212 1280
 		$globalCookies = false;
1213 1281
 
1214 1282
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1215
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1216
-			$globalCookies = true;
1283
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1284
+					$globalCookies = true;
1285
+		}
1217 1286
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1218
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1219
-			$localCookies = true;
1287
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1288
+					$localCookies = true;
1289
+		}
1220 1290
 
1221
-		if ($globalCookies)
1222
-			$newSettings[] = array('globalCookies', '1');
1223
-		if ($localCookies)
1224
-			$newSettings[] = array('localCookies', '1');
1291
+		if ($globalCookies) {
1292
+					$newSettings[] = array('globalCookies', '1');
1293
+		}
1294
+		if ($localCookies) {
1295
+					$newSettings[] = array('localCookies', '1');
1296
+		}
1225 1297
 	}
1226 1298
 
1227 1299
 	// Are we allowing stat collection?
@@ -1239,16 +1311,17 @@  discard block
 block discarded – undo
1239 1311
 			fwrite($fp, $out);
1240 1312
 
1241 1313
 			$return_data = '';
1242
-			while (!feof($fp))
1243
-				$return_data .= fgets($fp, 128);
1314
+			while (!feof($fp)) {
1315
+							$return_data .= fgets($fp, 128);
1316
+			}
1244 1317
 
1245 1318
 			fclose($fp);
1246 1319
 
1247 1320
 			// Get the unique site ID.
1248 1321
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1249 1322
 
1250
-			if (!empty($ID[1]))
1251
-				$smcFunc['db_insert']('replace',
1323
+			if (!empty($ID[1])) {
1324
+							$smcFunc['db_insert']('replace',
1252 1325
 					$db_prefix . 'settings',
1253 1326
 					array('variable' => 'string', 'value' => 'string'),
1254 1327
 					array(
@@ -1257,11 +1330,12 @@  discard block
 block discarded – undo
1257 1330
 					),
1258 1331
 					array('variable')
1259 1332
 				);
1333
+			}
1260 1334
 		}
1261 1335
 	}
1262 1336
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1263
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1264
-		$smcFunc['db_query']('', '
1337
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1338
+			$smcFunc['db_query']('', '
1265 1339
 			DELETE FROM {db_prefix}settings
1266 1340
 			WHERE variable = {string:enable_sm_stats}',
1267 1341
 			array(
@@ -1269,20 +1343,23 @@  discard block
 block discarded – undo
1269 1343
 				'db_error_skip' => true,
1270 1344
 			)
1271 1345
 		);
1346
+	}
1272 1347
 
1273 1348
 	// Are we enabling SSL?
1274
-	if (!empty($_POST['force_ssl']))
1275
-		$newSettings[] = array('force_ssl', 2);
1349
+	if (!empty($_POST['force_ssl'])) {
1350
+			$newSettings[] = array('force_ssl', 2);
1351
+	}
1276 1352
 
1277 1353
 	// Setting a timezone is required.
1278 1354
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1279 1355
 	{
1280 1356
 		// Get PHP's default timezone, if set
1281 1357
 		$ini_tz = ini_get('date.timezone');
1282
-		if (!empty($ini_tz))
1283
-			$timezone_id = $ini_tz;
1284
-		else
1285
-			$timezone_id = '';
1358
+		if (!empty($ini_tz)) {
1359
+					$timezone_id = $ini_tz;
1360
+		} else {
1361
+					$timezone_id = '';
1362
+		}
1286 1363
 
1287 1364
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1288 1365
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1291,8 +1368,9 @@  discard block
 block discarded – undo
1291 1368
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1292 1369
 		}
1293 1370
 
1294
-		if (date_default_timezone_set($timezone_id))
1295
-			$newSettings[] = array('default_timezone', $timezone_id);
1371
+		if (date_default_timezone_set($timezone_id)) {
1372
+					$newSettings[] = array('default_timezone', $timezone_id);
1373
+		}
1296 1374
 	}
1297 1375
 
1298 1376
 	if (!empty($newSettings))
@@ -1323,16 +1401,18 @@  discard block
 block discarded – undo
1323 1401
 	}
1324 1402
 
1325 1403
 	// MySQL specific stuff
1326
-	if (substr($db_type, 0, 5) != 'mysql')
1327
-		return false;
1404
+	if (substr($db_type, 0, 5) != 'mysql') {
1405
+			return false;
1406
+	}
1328 1407
 
1329 1408
 	// Find database user privileges.
1330 1409
 	$privs = array();
1331 1410
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1332 1411
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1333 1412
 	{
1334
-		if ($row['Privilege'] == 'Alter')
1335
-			$privs[] = $row['Privilege'];
1413
+		if ($row['Privilege'] == 'Alter') {
1414
+					$privs[] = $row['Privilege'];
1415
+		}
1336 1416
 	}
1337 1417
 	$smcFunc['db_free_result']($get_privs);
1338 1418
 
@@ -1362,8 +1442,9 @@  discard block
 block discarded – undo
1362 1442
 	$incontext['continue'] = 1;
1363 1443
 
1364 1444
 	// Skipping?
1365
-	if (!empty($_POST['skip']))
1366
-		return true;
1445
+	if (!empty($_POST['skip'])) {
1446
+			return true;
1447
+	}
1367 1448
 
1368 1449
 	// Need this to check whether we need the database password.
1369 1450
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1380,18 +1461,22 @@  discard block
 block discarded – undo
1380 1461
 	// We need this to properly hash the password for Admin
1381 1462
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1382 1463
 			global $sourcedir;
1383
-			if (function_exists('mb_strtolower'))
1384
-				return mb_strtolower($string, 'UTF-8');
1464
+			if (function_exists('mb_strtolower')) {
1465
+							return mb_strtolower($string, 'UTF-8');
1466
+			}
1385 1467
 			require_once($sourcedir . '/Subs-Charset.php');
1386 1468
 			return utf8_strtolower($string);
1387 1469
 		};
1388 1470
 
1389
-	if (!isset($_POST['username']))
1390
-		$_POST['username'] = '';
1391
-	if (!isset($_POST['email']))
1392
-		$_POST['email'] = '';
1393
-	if (!isset($_POST['server_email']))
1394
-		$_POST['server_email'] = '';
1471
+	if (!isset($_POST['username'])) {
1472
+			$_POST['username'] = '';
1473
+	}
1474
+	if (!isset($_POST['email'])) {
1475
+			$_POST['email'] = '';
1476
+	}
1477
+	if (!isset($_POST['server_email'])) {
1478
+			$_POST['server_email'] = '';
1479
+	}
1395 1480
 
1396 1481
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1397 1482
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1410,8 +1495,9 @@  discard block
 block discarded – undo
1410 1495
 			'admin_group' => 1,
1411 1496
 		)
1412 1497
 	);
1413
-	if ($smcFunc['db_num_rows']($request) != 0)
1414
-		$incontext['skip'] = 1;
1498
+	if ($smcFunc['db_num_rows']($request) != 0) {
1499
+			$incontext['skip'] = 1;
1500
+	}
1415 1501
 	$smcFunc['db_free_result']($request);
1416 1502
 
1417 1503
 	// Trying to create an account?
@@ -1442,8 +1528,9 @@  discard block
 block discarded – undo
1442 1528
 		}
1443 1529
 
1444 1530
 		// Update the webmaster's email?
1445
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1446
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1531
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1532
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1533
+		}
1447 1534
 
1448 1535
 		// Work out whether we're going to have dodgy characters and remove them.
1449 1536
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1466,32 +1553,27 @@  discard block
 block discarded – undo
1466 1553
 			$smcFunc['db_free_result']($result);
1467 1554
 
1468 1555
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1469
-		}
1470
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1556
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1471 1557
 		{
1472 1558
 			// Try the previous step again.
1473 1559
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1474 1560
 			return false;
1475
-		}
1476
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1561
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1477 1562
 		{
1478 1563
 			// Try the previous step again.
1479 1564
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1480 1565
 			return false;
1481
-		}
1482
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1566
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1483 1567
 		{
1484 1568
 			// One step back, this time fill out a proper admin email address.
1485 1569
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1486 1570
 			return false;
1487
-		}
1488
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1571
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1489 1572
 		{
1490 1573
 			// One step back, this time fill out a proper admin email address.
1491 1574
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1492 1575
 			return false;
1493
-		}
1494
-		elseif ($_POST['username'] != '')
1576
+		} elseif ($_POST['username'] != '')
1495 1577
 		{
1496 1578
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1497 1579
 
@@ -1559,17 +1641,19 @@  discard block
 block discarded – undo
1559 1641
 	reloadSettings();
1560 1642
 
1561 1643
 	// Bring a warning over.
1562
-	if (!empty($incontext['account_existed']))
1563
-		$incontext['warning'] = $incontext['account_existed'];
1644
+	if (!empty($incontext['account_existed'])) {
1645
+			$incontext['warning'] = $incontext['account_existed'];
1646
+	}
1564 1647
 
1565
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1566
-		$smcFunc['db_query']('', '
1648
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1649
+			$smcFunc['db_query']('', '
1567 1650
 			SET NAMES {string:db_character_set}',
1568 1651
 			array(
1569 1652
 				'db_character_set' => $db_character_set,
1570 1653
 				'db_error_skip' => true,
1571 1654
 			)
1572 1655
 		);
1656
+	}
1573 1657
 
1574 1658
 	// As track stats is by default enabled let's add some activity.
1575 1659
 	$smcFunc['db_insert']('ignore',
@@ -1590,14 +1674,16 @@  discard block
 block discarded – undo
1590 1674
 	// Only proceed if we can load the data.
1591 1675
 	if ($request)
1592 1676
 	{
1593
-		while ($row = $smcFunc['db_fetch_row']($request))
1594
-			$modSettings[$row[0]] = $row[1];
1677
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1678
+					$modSettings[$row[0]] = $row[1];
1679
+		}
1595 1680
 		$smcFunc['db_free_result']($request);
1596 1681
 	}
1597 1682
 
1598 1683
 	// Automatically log them in ;)
1599
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1600
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1684
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1685
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1686
+	}
1601 1687
 
1602 1688
 	$result = $smcFunc['db_query']('', '
1603 1689
 		SELECT value
@@ -1608,13 +1694,14 @@  discard block
 block discarded – undo
1608 1694
 			'db_error_skip' => true,
1609 1695
 		)
1610 1696
 	);
1611
-	if ($smcFunc['db_num_rows']($result) != 0)
1612
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1697
+	if ($smcFunc['db_num_rows']($result) != 0) {
1698
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1699
+	}
1613 1700
 	$smcFunc['db_free_result']($result);
1614 1701
 
1615
-	if (empty($db_sessions))
1616
-		$_SESSION['admin_time'] = time();
1617
-	else
1702
+	if (empty($db_sessions)) {
1703
+			$_SESSION['admin_time'] = time();
1704
+	} else
1618 1705
 	{
1619 1706
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1620 1707
 
@@ -1638,8 +1725,9 @@  discard block
 block discarded – undo
1638 1725
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1639 1726
 		function($string){
1640 1727
 			global $sourcedir;
1641
-			if (function_exists('mb_strtolower'))
1642
-				return mb_strtolower($string, 'UTF-8');
1728
+			if (function_exists('mb_strtolower')) {
1729
+							return mb_strtolower($string, 'UTF-8');
1730
+			}
1643 1731
 			require_once($sourcedir . '/Subs-Charset.php');
1644 1732
 			return utf8_strtolower($string);
1645 1733
 		};
@@ -1655,8 +1743,9 @@  discard block
 block discarded – undo
1655 1743
 		)
1656 1744
 	);
1657 1745
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1658
-	if ($smcFunc['db_num_rows']($request) > 0)
1659
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1746
+	if ($smcFunc['db_num_rows']($request) > 0) {
1747
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1748
+	}
1660 1749
 	$smcFunc['db_free_result']($request);
1661 1750
 
1662 1751
 	// Now is the perfect time to fetch the SM files.
@@ -1675,8 +1764,9 @@  discard block
 block discarded – undo
1675 1764
 
1676 1765
 	// Check if we need some stupid MySQL fix.
1677 1766
 	$server_version = $smcFunc['db_server_info']();
1678
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1679
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1767
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1768
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1769
+	}
1680 1770
 
1681 1771
 	// Some final context for the template.
1682 1772
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1696,8 +1786,9 @@  discard block
 block discarded – undo
1696 1786
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1697 1787
 
1698 1788
 	// @todo Do we just want to read the file in clean, and split it this way always?
1699
-	if (count($settingsArray) == 1)
1700
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1789
+	if (count($settingsArray) == 1) {
1790
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1791
+	}
1701 1792
 
1702 1793
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1703 1794
 	{
@@ -1712,19 +1803,22 @@  discard block
 block discarded – undo
1712 1803
 			continue;
1713 1804
 		}
1714 1805
 
1715
-		if (trim($settingsArray[$i]) == '?' . '>')
1716
-			$settingsArray[$i] = '';
1806
+		if (trim($settingsArray[$i]) == '?' . '>') {
1807
+					$settingsArray[$i] = '';
1808
+		}
1717 1809
 
1718 1810
 		// Don't trim or bother with it if it's not a variable.
1719
-		if (substr($settingsArray[$i], 0, 1) != '$')
1720
-			continue;
1811
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1812
+					continue;
1813
+		}
1721 1814
 
1722 1815
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1723 1816
 
1724
-		foreach ($vars as $var => $val)
1725
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1817
+		foreach ($vars as $var => $val) {
1818
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1726 1819
 			{
1727 1820
 				$comment = strstr($settingsArray[$i], '#');
1821
+		}
1728 1822
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1729 1823
 				unset($vars[$var]);
1730 1824
 			}
@@ -1734,36 +1828,41 @@  discard block
 block discarded – undo
1734 1828
 	if (!empty($vars))
1735 1829
 	{
1736 1830
 		$settingsArray[$i++] = '';
1737
-		foreach ($vars as $var => $val)
1738
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1831
+		foreach ($vars as $var => $val) {
1832
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1833
+		}
1739 1834
 	}
1740 1835
 
1741 1836
 	// Blank out the file - done to fix a oddity with some servers.
1742 1837
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1743
-	if (!$fp)
1744
-		return false;
1838
+	if (!$fp) {
1839
+			return false;
1840
+	}
1745 1841
 	fclose($fp);
1746 1842
 
1747 1843
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1748 1844
 
1749 1845
 	// Gotta have one of these ;)
1750
-	if (trim($settingsArray[0]) != '<?php')
1751
-		fwrite($fp, "<?php\n");
1846
+	if (trim($settingsArray[0]) != '<?php') {
1847
+			fwrite($fp, "<?php\n");
1848
+	}
1752 1849
 
1753 1850
 	$lines = count($settingsArray);
1754 1851
 	for ($i = 0; $i < $lines - 1; $i++)
1755 1852
 	{
1756 1853
 		// Don't just write a bunch of blank lines.
1757
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1758
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1854
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1855
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1856
+		}
1759 1857
 	}
1760 1858
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1761 1859
 	fclose($fp);
1762 1860
 
1763 1861
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1764 1862
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1765
-	if (function_exists('opcache_invalidate'))
1766
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1863
+	if (function_exists('opcache_invalidate')) {
1864
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1865
+	}
1767 1866
 
1768 1867
 	return true;
1769 1868
 }
@@ -1788,9 +1887,9 @@  discard block
 block discarded – undo
1788 1887
 	SecFilterScanPOST Off
1789 1888
 </IfModule>';
1790 1889
 
1791
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1792
-		return true;
1793
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1890
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1891
+			return true;
1892
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1794 1893
 	{
1795 1894
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1796 1895
 
@@ -1802,29 +1901,28 @@  discard block
 block discarded – undo
1802 1901
 				fwrite($ht_handle, $htaccess_addition);
1803 1902
 				fclose($ht_handle);
1804 1903
 				return true;
1904
+			} else {
1905
+							return false;
1805 1906
 			}
1806
-			else
1807
-				return false;
1907
+		} else {
1908
+					return true;
1808 1909
 		}
1809
-		else
1810
-			return true;
1811
-	}
1812
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1813
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1814
-	elseif (is_writable(dirname(__FILE__)))
1910
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1911
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1912
+	} elseif (is_writable(dirname(__FILE__)))
1815 1913
 	{
1816 1914
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1817 1915
 		{
1818 1916
 			fwrite($ht_handle, $htaccess_addition);
1819 1917
 			fclose($ht_handle);
1820 1918
 			return true;
1919
+		} else {
1920
+					return false;
1821 1921
 		}
1822
-		else
1922
+	} else {
1823 1923
 			return false;
1824 1924
 	}
1825
-	else
1826
-		return false;
1827
-}
1925
+	}
1828 1926
 
1829 1927
 function template_install_above()
1830 1928
 {
@@ -1862,9 +1960,10 @@  discard block
 block discarded – undo
1862 1960
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1863 1961
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1864 1962
 
1865
-		foreach ($incontext['detected_languages'] as $lang => $name)
1866
-			echo '
1963
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1964
+					echo '
1867 1965
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1966
+		}
1868 1967
 
1869 1968
 		echo '
1870 1969
 								</select>
@@ -1884,9 +1983,10 @@  discard block
 block discarded – undo
1884 1983
 						<h2>', $txt['upgrade_progress'], '</h2>
1885 1984
 						<ul>';
1886 1985
 
1887
-	foreach ($incontext['steps'] as $num => $step)
1888
-		echo '
1986
+	foreach ($incontext['steps'] as $num => $step) {
1987
+			echo '
1889 1988
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1989
+	}
1890 1990
 
1891 1991
 	echo '
1892 1992
 						</ul>
@@ -1911,20 +2011,23 @@  discard block
 block discarded – undo
1911 2011
 		echo '
1912 2012
 								<div>';
1913 2013
 
1914
-		if (!empty($incontext['continue']))
1915
-			echo '
2014
+		if (!empty($incontext['continue'])) {
2015
+					echo '
1916 2016
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1917
-		if (!empty($incontext['skip']))
1918
-			echo '
2017
+		}
2018
+		if (!empty($incontext['skip'])) {
2019
+					echo '
1919 2020
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2021
+		}
1920 2022
 		echo '
1921 2023
 								</div>';
1922 2024
 	}
1923 2025
 
1924 2026
 	// Show the closing form tag and other data only if not in the last step
1925
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1926
-		echo '
2027
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2028
+			echo '
1927 2029
 							</form>';
2030
+	}
1928 2031
 
1929 2032
 	echo '
1930 2033
 						</div>
@@ -1959,13 +2062,15 @@  discard block
 block discarded – undo
1959 2062
 		</div>';
1960 2063
 
1961 2064
 	// Show the warnings, or not.
1962
-	if (template_warning_divs())
1963
-		echo '
2065
+	if (template_warning_divs()) {
2066
+			echo '
1964 2067
 		<h3>', $txt['install_all_lovely'], '</h3>';
2068
+	}
1965 2069
 
1966 2070
 	// Say we want the continue button!
1967
-	if (empty($incontext['error']))
1968
-		$incontext['continue'] = 1;
2071
+	if (empty($incontext['error'])) {
2072
+			$incontext['continue'] = 1;
2073
+	}
1969 2074
 
1970 2075
 	// For the latest version stuff.
1971 2076
 	echo '
@@ -1999,8 +2104,8 @@  discard block
 block discarded – undo
1999 2104
 	global $txt, $incontext;
2000 2105
 
2001 2106
 	// Errors are very serious..
2002
-	if (!empty($incontext['error']))
2003
-		echo '
2107
+	if (!empty($incontext['error'])) {
2108
+			echo '
2004 2109
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2005 2110
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2006 2111
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -2008,9 +2113,10 @@  discard block
 block discarded – undo
2008 2113
 				', $incontext['error'], '
2009 2114
 			</div>
2010 2115
 		</div>';
2116
+	}
2011 2117
 	// A warning message?
2012
-	elseif (!empty($incontext['warning']))
2013
-		echo '
2118
+	elseif (!empty($incontext['warning'])) {
2119
+			echo '
2014 2120
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2015 2121
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2016 2122
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2018,6 +2124,7 @@  discard block
 block discarded – undo
2018 2124
 				', $incontext['warning'], '
2019 2125
 			</div>
2020 2126
 		</div>';
2127
+	}
2021 2128
 
2022 2129
 	return empty($incontext['error']) && empty($incontext['warning']);
2023 2130
 }
@@ -2033,27 +2140,30 @@  discard block
 block discarded – undo
2033 2140
 			<li>', $incontext['failed_files']), '</li>
2034 2141
 		</ul>';
2035 2142
 
2036
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2037
-		echo '
2143
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2144
+			echo '
2038 2145
 		<hr>
2039 2146
 		<p>', $txt['chmod_linux_info'], '</p>
2040 2147
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2148
+	}
2041 2149
 
2042 2150
 	// This is serious!
2043
-	if (!template_warning_divs())
2044
-		return;
2151
+	if (!template_warning_divs()) {
2152
+			return;
2153
+	}
2045 2154
 
2046 2155
 	echo '
2047 2156
 		<hr>
2048 2157
 		<p>', $txt['ftp_setup_info'], '</p>';
2049 2158
 
2050
-	if (!empty($incontext['ftp_errors']))
2051
-		echo '
2159
+	if (!empty($incontext['ftp_errors'])) {
2160
+			echo '
2052 2161
 		<div class="error_message">
2053 2162
 			', $txt['error_ftp_no_connect'], '<br><br>
2054 2163
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2055 2164
 		</div>
2056 2165
 		<br>';
2166
+	}
2057 2167
 
2058 2168
 	echo '
2059 2169
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2113,17 +2223,17 @@  discard block
 block discarded – undo
2113 2223
 				<td>
2114 2224
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2115 2225
 
2116
-	foreach ($incontext['supported_databases'] as $key => $db)
2117
-			echo '
2226
+	foreach ($incontext['supported_databases'] as $key => $db) {
2227
+				echo '
2118 2228
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2229
+	}
2119 2230
 
2120 2231
 	echo '
2121 2232
 					</select>
2122 2233
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2123 2234
 				</td>
2124 2235
 			</tr>';
2125
-	}
2126
-	else
2236
+	} else
2127 2237
 	{
2128 2238
 		echo '
2129 2239
 			<tr style="display: none;">
@@ -2315,9 +2425,10 @@  discard block
 block discarded – undo
2315 2425
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2316 2426
 				<ul>';
2317 2427
 
2318
-		foreach ($incontext['failures'] as $line => $fail)
2319
-			echo '
2428
+		foreach ($incontext['failures'] as $line => $fail) {
2429
+					echo '
2320 2430
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2431
+		}
2321 2432
 
2322 2433
 		echo '
2323 2434
 				</ul>';
@@ -2378,15 +2489,16 @@  discard block
 block discarded – undo
2378 2489
 			</tr>
2379 2490
 		</table>';
2380 2491
 
2381
-	if ($incontext['require_db_confirm'])
2382
-		echo '
2492
+	if ($incontext['require_db_confirm']) {
2493
+			echo '
2383 2494
 		<h2>', $txt['user_settings_database'], '</h2>
2384 2495
 		<p>', $txt['user_settings_database_info'], '</p>
2385 2496
 
2386 2497
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2387 2498
 			<input type="password" name="password3" size="30" class="input_password" />
2388 2499
 		</div>';
2389
-}
2500
+	}
2501
+	}
2390 2502
 
2391 2503
 // Tell them it's done, and to delete.
2392 2504
 function template_delete_install()
@@ -2399,14 +2511,15 @@  discard block
 block discarded – undo
2399 2511
 	template_warning_divs();
2400 2512
 
2401 2513
 	// Install directory still writable?
2402
-	if ($incontext['dir_still_writable'])
2403
-		echo '
2514
+	if ($incontext['dir_still_writable']) {
2515
+			echo '
2404 2516
 		<em>', $txt['still_writable'], '</em><br>
2405 2517
 		<br>';
2518
+	}
2406 2519
 
2407 2520
 	// Don't show the box if it's like 99% sure it won't work :P.
2408
-	if ($incontext['probably_delete_install'])
2409
-		echo '
2521
+	if ($incontext['probably_delete_install']) {
2522
+			echo '
2410 2523
 		<div style="margin: 1ex; font-weight: bold;">
2411 2524
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2412 2525
 		</div>
@@ -2422,6 +2535,7 @@  discard block
 block discarded – undo
2422 2535
 			}
2423 2536
 		</script>
2424 2537
 		<br>';
2538
+	}
2425 2539
 
2426 2540
 	echo '
2427 2541
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +215 added lines, -157 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -157,8 +159,9 @@  discard block
 block discarded – undo
157 159
 	while ($row = $smcFunc['db_fetch_assoc']($result))
158 160
 	{
159 161
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
160
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
161
-			continue;
162
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
163
+					continue;
164
+		}
162 165
 
163 166
 		// Force a censor of the title - as often these are used by others.
164 167
 		censorText($row['title'], $use_permissions ? false : true);
@@ -167,8 +170,9 @@  discard block
 block discarded – undo
167 170
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
168 171
 
169 172
 		// Sanity check
170
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
171
-			continue;
173
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
174
+					continue;
175
+		}
172 176
 
173 177
 		// Get set up for the loop
174 178
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -232,8 +236,8 @@  discard block
 block discarded – undo
232 236
 			);
233 237
 
234 238
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
235
-			if ($use_permissions)
236
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
239
+			if ($use_permissions) {
240
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
237 241
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
238 242
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
239 243
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -241,9 +245,10 @@  discard block
 block discarded – undo
241 245
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
242 246
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
243 247
 				));
248
+			}
244 249
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
245
-			else
246
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
250
+			else {
251
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
247 252
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
248 253
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
249 254
 					'can_edit' => false,
@@ -253,6 +258,7 @@  discard block
 block discarded – undo
253 258
 					'poster' => $row['id_member'],
254 259
 					'allowed_groups' => explode(',', $row['member_groups']),
255 260
 				));
261
+			}
256 262
 
257 263
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
258 264
 		}
@@ -262,8 +268,9 @@  discard block
 block discarded – undo
262 268
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
263 269
 	if ($use_permissions)
264 270
 	{
265
-		foreach ($events as $mday => $array)
266
-			$events[$mday][count($array) - 1]['is_last'] = true;
271
+		foreach ($events as $mday => $array) {
272
+					$events[$mday][count($array) - 1]['is_last'] = true;
273
+		}
267 274
 	}
268 275
 
269 276
 	ksort($events);
@@ -283,11 +290,12 @@  discard block
 block discarded – undo
283 290
 	global $smcFunc;
284 291
 
285 292
 	// Get the lowest and highest dates for "all years".
286
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
287
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
293
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
294
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
288 295
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
289
-	else
290
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
296
+	} else {
297
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
298
+	}
291 299
 
292 300
 	// Find some holidays... ;).
293 301
 	$result = $smcFunc['db_query']('', '
@@ -307,10 +315,11 @@  discard block
 block discarded – undo
307 315
 	$holidays = array();
308 316
 	while ($row = $smcFunc['db_fetch_assoc']($result))
309 317
 	{
310
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
311
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
312
-		else
313
-			$event_year = substr($low_date, 0, 4);
318
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
319
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
320
+		} else {
321
+					$event_year = substr($low_date, 0, 4);
322
+		}
314 323
 
315 324
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
316 325
 	}
@@ -336,10 +345,12 @@  discard block
 block discarded – undo
336 345
 	isAllowedTo('calendar_post');
337 346
 
338 347
 	// No board?  No topic?!?
339
-	if (empty($board))
340
-		fatal_lang_error('missing_board_id', false);
341
-	if (empty($topic))
342
-		fatal_lang_error('missing_topic_id', false);
348
+	if (empty($board)) {
349
+			fatal_lang_error('missing_board_id', false);
350
+	}
351
+	if (empty($topic)) {
352
+			fatal_lang_error('missing_topic_id', false);
353
+	}
343 354
 
344 355
 	// Administrator, Moderator, or owner.  Period.
345 356
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -357,12 +368,14 @@  discard block
 block discarded – undo
357 368
 		if ($row = $smcFunc['db_fetch_assoc']($result))
358 369
 		{
359 370
 			// Not the owner of the topic.
360
-			if ($row['id_member_started'] != $user_info['id'])
361
-				fatal_lang_error('not_your_topic', 'user');
371
+			if ($row['id_member_started'] != $user_info['id']) {
372
+							fatal_lang_error('not_your_topic', 'user');
373
+			}
362 374
 		}
363 375
 		// Topic/Board doesn't exist.....
364
-		else
365
-			fatal_lang_error('calendar_no_topic', 'general');
376
+		else {
377
+					fatal_lang_error('calendar_no_topic', 'general');
378
+		}
366 379
 		$smcFunc['db_free_result']($result);
367 380
 	}
368 381
 }
@@ -450,14 +463,16 @@  discard block
 block discarded – undo
450 463
 	if (!empty($calendarOptions['start_day']))
451 464
 	{
452 465
 		$nShift -= $calendarOptions['start_day'];
453
-		if ($nShift < 0)
454
-			$nShift = 7 + $nShift;
466
+		if ($nShift < 0) {
467
+					$nShift = 7 + $nShift;
468
+		}
455 469
 	}
456 470
 
457 471
 	// Number of rows required to fit the month.
458 472
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
459
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
460
-		$nRows++;
473
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
474
+			$nRows++;
475
+	}
461 476
 
462 477
 	// Fetch the arrays for birthdays, posted events, and holidays.
463 478
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -470,8 +485,9 @@  discard block
 block discarded – undo
470 485
 	{
471 486
 		$calendarGrid['week_days'][] = $count;
472 487
 		$count++;
473
-		if ($count == 7)
474
-			$count = 0;
488
+		if ($count == 7) {
489
+					$count = 0;
490
+		}
475 491
 	}
476 492
 
477 493
 	// Iterate through each week.
@@ -488,8 +504,9 @@  discard block
 block discarded – undo
488 504
 		{
489 505
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
490 506
 
491
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
492
-				$nDay = 0;
507
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
508
+							$nDay = 0;
509
+			}
493 510
 
494 511
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
495 512
 
@@ -507,8 +524,9 @@  discard block
 block discarded – undo
507 524
 	}
508 525
 
509 526
 	// What is the last day of the month?
510
-	if ($is_previous === true)
511
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
527
+	if ($is_previous === true) {
528
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
529
+	}
512 530
 
513 531
 	// We'll use the shift in the template.
514 532
 	$calendarGrid['shift'] = $nShift;
@@ -542,8 +560,9 @@  discard block
 block discarded – undo
542 560
 	{
543 561
 		// Here we offset accordingly to get things to the real start of a week.
544 562
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
545
-		if ($date_diff < 0)
546
-			$date_diff += 7;
563
+		if ($date_diff < 0) {
564
+					$date_diff += 7;
565
+		}
547 566
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
548 567
 		$day = (int) strftime('%d', $new_timestamp);
549 568
 		$month = (int) strftime('%m', $new_timestamp);
@@ -673,18 +692,20 @@  discard block
 block discarded – undo
673 692
 	{
674 693
 		foreach ($date_events as $event_key => $event_val)
675 694
 		{
676
-			if (in_array($event_val['id'], $temp))
677
-				unset($calendarGrid['events'][$date][$event_key]);
678
-			else
679
-				$temp[] = $event_val['id'];
695
+			if (in_array($event_val['id'], $temp)) {
696
+							unset($calendarGrid['events'][$date][$event_key]);
697
+			} else {
698
+							$temp[] = $event_val['id'];
699
+			}
680 700
 		}
681 701
 	}
682 702
 
683 703
 	// Give birthdays and holidays a friendly format, without the year
684
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
685
-		$date_format = '%b %d';
686
-	else
687
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
704
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
705
+			$date_format = '%b %d';
706
+	} else {
707
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
708
+	}
688 709
 
689 710
 	foreach (array('birthdays', 'holidays') as $type)
690 711
 	{
@@ -779,8 +800,9 @@  discard block
 block discarded – undo
779 800
 	// Holidays between now and now + days.
780 801
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
781 802
 	{
782
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
783
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
803
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
804
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
805
+		}
784 806
 	}
785 807
 
786 808
 	// Happy Birthday, guys and gals!
@@ -789,8 +811,9 @@  discard block
 block discarded – undo
789 811
 		$loop_date = strftime('%Y-%m-%d', $i);
790 812
 		if (isset($cached_data['birthdays'][$loop_date]))
791 813
 		{
792
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
793
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
814
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
815
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
816
+			}
794 817
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
795 818
 		}
796 819
 	}
@@ -802,8 +825,9 @@  discard block
 block discarded – undo
802 825
 		$loop_date = strftime('%Y-%m-%d', $i);
803 826
 
804 827
 		// No events today? Check the next day.
805
-		if (empty($cached_data['events'][$loop_date]))
806
-			continue;
828
+		if (empty($cached_data['events'][$loop_date])) {
829
+					continue;
830
+		}
807 831
 
808 832
 		// Loop through all events to add a few last-minute values.
809 833
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -816,9 +840,9 @@  discard block
 block discarded – undo
816 840
 			{
817 841
 				unset($cached_data['events'][$loop_date][$ev]);
818 842
 				continue;
843
+			} else {
844
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
819 845
 			}
820
-			else
821
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
822 846
 
823 847
 			// Might be set to true afterwards, depending on the permissions.
824 848
 			$this_event['can_edit'] = false;
@@ -826,15 +850,18 @@  discard block
 block discarded – undo
826 850
 			$this_event['date'] = $loop_date;
827 851
 		}
828 852
 
829
-		if (!empty($cached_data['events'][$loop_date]))
830
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
853
+		if (!empty($cached_data['events'][$loop_date])) {
854
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
855
+		}
831 856
 	}
832 857
 
833 858
 	// Mark the last item so that a list separator can be used in the template.
834
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
835
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
836
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
837
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
859
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
860
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
861
+	}
862
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
863
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
864
+	}
838 865
 
839 866
 	return array(
840 867
 		'data' => $return_data,
@@ -882,37 +909,46 @@  discard block
 block discarded – undo
882 909
 		if (isset($_POST['start_date']))
883 910
 		{
884 911
 			$d = date_parse($_POST['start_date']);
885
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
886
-				fatal_lang_error('invalid_date', false);
887
-			if (empty($d['year']))
888
-				fatal_lang_error('event_year_missing', false);
889
-			if (empty($d['month']))
890
-				fatal_lang_error('event_month_missing', false);
891
-		}
892
-		elseif (isset($_POST['start_datetime']))
912
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
913
+							fatal_lang_error('invalid_date', false);
914
+			}
915
+			if (empty($d['year'])) {
916
+							fatal_lang_error('event_year_missing', false);
917
+			}
918
+			if (empty($d['month'])) {
919
+							fatal_lang_error('event_month_missing', false);
920
+			}
921
+		} elseif (isset($_POST['start_datetime']))
893 922
 		{
894 923
 			$d = date_parse($_POST['start_datetime']);
895
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
896
-				fatal_lang_error('invalid_date', false);
897
-			if (empty($d['year']))
898
-				fatal_lang_error('event_year_missing', false);
899
-			if (empty($d['month']))
900
-				fatal_lang_error('event_month_missing', false);
924
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
925
+							fatal_lang_error('invalid_date', false);
926
+			}
927
+			if (empty($d['year'])) {
928
+							fatal_lang_error('event_year_missing', false);
929
+			}
930
+			if (empty($d['month'])) {
931
+							fatal_lang_error('event_month_missing', false);
932
+			}
901 933
 		}
902 934
 		// The 2.0 way
903 935
 		else
904 936
 		{
905 937
 			// No month?  No year?
906
-			if (!isset($_POST['month']))
907
-				fatal_lang_error('event_month_missing', false);
908
-			if (!isset($_POST['year']))
909
-				fatal_lang_error('event_year_missing', false);
938
+			if (!isset($_POST['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+			if (!isset($_POST['year'])) {
942
+							fatal_lang_error('event_year_missing', false);
943
+			}
910 944
 
911 945
 			// Check the month and year...
912
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
913
-				fatal_lang_error('invalid_month', false);
914
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
915
-				fatal_lang_error('invalid_year', false);
946
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
947
+							fatal_lang_error('invalid_month', false);
948
+			}
949
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
950
+							fatal_lang_error('invalid_year', false);
951
+			}
916 952
 		}
917 953
 	}
918 954
 
@@ -922,8 +958,9 @@  discard block
 block discarded – undo
922 958
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
923 959
 	if (isset($_POST['span']))
924 960
 	{
925
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
926
-			fatal_lang_error('invalid_days_numb', false);
961
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
962
+					fatal_lang_error('invalid_days_numb', false);
963
+		}
927 964
 	}
928 965
 
929 966
 	// There is no need to validate the following values if we are just deleting the event.
@@ -933,24 +970,29 @@  discard block
 block discarded – undo
933 970
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
934 971
 		{
935 972
 			// No day?
936
-			if (!isset($_POST['day']))
937
-				fatal_lang_error('event_day_missing', false);
973
+			if (!isset($_POST['day'])) {
974
+							fatal_lang_error('event_day_missing', false);
975
+			}
938 976
 
939 977
 			// Bad day?
940
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
941
-				fatal_lang_error('invalid_date', false);
978
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
979
+							fatal_lang_error('invalid_date', false);
980
+			}
942 981
 		}
943 982
 
944
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
945
-			fatal_lang_error('event_title_missing', false);
946
-		elseif (!isset($_POST['evtitle']))
947
-			$_POST['evtitle'] = $_POST['subject'];
983
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
984
+					fatal_lang_error('event_title_missing', false);
985
+		} elseif (!isset($_POST['evtitle'])) {
986
+					$_POST['evtitle'] = $_POST['subject'];
987
+		}
948 988
 
949 989
 		// No title?
950
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
951
-			fatal_lang_error('no_event_title', false);
952
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
953
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
990
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
991
+					fatal_lang_error('no_event_title', false);
992
+		}
993
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
994
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
995
+		}
954 996
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
955 997
 	}
956 998
 }
@@ -977,8 +1019,9 @@  discard block
 block discarded – undo
977 1019
 	);
978 1020
 
979 1021
 	// No results, return false.
980
-	if ($smcFunc['db_num_rows'] === 0)
981
-		return false;
1022
+	if ($smcFunc['db_num_rows'] === 0) {
1023
+			return false;
1024
+	}
982 1025
 
983 1026
 	// Grab the results and return.
984 1027
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1112,8 +1155,9 @@  discard block
 block discarded – undo
1112 1155
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1113 1156
 
1114 1157
 	$column_clauses = array();
1115
-	foreach ($event_columns as $col => $crit)
1116
-		$column_clauses[] = $col . ' = ' . $crit;
1158
+	foreach ($event_columns as $col => $crit) {
1159
+			$column_clauses[] = $col . ' = ' . $crit;
1160
+	}
1117 1161
 
1118 1162
 	$smcFunc['db_query']('', '
1119 1163
 		UPDATE {db_prefix}calendar
@@ -1198,8 +1242,9 @@  discard block
 block discarded – undo
1198 1242
 	);
1199 1243
 
1200 1244
 	// If nothing returned, we are in poo, poo.
1201
-	if ($smcFunc['db_num_rows']($request) === 0)
1202
-		return false;
1245
+	if ($smcFunc['db_num_rows']($request) === 0) {
1246
+			return false;
1247
+	}
1203 1248
 
1204 1249
 	$row = $smcFunc['db_fetch_assoc']($request);
1205 1250
 	$smcFunc['db_free_result']($request);
@@ -1207,8 +1252,9 @@  discard block
 block discarded – undo
1207 1252
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1208 1253
 
1209 1254
 	// Sanity check
1210
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1211
-		return false;
1255
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1256
+			return false;
1257
+	}
1212 1258
 
1213 1259
 	$return_value = array(
1214 1260
 		'boards' => array(),
@@ -1345,24 +1391,27 @@  discard block
 block discarded – undo
1345 1391
 
1346 1392
 	// Set $span, in case we need it
1347 1393
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1348
-	if ($span > 0)
1349
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1394
+	if ($span > 0) {
1395
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1396
+	}
1350 1397
 
1351 1398
 	// Define the timezone for this event, falling back to the default if not provided
1352
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1353
-		$tz = $eventOptions['tz'];
1354
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1355
-		$tz = $_POST['tz'];
1356
-	else
1357
-		$tz = getUserTimezone();
1399
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1400
+			$tz = $eventOptions['tz'];
1401
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1402
+			$tz = $_POST['tz'];
1403
+	} else {
1404
+			$tz = getUserTimezone();
1405
+	}
1358 1406
 
1359 1407
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1360
-	if (isset($eventOptions['allday']))
1361
-		$allday = $eventOptions['allday'];
1362
-	elseif (empty($_POST['allday']))
1363
-		$allday = false;
1364
-	else
1365
-		$allday = true;
1408
+	if (isset($eventOptions['allday'])) {
1409
+			$allday = $eventOptions['allday'];
1410
+	} elseif (empty($_POST['allday'])) {
1411
+			$allday = false;
1412
+	} else {
1413
+			$allday = true;
1414
+	}
1366 1415
 
1367 1416
 	// Input might come as individual parameters...
1368 1417
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1389,10 +1438,12 @@  discard block
 block discarded – undo
1389 1438
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1390 1439
 
1391 1440
 	// If the date and time were given in separate strings, combine them
1392
-	if (empty($start_string) && isset($start_date_string))
1393
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1394
-	if (empty($end_string) && isset($end_date_string))
1395
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1441
+	if (empty($start_string) && isset($start_date_string)) {
1442
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1443
+	}
1444
+	if (empty($end_string) && isset($end_date_string)) {
1445
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1446
+	}
1396 1447
 
1397 1448
 	// If some form of string input was given, override individually defined options with it
1398 1449
 	if (isset($start_string))
@@ -1483,10 +1534,11 @@  discard block
 block discarded – undo
1483 1534
 	if ($start_object >= $end_object)
1484 1535
 	{
1485 1536
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1486
-		if ($span > 0)
1487
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1488
-		else
1489
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1537
+		if ($span > 0) {
1538
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1539
+		} else {
1540
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1541
+		}
1490 1542
 	}
1491 1543
 
1492 1544
 	// Is $end_object too late?
@@ -1499,9 +1551,9 @@  discard block
 block discarded – undo
1499 1551
 			{
1500 1552
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1501 1553
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1554
+			} else {
1555
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1502 1556
 			}
1503
-			else
1504
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1505 1557
 		}
1506 1558
 	}
1507 1559
 
@@ -1514,8 +1566,7 @@  discard block
 block discarded – undo
1514 1566
 		$start_time = null;
1515 1567
 		$end_time = null;
1516 1568
 		$tz = null;
1517
-	}
1518
-	else
1569
+	} else
1519 1570
 	{
1520 1571
 		$start_time = date_format($start_object, 'H:i:s');
1521 1572
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1536,16 +1587,18 @@  discard block
 block discarded – undo
1536 1587
 	require_once($sourcedir . '/Subs.php');
1537 1588
 
1538 1589
 	// First, try to create a better date format, ignoring the "time" elements.
1539
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1540
-		$date_format = '%F';
1541
-	else
1542
-		$date_format = $matches[0];
1590
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1591
+			$date_format = '%F';
1592
+	} else {
1593
+			$date_format = $matches[0];
1594
+	}
1543 1595
 
1544 1596
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1545
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1546
-		$time_format = '%k:%M';
1547
-	else
1548
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1597
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1598
+			$time_format = '%k:%M';
1599
+	} else {
1600
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1601
+	}
1549 1602
 
1550 1603
 	// Should this be an all day event?
1551 1604
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
@@ -1554,8 +1607,9 @@  discard block
 block discarded – undo
1554 1607
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1555 1608
 
1556 1609
 	// We need to have a defined timezone in the steps below
1557
-	if (empty($row['timezone']))
1558
-		$row['timezone'] = getUserTimezone();
1610
+	if (empty($row['timezone'])) {
1611
+			$row['timezone'] = getUserTimezone();
1612
+	}
1559 1613
 
1560 1614
 	// Get most of the standard date information for the start and end datetimes
1561 1615
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1607,8 +1661,9 @@  discard block
 block discarded – undo
1607 1661
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1608 1662
 	static $member_cache = array();
1609 1663
 
1610
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1611
-		$id_member = $context['user']['id'];
1664
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1665
+			$id_member = $context['user']['id'];
1666
+	}
1612 1667
 
1613 1668
 	//check if the cache got the data
1614 1669
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1637,11 +1692,13 @@  discard block
 block discarded – undo
1637 1692
 		$smcFunc['db_free_result']($request);
1638 1693
 	}
1639 1694
 
1640
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1641
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1695
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1696
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1697
+	}
1642 1698
 
1643
-	if (isset($id_member))
1644
-		$member_cache[$id_member] = $timezone;
1699
+	if (isset($id_member)) {
1700
+			$member_cache[$id_member] = $timezone;
1701
+	}
1645 1702
 
1646 1703
 	return $timezone;
1647 1704
 }
@@ -1670,8 +1727,9 @@  discard block
 block discarded – undo
1670 1727
 		)
1671 1728
 	);
1672 1729
 	$holidays = array();
1673
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1674
-		$holidays[] = $row;
1730
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1731
+			$holidays[] = $row;
1732
+	}
1675 1733
 	$smcFunc['db_free_result']($request);
1676 1734
 
1677 1735
 	return $holidays;
Please login to merge, or discard this patch.