Completed
Push — release-2.1 ( aa21c4...7040ad )
by Mathias
09:20
created
Sources/QueryString.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
  * Validates a IPv6 address. returns true if it is ipv6.
326 326
  *
327 327
  * @param string $ip The ip address to be validated
328
- * @return boolean Whether the specified IP is a valid IPv6 address
328
+ * @return false|string Whether the specified IP is a valid IPv6 address
329 329
  */
330 330
 function isValidIPv6($ip)
331 331
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -426,8 +426,8 @@
 block discarded – undo
426 426
 */
427 427
 function matchIPtoCIDR($ip_address, $cidr_address)
428 428
 {
429
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
429
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
431 431
 }
432 432
 
433 433
 /**
Please login to merge, or discard this patch.
Braces   +181 added lines, -128 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 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,8 +201,9 @@  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 208
 		elseif (strpos($_REQUEST['topic'], '.') !== false)
194 209
 		{
@@ -199,19 +214,22 @@  discard block
 block discarded – undo
199 214
 
200 215
 		// Now make sure the online log gets the right number.
201 216
 		$_GET['topic'] = $topic;
217
+	} else {
218
+			$topic = 0;
202 219
 	}
203
-	else
204
-		$topic = 0;
205 220
 
206 221
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
207
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
208
-		$_REQUEST['start'] = 0;
222
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
223
+			$_REQUEST['start'] = 0;
224
+	}
209 225
 
210 226
 	// The action needs to be a string and not an array or anything else
211
-	if (isset($_REQUEST['action']))
212
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
213
-	if (isset($_GET['action']))
214
-		$_GET['action'] = (string) $_GET['action'];
227
+	if (isset($_REQUEST['action'])) {
228
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
229
+	}
230
+	if (isset($_GET['action'])) {
231
+			$_GET['action'] = (string) $_GET['action'];
232
+	}
215 233
 
216 234
 	// Some mail providers like to encode semicolons in activation URLs...
217 235
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -237,29 +255,33 @@  discard block
 block discarded – undo
237 255
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
238 256
 
239 257
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
240
-	if (!isset($modSettings['proxy_ip_header']))
241
-		$modSettings['proxy_ip_header'] = 'autodetect';
258
+	if (!isset($modSettings['proxy_ip_header'])) {
259
+			$modSettings['proxy_ip_header'] = 'autodetect';
260
+	}
242 261
 
243 262
 	// Which headers are we going to check for Reverse Proxy IP headers?
244
-	if ($modSettings['proxy_ip_header'] == 'disabled')
245
-		$reverseIPheaders = array();
246
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
247
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
248
-	else
249
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
263
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
264
+			$reverseIPheaders = array();
265
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
266
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
267
+	} else {
268
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
269
+	}
250 270
 
251 271
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
252 272
 	foreach ($reverseIPheaders as $proxyIPheader)
253 273
 	{
254 274
 		// Ignore if this is not set.
255
-		if (!isset($_SERVER[$proxyIPheader]))
256
-			continue;
275
+		if (!isset($_SERVER[$proxyIPheader])) {
276
+					continue;
277
+		}
257 278
 
258 279
 		if (!empty($modSettings['proxy_ip_servers']))
259 280
 		{
260
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
261
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
281
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
282
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
262 283
 					continue;
284
+			}
263 285
 		}
264 286
 
265 287
 		// If there are commas, get the last one.. probably.
@@ -279,8 +301,9 @@  discard block
 block discarded – undo
279 301
 
280 302
 						// Just incase we have a legacy IPv4 address.
281 303
 						// @ TODO: Convert to IPv6.
282
-						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)
283
-							continue;
304
+						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) {
305
+													continue;
306
+						}
284 307
 					}
285 308
 
286 309
 					continue;
@@ -292,36 +315,40 @@  discard block
 block discarded – undo
292 315
 			}
293 316
 		}
294 317
 		// Otherwise just use the only one.
295
-		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)
296
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
297
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
318
+		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) {
319
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
320
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
298 321
 		{
299 322
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
300 323
 
301 324
 			// Just incase we have a legacy IPv4 address.
302 325
 			// @ TODO: Convert to IPv6.
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;
326
+			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) {
327
+							continue;
328
+			}
305 329
 		}
306 330
 	}
307 331
 
308 332
 	// Make sure we know the URL of the current request.
309
-	if (empty($_SERVER['REQUEST_URI']))
310
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
311
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
312
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
313
-	else
314
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
333
+	if (empty($_SERVER['REQUEST_URI'])) {
334
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
335
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
336
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
337
+	} else {
338
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
339
+	}
315 340
 
316 341
 	// And make sure HTTP_USER_AGENT is set.
317 342
 	$_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)) : '';
318 343
 
319 344
 	// Some final checking.
320
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
321
-		$_SERVER['BAN_CHECK_IP'] = '';
322
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
323
-		$_SERVER['REMOTE_ADDR'] = '';
324
-}
345
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
346
+			$_SERVER['BAN_CHECK_IP'] = '';
347
+	}
348
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
349
+			$_SERVER['REMOTE_ADDR'] = '';
350
+	}
351
+	}
325 352
 
326 353
 /**
327 354
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -332,8 +359,9 @@  discard block
 block discarded – undo
332 359
 function isValidIPv6($ip)
333 360
 {
334 361
 	//looking for :
335
-	if (strpos($ip, ':') === false)
336
-		return false;
362
+	if (strpos($ip, ':') === false) {
363
+			return false;
364
+	}
337 365
 
338 366
 	//check valid address
339 367
 	return inet_pton($ip);
@@ -350,15 +378,17 @@  discard block
 block discarded – undo
350 378
 	static $expanded = array();
351 379
 
352 380
 	// Check if we have done this already.
353
-	if (isset($expanded[$ip]))
354
-		return $expanded[$ip];
381
+	if (isset($expanded[$ip])) {
382
+			return $expanded[$ip];
383
+	}
355 384
 
356 385
 	// Expand the IP out.
357 386
 	$expanded_ip = explode(':', expandIPv6($ip));
358 387
 
359 388
 	$new_ip = array();
360
-	foreach ($expanded_ip as $int)
361
-		$new_ip[] = hexdec($int);
389
+	foreach ($expanded_ip as $int) {
390
+			$new_ip[] = hexdec($int);
391
+	}
362 392
 
363 393
 	// Save this incase of repeated use.
364 394
 	$expanded[$ip] = $new_ip;
@@ -378,8 +408,9 @@  discard block
 block discarded – undo
378 408
 	static $converted = array();
379 409
 
380 410
 	// Check if we have done this already.
381
-	if (isset($converted[$addr]))
382
-		return $converted[$addr];
411
+	if (isset($converted[$addr])) {
412
+			return $converted[$addr];
413
+	}
383 414
 
384 415
 	// Check if there are segments missing, insert if necessary.
385 416
 	if (strpos($addr, '::') !== false)
@@ -389,18 +420,20 @@  discard block
 block discarded – undo
389 420
 		$part[1] = explode(':', $part[1]);
390 421
 		$missing = array();
391 422
 
392
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
393
-			array_push($missing, '0000');
423
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
424
+					array_push($missing, '0000');
425
+		}
394 426
 
395 427
 		$part = array_merge($part[0], $missing, $part[1]);
428
+	} else {
429
+			$part = explode(':', $addr);
396 430
 	}
397
-	else
398
-		$part = explode(':', $addr);
399 431
 
400 432
 	// Pad each segment until it has 4 digits.
401
-	foreach ($part as &$p)
402
-		while (strlen($p) < 4)
433
+	foreach ($part as &$p) {
434
+			while (strlen($p) < 4)
403 435
 			$p = '0' . $p;
436
+	}
404 437
 
405 438
 	unset($p);
406 439
 
@@ -411,11 +444,12 @@  discard block
 block discarded – undo
411 444
 	$converted[$addr] = $result;
412 445
 
413 446
 	// Quick check to make sure the length is as expected.
414
-	if (!$strict_check || strlen($result) == 39)
415
-		return $result;
416
-	else
417
-		return false;
418
-}
447
+	if (!$strict_check || strlen($result) == 39) {
448
+			return $result;
449
+	} else {
450
+			return false;
451
+	}
452
+	}
419 453
 
420 454
 
421 455
 /**
@@ -446,15 +480,17 @@  discard block
 block discarded – undo
446 480
 {
447 481
 	global $smcFunc;
448 482
 
449
-	if (!is_array($var))
450
-		return $smcFunc['db_escape_string']($var);
483
+	if (!is_array($var)) {
484
+			return $smcFunc['db_escape_string']($var);
485
+	}
451 486
 
452 487
 	// Reindex the array with slashes.
453 488
 	$new_var = array();
454 489
 
455 490
 	// Add slashes to every element, even the indexes!
456
-	foreach ($var as $k => $v)
457
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
491
+	foreach ($var as $k => $v) {
492
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
493
+	}
458 494
 
459 495
 	return $new_var;
460 496
 }
@@ -474,12 +510,14 @@  discard block
 block discarded – undo
474 510
 {
475 511
 	global $smcFunc;
476 512
 
477
-	if (!is_array($var))
478
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
513
+	if (!is_array($var)) {
514
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
515
+	}
479 516
 
480 517
 	// Add the htmlspecialchars to every element.
481
-	foreach ($var as $k => $v)
482
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
518
+	foreach ($var as $k => $v) {
519
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
520
+	}
483 521
 
484 522
 	return $var;
485 523
 }
@@ -497,15 +535,17 @@  discard block
 block discarded – undo
497 535
  */
498 536
 function urldecode__recursive($var, $level = 0)
499 537
 {
500
-	if (!is_array($var))
501
-		return urldecode($var);
538
+	if (!is_array($var)) {
539
+			return urldecode($var);
540
+	}
502 541
 
503 542
 	// Reindex the array...
504 543
 	$new_var = array();
505 544
 
506 545
 	// Add the htmlspecialchars to every element.
507
-	foreach ($var as $k => $v)
508
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
546
+	foreach ($var as $k => $v) {
547
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
548
+	}
509 549
 
510 550
 	return $new_var;
511 551
 }
@@ -523,15 +563,17 @@  discard block
 block discarded – undo
523 563
 {
524 564
 	global $smcFunc;
525 565
 
526
-	if (!is_array($var))
527
-		return $smcFunc['db_unescape_string']($var);
566
+	if (!is_array($var)) {
567
+			return $smcFunc['db_unescape_string']($var);
568
+	}
528 569
 
529 570
 	// Reindex the array without slashes, this time.
530 571
 	$new_var = array();
531 572
 
532 573
 	// Strip the slashes from every element.
533
-	foreach ($var as $k => $v)
534
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
574
+	foreach ($var as $k => $v) {
575
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
576
+	}
535 577
 
536 578
 	return $new_var;
537 579
 }
@@ -549,15 +591,17 @@  discard block
 block discarded – undo
549 591
  */
550 592
 function stripslashes__recursive($var, $level = 0)
551 593
 {
552
-	if (!is_array($var))
553
-		return stripslashes($var);
594
+	if (!is_array($var)) {
595
+			return stripslashes($var);
596
+	}
554 597
 
555 598
 	// Reindex the array without slashes, this time.
556 599
 	$new_var = array();
557 600
 
558 601
 	// Strip the slashes from every element.
559
-	foreach ($var as $k => $v)
560
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
602
+	foreach ($var as $k => $v) {
603
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
604
+	}
561 605
 
562 606
 	return $new_var;
563 607
 }
@@ -578,12 +622,14 @@  discard block
 block discarded – undo
578 622
 	global $smcFunc;
579 623
 
580 624
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
581
-	if (!is_array($var))
582
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
625
+	if (!is_array($var)) {
626
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
627
+	}
583 628
 
584 629
 	// Go through all the elements and remove the whitespace.
585
-	foreach ($var as $k => $v)
586
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
630
+	foreach ($var as $k => $v) {
631
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
632
+	}
587 633
 
588 634
 	return $var;
589 635
 }
@@ -648,30 +694,37 @@  discard block
 block discarded – undo
648 694
 	global $scripturl, $modSettings, $context;
649 695
 
650 696
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
651
-	if ($scripturl == '' || !defined('SID'))
652
-		return $buffer;
697
+	if ($scripturl == '' || !defined('SID')) {
698
+			return $buffer;
699
+	}
653 700
 
654 701
 	// 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.
655 702
 	// @todo smflib
656
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
657
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
703
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
704
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
705
+	}
658 706
 	// Debugging templates, are we?
659
-	elseif (isset($_GET['debug']))
660
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
707
+	elseif (isset($_GET['debug'])) {
708
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
709
+	}
661 710
 
662 711
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
663 712
 	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']))
664 713
 	{
665 714
 		// Let's do something special for session ids!
666
-		if (defined('SID') && SID != '')
667
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
715
+		if (defined('SID') && SID != '') {
716
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
668 717
 			{
669
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
718
+				global $scripturl;
719
+		}
720
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
670 721
 			}, $buffer);
671
-		else
672
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
722
+		else {
723
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
673 724
 			{
674
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
725
+				global $scripturl;
726
+		}
727
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
675 728
 			}, $buffer);
676 729
 	}
677 730
 
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -807,7 +807,7 @@
 block discarded – undo
807 807
 /**
808 808
  * Send a group of emails from the mail queue.
809 809
  *
810
- * @param bool|int $number The number to send each loop through or false to use the standard limits
810
+ * @param integer $number The number to send each loop through or false to use the standard limits
811 811
  * @param bool $override_limit Whether to bypass the limit
812 812
  * @param bool $force_send Whether to forcibly send the messages now (useful when using cron jobs)
813 813
  * @return bool Whether things were sent
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,7 +384,7 @@
 block discarded – undo
384 384
 	clean_cache();
385 385
 
386 386
 	// If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
387
-	list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
387
+	list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
388 388
 	if ($modSettings['warning_decrement'])
389 389
 	{
390 390
 		// Find every member who has a warning level...
Please login to merge, or discard this patch.
Braces   +277 added lines, -201 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -506,15 +531,17 @@  discard block
 block discarded – undo
506 531
 
507 532
 		// Store this useful data!
508 533
 		$boards[$row['id_board']] = $row['id_board'];
509
-		if ($row['id_topic'])
510
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
511
-		else
512
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
534
+		if ($row['id_topic']) {
535
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
536
+		} else {
537
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
538
+		}
513 539
 	}
514 540
 	$smcFunc['db_free_result']($request);
515 541
 
516
-	if (empty($boards))
517
-		return true;
542
+	if (empty($boards)) {
543
+			return true;
544
+	}
518 545
 
519 546
 	// Just get the board names.
520 547
 	$request = $smcFunc['db_query']('', '
@@ -526,12 +553,14 @@  discard block
 block discarded – undo
526 553
 		)
527 554
 	);
528 555
 	$boards = array();
529
-	while ($row = $smcFunc['db_fetch_assoc']($request))
530
-		$boards[$row['id_board']] = $row['name'];
556
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
557
+			$boards[$row['id_board']] = $row['name'];
558
+	}
531 559
 	$smcFunc['db_free_result']($request);
532 560
 
533
-	if (empty($boards))
534
-		return true;
561
+	if (empty($boards)) {
562
+			return true;
563
+	}
535 564
 
536 565
 	// Get the actual topics...
537 566
 	$request = $smcFunc['db_query']('', '
@@ -551,52 +580,57 @@  discard block
 block discarded – undo
551 580
 	$types = array();
552 581
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 582
 	{
554
-		if (!isset($types[$row['note_type']][$row['id_board']]))
555
-			$types[$row['note_type']][$row['id_board']] = array(
583
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
584
+					$types[$row['note_type']][$row['id_board']] = array(
556 585
 				'lines' => array(),
557 586
 				'name' => $row['board_name'],
558 587
 				'id' => $row['id_board'],
559 588
 			);
589
+		}
560 590
 
561 591
 		if ($row['note_type'] == 'reply')
562 592
 		{
563
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
564
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
565
-			else
566
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
593
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
594
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
595
+			} else {
596
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
567 597
 					'id' => $row['id_topic'],
568 598
 					'subject' => un_htmlspecialchars($row['subject']),
569 599
 					'count' => 1,
570 600
 				);
571
-		}
572
-		elseif ($row['note_type'] == 'topic')
601
+			}
602
+		} elseif ($row['note_type'] == 'topic')
573 603
 		{
574
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
575
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
604
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
605
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
576 606
 					'id' => $row['id_topic'],
577 607
 					'subject' => un_htmlspecialchars($row['subject']),
578 608
 				);
579
-		}
580
-		else
609
+			}
610
+		} else
581 611
 		{
582
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
583
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
612
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
613
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
584 614
 					'id' => $row['id_topic'],
585 615
 					'subject' => un_htmlspecialchars($row['subject']),
586 616
 					'starter' => $row['id_member_started'],
587 617
 				);
618
+			}
588 619
 		}
589 620
 
590 621
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
591
-		if (!empty($notify['topics'][$row['id_topic']]))
592
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
593
-		if (!empty($notify['boards'][$row['id_board']]))
594
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
622
+		if (!empty($notify['topics'][$row['id_topic']])) {
623
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
624
+		}
625
+		if (!empty($notify['boards'][$row['id_board']])) {
626
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
627
+		}
595 628
 	}
596 629
 	$smcFunc['db_free_result']($request);
597 630
 
598
-	if (empty($types))
599
-		return true;
631
+	if (empty($types)) {
632
+			return true;
633
+	}
600 634
 
601 635
 	// Let's load all the languages into a cache thingy.
602 636
 	$langtxt = array();
@@ -637,8 +671,9 @@  discard block
 block discarded – undo
637 671
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
638 672
 
639 673
 		// Did they not elect to choose this?
640
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
641
-			continue;
674
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
675
+					continue;
676
+		}
642 677
 
643 678
 		// Right character set!
644 679
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -654,39 +689,43 @@  discard block
 block discarded – undo
654 689
 		if (isset($types['topic']))
655 690
 		{
656 691
 			$titled = false;
657
-			foreach ($types['topic'] as $id => $board)
658
-				foreach ($board['lines'] as $topic)
692
+			foreach ($types['topic'] as $id => $board) {
693
+							foreach ($board['lines'] as $topic)
659 694
 					if (in_array($mid, $topic['members']))
660 695
 					{
661 696
 						if (!$titled)
662 697
 						{
663 698
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
699
+			}
664 700
 							$titled = true;
665 701
 						}
666 702
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
667 703
 					}
668
-			if ($titled)
669
-				$email['body'] .= "\n";
704
+			if ($titled) {
705
+							$email['body'] .= "\n";
706
+			}
670 707
 		}
671 708
 
672 709
 		// What about replies?
673 710
 		if (isset($types['reply']))
674 711
 		{
675 712
 			$titled = false;
676
-			foreach ($types['reply'] as $id => $board)
677
-				foreach ($board['lines'] as $topic)
713
+			foreach ($types['reply'] as $id => $board) {
714
+							foreach ($board['lines'] as $topic)
678 715
 					if (in_array($mid, $topic['members']))
679 716
 					{
680 717
 						if (!$titled)
681 718
 						{
682 719
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
720
+			}
683 721
 							$titled = true;
684 722
 						}
685 723
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
686 724
 					}
687 725
 
688
-			if ($titled)
689
-				$email['body'] .= "\n";
726
+			if ($titled) {
727
+							$email['body'] .= "\n";
728
+			}
690 729
 		}
691 730
 
692 731
 		// Finally, moderation actions!
@@ -695,24 +734,27 @@  discard block
 block discarded – undo
695 734
 			$titled = false;
696 735
 			foreach ($types as $note_type => $type)
697 736
 			{
698
-				if ($note_type == 'topic' || $note_type == 'reply')
699
-					continue;
737
+				if ($note_type == 'topic' || $note_type == 'reply') {
738
+									continue;
739
+				}
700 740
 
701
-				foreach ($type as $id => $board)
702
-					foreach ($board['lines'] as $topic)
741
+				foreach ($type as $id => $board) {
742
+									foreach ($board['lines'] as $topic)
703 743
 						if (in_array($mid, $topic['members']))
704 744
 						{
705 745
 							if (!$titled)
706 746
 							{
707 747
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
748
+				}
708 749
 								$titled = true;
709 750
 							}
710 751
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
711 752
 						}
712 753
 			}
713 754
 		}
714
-		if ($titled)
715
-			$email['body'] .= "\n";
755
+		if ($titled) {
756
+					$email['body'] .= "\n";
757
+		}
716 758
 
717 759
 		// Then just say our goodbyes!
718 760
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -740,8 +782,7 @@  discard block
 block discarded – undo
740 782
 				'not_daily' => 0,
741 783
 			)
742 784
 		);
743
-	}
744
-	else
785
+	} else
745 786
 	{
746 787
 		// Clear any only weekly ones, and stop us from sending daily again.
747 788
 		$smcFunc['db_query']('', '
@@ -803,16 +844,19 @@  discard block
 block discarded – undo
803 844
 	global $modSettings, $smcFunc, $sourcedir;
804 845
 
805 846
 	// Are we intending another script to be sending out the queue?
806
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
807
-		return false;
847
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
848
+			return false;
849
+	}
808 850
 
809 851
 	// By default send 5 at once.
810
-	if (!$number)
811
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
852
+	if (!$number) {
853
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
854
+	}
812 855
 
813 856
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
814
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
815
-		return false;
857
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
858
+			return false;
859
+	}
816 860
 
817 861
 	// By default move the next sending on by 10 seconds, and require an affected row.
818 862
 	if (!$override_limit)
@@ -829,8 +873,9 @@  discard block
 block discarded – undo
829 873
 				'last_send' => $modSettings['mail_next_send'],
830 874
 			)
831 875
 		);
832
-		if ($smcFunc['db_affected_rows']() == 0)
833
-			return false;
876
+		if ($smcFunc['db_affected_rows']() == 0) {
877
+					return false;
878
+		}
834 879
 		$modSettings['mail_next_send'] = time() + $delay;
835 880
 	}
836 881
 
@@ -851,8 +896,9 @@  discard block
 block discarded – undo
851 896
 			$mn += $number;
852 897
 		}
853 898
 		// No more I'm afraid, return!
854
-		else
855
-			return false;
899
+		else {
900
+					return false;
901
+		}
856 902
 
857 903
 		// Reflect that we're about to send some, do it now to be safe.
858 904
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -887,14 +933,15 @@  discard block
 block discarded – undo
887 933
 	$smcFunc['db_free_result']($request);
888 934
 
889 935
 	// Delete, delete, delete!!!
890
-	if (!empty($ids))
891
-		$smcFunc['db_query']('', '
936
+	if (!empty($ids)) {
937
+			$smcFunc['db_query']('', '
892 938
 			DELETE FROM {db_prefix}mail_queue
893 939
 			WHERE id_mail IN ({array_int:mail_list})',
894 940
 			array(
895 941
 				'mail_list' => $ids,
896 942
 			)
897 943
 		);
944
+	}
898 945
 
899 946
 	// Don't believe we have any left?
900 947
 	if (count($ids) < $number)
@@ -912,11 +959,13 @@  discard block
 block discarded – undo
912 959
 		);
913 960
 	}
914 961
 
915
-	if (empty($ids))
916
-		return false;
962
+	if (empty($ids)) {
963
+			return false;
964
+	}
917 965
 
918
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
919
-		require_once($sourcedir . '/Subs-Post.php');
966
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
967
+			require_once($sourcedir . '/Subs-Post.php');
968
+	}
920 969
 
921 970
 	// Send each email, yea!
922 971
 	$failed_emails = array();
@@ -936,15 +985,17 @@  discard block
 block discarded – undo
936 985
 
937 986
 			// Try to stop a timeout, this would be bad...
938 987
 			@set_time_limit(300);
939
-			if (function_exists('apache_reset_timeout'))
940
-				@apache_reset_timeout();
988
+			if (function_exists('apache_reset_timeout')) {
989
+							@apache_reset_timeout();
990
+			}
991
+		} else {
992
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
941 993
 		}
942
-		else
943
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
944 994
 
945 995
 		// Hopefully it sent?
946
-		if (!$result)
947
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
996
+		if (!$result) {
997
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
998
+		}
948 999
 	}
949 1000
 
950 1001
 	// Any emails that didn't send?
@@ -959,8 +1010,8 @@  discard block
 block discarded – undo
959 1010
 		);
960 1011
 
961 1012
 		// If we have failed to many times, tell mail to wait a bit and try again.
962
-		if ($modSettings['mail_failed_attempts'] > 5)
963
-			$smcFunc['db_query']('', '
1013
+		if ($modSettings['mail_failed_attempts'] > 5) {
1014
+					$smcFunc['db_query']('', '
964 1015
 				UPDATE {db_prefix}settings
965 1016
 				SET value = {string:next_mail_send}
966 1017
 				WHERE variable = {literal:mail_next_send}
@@ -969,6 +1020,7 @@  discard block
 block discarded – undo
969 1020
 					'next_mail_send' => time() + 60,
970 1021
 					'last_send' => $modSettings['mail_next_send'],
971 1022
 			));
1023
+		}
972 1024
 
973 1025
 		// Add our email back to the queue, manually.
974 1026
 		$smcFunc['db_insert']('insert',
@@ -981,8 +1033,8 @@  discard block
 block discarded – undo
981 1033
 		return false;
982 1034
 	}
983 1035
 	// We where unable to send the email, clear our failed attempts.
984
-	elseif (!empty($modSettings['mail_failed_attempts']))
985
-		$smcFunc['db_query']('', '
1036
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1037
+			$smcFunc['db_query']('', '
986 1038
 			UPDATE {db_prefix}settings
987 1039
 			SET value = {string:zero}
988 1040
 			WHERE variable = {string:mail_failed_attempts}',
@@ -990,6 +1042,7 @@  discard block
 block discarded – undo
990 1042
 				'zero' => '0',
991 1043
 				'mail_failed_attempts' => 'mail_failed_attempts',
992 1044
 		));
1045
+	}
993 1046
 
994 1047
 	// Had something to send...
995 1048
 	return true;
@@ -1006,16 +1059,18 @@  discard block
 block discarded – undo
1006 1059
 	global $modSettings, $smcFunc;
1007 1060
 
1008 1061
 	$task_query = '';
1009
-	if (!is_array($tasks))
1010
-		$tasks = array($tasks);
1062
+	if (!is_array($tasks)) {
1063
+			$tasks = array($tasks);
1064
+	}
1011 1065
 
1012 1066
 	// Actually have something passed?
1013 1067
 	if (!empty($tasks))
1014 1068
 	{
1015
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1016
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1017
-		else
1018
-			$task_query = ' AND task IN ({array_string:tasks})';
1069
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1070
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1071
+		} else {
1072
+					$task_query = ' AND task IN ({array_string:tasks})';
1073
+		}
1019 1074
 	}
1020 1075
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1021 1076
 
@@ -1036,20 +1091,22 @@  discard block
 block discarded – undo
1036 1091
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1037 1092
 
1038 1093
 		// Only bother moving the task if it's out of place or we're forcing it!
1039
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1040
-			$tasks[$row['id_task']] = $next_time;
1041
-		else
1042
-			$next_time = $row['next_time'];
1094
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1095
+					$tasks[$row['id_task']] = $next_time;
1096
+		} else {
1097
+					$next_time = $row['next_time'];
1098
+		}
1043 1099
 
1044 1100
 		// If this is sooner than the current next task, make this the next task.
1045
-		if ($next_time < $nextTaskTime)
1046
-			$nextTaskTime = $next_time;
1101
+		if ($next_time < $nextTaskTime) {
1102
+					$nextTaskTime = $next_time;
1103
+		}
1047 1104
 	}
1048 1105
 	$smcFunc['db_free_result']($request);
1049 1106
 
1050 1107
 	// Now make the changes!
1051
-	foreach ($tasks as $id => $time)
1052
-		$smcFunc['db_query']('', '
1108
+	foreach ($tasks as $id => $time) {
1109
+			$smcFunc['db_query']('', '
1053 1110
 			UPDATE {db_prefix}scheduled_tasks
1054 1111
 			SET next_time = {int:next_time}
1055 1112
 			WHERE id_task = {int:id_task}',
@@ -1058,11 +1115,13 @@  discard block
 block discarded – undo
1058 1115
 				'id_task' => $id,
1059 1116
 			)
1060 1117
 		);
1118
+	}
1061 1119
 
1062 1120
 	// If the next task is now different update.
1063
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1064
-		updateSettings(array('next_task_time' => $nextTaskTime));
1065
-}
1121
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1122
+			updateSettings(array('next_task_time' => $nextTaskTime));
1123
+	}
1124
+	}
1066 1125
 
1067 1126
 /**
1068 1127
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1075,8 +1134,9 @@  discard block
 block discarded – undo
1075 1134
 function next_time($regularity, $unit, $offset)
1076 1135
 {
1077 1136
 	// Just in case!
1078
-	if ($regularity == 0)
1079
-		$regularity = 2;
1137
+	if ($regularity == 0) {
1138
+			$regularity = 2;
1139
+	}
1080 1140
 
1081 1141
 	$curMin = date('i', time());
1082 1142
 
@@ -1086,15 +1146,16 @@  discard block
 block discarded – undo
1086 1146
 		$off = date('i', $offset);
1087 1147
 
1088 1148
 		// If it's now just pretend it ain't,
1089
-		if ($off == $curMin)
1090
-			$next_time = time() + $regularity;
1091
-		else
1149
+		if ($off == $curMin) {
1150
+					$next_time = time() + $regularity;
1151
+		} else
1092 1152
 		{
1093 1153
 			// Make sure that the offset is always in the past.
1094 1154
 			$off = $off > $curMin ? $off - 60 : $off;
1095 1155
 
1096
-			while ($off <= $curMin)
1097
-				$off += $regularity;
1156
+			while ($off <= $curMin) {
1157
+							$off += $regularity;
1158
+			}
1098 1159
 
1099 1160
 			// Now we know when the time should be!
1100 1161
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1114,11 +1175,13 @@  discard block
 block discarded – undo
1114 1175
 		// Default we'll jump in hours.
1115 1176
 		$applyOffset = 3600;
1116 1177
 		// 24 hours = 1 day.
1117
-		if ($unit == 'd')
1118
-			$applyOffset = 86400;
1178
+		if ($unit == 'd') {
1179
+					$applyOffset = 86400;
1180
+		}
1119 1181
 		// Otherwise a week.
1120
-		if ($unit == 'w')
1121
-			$applyOffset = 604800;
1182
+		if ($unit == 'w') {
1183
+					$applyOffset = 604800;
1184
+		}
1122 1185
 
1123 1186
 		$applyOffset *= $regularity;
1124 1187
 
@@ -1155,8 +1218,9 @@  discard block
 block discarded – undo
1155 1218
 		$settings[$row['variable']] = $row['value'];
1156 1219
 
1157 1220
 		// Is this the default theme?
1158
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1159
-			$settings['default_' . $row['variable']] = $row['value'];
1221
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1222
+					$settings['default_' . $row['variable']] = $row['value'];
1223
+		}
1160 1224
 	}
1161 1225
 	$smcFunc['db_free_result']($result);
1162 1226
 
@@ -1166,12 +1230,14 @@  discard block
 block discarded – undo
1166 1230
 		$settings['template_dirs'] = array($settings['theme_dir']);
1167 1231
 
1168 1232
 		// Based on theme (if there is one).
1169
-		if (!empty($settings['base_theme_dir']))
1170
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1233
+		if (!empty($settings['base_theme_dir'])) {
1234
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1235
+		}
1171 1236
 
1172 1237
 		// Lastly the default theme.
1173
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1174
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1238
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1239
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1240
+		}
1175 1241
 	}
1176 1242
 
1177 1243
 	// Assume we want this.
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 	// Ok should we prune the logs?
1319 1385
 	if (!empty($modSettings['pruningOptions']))
1320 1386
 	{
1321
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1322
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1387
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1388
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1389
+		}
1323 1390
 
1324 1391
 		if (!empty($modSettings['pruneErrorLog']))
1325 1392
 		{
@@ -1385,8 +1452,9 @@  discard block
 block discarded – undo
1385 1452
 				)
1386 1453
 			);
1387 1454
 
1388
-			while ($row = $smcFunc['db_fetch_row']($result))
1389
-				$reports[] = $row[0];
1455
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1456
+							$reports[] = $row[0];
1457
+			}
1390 1458
 
1391 1459
 			$smcFunc['db_free_result']($result);
1392 1460
 
@@ -1548,8 +1616,9 @@  discard block
 block discarded – undo
1548 1616
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1549 1617
 
1550 1618
 		// Send the actual email.
1551
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1552
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1619
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1620
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1621
+		}
1553 1622
 
1554 1623
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1555 1624
 		{
@@ -1572,18 +1641,19 @@  discard block
 block discarded – undo
1572 1641
 	}
1573 1642
 
1574 1643
 	// Insert the alerts if any
1575
-	if (!empty($alert_rows))
1576
-		$smcFunc['db_insert']('',
1644
+	if (!empty($alert_rows)) {
1645
+			$smcFunc['db_insert']('',
1577 1646
 			'{db_prefix}user_alerts',
1578 1647
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1579 1648
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1580 1649
 			$alert_rows,
1581 1650
 			array()
1582 1651
 		);
1652
+	}
1583 1653
 
1584 1654
 	// Mark the reminder as sent.
1585
-	if (!empty($subs_reminded))
1586
-		$smcFunc['db_query']('', '
1655
+	if (!empty($subs_reminded)) {
1656
+			$smcFunc['db_query']('', '
1587 1657
 			UPDATE {db_prefix}log_subscribed
1588 1658
 			SET reminder_sent = {int:reminder_sent}
1589 1659
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1592,6 +1662,7 @@  discard block
 block discarded – undo
1592 1662
 				'reminder_sent' => 1,
1593 1663
 			)
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	return true;
1597 1668
 }
@@ -1607,13 +1678,13 @@  discard block
 block discarded – undo
1607 1678
 	// We need to know where this thing is going.
1608 1679
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1609 1680
 	{
1610
-		if (!is_array($modSettings['attachmentUploadDir']))
1611
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1681
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1682
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1683
+		}
1612 1684
 
1613 1685
 		// Just use the current path for temp files.
1614 1686
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1615
-	}
1616
-	else
1687
+	} else
1617 1688
 	{
1618 1689
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1619 1690
 	}
@@ -1632,14 +1703,16 @@  discard block
 block discarded – undo
1632 1703
 
1633 1704
 		while ($file = readdir($dir))
1634 1705
 		{
1635
-			if ($file == '.' || $file == '..')
1636
-				continue;
1706
+			if ($file == '.' || $file == '..') {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (strpos($file, 'post_tmp_') !== false)
1639 1711
 			{
1640 1712
 				// Temp file is more than 5 hours old!
1641
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1642
-					@unlink($attach_dir . '/' . $file);
1713
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1714
+									@unlink($attach_dir . '/' . $file);
1715
+				}
1643 1716
 			}
1644 1717
 		}
1645 1718
 		closedir($dir);
@@ -1672,8 +1745,9 @@  discard block
 block discarded – undo
1672 1745
 		)
1673 1746
 	);
1674 1747
 
1675
-	while ($row = $smcFunc['db_fetch_row']($request))
1676
-		$topics[] = $row[0];
1748
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1749
+			$topics[] = $row[0];
1750
+	}
1677 1751
 	$smcFunc['db_free_result']($request);
1678 1752
 
1679 1753
 	// Zap, your gone
@@ -1693,8 +1767,9 @@  discard block
 block discarded – undo
1693 1767
 {
1694 1768
 	global $smcFunc, $sourcedir, $modSettings;
1695 1769
 
1696
-	if (empty($modSettings['drafts_keep_days']))
1697
-		return true;
1770
+	if (empty($modSettings['drafts_keep_days'])) {
1771
+			return true;
1772
+	}
1698 1773
 
1699 1774
 	// init
1700 1775
 	$drafts = array();
@@ -1712,8 +1787,9 @@  discard block
 block discarded – undo
1712 1787
 		)
1713 1788
 	);
1714 1789
 
1715
-	while ($row = $smcFunc['db_fetch_row']($request))
1716
-		$drafts[] = (int) $row[0];
1790
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1791
+			$drafts[] = (int) $row[0];
1792
+	}
1717 1793
 	$smcFunc['db_free_result']($request);
1718 1794
 
1719 1795
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -457,7 +457,6 @@  discard block
 block discarded – undo
457 457
 
458 458
 /**
459 459
  * affected_rows
460
- * @param resource $connection
461 460
  */
462 461
 function smf_db_affected_rows($result = null)
463 462
 {
@@ -800,7 +799,7 @@  discard block
 block discarded – undo
800 799
  *
801 800
  * @param string $db_name The database name
802 801
  * @param resource $db_connection The database connection
803
- * @return true Always returns true
802
+ * @return boolean Always returns true
804 803
  */
805 804
 function smf_db_select_db($db_name, $db_connection)
806 805
 {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -200,22 +200,22 @@  discard block
 block discarded – undo
200 200
 
201 201
 		case 'date':
202 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';
203
+				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date';
204 204
 			else
205 205
 				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206 206
 		break;
207 207
 
208 208
 		case 'time':
209 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';
210
+				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time';
211 211
 			else
212 212
 				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213 213
 		break;
214 214
 
215 215
 		case 'datetime':
216 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('.
218
-					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]).
217
+				return 'to_timestamp(' .
218
+					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 219
 					',\'YYYY-MM-DD HH24:MI:SS\')';
220 220
 			else
221 221
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -764,10 +764,10 @@  discard block
 block discarded – undo
764 764
 	$returning = '';
765 765
 	$with_returning = false;
766 766
 	// lets build the returning string, mysql allow only in normal mode
767
-	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
767
+	if (!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
768 768
 	{
769 769
 		// we only take the first key
770
-		$returning = ' RETURNING '.$keys[0];
770
+		$returning = ' RETURNING ' . $keys[0];
771 771
 		$with_returning = true;
772 772
 	}
773 773
 
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
 			INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
799 799
 			VALUES
800 800
 				' . implode(',
801
-				', $insertRows).$replace.$returning,
801
+				', $insertRows) . $replace . $returning,
802 802
 			array(
803 803
 				'security_override' => true,
804 804
 				'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors',
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 			if ($returnmode === 2)
812 812
 				$return_var = array();
813 813
 
814
-			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
814
+			while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
815 815
 			{
816 816
 				if (is_numeric($row[0])) // try to emulate mysql limitation
817 817
 				{
Please login to merge, or discard this 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,31 +127,38 @@  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
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
132
-		return $user_info[$matches[1]];
134
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
135
+			return $user_info[$matches[1]];
136
+	}
133 137
 
134
-	if ($matches[1] === 'empty')
135
-		return '\'\'';
138
+	if ($matches[1] === 'empty') {
139
+			return '\'\'';
140
+	}
136 141
 
137
-	if (!isset($matches[2]))
138
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
142
+	if (!isset($matches[2])) {
143
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	}
139 145
 
140
-	if ($matches[1] === 'literal')
141
-		return '\'' . pg_escape_string($matches[2]) . '\'';
146
+	if ($matches[1] === 'literal') {
147
+			return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	}
142 149
 
143
-	if (!isset($values[$matches[2]]))
144
-		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__);
150
+	if (!isset($values[$matches[2]])) {
151
+			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__);
152
+	}
145 153
 
146 154
 	$replacement = $values[$matches[2]];
147 155
 
148 156
 	switch ($matches[1])
149 157
 	{
150 158
 		case 'int':
151
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
152
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
159
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
160
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			}
153 162
 			return (string) (int) $replacement;
154 163
 		break;
155 164
 
@@ -161,65 +170,73 @@  discard block
 block discarded – undo
161 170
 		case 'array_int':
162 171
 			if (is_array($replacement))
163 172
 			{
164
-				if (empty($replacement))
165
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
173
+				if (empty($replacement)) {
174
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				}
166 176
 
167 177
 				foreach ($replacement as $key => $value)
168 178
 				{
169
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
170
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
180
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					}
171 182
 
172 183
 					$replacement[$key] = (string) (int) $value;
173 184
 				}
174 185
 
175 186
 				return implode(', ', $replacement);
187
+			} else {
188
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176 189
 			}
177
-			else
178
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
179 190
 
180 191
 		break;
181 192
 
182 193
 		case 'array_string':
183 194
 			if (is_array($replacement))
184 195
 			{
185
-				if (empty($replacement))
186
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196
+				if (empty($replacement)) {
197
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				}
187 199
 
188
-				foreach ($replacement as $key => $value)
189
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
200
+				foreach ($replacement as $key => $value) {
201
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				}
190 203
 
191 204
 				return implode(', ', $replacement);
205
+			} else {
206
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
192 207
 			}
193
-			else
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195 208
 		break;
196 209
 
197 210
 		case 'date':
198
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
199
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
200
-			else
201
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
212
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
213
+			} else {
214
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			}
202 216
 		break;
203 217
 
204 218
 		case 'time':
205
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
206
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
207
-			else
208
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
220
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
221
+			} else {
222
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			}
209 224
 		break;
210 225
 
211 226
 		case 'datetime':
212
-			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)
213
-				return 'to_timestamp('.
227
+			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) {
228
+							return 'to_timestamp('.
214 229
 					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]).
215 230
 					',\'YYYY-MM-DD HH24:MI:SS\')';
216
-			else
217
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			} else {
232
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			}
218 234
 		break;
219 235
 
220 236
 		case 'float':
221
-			if (!is_numeric($replacement))
222
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			if (!is_numeric($replacement)) {
238
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239
+			}
223 240
 			return (string) (float) $replacement;
224 241
 		break;
225 242
 
@@ -232,31 +249,36 @@  discard block
 block discarded – undo
232 249
 		break;
233 250
 
234 251
 		case 'inet':
235
-			if ($replacement == 'null' || $replacement == '')
236
-				return 'null';
237
-			if (inet_pton($replacement) === false)
238
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+			if ($replacement == 'null' || $replacement == '') {
253
+							return 'null';
254
+			}
255
+			if (inet_pton($replacement) === false) {
256
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+			}
239 258
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
240 259
 
241 260
 		case 'array_inet':
242 261
 			if (is_array($replacement))
243 262
 			{
244
-				if (empty($replacement))
245
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+				if (empty($replacement)) {
264
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+				}
246 266
 
247 267
 				foreach ($replacement as $key => $value)
248 268
 				{
249
-					if ($replacement == 'null' || $replacement == '')
250
-						$replacement[$key] = 'null';
251
-					if (!isValidIP($value))
252
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+					if ($replacement == 'null' || $replacement == '') {
270
+											$replacement[$key] = 'null';
271
+					}
272
+					if (!isValidIP($value)) {
273
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+					}
253 275
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
254 276
 				}
255 277
 
256 278
 				return implode(', ', $replacement);
279
+			} else {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257 281
 			}
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260 282
 		break;
261 283
 
262 284
 		default:
@@ -350,14 +372,16 @@  discard block
 block discarded – undo
350 372
 		),
351 373
 	);
352 374
 
353
-	if (isset($replacements[$identifier]))
354
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
375
+	if (isset($replacements[$identifier])) {
376
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
377
+	}
355 378
 
356 379
 	// Limits need to be a little different.
357 380
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
358 381
 
359
-	if (trim($db_string) == '')
360
-		return false;
382
+	if (trim($db_string) == '') {
383
+			return false;
384
+	}
361 385
 
362 386
 	// Comments that are allowed in a query are preg_removed.
363 387
 	static $allowed_comments_from = array(
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
378 402
 	$db_replace_result = 0;
379 403
 
380
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
381
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
404
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
405
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
406
+	}
382 407
 
383 408
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
384 409
 	{
@@ -399,8 +424,9 @@  discard block
 block discarded – undo
399 424
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
400 425
 
401 426
 		// Initialize $db_cache if not already initialized.
402
-		if (!isset($db_cache))
403
-			$db_cache = array();
427
+		if (!isset($db_cache)) {
428
+					$db_cache = array();
429
+		}
404 430
 
405 431
 		if (!empty($_SESSION['debug_redirect']))
406 432
 		{
@@ -426,17 +452,18 @@  discard block
 block discarded – undo
426 452
 		while (true)
427 453
 		{
428 454
 			$pos = strpos($db_string, '\'', $pos + 1);
429
-			if ($pos === false)
430
-				break;
455
+			if ($pos === false) {
456
+							break;
457
+			}
431 458
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
432 459
 
433 460
 			while (true)
434 461
 			{
435 462
 				$pos1 = strpos($db_string, '\'', $pos + 1);
436 463
 				$pos2 = strpos($db_string, '\\', $pos + 1);
437
-				if ($pos1 === false)
438
-					break;
439
-				elseif ($pos2 === false || $pos2 > $pos1)
464
+				if ($pos1 === false) {
465
+									break;
466
+				} elseif ($pos2 === false || $pos2 > $pos1)
440 467
 				{
441 468
 					$pos = $pos1;
442 469
 					break;
@@ -452,16 +479,19 @@  discard block
 block discarded – undo
452 479
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
453 480
 
454 481
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
455
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
456
-			$fail = true;
482
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
483
+					$fail = true;
484
+		}
457 485
 		// Trying to change passwords, slow us down, or something?
458
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
459
-			$fail = true;
460
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
461
-			$fail = true;
486
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
487
+					$fail = true;
488
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
489
+					$fail = true;
490
+		}
462 491
 
463
-		if (!empty($fail) && function_exists('log_error'))
464
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
492
+		if (!empty($fail) && function_exists('log_error')) {
493
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
494
+		}
465 495
 	}
466 496
 
467 497
 	// Set optimize stuff
@@ -480,18 +510,21 @@  discard block
 block discarded – undo
480 510
 
481 511
 		$db_string = $query_hints_set . $db_string;
482 512
 		
483
-		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...')
484
-			$db_cache[$db_count]['q'] = "\t\t" . $db_string;
513
+		if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') {
514
+					$db_cache[$db_count]['q'] = "\t\t" . $db_string;
515
+		}
485 516
 	}
486 517
 
487 518
 	$db_last_result = @pg_query($connection, $db_string);
488 519
 
489
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
490
-		$db_last_result = smf_db_error($db_string, $connection);
520
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
521
+			$db_last_result = smf_db_error($db_string, $connection);
522
+	}
491 523
 
492 524
 	// Debugging.
493
-	if (isset($db_show_debug) && $db_show_debug === true)
494
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
525
+	if (isset($db_show_debug) && $db_show_debug === true) {
526
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
527
+	}
495 528
 
496 529
 	return $db_last_result;
497 530
 }
@@ -504,10 +537,11 @@  discard block
 block discarded – undo
504 537
 {
505 538
 	global $db_last_result, $db_replace_result;
506 539
 
507
-	if ($db_replace_result)
508
-		return $db_replace_result;
509
-	elseif ($result === null && !$db_last_result)
510
-		return 0;
540
+	if ($db_replace_result) {
541
+			return $db_replace_result;
542
+	} elseif ($result === null && !$db_last_result) {
543
+			return 0;
544
+	}
511 545
 
512 546
 	return pg_affected_rows($result === null ? $db_last_result : $result);
513 547
 }
@@ -531,8 +565,9 @@  discard block
 block discarded – undo
531 565
 		array(
532 566
 		)
533 567
 	);
534
-	if (!$request)
535
-		return false;
568
+	if (!$request) {
569
+			return false;
570
+	}
536 571
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
537 572
 	$smcFunc['db_free_result']($request);
538 573
 
@@ -553,12 +588,13 @@  discard block
 block discarded – undo
553 588
 	// Decide which connection to use
554 589
 	$connection = $connection === null ? $db_connection : $connection;
555 590
 
556
-	if ($type == 'begin')
557
-		return @pg_query($connection, 'BEGIN');
558
-	elseif ($type == 'rollback')
559
-		return @pg_query($connection, 'ROLLBACK');
560
-	elseif ($type == 'commit')
561
-		return @pg_query($connection, 'COMMIT');
591
+	if ($type == 'begin') {
592
+			return @pg_query($connection, 'BEGIN');
593
+	} elseif ($type == 'rollback') {
594
+			return @pg_query($connection, 'ROLLBACK');
595
+	} elseif ($type == 'commit') {
596
+			return @pg_query($connection, 'COMMIT');
597
+	}
562 598
 
563 599
 	return false;
564 600
 }
@@ -586,19 +622,22 @@  discard block
 block discarded – undo
586 622
 	$query_error = @pg_last_error($connection);
587 623
 
588 624
 	// Log the error.
589
-	if (function_exists('log_error'))
590
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
625
+	if (function_exists('log_error')) {
626
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
627
+	}
591 628
 
592 629
 	// Nothing's defined yet... just die with it.
593
-	if (empty($context) || empty($txt))
594
-		die($query_error);
630
+	if (empty($context) || empty($txt)) {
631
+			die($query_error);
632
+	}
595 633
 
596 634
 	// Show an error message, if possible.
597 635
 	$context['error_title'] = $txt['database_error'];
598
-	if (allowedTo('admin_forum'))
599
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
600
-	else
601
-		$context['error_message'] = $txt['try_again'];
636
+	if (allowedTo('admin_forum')) {
637
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
638
+	} else {
639
+			$context['error_message'] = $txt['try_again'];
640
+	}
602 641
 
603 642
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
604 643
 	{
@@ -620,12 +659,14 @@  discard block
 block discarded – undo
620 659
 {
621 660
 	global $db_row_count;
622 661
 
623
-	if ($counter !== false)
624
-		return pg_fetch_row($request, $counter);
662
+	if ($counter !== false) {
663
+			return pg_fetch_row($request, $counter);
664
+	}
625 665
 
626 666
 	// Reset the row counter...
627
-	if (!isset($db_row_count[(int) $request]))
628
-		$db_row_count[(int) $request] = 0;
667
+	if (!isset($db_row_count[(int) $request])) {
668
+			$db_row_count[(int) $request] = 0;
669
+	}
629 670
 
630 671
 	// Return the right row.
631 672
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -642,12 +683,14 @@  discard block
 block discarded – undo
642 683
 {
643 684
 	global $db_row_count;
644 685
 
645
-	if ($counter !== false)
646
-		return pg_fetch_assoc($request, $counter);
686
+	if ($counter !== false) {
687
+			return pg_fetch_assoc($request, $counter);
688
+	}
647 689
 
648 690
 	// Reset the row counter...
649
-	if (!isset($db_row_count[(int) $request]))
650
-		$db_row_count[(int) $request] = 0;
691
+	if (!isset($db_row_count[(int) $request])) {
692
+			$db_row_count[(int) $request] = 0;
693
+	}
651 694
 
652 695
 	// Return the right row.
653 696
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -700,11 +743,13 @@  discard block
 block discarded – undo
700 743
 
701 744
 	$replace = '';
702 745
 
703
-	if (empty($data))
704
-		return;
746
+	if (empty($data)) {
747
+			return;
748
+	}
705 749
 
706
-	if (!is_array($data[array_rand($data)]))
707
-		$data = array($data);
750
+	if (!is_array($data[array_rand($data)])) {
751
+			$data = array($data);
752
+	}
708 753
 
709 754
 	// Replace the prefix holder with the actual prefix.
710 755
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -723,11 +768,13 @@  discard block
 block discarded – undo
723 768
 			//pg 9.5 got replace support
724 769
 			$pg_version = $smcFunc['db_get_version']();
725 770
 			// if we got a Beta Version
726
-			if (stripos($pg_version, 'beta') !== false)
727
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
771
+			if (stripos($pg_version, 'beta') !== false) {
772
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
773
+			}
728 774
 			// or RC
729
-			if (stripos($pg_version, 'rc') !== false)
730
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
775
+			if (stripos($pg_version, 'rc') !== false) {
776
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
777
+			}
731 778
 
732 779
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
733 780
 		}
@@ -746,8 +793,7 @@  discard block
 block discarded – undo
746 793
 					$key_str .= ($count_pk > 0 ? ',' : '');
747 794
 					$key_str .= $columnName;
748 795
 					$count_pk++;
749
-				}
750
-				else //normal field
796
+				} else //normal field
751 797
 				{
752 798
 					$col_str .= ($count > 0 ? ',' : '');
753 799
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -755,20 +801,21 @@  discard block
 block discarded – undo
755 801
 				}
756 802
 			}
757 803
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
758
-		}
759
-		else
804
+		} else
760 805
 		{
761 806
 			foreach ($columns as $columnName => $type)
762 807
 			{
763 808
 				// Are we restricting the length?
764
-				if (strpos($type, 'string-') !== false)
765
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
766
-				else
767
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
809
+				if (strpos($type, 'string-') !== false) {
810
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
811
+				} else {
812
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
813
+				}
768 814
 
769 815
 				// A key? That's what we were looking for.
770
-				if (in_array($columnName, $keys))
771
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
816
+				if (in_array($columnName, $keys)) {
817
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
818
+				}
772 819
 				$count++;
773 820
 			}
774 821
 
@@ -804,10 +851,11 @@  discard block
 block discarded – undo
804 851
 		foreach ($columns as $columnName => $type)
805 852
 		{
806 853
 			// Are we restricting the length?
807
-			if (strpos($type, 'string-') !== false)
808
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
809
-			else
810
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+			if (strpos($type, 'string-') !== false) {
855
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
856
+			} else {
857
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
858
+			}
811 859
 		}
812 860
 		$insertData = substr($insertData, 0, -2) . ')';
813 861
 
@@ -816,8 +864,9 @@  discard block
 block discarded – undo
816 864
 
817 865
 		// Here's where the variables are injected to the query.
818 866
 		$insertRows = array();
819
-		foreach ($data as $dataRow)
820
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
867
+		foreach ($data as $dataRow) {
868
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
869
+		}
821 870
 
822 871
 		// Do the insert.
823 872
 		$request = $smcFunc['db_query']('', '
@@ -834,19 +883,21 @@  discard block
 block discarded – undo
834 883
 
835 884
 		if ($with_returning && $request !== false)
836 885
 		{
837
-			if ($returnmode === 2)
838
-				$return_var = array();
886
+			if ($returnmode === 2) {
887
+							$return_var = array();
888
+			}
839 889
 
840 890
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
841 891
 			{
842
-				if (is_numeric($row[0])) // try to emulate mysql limitation
892
+				if (is_numeric($row[0])) {
893
+					// try to emulate mysql limitation
843 894
 				{
844 895
 					if ($returnmode === 1)
845 896
 						$return_var = $row[0];
846
-					elseif ($returnmode === 2)
847
-						$return_var[] = $row[0];
848
-				}
849
-				else
897
+				} elseif ($returnmode === 2) {
898
+											$return_var[] = $row[0];
899
+					}
900
+				} else
850 901
 				{
851 902
 					$with_returning = false;
852 903
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -855,9 +906,10 @@  discard block
 block discarded – undo
855 906
 		}
856 907
 	}
857 908
 
858
-	if ($with_returning && !empty($return_var))
859
-		return $return_var;
860
-}
909
+	if ($with_returning && !empty($return_var)) {
910
+			return $return_var;
911
+	}
912
+	}
861 913
 
862 914
 /**
863 915
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -894,8 +946,9 @@  discard block
 block discarded – undo
894 946
  */
895 947
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
896 948
 {
897
-	if (empty($log_message))
898
-		$log_message = $error_message;
949
+	if (empty($log_message)) {
950
+			$log_message = $error_message;
951
+	}
899 952
 
900 953
 	foreach (debug_backtrace() as $step)
901 954
 	{
@@ -914,12 +967,14 @@  discard block
 block discarded – undo
914 967
 	}
915 968
 
916 969
 	// A special case - we want the file and line numbers for debugging.
917
-	if ($error_type == 'return')
918
-		return array($file, $line);
970
+	if ($error_type == 'return') {
971
+			return array($file, $line);
972
+	}
919 973
 
920 974
 	// Is always a critical error.
921
-	if (function_exists('log_error'))
922
-		log_error($log_message, 'critical', $file, $line);
975
+	if (function_exists('log_error')) {
976
+			log_error($log_message, 'critical', $file, $line);
977
+	}
923 978
 
924 979
 	if (function_exists('fatal_error'))
925 980
 	{
@@ -927,12 +982,12 @@  discard block
 block discarded – undo
927 982
 
928 983
 		// Cannot continue...
929 984
 		exit;
985
+	} elseif ($error_type) {
986
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
987
+	} else {
988
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
989
+	}
930 990
 	}
931
-	elseif ($error_type)
932
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
933
-	else
934
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
935
-}
936 991
 
937 992
 /**
938 993
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -949,10 +1004,11 @@  discard block
 block discarded – undo
949 1004
 		'\\' => '\\\\',
950 1005
 	);
951 1006
 
952
-	if ($translate_human_wildcards)
953
-		$replacements += array(
1007
+	if ($translate_human_wildcards) {
1008
+			$replacements += array(
954 1009
 			'*' => '%',
955 1010
 		);
1011
+	}
956 1012
 
957 1013
 	return strtr($string, $replacements);
958 1014
 }
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -5370,7 +5370,6 @@  discard block
 block discarded – undo
5370 5370
 
5371 5371
 /**
5372 5372
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5373
-
5374 5373
  * @param string $file The file/dir full path.
5375 5374
  * @param int $value Not needed, added for legacy reasons.
5376 5375
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5410,7 +5409,6 @@  discard block
 block discarded – undo
5410 5409
 
5411 5410
 /**
5412 5411
  * Wrapper function for json_decode() with error handling.
5413
-
5414 5412
  * @param string $json The string to decode.
5415 5413
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5416 5414
  * @param bool $logIt To specify if the error will be logged if theres any.
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  * - caches the formatting data from the setting for optimization.
677 677
  *
678 678
  * @param float $number A number
679
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
679
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
680 680
  * @return string A formatted number
681 681
  */
682 682
 function comma_format($number, $override_decimal_count = false)
@@ -5527,7 +5527,7 @@  discard block
 block discarded – undo
5527 5527
  * It assumes the data is already a string.
5528 5528
  * @param string $data The data to print
5529 5529
  * @param string $type The content type. Defaults to Json.
5530
- * @return void
5530
+ * @return false|null
5531 5531
  */
5532 5532
 function smf_serverResponse($data = '', $type = 'Content-Type: application/json')
5533 5533
 {
Please login to merge, or discard this patch.
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 		if (empty($low_id))
600 600
 			$pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
601 601
 		else
602
-			$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id);
602
+			$pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L' . $low_id);
603 603
 		
604 604
 		// Show all the pages.
605 605
 		$display_page = 1;
@@ -608,11 +608,11 @@  discard block
 block discarded – undo
608 608
 
609 609
 		// Show the right arrow.
610 610
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
611
-		if ($start != $counter - $max_value && !$start_invalid){
611
+		if ($start != $counter - $max_value && !$start_invalid) {
612 612
 			if (empty($max_id))
613 613
 				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
614 614
 			else
615
-				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id);
615
+				$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page, $settings['page_index']['next_page'], 'M' . $max_id);
616 616
 		}
617 617
 			
618 618
 	}
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 			if (empty($low_id))
627 627
 				$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628 628
 			else
629
-				$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id);
629
+				$pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L' . $low_id);
630 630
 		else
631 631
 			$pageindex .= '';
632 632
 
@@ -648,10 +648,10 @@  discard block
 block discarded – undo
648 648
 			if ($start >= $num_per_page * $nCont)
649 649
 			{
650 650
 				$tmpStart = $start - $num_per_page * $nCont;
651
-				if($nCont != 1 || empty($low_id))
651
+				if ($nCont != 1 || empty($low_id))
652 652
 					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
653 653
 				else
654
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id);
654
+					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L' . $low_id);
655 655
 			}
656 656
 
657 657
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
 			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 667
 			{
668 668
 				$tmpStart = $start + $num_per_page * $nCont;
669
-				if($nCont != 1 || empty($max_id))
669
+				if ($nCont != 1 || empty($max_id))
670 670
 					$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
671 671
 				else
672
-					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id);
672
+					$pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M' . $max_id);
673 673
 			}
674 674
 
675 675
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 			if (empty($max_id))
691 691
 				$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
692 692
 			else
693
-				$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id);
693
+				$pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M' . $max_id);
694 694
 	}
695 695
 	$pageindex .= $settings['page_index']['extra_after'];
696 696
 
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1126 1126
 				),
1127 1127
 				'content' => '$1',
1128
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1128
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1129 1129
 				{
1130 1130
 					$returnContext = '';
1131 1131
 
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
 						}
1161 1161
 
1162 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>';
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 1164
 						else
1165 1165
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1166 1166
 					}
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 				'type' => 'unparsed_content',
1190 1190
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1191 1191
 				// @todo Maybe this can be simplified?
1192
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1192
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1193 1193
 				{
1194 1194
 					if (!isset($disabled['code']))
1195 1195
 					{
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
 				'type' => 'unparsed_equals_content',
1227 1227
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1228 1228
 				// @todo Maybe this can be simplified?
1229
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1229
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1230 1230
 				{
1231 1231
 					if (!isset($disabled['code']))
1232 1232
 					{
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
 				'type' => 'unparsed_content',
1271 1271
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1272 1272
 				// @todo Should this respect guest_hideContacts?
1273
-				'validate' => function (&$tag, &$data, $disabled)
1273
+				'validate' => function(&$tag, &$data, $disabled)
1274 1274
 				{
1275 1275
 					$data = strtr($data, array('<br>' => ''));
1276 1276
 				},
@@ -1289,7 +1289,7 @@  discard block
 block discarded – undo
1289 1289
 				'type' => 'unparsed_commas_content',
1290 1290
 				'test' => '\d+,\d+\]',
1291 1291
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1292
-				'validate' => function (&$tag, &$data, $disabled)
1292
+				'validate' => function(&$tag, &$data, $disabled)
1293 1293
 				{
1294 1294
 					if (isset($disabled['url']))
1295 1295
 						$tag['content'] = '$1';
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1306 1306
 				'before' => '<div $1>',
1307 1307
 				'after' => '</div>',
1308
-				'validate' => function (&$tag, &$data, $disabled)
1308
+				'validate' => function(&$tag, &$data, $disabled)
1309 1309
 				{
1310 1310
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1311 1311
 
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1355 1355
 				),
1356 1356
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1357
-				'validate' => function (&$tag, &$data, $disabled)
1357
+				'validate' => function(&$tag, &$data, $disabled)
1358 1358
 				{
1359 1359
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1360 1360
 
@@ -1377,7 +1377,7 @@  discard block
 block discarded – undo
1377 1377
 				'tag' => 'img',
1378 1378
 				'type' => 'unparsed_content',
1379 1379
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1380
-				'validate' => function (&$tag, &$data, $disabled)
1380
+				'validate' => function(&$tag, &$data, $disabled)
1381 1381
 				{
1382 1382
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1383 1383
 
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 				'tag' => 'iurl',
1401 1401
 				'type' => 'unparsed_content',
1402 1402
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1403
-				'validate' => function (&$tag, &$data, $disabled)
1403
+				'validate' => function(&$tag, &$data, $disabled)
1404 1404
 				{
1405 1405
 					$data = strtr($data, array('<br>' => ''));
1406 1406
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
 				'quoted' => 'optional',
1415 1415
 				'before' => '<a href="$1" class="bbc_link">',
1416 1416
 				'after' => '</a>',
1417
-				'validate' => function (&$tag, &$data, $disabled)
1417
+				'validate' => function(&$tag, &$data, $disabled)
1418 1418
 				{
1419 1419
 					if (substr($data, 0, 1) == '#')
1420 1420
 						$data = '#post_' . substr($data, 1);
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
 				'tag' => 'php',
1495 1495
 				'type' => 'unparsed_content',
1496 1496
 				'content' => '<span class="phpcode">$1</span>',
1497
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1497
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1498 1498
 				{
1499 1499
 					if (!isset($disabled['php']))
1500 1500
 					{
@@ -1592,7 +1592,7 @@  discard block
 block discarded – undo
1592 1592
 				'test' => '[1-7]\]',
1593 1593
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1594 1594
 				'after' => '</span>',
1595
-				'validate' => function (&$tag, &$data, $disabled)
1595
+				'validate' => function(&$tag, &$data, $disabled)
1596 1596
 				{
1597 1597
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1598 1598
 					$data = $sizes[$data] . 'em';
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
 				'tag' => 'time',
1631 1631
 				'type' => 'unparsed_content',
1632 1632
 				'content' => '$1',
1633
-				'validate' => function (&$tag, &$data, $disabled)
1633
+				'validate' => function(&$tag, &$data, $disabled)
1634 1634
 				{
1635 1635
 					if (is_numeric($data))
1636 1636
 						$data = timeformat($data);
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
 				'tag' => 'url',
1659 1659
 				'type' => 'unparsed_content',
1660 1660
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1661
-				'validate' => function (&$tag, &$data, $disabled)
1661
+				'validate' => function(&$tag, &$data, $disabled)
1662 1662
 				{
1663 1663
 					$data = strtr($data, array('<br>' => ''));
1664 1664
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1672,7 +1672,7 @@  discard block
 block discarded – undo
1672 1672
 				'quoted' => 'optional',
1673 1673
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1674 1674
 				'after' => '</a>',
1675
-				'validate' => function (&$tag, &$data, $disabled)
1675
+				'validate' => function(&$tag, &$data, $disabled)
1676 1676
 				{
1677 1677
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1678 1678
 					if (empty($scheme))
@@ -1698,7 +1698,7 @@  discard block
 block discarded – undo
1698 1698
 		{
1699 1699
 			if (isset($temp_bbc))
1700 1700
 				$bbc_codes = $temp_bbc;
1701
-			usort($codes, function ($a, $b) {
1701
+			usort($codes, function($a, $b) {
1702 1702
 				return strcmp($a['tag'], $b['tag']);
1703 1703
 			});
1704 1704
 			return $codes;
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
 										# a run of Unicode domain name characters and a dot
1937 1937
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1938 1938
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1939
-										(?:'. $modSettings['tld_regex'] .'|local)
1939
+										(?:'. $modSettings['tld_regex'] . '|local)
1940 1940
 									)
1941 1941
 									# followed by a non-domain character or end of line
1942 1942
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -2004,7 +2004,7 @@  discard block
 block discarded – undo
2004 2004
 						)?
2005 2005
 						';
2006 2006
 
2007
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
2007
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
2008 2008
 							$url = array_shift($matches);
2009 2009
 
2010 2010
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2741,7 +2741,7 @@  discard block
 block discarded – undo
2741 2741
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2742 2742
 		{
2743 2743
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2744
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2744
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2745 2745
 
2746 2746
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2747 2747
 
@@ -2758,7 +2758,7 @@  discard block
 block discarded – undo
2758 2758
 
2759 2759
 	// Replace away!
2760 2760
 	$message = preg_replace_callback($smileyPregSearch,
2761
-		function ($matches) use ($smileyPregReplacements)
2761
+		function($matches) use ($smileyPregReplacements)
2762 2762
 		{
2763 2763
 			return $smileyPregReplacements[$matches[1]];
2764 2764
 		}, $message);
@@ -2824,13 +2824,13 @@  discard block
 block discarded – undo
2824 2824
 	{
2825 2825
 		if (defined('SID') && SID != '')
2826 2826
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2827
-				function ($m) use ($scripturl)
2827
+				function($m) use ($scripturl)
2828 2828
 				{
2829
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2829
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2830 2830
 				}, $setLocation);
2831 2831
 		else
2832 2832
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2833
-				function ($m) use ($scripturl)
2833
+				function($m) use ($scripturl)
2834 2834
 				{
2835 2835
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2836 2836
 				}, $setLocation);
@@ -3153,7 +3153,7 @@  discard block
 block discarded – undo
3153 3153
 
3154 3154
 	// Add a generic "Are you sure?" confirmation message.
3155 3155
 	addInlineJavaScript('
3156
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3156
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3157 3157
 
3158 3158
 	// Now add the capping code for avatars.
3159 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')
@@ -3514,7 +3514,7 @@  discard block
 block discarded – undo
3514 3514
 
3515 3515
 		else
3516 3516
 			echo '
3517
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3517
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3518 3518
 	}
3519 3519
 
3520 3520
 	// Inline JavaScript - Actually useful some times!
@@ -3592,14 +3592,14 @@  discard block
 block discarded – undo
3592 3592
 
3593 3593
 		else
3594 3594
 			echo '
3595
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3595
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3596 3596
 	}
3597 3597
 
3598 3598
 	// Print the rest after the minified files.
3599 3599
 	if (!empty($normal))
3600 3600
 		foreach ($normal as $nf)
3601 3601
 			echo '
3602
-	<link rel="stylesheet" href="', $nf ,'">';
3602
+	<link rel="stylesheet" href="', $nf, '">';
3603 3603
 
3604 3604
 	if ($db_show_debug === true)
3605 3605
 	{
@@ -3615,7 +3615,7 @@  discard block
 block discarded – undo
3615 3615
 	<style>';
3616 3616
 
3617 3617
 		foreach ($context['css_header'] as $css)
3618
-			echo $css .'
3618
+			echo $css . '
3619 3619
 	';
3620 3620
 
3621 3621
 		echo'
@@ -3644,27 +3644,27 @@  discard block
 block discarded – undo
3644 3644
 		return false;
3645 3645
 
3646 3646
 	// Did we already did this?
3647
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3647
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3648 3648
 
3649 3649
 	// Already done?
3650 3650
 	if (!empty($toCache))
3651 3651
 		return true;
3652 3652
 
3653 3653
 	// No namespaces, sorry!
3654
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3654
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3655 3655
 
3656 3656
 	// Temp path.
3657
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3657
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3658 3658
 
3659 3659
 	// What kind of file are we going to create?
3660
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3660
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3661 3661
 
3662 3662
 	// File has to exists, if it isn't try to create it.
3663 3663
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3664 3664
 	{
3665 3665
 		loadLanguage('Errors');
3666 3666
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3667
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3667
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3668 3668
 
3669 3669
 		// The process failed so roll back to print each individual file.
3670 3670
 		return $data;
@@ -3699,14 +3699,14 @@  discard block
 block discarded – undo
3699 3699
 	{
3700 3700
 		loadLanguage('Errors');
3701 3701
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3702
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3702
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3703 3703
 
3704 3704
 		// The process failed so roll back to print each individual file.
3705 3705
 		return $data;
3706 3706
 	}
3707 3707
 
3708 3708
 	// And create a long lived cache entry.
3709
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3709
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3710 3710
 
3711 3711
 	return true;
3712 3712
 }
@@ -3766,7 +3766,7 @@  discard block
 block discarded – undo
3766 3766
 	else
3767 3767
 		$path = $modSettings['attachmentUploadDir'];
3768 3768
 
3769
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3769
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3770 3770
 }
3771 3771
 
3772 3772
 /**
@@ -3810,10 +3810,10 @@  discard block
 block discarded – undo
3810 3810
 		$valid_low = isValidIP($ip_parts[0]);
3811 3811
 		$valid_high = isValidIP($ip_parts[1]);
3812 3812
 		$count = 0;
3813
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3813
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3814 3814
 		$max = ($mode == ':' ? 'ffff' : '255');
3815 3815
 		$min = 0;
3816
-		if(!$valid_low)
3816
+		if (!$valid_low)
3817 3817
 		{
3818 3818
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3819 3819
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3827,7 +3827,7 @@  discard block
 block discarded – undo
3827 3827
 		}
3828 3828
 
3829 3829
 		$count = 0;
3830
-		if(!$valid_high)
3830
+		if (!$valid_high)
3831 3831
 		{
3832 3832
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3833 3833
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3840,7 +3840,7 @@  discard block
 block discarded – undo
3840 3840
 			}
3841 3841
 		}
3842 3842
 
3843
-		if($valid_high && $valid_low)
3843
+		if ($valid_high && $valid_low)
3844 3844
 		{
3845 3845
 			$ip_array['low'] = $ip_parts[0];
3846 3846
 			$ip_array['high'] = $ip_parts[1];
@@ -4022,7 +4022,7 @@  discard block
 block discarded – undo
4022 4022
 		addInlineJavaScript('
4023 4023
 	var user_menus = new smc_PopupMenu();
4024 4024
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4025
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4025
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4026 4026
 		if ($context['allow_pm'])
4027 4027
 			addInlineJavaScript('
4028 4028
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4644,7 +4644,7 @@  discard block
 block discarded – undo
4644 4644
 		// No? try a fallback to $sourcedir
4645 4645
 		else
4646 4646
 		{
4647
-			$absPath = $sourcedir .'/'. $file;
4647
+			$absPath = $sourcedir . '/' . $file;
4648 4648
 
4649 4649
 			if (file_exists($absPath))
4650 4650
 				require_once($absPath);
@@ -4725,15 +4725,15 @@  discard block
 block discarded – undo
4725 4725
 
4726 4726
 	// UTF-8 occurences of MS special characters
4727 4727
 	$findchars_utf8 = array(
4728
-		"\xe2\x80\x9a",	// single low-9 quotation mark
4729
-		"\xe2\x80\x9e",	// double low-9 quotation mark
4730
-		"\xe2\x80\xa6",	// horizontal ellipsis
4731
-		"\xe2\x80\x98",	// left single curly quote
4732
-		"\xe2\x80\x99",	// right single curly quote
4733
-		"\xe2\x80\x9c",	// left double curly quote
4734
-		"\xe2\x80\x9d",	// right double curly quote
4735
-		"\xe2\x80\x93",	// en dash
4736
-		"\xe2\x80\x94",	// em dash
4728
+		"\xe2\x80\x9a", // single low-9 quotation mark
4729
+		"\xe2\x80\x9e", // double low-9 quotation mark
4730
+		"\xe2\x80\xa6", // horizontal ellipsis
4731
+		"\xe2\x80\x98", // left single curly quote
4732
+		"\xe2\x80\x99", // right single curly quote
4733
+		"\xe2\x80\x9c", // left double curly quote
4734
+		"\xe2\x80\x9d", // right double curly quote
4735
+		"\xe2\x80\x93", // en dash
4736
+		"\xe2\x80\x94", // em dash
4737 4737
 	);
4738 4738
 
4739 4739
 	// windows 1252 / iso equivalents
@@ -4751,15 +4751,15 @@  discard block
 block discarded – undo
4751 4751
 
4752 4752
 	// safe replacements
4753 4753
 	$replacechars = array(
4754
-		',',	// &sbquo;
4755
-		',,',	// &bdquo;
4756
-		'...',	// &hellip;
4757
-		"'",	// &lsquo;
4758
-		"'",	// &rsquo;
4759
-		'"',	// &ldquo;
4760
-		'"',	// &rdquo;
4761
-		'-',	// &ndash;
4762
-		'--',	// &mdash;
4754
+		',', // &sbquo;
4755
+		',,', // &bdquo;
4756
+		'...', // &hellip;
4757
+		"'", // &lsquo;
4758
+		"'", // &rsquo;
4759
+		'"', // &ldquo;
4760
+		'"', // &rdquo;
4761
+		'-', // &ndash;
4762
+		'--', // &mdash;
4763 4763
 	);
4764 4764
 
4765 4765
 	if ($context['utf8'])
@@ -5177,7 +5177,7 @@  discard block
 block discarded – undo
5177 5177
  */
5178 5178
 function inet_dtop($bin)
5179 5179
 {
5180
-	if(empty($bin))
5180
+	if (empty($bin))
5181 5181
 		return '';
5182 5182
 
5183 5183
 	global $db_type;
@@ -5208,28 +5208,28 @@  discard block
 block discarded – undo
5208 5208
  */
5209 5209
 function _safe_serialize($value)
5210 5210
 {
5211
-	if(is_null($value))
5211
+	if (is_null($value))
5212 5212
 		return 'N;';
5213 5213
 
5214
-	if(is_bool($value))
5215
-		return 'b:'. (int) $value .';';
5214
+	if (is_bool($value))
5215
+		return 'b:' . (int) $value . ';';
5216 5216
 
5217
-	if(is_int($value))
5218
-		return 'i:'. $value .';';
5217
+	if (is_int($value))
5218
+		return 'i:' . $value . ';';
5219 5219
 
5220
-	if(is_float($value))
5221
-		return 'd:'. str_replace(',', '.', $value) .';';
5220
+	if (is_float($value))
5221
+		return 'd:' . str_replace(',', '.', $value) . ';';
5222 5222
 
5223
-	if(is_string($value))
5224
-		return 's:'. strlen($value) .':"'. $value .'";';
5223
+	if (is_string($value))
5224
+		return 's:' . strlen($value) . ':"' . $value . '";';
5225 5225
 
5226
-	if(is_array($value))
5226
+	if (is_array($value))
5227 5227
 	{
5228 5228
 		$out = '';
5229
-		foreach($value as $k => $v)
5229
+		foreach ($value as $k => $v)
5230 5230
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5231 5231
 
5232
-		return 'a:'. count($value) .':{'. $out .'}';
5232
+		return 'a:' . count($value) . ':{' . $out . '}';
5233 5233
 	}
5234 5234
 
5235 5235
 	// safe_serialize cannot serialize resources or objects.
@@ -5271,7 +5271,7 @@  discard block
 block discarded – undo
5271 5271
 function _safe_unserialize($str)
5272 5272
 {
5273 5273
 	// Input  is not a string.
5274
-	if(empty($str) || !is_string($str))
5274
+	if (empty($str) || !is_string($str))
5275 5275
 		return false;
5276 5276
 
5277 5277
 	$stack = array();
@@ -5285,40 +5285,40 @@  discard block
 block discarded – undo
5285 5285
 	 *   3 - in array, expecting value or another array
5286 5286
 	 */
5287 5287
 	$state = 0;
5288
-	while($state != 1)
5288
+	while ($state != 1)
5289 5289
 	{
5290 5290
 		$type = isset($str[0]) ? $str[0] : '';
5291
-		if($type == '}')
5291
+		if ($type == '}')
5292 5292
 			$str = substr($str, 1);
5293 5293
 
5294
-		else if($type == 'N' && $str[1] == ';')
5294
+		else if ($type == 'N' && $str[1] == ';')
5295 5295
 		{
5296 5296
 			$value = null;
5297 5297
 			$str = substr($str, 2);
5298 5298
 		}
5299
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5299
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5300 5300
 		{
5301 5301
 			$value = $matches[1] == '1' ? true : false;
5302 5302
 			$str = substr($str, 4);
5303 5303
 		}
5304
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5304
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5305 5305
 		{
5306
-			$value = (int)$matches[1];
5306
+			$value = (int) $matches[1];
5307 5307
 			$str = $matches[2];
5308 5308
 		}
5309
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5309
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5310 5310
 		{
5311
-			$value = (float)$matches[1];
5311
+			$value = (float) $matches[1];
5312 5312
 			$str = $matches[3];
5313 5313
 		}
5314
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5314
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5315 5315
 		{
5316
-			$value = substr($matches[2], 0, (int)$matches[1]);
5317
-			$str = substr($matches[2], (int)$matches[1] + 2);
5316
+			$value = substr($matches[2], 0, (int) $matches[1]);
5317
+			$str = substr($matches[2], (int) $matches[1] + 2);
5318 5318
 		}
5319
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5319
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5320 5320
 		{
5321
-			$expectedLength = (int)$matches[1];
5321
+			$expectedLength = (int) $matches[1];
5322 5322
 			$str = $matches[2];
5323 5323
 		}
5324 5324
 
@@ -5326,10 +5326,10 @@  discard block
 block discarded – undo
5326 5326
 		else
5327 5327
 			return false;
5328 5328
 
5329
-		switch($state)
5329
+		switch ($state)
5330 5330
 		{
5331 5331
 			case 3: // In array, expecting value or another array.
5332
-				if($type == 'a')
5332
+				if ($type == 'a')
5333 5333
 				{
5334 5334
 					$stack[] = &$list;
5335 5335
 					$list[$key] = array();
@@ -5338,7 +5338,7 @@  discard block
 block discarded – undo
5338 5338
 					$state = 2;
5339 5339
 					break;
5340 5340
 				}
5341
-				if($type != '}')
5341
+				if ($type != '}')
5342 5342
 				{
5343 5343
 					$list[$key] = $value;
5344 5344
 					$state = 2;
@@ -5349,29 +5349,29 @@  discard block
 block discarded – undo
5349 5349
 				return false;
5350 5350
 
5351 5351
 			case 2: // in array, expecting end of array or a key
5352
-				if($type == '}')
5352
+				if ($type == '}')
5353 5353
 				{
5354 5354
 					// Array size is less than expected.
5355
-					if(count($list) < end($expected))
5355
+					if (count($list) < end($expected))
5356 5356
 						return false;
5357 5357
 
5358 5358
 					unset($list);
5359
-					$list = &$stack[count($stack)-1];
5359
+					$list = &$stack[count($stack) - 1];
5360 5360
 					array_pop($stack);
5361 5361
 
5362 5362
 					// Go to terminal state if we're at the end of the root array.
5363 5363
 					array_pop($expected);
5364 5364
 
5365
-					if(count($expected) == 0)
5365
+					if (count($expected) == 0)
5366 5366
 						$state = 1;
5367 5367
 
5368 5368
 					break;
5369 5369
 				}
5370 5370
 
5371
-				if($type == 'i' || $type == 's')
5371
+				if ($type == 'i' || $type == 's')
5372 5372
 				{
5373 5373
 					// Array size exceeds expected length.
5374
-					if(count($list) >= end($expected))
5374
+					if (count($list) >= end($expected))
5375 5375
 						return false;
5376 5376
 
5377 5377
 					$key = $value;
@@ -5384,7 +5384,7 @@  discard block
 block discarded – undo
5384 5384
 
5385 5385
 			// Expecting array or value.
5386 5386
 			case 0:
5387
-				if($type == 'a')
5387
+				if ($type == 'a')
5388 5388
 				{
5389 5389
 					$data = array();
5390 5390
 					$list = &$data;
@@ -5393,7 +5393,7 @@  discard block
 block discarded – undo
5393 5393
 					break;
5394 5394
 				}
5395 5395
 
5396
-				if($type != '}')
5396
+				if ($type != '}')
5397 5397
 				{
5398 5398
 					$data = $value;
5399 5399
 					$state = 1;
@@ -5406,7 +5406,7 @@  discard block
 block discarded – undo
5406 5406
 	}
5407 5407
 
5408 5408
 	// Trailing data in input.
5409
-	if(!empty($str))
5409
+	if (!empty($str))
5410 5410
 		return false;
5411 5411
 
5412 5412
 	return $data;
@@ -5460,7 +5460,7 @@  discard block
 block discarded – undo
5460 5460
 	// Set different modes.
5461 5461
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5462 5462
 
5463
-	foreach($chmodValues as $val)
5463
+	foreach ($chmodValues as $val)
5464 5464
 	{
5465 5465
 		// If it's writable, break out of the loop.
5466 5466
 		if (is_writable($file))
@@ -5495,13 +5495,13 @@  discard block
 block discarded – undo
5495 5495
 	$returnArray = @json_decode($json, $returnAsArray);
5496 5496
 
5497 5497
 	// PHP 5.3 so no json_last_error_msg()
5498
-	switch(json_last_error())
5498
+	switch (json_last_error())
5499 5499
 	{
5500 5500
 		case JSON_ERROR_NONE:
5501 5501
 			$jsonError = false;
5502 5502
 			break;
5503 5503
 		case JSON_ERROR_DEPTH:
5504
-			$jsonError =  'JSON_ERROR_DEPTH';
5504
+			$jsonError = 'JSON_ERROR_DEPTH';
5505 5505
 			break;
5506 5506
 		case JSON_ERROR_STATE_MISMATCH:
5507 5507
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5529,10 +5529,10 @@  discard block
 block discarded – undo
5529 5529
 		loadLanguage('Errors');
5530 5530
 
5531 5531
 		if (!empty($jsonDebug))
5532
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5532
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5533 5533
 
5534 5534
 		else
5535
-			log_error($txt['json_'. $jsonError], 'critical');
5535
+			log_error($txt['json_' . $jsonError], 'critical');
5536 5536
 
5537 5537
 		// Everyone expects an array.
5538 5538
 		return array();
@@ -5636,7 +5636,7 @@  discard block
 block discarded – undo
5636 5636
 		});
5637 5637
 
5638 5638
 		// Convert Punycode to Unicode
5639
-		$tlds = array_map(function ($input) {
5639
+		$tlds = array_map(function($input) {
5640 5640
 			$prefix = 'xn--';
5641 5641
 			$safe_char = 0xFFFC;
5642 5642
 			$base = 36;
@@ -5652,7 +5652,7 @@  discard block
 block discarded – undo
5652 5652
 
5653 5653
 			foreach ($enco_parts as $encoded)
5654 5654
 			{
5655
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5655
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5656 5656
 				{
5657 5657
 					$output_parts[] = $encoded;
5658 5658
 					continue;
@@ -5663,7 +5663,7 @@  discard block
 block discarded – undo
5663 5663
 				$idx = 0;
5664 5664
 				$char = 0x80;
5665 5665
 				$decoded = array();
5666
-				$output='';
5666
+				$output = '';
5667 5667
 				$delim_pos = strrpos($encoded, '-');
5668 5668
 
5669 5669
 				if ($delim_pos > strlen($prefix))
@@ -5679,7 +5679,7 @@  discard block
 block discarded – undo
5679 5679
 
5680 5680
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5681 5681
 				{
5682
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5682
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5683 5683
 					{
5684 5684
 						$cp = ord($encoded{$enco_idx++});
5685 5685
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5720,15 +5720,15 @@  discard block
 block discarded – undo
5720 5720
 
5721 5721
 					// 2 bytes
5722 5722
 					elseif ($v < (1 << 11))
5723
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5723
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5724 5724
 
5725 5725
 					// 3 bytes
5726 5726
 					elseif ($v < (1 << 16))
5727
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5727
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5728 5728
 
5729 5729
 					// 4 bytes
5730 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));
5731
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5732 5732
 
5733 5733
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5734 5734
 					else
@@ -5835,7 +5835,7 @@  discard block
 block discarded – undo
5835 5835
 	}
5836 5836
 
5837 5837
 	// This recursive function creates the index array from the strings
5838
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5838
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5839 5839
 	{
5840 5840
 		static $depth = 0;
5841 5841
 		$depth++;
@@ -5862,7 +5862,7 @@  discard block
 block discarded – undo
5862 5862
 	};
5863 5863
 
5864 5864
 	// This recursive function turns the index array into a regular expression
5865
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5865
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5866 5866
 	{
5867 5867
 		static $depth = 0;
5868 5868
 		$depth++;
@@ -5886,11 +5886,11 @@  discard block
 block discarded – undo
5886 5886
 
5887 5887
 				if (count(array_keys($value)) == 1)
5888 5888
 				{
5889
-					$new_key_array = explode('(?'.'>', $sub_regex);
5889
+					$new_key_array = explode('(?' . '>', $sub_regex);
5890 5890
 					$new_key .= $new_key_array[0];
5891 5891
 				}
5892 5892
 				else
5893
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5893
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5894 5894
 			}
5895 5895
 
5896 5896
 			if ($depth > 1)
@@ -5930,7 +5930,7 @@  discard block
 block discarded – undo
5930 5930
 		$index = $add_string_to_index($string, $index);
5931 5931
 
5932 5932
 	while (!empty($index))
5933
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5933
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5934 5934
 
5935 5935
 	// Restore PHP's internal character encoding to whatever it was originally
5936 5936
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Braces   +1321 added lines, -983 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];
@@ -751,17 +788,20 @@  discard block
 block discarded – undo
751 788
 	static $local_cache;
752 789
 
753 790
 	// Offset the time.
754
-	if (!$offset_type)
755
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
791
+	if (!$offset_type) {
792
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
793
+	}
756 794
 	// Just the forum offset?
757
-	elseif ($offset_type == 'forum')
758
-		$time = $log_time + $modSettings['time_offset'] * 3600;
759
-	else
760
-		$time = $log_time;
795
+	elseif ($offset_type == 'forum') {
796
+			$time = $log_time + $modSettings['time_offset'] * 3600;
797
+	} else {
798
+			$time = $log_time;
799
+	}
761 800
 
762 801
 	// We can't have a negative date (on Windows, at least.)
763
-	if ($log_time < 0)
764
-		$log_time = 0;
802
+	if ($log_time < 0) {
803
+			$log_time = 0;
804
+	}
765 805
 
766 806
 	// Today and Yesterday?
767 807
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -778,56 +818,65 @@  discard block
 block discarded – undo
778 818
 		{
779 819
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
780 820
 			$today_fmt = $h . ':%M' . $s . ' %p';
821
+		} else {
822
+					$today_fmt = '%H:%M' . $s;
781 823
 		}
782
-		else
783
-			$today_fmt = '%H:%M' . $s;
784 824
 
785 825
 		// Same day of the year, same year.... Today!
786
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
787
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
826
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
827
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
828
+		}
788 829
 
789 830
 		// 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...
790
-		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))
791
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
831
+		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)) {
832
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
833
+		}
792 834
 	}
793 835
 
794 836
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
795 837
 
796
-	if (!isset($local_cache))
797
-		$local_cache = setlocale(LC_TIME, $txt['lang_locale']);
838
+	if (!isset($local_cache)) {
839
+			$local_cache = setlocale(LC_TIME, $txt['lang_locale']);
840
+	}
798 841
 
799 842
 	if ($local_cache !== false)
800 843
 	{
801 844
 		//check if other process change the local
802 845
 		if ($process_safe === true)
803 846
 		{
804
-			if (setlocale(LC_TIME, '0') != $local_cache)
805
-				setlocale(LC_TIME, $txt['lang_locale']);
847
+			if (setlocale(LC_TIME, '0') != $local_cache) {
848
+							setlocale(LC_TIME, $txt['lang_locale']);
849
+			}
806 850
 		}
807 851
 
808
-		if (!isset($non_twelve_hour))
809
-			$non_twelve_hour = trim(strftime('%p')) === '';
810
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
811
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
852
+		if (!isset($non_twelve_hour)) {
853
+					$non_twelve_hour = trim(strftime('%p')) === '';
854
+		}
855
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
856
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
857
+		}
812 858
 
813
-		foreach (array('%a', '%A', '%b', '%B') as $token)
814
-			if (strpos($str, $token) !== false)
859
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
860
+					if (strpos($str, $token) !== false)
815 861
 				$str = str_replace($token, strftime($token, $time), $str);
816
-	}
817
-	else
862
+		}
863
+	} else
818 864
 	{
819 865
 		// Do-it-yourself time localization.  Fun.
820
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
821
-			if (strpos($str, $token) !== false)
866
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
867
+					if (strpos($str, $token) !== false)
822 868
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
869
+		}
823 870
 
824
-		if (strpos($str, '%p') !== false)
825
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
871
+		if (strpos($str, '%p') !== false) {
872
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
873
+		}
826 874
 	}
827 875
 
828 876
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
829
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
830
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
877
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
878
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
879
+	}
831 880
 
832 881
 	// Format any other characters..
833 882
 	return strftime($str, $time);
@@ -849,16 +898,19 @@  discard block
 block discarded – undo
849 898
 	static $translation = array();
850 899
 
851 900
 	// Determine the character set... Default to UTF-8
852
-	if (empty($context['character_set']))
853
-		$charset = 'UTF-8';
901
+	if (empty($context['character_set'])) {
902
+			$charset = 'UTF-8';
903
+	}
854 904
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
855
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
856
-		$charset = 'ISO-8859-1';
857
-	else
858
-		$charset = $context['character_set'];
905
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
906
+			$charset = 'ISO-8859-1';
907
+	} else {
908
+			$charset = $context['character_set'];
909
+	}
859 910
 
860
-	if (empty($translation))
861
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
911
+	if (empty($translation)) {
912
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
913
+	}
862 914
 
863 915
 	return strtr($string, $translation);
864 916
 }
@@ -880,8 +932,9 @@  discard block
 block discarded – undo
880 932
 	global $smcFunc;
881 933
 
882 934
 	// It was already short enough!
883
-	if ($smcFunc['strlen']($subject) <= $len)
884
-		return $subject;
935
+	if ($smcFunc['strlen']($subject) <= $len) {
936
+			return $subject;
937
+	}
885 938
 
886 939
 	// Shorten it by the length it was too long, and strip off junk from the end.
887 940
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -900,10 +953,11 @@  discard block
 block discarded – undo
900 953
 {
901 954
 	global $user_info, $modSettings;
902 955
 
903
-	if ($timestamp === null)
904
-		$timestamp = time();
905
-	elseif ($timestamp == 0)
906
-		return 0;
956
+	if ($timestamp === null) {
957
+			$timestamp = time();
958
+	} elseif ($timestamp == 0) {
959
+			return 0;
960
+	}
907 961
 
908 962
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
909 963
 }
@@ -932,8 +986,9 @@  discard block
 block discarded – undo
932 986
 		$array[$i] = $array[$j];
933 987
 		$array[$j] = $temp;
934 988
 
935
-		for ($i = 1; $p[$i] == 0; $i++)
936
-			$p[$i] = 1;
989
+		for ($i = 1; $p[$i] == 0; $i++) {
990
+					$p[$i] = 1;
991
+		}
937 992
 
938 993
 		$orders[] = $array;
939 994
 	}
@@ -965,12 +1020,14 @@  discard block
 block discarded – undo
965 1020
 	static $disabled;
966 1021
 
967 1022
 	// Don't waste cycles
968
-	if ($message === '')
969
-		return '';
1023
+	if ($message === '') {
1024
+			return '';
1025
+	}
970 1026
 
971 1027
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
972
-	if (!isset($context['utf8']))
973
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1028
+	if (!isset($context['utf8'])) {
1029
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1030
+	}
974 1031
 
975 1032
 	// Clean up any cut/paste issues we may have
976 1033
 	$message = sanitizeMSCutPaste($message);
@@ -982,13 +1039,15 @@  discard block
 block discarded – undo
982 1039
 		return $message;
983 1040
 	}
984 1041
 
985
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
986
-		$smileys = (bool) $smileys;
1042
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1043
+			$smileys = (bool) $smileys;
1044
+	}
987 1045
 
988 1046
 	if (empty($modSettings['enableBBC']) && $message !== false)
989 1047
 	{
990
-		if ($smileys === true)
991
-			parsesmileys($message);
1048
+		if ($smileys === true) {
1049
+					parsesmileys($message);
1050
+		}
992 1051
 
993 1052
 		return $message;
994 1053
 	}
@@ -1001,8 +1060,9 @@  discard block
 block discarded – undo
1001 1060
 	}
1002 1061
 
1003 1062
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1004
-	if (!empty($modSettings['autoLinkUrls']))
1005
-		set_tld_regex();
1063
+	if (!empty($modSettings['autoLinkUrls'])) {
1064
+			set_tld_regex();
1065
+	}
1006 1066
 
1007 1067
 	// Allow mods access before entering the main parse_bbc loop
1008 1068
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1016,12 +1076,14 @@  discard block
 block discarded – undo
1016 1076
 
1017 1077
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1018 1078
 
1019
-			foreach ($temp as $tag)
1020
-				$disabled[trim($tag)] = true;
1079
+			foreach ($temp as $tag) {
1080
+							$disabled[trim($tag)] = true;
1081
+			}
1021 1082
 		}
1022 1083
 
1023
-		if (empty($modSettings['enableEmbeddedFlash']))
1024
-			$disabled['flash'] = true;
1084
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1085
+					$disabled['flash'] = true;
1086
+		}
1025 1087
 
1026 1088
 		/* The following bbc are formatted as an array, with keys as follows:
1027 1089
 
@@ -1142,8 +1204,9 @@  discard block
 block discarded – undo
1142 1204
 					$returnContext = '';
1143 1205
 
1144 1206
 					// BBC or the entire attachments feature is disabled
1145
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1146
-						return $data;
1207
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1208
+											return $data;
1209
+					}
1147 1210
 
1148 1211
 					// Save the attach ID.
1149 1212
 					$attachID = $data;
@@ -1154,8 +1217,9 @@  discard block
 block discarded – undo
1154 1217
 					$currentAttachment = parseAttachBBC($attachID);
1155 1218
 
1156 1219
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1157
-					if (is_string($currentAttachment))
1158
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1220
+					if (is_string($currentAttachment)) {
1221
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1222
+					}
1159 1223
 
1160 1224
 					if (!empty($currentAttachment['is_image']))
1161 1225
 					{
@@ -1171,15 +1235,17 @@  discard block
 block discarded – undo
1171 1235
 							$height = ' height="' . $currentAttachment['height'] . '"';
1172 1236
 						}
1173 1237
 
1174
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1175
-							$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>';
1176
-						else
1177
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1238
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1239
+													$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>';
1240
+						} else {
1241
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1242
+						}
1178 1243
 					}
1179 1244
 
1180 1245
 					// No image. Show a link.
1181
-					else
1182
-						$returnContext .= $currentAttachment['link'];
1246
+					else {
1247
+											$returnContext .= $currentAttachment['link'];
1248
+					}
1183 1249
 
1184 1250
 					// Gotta append what we just did.
1185 1251
 					$data = $returnContext;
@@ -1210,8 +1276,9 @@  discard block
 block discarded – undo
1210 1276
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1211 1277
 						{
1212 1278
 							// Do PHP code coloring?
1213
-							if ($php_parts[$php_i] != '&lt;?php')
1214
-								continue;
1279
+							if ($php_parts[$php_i] != '&lt;?php') {
1280
+															continue;
1281
+							}
1215 1282
 
1216 1283
 							$php_string = '';
1217 1284
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1227,8 +1294,9 @@  discard block
 block discarded – undo
1227 1294
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1228 1295
 
1229 1296
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1230
-						if ($context['browser']['is_opera'])
1231
-							$data .= '&nbsp;';
1297
+						if ($context['browser']['is_opera']) {
1298
+													$data .= '&nbsp;';
1299
+						}
1232 1300
 					}
1233 1301
 				},
1234 1302
 				'block_level' => true,
@@ -1247,8 +1315,9 @@  discard block
 block discarded – undo
1247 1315
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1248 1316
 						{
1249 1317
 							// Do PHP code coloring?
1250
-							if ($php_parts[$php_i] != '&lt;?php')
1251
-								continue;
1318
+							if ($php_parts[$php_i] != '&lt;?php') {
1319
+															continue;
1320
+							}
1252 1321
 
1253 1322
 							$php_string = '';
1254 1323
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1264,8 +1333,9 @@  discard block
 block discarded – undo
1264 1333
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1265 1334
 
1266 1335
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1267
-						if ($context['browser']['is_opera'])
1268
-							$data[0] .= '&nbsp;';
1336
+						if ($context['browser']['is_opera']) {
1337
+													$data[0] .= '&nbsp;';
1338
+						}
1269 1339
 					}
1270 1340
 				},
1271 1341
 				'block_level' => true,
@@ -1303,11 +1373,13 @@  discard block
 block discarded – undo
1303 1373
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1304 1374
 				'validate' => function (&$tag, &$data, $disabled)
1305 1375
 				{
1306
-					if (isset($disabled['url']))
1307
-						$tag['content'] = '$1';
1376
+					if (isset($disabled['url'])) {
1377
+											$tag['content'] = '$1';
1378
+					}
1308 1379
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1309
-					if (empty($scheme))
1310
-						$data[0] = '//' . ltrim($data[0], ':/');
1380
+					if (empty($scheme)) {
1381
+											$data[0] = '//' . ltrim($data[0], ':/');
1382
+					}
1311 1383
 				},
1312 1384
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1313 1385
 			),
@@ -1321,10 +1393,11 @@  discard block
 block discarded – undo
1321 1393
 				{
1322 1394
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1323 1395
 
1324
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1325
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1326
-					else
1327
-						$css = '';
1396
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1397
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1398
+					} else {
1399
+											$css = '';
1400
+					}
1328 1401
 
1329 1402
 					$data = $class . $css;
1330 1403
 				},
@@ -1374,14 +1447,16 @@  discard block
 block discarded – undo
1374 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1375 1448
 					if ($image_proxy_enabled)
1376 1449
 					{
1377
-						if (empty($scheme))
1378
-							$data = 'http://' . ltrim($data, ':/');
1450
+						if (empty($scheme)) {
1451
+													$data = 'http://' . ltrim($data, ':/');
1452
+						}
1379 1453
 
1380
-						if ($scheme != 'https')
1381
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1454
+						if ($scheme != 'https') {
1455
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1456
+						}
1457
+					} elseif (empty($scheme)) {
1458
+											$data = '//' . ltrim($data, ':/');
1382 1459
 					}
1383
-					elseif (empty($scheme))
1384
-						$data = '//' . ltrim($data, ':/');
1385 1460
 				},
1386 1461
 				'disabled_content' => '($1)',
1387 1462
 			),
@@ -1397,14 +1472,16 @@  discard block
 block discarded – undo
1397 1472
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1398 1473
 					if ($image_proxy_enabled)
1399 1474
 					{
1400
-						if (empty($scheme))
1401
-							$data = 'http://' . ltrim($data, ':/');
1475
+						if (empty($scheme)) {
1476
+													$data = 'http://' . ltrim($data, ':/');
1477
+						}
1402 1478
 
1403
-						if ($scheme != 'https')
1404
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1479
+						if ($scheme != 'https') {
1480
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1481
+						}
1482
+					} elseif (empty($scheme)) {
1483
+											$data = '//' . ltrim($data, ':/');
1405 1484
 					}
1406
-					elseif (empty($scheme))
1407
-						$data = '//' . ltrim($data, ':/');
1408 1485
 				},
1409 1486
 				'disabled_content' => '($1)',
1410 1487
 			),
@@ -1416,8 +1493,9 @@  discard block
 block discarded – undo
1416 1493
 				{
1417 1494
 					$data = strtr($data, array('<br>' => ''));
1418 1495
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1419
-					if (empty($scheme))
1420
-						$data = '//' . ltrim($data, ':/');
1496
+					if (empty($scheme)) {
1497
+											$data = '//' . ltrim($data, ':/');
1498
+					}
1421 1499
 				},
1422 1500
 			),
1423 1501
 			array(
@@ -1428,13 +1506,14 @@  discard block
 block discarded – undo
1428 1506
 				'after' => '</a>',
1429 1507
 				'validate' => function (&$tag, &$data, $disabled)
1430 1508
 				{
1431
-					if (substr($data, 0, 1) == '#')
1432
-						$data = '#post_' . substr($data, 1);
1433
-					else
1509
+					if (substr($data, 0, 1) == '#') {
1510
+											$data = '#post_' . substr($data, 1);
1511
+					} else
1434 1512
 					{
1435 1513
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1436
-						if (empty($scheme))
1437
-							$data = '//' . ltrim($data, ':/');
1514
+						if (empty($scheme)) {
1515
+													$data = '//' . ltrim($data, ':/');
1516
+						}
1438 1517
 					}
1439 1518
 				},
1440 1519
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1512,8 +1591,9 @@  discard block
 block discarded – undo
1512 1591
 					{
1513 1592
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1514 1593
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1515
-						if ($add_begin)
1516
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1594
+						if ($add_begin) {
1595
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1596
+						}
1517 1597
 					}
1518 1598
 				},
1519 1599
 				'block_level' => false,
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 				'content' => '$1',
1645 1725
 				'validate' => function (&$tag, &$data, $disabled)
1646 1726
 				{
1647
-					if (is_numeric($data))
1648
-						$data = timeformat($data);
1649
-					else
1650
-						$tag['content'] = '[time]$1[/time]';
1727
+					if (is_numeric($data)) {
1728
+											$data = timeformat($data);
1729
+					} else {
1730
+											$tag['content'] = '[time]$1[/time]';
1731
+					}
1651 1732
 				},
1652 1733
 			),
1653 1734
 			array(
@@ -1674,8 +1755,9 @@  discard block
 block discarded – undo
1674 1755
 				{
1675 1756
 					$data = strtr($data, array('<br>' => ''));
1676 1757
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1677
-					if (empty($scheme))
1678
-						$data = '//' . ltrim($data, ':/');
1758
+					if (empty($scheme)) {
1759
+											$data = '//' . ltrim($data, ':/');
1760
+					}
1679 1761
 				},
1680 1762
 			),
1681 1763
 			array(
@@ -1687,8 +1769,9 @@  discard block
 block discarded – undo
1687 1769
 				'validate' => function (&$tag, &$data, $disabled)
1688 1770
 				{
1689 1771
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1690
-					if (empty($scheme))
1691
-						$data = '//' . ltrim($data, ':/');
1772
+					if (empty($scheme)) {
1773
+											$data = '//' . ltrim($data, ':/');
1774
+					}
1692 1775
 				},
1693 1776
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1694 1777
 				'disabled_after' => ' ($1)',
@@ -1708,8 +1791,9 @@  discard block
 block discarded – undo
1708 1791
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1709 1792
 		if ($message === false)
1710 1793
 		{
1711
-			if (isset($temp_bbc))
1712
-				$bbc_codes = $temp_bbc;
1794
+			if (isset($temp_bbc)) {
1795
+							$bbc_codes = $temp_bbc;
1796
+			}
1713 1797
 			usort($codes, function ($a, $b) {
1714 1798
 				return strcmp($a['tag'], $b['tag']);
1715 1799
 			});
@@ -1729,8 +1813,9 @@  discard block
 block discarded – undo
1729 1813
 		);
1730 1814
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1731 1815
 		{
1732
-			foreach ($itemcodes as $c => $dummy)
1733
-				$bbc_codes[$c] = array();
1816
+			foreach ($itemcodes as $c => $dummy) {
1817
+							$bbc_codes[$c] = array();
1818
+			}
1734 1819
 		}
1735 1820
 
1736 1821
 		// Shhhh!
@@ -1751,12 +1836,14 @@  discard block
 block discarded – undo
1751 1836
 		foreach ($codes as $code)
1752 1837
 		{
1753 1838
 			// Make it easier to process parameters later
1754
-			if (!empty($code['parameters']))
1755
-				ksort($code['parameters'], SORT_STRING);
1839
+			if (!empty($code['parameters'])) {
1840
+							ksort($code['parameters'], SORT_STRING);
1841
+			}
1756 1842
 
1757 1843
 			// If we are not doing every tag only do ones we are interested in.
1758
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1759
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1844
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1845
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1846
+			}
1760 1847
 		}
1761 1848
 		$codes = null;
1762 1849
 	}
@@ -1767,8 +1854,9 @@  discard block
 block discarded – undo
1767 1854
 		// It's likely this will change if the message is modified.
1768 1855
 		$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']);
1769 1856
 
1770
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1771
-			return $temp;
1857
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1858
+					return $temp;
1859
+		}
1772 1860
 
1773 1861
 		$cache_t = microtime();
1774 1862
 	}
@@ -1800,8 +1888,9 @@  discard block
 block discarded – undo
1800 1888
 		$disabled['flash'] = true;
1801 1889
 
1802 1890
 		// @todo Change maybe?
1803
-		if (!isset($_GET['images']))
1804
-			$disabled['img'] = true;
1891
+		if (!isset($_GET['images'])) {
1892
+					$disabled['img'] = true;
1893
+		}
1805 1894
 
1806 1895
 		// @todo Interface/setting to add more?
1807 1896
 	}
@@ -1825,8 +1914,9 @@  discard block
 block discarded – undo
1825 1914
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1826 1915
 
1827 1916
 		// Failsafe.
1828
-		if ($pos === false || $last_pos > $pos)
1829
-			$pos = strlen($message) + 1;
1917
+		if ($pos === false || $last_pos > $pos) {
1918
+					$pos = strlen($message) + 1;
1919
+		}
1830 1920
 
1831 1921
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1832 1922
 		if ($last_pos < $pos - 1)
@@ -1845,8 +1935,9 @@  discard block
 block discarded – undo
1845 1935
 
1846 1936
 				// <br> should be empty.
1847 1937
 				$empty_tags = array('br', 'hr');
1848
-				foreach ($empty_tags as $tag)
1849
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1938
+				foreach ($empty_tags as $tag) {
1939
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1940
+				}
1850 1941
 
1851 1942
 				// b, u, i, s, pre... basic tags.
1852 1943
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1855,8 +1946,9 @@  discard block
 block discarded – undo
1855 1946
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1856 1947
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1857 1948
 
1858
-					if ($diff > 0)
1859
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1949
+					if ($diff > 0) {
1950
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1951
+					}
1860 1952
 				}
1861 1953
 
1862 1954
 				// Do <img ...> - with security... action= -> action-.
@@ -1869,8 +1961,9 @@  discard block
 block discarded – undo
1869 1961
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1870 1962
 
1871 1963
 						// Remove action= from the URL - no funny business, now.
1872
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1873
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1964
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1965
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1966
+						}
1874 1967
 
1875 1968
 						// Check if the image is larger than allowed.
1876 1969
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1891,9 +1984,9 @@  discard block
 block discarded – undo
1891 1984
 
1892 1985
 							// Set the new image tag.
1893 1986
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1987
+						} else {
1988
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1894 1989
 						}
1895
-						else
1896
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1897 1990
 					}
1898 1991
 
1899 1992
 					$data = strtr($data, $replaces);
@@ -1906,16 +1999,18 @@  discard block
 block discarded – undo
1906 1999
 				$no_autolink_area = false;
1907 2000
 				if (!empty($open_tags))
1908 2001
 				{
1909
-					foreach ($open_tags as $open_tag)
1910
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2002
+					foreach ($open_tags as $open_tag) {
2003
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1911 2004
 							$no_autolink_area = true;
2005
+					}
1912 2006
 				}
1913 2007
 
1914 2008
 				// Don't go backwards.
1915 2009
 				// @todo Don't think is the real solution....
1916 2010
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1917
-				if ($pos < $lastAutoPos)
1918
-					$no_autolink_area = true;
2011
+				if ($pos < $lastAutoPos) {
2012
+									$no_autolink_area = true;
2013
+				}
1919 2014
 				$lastAutoPos = $pos;
1920 2015
 
1921 2016
 				if (!$no_autolink_area)
@@ -2024,17 +2119,19 @@  discard block
 block discarded – undo
2024 2119
 							if ($scheme == 'mailto')
2025 2120
 							{
2026 2121
 								$email_address = str_replace('mailto:', '', $url);
2027
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2028
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2029
-								else
2030
-									return $url;
2122
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2123
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2124
+								} else {
2125
+																	return $url;
2126
+								}
2031 2127
 							}
2032 2128
 
2033 2129
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2034
-							if (empty($scheme))
2035
-								$fullUrl = '//' . ltrim($url, ':/');
2036
-							else
2037
-								$fullUrl = $url;
2130
+							if (empty($scheme)) {
2131
+															$fullUrl = '//' . ltrim($url, ':/');
2132
+							} else {
2133
+															$fullUrl = $url;
2134
+							}
2038 2135
 
2039 2136
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2040 2137
 						}, $data);
@@ -2083,16 +2180,18 @@  discard block
 block discarded – undo
2083 2180
 		}
2084 2181
 
2085 2182
 		// Are we there yet?  Are we there yet?
2086
-		if ($pos >= strlen($message) - 1)
2087
-			break;
2183
+		if ($pos >= strlen($message) - 1) {
2184
+					break;
2185
+		}
2088 2186
 
2089 2187
 		$tags = strtolower($message[$pos + 1]);
2090 2188
 
2091 2189
 		if ($tags == '/' && !empty($open_tags))
2092 2190
 		{
2093 2191
 			$pos2 = strpos($message, ']', $pos + 1);
2094
-			if ($pos2 == $pos + 2)
2095
-				continue;
2192
+			if ($pos2 == $pos + 2) {
2193
+							continue;
2194
+			}
2096 2195
 
2097 2196
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2098 2197
 
@@ -2102,8 +2201,9 @@  discard block
 block discarded – undo
2102 2201
 			do
2103 2202
 			{
2104 2203
 				$tag = array_pop($open_tags);
2105
-				if (!$tag)
2106
-					break;
2204
+				if (!$tag) {
2205
+									break;
2206
+				}
2107 2207
 
2108 2208
 				if (!empty($tag['block_level']))
2109 2209
 				{
@@ -2117,10 +2217,11 @@  discard block
 block discarded – undo
2117 2217
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2118 2218
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2119 2219
 					{
2120
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2121
-							if ($temp['tag'] == $look_for)
2220
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2221
+													if ($temp['tag'] == $look_for)
2122 2222
 							{
2123 2223
 								$block_level = !empty($temp['block_level']);
2224
+						}
2124 2225
 								break;
2125 2226
 							}
2126 2227
 					}
@@ -2142,15 +2243,15 @@  discard block
 block discarded – undo
2142 2243
 			{
2143 2244
 				$open_tags = $to_close;
2144 2245
 				continue;
2145
-			}
2146
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2246
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2147 2247
 			{
2148 2248
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2149 2249
 				{
2150
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2151
-						if ($temp['tag'] == $look_for)
2250
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2251
+											if ($temp['tag'] == $look_for)
2152 2252
 						{
2153 2253
 							$block_level = !empty($temp['block_level']);
2254
+					}
2154 2255
 							break;
2155 2256
 						}
2156 2257
 				}
@@ -2158,8 +2259,9 @@  discard block
 block discarded – undo
2158 2259
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2159 2260
 				if (!$block_level)
2160 2261
 				{
2161
-					foreach ($to_close as $tag)
2162
-						array_push($open_tags, $tag);
2262
+					foreach ($to_close as $tag) {
2263
+											array_push($open_tags, $tag);
2264
+					}
2163 2265
 					continue;
2164 2266
 				}
2165 2267
 			}
@@ -2172,14 +2274,17 @@  discard block
 block discarded – undo
2172 2274
 
2173 2275
 				// See the comment at the end of the big loop - just eating whitespace ;).
2174 2276
 				$whitespace_regex = '';
2175
-				if (!empty($tag['block_level']))
2176
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2277
+				if (!empty($tag['block_level'])) {
2278
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2279
+				}
2177 2280
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2178
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2179
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2281
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2282
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2283
+				}
2180 2284
 
2181
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2182
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2285
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2286
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2287
+				}
2183 2288
 			}
2184 2289
 
2185 2290
 			if (!empty($to_close))
@@ -2192,8 +2297,9 @@  discard block
 block discarded – undo
2192 2297
 		}
2193 2298
 
2194 2299
 		// No tags for this character, so just keep going (fastest possible course.)
2195
-		if (!isset($bbc_codes[$tags]))
2196
-			continue;
2300
+		if (!isset($bbc_codes[$tags])) {
2301
+					continue;
2302
+		}
2197 2303
 
2198 2304
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2199 2305
 		$tag = null;
@@ -2202,44 +2308,52 @@  discard block
 block discarded – undo
2202 2308
 			$pt_strlen = strlen($possible['tag']);
2203 2309
 
2204 2310
 			// Not a match?
2205
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2206
-				continue;
2311
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2312
+							continue;
2313
+			}
2207 2314
 
2208 2315
 			$next_c = $message[$pos + 1 + $pt_strlen];
2209 2316
 
2210 2317
 			// A test validation?
2211
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2212
-				continue;
2318
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2319
+							continue;
2320
+			}
2213 2321
 			// Do we want parameters?
2214 2322
 			elseif (!empty($possible['parameters']))
2215 2323
 			{
2216
-				if ($next_c != ' ')
2217
-					continue;
2218
-			}
2219
-			elseif (isset($possible['type']))
2324
+				if ($next_c != ' ') {
2325
+									continue;
2326
+				}
2327
+			} elseif (isset($possible['type']))
2220 2328
 			{
2221 2329
 				// Do we need an equal sign?
2222
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2223
-					continue;
2330
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2331
+									continue;
2332
+				}
2224 2333
 				// Maybe we just want a /...
2225
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2226
-					continue;
2334
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2335
+									continue;
2336
+				}
2227 2337
 				// An immediate ]?
2228
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2229
-					continue;
2338
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2339
+									continue;
2340
+				}
2230 2341
 			}
2231 2342
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2232
-			elseif ($next_c != ']')
2233
-				continue;
2343
+			elseif ($next_c != ']') {
2344
+							continue;
2345
+			}
2234 2346
 
2235 2347
 			// Check allowed tree?
2236
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2237
-				continue;
2238
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2239
-				continue;
2348
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2349
+							continue;
2350
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2351
+							continue;
2352
+			}
2240 2353
 			// If this is in the list of disallowed child tags, don't parse it.
2241
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2242
-				continue;
2354
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2355
+							continue;
2356
+			}
2243 2357
 
2244 2358
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2245 2359
 
@@ -2251,8 +2365,9 @@  discard block
 block discarded – undo
2251 2365
 				foreach ($open_tags as $open_quote)
2252 2366
 				{
2253 2367
 					// Every parent quote this quote has flips the styling
2254
-					if ($open_quote['tag'] == 'quote')
2255
-						$quote_alt = !$quote_alt;
2368
+					if ($open_quote['tag'] == 'quote') {
2369
+											$quote_alt = !$quote_alt;
2370
+					}
2256 2371
 				}
2257 2372
 				// Add a class to the quote to style alternating blockquotes
2258 2373
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2263,8 +2378,9 @@  discard block
 block discarded – undo
2263 2378
 			{
2264 2379
 				// Build a regular expression for each parameter for the current tag.
2265 2380
 				$preg = array();
2266
-				foreach ($possible['parameters'] as $p => $info)
2267
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2381
+				foreach ($possible['parameters'] as $p => $info) {
2382
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2383
+				}
2268 2384
 
2269 2385
 				// Extract the string that potentially holds our parameters.
2270 2386
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2284,24 +2400,27 @@  discard block
 block discarded – undo
2284 2400
 
2285 2401
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2286 2402
 
2287
-					if ($match)
2288
-						$blob_counter = count($blobs) + 1;
2403
+					if ($match) {
2404
+											$blob_counter = count($blobs) + 1;
2405
+					}
2289 2406
 				}
2290 2407
 
2291 2408
 				// Didn't match our parameter list, try the next possible.
2292
-				if (!$match)
2293
-					continue;
2409
+				if (!$match) {
2410
+									continue;
2411
+				}
2294 2412
 
2295 2413
 				$params = array();
2296 2414
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2297 2415
 				{
2298 2416
 					$key = strtok(ltrim($matches[$i]), '=');
2299
-					if (isset($possible['parameters'][$key]['value']))
2300
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2301
-					elseif (isset($possible['parameters'][$key]['validate']))
2302
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2303
-					else
2304
-						$params['{' . $key . '}'] = $matches[$i + 1];
2417
+					if (isset($possible['parameters'][$key]['value'])) {
2418
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2419
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2420
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2421
+					} else {
2422
+											$params['{' . $key . '}'] = $matches[$i + 1];
2423
+					}
2305 2424
 
2306 2425
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2307 2426
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2309,23 +2428,26 @@  discard block
 block discarded – undo
2309 2428
 
2310 2429
 				foreach ($possible['parameters'] as $p => $info)
2311 2430
 				{
2312
-					if (!isset($params['{' . $p . '}']))
2313
-						$params['{' . $p . '}'] = '';
2431
+					if (!isset($params['{' . $p . '}'])) {
2432
+											$params['{' . $p . '}'] = '';
2433
+					}
2314 2434
 				}
2315 2435
 
2316 2436
 				$tag = $possible;
2317 2437
 
2318 2438
 				// Put the parameters into the string.
2319
-				if (isset($tag['before']))
2320
-					$tag['before'] = strtr($tag['before'], $params);
2321
-				if (isset($tag['after']))
2322
-					$tag['after'] = strtr($tag['after'], $params);
2323
-				if (isset($tag['content']))
2324
-					$tag['content'] = strtr($tag['content'], $params);
2439
+				if (isset($tag['before'])) {
2440
+									$tag['before'] = strtr($tag['before'], $params);
2441
+				}
2442
+				if (isset($tag['after'])) {
2443
+									$tag['after'] = strtr($tag['after'], $params);
2444
+				}
2445
+				if (isset($tag['content'])) {
2446
+									$tag['content'] = strtr($tag['content'], $params);
2447
+				}
2325 2448
 
2326 2449
 				$pos1 += strlen($given_param_string);
2327
-			}
2328
-			else
2450
+			} else
2329 2451
 			{
2330 2452
 				$tag = $possible;
2331 2453
 				$params = array();
@@ -2336,8 +2458,9 @@  discard block
 block discarded – undo
2336 2458
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2337 2459
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2338 2460
 		{
2339
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2340
-				continue;
2461
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2462
+							continue;
2463
+			}
2341 2464
 
2342 2465
 			$tag = $itemcodes[$message[$pos + 1]];
2343 2466
 
@@ -2358,9 +2481,9 @@  discard block
 block discarded – undo
2358 2481
 			{
2359 2482
 				array_pop($open_tags);
2360 2483
 				$code = '</li>';
2484
+			} else {
2485
+							$code = '';
2361 2486
 			}
2362
-			else
2363
-				$code = '';
2364 2487
 
2365 2488
 			// Now we open a new tag.
2366 2489
 			$open_tags[] = array(
@@ -2407,12 +2530,14 @@  discard block
 block discarded – undo
2407 2530
 		}
2408 2531
 
2409 2532
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2410
-		if ($tag === null)
2411
-			continue;
2533
+		if ($tag === null) {
2534
+					continue;
2535
+		}
2412 2536
 
2413 2537
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2414
-		if (isset($inside['disallow_children']))
2415
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2538
+		if (isset($inside['disallow_children'])) {
2539
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2540
+		}
2416 2541
 
2417 2542
 		// Is this tag disabled?
2418 2543
 		if (isset($disabled[$tag['tag']]))
@@ -2422,14 +2547,13 @@  discard block
 block discarded – undo
2422 2547
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2423 2548
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2424 2549
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2425
-			}
2426
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2550
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2427 2551
 			{
2428 2552
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2429 2553
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2554
+			} else {
2555
+							$tag['content'] = $tag['disabled_content'];
2430 2556
 			}
2431
-			else
2432
-				$tag['content'] = $tag['disabled_content'];
2433 2557
 		}
2434 2558
 
2435 2559
 		// we use this a lot
@@ -2439,8 +2563,9 @@  discard block
 block discarded – undo
2439 2563
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2440 2564
 		{
2441 2565
 			$n = count($open_tags) - 1;
2442
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2443
-				$n--;
2566
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2567
+							$n--;
2568
+			}
2444 2569
 
2445 2570
 			// Close all the non block level tags so this tag isn't surrounded by them.
2446 2571
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2452,12 +2577,15 @@  discard block
 block discarded – undo
2452 2577
 
2453 2578
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2454 2579
 				$whitespace_regex = '';
2455
-				if (!empty($tag['block_level']))
2456
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2457
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2458
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2459
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2460
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2580
+				if (!empty($tag['block_level'])) {
2581
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2582
+				}
2583
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2584
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2585
+				}
2586
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2587
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2588
+				}
2461 2589
 
2462 2590
 				array_pop($open_tags);
2463 2591
 			}
@@ -2475,16 +2603,19 @@  discard block
 block discarded – undo
2475 2603
 		elseif ($tag['type'] == 'unparsed_content')
2476 2604
 		{
2477 2605
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2478
-			if ($pos2 === false)
2479
-				continue;
2606
+			if ($pos2 === false) {
2607
+							continue;
2608
+			}
2480 2609
 
2481 2610
 			$data = substr($message, $pos1, $pos2 - $pos1);
2482 2611
 
2483
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2484
-				$data = substr($data, 4);
2612
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2613
+							$data = substr($data, 4);
2614
+			}
2485 2615
 
2486
-			if (isset($tag['validate']))
2487
-				$tag['validate']($tag, $data, $disabled, $params);
2616
+			if (isset($tag['validate'])) {
2617
+							$tag['validate']($tag, $data, $disabled, $params);
2618
+			}
2488 2619
 
2489 2620
 			$code = strtr($tag['content'], array('$1' => $data));
2490 2621
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2500,34 +2631,40 @@  discard block
 block discarded – undo
2500 2631
 			if (isset($tag['quoted']))
2501 2632
 			{
2502 2633
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2503
-				if ($tag['quoted'] != 'optional' && !$quoted)
2504
-					continue;
2634
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2635
+									continue;
2636
+				}
2505 2637
 
2506
-				if ($quoted)
2507
-					$pos1 += 6;
2638
+				if ($quoted) {
2639
+									$pos1 += 6;
2640
+				}
2641
+			} else {
2642
+							$quoted = false;
2508 2643
 			}
2509
-			else
2510
-				$quoted = false;
2511 2644
 
2512 2645
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2513
-			if ($pos2 === false)
2514
-				continue;
2646
+			if ($pos2 === false) {
2647
+							continue;
2648
+			}
2515 2649
 
2516 2650
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2517
-			if ($pos3 === false)
2518
-				continue;
2651
+			if ($pos3 === false) {
2652
+							continue;
2653
+			}
2519 2654
 
2520 2655
 			$data = array(
2521 2656
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2522 2657
 				substr($message, $pos1, $pos2 - $pos1)
2523 2658
 			);
2524 2659
 
2525
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2526
-				$data[0] = substr($data[0], 4);
2660
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2661
+							$data[0] = substr($data[0], 4);
2662
+			}
2527 2663
 
2528 2664
 			// Validation for my parking, please!
2529
-			if (isset($tag['validate']))
2530
-				$tag['validate']($tag, $data, $disabled, $params);
2665
+			if (isset($tag['validate'])) {
2666
+							$tag['validate']($tag, $data, $disabled, $params);
2667
+			}
2531 2668
 
2532 2669
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2533 2670
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2544,23 +2681,27 @@  discard block
 block discarded – undo
2544 2681
 		elseif ($tag['type'] == 'unparsed_commas_content')
2545 2682
 		{
2546 2683
 			$pos2 = strpos($message, ']', $pos1);
2547
-			if ($pos2 === false)
2548
-				continue;
2684
+			if ($pos2 === false) {
2685
+							continue;
2686
+			}
2549 2687
 
2550 2688
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2551
-			if ($pos3 === false)
2552
-				continue;
2689
+			if ($pos3 === false) {
2690
+							continue;
2691
+			}
2553 2692
 
2554 2693
 			// We want $1 to be the content, and the rest to be csv.
2555 2694
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2556 2695
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2557 2696
 
2558
-			if (isset($tag['validate']))
2559
-				$tag['validate']($tag, $data, $disabled, $params);
2697
+			if (isset($tag['validate'])) {
2698
+							$tag['validate']($tag, $data, $disabled, $params);
2699
+			}
2560 2700
 
2561 2701
 			$code = $tag['content'];
2562
-			foreach ($data as $k => $d)
2563
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2702
+			foreach ($data as $k => $d) {
2703
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2704
+			}
2564 2705
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2565 2706
 			$pos += strlen($code) - 1 + 2;
2566 2707
 		}
@@ -2568,24 +2709,28 @@  discard block
 block discarded – undo
2568 2709
 		elseif ($tag['type'] == 'unparsed_commas')
2569 2710
 		{
2570 2711
 			$pos2 = strpos($message, ']', $pos1);
2571
-			if ($pos2 === false)
2572
-				continue;
2712
+			if ($pos2 === false) {
2713
+							continue;
2714
+			}
2573 2715
 
2574 2716
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2575 2717
 
2576
-			if (isset($tag['validate']))
2577
-				$tag['validate']($tag, $data, $disabled, $params);
2718
+			if (isset($tag['validate'])) {
2719
+							$tag['validate']($tag, $data, $disabled, $params);
2720
+			}
2578 2721
 
2579 2722
 			// Fix after, for disabled code mainly.
2580
-			foreach ($data as $k => $d)
2581
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2723
+			foreach ($data as $k => $d) {
2724
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2725
+			}
2582 2726
 
2583 2727
 			$open_tags[] = $tag;
2584 2728
 
2585 2729
 			// Replace them out, $1, $2, $3, $4, etc.
2586 2730
 			$code = $tag['before'];
2587
-			foreach ($data as $k => $d)
2588
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2731
+			foreach ($data as $k => $d) {
2732
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2733
+			}
2589 2734
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2590 2735
 			$pos += strlen($code) - 1 + 2;
2591 2736
 		}
@@ -2596,28 +2741,33 @@  discard block
 block discarded – undo
2596 2741
 			if (isset($tag['quoted']))
2597 2742
 			{
2598 2743
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2599
-				if ($tag['quoted'] != 'optional' && !$quoted)
2600
-					continue;
2744
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2745
+									continue;
2746
+				}
2601 2747
 
2602
-				if ($quoted)
2603
-					$pos1 += 6;
2748
+				if ($quoted) {
2749
+									$pos1 += 6;
2750
+				}
2751
+			} else {
2752
+							$quoted = false;
2604 2753
 			}
2605
-			else
2606
-				$quoted = false;
2607 2754
 
2608 2755
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2609
-			if ($pos2 === false)
2610
-				continue;
2756
+			if ($pos2 === false) {
2757
+							continue;
2758
+			}
2611 2759
 
2612 2760
 			$data = substr($message, $pos1, $pos2 - $pos1);
2613 2761
 
2614 2762
 			// Validation for my parking, please!
2615
-			if (isset($tag['validate']))
2616
-				$tag['validate']($tag, $data, $disabled, $params);
2763
+			if (isset($tag['validate'])) {
2764
+							$tag['validate']($tag, $data, $disabled, $params);
2765
+			}
2617 2766
 
2618 2767
 			// For parsed content, we must recurse to avoid security problems.
2619
-			if ($tag['type'] != 'unparsed_equals')
2620
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2768
+			if ($tag['type'] != 'unparsed_equals') {
2769
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2770
+			}
2621 2771
 
2622 2772
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2623 2773
 
@@ -2629,34 +2779,40 @@  discard block
 block discarded – undo
2629 2779
 		}
2630 2780
 
2631 2781
 		// If this is block level, eat any breaks after it.
2632
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2633
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2782
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2783
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2784
+		}
2634 2785
 
2635 2786
 		// Are we trimming outside this tag?
2636
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2637
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2787
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2788
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2789
+		}
2638 2790
 	}
2639 2791
 
2640 2792
 	// Close any remaining tags.
2641
-	while ($tag = array_pop($open_tags))
2642
-		$message .= "\n" . $tag['after'] . "\n";
2793
+	while ($tag = array_pop($open_tags)) {
2794
+			$message .= "\n" . $tag['after'] . "\n";
2795
+	}
2643 2796
 
2644 2797
 	// Parse the smileys within the parts where it can be done safely.
2645 2798
 	if ($smileys === true)
2646 2799
 	{
2647 2800
 		$message_parts = explode("\n", $message);
2648
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2649
-			parsesmileys($message_parts[$i]);
2801
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2802
+					parsesmileys($message_parts[$i]);
2803
+		}
2650 2804
 
2651 2805
 		$message = implode('', $message_parts);
2652 2806
 	}
2653 2807
 
2654 2808
 	// No smileys, just get rid of the markers.
2655
-	else
2656
-		$message = strtr($message, array("\n" => ''));
2809
+	else {
2810
+			$message = strtr($message, array("\n" => ''));
2811
+	}
2657 2812
 
2658
-	if ($message !== '' && $message[0] === ' ')
2659
-		$message = '&nbsp;' . substr($message, 1);
2813
+	if ($message !== '' && $message[0] === ' ') {
2814
+			$message = '&nbsp;' . substr($message, 1);
2815
+	}
2660 2816
 
2661 2817
 	// Cleanup whitespace.
2662 2818
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2665,15 +2821,16 @@  discard block
 block discarded – undo
2665 2821
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2666 2822
 
2667 2823
 	// Cache the output if it took some time...
2668
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2669
-		cache_put_data($cache_key, $message, 240);
2824
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2825
+			cache_put_data($cache_key, $message, 240);
2826
+	}
2670 2827
 
2671 2828
 	// If this was a force parse revert if needed.
2672 2829
 	if (!empty($parse_tags))
2673 2830
 	{
2674
-		if (empty($temp_bbc))
2675
-			$bbc_codes = array();
2676
-		else
2831
+		if (empty($temp_bbc)) {
2832
+					$bbc_codes = array();
2833
+		} else
2677 2834
 		{
2678 2835
 			$bbc_codes = $temp_bbc;
2679 2836
 			unset($temp_bbc);
@@ -2700,8 +2857,9 @@  discard block
 block discarded – undo
2700 2857
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2701 2858
 
2702 2859
 	// No smiley set at all?!
2703
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2704
-		return;
2860
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2861
+			return;
2862
+	}
2705 2863
 
2706 2864
 	// If smileyPregSearch hasn't been set, do it now.
2707 2865
 	if (empty($smileyPregSearch))
@@ -2712,8 +2870,7 @@  discard block
 block discarded – undo
2712 2870
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2713 2871
 			$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');
2714 2872
 			$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'], '', '', '', '');
2715
-		}
2716
-		else
2873
+		} else
2717 2874
 		{
2718 2875
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2719 2876
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2737,9 +2894,9 @@  discard block
 block discarded – undo
2737 2894
 				$smcFunc['db_free_result']($result);
2738 2895
 
2739 2896
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2897
+			} else {
2898
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2740 2899
 			}
2741
-			else
2742
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2743 2900
 		}
2744 2901
 
2745 2902
 		// The non-breaking-space is a complex thing...
@@ -2816,35 +2973,41 @@  discard block
 block discarded – undo
2816 2973
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2817 2974
 
2818 2975
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2819
-	if (!empty($context['flush_mail']))
2820
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2976
+	if (!empty($context['flush_mail'])) {
2977
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2821 2978
 		AddMailQueue(true);
2979
+	}
2822 2980
 
2823 2981
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2824 2982
 
2825
-	if ($add)
2826
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2983
+	if ($add) {
2984
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2985
+	}
2827 2986
 
2828 2987
 	// Put the session ID in.
2829
-	if (defined('SID') && SID != '')
2830
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2988
+	if (defined('SID') && SID != '') {
2989
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2990
+	}
2831 2991
 	// Keep that debug in their for template debugging!
2832
-	elseif (isset($_GET['debug']))
2833
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2992
+	elseif (isset($_GET['debug'])) {
2993
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2994
+	}
2834 2995
 
2835 2996
 	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'])))
2836 2997
 	{
2837
-		if (defined('SID') && SID != '')
2838
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2998
+		if (defined('SID') && SID != '') {
2999
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2839 3000
 				function ($m) use ($scripturl)
2840 3001
 				{
2841 3002
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3003
+		}
2842 3004
 				}, $setLocation);
2843
-		else
2844
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3005
+		else {
3006
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2845 3007
 				function ($m) use ($scripturl)
2846 3008
 				{
2847 3009
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3010
+		}
2848 3011
 				}, $setLocation);
2849 3012
 	}
2850 3013
 
@@ -2855,8 +3018,9 @@  discard block
 block discarded – undo
2855 3018
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2856 3019
 
2857 3020
 	// Debugging.
2858
-	if (isset($db_show_debug) && $db_show_debug === true)
2859
-		$_SESSION['debug_redirect'] = $db_cache;
3021
+	if (isset($db_show_debug) && $db_show_debug === true) {
3022
+			$_SESSION['debug_redirect'] = $db_cache;
3023
+	}
2860 3024
 
2861 3025
 	obExit(false);
2862 3026
 }
@@ -2875,51 +3039,60 @@  discard block
 block discarded – undo
2875 3039
 
2876 3040
 	// Attempt to prevent a recursive loop.
2877 3041
 	++$level;
2878
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2879
-		exit;
2880
-	if ($from_fatal_error)
2881
-		$has_fatal_error = true;
3042
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3043
+			exit;
3044
+	}
3045
+	if ($from_fatal_error) {
3046
+			$has_fatal_error = true;
3047
+	}
2882 3048
 
2883 3049
 	// Clear out the stat cache.
2884 3050
 	trackStats();
2885 3051
 
2886 3052
 	// If we have mail to send, send it.
2887
-	if (!empty($context['flush_mail']))
2888
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3053
+	if (!empty($context['flush_mail'])) {
3054
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2889 3055
 		AddMailQueue(true);
3056
+	}
2890 3057
 
2891 3058
 	$do_header = $header === null ? !$header_done : $header;
2892
-	if ($do_footer === null)
2893
-		$do_footer = $do_header;
3059
+	if ($do_footer === null) {
3060
+			$do_footer = $do_header;
3061
+	}
2894 3062
 
2895 3063
 	// Has the template/header been done yet?
2896 3064
 	if ($do_header)
2897 3065
 	{
2898 3066
 		// Was the page title set last minute? Also update the HTML safe one.
2899
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2900
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3067
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3068
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3069
+		}
2901 3070
 
2902 3071
 		// Start up the session URL fixer.
2903 3072
 		ob_start('ob_sessrewrite');
2904 3073
 
2905
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2906
-			$buffers = explode(',', $settings['output_buffers']);
2907
-		elseif (!empty($settings['output_buffers']))
2908
-			$buffers = $settings['output_buffers'];
2909
-		else
2910
-			$buffers = array();
3074
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3075
+					$buffers = explode(',', $settings['output_buffers']);
3076
+		} elseif (!empty($settings['output_buffers'])) {
3077
+					$buffers = $settings['output_buffers'];
3078
+		} else {
3079
+					$buffers = array();
3080
+		}
2911 3081
 
2912
-		if (isset($modSettings['integrate_buffer']))
2913
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3082
+		if (isset($modSettings['integrate_buffer'])) {
3083
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3084
+		}
2914 3085
 
2915
-		if (!empty($buffers))
2916
-			foreach ($buffers as $function)
3086
+		if (!empty($buffers)) {
3087
+					foreach ($buffers as $function)
2917 3088
 			{
2918 3089
 				$call = call_helper($function, true);
3090
+		}
2919 3091
 
2920 3092
 				// Is it valid?
2921
-				if (!empty($call))
2922
-					ob_start($call);
3093
+				if (!empty($call)) {
3094
+									ob_start($call);
3095
+				}
2923 3096
 			}
2924 3097
 
2925 3098
 		// Display the screen in the logical order.
@@ -2931,8 +3104,9 @@  discard block
 block discarded – undo
2931 3104
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2932 3105
 
2933 3106
 		// Anything special to put out?
2934
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2935
-			echo $context['insert_after_template'];
3107
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3108
+					echo $context['insert_after_template'];
3109
+		}
2936 3110
 
2937 3111
 		// Just so we don't get caught in an endless loop of errors from the footer...
2938 3112
 		if (!$footer_done)
@@ -2941,14 +3115,16 @@  discard block
 block discarded – undo
2941 3115
 			template_footer();
2942 3116
 
2943 3117
 			// (since this is just debugging... it's okay that it's after </html>.)
2944
-			if (!isset($_REQUEST['xml']))
2945
-				displayDebug();
3118
+			if (!isset($_REQUEST['xml'])) {
3119
+							displayDebug();
3120
+			}
2946 3121
 		}
2947 3122
 	}
2948 3123
 
2949 3124
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2950
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2951
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3125
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3126
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3127
+	}
2952 3128
 
2953 3129
 	// For session check verification.... don't switch browsers...
2954 3130
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2957,9 +3133,10 @@  discard block
 block discarded – undo
2957 3133
 	call_integration_hook('integrate_exit', array($do_footer));
2958 3134
 
2959 3135
 	// Don't exit if we're coming from index.php; that will pass through normally.
2960
-	if (!$from_index)
2961
-		exit;
2962
-}
3136
+	if (!$from_index) {
3137
+			exit;
3138
+	}
3139
+	}
2963 3140
 
2964 3141
 /**
2965 3142
  * Get the size of a specified image with better error handling.
@@ -2978,8 +3155,9 @@  discard block
 block discarded – undo
2978 3155
 	$url = str_replace(' ', '%20', $url);
2979 3156
 
2980 3157
 	// Can we pull this from the cache... please please?
2981
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2982
-		return $temp;
3158
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3159
+			return $temp;
3160
+	}
2983 3161
 	$t = microtime();
2984 3162
 
2985 3163
 	// Get the host to pester...
@@ -2989,12 +3167,10 @@  discard block
 block discarded – undo
2989 3167
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2990 3168
 	{
2991 3169
 		return false;
2992
-	}
2993
-	elseif (!isset($match[1]))
3170
+	} elseif (!isset($match[1]))
2994 3171
 	{
2995 3172
 		$size = @getimagesize($url);
2996
-	}
2997
-	else
3173
+	} else
2998 3174
 	{
2999 3175
 		// Try to connect to the server... give it half a second.
3000 3176
 		$temp = 0;
@@ -3033,12 +3209,14 @@  discard block
 block discarded – undo
3033 3209
 	}
3034 3210
 
3035 3211
 	// If we didn't get it, we failed.
3036
-	if (!isset($size))
3037
-		$size = false;
3212
+	if (!isset($size)) {
3213
+			$size = false;
3214
+	}
3038 3215
 
3039 3216
 	// If this took a long time, we may never have to do it again, but then again we might...
3040
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3041
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3217
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3218
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3219
+	}
3042 3220
 
3043 3221
 	// Didn't work.
3044 3222
 	return $size;
@@ -3056,8 +3234,9 @@  discard block
 block discarded – undo
3056 3234
 
3057 3235
 	// Under SSI this function can be called more then once.  That can cause some problems.
3058 3236
 	//   So only run the function once unless we are forced to run it again.
3059
-	if ($loaded && !$forceload)
3060
-		return;
3237
+	if ($loaded && !$forceload) {
3238
+			return;
3239
+	}
3061 3240
 
3062 3241
 	$loaded = true;
3063 3242
 
@@ -3069,14 +3248,16 @@  discard block
 block discarded – undo
3069 3248
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3070 3249
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3071 3250
 	{
3072
-		if (trim($context['news_lines'][$i]) == '')
3073
-			continue;
3251
+		if (trim($context['news_lines'][$i]) == '') {
3252
+					continue;
3253
+		}
3074 3254
 
3075 3255
 		// Clean it up for presentation ;).
3076 3256
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3077 3257
 	}
3078
-	if (!empty($context['news_lines']))
3079
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3258
+	if (!empty($context['news_lines'])) {
3259
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3260
+	}
3080 3261
 
3081 3262
 	if (!$user_info['is_guest'])
3082 3263
 	{
@@ -3085,40 +3266,48 @@  discard block
 block discarded – undo
3085 3266
 		$context['user']['alerts'] = &$user_info['alerts'];
3086 3267
 
3087 3268
 		// Personal message popup...
3088
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3089
-			$context['user']['popup_messages'] = true;
3090
-		else
3091
-			$context['user']['popup_messages'] = false;
3269
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3270
+					$context['user']['popup_messages'] = true;
3271
+		} else {
3272
+					$context['user']['popup_messages'] = false;
3273
+		}
3092 3274
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3093 3275
 
3094
-		if (allowedTo('moderate_forum'))
3095
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3276
+		if (allowedTo('moderate_forum')) {
3277
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3278
+		}
3096 3279
 
3097 3280
 		$context['user']['avatar'] = array();
3098 3281
 
3099 3282
 		// Check for gravatar first since we might be forcing them...
3100 3283
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3101 3284
 		{
3102
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3103
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3104
-			else
3105
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3285
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3286
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3287
+			} else {
3288
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3289
+			}
3106 3290
 		}
3107 3291
 		// Uploaded?
3108
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3109
-			$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';
3292
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3293
+					$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';
3294
+		}
3110 3295
 		// Full URL?
3111
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3112
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3296
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3297
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3298
+		}
3113 3299
 		// Otherwise we assume it's server stored.
3114
-		elseif ($user_info['avatar']['url'] != '')
3115
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3300
+		elseif ($user_info['avatar']['url'] != '') {
3301
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3302
+		}
3116 3303
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3117
-		else
3118
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3304
+		else {
3305
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3306
+		}
3119 3307
 
3120
-		if (!empty($context['user']['avatar']))
3121
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3308
+		if (!empty($context['user']['avatar'])) {
3309
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3310
+		}
3122 3311
 
3123 3312
 		// Figure out how long they've been logged in.
3124 3313
 		$context['user']['total_time_logged_in'] = array(
@@ -3126,8 +3315,7 @@  discard block
 block discarded – undo
3126 3315
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3127 3316
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3128 3317
 		);
3129
-	}
3130
-	else
3318
+	} else
3131 3319
 	{
3132 3320
 		$context['user']['messages'] = 0;
3133 3321
 		$context['user']['unread_messages'] = 0;
@@ -3135,12 +3323,14 @@  discard block
 block discarded – undo
3135 3323
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3136 3324
 		$context['user']['popup_messages'] = false;
3137 3325
 
3138
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3139
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3326
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3327
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3328
+		}
3140 3329
 
3141 3330
 		// If we've upgraded recently, go easy on the passwords.
3142
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3143
-			$context['disable_login_hashing'] = true;
3331
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3332
+					$context['disable_login_hashing'] = true;
3333
+		}
3144 3334
 	}
3145 3335
 
3146 3336
 	// Setup the main menu items.
@@ -3153,8 +3343,8 @@  discard block
 block discarded – undo
3153 3343
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3154 3344
 
3155 3345
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3156
-	if ($context['show_pm_popup'])
3157
-		addInlineJavaScript('
3346
+	if ($context['show_pm_popup']) {
3347
+			addInlineJavaScript('
3158 3348
 		jQuery(document).ready(function($) {
3159 3349
 			new smc_Popup({
3160 3350
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3162,15 +3352,17 @@  discard block
 block discarded – undo
3162 3352
 				icon_class: \'generic_icons mail_new\'
3163 3353
 			});
3164 3354
 		});');
3355
+	}
3165 3356
 
3166 3357
 	// Add a generic "Are you sure?" confirmation message.
3167 3358
 	addInlineJavaScript('
3168 3359
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3169 3360
 
3170 3361
 	// Now add the capping code for avatars.
3171
-	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')
3172
-		addInlineCss('
3362
+	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') {
3363
+			addInlineCss('
3173 3364
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3365
+	}
3174 3366
 
3175 3367
 	// This looks weird, but it's because BoardIndex.php references the variable.
3176 3368
 	$context['common_stats']['latest_member'] = array(
@@ -3187,11 +3379,13 @@  discard block
 block discarded – undo
3187 3379
 	);
3188 3380
 	$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']);
3189 3381
 
3190
-	if (empty($settings['theme_version']))
3191
-		addJavaScriptVar('smf_scripturl', $scripturl);
3382
+	if (empty($settings['theme_version'])) {
3383
+			addJavaScriptVar('smf_scripturl', $scripturl);
3384
+	}
3192 3385
 
3193
-	if (!isset($context['page_title']))
3194
-		$context['page_title'] = '';
3386
+	if (!isset($context['page_title'])) {
3387
+			$context['page_title'] = '';
3388
+	}
3195 3389
 
3196 3390
 	// Set some specific vars.
3197 3391
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3201,21 +3395,23 @@  discard block
 block discarded – undo
3201 3395
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3202 3396
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3203 3397
 
3204
-	if (!empty($context['meta_keywords']))
3205
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3398
+	if (!empty($context['meta_keywords'])) {
3399
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3400
+	}
3206 3401
 
3207
-	if (!empty($context['canonical_url']))
3208
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3402
+	if (!empty($context['canonical_url'])) {
3403
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3404
+	}
3209 3405
 
3210
-	if (!empty($settings['og_image']))
3211
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3406
+	if (!empty($settings['og_image'])) {
3407
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3408
+	}
3212 3409
 
3213 3410
 	if (!empty($context['meta_description']))
3214 3411
 	{
3215 3412
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3216 3413
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3217
-	}
3218
-	else
3414
+	} else
3219 3415
 	{
3220 3416
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3221 3417
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3240,8 +3436,9 @@  discard block
 block discarded – undo
3240 3436
 	$memory_needed = memoryReturnBytes($needed);
3241 3437
 
3242 3438
 	// should we account for how much is currently being used?
3243
-	if ($in_use)
3244
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3439
+	if ($in_use) {
3440
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3441
+	}
3245 3442
 
3246 3443
 	// if more is needed, request it
3247 3444
 	if ($memory_current < $memory_needed)
@@ -3264,8 +3461,9 @@  discard block
 block discarded – undo
3264 3461
  */
3265 3462
 function memoryReturnBytes($val)
3266 3463
 {
3267
-	if (is_integer($val))
3268
-		return $val;
3464
+	if (is_integer($val)) {
3465
+			return $val;
3466
+	}
3269 3467
 
3270 3468
 	// Separate the number from the designator
3271 3469
 	$val = trim($val);
@@ -3301,10 +3499,11 @@  discard block
 block discarded – undo
3301 3499
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3302 3500
 
3303 3501
 		// Are we debugging the template/html content?
3304
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3305
-			header('Content-Type: application/xhtml+xml');
3306
-		elseif (!isset($_REQUEST['xml']))
3307
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3502
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3503
+					header('Content-Type: application/xhtml+xml');
3504
+		} elseif (!isset($_REQUEST['xml'])) {
3505
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3506
+		}
3308 3507
 	}
3309 3508
 
3310 3509
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3313,8 +3512,9 @@  discard block
 block discarded – undo
3313 3512
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3314 3513
 	{
3315 3514
 		$position = array_search('body', $context['template_layers']);
3316
-		if ($position === false)
3317
-			$position = array_search('main', $context['template_layers']);
3515
+		if ($position === false) {
3516
+					$position = array_search('main', $context['template_layers']);
3517
+		}
3318 3518
 
3319 3519
 		if ($position !== false)
3320 3520
 		{
@@ -3342,23 +3542,25 @@  discard block
 block discarded – undo
3342 3542
 
3343 3543
 			foreach ($securityFiles as $i => $securityFile)
3344 3544
 			{
3345
-				if (!file_exists($boarddir . '/' . $securityFile))
3346
-					unset($securityFiles[$i]);
3545
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3546
+									unset($securityFiles[$i]);
3547
+				}
3347 3548
 			}
3348 3549
 
3349 3550
 			// We are already checking so many files...just few more doesn't make any difference! :P
3350
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3351
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3352
-
3353
-			else
3354
-				$path = $modSettings['attachmentUploadDir'];
3551
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3552
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3553
+			} else {
3554
+							$path = $modSettings['attachmentUploadDir'];
3555
+			}
3355 3556
 
3356 3557
 			secureDirectory($path, true);
3357 3558
 			secureDirectory($cachedir);
3358 3559
 
3359 3560
 			// If agreement is enabled, at least the english version shall exists
3360
-			if ($modSettings['requireAgreement'])
3361
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3561
+			if ($modSettings['requireAgreement']) {
3562
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3563
+			}
3362 3564
 
3363 3565
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3364 3566
 			{
@@ -3373,18 +3575,21 @@  discard block
 block discarded – undo
3373 3575
 					echo '
3374 3576
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3375 3577
 
3376
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3377
-						echo '
3578
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3579
+											echo '
3378 3580
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3581
+					}
3379 3582
 				}
3380 3583
 
3381
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3382
-					echo '
3584
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3585
+									echo '
3383 3586
 				<strong>', $txt['cache_writable'], '</strong><br>';
3587
+				}
3384 3588
 
3385
-				if (!empty($agreement))
3386
-					echo '
3589
+				if (!empty($agreement)) {
3590
+									echo '
3387 3591
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3592
+				}
3388 3593
 
3389 3594
 				echo '
3390 3595
 			</p>
@@ -3399,16 +3604,18 @@  discard block
 block discarded – undo
3399 3604
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3400 3605
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3401 3606
 
3402
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3403
-				echo '
3607
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3608
+							echo '
3404 3609
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3610
+			}
3405 3611
 
3406
-			if (!empty($_SESSION['ban']['expire_time']))
3407
-				echo '
3612
+			if (!empty($_SESSION['ban']['expire_time'])) {
3613
+							echo '
3408 3614
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3409
-			else
3410
-				echo '
3615
+			} else {
3616
+							echo '
3411 3617
 					<div>', $txt['your_ban_expires_never'], '</div>';
3618
+			}
3412 3619
 
3413 3620
 			echo '
3414 3621
 				</div>';
@@ -3424,8 +3631,9 @@  discard block
 block discarded – undo
3424 3631
 	global $forum_copyright, $software_year, $forum_version;
3425 3632
 
3426 3633
 	// Don't display copyright for things like SSI.
3427
-	if (!isset($forum_version) || !isset($software_year))
3428
-		return;
3634
+	if (!isset($forum_version) || !isset($software_year)) {
3635
+			return;
3636
+	}
3429 3637
 
3430 3638
 	// Put in the version...
3431 3639
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3443,9 +3651,10 @@  discard block
 block discarded – undo
3443 3651
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3444 3652
 	$context['load_queries'] = $db_count;
3445 3653
 
3446
-	foreach (array_reverse($context['template_layers']) as $layer)
3447
-		loadSubTemplate($layer . '_below', true);
3448
-}
3654
+	foreach (array_reverse($context['template_layers']) as $layer) {
3655
+			loadSubTemplate($layer . '_below', true);
3656
+	}
3657
+	}
3449 3658
 
3450 3659
 /**
3451 3660
  * Output the Javascript files
@@ -3476,8 +3685,7 @@  discard block
 block discarded – undo
3476 3685
 			{
3477 3686
 				echo '
3478 3687
 		var ', $key, ';';
3479
-			}
3480
-			else
3688
+			} else
3481 3689
 			{
3482 3690
 				echo '
3483 3691
 		var ', $key, ' = ', $value, ';';
@@ -3492,26 +3700,27 @@  discard block
 block discarded – undo
3492 3700
 	foreach ($context['javascript_files'] as $id => $js_file)
3493 3701
 	{
3494 3702
 		// Last minute call! allow theme authors to disable single files.
3495
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3496
-			continue;
3703
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3704
+					continue;
3705
+		}
3497 3706
 
3498 3707
 		// By default all files don't get minimized unless the file explicitly says so!
3499 3708
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3500 3709
 		{
3501
-			if ($do_deferred && !empty($js_file['options']['defer']))
3502
-				$toMinifyDefer[] = $js_file;
3503
-
3504
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3505
-				$toMinify[] = $js_file;
3710
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3711
+							$toMinifyDefer[] = $js_file;
3712
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3713
+							$toMinify[] = $js_file;
3714
+			}
3506 3715
 
3507 3716
 			// Grab a random seed.
3508
-			if (!isset($minSeed))
3509
-				$minSeed = $js_file['options']['seed'];
3510
-		}
3511
-
3512
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3513
-			echo '
3717
+			if (!isset($minSeed)) {
3718
+							$minSeed = $js_file['options']['seed'];
3719
+			}
3720
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3721
+					echo '
3514 3722
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3723
+		}
3515 3724
 	}
3516 3725
 
3517 3726
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3519,14 +3728,14 @@  discard block
 block discarded – undo
3519 3728
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3520 3729
 
3521 3730
 		// Minify process couldn't work, print each individual files.
3522
-		if (!empty($result) && is_array($result))
3523
-			foreach ($result as $minFailedFile)
3731
+		if (!empty($result) && is_array($result)) {
3732
+					foreach ($result as $minFailedFile)
3524 3733
 				echo '
3525 3734
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3526
-
3527
-		else
3528
-			echo '
3735
+		} else {
3736
+					echo '
3529 3737
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3738
+		}
3530 3739
 	}
3531 3740
 
3532 3741
 	// Inline JavaScript - Actually useful some times!
@@ -3537,8 +3746,9 @@  discard block
 block discarded – undo
3537 3746
 			echo '
3538 3747
 <script>';
3539 3748
 
3540
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3541
-				echo $js_code;
3749
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3750
+							echo $js_code;
3751
+			}
3542 3752
 
3543 3753
 			echo '
3544 3754
 </script>';
@@ -3549,8 +3759,9 @@  discard block
 block discarded – undo
3549 3759
 			echo '
3550 3760
 	<script>';
3551 3761
 
3552
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3553
-				echo $js_code;
3762
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3763
+							echo $js_code;
3764
+			}
3554 3765
 
3555 3766
 			echo '
3556 3767
 	</script>';
@@ -3575,8 +3786,9 @@  discard block
 block discarded – undo
3575 3786
 	foreach ($context['css_files'] as $id => $file)
3576 3787
 	{
3577 3788
 		// Last minute call! allow theme authors to disable single files.
3578
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3579
-			continue;
3789
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3790
+					continue;
3791
+		}
3580 3792
 
3581 3793
 		// By default all files don't get minimized unless the file explicitly says so!
3582 3794
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3584,12 +3796,12 @@  discard block
 block discarded – undo
3584 3796
 			$toMinify[] = $file;
3585 3797
 
3586 3798
 			// Grab a random seed.
3587
-			if (!isset($minSeed))
3588
-				$minSeed = $file['options']['seed'];
3799
+			if (!isset($minSeed)) {
3800
+							$minSeed = $file['options']['seed'];
3801
+			}
3802
+		} else {
3803
+					$normal[] = $file['fileUrl'];
3589 3804
 		}
3590
-
3591
-		else
3592
-			$normal[] = $file['fileUrl'];
3593 3805
 	}
3594 3806
 
3595 3807
 	if (!empty($toMinify))
@@ -3597,28 +3809,30 @@  discard block
 block discarded – undo
3597 3809
 		$result = custMinify($toMinify, 'css');
3598 3810
 
3599 3811
 		// Minify process couldn't work, print each individual files.
3600
-		if (!empty($result) && is_array($result))
3601
-			foreach ($result as $minFailedFile)
3812
+		if (!empty($result) && is_array($result)) {
3813
+					foreach ($result as $minFailedFile)
3602 3814
 				echo '
3603 3815
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3604
-
3605
-		else
3606
-			echo '
3816
+		} else {
3817
+					echo '
3607 3818
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3819
+		}
3608 3820
 	}
3609 3821
 
3610 3822
 	// Print the rest after the minified files.
3611
-	if (!empty($normal))
3612
-		foreach ($normal as $nf)
3823
+	if (!empty($normal)) {
3824
+			foreach ($normal as $nf)
3613 3825
 			echo '
3614 3826
 	<link rel="stylesheet" href="', $nf ,'">';
3827
+	}
3615 3828
 
3616 3829
 	if ($db_show_debug === true)
3617 3830
 	{
3618 3831
 		// Try to keep only what's useful.
3619 3832
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3620
-		foreach ($context['css_files'] as $file)
3621
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3833
+		foreach ($context['css_files'] as $file) {
3834
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3835
+		}
3622 3836
 	}
3623 3837
 
3624 3838
 	if (!empty($context['css_header']))
@@ -3626,9 +3840,10 @@  discard block
 block discarded – undo
3626 3840
 		echo '
3627 3841
 	<style>';
3628 3842
 
3629
-		foreach ($context['css_header'] as $css)
3630
-			echo $css .'
3843
+		foreach ($context['css_header'] as $css) {
3844
+					echo $css .'
3631 3845
 	';
3846
+		}
3632 3847
 
3633 3848
 		echo'
3634 3849
 	</style>';
@@ -3652,15 +3867,17 @@  discard block
 block discarded – undo
3652 3867
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3653 3868
 	$data = !empty($data) ? $data : false;
3654 3869
 
3655
-	if (empty($type) || empty($data))
3656
-		return false;
3870
+	if (empty($type) || empty($data)) {
3871
+			return false;
3872
+	}
3657 3873
 
3658 3874
 	// Did we already did this?
3659 3875
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3660 3876
 
3661 3877
 	// Already done?
3662
-	if (!empty($toCache))
3663
-		return true;
3878
+	if (!empty($toCache)) {
3879
+			return true;
3880
+	}
3664 3881
 
3665 3882
 	// No namespaces, sorry!
3666 3883
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3742,8 +3959,9 @@  discard block
 block discarded – undo
3742 3959
 	global $modSettings, $smcFunc;
3743 3960
 
3744 3961
 	// Just make up a nice hash...
3745
-	if ($new)
3746
-		return sha1(md5($filename . time()) . mt_rand());
3962
+	if ($new) {
3963
+			return sha1(md5($filename . time()) . mt_rand());
3964
+	}
3747 3965
 
3748 3966
 	// Just make sure that attachment id is only a int
3749 3967
 	$attachment_id = (int) $attachment_id;
@@ -3760,23 +3978,25 @@  discard block
 block discarded – undo
3760 3978
 				'id_attach' => $attachment_id,
3761 3979
 			));
3762 3980
 
3763
-		if ($smcFunc['db_num_rows']($request) === 0)
3764
-			return false;
3981
+		if ($smcFunc['db_num_rows']($request) === 0) {
3982
+					return false;
3983
+		}
3765 3984
 
3766 3985
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3767 3986
 		$smcFunc['db_free_result']($request);
3768 3987
 	}
3769 3988
 
3770 3989
 	// Still no hash? mmm...
3771
-	if (empty($file_hash))
3772
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3990
+	if (empty($file_hash)) {
3991
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3992
+	}
3773 3993
 
3774 3994
 	// Are we using multiple directories?
3775
-	if (is_array($modSettings['attachmentUploadDir']))
3776
-		$path = $modSettings['attachmentUploadDir'][$dir];
3777
-
3778
-	else
3779
-		$path = $modSettings['attachmentUploadDir'];
3995
+	if (is_array($modSettings['attachmentUploadDir'])) {
3996
+			$path = $modSettings['attachmentUploadDir'][$dir];
3997
+	} else {
3998
+			$path = $modSettings['attachmentUploadDir'];
3999
+	}
3780 4000
 
3781 4001
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3782 4002
 }
@@ -3791,8 +4011,9 @@  discard block
 block discarded – undo
3791 4011
 function ip2range($fullip)
3792 4012
 {
3793 4013
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3794
-	if ($fullip == 'unknown')
3795
-		$fullip = '255.255.255.255';
4014
+	if ($fullip == 'unknown') {
4015
+			$fullip = '255.255.255.255';
4016
+	}
3796 4017
 
3797 4018
 	$ip_parts = explode('-', $fullip);
3798 4019
 	$ip_array = array();
@@ -3816,10 +4037,11 @@  discard block
 block discarded – undo
3816 4037
 		$ip_array['low'] = $ip_parts[0];
3817 4038
 		$ip_array['high'] = $ip_parts[1];
3818 4039
 		return $ip_array;
3819
-	}
3820
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4040
+	} elseif (count($ip_parts) == 2) {
4041
+		// if ip 22.22.*-22.22.*
3821 4042
 	{
3822 4043
 		$valid_low = isValidIP($ip_parts[0]);
4044
+	}
3823 4045
 		$valid_high = isValidIP($ip_parts[1]);
3824 4046
 		$count = 0;
3825 4047
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3834,7 +4056,9 @@  discard block
 block discarded – undo
3834 4056
 				$ip_parts[0] .= $mode . $min;
3835 4057
 				$valid_low = isValidIP($ip_parts[0]);
3836 4058
 				$count++;
3837
-				if ($count > 9) break;
4059
+				if ($count > 9) {
4060
+					break;
4061
+				}
3838 4062
 			}
3839 4063
 		}
3840 4064
 
@@ -3848,7 +4072,9 @@  discard block
 block discarded – undo
3848 4072
 				$ip_parts[1] .= $mode . $max;
3849 4073
 				$valid_high = isValidIP($ip_parts[1]);
3850 4074
 				$count++;
3851
-				if ($count > 9) break;
4075
+				if ($count > 9) {
4076
+					break;
4077
+				}
3852 4078
 			}
3853 4079
 		}
3854 4080
 
@@ -3873,46 +4099,54 @@  discard block
 block discarded – undo
3873 4099
 {
3874 4100
 	global $modSettings;
3875 4101
 
3876
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3877
-		return $host;
4102
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4103
+			return $host;
4104
+	}
3878 4105
 	$t = microtime();
3879 4106
 
3880 4107
 	// Try the Linux host command, perhaps?
3881 4108
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3882 4109
 	{
3883
-		if (!isset($modSettings['host_to_dis']))
3884
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3885
-		else
3886
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4110
+		if (!isset($modSettings['host_to_dis'])) {
4111
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4112
+		} else {
4113
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4114
+		}
3887 4115
 
3888 4116
 		// Did host say it didn't find anything?
3889
-		if (strpos($test, 'not found') !== false)
3890
-			$host = '';
4117
+		if (strpos($test, 'not found') !== false) {
4118
+					$host = '';
4119
+		}
3891 4120
 		// Invalid server option?
3892
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3893
-			updateSettings(array('host_to_dis' => 1));
4121
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4122
+					updateSettings(array('host_to_dis' => 1));
4123
+		}
3894 4124
 		// Maybe it found something, after all?
3895
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3896
-			$host = $match[1];
4125
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4126
+					$host = $match[1];
4127
+		}
3897 4128
 	}
3898 4129
 
3899 4130
 	// This is nslookup; usually only Windows, but possibly some Unix?
3900 4131
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3901 4132
 	{
3902 4133
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3903
-		if (strpos($test, 'Non-existent domain') !== false)
3904
-			$host = '';
3905
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3906
-			$host = $match[1];
4134
+		if (strpos($test, 'Non-existent domain') !== false) {
4135
+					$host = '';
4136
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4137
+					$host = $match[1];
4138
+		}
3907 4139
 	}
3908 4140
 
3909 4141
 	// This is the last try :/.
3910
-	if (!isset($host) || $host === false)
3911
-		$host = @gethostbyaddr($ip);
4142
+	if (!isset($host) || $host === false) {
4143
+			$host = @gethostbyaddr($ip);
4144
+	}
3912 4145
 
3913 4146
 	// It took a long time, so let's cache it!
3914
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3915
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4147
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4148
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4149
+	}
3916 4150
 
3917 4151
 	return $host;
3918 4152
 }
@@ -3948,20 +4182,21 @@  discard block
 block discarded – undo
3948 4182
 			{
3949 4183
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3950 4184
 				$total = 0;
3951
-				for ($i = 0; $i < $max_chars; $i++)
3952
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4185
+				for ($i = 0; $i < $max_chars; $i++) {
4186
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4187
+				}
3953 4188
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3954 4189
 			}
3955 4190
 		}
3956 4191
 		return array_unique($returned_ints);
3957
-	}
3958
-	else
4192
+	} else
3959 4193
 	{
3960 4194
 		// Trim characters before and after and add slashes for database insertion.
3961 4195
 		$returned_words = array();
3962
-		foreach ($words as $word)
3963
-			if (($word = trim($word, '-_\'')) !== '')
4196
+		foreach ($words as $word) {
4197
+					if (($word = trim($word, '-_\'')) !== '')
3964 4198
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4199
+		}
3965 4200
 
3966 4201
 		// Filter out all words that occur more than once.
3967 4202
 		return array_unique($returned_words);
@@ -3983,16 +4218,18 @@  discard block
 block discarded – undo
3983 4218
 	global $settings, $txt;
3984 4219
 
3985 4220
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3986
-	if (function_exists('template_create_button') && !$force_use)
3987
-		return template_create_button($name, $alt, $label = '', $custom = '');
4221
+	if (function_exists('template_create_button') && !$force_use) {
4222
+			return template_create_button($name, $alt, $label = '', $custom = '');
4223
+	}
3988 4224
 
3989
-	if (!$settings['use_image_buttons'])
3990
-		return $txt[$alt];
3991
-	elseif (!empty($settings['use_buttons']))
3992
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3993
-	else
3994
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3995
-}
4225
+	if (!$settings['use_image_buttons']) {
4226
+			return $txt[$alt];
4227
+	} elseif (!empty($settings['use_buttons'])) {
4228
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4229
+	} else {
4230
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4231
+	}
4232
+	}
3996 4233
 
3997 4234
 /**
3998 4235
  * Sets up all of the top menu buttons
@@ -4035,9 +4272,10 @@  discard block
 block discarded – undo
4035 4272
 	var user_menus = new smc_PopupMenu();
4036 4273
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4037 4274
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4038
-		if ($context['allow_pm'])
4039
-			addInlineJavaScript('
4275
+		if ($context['allow_pm']) {
4276
+					addInlineJavaScript('
4040 4277
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4278
+		}
4041 4279
 
4042 4280
 		if (!empty($modSettings['enable_ajax_alerts']))
4043 4281
 		{
@@ -4197,88 +4435,96 @@  discard block
 block discarded – undo
4197 4435
 
4198 4436
 		// Now we put the buttons in the context so the theme can use them.
4199 4437
 		$menu_buttons = array();
4200
-		foreach ($buttons as $act => $button)
4201
-			if (!empty($button['show']))
4438
+		foreach ($buttons as $act => $button) {
4439
+					if (!empty($button['show']))
4202 4440
 			{
4203 4441
 				$button['active_button'] = false;
4442
+		}
4204 4443
 
4205 4444
 				// This button needs some action.
4206
-				if (isset($button['action_hook']))
4207
-					$needs_action_hook = true;
4445
+				if (isset($button['action_hook'])) {
4446
+									$needs_action_hook = true;
4447
+				}
4208 4448
 
4209 4449
 				// Make sure the last button truly is the last button.
4210 4450
 				if (!empty($button['is_last']))
4211 4451
 				{
4212
-					if (isset($last_button))
4213
-						unset($menu_buttons[$last_button]['is_last']);
4452
+					if (isset($last_button)) {
4453
+											unset($menu_buttons[$last_button]['is_last']);
4454
+					}
4214 4455
 					$last_button = $act;
4215 4456
 				}
4216 4457
 
4217 4458
 				// Go through the sub buttons if there are any.
4218
-				if (!empty($button['sub_buttons']))
4219
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4459
+				if (!empty($button['sub_buttons'])) {
4460
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4220 4461
 					{
4221 4462
 						if (empty($subbutton['show']))
4222 4463
 							unset($button['sub_buttons'][$key]);
4464
+				}
4223 4465
 
4224 4466
 						// 2nd level sub buttons next...
4225 4467
 						if (!empty($subbutton['sub_buttons']))
4226 4468
 						{
4227 4469
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4228 4470
 							{
4229
-								if (empty($sub_button2['show']))
4230
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4471
+								if (empty($sub_button2['show'])) {
4472
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4473
+								}
4231 4474
 							}
4232 4475
 						}
4233 4476
 					}
4234 4477
 
4235 4478
 				// Does this button have its own icon?
4236
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4237
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4238
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4239
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4240
-				elseif (isset($button['icon']))
4241
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4242
-				else
4243
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4479
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4480
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4481
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4482
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4483
+				} elseif (isset($button['icon'])) {
4484
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4485
+				} else {
4486
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4487
+				}
4244 4488
 
4245 4489
 				$menu_buttons[$act] = $button;
4246 4490
 			}
4247 4491
 
4248
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4249
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4492
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4493
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4494
+		}
4250 4495
 	}
4251 4496
 
4252 4497
 	$context['menu_buttons'] = $menu_buttons;
4253 4498
 
4254 4499
 	// Logging out requires the session id in the url.
4255
-	if (isset($context['menu_buttons']['logout']))
4256
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4500
+	if (isset($context['menu_buttons']['logout'])) {
4501
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4502
+	}
4257 4503
 
4258 4504
 	// Figure out which action we are doing so we can set the active tab.
4259 4505
 	// Default to home.
4260 4506
 	$current_action = 'home';
4261 4507
 
4262
-	if (isset($context['menu_buttons'][$context['current_action']]))
4263
-		$current_action = $context['current_action'];
4264
-	elseif ($context['current_action'] == 'search2')
4265
-		$current_action = 'search';
4266
-	elseif ($context['current_action'] == 'theme')
4267
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4268
-	elseif ($context['current_action'] == 'register2')
4269
-		$current_action = 'register';
4270
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4271
-		$current_action = 'login';
4272
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4273
-		$current_action = 'moderate';
4508
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4509
+			$current_action = $context['current_action'];
4510
+	} elseif ($context['current_action'] == 'search2') {
4511
+			$current_action = 'search';
4512
+	} elseif ($context['current_action'] == 'theme') {
4513
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4514
+	} elseif ($context['current_action'] == 'register2') {
4515
+			$current_action = 'register';
4516
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4517
+			$current_action = 'login';
4518
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4519
+			$current_action = 'moderate';
4520
+	}
4274 4521
 
4275 4522
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4276 4523
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4277 4524
 	{
4278 4525
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4279 4526
 		$context[$current_action] = true;
4280
-	}
4281
-	elseif ($context['current_action'] == 'pm')
4527
+	} elseif ($context['current_action'] == 'pm')
4282 4528
 	{
4283 4529
 		$current_action = 'self_pm';
4284 4530
 		$context['self_pm'] = true;
@@ -4319,12 +4565,14 @@  discard block
 block discarded – undo
4319 4565
 	}
4320 4566
 
4321 4567
 	// Not all actions are simple.
4322
-	if (!empty($needs_action_hook))
4323
-		call_integration_hook('integrate_current_action', array(&$current_action));
4568
+	if (!empty($needs_action_hook)) {
4569
+			call_integration_hook('integrate_current_action', array(&$current_action));
4570
+	}
4324 4571
 
4325
-	if (isset($context['menu_buttons'][$current_action]))
4326
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4327
-}
4572
+	if (isset($context['menu_buttons'][$current_action])) {
4573
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4574
+	}
4575
+	}
4328 4576
 
4329 4577
 /**
4330 4578
  * Generate a random seed and ensure it's stored in settings.
@@ -4348,30 +4596,35 @@  discard block
 block discarded – undo
4348 4596
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4349 4597
 	global $context, $txt;
4350 4598
 
4351
-	if ($db_show_debug === true)
4352
-		$context['debug']['hooks'][] = $hook;
4599
+	if ($db_show_debug === true) {
4600
+			$context['debug']['hooks'][] = $hook;
4601
+	}
4353 4602
 
4354 4603
 	// Need to have some control.
4355
-	if (!isset($context['instances']))
4356
-		$context['instances'] = array();
4604
+	if (!isset($context['instances'])) {
4605
+			$context['instances'] = array();
4606
+	}
4357 4607
 
4358 4608
 	$results = array();
4359
-	if (empty($modSettings[$hook]))
4360
-		return $results;
4609
+	if (empty($modSettings[$hook])) {
4610
+			return $results;
4611
+	}
4361 4612
 
4362 4613
 	$functions = explode(',', $modSettings[$hook]);
4363 4614
 	// Loop through each function.
4364 4615
 	foreach ($functions as $function)
4365 4616
 	{
4366 4617
 		// Hook has been marked as "disabled". Skip it!
4367
-		if (strpos($function, '!') !== false)
4368
-			continue;
4618
+		if (strpos($function, '!') !== false) {
4619
+					continue;
4620
+		}
4369 4621
 
4370 4622
 		$call = call_helper($function, true);
4371 4623
 
4372 4624
 		// Is it valid?
4373
-		if (!empty($call))
4374
-			$results[$function] = call_user_func_array($call, $parameters);
4625
+		if (!empty($call)) {
4626
+					$results[$function] = call_user_func_array($call, $parameters);
4627
+		}
4375 4628
 
4376 4629
 		// Whatever it was suppose to call, it failed :(
4377 4630
 		elseif (!empty($function))
@@ -4387,8 +4640,9 @@  discard block
 block discarded – undo
4387 4640
 			}
4388 4641
 
4389 4642
 			// "Assume" the file resides on $boarddir somewhere...
4390
-			else
4391
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4643
+			else {
4644
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4645
+			}
4392 4646
 		}
4393 4647
 	}
4394 4648
 
@@ -4410,12 +4664,14 @@  discard block
 block discarded – undo
4410 4664
 	global $smcFunc, $modSettings;
4411 4665
 
4412 4666
 	// Any objects?
4413
-	if ($object)
4414
-		$function = $function . '#';
4667
+	if ($object) {
4668
+			$function = $function . '#';
4669
+	}
4415 4670
 
4416 4671
 	// Any files  to load?
4417
-	if (!empty($file) && is_string($file))
4418
-		$function = $file . (!empty($function) ? '|' . $function : '');
4672
+	if (!empty($file) && is_string($file)) {
4673
+			$function = $file . (!empty($function) ? '|' . $function : '');
4674
+	}
4419 4675
 
4420 4676
 	// Get the correct string.
4421 4677
 	$integration_call = $function;
@@ -4437,13 +4693,14 @@  discard block
 block discarded – undo
4437 4693
 		if (!empty($current_functions))
4438 4694
 		{
4439 4695
 			$current_functions = explode(',', $current_functions);
4440
-			if (in_array($integration_call, $current_functions))
4441
-				return;
4696
+			if (in_array($integration_call, $current_functions)) {
4697
+							return;
4698
+			}
4442 4699
 
4443 4700
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4701
+		} else {
4702
+					$permanent_functions = array($integration_call);
4444 4703
 		}
4445
-		else
4446
-			$permanent_functions = array($integration_call);
4447 4704
 
4448 4705
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4449 4706
 	}
@@ -4452,8 +4709,9 @@  discard block
 block discarded – undo
4452 4709
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4453 4710
 
4454 4711
 	// Do nothing, if it's already there.
4455
-	if (in_array($integration_call, $functions))
4456
-		return;
4712
+	if (in_array($integration_call, $functions)) {
4713
+			return;
4714
+	}
4457 4715
 
4458 4716
 	$functions[] = $integration_call;
4459 4717
 	$modSettings[$hook] = implode(',', $functions);
@@ -4476,12 +4734,14 @@  discard block
 block discarded – undo
4476 4734
 	global $smcFunc, $modSettings;
4477 4735
 
4478 4736
 	// Any objects?
4479
-	if ($object)
4480
-		$function = $function . '#';
4737
+	if ($object) {
4738
+			$function = $function . '#';
4739
+	}
4481 4740
 
4482 4741
 	// Any files  to load?
4483
-	if (!empty($file) && is_string($file))
4484
-		$function = $file . '|' . $function;
4742
+	if (!empty($file) && is_string($file)) {
4743
+			$function = $file . '|' . $function;
4744
+	}
4485 4745
 
4486 4746
 	// Get the correct string.
4487 4747
 	$integration_call = $function;
@@ -4502,16 +4762,18 @@  discard block
 block discarded – undo
4502 4762
 	{
4503 4763
 		$current_functions = explode(',', $current_functions);
4504 4764
 
4505
-		if (in_array($integration_call, $current_functions))
4506
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4765
+		if (in_array($integration_call, $current_functions)) {
4766
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4767
+		}
4507 4768
 	}
4508 4769
 
4509 4770
 	// Turn the function list into something usable.
4510 4771
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4511 4772
 
4512 4773
 	// You can only remove it if it's available.
4513
-	if (!in_array($integration_call, $functions))
4514
-		return;
4774
+	if (!in_array($integration_call, $functions)) {
4775
+			return;
4776
+	}
4515 4777
 
4516 4778
 	$functions = array_diff($functions, array($integration_call));
4517 4779
 	$modSettings[$hook] = implode(',', $functions);
@@ -4532,17 +4794,20 @@  discard block
 block discarded – undo
4532 4794
 	global $context, $smcFunc, $txt, $db_show_debug;
4533 4795
 
4534 4796
 	// Really?
4535
-	if (empty($string))
4536
-		return false;
4797
+	if (empty($string)) {
4798
+			return false;
4799
+	}
4537 4800
 
4538 4801
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4539 4802
 	// A closure? should be a callable one.
4540
-	if (is_array($string) || $string instanceof Closure)
4541
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4803
+	if (is_array($string) || $string instanceof Closure) {
4804
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4805
+	}
4542 4806
 
4543 4807
 	// No full objects, sorry! pass a method or a property instead!
4544
-	if (is_object($string))
4545
-		return false;
4808
+	if (is_object($string)) {
4809
+			return false;
4810
+	}
4546 4811
 
4547 4812
 	// Stay vitaminized my friends...
4548 4813
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4551,8 +4816,9 @@  discard block
 block discarded – undo
4551 4816
 	$string = load_file($string);
4552 4817
 
4553 4818
 	// Loaded file failed
4554
-	if (empty($string))
4555
-		return false;
4819
+	if (empty($string)) {
4820
+			return false;
4821
+	}
4556 4822
 
4557 4823
 	// Found a method.
4558 4824
 	if (strpos($string, '::') !== false)
@@ -4573,8 +4839,9 @@  discard block
 block discarded – undo
4573 4839
 				// Add another one to the list.
4574 4840
 				if ($db_show_debug === true)
4575 4841
 				{
4576
-					if (!isset($context['debug']['instances']))
4577
-						$context['debug']['instances'] = array();
4842
+					if (!isset($context['debug']['instances'])) {
4843
+											$context['debug']['instances'] = array();
4844
+					}
4578 4845
 
4579 4846
 					$context['debug']['instances'][$class] = $class;
4580 4847
 				}
@@ -4584,13 +4851,15 @@  discard block
 block discarded – undo
4584 4851
 		}
4585 4852
 
4586 4853
 		// Right then. This is a call to a static method.
4587
-		else
4588
-			$func = array($class, $method);
4854
+		else {
4855
+					$func = array($class, $method);
4856
+		}
4589 4857
 	}
4590 4858
 
4591 4859
 	// Nope! just a plain regular function.
4592
-	else
4593
-		$func = $string;
4860
+	else {
4861
+			$func = $string;
4862
+	}
4594 4863
 
4595 4864
 	// Right, we got what we need, time to do some checks.
4596 4865
 	if (!is_callable($func, false, $callable_name))
@@ -4606,17 +4875,18 @@  discard block
 block discarded – undo
4606 4875
 	else
4607 4876
 	{
4608 4877
 		// What are we gonna do about it?
4609
-		if ($return)
4610
-			return $func;
4878
+		if ($return) {
4879
+					return $func;
4880
+		}
4611 4881
 
4612 4882
 		// If this is a plain function, avoid the heat of calling call_user_func().
4613 4883
 		else
4614 4884
 		{
4615
-			if (is_array($func))
4616
-				call_user_func($func);
4617
-
4618
-			else
4619
-				$func();
4885
+			if (is_array($func)) {
4886
+							call_user_func($func);
4887
+			} else {
4888
+							$func();
4889
+			}
4620 4890
 		}
4621 4891
 	}
4622 4892
 }
@@ -4633,31 +4903,34 @@  discard block
 block discarded – undo
4633 4903
 {
4634 4904
 	global $sourcedir, $txt, $boarddir, $settings;
4635 4905
 
4636
-	if (empty($string))
4637
-		return false;
4906
+	if (empty($string)) {
4907
+			return false;
4908
+	}
4638 4909
 
4639 4910
 	if (strpos($string, '|') !== false)
4640 4911
 	{
4641 4912
 		list ($file, $string) = explode('|', $string);
4642 4913
 
4643 4914
 		// Match the wildcards to their regular vars.
4644
-		if (empty($settings['theme_dir']))
4645
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4646
-
4647
-		else
4648
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4915
+		if (empty($settings['theme_dir'])) {
4916
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4917
+		} else {
4918
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4919
+		}
4649 4920
 
4650 4921
 		// Load the file if it can be loaded.
4651
-		if (file_exists($absPath))
4652
-			require_once($absPath);
4922
+		if (file_exists($absPath)) {
4923
+					require_once($absPath);
4924
+		}
4653 4925
 
4654 4926
 		// No? try a fallback to $sourcedir
4655 4927
 		else
4656 4928
 		{
4657 4929
 			$absPath = $sourcedir .'/'. $file;
4658 4930
 
4659
-			if (file_exists($absPath))
4660
-				require_once($absPath);
4931
+			if (file_exists($absPath)) {
4932
+							require_once($absPath);
4933
+			}
4661 4934
 
4662 4935
 			// Sorry, can't do much for you at this point.
4663 4936
 			else
@@ -4684,8 +4957,9 @@  discard block
 block discarded – undo
4684 4957
 	global $user_info, $smcFunc;
4685 4958
 
4686 4959
 	// Make sure we have something to work with.
4687
-	if (empty($topic))
4688
-		return array();
4960
+	if (empty($topic)) {
4961
+			return array();
4962
+	}
4689 4963
 
4690 4964
 
4691 4965
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4708,8 +4982,9 @@  discard block
 block discarded – undo
4708 4982
 				'topic' => $topic,
4709 4983
 			)
4710 4984
 		);
4711
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4712
-			$temp[] = (int) $row['content_id'];
4985
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4986
+					$temp[] = (int) $row['content_id'];
4987
+		}
4713 4988
 
4714 4989
 		cache_put_data($cache_key, $temp, $ttl);
4715 4990
 	}
@@ -4730,8 +5005,9 @@  discard block
 block discarded – undo
4730 5005
 {
4731 5006
 	global $context;
4732 5007
 
4733
-	if (empty($string))
4734
-		return $string;
5008
+	if (empty($string)) {
5009
+			return $string;
5010
+	}
4735 5011
 
4736 5012
 	// UTF-8 occurences of MS special characters
4737 5013
 	$findchars_utf8 = array(
@@ -4772,10 +5048,11 @@  discard block
 block discarded – undo
4772 5048
 		'--',	// &mdash;
4773 5049
 	);
4774 5050
 
4775
-	if ($context['utf8'])
4776
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4777
-	else
4778
-		$string = str_replace($findchars_iso, $replacechars, $string);
5051
+	if ($context['utf8']) {
5052
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5053
+	} else {
5054
+			$string = str_replace($findchars_iso, $replacechars, $string);
5055
+	}
4779 5056
 
4780 5057
 	return $string;
4781 5058
 }
@@ -4794,49 +5071,59 @@  discard block
 block discarded – undo
4794 5071
 {
4795 5072
 	global $context;
4796 5073
 
4797
-	if (!isset($matches[2]))
4798
-		return '';
5074
+	if (!isset($matches[2])) {
5075
+			return '';
5076
+	}
4799 5077
 
4800 5078
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4801 5079
 
4802 5080
 	// remove left to right / right to left overrides
4803
-	if ($num === 0x202D || $num === 0x202E)
4804
-		return '';
5081
+	if ($num === 0x202D || $num === 0x202E) {
5082
+			return '';
5083
+	}
4805 5084
 
4806 5085
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4807
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4808
-		return '&#' . $num . ';';
5086
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5087
+			return '&#' . $num . ';';
5088
+	}
4809 5089
 
4810 5090
 	if (empty($context['utf8']))
4811 5091
 	{
4812 5092
 		// no control characters
4813
-		if ($num < 0x20)
4814
-			return '';
5093
+		if ($num < 0x20) {
5094
+					return '';
5095
+		}
4815 5096
 		// text is text
4816
-		elseif ($num < 0x80)
4817
-			return chr($num);
5097
+		elseif ($num < 0x80) {
5098
+					return chr($num);
5099
+		}
4818 5100
 		// all others get html-ised
4819
-		else
4820
-			return '&#' . $matches[2] . ';';
4821
-	}
4822
-	else
5101
+		else {
5102
+					return '&#' . $matches[2] . ';';
5103
+		}
5104
+	} else
4823 5105
 	{
4824 5106
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4825 5107
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4826
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4827
-			return '';
5108
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5109
+					return '';
5110
+		}
4828 5111
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4829
-		elseif ($num < 0x80)
4830
-			return chr($num);
5112
+		elseif ($num < 0x80) {
5113
+					return chr($num);
5114
+		}
4831 5115
 		// <0x800 (2048)
4832
-		elseif ($num < 0x800)
4833
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5116
+		elseif ($num < 0x800) {
5117
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5118
+		}
4834 5119
 		// < 0x10000 (65536)
4835
-		elseif ($num < 0x10000)
4836
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5120
+		elseif ($num < 0x10000) {
5121
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5122
+		}
4837 5123
 		// <= 0x10FFFF (1114111)
4838
-		else
4839
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5124
+		else {
5125
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5126
+		}
4840 5127
 	}
4841 5128
 }
4842 5129
 
@@ -4852,28 +5139,34 @@  discard block
 block discarded – undo
4852 5139
  */
4853 5140
 function fixchar__callback($matches)
4854 5141
 {
4855
-	if (!isset($matches[1]))
4856
-		return '';
5142
+	if (!isset($matches[1])) {
5143
+			return '';
5144
+	}
4857 5145
 
4858 5146
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4859 5147
 
4860 5148
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4861 5149
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4862
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4863
-		return '';
5150
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5151
+			return '';
5152
+	}
4864 5153
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4865
-	elseif ($num < 0x80)
4866
-		return chr($num);
5154
+	elseif ($num < 0x80) {
5155
+			return chr($num);
5156
+	}
4867 5157
 	// <0x800 (2048)
4868
-	elseif ($num < 0x800)
4869
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5158
+	elseif ($num < 0x800) {
5159
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5160
+	}
4870 5161
 	// < 0x10000 (65536)
4871
-	elseif ($num < 0x10000)
4872
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5162
+	elseif ($num < 0x10000) {
5163
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5164
+	}
4873 5165
 	// <= 0x10FFFF (1114111)
4874
-	else
4875
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4876
-}
5166
+	else {
5167
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5168
+	}
5169
+	}
4877 5170
 
4878 5171
 /**
4879 5172
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4886,17 +5179,19 @@  discard block
 block discarded – undo
4886 5179
  */
4887 5180
 function entity_fix__callback($matches)
4888 5181
 {
4889
-	if (!isset($matches[2]))
4890
-		return '';
5182
+	if (!isset($matches[2])) {
5183
+			return '';
5184
+	}
4891 5185
 
4892 5186
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4893 5187
 
4894 5188
 	// we don't allow control characters, characters out of range, byte markers, etc
4895
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4896
-		return '';
4897
-	else
4898
-		return '&#' . $num . ';';
4899
-}
5189
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5190
+			return '';
5191
+	} else {
5192
+			return '&#' . $num . ';';
5193
+	}
5194
+	}
4900 5195
 
4901 5196
 /**
4902 5197
  * Return a Gravatar URL based on
@@ -4920,18 +5215,23 @@  discard block
 block discarded – undo
4920 5215
 		$ratings = array('G', 'PG', 'R', 'X');
4921 5216
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4922 5217
 		$url_params = array();
4923
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4924
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4925
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4926
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4927
-		if (!empty($modSettings['avatar_max_width_external']))
4928
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4929
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4930
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5218
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5219
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5220
+		}
5221
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5222
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5223
+		}
5224
+		if (!empty($modSettings['avatar_max_width_external'])) {
5225
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5226
+		}
5227
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5228
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4931 5229
 				$size_string = $modSettings['avatar_max_height_external'];
5230
+		}
4932 5231
 
4933
-		if (!empty($size_string))
4934
-			$url_params[] = 's=' . $size_string;
5232
+		if (!empty($size_string)) {
5233
+					$url_params[] = 's=' . $size_string;
5234
+		}
4935 5235
 	}
4936 5236
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4937 5237
 
@@ -4950,22 +5250,26 @@  discard block
 block discarded – undo
4950 5250
 	static $timezones = null, $lastwhen = null;
4951 5251
 
4952 5252
 	// No point doing this over if we already did it once
4953
-	if (!empty($timezones) && $when == $lastwhen)
4954
-		return $timezones;
4955
-	else
4956
-		$lastwhen = $when;
5253
+	if (!empty($timezones) && $when == $lastwhen) {
5254
+			return $timezones;
5255
+	} else {
5256
+			$lastwhen = $when;
5257
+	}
4957 5258
 
4958 5259
 	// Parseable datetime string?
4959
-	if (is_int($timestamp = strtotime($when)))
4960
-		$when = $timestamp;
5260
+	if (is_int($timestamp = strtotime($when))) {
5261
+			$when = $timestamp;
5262
+	}
4961 5263
 
4962 5264
 	// A Unix timestamp?
4963
-	elseif (is_numeric($when))
4964
-		$when = intval($when);
5265
+	elseif (is_numeric($when)) {
5266
+			$when = intval($when);
5267
+	}
4965 5268
 
4966 5269
 	// Invalid value? Just get current Unix timestamp.
4967
-	else
4968
-		$when = time();
5270
+	else {
5271
+			$when = time();
5272
+	}
4969 5273
 
4970 5274
 	// We'll need these too
4971 5275
 	$date_when = date_create('@' . $when);
@@ -5029,8 +5333,9 @@  discard block
 block discarded – undo
5029 5333
 	foreach ($priority_countries as $country)
5030 5334
 	{
5031 5335
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5032
-		if (!empty($country_tzids))
5033
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5336
+		if (!empty($country_tzids)) {
5337
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5338
+		}
5034 5339
 	}
5035 5340
 
5036 5341
 	// Process the preferred timezones first, then the rest.
@@ -5040,8 +5345,9 @@  discard block
 block discarded – undo
5040 5345
 	foreach ($tzids as $tzid)
5041 5346
 	{
5042 5347
 		// We don't want UTC right now
5043
-		if ($tzid == 'UTC')
5044
-			continue;
5348
+		if ($tzid == 'UTC') {
5349
+					continue;
5350
+		}
5045 5351
 
5046 5352
 		$tz = timezone_open($tzid);
5047 5353
 
@@ -5056,12 +5362,14 @@  discard block
 block discarded – undo
5056 5362
 		$tzgeo = timezone_location_get($tz);
5057 5363
 
5058 5364
 		// Don't overwrite our preferred tzids
5059
-		if (empty($zones[$tzkey]['tzid']))
5060
-			$zones[$tzkey]['tzid'] = $tzid;
5365
+		if (empty($zones[$tzkey]['tzid'])) {
5366
+					$zones[$tzkey]['tzid'] = $tzid;
5367
+		}
5061 5368
 
5062 5369
 		// A time zone from a prioritized country?
5063
-		if (in_array($tzid, $priority_tzids))
5064
-			$priority_zones[$tzkey] = true;
5370
+		if (in_array($tzid, $priority_tzids)) {
5371
+					$priority_zones[$tzkey] = true;
5372
+		}
5065 5373
 
5066 5374
 		// Keep track of the location and offset for this tzid
5067 5375
 		$tzid_parts = explode('/', $tzid);
@@ -5082,15 +5390,17 @@  discard block
 block discarded – undo
5082 5390
 
5083 5391
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5084 5392
 
5085
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5086
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5087
-		else
5088
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5393
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5394
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5395
+		} else {
5396
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5397
+		}
5089 5398
 
5090
-		if (isset($priority_zones[$tzkey]))
5091
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5092
-		else
5093
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5399
+		if (isset($priority_zones[$tzkey])) {
5400
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5401
+		} else {
5402
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5403
+		}
5094 5404
 	}
5095 5405
 
5096 5406
 	$timezones = array_merge(
@@ -5144,9 +5454,9 @@  discard block
 block discarded – undo
5144 5454
 			'Indian/Kerguelen' => 'TFT',
5145 5455
 		);
5146 5456
 
5147
-		if (!empty($missing_tz_abbrs[$tzid]))
5148
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5149
-		else
5457
+		if (!empty($missing_tz_abbrs[$tzid])) {
5458
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5459
+		} else
5150 5460
 		{
5151 5461
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5152 5462
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5174,8 +5484,9 @@  discard block
 block discarded – undo
5174 5484
  */
5175 5485
 function inet_ptod($ip_address)
5176 5486
 {
5177
-	if (!isValidIP($ip_address))
5178
-		return $ip_address;
5487
+	if (!isValidIP($ip_address)) {
5488
+			return $ip_address;
5489
+	}
5179 5490
 
5180 5491
 	$bin = inet_pton($ip_address);
5181 5492
 	return $bin;
@@ -5187,13 +5498,15 @@  discard block
 block discarded – undo
5187 5498
  */
5188 5499
 function inet_dtop($bin)
5189 5500
 {
5190
-	if(empty($bin))
5191
-		return '';
5501
+	if(empty($bin)) {
5502
+			return '';
5503
+	}
5192 5504
 
5193 5505
 	global $db_type;
5194 5506
 
5195
-	if ($db_type == 'postgresql')
5196
-		return $bin;
5507
+	if ($db_type == 'postgresql') {
5508
+			return $bin;
5509
+	}
5197 5510
 
5198 5511
 	$ip_address = inet_ntop($bin);
5199 5512
 
@@ -5218,26 +5531,32 @@  discard block
 block discarded – undo
5218 5531
  */
5219 5532
 function _safe_serialize($value)
5220 5533
 {
5221
-	if(is_null($value))
5222
-		return 'N;';
5534
+	if(is_null($value)) {
5535
+			return 'N;';
5536
+	}
5223 5537
 
5224
-	if(is_bool($value))
5225
-		return 'b:'. (int) $value .';';
5538
+	if(is_bool($value)) {
5539
+			return 'b:'. (int) $value .';';
5540
+	}
5226 5541
 
5227
-	if(is_int($value))
5228
-		return 'i:'. $value .';';
5542
+	if(is_int($value)) {
5543
+			return 'i:'. $value .';';
5544
+	}
5229 5545
 
5230
-	if(is_float($value))
5231
-		return 'd:'. str_replace(',', '.', $value) .';';
5546
+	if(is_float($value)) {
5547
+			return 'd:'. str_replace(',', '.', $value) .';';
5548
+	}
5232 5549
 
5233
-	if(is_string($value))
5234
-		return 's:'. strlen($value) .':"'. $value .'";';
5550
+	if(is_string($value)) {
5551
+			return 's:'. strlen($value) .':"'. $value .'";';
5552
+	}
5235 5553
 
5236 5554
 	if(is_array($value))
5237 5555
 	{
5238 5556
 		$out = '';
5239
-		foreach($value as $k => $v)
5240
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5557
+		foreach($value as $k => $v) {
5558
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5559
+		}
5241 5560
 
5242 5561
 		return 'a:'. count($value) .':{'. $out .'}';
5243 5562
 	}
@@ -5263,8 +5582,9 @@  discard block
 block discarded – undo
5263 5582
 
5264 5583
 	$out = _safe_serialize($value);
5265 5584
 
5266
-	if (isset($mbIntEnc))
5267
-		mb_internal_encoding($mbIntEnc);
5585
+	if (isset($mbIntEnc)) {
5586
+			mb_internal_encoding($mbIntEnc);
5587
+	}
5268 5588
 
5269 5589
 	return $out;
5270 5590
 }
@@ -5281,8 +5601,9 @@  discard block
 block discarded – undo
5281 5601
 function _safe_unserialize($str)
5282 5602
 {
5283 5603
 	// Input  is not a string.
5284
-	if(empty($str) || !is_string($str))
5285
-		return false;
5604
+	if(empty($str) || !is_string($str)) {
5605
+			return false;
5606
+	}
5286 5607
 
5287 5608
 	$stack = array();
5288 5609
 	$expected = array();
@@ -5298,43 +5619,38 @@  discard block
 block discarded – undo
5298 5619
 	while($state != 1)
5299 5620
 	{
5300 5621
 		$type = isset($str[0]) ? $str[0] : '';
5301
-		if($type == '}')
5302
-			$str = substr($str, 1);
5303
-
5304
-		else if($type == 'N' && $str[1] == ';')
5622
+		if($type == '}') {
5623
+					$str = substr($str, 1);
5624
+		} else if($type == 'N' && $str[1] == ';')
5305 5625
 		{
5306 5626
 			$value = null;
5307 5627
 			$str = substr($str, 2);
5308
-		}
5309
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5628
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5310 5629
 		{
5311 5630
 			$value = $matches[1] == '1' ? true : false;
5312 5631
 			$str = substr($str, 4);
5313
-		}
5314
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5632
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5315 5633
 		{
5316 5634
 			$value = (int)$matches[1];
5317 5635
 			$str = $matches[2];
5318
-		}
5319
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5636
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5320 5637
 		{
5321 5638
 			$value = (float)$matches[1];
5322 5639
 			$str = $matches[3];
5323
-		}
5324
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5640
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5325 5641
 		{
5326 5642
 			$value = substr($matches[2], 0, (int)$matches[1]);
5327 5643
 			$str = substr($matches[2], (int)$matches[1] + 2);
5328
-		}
5329
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5644
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5330 5645
 		{
5331 5646
 			$expectedLength = (int)$matches[1];
5332 5647
 			$str = $matches[2];
5333 5648
 		}
5334 5649
 
5335 5650
 		// Object or unknown/malformed type.
5336
-		else
5337
-			return false;
5651
+		else {
5652
+					return false;
5653
+		}
5338 5654
 
5339 5655
 		switch($state)
5340 5656
 		{
@@ -5362,8 +5678,9 @@  discard block
 block discarded – undo
5362 5678
 				if($type == '}')
5363 5679
 				{
5364 5680
 					// Array size is less than expected.
5365
-					if(count($list) < end($expected))
5366
-						return false;
5681
+					if(count($list) < end($expected)) {
5682
+											return false;
5683
+					}
5367 5684
 
5368 5685
 					unset($list);
5369 5686
 					$list = &$stack[count($stack)-1];
@@ -5372,8 +5689,9 @@  discard block
 block discarded – undo
5372 5689
 					// Go to terminal state if we're at the end of the root array.
5373 5690
 					array_pop($expected);
5374 5691
 
5375
-					if(count($expected) == 0)
5376
-						$state = 1;
5692
+					if(count($expected) == 0) {
5693
+											$state = 1;
5694
+					}
5377 5695
 
5378 5696
 					break;
5379 5697
 				}
@@ -5381,8 +5699,9 @@  discard block
 block discarded – undo
5381 5699
 				if($type == 'i' || $type == 's')
5382 5700
 				{
5383 5701
 					// Array size exceeds expected length.
5384
-					if(count($list) >= end($expected))
5385
-						return false;
5702
+					if(count($list) >= end($expected)) {
5703
+											return false;
5704
+					}
5386 5705
 
5387 5706
 					$key = $value;
5388 5707
 					$state = 3;
@@ -5416,8 +5735,9 @@  discard block
 block discarded – undo
5416 5735
 	}
5417 5736
 
5418 5737
 	// Trailing data in input.
5419
-	if(!empty($str))
5420
-		return false;
5738
+	if(!empty($str)) {
5739
+			return false;
5740
+	}
5421 5741
 
5422 5742
 	return $data;
5423 5743
 }
@@ -5440,8 +5760,9 @@  discard block
 block discarded – undo
5440 5760
 
5441 5761
 	$out = _safe_unserialize($str);
5442 5762
 
5443
-	if (isset($mbIntEnc))
5444
-		mb_internal_encoding($mbIntEnc);
5763
+	if (isset($mbIntEnc)) {
5764
+			mb_internal_encoding($mbIntEnc);
5765
+	}
5445 5766
 
5446 5767
 	return $out;
5447 5768
 }
@@ -5456,12 +5777,14 @@  discard block
 block discarded – undo
5456 5777
 function smf_chmod($file, $value = 0)
5457 5778
 {
5458 5779
 	// No file? no checks!
5459
-	if (empty($file))
5460
-		return false;
5780
+	if (empty($file)) {
5781
+			return false;
5782
+	}
5461 5783
 
5462 5784
 	// Already writable?
5463
-	if (is_writable($file))
5464
-		return true;
5785
+	if (is_writable($file)) {
5786
+			return true;
5787
+	}
5465 5788
 
5466 5789
 	// Do we have a file or a dir?
5467 5790
 	$isDir = is_dir($file);
@@ -5477,10 +5800,9 @@  discard block
 block discarded – undo
5477 5800
 		{
5478 5801
 			$isWritable = true;
5479 5802
 			break;
5803
+		} else {
5804
+					@chmod($file, $val);
5480 5805
 		}
5481
-
5482
-		else
5483
-			@chmod($file, $val);
5484 5806
 	}
5485 5807
 
5486 5808
 	return $isWritable;
@@ -5499,8 +5821,9 @@  discard block
 block discarded – undo
5499 5821
 	global $txt;
5500 5822
 
5501 5823
 	// Come on...
5502
-	if (empty($json) || !is_string($json))
5503
-		return array();
5824
+	if (empty($json) || !is_string($json)) {
5825
+			return array();
5826
+	}
5504 5827
 
5505 5828
 	$returnArray = @json_decode($json, $returnAsArray);
5506 5829
 
@@ -5538,11 +5861,11 @@  discard block
 block discarded – undo
5538 5861
 		$jsonDebug = $jsonDebug[0];
5539 5862
 		loadLanguage('Errors');
5540 5863
 
5541
-		if (!empty($jsonDebug))
5542
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5543
-
5544
-		else
5545
-			log_error($txt['json_'. $jsonError], 'critical');
5864
+		if (!empty($jsonDebug)) {
5865
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5866
+		} else {
5867
+					log_error($txt['json_'. $jsonError], 'critical');
5868
+		}
5546 5869
 
5547 5870
 		// Everyone expects an array.
5548 5871
 		return array();
@@ -5572,8 +5895,9 @@  discard block
 block discarded – undo
5572 5895
 	global $db_show_debug, $modSettings;
5573 5896
 
5574 5897
 	// Defensive programming anyone?
5575
-	if (empty($data))
5576
-		return false;
5898
+	if (empty($data)) {
5899
+			return false;
5900
+	}
5577 5901
 
5578 5902
 	// Don't need extra stuff...
5579 5903
 	$db_show_debug = false;
@@ -5581,11 +5905,11 @@  discard block
 block discarded – undo
5581 5905
 	// Kill anything else.
5582 5906
 	ob_end_clean();
5583 5907
 
5584
-	if (!empty($modSettings['CompressedOutput']))
5585
-		@ob_start('ob_gzhandler');
5586
-
5587
-	else
5588
-		ob_start();
5908
+	if (!empty($modSettings['CompressedOutput'])) {
5909
+			@ob_start('ob_gzhandler');
5910
+	} else {
5911
+			ob_start();
5912
+	}
5589 5913
 
5590 5914
 	// Set the header.
5591 5915
 	header($type);
@@ -5617,8 +5941,9 @@  discard block
 block discarded – undo
5617 5941
 	static $done = false;
5618 5942
 
5619 5943
 	// If we don't need to do anything, don't
5620
-	if (!$update && $done)
5621
-		return;
5944
+	if (!$update && $done) {
5945
+			return;
5946
+	}
5622 5947
 
5623 5948
 	// Should we get a new copy of the official list of TLDs?
5624 5949
 	if ($update)
@@ -5639,10 +5964,11 @@  discard block
 block discarded – undo
5639 5964
 		// Clean $tlds and convert it to an array
5640 5965
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5641 5966
 			$line = trim($line);
5642
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5643
-				return false;
5644
-			else
5645
-				return true;
5967
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5968
+							return false;
5969
+			} else {
5970
+							return true;
5971
+			}
5646 5972
 		});
5647 5973
 
5648 5974
 		// Convert Punycode to Unicode
@@ -5696,8 +6022,9 @@  discard block
 block discarded – undo
5696 6022
 						$idx += $digit * $w;
5697 6023
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5698 6024
 
5699
-						if ($digit < $t)
5700
-							break;
6025
+						if ($digit < $t) {
6026
+													break;
6027
+						}
5701 6028
 
5702 6029
 						$w = (int) ($w * ($base - $t));
5703 6030
 					}
@@ -5706,8 +6033,9 @@  discard block
 block discarded – undo
5706 6033
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5707 6034
 					$delta += intval($delta / ($deco_len + 1));
5708 6035
 
5709
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5710
-						$delta = intval($delta / ($base - $tmin));
6036
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6037
+											$delta = intval($delta / ($base - $tmin));
6038
+					}
5711 6039
 
5712 6040
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5713 6041
 					$is_first = false;
@@ -5716,8 +6044,9 @@  discard block
 block discarded – undo
5716 6044
 
5717 6045
 					if ($deco_len > 0)
5718 6046
 					{
5719
-						for ($i = $deco_len; $i > $idx; $i--)
5720
-							$decoded[$i] = $decoded[($i - 1)];
6047
+						for ($i = $deco_len; $i > $idx; $i--) {
6048
+													$decoded[$i] = $decoded[($i - 1)];
6049
+						}
5721 6050
 					}
5722 6051
 					$decoded[$idx++] = $char;
5723 6052
 				}
@@ -5725,24 +6054,29 @@  discard block
 block discarded – undo
5725 6054
 				foreach ($decoded as $k => $v)
5726 6055
 				{
5727 6056
 					// 7bit are transferred literally
5728
-					if ($v < 128)
5729
-						$output .= chr($v);
6057
+					if ($v < 128) {
6058
+											$output .= chr($v);
6059
+					}
5730 6060
 
5731 6061
 					// 2 bytes
5732
-					elseif ($v < (1 << 11))
5733
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6062
+					elseif ($v < (1 << 11)) {
6063
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6064
+					}
5734 6065
 
5735 6066
 					// 3 bytes
5736
-					elseif ($v < (1 << 16))
5737
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6067
+					elseif ($v < (1 << 16)) {
6068
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6069
+					}
5738 6070
 
5739 6071
 					// 4 bytes
5740
-					elseif ($v < (1 << 21))
5741
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6072
+					elseif ($v < (1 << 21)) {
6073
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6074
+					}
5742 6075
 
5743 6076
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5744
-					else
5745
-						$output .= $safe_char;
6077
+					else {
6078
+											$output .= $safe_char;
6079
+					}
5746 6080
 				}
5747 6081
 
5748 6082
 				$output_parts[] = $output;
@@ -5837,8 +6171,7 @@  discard block
 block discarded – undo
5837 6171
 
5838 6172
 		$strlen = 'mb_strlen';
5839 6173
 		$substr = 'mb_substr';
5840
-	}
5841
-	else
6174
+	} else
5842 6175
 	{
5843 6176
 		$strlen = $smcFunc['strlen'];
5844 6177
 		$substr = $smcFunc['substr'];
@@ -5852,20 +6185,21 @@  discard block
 block discarded – undo
5852 6185
 
5853 6186
 		$first = $substr($string, 0, 1);
5854 6187
 
5855
-		if (empty($index[$first]))
5856
-			$index[$first] = array();
6188
+		if (empty($index[$first])) {
6189
+					$index[$first] = array();
6190
+		}
5857 6191
 
5858 6192
 		if ($strlen($string) > 1)
5859 6193
 		{
5860 6194
 			// Sanity check on recursion
5861
-			if ($depth > 99)
5862
-				$index[$first][$substr($string, 1)] = '';
5863
-
5864
-			else
5865
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6195
+			if ($depth > 99) {
6196
+							$index[$first][$substr($string, 1)] = '';
6197
+			} else {
6198
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6199
+			}
6200
+		} else {
6201
+					$index[$first][''] = '';
5866 6202
 		}
5867
-		else
5868
-			$index[$first][''] = '';
5869 6203
 
5870 6204
 		$depth--;
5871 6205
 		return $index;
@@ -5888,9 +6222,9 @@  discard block
 block discarded – undo
5888 6222
 			$key_regex = preg_quote($key, $delim);
5889 6223
 			$new_key = $key;
5890 6224
 
5891
-			if (empty($value))
5892
-				$sub_regex = '';
5893
-			else
6225
+			if (empty($value)) {
6226
+							$sub_regex = '';
6227
+			} else
5894 6228
 			{
5895 6229
 				$sub_regex = $index_to_regex($value, $delim);
5896 6230
 
@@ -5898,22 +6232,22 @@  discard block
 block discarded – undo
5898 6232
 				{
5899 6233
 					$new_key_array = explode('(?'.'>', $sub_regex);
5900 6234
 					$new_key .= $new_key_array[0];
6235
+				} else {
6236
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5901 6237
 				}
5902
-				else
5903
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5904 6238
 			}
5905 6239
 
5906
-			if ($depth > 1)
5907
-				$regex[$new_key] = $key_regex . $sub_regex;
5908
-			else
6240
+			if ($depth > 1) {
6241
+							$regex[$new_key] = $key_regex . $sub_regex;
6242
+			} else
5909 6243
 			{
5910 6244
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5911 6245
 				{
5912 6246
 					$regex[$new_key] = $key_regex . $sub_regex;
5913 6247
 					unset($index[$key]);
6248
+				} else {
6249
+									break;
5914 6250
 				}
5915
-				else
5916
-					break;
5917 6251
 			}
5918 6252
 		}
5919 6253
 
@@ -5922,10 +6256,11 @@  discard block
 block discarded – undo
5922 6256
 			$l1 = $strlen($k1);
5923 6257
 			$l2 = $strlen($k2);
5924 6258
 
5925
-			if ($l1 == $l2)
5926
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5927
-			else
5928
-				return $l1 > $l2 ? -1 : 1;
6259
+			if ($l1 == $l2) {
6260
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6261
+			} else {
6262
+							return $l1 > $l2 ? -1 : 1;
6263
+			}
5929 6264
 		});
5930 6265
 
5931 6266
 		$depth--;
@@ -5936,15 +6271,18 @@  discard block
 block discarded – undo
5936 6271
 	$index = array();
5937 6272
 	$regexes = array();
5938 6273
 
5939
-	foreach ($strings as $string)
5940
-		$index = $add_string_to_index($string, $index);
6274
+	foreach ($strings as $string) {
6275
+			$index = $add_string_to_index($string, $index);
6276
+	}
5941 6277
 
5942
-	while (!empty($index))
5943
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6278
+	while (!empty($index)) {
6279
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6280
+	}
5944 6281
 
5945 6282
 	// Restore PHP's internal character encoding to whatever it was originally
5946
-	if (!empty($current_encoding))
5947
-		mb_internal_encoding($current_encoding);
6283
+	if (!empty($current_encoding)) {
6284
+			mb_internal_encoding($current_encoding);
6285
+	}
5948 6286
 
5949 6287
 	return $regexes;
5950 6288
 }
Please login to merge, or discard this patch.
other/upgrade.php 4 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -393,6 +393,9 @@  discard block
 block discarded – undo
393 393
 }
394 394
 
395 395
 // Used to direct the user to another location.
396
+/**
397
+ * @param string $location
398
+ */
396 399
 function redirectLocation($location, $addForm = true)
397 400
 {
398 401
 	global $upgradeurl, $upcontext, $command_line;
@@ -1573,6 +1576,9 @@  discard block
 block discarded – undo
1573 1576
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1574 1577
 }
1575 1578
 
1579
+/**
1580
+ * @param string $filename
1581
+ */
1576 1582
 function parse_sql($filename)
1577 1583
 {
1578 1584
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -1607,6 +1613,10 @@  discard block
 block discarded – undo
1607 1613
 
1608 1614
 	// Our custom error handler - does nothing but does stop public errors from XML!
1609 1615
 	set_error_handler(
1616
+
1617
+		/**
1618
+		 * @param string $errno
1619
+		 */
1610 1620
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1611 1621
 		{
1612 1622
 			if ($support_js)
@@ -1853,6 +1863,9 @@  discard block
 block discarded – undo
1853 1863
 	return true;
1854 1864
 }
1855 1865
 
1866
+/**
1867
+ * @param string $string
1868
+ */
1856 1869
 function upgrade_query($string, $unbuffered = false)
1857 1870
 {
1858 1871
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4512,7 +4525,7 @@  discard block
 block discarded – undo
4512 4525
  * @param int $setSize The amount of entries after which to update the database.
4513 4526
  *
4514 4527
  * newCol needs to be a varbinary(16) null able field
4515
- * @return bool
4528
+ * @return boolean|null
4516 4529
  */
4517 4530
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4518 4531
 {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84 84
 if (!file_exists($upgrade_path . '/upgrade-helper.php'))
85
-    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.');
85
+	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.');
86 86
 
87 87
 require_once($upgrade_path . '/upgrade-helper.php');
88 88
 
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
 
1626 1626
 	// Our custom error handler - does nothing but does stop public errors from XML!
1627 1627
 	set_error_handler(
1628
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1628
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1629 1629
 		{
1630 1630
 			if ($support_js)
1631 1631
 				return true;
@@ -2610,94 +2610,94 @@  discard block
 block discarded – undo
2610 2610
 		// Translation table for the character sets not native for MySQL.
2611 2611
 		$translation_tables = array(
2612 2612
 			'windows-1255' => array(
2613
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2614
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2615
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2616
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2617
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2618
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2619
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2620
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2621
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2622
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2623
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2624
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2625
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2626
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2627
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2628
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2629
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2630
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2631
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2632
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2633
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2634
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2635
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2636
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2637
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2638
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2639
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2640
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2641
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2642
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2643
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2644
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2645
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2646
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2647
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2648
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2649
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2650
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2651
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2652
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2653
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2654
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2613
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2614
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2615
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2616
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2617
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2618
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2619
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2620
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2621
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2622
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2623
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2624
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2625
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2626
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2627
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2628
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2629
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2630
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2631
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2632
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2633
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2634
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2635
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2636
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2637
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2638
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2639
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2640
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2641
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2642
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2643
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2644
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2645
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2646
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2647
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2648
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2649
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2650
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2651
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2652
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2653
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2654
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2655 2655
 				'0xFA' => '0xD7AA',
2656 2656
 			),
2657 2657
 			'windows-1253' => array(
2658
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2659
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2660
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2661
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2662
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2663
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2664
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2665
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2666
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2667
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2668
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2669
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2670
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2671
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2672
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2673
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2674
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2675
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2676
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2677
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2678
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2679
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2680
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2681
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2682
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2683
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2684
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2685
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2686
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2687
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2688
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2689
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2690
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2691
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2692
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2693
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2694
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2695
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2696
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2697
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2698
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2699
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2700
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2658
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2659
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2660
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2661
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2662
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2663
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2664
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2665
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2666
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2667
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2668
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2669
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2670
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2671
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2672
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2673
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2674
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2675
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2676
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2677
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2678
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2679
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2680
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2681
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2682
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2683
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2684
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2685
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2686
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2687
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2688
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2689
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2690
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2691
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2692
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2693
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2694
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2695
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2696
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2697
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2698
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2699
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2700
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2701 2701
 			),
2702 2702
 		);
2703 2703
 
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
3800 3800
 			<input type="hidden" name="backup_done" id="backup_done" value="0">
3801 3801
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
3802
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
3802
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
3803 3803
 			<span id="debuginfo"></span>
3804 3804
 			</div>';
3805 3805
 
@@ -4300,7 +4300,7 @@  discard block
 block discarded – undo
4300 4300
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4301 4301
 			<input type="hidden" name="utf8_done" id="utf8_done" value="0">
4302 4302
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4303
-			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12') , 'px; overflow: auto;">
4303
+			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12'), 'px; overflow: auto;">
4304 4304
 			<span id="debuginfo"></span>
4305 4305
 			</div>';
4306 4306
 
@@ -4401,7 +4401,7 @@  discard block
 block discarded – undo
4401 4401
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4402 4402
 			<input type="hidden" name="json_done" id="json_done" value="0">
4403 4403
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4404
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
4404
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
4405 4405
 			<span id="debuginfo"></span>
4406 4406
 			</div>';
4407 4407
 
Please login to merge, or discard this 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']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2881
-				return upgradeExit();
3040
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
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.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 
257 257
 		case 'datetime':
258 258
 			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)
259
-				return 'str_to_date('.
260
-					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]).
259
+				return 'str_to_date(' .
260
+					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]) .
261 261
 					',\'%Y-%m-%d %h:%i:%s\')';
262 262
 			else
263 263
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		$connection
825 825
 	);
826 826
 
827
-	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
827
+	if (!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
828 828
 	{
829 829
 		if ($returnmode == 1)
830 830
 			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
 			$return_var = array();
834 834
 			$count = count($insertRows);
835 835
 			$start = smf_db_insert_id($table, $keys[0]);
836
-			for ($i = 0; $i < $count; $i++ )
836
+			for ($i = 0; $i < $count; $i++)
837 837
 				$return_var[] = $start + $i;
838 838
 		}
839 839
 		return $return_var;
Please login to merge, or discard this patch.
Braces   +251 added lines, -185 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)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 
@@ -71,24 +74,27 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	$smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'',
94 100
 		array(),
@@ -164,34 +170,42 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
174
-		return $user_info[$matches[1]];
181
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
182
+			return $user_info[$matches[1]];
183
+	}
175 184
 
176
-	if ($matches[1] === 'empty')
177
-		return '\'\'';
185
+	if ($matches[1] === 'empty') {
186
+			return '\'\'';
187
+	}
178 188
 
179
-	if (!isset($matches[2]))
180
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
189
+	if (!isset($matches[2])) {
190
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	}
181 192
 
182
-	if ($matches[1] === 'literal')
183
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
193
+	if ($matches[1] === 'literal') {
194
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	}
184 196
 
185
-	if (!isset($values[$matches[2]]))
186
-		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__);
197
+	if (!isset($values[$matches[2]])) {
198
+			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__);
199
+	}
187 200
 
188 201
 	$replacement = $values[$matches[2]];
189 202
 
190 203
 	switch ($matches[1])
191 204
 	{
192 205
 		case 'int':
193
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
194
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
207
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			}
195 209
 			return (string) (int) $replacement;
196 210
 		break;
197 211
 
@@ -203,65 +217,73 @@  discard block
 block discarded – undo
203 217
 		case 'array_int':
204 218
 			if (is_array($replacement))
205 219
 			{
206
-				if (empty($replacement))
207
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				if (empty($replacement)) {
221
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				}
208 223
 
209 224
 				foreach ($replacement as $key => $value)
210 225
 				{
211
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
212
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
227
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					}
213 229
 
214 230
 					$replacement[$key] = (string) (int) $value;
215 231
 				}
216 232
 
217 233
 				return implode(', ', $replacement);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218 236
 			}
219
-			else
220
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 237
 
222 238
 		break;
223 239
 
224 240
 		case 'array_string':
225 241
 			if (is_array($replacement))
226 242
 			{
227
-				if (empty($replacement))
228
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+				if (empty($replacement)) {
244
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				}
229 246
 
230
-				foreach ($replacement as $key => $value)
231
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
247
+				foreach ($replacement as $key => $value) {
248
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				}
232 250
 
233 251
 				return implode(', ', $replacement);
252
+			} else {
253
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234 254
 			}
235
-			else
236
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 255
 		break;
238 256
 
239 257
 		case 'date':
240
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
241
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
242
-			else
243
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
259
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
260
+			} else {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
244 263
 		break;
245 264
 
246 265
 		case 'time':
247
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
248
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
249
-			else
250
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
267
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
268
+			} else {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
251 271
 		break;
252 272
 
253 273
 		case 'datetime':
254
-			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)
255
-				return 'str_to_date('.
274
+			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) {
275
+							return 'str_to_date('.
256 276
 					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]).
257 277
 					',\'%Y-%m-%d %h:%i:%s\')';
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+			} else {
279
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			}
260 281
 		break;
261 282
 
262 283
 		case 'float':
263
-			if (!is_numeric($replacement))
264
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			if (!is_numeric($replacement)) {
285
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			}
265 287
 			return (string) (float) $replacement;
266 288
 		break;
267 289
 
@@ -275,32 +297,37 @@  discard block
 block discarded – undo
275 297
 		break;
276 298
 
277 299
 		case 'inet':
278
-			if ($replacement == 'null' || $replacement == '')
279
-				return 'null';
280
-			if (!isValidIP($replacement))
281
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			if ($replacement == 'null' || $replacement == '') {
301
+							return 'null';
302
+			}
303
+			if (!isValidIP($replacement)) {
304
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305
+			}
282 306
 			//we don't use the native support of mysql > 5.6.2
283 307
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
284 308
 
285 309
 		case 'array_inet':
286 310
 			if (is_array($replacement))
287 311
 			{
288
-				if (empty($replacement))
289
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+				if (empty($replacement)) {
313
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				}
290 315
 
291 316
 				foreach ($replacement as $key => $value)
292 317
 				{
293
-					if ($replacement == 'null' || $replacement == '')
294
-						$replacement[$key] = 'null';
295
-					if (!isValidIP($value))
296
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					if ($replacement == 'null' || $replacement == '') {
319
+											$replacement[$key] = 'null';
320
+					}
321
+					if (!isValidIP($value)) {
322
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
323
+					}
297 324
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
298 325
 				}
299 326
 
300 327
 				return implode(', ', $replacement);
328
+			} else {
329
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
301 330
 			}
302
-			else
303
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304 331
 		break;
305 332
 
306 333
 		default:
@@ -376,22 +403,25 @@  discard block
 block discarded – undo
376 403
 		// Are we in SSI mode?  If so try that username and password first
377 404
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
378 405
 		{
379
-			if (empty($db_persist))
380
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
381
-			else
382
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
406
+			if (empty($db_persist)) {
407
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
408
+			} else {
409
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
410
+			}
383 411
 		}
384 412
 		// Fall back to the regular username and password if need be
385 413
 		if (!$db_connection)
386 414
 		{
387
-			if (empty($db_persist))
388
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
389
-			else
390
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
415
+			if (empty($db_persist)) {
416
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
417
+			} else {
418
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
419
+			}
391 420
 		}
392 421
 
393
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
394
-			$db_connection = false;
422
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
423
+					$db_connection = false;
424
+		}
395 425
 
396 426
 		$connection = $db_connection;
397 427
 	}
@@ -399,18 +429,20 @@  discard block
 block discarded – undo
399 429
 	// One more query....
400 430
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
401 431
 
402
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
403
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
432
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
433
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
434
+	}
404 435
 
405 436
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
406 437
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
407 438
 	{
408 439
 		// Add before LIMIT
409
-		if ($pos = strpos($db_string, 'LIMIT '))
410
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
411
-		else
412
-			// Append it.
440
+		if ($pos = strpos($db_string, 'LIMIT ')) {
441
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
442
+		} else {
443
+					// Append it.
413 444
 			$db_string .= "\n\t\t\tORDER BY null";
445
+		}
414 446
 	}
415 447
 
416 448
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -432,8 +464,9 @@  discard block
 block discarded – undo
432 464
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
433 465
 
434 466
 		// Initialize $db_cache if not already initialized.
435
-		if (!isset($db_cache))
436
-			$db_cache = array();
467
+		if (!isset($db_cache)) {
468
+					$db_cache = array();
469
+		}
437 470
 
438 471
 		if (!empty($_SESSION['debug_redirect']))
439 472
 		{
@@ -459,17 +492,18 @@  discard block
 block discarded – undo
459 492
 		while (true)
460 493
 		{
461 494
 			$pos = strpos($db_string, '\'', $pos + 1);
462
-			if ($pos === false)
463
-				break;
495
+			if ($pos === false) {
496
+							break;
497
+			}
464 498
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
465 499
 
466 500
 			while (true)
467 501
 			{
468 502
 				$pos1 = strpos($db_string, '\'', $pos + 1);
469 503
 				$pos2 = strpos($db_string, '\\', $pos + 1);
470
-				if ($pos1 === false)
471
-					break;
472
-				elseif ($pos2 === false || $pos2 > $pos1)
504
+				if ($pos1 === false) {
505
+									break;
506
+				} elseif ($pos2 === false || $pos2 > $pos1)
473 507
 				{
474 508
 					$pos = $pos1;
475 509
 					break;
@@ -485,29 +519,35 @@  discard block
 block discarded – undo
485 519
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
486 520
 
487 521
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
488
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
489
-			$fail = true;
522
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
523
+					$fail = true;
524
+		}
490 525
 		// Trying to change passwords, slow us down, or something?
491
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
492
-			$fail = true;
493
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
494
-			$fail = true;
526
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
527
+					$fail = true;
528
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
529
+					$fail = true;
530
+		}
495 531
 
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__);
532
+		if (!empty($fail) && function_exists('log_error')) {
533
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
534
+		}
498 535
 	}
499 536
 
500
-	if (empty($db_unbuffered))
501
-		$ret = @mysqli_query($connection, $db_string);
502
-	else
503
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
537
+	if (empty($db_unbuffered)) {
538
+			$ret = @mysqli_query($connection, $db_string);
539
+	} else {
540
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
541
+	}
504 542
 
505
-	if ($ret === false && empty($db_values['db_error_skip']))
506
-		$ret = smf_db_error($db_string, $connection);
543
+	if ($ret === false && empty($db_values['db_error_skip'])) {
544
+			$ret = smf_db_error($db_string, $connection);
545
+	}
507 546
 
508 547
 	// Debugging.
509
-	if (isset($db_show_debug) && $db_show_debug === true)
510
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
548
+	if (isset($db_show_debug) && $db_show_debug === true) {
549
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
550
+	}
511 551
 
512 552
 	return $ret;
513 553
 }
@@ -554,12 +594,13 @@  discard block
 block discarded – undo
554 594
 	// Decide which connection to use
555 595
 	$connection = $connection === null ? $db_connection : $connection;
556 596
 
557
-	if ($type == 'begin')
558
-		return @mysqli_query($connection, 'BEGIN');
559
-	elseif ($type == 'rollback')
560
-		return @mysqli_query($connection, 'ROLLBACK');
561
-	elseif ($type == 'commit')
562
-		return @mysqli_query($connection, 'COMMIT');
597
+	if ($type == 'begin') {
598
+			return @mysqli_query($connection, 'BEGIN');
599
+	} elseif ($type == 'rollback') {
600
+			return @mysqli_query($connection, 'ROLLBACK');
601
+	} elseif ($type == 'commit') {
602
+			return @mysqli_query($connection, 'COMMIT');
603
+	}
563 604
 
564 605
 	return false;
565 606
 }
@@ -599,8 +640,9 @@  discard block
 block discarded – undo
599 640
 	//    2013: Lost connection to server during query.
600 641
 
601 642
 	// Log the error.
602
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
603
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
643
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
644
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
645
+	}
604 646
 
605 647
 	// Database error auto fixing ;).
606 648
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -609,8 +651,9 @@  discard block
 block discarded – undo
609 651
 		$old_cache = @$modSettings['cache_enable'];
610 652
 		$modSettings['cache_enable'] = '1';
611 653
 
612
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
613
-			$db_last_error = max(@$db_last_error, $temp);
654
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
655
+					$db_last_error = max(@$db_last_error, $temp);
656
+		}
614 657
 
615 658
 		if (@$db_last_error < time() - 3600 * 24 * 3)
616 659
 		{
@@ -626,8 +669,9 @@  discard block
 block discarded – undo
626 669
 					foreach ($tables as $table)
627 670
 					{
628 671
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
629
-						if (trim($table) != '')
630
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
672
+						if (trim($table) != '') {
673
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
674
+						}
631 675
 					}
632 676
 				}
633 677
 
@@ -636,8 +680,9 @@  discard block
 block discarded – undo
636 680
 			// Table crashed.  Let's try to fix it.
637 681
 			elseif ($query_errno == 1016)
638 682
 			{
639
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
640
-					$fix_tables = array('`' . $match[1] . '`');
683
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
684
+									$fix_tables = array('`' . $match[1] . '`');
685
+				}
641 686
 			}
642 687
 			// Indexes crashed.  Should be easy to fix!
643 688
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -656,13 +701,15 @@  discard block
 block discarded – undo
656 701
 
657 702
 			// Make a note of the REPAIR...
658 703
 			cache_put_data('db_last_error', time(), 600);
659
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
660
-				updateSettingsFile(array('db_last_error' => time()));
704
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
705
+							updateSettingsFile(array('db_last_error' => time()));
706
+			}
661 707
 
662 708
 			// Attempt to find and repair the broken table.
663
-			foreach ($fix_tables as $table)
664
-				$smcFunc['db_query']('', "
709
+			foreach ($fix_tables as $table) {
710
+							$smcFunc['db_query']('', "
665 711
 					REPAIR TABLE $table", false, false);
712
+			}
666 713
 
667 714
 			// And send off an email!
668 715
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -671,11 +718,12 @@  discard block
 block discarded – undo
671 718
 
672 719
 			// Try the query again...?
673 720
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
674
-			if ($ret !== false)
675
-				return $ret;
721
+			if ($ret !== false) {
722
+							return $ret;
723
+			}
724
+		} else {
725
+					$modSettings['cache_enable'] = $old_cache;
676 726
 		}
677
-		else
678
-			$modSettings['cache_enable'] = $old_cache;
679 727
 
680 728
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
681 729
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -685,22 +733,25 @@  discard block
 block discarded – undo
685 733
 				// Are we in SSI mode?  If so try that username and password first
686 734
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
687 735
 				{
688
-					if (empty($db_persist))
689
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
690
-					else
691
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
736
+					if (empty($db_persist)) {
737
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
738
+					} else {
739
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
740
+					}
692 741
 				}
693 742
 				// Fall back to the regular username and password if need be
694 743
 				if (!$db_connection)
695 744
 				{
696
-					if (empty($db_persist))
697
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
698
-					else
699
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
745
+					if (empty($db_persist)) {
746
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
747
+					} else {
748
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
749
+					}
700 750
 				}
701 751
 
702
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
703
-					$db_connection = false;
752
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
753
+									$db_connection = false;
754
+				}
704 755
 			}
705 756
 
706 757
 			if ($db_connection)
@@ -711,24 +762,27 @@  discard block
 block discarded – undo
711 762
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
712 763
 
713 764
 					$new_errno = mysqli_errno($db_connection);
714
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
715
-						break;
765
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
766
+											break;
767
+					}
716 768
 				}
717 769
 
718 770
 				// If it failed again, shucks to be you... we're not trying it over and over.
719
-				if ($ret !== false)
720
-					return $ret;
771
+				if ($ret !== false) {
772
+									return $ret;
773
+				}
721 774
 			}
722 775
 		}
723 776
 		// Are they out of space, perhaps?
724 777
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
725 778
 		{
726
-			if (!isset($txt))
727
-				$query_error .= ' - check database storage space.';
728
-			else
779
+			if (!isset($txt)) {
780
+							$query_error .= ' - check database storage space.';
781
+			} else
729 782
 			{
730
-				if (!isset($txt['mysql_error_space']))
731
-					loadLanguage('Errors');
783
+				if (!isset($txt['mysql_error_space'])) {
784
+									loadLanguage('Errors');
785
+				}
732 786
 
733 787
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
734 788
 			}
@@ -736,15 +790,17 @@  discard block
 block discarded – undo
736 790
 	}
737 791
 
738 792
 	// Nothing's defined yet... just die with it.
739
-	if (empty($context) || empty($txt))
740
-		die($query_error);
793
+	if (empty($context) || empty($txt)) {
794
+			die($query_error);
795
+	}
741 796
 
742 797
 	// Show an error message, if possible.
743 798
 	$context['error_title'] = $txt['database_error'];
744
-	if (allowedTo('admin_forum'))
745
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
746
-	else
747
-		$context['error_message'] = $txt['try_again'];
799
+	if (allowedTo('admin_forum')) {
800
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
801
+	} else {
802
+			$context['error_message'] = $txt['try_again'];
803
+	}
748 804
 
749 805
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
750 806
 	{
@@ -774,25 +830,28 @@  discard block
 block discarded – undo
774 830
 	$connection = $connection === null ? $db_connection : $connection;
775 831
 
776 832
 	// With nothing to insert, simply return.
777
-	if (empty($data))
778
-		return;
833
+	if (empty($data)) {
834
+			return;
835
+	}
779 836
 
780 837
 	// Replace the prefix holder with the actual prefix.
781 838
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
782 839
 
783 840
 	// Inserting data as a single row can be done as a single array.
784
-	if (!is_array($data[array_rand($data)]))
785
-		$data = array($data);
841
+	if (!is_array($data[array_rand($data)])) {
842
+			$data = array($data);
843
+	}
786 844
 
787 845
 	// Create the mold for a single row insert.
788 846
 	$insertData = '(';
789 847
 	foreach ($columns as $columnName => $type)
790 848
 	{
791 849
 		// Are we restricting the length?
792
-		if (strpos($type, 'string-') !== false)
793
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
794
-		else
795
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+		if (strpos($type, 'string-') !== false) {
851
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
852
+		} else {
853
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+		}
796 855
 	}
797 856
 	$insertData = substr($insertData, 0, -2) . ')';
798 857
 
@@ -801,8 +860,9 @@  discard block
 block discarded – undo
801 860
 
802 861
 	// Here's where the variables are injected to the query.
803 862
 	$insertRows = array();
804
-	foreach ($data as $dataRow)
805
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
863
+	foreach ($data as $dataRow) {
864
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
865
+	}
806 866
 
807 867
 	// Determine the method of insertion.
808 868
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -822,15 +882,16 @@  discard block
 block discarded – undo
822 882
 
823 883
 	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
824 884
 	{
825
-		if ($returnmode == 1)
826
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
827
-		else if ($returnmode == 2)
885
+		if ($returnmode == 1) {
886
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
887
+		} else if ($returnmode == 2)
828 888
 		{
829 889
 			$return_var = array();
830 890
 			$count = count($insertRows);
831 891
 			$start = smf_db_insert_id($table, $keys[0]);
832
-			for ($i = 0; $i < $count; $i++ )
833
-				$return_var[] = $start + $i;
892
+			for ($i = 0; $i < $count; $i++ ) {
893
+							$return_var[] = $start + $i;
894
+			}
834 895
 		}
835 896
 		return $return_var;
836 897
 	}
@@ -848,8 +909,9 @@  discard block
 block discarded – undo
848 909
  */
849 910
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
850 911
 {
851
-	if (empty($log_message))
852
-		$log_message = $error_message;
912
+	if (empty($log_message)) {
913
+			$log_message = $error_message;
914
+	}
853 915
 
854 916
 	foreach (debug_backtrace() as $step)
855 917
 	{
@@ -868,12 +930,14 @@  discard block
 block discarded – undo
868 930
 	}
869 931
 
870 932
 	// A special case - we want the file and line numbers for debugging.
871
-	if ($error_type == 'return')
872
-		return array($file, $line);
933
+	if ($error_type == 'return') {
934
+			return array($file, $line);
935
+	}
873 936
 
874 937
 	// Is always a critical error.
875
-	if (function_exists('log_error'))
876
-		log_error($log_message, 'critical', $file, $line);
938
+	if (function_exists('log_error')) {
939
+			log_error($log_message, 'critical', $file, $line);
940
+	}
877 941
 
878 942
 	if (function_exists('fatal_error'))
879 943
 	{
@@ -881,12 +945,12 @@  discard block
 block discarded – undo
881 945
 
882 946
 		// Cannot continue...
883 947
 		exit;
948
+	} elseif ($error_type) {
949
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
950
+	} else {
951
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
952
+	}
884 953
 	}
885
-	elseif ($error_type)
886
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
887
-	else
888
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
889
-}
890 954
 
891 955
 /**
892 956
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -903,10 +967,11 @@  discard block
 block discarded – undo
903 967
 		'\\' => '\\\\',
904 968
 	);
905 969
 
906
-	if ($translate_human_wildcards)
907
-		$replacements += array(
970
+	if ($translate_human_wildcards) {
971
+			$replacements += array(
908 972
 			'*' => '%',
909 973
 		);
974
+	}
910 975
 
911 976
 	return strtr($string, $replacements);
912 977
 }
@@ -920,8 +985,9 @@  discard block
 block discarded – undo
920 985
  */
921 986
 function smf_is_resource($result)
922 987
 {
923
-	if ($result instanceof mysqli_result)
924
-		return true;
988
+	if ($result instanceof mysqli_result) {
989
+			return true;
990
+	}
925 991
 
926 992
 	return false;
927 993
 }
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.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,19 +466,20 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
@@ -469,14 +490,12 @@  discard block
 block discarded – undo
469 490
 	{
470 491
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
471 492
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
472
-	}
473
-	elseif ($_SESSION['mc']['bq'] != '0=1')
493
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
474 494
 	{
475 495
 		require_once($sourcedir . '/Subs-ReportedContent.php');
476 496
 		$context['open_mod_reports'] = recountOpenReports('posts');
477 497
 		$context['open_member_reports'] = recountOpenReports('members');
478
-	}
479
-	else
498
+	} else
480 499
 	{
481 500
 		$context['open_mod_reports'] = 0;
482 501
 		$context['open_member_reports'] = 0;
@@ -496,8 +515,9 @@  discard block
 block discarded – undo
496 515
 	global $user_info, $smcFunc;
497 516
 
498 517
 	// Don't log web accelerators, it's very confusing...
499
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
500
-		return;
518
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
519
+			return;
520
+	}
501 521
 
502 522
 	$smcFunc['db_insert']('',
503 523
 		'{db_prefix}log_banned',
@@ -507,8 +527,8 @@  discard block
 block discarded – undo
507 527
 	);
508 528
 
509 529
 	// One extra point for these bans.
510
-	if (!empty($ban_ids))
511
-		$smcFunc['db_query']('', '
530
+	if (!empty($ban_ids)) {
531
+			$smcFunc['db_query']('', '
512 532
 			UPDATE {db_prefix}ban_items
513 533
 			SET hits = hits + 1
514 534
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -516,7 +536,8 @@  discard block
 block discarded – undo
516 536
 				'ban_ids' => $ban_ids,
517 537
 			)
518 538
 		);
519
-}
539
+	}
540
+	}
520 541
 
521 542
 /**
522 543
  * Checks if a given email address might be banned.
@@ -532,8 +553,9 @@  discard block
 block discarded – undo
532 553
 	global $txt, $smcFunc;
533 554
 
534 555
 	// Can't ban an empty email
535
-	if (empty($email) || trim($email) == '')
536
-		return;
556
+	if (empty($email) || trim($email) == '') {
557
+			return;
558
+	}
537 559
 
538 560
 	// Let's start with the bans based on your IP/hostname/memberID...
539 561
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -606,16 +628,18 @@  discard block
 block discarded – undo
606 628
 	if ($type == 'post')
607 629
 	{
608 630
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
609
-		if ($check !== $sc)
610
-			$error = 'session_timeout';
631
+		if ($check !== $sc) {
632
+					$error = 'session_timeout';
633
+		}
611 634
 	}
612 635
 
613 636
 	// How about $_GET['sesc']?
614 637
 	elseif ($type == 'get')
615 638
 	{
616 639
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
617
-		if ($check !== $sc)
618
-			$error = 'session_verify_fail';
640
+		if ($check !== $sc) {
641
+					$error = 'session_verify_fail';
642
+		}
619 643
 	}
620 644
 
621 645
 	// Or can it be in either?
@@ -623,13 +647,15 @@  discard block
 block discarded – undo
623 647
 	{
624 648
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
625 649
 
626
-		if ($check !== $sc)
627
-			$error = 'session_verify_fail';
650
+		if ($check !== $sc) {
651
+					$error = 'session_verify_fail';
652
+		}
628 653
 	}
629 654
 
630 655
 	// Verify that they aren't changing user agents on us - that could be bad.
631
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
632
-		$error = 'session_verify_fail';
656
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
657
+			$error = 'session_verify_fail';
658
+	}
633 659
 
634 660
 	// Make sure a page with session check requirement is not being prefetched.
635 661
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -640,30 +666,35 @@  discard block
 block discarded – undo
640 666
 	}
641 667
 
642 668
 	// Check the referring site - it should be the same server at least!
643
-	if (isset($_SESSION['request_referer']))
644
-		$referrer = $_SESSION['request_referer'];
645
-	else
646
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
669
+	if (isset($_SESSION['request_referer'])) {
670
+			$referrer = $_SESSION['request_referer'];
671
+	} else {
672
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
673
+	}
647 674
 	if (!empty($referrer['host']))
648 675
 	{
649
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
650
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
651
-		else
652
-			$real_host = $_SERVER['HTTP_HOST'];
676
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
677
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
678
+		} else {
679
+					$real_host = $_SERVER['HTTP_HOST'];
680
+		}
653 681
 
654 682
 		$parsed_url = parse_url($boardurl);
655 683
 
656 684
 		// Are global cookies on?  If so, let's check them ;).
657 685
 		if (!empty($modSettings['globalCookies']))
658 686
 		{
659
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
660
-				$parsed_url['host'] = $parts[1];
687
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
688
+							$parsed_url['host'] = $parts[1];
689
+			}
661 690
 
662
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
663
-				$referrer['host'] = $parts[1];
691
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
692
+							$referrer['host'] = $parts[1];
693
+			}
664 694
 
665
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
666
-				$real_host = $parts[1];
695
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
696
+							$real_host = $parts[1];
697
+			}
667 698
 		}
668 699
 
669 700
 		// Okay: referrer must either match parsed_url or real_host.
@@ -681,12 +712,14 @@  discard block
 block discarded – undo
681 712
 		$log_error = true;
682 713
 	}
683 714
 
684
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
685
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
715
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
716
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
717
+	}
686 718
 
687 719
 	// Everything is ok, return an empty string.
688
-	if (!isset($error))
689
-		return '';
720
+	if (!isset($error)) {
721
+			return '';
722
+	}
690 723
 	// A session error occurred, show the error.
691 724
 	elseif ($is_fatal)
692 725
 	{
@@ -695,13 +728,14 @@  discard block
 block discarded – undo
695 728
 			ob_end_clean();
696 729
 			header('HTTP/1.1 403 Forbidden - Session timeout');
697 730
 			die;
731
+		} else {
732
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
698 733
 		}
699
-		else
700
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
701 734
 	}
702 735
 	// A session error occurred, return the error to the calling function.
703
-	else
704
-		return $error;
736
+	else {
737
+			return $error;
738
+	}
705 739
 
706 740
 	// We really should never fall through here, for very important reasons.  Let's make sure.
707 741
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -717,10 +751,9 @@  discard block
 block discarded – undo
717 751
 {
718 752
 	global $modSettings;
719 753
 
720
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
721
-		return true;
722
-
723
-	else
754
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
755
+			return true;
756
+	} else
724 757
 	{
725 758
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
726 759
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -771,9 +804,9 @@  discard block
 block discarded – undo
771 804
 			$return = $_SESSION['token'][$type . '-' . $action][3];
772 805
 			unset($_SESSION['token'][$type . '-' . $action]);
773 806
 			return $return;
807
+		} else {
808
+					return '';
774 809
 		}
775
-		else
776
-			return '';
777 810
 	}
778 811
 
779 812
 	// This nasty piece of code validates a token.
@@ -804,12 +837,14 @@  discard block
 block discarded – undo
804 837
 		fatal_lang_error('token_verify_fail', false);
805 838
 	}
806 839
 	// Remove this token as its useless
807
-	else
808
-		unset($_SESSION['token'][$type . '-' . $action]);
840
+	else {
841
+			unset($_SESSION['token'][$type . '-' . $action]);
842
+	}
809 843
 
810 844
 	// Randomly check if we should remove some older tokens.
811
-	if (mt_rand(0, 138) == 23)
812
-		cleanTokens();
845
+	if (mt_rand(0, 138) == 23) {
846
+			cleanTokens();
847
+	}
813 848
 
814 849
 	return false;
815 850
 }
@@ -824,14 +859,16 @@  discard block
 block discarded – undo
824 859
 function cleanTokens($complete = false)
825 860
 {
826 861
 	// We appreciate cleaning up after yourselves.
827
-	if (!isset($_SESSION['token']))
828
-		return;
862
+	if (!isset($_SESSION['token'])) {
863
+			return;
864
+	}
829 865
 
830 866
 	// Clean up tokens, trying to give enough time still.
831
-	foreach ($_SESSION['token'] as $key => $data)
832
-		if ($data[2] + 10800 < time() || $complete)
867
+	foreach ($_SESSION['token'] as $key => $data) {
868
+			if ($data[2] + 10800 < time() || $complete)
833 869
 			unset($_SESSION['token'][$key]);
834
-}
870
+	}
871
+	}
835 872
 
836 873
 /**
837 874
  * Check whether a form has been submitted twice.
@@ -849,37 +886,40 @@  discard block
 block discarded – undo
849 886
 {
850 887
 	global $context;
851 888
 
852
-	if (!isset($_SESSION['forms']))
853
-		$_SESSION['forms'] = array();
889
+	if (!isset($_SESSION['forms'])) {
890
+			$_SESSION['forms'] = array();
891
+	}
854 892
 
855 893
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
856 894
 	if ($action == 'register')
857 895
 	{
858 896
 		$context['form_sequence_number'] = 0;
859
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
860
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
897
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
898
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
899
+		}
861 900
 	}
862 901
 	// Check whether the submitted number can be found in the session.
863 902
 	elseif ($action == 'check')
864 903
 	{
865
-		if (!isset($_REQUEST['seqnum']))
866
-			return true;
867
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
904
+		if (!isset($_REQUEST['seqnum'])) {
905
+					return true;
906
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
868 907
 		{
869 908
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
870 909
 			return true;
910
+		} elseif ($is_fatal) {
911
+					fatal_lang_error('error_form_already_submitted', false);
912
+		} else {
913
+					return false;
871 914
 		}
872
-		elseif ($is_fatal)
873
-			fatal_lang_error('error_form_already_submitted', false);
874
-		else
875
-			return false;
876 915
 	}
877 916
 	// Don't check, just free the stack number.
878
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
879
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
880
-	elseif ($action != 'free')
881
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
882
-}
917
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
918
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
919
+	} elseif ($action != 'free') {
920
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
921
+	}
922
+	}
883 923
 
884 924
 /**
885 925
  * Check the user's permissions.
@@ -896,16 +936,19 @@  discard block
 block discarded – undo
896 936
 	global $user_info, $smcFunc;
897 937
 
898 938
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
899
-	if (empty($permission))
900
-		return true;
939
+	if (empty($permission)) {
940
+			return true;
941
+	}
901 942
 
902 943
 	// You're never allowed to do something if your data hasn't been loaded yet!
903
-	if (empty($user_info))
904
-		return false;
944
+	if (empty($user_info)) {
945
+			return false;
946
+	}
905 947
 
906 948
 	// Administrators are supermen :P.
907
-	if ($user_info['is_admin'])
908
-		return true;
949
+	if ($user_info['is_admin']) {
950
+			return true;
951
+	}
909 952
 
910 953
 	// Let's ensure this is an array.
911 954
 	$permission = (array) $permission;
@@ -913,14 +956,16 @@  discard block
 block discarded – undo
913 956
 	// Are we checking the _current_ board, or some other boards?
914 957
 	if ($boards === null)
915 958
 	{
916
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
917
-			return true;
959
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
960
+					return true;
961
+		}
918 962
 		// You aren't allowed, by default.
919
-		else
920
-			return false;
963
+		else {
964
+					return false;
965
+		}
966
+	} elseif (!is_array($boards)) {
967
+			$boards = array($boards);
921 968
 	}
922
-	elseif (!is_array($boards))
923
-		$boards = array($boards);
924 969
 
925 970
 	$request = $smcFunc['db_query']('', '
926 971
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -943,12 +988,14 @@  discard block
 block discarded – undo
943 988
 	);
944 989
 
945 990
 	// Make sure they can do it on all of the boards.
946
-	if ($smcFunc['db_num_rows']($request) != count($boards))
947
-		return false;
991
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
992
+			return false;
993
+	}
948 994
 
949 995
 	$result = true;
950
-	while ($row = $smcFunc['db_fetch_assoc']($request))
951
-		$result &= !empty($row['add_deny']);
996
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
997
+			$result &= !empty($row['add_deny']);
998
+	}
952 999
 	$smcFunc['db_free_result']($request);
953 1000
 
954 1001
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1013,9 +1060,10 @@  discard block
 block discarded – undo
1013 1060
 
1014 1061
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1015 1062
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1016
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1017
-		validateSession();
1018
-}
1063
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1064
+			validateSession();
1065
+	}
1066
+	}
1019 1067
 
1020 1068
 /**
1021 1069
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1034,8 +1082,9 @@  discard block
 block discarded – undo
1034 1082
 	global $user_info, $smcFunc;
1035 1083
 
1036 1084
 	// Arrays are nice, most of the time.
1037
-	if (!is_array($permissions))
1038
-		$permissions = array($permissions);
1085
+	if (!is_array($permissions)) {
1086
+			$permissions = array($permissions);
1087
+	}
1039 1088
 
1040 1089
 	/*
1041 1090
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1047,13 +1096,14 @@  discard block
 block discarded – undo
1047 1096
 	// Administrators are all powerful, sorry.
1048 1097
 	if ($user_info['is_admin'])
1049 1098
 	{
1050
-		if ($simple)
1051
-			return array(0);
1052
-		else
1099
+		if ($simple) {
1100
+					return array(0);
1101
+		} else
1053 1102
 		{
1054 1103
 			$boards = array();
1055
-			foreach ($permissions as $permission)
1056
-				$boards[$permission] = array(0);
1104
+			foreach ($permissions as $permission) {
1105
+							$boards[$permission] = array(0);
1106
+			}
1057 1107
 
1058 1108
 			return $boards;
1059 1109
 		}
@@ -1085,31 +1135,32 @@  discard block
 block discarded – undo
1085 1135
 	{
1086 1136
 		if ($simple)
1087 1137
 		{
1088
-			if (empty($row['add_deny']))
1089
-				$deny_boards[] = $row['id_board'];
1090
-			else
1091
-				$boards[] = $row['id_board'];
1092
-		}
1093
-		else
1138
+			if (empty($row['add_deny'])) {
1139
+							$deny_boards[] = $row['id_board'];
1140
+			} else {
1141
+							$boards[] = $row['id_board'];
1142
+			}
1143
+		} else
1094 1144
 		{
1095
-			if (empty($row['add_deny']))
1096
-				$deny_boards[$row['permission']][] = $row['id_board'];
1097
-			else
1098
-				$boards[$row['permission']][] = $row['id_board'];
1145
+			if (empty($row['add_deny'])) {
1146
+							$deny_boards[$row['permission']][] = $row['id_board'];
1147
+			} else {
1148
+							$boards[$row['permission']][] = $row['id_board'];
1149
+			}
1099 1150
 		}
1100 1151
 	}
1101 1152
 	$smcFunc['db_free_result']($request);
1102 1153
 
1103
-	if ($simple)
1104
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1105
-	else
1154
+	if ($simple) {
1155
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1156
+	} else
1106 1157
 	{
1107 1158
 		foreach ($permissions as $permission)
1108 1159
 		{
1109 1160
 			// never had it to start with
1110
-			if (empty($boards[$permission]))
1111
-				$boards[$permission] = array();
1112
-			else
1161
+			if (empty($boards[$permission])) {
1162
+							$boards[$permission] = array();
1163
+			} else
1113 1164
 			{
1114 1165
 				// Or it may have been removed
1115 1166
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1145,10 +1196,11 @@  discard block
 block discarded – undo
1145 1196
 
1146 1197
 
1147 1198
 	// Moderators are free...
1148
-	if (!allowedTo('moderate_board'))
1149
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1150
-	else
1151
-		$timeLimit = 2;
1199
+	if (!allowedTo('moderate_board')) {
1200
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1201
+	} else {
1202
+			$timeLimit = 2;
1203
+	}
1152 1204
 
1153 1205
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1154 1206
 
@@ -1175,8 +1227,9 @@  discard block
 block discarded – undo
1175 1227
 	if ($smcFunc['db_affected_rows']() != 1)
1176 1228
 	{
1177 1229
 		// Spammer!  You only have to wait a *few* seconds!
1178
-		if (!$only_return_result)
1179
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1230
+		if (!$only_return_result) {
1231
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1232
+		}
1180 1233
 
1181 1234
 		return true;
1182 1235
 	}
@@ -1194,11 +1247,13 @@  discard block
 block discarded – undo
1194 1247
  */
1195 1248
 function secureDirectory($path, $attachments = false)
1196 1249
 {
1197
-	if (empty($path))
1198
-		return 'empty_path';
1250
+	if (empty($path)) {
1251
+			return 'empty_path';
1252
+	}
1199 1253
 
1200
-	if (!is_writable($path))
1201
-		return 'path_not_writable';
1254
+	if (!is_writable($path)) {
1255
+			return 'path_not_writable';
1256
+	}
1202 1257
 
1203 1258
 	$directoryname = basename($path);
1204 1259
 
@@ -1210,9 +1265,9 @@  discard block
 block discarded – undo
1210 1265
 
1211 1266
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1212 1267
 
1213
-	if (file_exists($path . '/.htaccess'))
1214
-		$errors[] = 'htaccess_exists';
1215
-	else
1268
+	if (file_exists($path . '/.htaccess')) {
1269
+			$errors[] = 'htaccess_exists';
1270
+	} else
1216 1271
 	{
1217 1272
 		$fh = @fopen($path . '/.htaccess', 'w');
1218 1273
 		if ($fh) {
@@ -1224,9 +1279,9 @@  discard block
 block discarded – undo
1224 1279
 		$errors[] = 'htaccess_cannot_create_file';
1225 1280
 	}
1226 1281
 
1227
-	if (file_exists($path . '/index.php'))
1228
-		$errors[] = 'index-php_exists';
1229
-	else
1282
+	if (file_exists($path . '/index.php')) {
1283
+			$errors[] = 'index-php_exists';
1284
+	} else
1230 1285
 	{
1231 1286
 		$fh = @fopen($path . '/index.php', 'w');
1232 1287
 		if ($fh) {
@@ -1253,11 +1308,12 @@  discard block
 block discarded – undo
1253 1308
 		$errors[] = 'index-php_cannot_create_file';
1254 1309
 	}
1255 1310
 
1256
-	if (!empty($errors))
1257
-		return $errors;
1258
-	else
1259
-		return true;
1260
-}
1311
+	if (!empty($errors)) {
1312
+			return $errors;
1313
+	} else {
1314
+			return true;
1315
+	}
1316
+	}
1261 1317
 
1262 1318
 /**
1263 1319
 * This sets the X-Frame-Options header.
@@ -1270,14 +1326,16 @@  discard block
 block discarded – undo
1270 1326
 	global $modSettings;
1271 1327
 
1272 1328
 	$option = 'SAMEORIGIN';
1273
-	if (is_null($override) && !empty($modSettings['frame_security']))
1274
-		$option = $modSettings['frame_security'];
1275
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1276
-		$option = $override;
1329
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1330
+			$option = $modSettings['frame_security'];
1331
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1332
+			$option = $override;
1333
+	}
1277 1334
 
1278 1335
 	// Don't bother setting the header if we have disabled it.
1279
-	if ($option == 'DISABLE')
1280
-		return;
1336
+	if ($option == 'DISABLE') {
1337
+			return;
1338
+	}
1281 1339
 
1282 1340
 	// Finally set it.
1283 1341
 	header('X-Frame-Options: ' . $option);
Please login to merge, or discard this patch.
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 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
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.