Completed
Push — release-2.1 ( e8fdb7...e47446 )
by Mathias
07:58
created
Sources/Subs-Db-mysql.php 1 patch
Braces   +257 added lines, -189 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
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',
@@ -59,9 +60,11 @@  discard block
 block discarded – undo
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 			'db_mb4'                    => false,
61 62
 		);
63
+	}
62 64
 
63
-	if (!empty($db_options['persist']))
64
-		$db_server = 'p:' . $db_server;
65
+	if (!empty($db_options['persist'])) {
66
+			$db_server = 'p:' . $db_server;
67
+	}
65 68
 
66 69
 	$connection = mysqli_init();
67 70
 	
@@ -70,31 +73,35 @@  discard block
 block discarded – undo
70 73
 	$success = false;
71 74
 	
72 75
 	if ($connection) {
73
-		if (!empty($db_options['port']))
74
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
75
-		else
76
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
76
+		if (!empty($db_options['port'])) {
77
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
78
+		} else {
79
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
80
+		}
77 81
 	}
78 82
 
79 83
 	// Something's wrong, show an error if its fatal (which we assume it is)
80 84
 	if ($success === false)
81 85
 	{
82
-		if (!empty($db_options['non_fatal']))
83
-			return null;
84
-		else
85
-			display_db_error();
86
+		if (!empty($db_options['non_fatal'])) {
87
+					return null;
88
+		} else {
89
+					display_db_error();
90
+		}
86 91
 	}
87 92
 
88 93
 	// Select the database, unless told not to
89
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
90
-		display_db_error();
94
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
95
+			display_db_error();
96
+	}
91 97
 
92 98
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
93
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
94
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
99
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
100
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
95 101
 		array(),
96 102
 		false
97 103
 	);
104
+	}
98 105
 
99 106
 	return $connection;
100 107
 }
@@ -165,37 +172,46 @@  discard block
 block discarded – undo
165 172
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
166 173
 
167 174
 	list ($values, $connection) = $db_callback;
168
-	if (!is_object($connection))
169
-		display_db_error();
175
+	if (!is_object($connection)) {
176
+			display_db_error();
177
+	}
170 178
 
171
-	if ($matches[1] === 'db_prefix')
172
-		return $db_prefix;
179
+	if ($matches[1] === 'db_prefix') {
180
+			return $db_prefix;
181
+	}
173 182
 
174
-	if ($matches[1] === 'query_see_board')
175
-		return $user_info['query_see_board'];
183
+	if ($matches[1] === 'query_see_board') {
184
+			return $user_info['query_see_board'];
185
+	}
176 186
 
177
-	if ($matches[1] === 'query_wanna_see_board')
178
-		return $user_info['query_wanna_see_board'];
187
+	if ($matches[1] === 'query_wanna_see_board') {
188
+			return $user_info['query_wanna_see_board'];
189
+	}
179 190
 
180
-	if ($matches[1] === 'empty')
181
-		return '\'\'';
191
+	if ($matches[1] === 'empty') {
192
+			return '\'\'';
193
+	}
182 194
 
183
-	if (!isset($matches[2]))
184
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
195
+	if (!isset($matches[2])) {
196
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
197
+	}
185 198
 
186
-	if ($matches[1] === 'literal')
187
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
199
+	if ($matches[1] === 'literal') {
200
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
201
+	}
188 202
 
189
-	if (!isset($values[$matches[2]]))
190
-		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__);
203
+	if (!isset($values[$matches[2]])) {
204
+			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__);
205
+	}
191 206
 
192 207
 	$replacement = $values[$matches[2]];
193 208
 
194 209
 	switch ($matches[1])
195 210
 	{
196 211
 		case 'int':
197
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
198
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
213
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
214
+			}
199 215
 			return (string) (int) $replacement;
200 216
 		break;
201 217
 
@@ -207,65 +223,73 @@  discard block
 block discarded – undo
207 223
 		case 'array_int':
208 224
 			if (is_array($replacement))
209 225
 			{
210
-				if (empty($replacement))
211
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+				if (empty($replacement)) {
227
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+				}
212 229
 
213 230
 				foreach ($replacement as $key => $value)
214 231
 				{
215
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
216
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
233
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+					}
217 235
 
218 236
 					$replacement[$key] = (string) (int) $value;
219 237
 				}
220 238
 
221 239
 				return implode(', ', $replacement);
240
+			} else {
241
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222 242
 			}
223
-			else
224
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225 243
 
226 244
 		break;
227 245
 
228 246
 		case 'array_string':
229 247
 			if (is_array($replacement))
230 248
 			{
231
-				if (empty($replacement))
232
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+				if (empty($replacement)) {
250
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
251
+				}
233 252
 
234
-				foreach ($replacement as $key => $value)
235
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
253
+				foreach ($replacement as $key => $value) {
254
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
255
+				}
236 256
 
237 257
 				return implode(', ', $replacement);
258
+			} else {
259
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
238 260
 			}
239
-			else
240
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241 261
 		break;
242 262
 
243 263
 		case 'date':
244
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
245
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
246
-			else
247
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
264
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
265
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
266
+			} else {
267
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+			}
248 269
 		break;
249 270
 
250 271
 		case 'time':
251
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
252
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
253
-			else
254
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
273
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
274
+			} else {
275
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
276
+			}
255 277
 		break;
256 278
 		
257 279
 		case 'datetime':
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('.
280
+			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) {
281
+							return 'str_to_date('.
260 282
 					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 283
 					',\'%Y-%m-%d %h:%i:%s\')';
262
-			else
263
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			} else {
285
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			}
264 287
 		break;
265 288
 
266 289
 		case 'float':
267
-			if (!is_numeric($replacement))
268
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
290
+			if (!is_numeric($replacement)) {
291
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
292
+			}
269 293
 			return (string) (float) $replacement;
270 294
 		break;
271 295
 
@@ -279,32 +303,37 @@  discard block
 block discarded – undo
279 303
 		break;
280 304
 
281 305
 		case 'inet':
282
-			if ($replacement == 'null' || $replacement == '')
283
-				return 'null';
284
-			if (!isValidIP($replacement))
285
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306
+			if ($replacement == 'null' || $replacement == '') {
307
+							return 'null';
308
+			}
309
+			if (!isValidIP($replacement)) {
310
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
311
+			}
286 312
 			//we don't use the native support of mysql > 5.6.2
287 313
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
288 314
 
289 315
 		case 'array_inet':
290 316
 			if (is_array($replacement))
291 317
 			{
292
-				if (empty($replacement))
293
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+				if (empty($replacement)) {
319
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
320
+				}
294 321
 
295 322
 				foreach ($replacement as $key => $value)
296 323
 				{
297
-					if ($replacement == 'null' || $replacement == '')
298
-						$replacement[$key] = 'null';
299
-					if (!isValidIP($value))
300
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
324
+					if ($replacement == 'null' || $replacement == '') {
325
+											$replacement[$key] = 'null';
326
+					}
327
+					if (!isValidIP($value)) {
328
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
329
+					}
301 330
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
302 331
 				}
303 332
 
304 333
 				return implode(', ', $replacement);
334
+			} else {
335
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305 336
 			}
306
-			else
307
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
308 337
 		break;
309 338
 
310 339
 		default:
@@ -380,22 +409,25 @@  discard block
 block discarded – undo
380 409
 		// Are we in SSI mode?  If so try that username and password first
381 410
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
382 411
 		{
383
-			if (empty($db_persist))
384
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
385
-			else
386
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
412
+			if (empty($db_persist)) {
413
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
414
+			} else {
415
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
416
+			}
387 417
 		}
388 418
 		// Fall back to the regular username and password if need be
389 419
 		if (!$db_connection)
390 420
 		{
391
-			if (empty($db_persist))
392
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
393
-			else
394
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
421
+			if (empty($db_persist)) {
422
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
423
+			} else {
424
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
425
+			}
395 426
 		}
396 427
 
397
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
398
-			$db_connection = false;
428
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
429
+					$db_connection = false;
430
+		}
399 431
 
400 432
 		$connection = $db_connection;
401 433
 	}
@@ -403,18 +435,20 @@  discard block
 block discarded – undo
403 435
 	// One more query....
404 436
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
405 437
 
406
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
407
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
438
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
439
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
440
+	}
408 441
 
409 442
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
410 443
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
411 444
 	{
412 445
 		// Add before LIMIT
413
-		if ($pos = strpos($db_string, 'LIMIT '))
414
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
415
-		else
416
-			// Append it.
446
+		if ($pos = strpos($db_string, 'LIMIT ')) {
447
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
448
+		} else {
449
+					// Append it.
417 450
 			$db_string .= "\n\t\t\tORDER BY null";
451
+		}
418 452
 	}
419 453
 
420 454
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -436,8 +470,9 @@  discard block
 block discarded – undo
436 470
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
437 471
 
438 472
 		// Initialize $db_cache if not already initialized.
439
-		if (!isset($db_cache))
440
-			$db_cache = array();
473
+		if (!isset($db_cache)) {
474
+					$db_cache = array();
475
+		}
441 476
 
442 477
 		if (!empty($_SESSION['debug_redirect']))
443 478
 		{
@@ -463,17 +498,18 @@  discard block
 block discarded – undo
463 498
 		while (true)
464 499
 		{
465 500
 			$pos = strpos($db_string, '\'', $pos + 1);
466
-			if ($pos === false)
467
-				break;
501
+			if ($pos === false) {
502
+							break;
503
+			}
468 504
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
469 505
 
470 506
 			while (true)
471 507
 			{
472 508
 				$pos1 = strpos($db_string, '\'', $pos + 1);
473 509
 				$pos2 = strpos($db_string, '\\', $pos + 1);
474
-				if ($pos1 === false)
475
-					break;
476
-				elseif ($pos2 === false || $pos2 > $pos1)
510
+				if ($pos1 === false) {
511
+									break;
512
+				} elseif ($pos2 === false || $pos2 > $pos1)
477 513
 				{
478 514
 					$pos = $pos1;
479 515
 					break;
@@ -489,29 +525,35 @@  discard block
 block discarded – undo
489 525
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
490 526
 
491 527
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
492
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
493
-			$fail = true;
528
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
529
+					$fail = true;
530
+		}
494 531
 		// Trying to change passwords, slow us down, or something?
495
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
496
-			$fail = true;
497
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
498
-			$fail = true;
532
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
533
+					$fail = true;
534
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
535
+					$fail = true;
536
+		}
499 537
 
500
-		if (!empty($fail) && function_exists('log_error'))
501
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
538
+		if (!empty($fail) && function_exists('log_error')) {
539
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
540
+		}
502 541
 	}
503 542
 
504
-	if (empty($db_unbuffered))
505
-		$ret = @mysqli_query($connection, $db_string);
506
-	else
507
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
543
+	if (empty($db_unbuffered)) {
544
+			$ret = @mysqli_query($connection, $db_string);
545
+	} else {
546
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
547
+	}
508 548
 
509
-	if ($ret === false && empty($db_values['db_error_skip']))
510
-		$ret = smf_db_error($db_string, $connection);
549
+	if ($ret === false && empty($db_values['db_error_skip'])) {
550
+			$ret = smf_db_error($db_string, $connection);
551
+	}
511 552
 
512 553
 	// Debugging.
513
-	if (isset($db_show_debug) && $db_show_debug === true)
514
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
554
+	if (isset($db_show_debug) && $db_show_debug === true) {
555
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
556
+	}
515 557
 
516 558
 	return $ret;
517 559
 }
@@ -558,12 +600,13 @@  discard block
 block discarded – undo
558 600
 	// Decide which connection to use
559 601
 	$connection = $connection === null ? $db_connection : $connection;
560 602
 
561
-	if ($type == 'begin')
562
-		return @mysqli_query($connection, 'BEGIN');
563
-	elseif ($type == 'rollback')
564
-		return @mysqli_query($connection, 'ROLLBACK');
565
-	elseif ($type == 'commit')
566
-		return @mysqli_query($connection, 'COMMIT');
603
+	if ($type == 'begin') {
604
+			return @mysqli_query($connection, 'BEGIN');
605
+	} elseif ($type == 'rollback') {
606
+			return @mysqli_query($connection, 'ROLLBACK');
607
+	} elseif ($type == 'commit') {
608
+			return @mysqli_query($connection, 'COMMIT');
609
+	}
567 610
 
568 611
 	return false;
569 612
 }
@@ -603,8 +646,9 @@  discard block
 block discarded – undo
603 646
 	//    2013: Lost connection to server during query.
604 647
 
605 648
 	// Log the error.
606
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
607
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
649
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
650
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
651
+	}
608 652
 
609 653
 	// Database error auto fixing ;).
610 654
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -613,8 +657,9 @@  discard block
 block discarded – undo
613 657
 		$old_cache = @$modSettings['cache_enable'];
614 658
 		$modSettings['cache_enable'] = '1';
615 659
 
616
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
617
-			$db_last_error = max(@$db_last_error, $temp);
660
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
661
+					$db_last_error = max(@$db_last_error, $temp);
662
+		}
618 663
 
619 664
 		if (@$db_last_error < time() - 3600 * 24 * 3)
620 665
 		{
@@ -630,8 +675,9 @@  discard block
 block discarded – undo
630 675
 					foreach ($tables as $table)
631 676
 					{
632 677
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
633
-						if (trim($table) != '')
634
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
678
+						if (trim($table) != '') {
679
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
680
+						}
635 681
 					}
636 682
 				}
637 683
 
@@ -640,8 +686,9 @@  discard block
 block discarded – undo
640 686
 			// Table crashed.  Let's try to fix it.
641 687
 			elseif ($query_errno == 1016)
642 688
 			{
643
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
644
-					$fix_tables = array('`' . $match[1] . '`');
689
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
690
+									$fix_tables = array('`' . $match[1] . '`');
691
+				}
645 692
 			}
646 693
 			// Indexes crashed.  Should be easy to fix!
647 694
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -660,13 +707,15 @@  discard block
 block discarded – undo
660 707
 
661 708
 			// Make a note of the REPAIR...
662 709
 			cache_put_data('db_last_error', time(), 600);
663
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
664
-				updateSettingsFile(array('db_last_error' => time()));
710
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
711
+							updateSettingsFile(array('db_last_error' => time()));
712
+			}
665 713
 
666 714
 			// Attempt to find and repair the broken table.
667
-			foreach ($fix_tables as $table)
668
-				$smcFunc['db_query']('', "
715
+			foreach ($fix_tables as $table) {
716
+							$smcFunc['db_query']('', "
669 717
 					REPAIR TABLE $table", false, false);
718
+			}
670 719
 
671 720
 			// And send off an email!
672 721
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -675,11 +724,12 @@  discard block
 block discarded – undo
675 724
 
676 725
 			// Try the query again...?
677 726
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
678
-			if ($ret !== false)
679
-				return $ret;
727
+			if ($ret !== false) {
728
+							return $ret;
729
+			}
730
+		} else {
731
+					$modSettings['cache_enable'] = $old_cache;
680 732
 		}
681
-		else
682
-			$modSettings['cache_enable'] = $old_cache;
683 733
 
684 734
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
685 735
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -689,22 +739,25 @@  discard block
 block discarded – undo
689 739
 				// Are we in SSI mode?  If so try that username and password first
690 740
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
691 741
 				{
692
-					if (empty($db_persist))
693
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
694
-					else
695
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
742
+					if (empty($db_persist)) {
743
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
744
+					} else {
745
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
746
+					}
696 747
 				}
697 748
 				// Fall back to the regular username and password if need be
698 749
 				if (!$db_connection)
699 750
 				{
700
-					if (empty($db_persist))
701
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
702
-					else
703
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
751
+					if (empty($db_persist)) {
752
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
753
+					} else {
754
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
755
+					}
704 756
 				}
705 757
 
706
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
707
-					$db_connection = false;
758
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
759
+									$db_connection = false;
760
+				}
708 761
 			}
709 762
 
710 763
 			if ($db_connection)
@@ -715,24 +768,27 @@  discard block
 block discarded – undo
715 768
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
716 769
 
717 770
 					$new_errno = mysqli_errno($db_connection);
718
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
719
-						break;
771
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
772
+											break;
773
+					}
720 774
 				}
721 775
 
722 776
 				// If it failed again, shucks to be you... we're not trying it over and over.
723
-				if ($ret !== false)
724
-					return $ret;
777
+				if ($ret !== false) {
778
+									return $ret;
779
+				}
725 780
 			}
726 781
 		}
727 782
 		// Are they out of space, perhaps?
728 783
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
729 784
 		{
730
-			if (!isset($txt))
731
-				$query_error .= ' - check database storage space.';
732
-			else
785
+			if (!isset($txt)) {
786
+							$query_error .= ' - check database storage space.';
787
+			} else
733 788
 			{
734
-				if (!isset($txt['mysql_error_space']))
735
-					loadLanguage('Errors');
789
+				if (!isset($txt['mysql_error_space'])) {
790
+									loadLanguage('Errors');
791
+				}
736 792
 
737 793
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
738 794
 			}
@@ -740,15 +796,17 @@  discard block
 block discarded – undo
740 796
 	}
741 797
 
742 798
 	// Nothing's defined yet... just die with it.
743
-	if (empty($context) || empty($txt))
744
-		die($query_error);
799
+	if (empty($context) || empty($txt)) {
800
+			die($query_error);
801
+	}
745 802
 
746 803
 	// Show an error message, if possible.
747 804
 	$context['error_title'] = $txt['database_error'];
748
-	if (allowedTo('admin_forum'))
749
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
750
-	else
751
-		$context['error_message'] = $txt['try_again'];
805
+	if (allowedTo('admin_forum')) {
806
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
807
+	} else {
808
+			$context['error_message'] = $txt['try_again'];
809
+	}
752 810
 
753 811
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
754 812
 	{
@@ -778,25 +836,28 @@  discard block
 block discarded – undo
778 836
 	$connection = $connection === null ? $db_connection : $connection;
779 837
 
780 838
 	// With nothing to insert, simply return.
781
-	if (empty($data))
782
-		return;
839
+	if (empty($data)) {
840
+			return;
841
+	}
783 842
 
784 843
 	// Replace the prefix holder with the actual prefix.
785 844
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
786 845
 
787 846
 	// Inserting data as a single row can be done as a single array.
788
-	if (!is_array($data[array_rand($data)]))
789
-		$data = array($data);
847
+	if (!is_array($data[array_rand($data)])) {
848
+			$data = array($data);
849
+	}
790 850
 
791 851
 	// Create the mold for a single row insert.
792 852
 	$insertData = '(';
793 853
 	foreach ($columns as $columnName => $type)
794 854
 	{
795 855
 		// Are we restricting the length?
796
-		if (strpos($type, 'string-') !== false)
797
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
798
-		else
799
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
856
+		if (strpos($type, 'string-') !== false) {
857
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
858
+		} else {
859
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
860
+		}
800 861
 	}
801 862
 	$insertData = substr($insertData, 0, -2) . ')';
802 863
 
@@ -805,8 +866,9 @@  discard block
 block discarded – undo
805 866
 
806 867
 	// Here's where the variables are injected to the query.
807 868
 	$insertRows = array();
808
-	foreach ($data as $dataRow)
809
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
869
+	foreach ($data as $dataRow) {
870
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
871
+	}
810 872
 
811 873
 	// Determine the method of insertion.
812 874
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -826,15 +888,16 @@  discard block
 block discarded – undo
826 888
 	
827 889
 	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
828 890
 	{
829
-		if ($returnmode == 1)
830
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
831
-		else if ($returnmode == 2)
891
+		if ($returnmode == 1) {
892
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
893
+		} else if ($returnmode == 2)
832 894
 		{
833 895
 			$return_var = array();
834 896
 			$count = count($insertRows);
835 897
 			$start = smf_db_insert_id($table, $keys[0]);
836
-			for ($i = 0; $i < $count; $i++ )
837
-				$return_var[] = $start + $i;
898
+			for ($i = 0; $i < $count; $i++ ) {
899
+							$return_var[] = $start + $i;
900
+			}
838 901
 		}
839 902
 		return $return_var;
840 903
 	}
@@ -852,8 +915,9 @@  discard block
 block discarded – undo
852 915
  */
853 916
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
854 917
 {
855
-	if (empty($log_message))
856
-		$log_message = $error_message;
918
+	if (empty($log_message)) {
919
+			$log_message = $error_message;
920
+	}
857 921
 
858 922
 	foreach (debug_backtrace() as $step)
859 923
 	{
@@ -872,12 +936,14 @@  discard block
 block discarded – undo
872 936
 	}
873 937
 
874 938
 	// A special case - we want the file and line numbers for debugging.
875
-	if ($error_type == 'return')
876
-		return array($file, $line);
939
+	if ($error_type == 'return') {
940
+			return array($file, $line);
941
+	}
877 942
 
878 943
 	// Is always a critical error.
879
-	if (function_exists('log_error'))
880
-		log_error($log_message, 'critical', $file, $line);
944
+	if (function_exists('log_error')) {
945
+			log_error($log_message, 'critical', $file, $line);
946
+	}
881 947
 
882 948
 	if (function_exists('fatal_error'))
883 949
 	{
@@ -885,12 +951,12 @@  discard block
 block discarded – undo
885 951
 
886 952
 		// Cannot continue...
887 953
 		exit;
954
+	} elseif ($error_type) {
955
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
956
+	} else {
957
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
958
+	}
888 959
 	}
889
-	elseif ($error_type)
890
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
891
-	else
892
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
893
-}
894 960
 
895 961
 /**
896 962
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -907,10 +973,11 @@  discard block
 block discarded – undo
907 973
 		'\\' => '\\\\',
908 974
 	);
909 975
 
910
-	if ($translate_human_wildcards)
911
-		$replacements += array(
976
+	if ($translate_human_wildcards) {
977
+			$replacements += array(
912 978
 			'*' => '%',
913 979
 		);
980
+	}
914 981
 
915 982
 	return strtr($string, $replacements);
916 983
 }
@@ -924,8 +991,9 @@  discard block
 block discarded – undo
924 991
  */
925 992
 function smf_is_resource($result)
926 993
 {
927
-	if ($result instanceof mysqli_result)
928
-		return true;
994
+	if ($result instanceof mysqli_result) {
995
+			return true;
996
+	}
929 997
 
930 998
 	return false;
931 999
 }
Please login to merge, or discard this patch.
Sources/tasks/Likes-Notify.php 1 patch
Braces   +19 added lines, -14 removed lines patch added patch discarded remove patch
@@ -51,30 +51,33 @@  discard block
 block discarded – undo
51 51
 				$ignored_members = explode(',', $row['pm_ignore_list']);
52 52
 
53 53
 				// If the user is in group 1 anywhere, they can see everything anyway.
54
-				if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0)
55
-					$author = $row['id_member'];
54
+				if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) {
55
+									$author = $row['id_member'];
56
+				}
56 57
 			}
57 58
 			$smcFunc['db_free_result']($request);
58
-		}
59
-		else
59
+		} else
60 60
 		{
61 61
 			// This isn't something we know natively how to support. Call the hooks, if they're dealing with it, return false, otherwise return the user id.
62 62
 			$hook_results = call_integration_hook('integrate_find_like_author', array($this->_details['content_type'], $this->_details['content_id']));
63
-			foreach ($hook_results as $result)
64
-				if (!empty($result))
63
+			foreach ($hook_results as $result) {
64
+							if (!empty($result))
65 65
 				{
66 66
 					$author = $result;
67
+			}
67 68
 					break;
68 69
 				}
69 70
 		}
70 71
 
71 72
 		// If we didn't have a member... leave.
72
-		if (empty($author))
73
-			return true;
73
+		if (empty($author)) {
74
+					return true;
75
+		}
74 76
 
75 77
 		// If the person who sent the notification is the person whose content it is, do nothing.
76
-		if ($author == $this->_details['sender_id'])
77
-			return true;
78
+		if ($author == $this->_details['sender_id']) {
79
+					return true;
80
+		}
78 81
 
79 82
 		// If the person who sent the notification is on this person's ignore list, do nothing.
80 83
 		if (!empty($ignored_members) && in_array($this->_details['sender_id'], $ignored_members)) {
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		// As a result, the value should really just be non empty.
89 92
 
90 93
 		// Check the value. If no value or it's empty, they didn't want alerts, oh well.
91
-		if (empty($prefs[$author][$this->_details['content_type'] . '_like']))
92
-			return true;
94
+		if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) {
95
+					return true;
96
+		}
93 97
 
94 98
 		// Don't spam the alerts: if there is an existing unread alert of the
95 99
 		// requested type for the target user from the sender, don't make a new one.
@@ -109,8 +113,9 @@  discard block
 block discarded – undo
109 113
 			)
110 114
 		);
111 115
 
112
-		if ($smcFunc['db_num_rows']($request) > 0)
113
-			return true;
116
+		if ($smcFunc['db_num_rows']($request) > 0) {
117
+					return true;
118
+		}
114 119
 		$smcFunc['db_free_result']($request);
115 120
 
116 121
 		// Issue, update, move on.
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +60 added lines, -47 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Fetches a list of boards and (optional) categories including
@@ -37,11 +38,12 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
47 49
 	$result_boards = $smcFunc['db_query']('', '
@@ -74,10 +76,11 @@  discard block
 block discarded – undo
74 76
 	);
75 77
 
76 78
 	// Start with an empty array.
77
-	if ($boardIndexOptions['include_categories'])
78
-		$categories = array();
79
-	else
80
-		$this_category = array();
79
+	if ($boardIndexOptions['include_categories']) {
80
+			$categories = array();
81
+	} else {
82
+			$this_category = array();
83
+	}
81 84
 	$boards = array();
82 85
 
83 86
 	// Run through the categories and boards (or only boards)....
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
89 92
 
90 93
 		// Add parent boards to the $boards list later used to fetch moderators
91
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
92
-			$boards[] = $row_board['id_board'];
94
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
95
+					$boards[] = $row_board['id_board'];
96
+		}
93 97
 
94 98
 		if ($boardIndexOptions['include_categories'])
95 99
 		{
@@ -111,8 +115,9 @@  discard block
 block discarded – undo
111 115
 			}
112 116
 
113 117
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
114
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
115
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
118
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
119
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
120
+			}
116 121
 
117 122
 			// Avoid showing category unread link where it only has redirection boards.
118 123
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -160,14 +165,12 @@  discard block
 block discarded – undo
160 165
 				{
161 166
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
162 167
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
163
-				}
164
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
168
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
165 169
 				{
166 170
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
167 171
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
168 172
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
169
-				}
170
-				else
173
+				} else
171 174
 				{
172 175
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
173 176
 				}
@@ -218,14 +221,16 @@  discard block
 block discarded – undo
218 221
 		// Child of a child... just add it on...
219 222
 		elseif (!empty($boardIndexOptions['countChildPosts']))
220 223
 		{
221
-			if (!isset($parent_map))
222
-				$parent_map = array();
224
+			if (!isset($parent_map)) {
225
+							$parent_map = array();
226
+			}
223 227
 
224
-			if (!isset($parent_map[$row_board['id_parent']]))
225
-				foreach ($this_category as $id => $board)
228
+			if (!isset($parent_map[$row_board['id_parent']])) {
229
+							foreach ($this_category as $id => $board)
226 230
 				{
227 231
 					if (!isset($board['children'][$row_board['id_parent']]))
228 232
 						continue;
233
+			}
229 234
 
230 235
 					$parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
231 236
 					$parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
@@ -246,8 +251,9 @@  discard block
 block discarded – undo
246 251
 			continue;
247 252
 		}
248 253
 		// Found a child of a child - skip.
249
-		else
250
-			continue;
254
+		else {
255
+					continue;
256
+		}
251 257
 
252 258
 		// Prepare the subject, and make sure it's not too long.
253 259
 		censorText($row_board['subject']);
@@ -268,12 +274,13 @@  discard block
 block discarded – undo
268 274
 			'topic' => $row_board['id_topic']
269 275
 		);
270 276
 
271
-		if (!empty($settings['avatars_on_boardIndex']))
272
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
277
+		if (!empty($settings['avatars_on_boardIndex'])) {
278
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
273 279
 				'avatar' => $row_board['avatar'],
274 280
 				'email' => $row_board['email_address'],
275 281
 				'filename' => !empty($row['member_filename']) ? $row_board['member_filename'] : '',
276 282
 			));
283
+		}
277 284
 
278 285
 		// Provide the href and link.
279 286
 		if ($row_board['subject'] != '')
@@ -285,8 +292,7 @@  discard block
 block discarded – undo
285 292
 			link, href, subject, start (where they should go for the first unread post.),
286 293
 			and member. (which has id, name, link, href, username in it.) */
287 294
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
288
-		}
289
-		else
295
+		} else
290 296
 		{
291 297
 			$this_last_post['href'] = '';
292 298
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -294,8 +300,9 @@  discard block
 block discarded – undo
294 300
 		}
295 301
 
296 302
 		// Set the last post in the parent board.
297
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
298
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
303
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) {
304
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
305
+		}
299 306
 		// Just in the child...?
300 307
 		if ($isChild)
301 308
 		{
@@ -305,15 +312,17 @@  discard block
 block discarded – undo
305 312
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
306 313
 		}
307 314
 		// No last post for this board?  It's not new then, is it..?
308
-		elseif ($row_board['poster_name'] == '')
309
-			$this_category[$row_board['id_board']]['new'] = false;
315
+		elseif ($row_board['poster_name'] == '') {
316
+					$this_category[$row_board['id_board']]['new'] = false;
317
+		}
310 318
 
311 319
 		// Determine a global most recent topic.
312
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
313
-			$latest_post = array(
320
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
321
+					$latest_post = array(
314 322
 				'timestamp' => $row_board['poster_time'],
315 323
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
316 324
 			);
325
+		}
317 326
 	}
318 327
 	$smcFunc['db_free_result']($result_boards);
319 328
 
@@ -330,8 +339,9 @@  discard block
 block discarded – undo
330 339
 				if (!empty($moderators[$board['id']]))
331 340
 				{
332 341
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
333
-					foreach ($moderators[$board['id']] as $moderator)
334
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
342
+					foreach ($moderators[$board['id']] as $moderator) {
343
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
344
+					}
335 345
 				}
336 346
 				if (!empty($groups[$board['id']]))
337 347
 				{
@@ -344,16 +354,16 @@  discard block
 block discarded – undo
344 354
 				}
345 355
 			}
346 356
 		}
347
-	}
348
-	else
357
+	} else
349 358
 	{
350 359
 		foreach ($this_category as $k => $board)
351 360
 		{
352 361
 			if (!empty($moderators[$board['id']]))
353 362
 			{
354 363
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
355
-				foreach ($moderators[$board['id']] as $moderator)
356
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
364
+				foreach ($moderators[$board['id']] as $moderator) {
365
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
366
+				}
357 367
 			}
358 368
 			if (!empty($groups[$board['id']]))
359 369
 			{
@@ -367,20 +377,23 @@  discard block
 block discarded – undo
367 377
 		}
368 378
 	}
369 379
 
370
-	if ($boardIndexOptions['include_categories'])
371
-		sortCategories($categories);
372
-	else
373
-		sortBoards($this_category);
380
+	if ($boardIndexOptions['include_categories']) {
381
+			sortCategories($categories);
382
+	} else {
383
+			sortBoards($this_category);
384
+	}
374 385
 
375 386
 	// By now we should know the most recent post...if we wanna know it that is.
376
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
377
-		$context['latest_post'] = $latest_post['ref'];
387
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
388
+			$context['latest_post'] = $latest_post['ref'];
389
+	}
378 390
 
379 391
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
380
-	if ($boardIndexOptions['include_categories'])
381
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
382
-	else
383
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
392
+	if ($boardIndexOptions['include_categories']) {
393
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
394
+	} else {
395
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
396
+	}
384 397
 
385 398
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
386 399
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +798 added lines, -602 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
88 98
 	{
89
-		if (!$utf8 || $smcFunc['db_mb4'])
90
-			return $string;
99
+		if (!$utf8 || $smcFunc['db_mb4']) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i + 1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -214,23 +223,25 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
225
-		date_default_timezone_set($modSettings['default_timezone']);
226
-	else
234
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	} else
227 237
 	{
228 238
 		// Get PHP's default timezone, if set
229 239
 		$ini_tz = ini_get('date.timezone');
230
-		if (!empty($ini_tz))
231
-			$modSettings['default_timezone'] = $ini_tz;
232
-		else
233
-			$modSettings['default_timezone'] = '';
240
+		if (!empty($ini_tz)) {
241
+					$modSettings['default_timezone'] = $ini_tz;
242
+		} else {
243
+					$modSettings['default_timezone'] = '';
244
+		}
234 245
 
235 246
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
236 247
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -248,22 +259,26 @@  discard block
 block discarded – undo
248 259
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
249 260
 		{
250 261
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
251
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
252
-				$modSettings['load_average'] = (float) $matches[1];
253
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
254
-				$modSettings['load_average'] = (float) $matches[1];
255
-			else
256
-				unset($modSettings['load_average']);
262
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
263
+							$modSettings['load_average'] = (float) $matches[1];
264
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
265
+							$modSettings['load_average'] = (float) $matches[1];
266
+			} else {
267
+							unset($modSettings['load_average']);
268
+			}
257 269
 
258
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
259
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
270
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
271
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
272
+			}
260 273
 		}
261 274
 
262
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
263
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
275
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
276
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
277
+		}
264 278
 
265
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
266
-			display_loadavg_error();
279
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
280
+					display_loadavg_error();
281
+		}
267 282
 	}
268 283
 
269 284
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -284,8 +299,9 @@  discard block
 block discarded – undo
284 299
 	if (defined('SMF_INTEGRATION_SETTINGS'))
285 300
 	{
286 301
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
287
-		foreach ($integration_settings as $hook => $function)
288
-			add_integration_function($hook, $function, '', false);
302
+		foreach ($integration_settings as $hook => $function) {
303
+					add_integration_function($hook, $function, '', false);
304
+		}
289 305
 	}
290 306
 
291 307
 	// Any files to pre include?
@@ -295,8 +311,9 @@  discard block
 block discarded – undo
295 311
 		foreach ($pre_includes as $include)
296 312
 		{
297 313
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
298
-			if (file_exists($include))
299
-				require_once($include);
314
+			if (file_exists($include)) {
315
+							require_once($include);
316
+			}
300 317
 		}
301 318
 	}
302 319
 
@@ -400,27 +417,28 @@  discard block
 block discarded – undo
400 417
 				break;
401 418
 			}
402 419
 		}
420
+	} else {
421
+			$id_member = 0;
403 422
 	}
404
-	else
405
-		$id_member = 0;
406 423
 
407 424
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
408 425
 	{
409 426
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
410 427
 
411
-		if (empty($cookie_data))
412
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
428
+		if (empty($cookie_data)) {
429
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
430
+		}
413 431
 
414 432
 		list ($id_member, $password) = $cookie_data;
415 433
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
434
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 435
 	{
419 436
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 437
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
421 438
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
439
+		if (empty($cookie_data)) {
440
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
441
+		}
424 442
 
425 443
 		list ($id_member, $password, $login_span) = $cookie_data;
426 444
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +463,34 @@  discard block
 block discarded – undo
445 463
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 464
 			$smcFunc['db_free_result']($request);
447 465
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
466
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
467
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
468
+			}
450 469
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
470
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
471
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
472
+			}
453 473
 		}
454 474
 
455 475
 		// Did we find 'im?  If not, junk it.
456 476
 		if (!empty($user_settings))
457 477
 		{
458 478
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
479
+			if (!empty($already_verified) && $already_verified === true) {
480
+							$check = true;
481
+			}
461 482
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
483
+			elseif (strlen($password) == 128) {
484
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
485
+			} else {
486
+							$check = false;
487
+			}
466 488
 
467 489
 			// Wrong password or not activated - either way, you're going nowhere.
468 490
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
491
+		} else {
492
+					$id_member = 0;
469 493
 		}
470
-		else
471
-			$id_member = 0;
472 494
 
473 495
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 496
 		if (!$id_member)
@@ -490,13 +512,15 @@  discard block
 block discarded – undo
490 512
 				{
491 513
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
492 514
 
493
-					if (is_null($tfa_data))
494
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
515
+					if (is_null($tfa_data)) {
516
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
517
+					}
495 518
 
496 519
 					list ($tfamember, $tfasecret) = $tfa_data;
497 520
 
498
-					if ((int) $tfamember != $id_member)
499
-						$tfasecret = null;
521
+					if ((int) $tfamember != $id_member) {
522
+											$tfasecret = null;
523
+					}
500 524
 				}
501 525
 
502 526
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +540,12 @@  discard block
 block discarded – undo
516 540
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 541
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 542
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
543
+			if ($modSettings['tfa_mode'] == 2) {
544
+				//only do this if we are just forcing SOME membergroups
520 545
 			{
521 546
 				//Build an array of ALL user membergroups.
522 547
 				$full_groups = array($user_settings['id_group']);
548
+			}
523 549
 				if (!empty($user_settings['additional_groups']))
524 550
 				{
525 551
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +565,17 @@  discard block
 block discarded – undo
539 565
 				);
540 566
 				$row = $smcFunc['db_fetch_assoc']($request);
541 567
 				$smcFunc['db_free_result']($request);
568
+			} else {
569
+							$row['total'] = 1;
542 570
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
571
+			//simplifies logics in the next "if"
545 572
 
546 573
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 574
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 575
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
576
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
577
+							redirectexit('action=profile;area=tfasetup;forced');
578
+			}
551 579
 		}
552 580
 	}
553 581
 
@@ -584,33 +612,37 @@  discard block
 block discarded – undo
584 612
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
585 613
 				$user_settings['last_login'] = time();
586 614
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
615
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
616
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				}
589 618
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
619
+				if (!empty($modSettings['cache_enable'])) {
620
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				}
592 622
 			}
623
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
624
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 625
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 626
 
597 627
 		$username = $user_settings['member_name'];
598 628
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
629
+		if (empty($user_settings['additional_groups'])) {
630
+					$user_info = array(
601 631
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 632
 			);
603
-		else
604
-			$user_info = array(
633
+		} else {
634
+					$user_info = array(
605 635
 				'groups' => array_merge(
606 636
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 637
 					explode(',', $user_settings['additional_groups'])
608 638
 				)
609 639
 			);
640
+		}
610 641
 
611 642
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
643
+		foreach ($user_info['groups'] as $k => $v) {
644
+					$user_info['groups'][$k] = (int) $v;
645
+		}
614 646
 
615 647
 		// This is a logged in user, so definitely not a spider.
616 648
 		$user_info['possibly_robot'] = false;
@@ -624,8 +656,7 @@  discard block
 block discarded – undo
624 656
 			$time_system = new DateTime('now', $tz_system);
625 657
 			$time_user = new DateTime('now', $tz_user);
626 658
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
659
+		} else
629 660
 		{
630 661
 			// !!! Compatibility.
631 662
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -639,16 +670,18 @@  discard block
 block discarded – undo
639 670
 		$user_info = array('groups' => array(-1));
640 671
 		$user_settings = array();
641 672
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
673
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
674
+					$_COOKIE[$cookiename] = '';
675
+		}
644 676
 
645 677
 		// Expire the 2FA cookie
646 678
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
647 679
 		{
648 680
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
649 681
 
650
-			if (is_null($tfa_data))
651
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
682
+			if (is_null($tfa_data)) {
683
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
684
+			}
652 685
 
653 686
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
654 687
 
@@ -660,19 +693,20 @@  discard block
 block discarded – undo
660 693
 		}
661 694
 
662 695
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
667 701
 
668 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 704
 		{
671 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 709
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 710
 		// If we haven't turned on proper spider hunts then have a guess!
677 711
 		else
678 712
 		{
@@ -720,8 +754,9 @@  discard block
 block discarded – undo
720 754
 	$user_info['groups'] = array_unique($user_info['groups']);
721 755
 
722 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
725 760
 
726 761
 	// Allow the user to change their language.
727 762
 	if (!empty($modSettings['userLanguage']))
@@ -734,31 +769,36 @@  discard block
 block discarded – undo
734 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 770
 
736 771
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 779
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 780
 	}
745 781
 
746 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
747
-	if ($user_info['is_admin'])
748
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
749 786
 	// Otherwise just the groups in $user_info['groups'].
750
-	else
751
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
752 790
 
753 791
 	// Build the list of boards they WANT to see.
754 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
755 793
 
756 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
757
-	if (empty($user_info['ignoreboards']))
758
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
759 798
 	// Ok I guess they don't want to see all the boards
760
-	else
761
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
762 802
 
763 803
 	call_integration_hook('integrate_user_info');
764 804
 }
@@ -816,9 +856,9 @@  discard block
 block discarded – undo
816 856
 		}
817 857
 
818 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
822 862
 		{
823 863
 			loadPermissions();
824 864
 			loadTheme();
@@ -836,10 +876,11 @@  discard block
 block discarded – undo
836 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 877
 	{
838 878
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
843 884
 
844 885
 		if (!empty($temp))
845 886
 		{
@@ -877,8 +918,9 @@  discard block
 block discarded – undo
877 918
 			$row = $smcFunc['db_fetch_assoc']($request);
878 919
 
879 920
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
882 924
 
883 925
 			// Basic operating information. (globals... :/)
884 926
 			$board_info = array(
@@ -914,21 +956,23 @@  discard block
 block discarded – undo
914 956
 
915 957
 			do
916 958
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
919 961
 						'id' => $row['id_moderator'],
920 962
 						'name' => $row['real_name'],
921 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 965
 					);
966
+				}
924 967
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 970
 						'id' => $row['id_moderator_group'],
928 971
 						'name' => $row['group_name'],
929 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 974
 					);
975
+				}
932 976
 			}
933 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 978
 
@@ -960,12 +1004,12 @@  discard block
 block discarded – undo
960 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 1005
 			{
962 1006
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
965 1010
 				cache_put_data('board-' . $board, $board_info, 120);
966 1011
 			}
967
-		}
968
-		else
1012
+		} else
969 1013
 		{
970 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1015
 			$board_info = array(
@@ -979,8 +1023,9 @@  discard block
 block discarded – undo
979 1023
 		$smcFunc['db_free_result']($request);
980 1024
 	}
981 1025
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
984 1029
 
985 1030
 	if (!empty($board))
986 1031
 	{
@@ -990,10 +1035,12 @@  discard block
 block discarded – undo
990 1035
 		// Now check if the user is a moderator.
991 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1037
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
997 1044
 
998 1045
 		// Build up the linktree.
999 1046
 		$context['linktree'] = array_merge(
@@ -1016,8 +1063,9 @@  discard block
 block discarded – undo
1016 1063
 	$context['current_board'] = $board;
1017 1064
 
1018 1065
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1021 1069
 
1022 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1091,23 @@  discard block
 block discarded – undo
1043 1091
 			ob_end_clean();
1044 1092
 			header('HTTP/1.1 403 Forbidden');
1045 1093
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1095
 		{
1049 1096
 			// Slightly different error message here...
1050 1097
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1053 1099
 		{
1054 1100
 			loadLanguage('Errors');
1055 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1056 1104
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1105
 	}
1060 1106
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1064 1111
 
1065 1112
 /**
1066 1113
  * Load this user's permissions.
@@ -1081,8 +1128,9 @@  discard block
 block discarded – undo
1081 1128
 		asort($cache_groups);
1082 1129
 		$cache_groups = implode(',', $cache_groups);
1083 1130
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1086 1134
 
1087 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1136
 		{
@@ -1090,9 +1138,9 @@  discard block
 block discarded – undo
1090 1138
 			banPermissions();
1091 1139
 
1092 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1093 1143
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1144
 	}
1097 1145
 
1098 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1162,26 @@  discard block
 block discarded – undo
1114 1162
 		$removals = array();
1115 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1164
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1121 1170
 		}
1122 1171
 		$smcFunc['db_free_result']($request);
1123 1172
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1126 1176
 	}
1127 1177
 
1128 1178
 	// Get the board permissions.
1129 1179
 	if (!empty($board))
1130 1180
 	{
1131 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1134 1185
 
1135 1186
 		$request = $smcFunc['db_query']('', '
1136 1187
 			SELECT permission, add_deny
@@ -1146,20 +1197,23 @@  discard block
 block discarded – undo
1146 1197
 		);
1147 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1199
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1153 1205
 		}
1154 1206
 		$smcFunc['db_free_result']($request);
1155 1207
 	}
1156 1208
 
1157 1209
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1160 1213
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1163 1217
 
1164 1218
 	// Banned?  Watch, don't touch..
1165 1219
 	banPermissions();
@@ -1171,17 +1225,18 @@  discard block
 block discarded – undo
1171 1225
 		{
1172 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1230
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1231
 
1178 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1233
 		// For example this drastically simplifies certain changes to the profile area.
1180 1234
 		$user_info['permissions'][] = 'is_not_guest';
1181 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1236
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1185 1240
 	}
1186 1241
 }
1187 1242
 
@@ -1199,8 +1254,9 @@  discard block
 block discarded – undo
1199 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1200 1255
 
1201 1256
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1204 1260
 
1205 1261
 	// Pass the set value
1206 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1271,9 @@  discard block
 block discarded – undo
1215 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1272
 		{
1217 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1220 1277
 
1221 1278
 			$loaded_ids[] = $data['id_member'];
1222 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1283,13 +1340,16 @@  discard block
 block discarded – undo
1283 1340
 			$row['avatar_original'] = $row['avatar'];
1284 1341
 
1285 1342
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1287
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1343
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1344
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1345
+			}
1288 1346
 
1289
-			if (isset($row['member_ip']))
1290
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1291
-			if (isset($row['member_ip2']))
1292
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			if (isset($row['member_ip'])) {
1348
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1349
+			}
1350
+			if (isset($row['member_ip2'])) {
1351
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1352
+			}
1293 1353
 			$new_loaded_ids[] = $row['id_member'];
1294 1354
 			$loaded_ids[] = $row['id_member'];
1295 1355
 			$row['options'] = array();
@@ -1308,8 +1368,9 @@  discard block
 block discarded – undo
1308 1368
 				'loaded_ids' => $new_loaded_ids,
1309 1369
 			)
1310 1370
 		);
1311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1312
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1371
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1372
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1373
+		}
1313 1374
 		$smcFunc['db_free_result']($request);
1314 1375
 	}
1315 1376
 
@@ -1320,10 +1381,11 @@  discard block
 block discarded – undo
1320 1381
 	{
1321 1382
 		foreach ($loaded_ids as $a_member)
1322 1383
 		{
1323
-			if (!empty($user_profile[$a_member]['additional_groups']))
1324
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1325
-			else
1326
-				$groups = array($user_profile[$a_member]['id_group']);
1384
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1385
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1386
+			} else {
1387
+							$groups = array($user_profile[$a_member]['id_group']);
1388
+			}
1327 1389
 
1328 1390
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1329 1391
 
@@ -1336,8 +1398,9 @@  discard block
 block discarded – undo
1336 1398
 
1337 1399
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1338 1400
 	{
1339
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1340
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1401
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1402
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1403
+		}
1341 1404
 	}
1342 1405
 
1343 1406
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1363,14 +1426,17 @@  discard block
 block discarded – undo
1363 1426
 		foreach ($temp_mods as $id)
1364 1427
 		{
1365 1428
 			// By popular demand, don't show admins or global moderators as moderators.
1366
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1367
-				$user_profile[$id]['member_group'] = $row['member_group'];
1429
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1430
+							$user_profile[$id]['member_group'] = $row['member_group'];
1431
+			}
1368 1432
 
1369 1433
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1370
-			if (!empty($row['icons']))
1371
-				$user_profile[$id]['icons'] = $row['icons'];
1372
-			if (!empty($row['member_group_color']))
1373
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			if (!empty($row['icons'])) {
1435
+							$user_profile[$id]['icons'] = $row['icons'];
1436
+			}
1437
+			if (!empty($row['member_group_color'])) {
1438
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1439
+			}
1374 1440
 		}
1375 1441
 	}
1376 1442
 
@@ -1392,12 +1458,14 @@  discard block
 block discarded – undo
1392 1458
 	static $loadedLanguages = array();
1393 1459
 
1394 1460
 	// If this person's data is already loaded, skip it.
1395
-	if (isset($dataLoaded[$user]))
1396
-		return true;
1461
+	if (isset($dataLoaded[$user])) {
1462
+			return true;
1463
+	}
1397 1464
 
1398 1465
 	// We can't load guests or members not loaded by loadMemberData()!
1399
-	if ($user == 0)
1400
-		return false;
1466
+	if ($user == 0) {
1467
+			return false;
1468
+	}
1401 1469
 	if (!isset($user_profile[$user]))
1402 1470
 	{
1403 1471
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1423,12 +1491,16 @@  discard block
 block discarded – undo
1423 1491
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1424 1492
 
1425 1493
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1426
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1494
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1495
+		//icon is set and exists
1427 1496
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1428
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1497
+	} elseif (isset($profile['icons'][1])) {
1498
+		//icon is set and doesn't exist, fallback to default
1429 1499
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1430
-	else //not set, bye bye
1500
+	} else {
1501
+		//not set, bye bye
1431 1502
 		$group_icon_url = '';
1503
+	}
1432 1504
 
1433 1505
 	// These minimal values are always loaded
1434 1506
 	$memberContext[$user] = array(
@@ -1447,8 +1519,9 @@  discard block
 block discarded – undo
1447 1519
 	if ($context['loadMemberContext_set'] != 'minimal')
1448 1520
 	{
1449 1521
 		// Go the extra mile and load the user's native language name.
1450
-		if (empty($loadedLanguages))
1451
-			$loadedLanguages = getLanguages();
1522
+		if (empty($loadedLanguages)) {
1523
+					$loadedLanguages = getLanguages();
1524
+		}
1452 1525
 
1453 1526
 		$memberContext[$user] += array(
1454 1527
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1502,31 +1575,33 @@  discard block
 block discarded – undo
1502 1575
 	{
1503 1576
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1504 1577
 		{
1505
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1506
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1507
-			else
1508
-				$image = get_gravatar_url($profile['email_address']);
1509
-		}
1510
-		else
1578
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1579
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1580
+			} else {
1581
+							$image = get_gravatar_url($profile['email_address']);
1582
+			}
1583
+		} else
1511 1584
 		{
1512 1585
 			// So it's stored in the member table?
1513 1586
 			if (!empty($profile['avatar']))
1514 1587
 			{
1515 1588
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1589
+			} elseif (!empty($profile['filename'])) {
1590
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1591
 			}
1517
-			elseif (!empty($profile['filename']))
1518
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1519 1592
 			// Right... no avatar...use the default one
1520
-			else
1521
-				$image = $modSettings['avatar_url'] . '/default.png';
1593
+			else {
1594
+							$image = $modSettings['avatar_url'] . '/default.png';
1595
+			}
1522 1596
 		}
1523
-		if (!empty($image))
1524
-			$memberContext[$user]['avatar'] = array(
1597
+		if (!empty($image)) {
1598
+					$memberContext[$user]['avatar'] = array(
1525 1599
 				'name' => $profile['avatar'],
1526 1600
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1527 1601
 				'href' => $image,
1528 1602
 				'url' => $image,
1529 1603
 			);
1604
+		}
1530 1605
 	}
1531 1606
 
1532 1607
 	// Are we also loading the members custom fields into context?
@@ -1534,35 +1609,41 @@  discard block
 block discarded – undo
1534 1609
 	{
1535 1610
 		$memberContext[$user]['custom_fields'] = array();
1536 1611
 
1537
-		if (!isset($context['display_fields']))
1538
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1612
+		if (!isset($context['display_fields'])) {
1613
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1614
+		}
1539 1615
 
1540 1616
 		foreach ($context['display_fields'] as $custom)
1541 1617
 		{
1542
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1543
-				continue;
1618
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1619
+							continue;
1620
+			}
1544 1621
 
1545 1622
 			$value = $profile['options'][$custom['col_name']];
1546 1623
 
1547 1624
 			// Don't show the "disabled" option for the "gender" field.
1548
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1549
-				continue;
1625
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1626
+							continue;
1627
+			}
1550 1628
 
1551 1629
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1630
+			if ($custom['bbc']) {
1631
+							$value = parse_bbc($value);
1632
+			}
1554 1633
 			// ... or checkbox?
1555
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1556
-				$value = $value ? $txt['yes'] : $txt['no'];
1634
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1635
+							$value = $value ? $txt['yes'] : $txt['no'];
1636
+			}
1557 1637
 
1558 1638
 			// Enclosing the user input within some other text?
1559
-			if (!empty($custom['enclose']))
1560
-				$value = strtr($custom['enclose'], array(
1639
+			if (!empty($custom['enclose'])) {
1640
+							$value = strtr($custom['enclose'], array(
1561 1641
 					'{SCRIPTURL}' => $scripturl,
1562 1642
 					'{IMAGES_URL}' => $settings['images_url'],
1563 1643
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1564 1644
 					'{INPUT}' => $value,
1565 1645
 				));
1646
+			}
1566 1647
 
1567 1648
 			$memberContext[$user]['custom_fields'][] = array(
1568 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1670,9 @@  discard block
 block discarded – undo
1589 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1671
 
1591 1672
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1594 1676
 
1595 1677
 	// Make sure it's an array.
1596 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1614,31 +1696,36 @@  discard block
 block discarded – undo
1614 1696
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1615 1697
 	{
1616 1698
 		// BBC?
1617
-		if (!empty($row['bbc']))
1618
-			$row['value'] = parse_bbc($row['value']);
1699
+		if (!empty($row['bbc'])) {
1700
+					$row['value'] = parse_bbc($row['value']);
1701
+		}
1619 1702
 
1620 1703
 		// ... or checkbox?
1621
-		elseif (isset($row['type']) && $row['type'] == 'check')
1622
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1704
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1705
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1706
+		}
1623 1707
 
1624 1708
 		// Enclosing the user input within some other text?
1625
-		if (!empty($row['enclose']))
1626
-			$row['value'] = strtr($row['enclose'], array(
1709
+		if (!empty($row['enclose'])) {
1710
+					$row['value'] = strtr($row['enclose'], array(
1627 1711
 				'{SCRIPTURL}' => $scripturl,
1628 1712
 				'{IMAGES_URL}' => $settings['images_url'],
1629 1713
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1630 1714
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1631 1715
 			));
1716
+		}
1632 1717
 
1633 1718
 		// Send a simple array if there is just 1 param
1634
-		if (count($params) == 1)
1635
-			$return[$row['id_member']] = $row;
1719
+		if (count($params) == 1) {
1720
+					$return[$row['id_member']] = $row;
1721
+		}
1636 1722
 
1637 1723
 		// More than 1? knock yourself out...
1638 1724
 		else
1639 1725
 		{
1640
-			if (!isset($return[$row['id_member']]))
1641
-				$return[$row['id_member']] = array();
1726
+			if (!isset($return[$row['id_member']])) {
1727
+							$return[$row['id_member']] = array();
1728
+			}
1642 1729
 
1643 1730
 			$return[$row['id_member']][$row['variable']] = $row;
1644 1731
 		}
@@ -1672,8 +1759,9 @@  discard block
 block discarded – undo
1672 1759
 	global $context;
1673 1760
 
1674 1761
 	// Don't know any browser!
1675
-	if (empty($context['browser']))
1676
-		detectBrowser();
1762
+	if (empty($context['browser'])) {
1763
+			detectBrowser();
1764
+	}
1677 1765
 
1678 1766
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1679 1767
 }
@@ -1691,8 +1779,9 @@  discard block
 block discarded – undo
1691 1779
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1692 1780
 
1693 1781
 	// The theme was specified by parameter.
1694
-	if (!empty($id_theme))
1695
-		$id_theme = (int) $id_theme;
1782
+	if (!empty($id_theme)) {
1783
+			$id_theme = (int) $id_theme;
1784
+	}
1696 1785
 	// The theme was specified by REQUEST.
1697 1786
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1698 1787
 	{
@@ -1700,51 +1789,58 @@  discard block
 block discarded – undo
1700 1789
 		$_SESSION['id_theme'] = $id_theme;
1701 1790
 	}
1702 1791
 	// The theme was specified by REQUEST... previously.
1703
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1704
-		$id_theme = (int) $_SESSION['id_theme'];
1792
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1793
+			$id_theme = (int) $_SESSION['id_theme'];
1794
+	}
1705 1795
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1706
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1707
-		$id_theme = $user_info['theme'];
1796
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1797
+			$id_theme = $user_info['theme'];
1798
+	}
1708 1799
 	// The theme was specified by the board.
1709
-	elseif (!empty($board_info['theme']))
1710
-		$id_theme = $board_info['theme'];
1800
+	elseif (!empty($board_info['theme'])) {
1801
+			$id_theme = $board_info['theme'];
1802
+	}
1711 1803
 	// The theme is the forum's default.
1712
-	else
1713
-		$id_theme = $modSettings['theme_guests'];
1804
+	else {
1805
+			$id_theme = $modSettings['theme_guests'];
1806
+	}
1714 1807
 
1715 1808
 	// Verify the id_theme... no foul play.
1716 1809
 	// Always allow the board specific theme, if they are overriding.
1717
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1718
-		$id_theme = $board_info['theme'];
1810
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1811
+			$id_theme = $board_info['theme'];
1812
+	}
1719 1813
 	// If they have specified a particular theme to use with SSI allow it to be used.
1720
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1721
-		$id_theme = (int) $id_theme;
1722
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1814
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1815
+			$id_theme = (int) $id_theme;
1816
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1723 1817
 	{
1724 1818
 		$themes = explode(',', $modSettings['enableThemes']);
1725
-		if (!in_array($id_theme, $themes))
1726
-			$id_theme = $modSettings['theme_guests'];
1727
-		else
1819
+		if (!in_array($id_theme, $themes)) {
1820
+					$id_theme = $modSettings['theme_guests'];
1821
+		} else {
1822
+					$id_theme = (int) $id_theme;
1823
+		}
1824
+	} else {
1728 1825
 			$id_theme = (int) $id_theme;
1729 1826
 	}
1730
-	else
1731
-		$id_theme = (int) $id_theme;
1732 1827
 
1733 1828
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1734 1829
 
1735 1830
 	// Disable image proxy if we don't have SSL enabled
1736
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1737
-		$image_proxy_enabled = false;
1831
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1832
+			$image_proxy_enabled = false;
1833
+	}
1738 1834
 
1739 1835
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1740 1836
 	{
1741 1837
 		$themeData = $temp;
1742 1838
 		$flag = true;
1839
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1840
+			$themeData = $temp + array($member => array());
1841
+	} else {
1842
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1743 1843
 	}
1744
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1745
-		$themeData = $temp + array($member => array());
1746
-	else
1747
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1844
 
1749 1845
 	if (empty($flag))
1750 1846
 	{
@@ -1763,31 +1859,37 @@  discard block
 block discarded – undo
1763 1859
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1764 1860
 		{
1765 1861
 			// There are just things we shouldn't be able to change as members.
1766
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1767
-				continue;
1862
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1863
+							continue;
1864
+			}
1768 1865
 
1769 1866
 			// If this is the theme_dir of the default theme, store it.
1770
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1771
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1868
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1869
+			}
1772 1870
 
1773 1871
 			// If this isn't set yet, is a theme option, or is not the default theme..
1774
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1775
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1873
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1874
+			}
1776 1875
 		}
1777 1876
 		$smcFunc['db_free_result']($result);
1778 1877
 
1779
-		if (!empty($themeData[-1]))
1780
-			foreach ($themeData[-1] as $k => $v)
1878
+		if (!empty($themeData[-1])) {
1879
+					foreach ($themeData[-1] as $k => $v)
1781 1880
 			{
1782 1881
 				if (!isset($themeData[$member][$k]))
1783 1882
 					$themeData[$member][$k] = $v;
1883
+		}
1784 1884
 			}
1785 1885
 
1786
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1787
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1887
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1888
+		}
1788 1889
 		// Only if we didn't already load that part of the cache...
1789
-		elseif (!isset($temp))
1790
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+		elseif (!isset($temp)) {
1891
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1892
+		}
1791 1893
 	}
1792 1894
 
1793 1895
 	$settings = $themeData[0];
@@ -1804,20 +1906,24 @@  discard block
 block discarded – undo
1804 1906
 	$settings['template_dirs'][] = $settings['theme_dir'];
1805 1907
 
1806 1908
 	// Based on theme (if there is one).
1807
-	if (!empty($settings['base_theme_dir']))
1808
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+	if (!empty($settings['base_theme_dir'])) {
1910
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1911
+	}
1809 1912
 
1810 1913
 	// Lastly the default theme.
1811
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1812
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1915
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1916
+	}
1813 1917
 
1814
-	if (!$initialize)
1815
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1816 1921
 
1817 1922
 	// Check to see if we're forcing SSL
1818 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1819
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1820
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1821 1927
 
1822 1928
 	// Check to see if they're accessing it from the wrong place.
1823 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1825,8 +1931,9 @@  discard block
 block discarded – undo
1825 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1826 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1827 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1828
-		if ($temp != '/')
1829
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1830 1937
 	}
1831 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1832 1939
 	{
@@ -1838,8 +1945,9 @@  discard block
 block discarded – undo
1838 1945
 			foreach ($aliases as $alias)
1839 1946
 			{
1840 1947
 				// Rip off all the boring parts, spaces, etc.
1841
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1842
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1843 1951
 			}
1844 1952
 		}
1845 1953
 
@@ -1847,20 +1955,22 @@  discard block
 block discarded – undo
1847 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1848 1956
 		{
1849 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1850
-			if (empty($_GET))
1851
-				redirectexit('wwwRedirect');
1852
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1853 1961
 			{
1854 1962
 				list ($k, $v) = each($_GET);
1855 1963
 
1856
-				if ($k != 'wwwRedirect')
1857
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1858 1967
 			}
1859 1968
 		}
1860 1969
 
1861 1970
 		// #3 is just a check for SSL...
1862
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1863
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1864 1974
 
1865 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1866 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1894,8 +2004,9 @@  discard block
 block discarded – undo
1894 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1895 2005
 				}
1896 2006
 			}
1897
-			foreach ($context['linktree'] as $k => $dummy)
1898
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1899 2010
 		}
1900 2011
 	}
1901 2012
 	// Set up the contextual user array.
@@ -1914,16 +2025,16 @@  discard block
 block discarded – undo
1914 2025
 			'email' => $user_info['email'],
1915 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1916 2027
 		);
1917
-		if (!$context['user']['is_guest'])
1918
-			$context['user']['name'] = $user_info['name'];
1919
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1920
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1921 2033
 
1922 2034
 		// Determine the current smiley set.
1923 2035
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1924 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1925
-	}
1926
-	else
2037
+	} else
1927 2038
 	{
1928 2039
 		$context['user'] = array(
1929 2040
 			'id' => -1,
@@ -1939,18 +2050,24 @@  discard block
 block discarded – undo
1939 2050
 	}
1940 2051
 
1941 2052
 	// Some basic information...
1942
-	if (!isset($context['html_headers']))
1943
-		$context['html_headers'] = '';
1944
-	if (!isset($context['javascript_files']))
1945
-		$context['javascript_files'] = array();
1946
-	if (!isset($context['css_files']))
1947
-		$context['css_files'] = array();
1948
-	if (!isset($context['css_header']))
1949
-		$context['css_header'] = array();
1950
-	if (!isset($context['javascript_inline']))
1951
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1952
-	if (!isset($context['javascript_vars']))
1953
-		$context['javascript_vars'] = array();
2053
+	if (!isset($context['html_headers'])) {
2054
+			$context['html_headers'] = '';
2055
+	}
2056
+	if (!isset($context['javascript_files'])) {
2057
+			$context['javascript_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_files'])) {
2060
+			$context['css_files'] = array();
2061
+	}
2062
+	if (!isset($context['css_header'])) {
2063
+			$context['css_header'] = array();
2064
+	}
2065
+	if (!isset($context['javascript_inline'])) {
2066
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2067
+	}
2068
+	if (!isset($context['javascript_vars'])) {
2069
+			$context['javascript_vars'] = array();
2070
+	}
1954 2071
 
1955 2072
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1956 2073
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1962,8 +2079,9 @@  discard block
 block discarded – undo
1962 2079
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1963 2080
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1964 2081
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1965
-	if (isset($modSettings['load_average']))
1966
-		$context['load_average'] = $modSettings['load_average'];
2082
+	if (isset($modSettings['load_average'])) {
2083
+			$context['load_average'] = $modSettings['load_average'];
2084
+	}
1967 2085
 
1968 2086
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1969 2087
 	detectBrowser();
@@ -1977,8 +2095,9 @@  discard block
 block discarded – undo
1977 2095
 	// This allows sticking some HTML on the page output - useful for controls.
1978 2096
 	$context['insert_after_template'] = '';
1979 2097
 
1980
-	if (!isset($txt))
1981
-		$txt = array();
2098
+	if (!isset($txt)) {
2099
+			$txt = array();
2100
+	}
1982 2101
 
1983 2102
 	$simpleActions = array(
1984 2103
 		'findmember',
@@ -2024,9 +2143,10 @@  discard block
 block discarded – undo
2024 2143
 
2025 2144
 	// See if theres any extra param to check.
2026 2145
 	$requiresXML = false;
2027
-	foreach ($extraParams as $key => $extra)
2028
-		if (isset($_REQUEST[$extra]))
2146
+	foreach ($extraParams as $key => $extra) {
2147
+			if (isset($_REQUEST[$extra]))
2029 2148
 			$requiresXML = true;
2149
+	}
2030 2150
 
2031 2151
 	// Output is fully XML, so no need for the index template.
2032 2152
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2041,37 +2161,39 @@  discard block
 block discarded – undo
2041 2161
 	{
2042 2162
 		loadLanguage('index+Modifications');
2043 2163
 		$context['template_layers'] = array();
2044
-	}
2045
-
2046
-	else
2164
+	} else
2047 2165
 	{
2048 2166
 		// Custom templates to load, or just default?
2049
-		if (isset($settings['theme_templates']))
2050
-			$templates = explode(',', $settings['theme_templates']);
2051
-		else
2052
-			$templates = array('index');
2167
+		if (isset($settings['theme_templates'])) {
2168
+					$templates = explode(',', $settings['theme_templates']);
2169
+		} else {
2170
+					$templates = array('index');
2171
+		}
2053 2172
 
2054 2173
 		// Load each template...
2055
-		foreach ($templates as $template)
2056
-			loadTemplate($template);
2174
+		foreach ($templates as $template) {
2175
+					loadTemplate($template);
2176
+		}
2057 2177
 
2058 2178
 		// ...and attempt to load their associated language files.
2059 2179
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2060 2180
 		loadLanguage($required_files, '', false);
2061 2181
 
2062 2182
 		// Custom template layers?
2063
-		if (isset($settings['theme_layers']))
2064
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2065
-		else
2066
-			$context['template_layers'] = array('html', 'body');
2183
+		if (isset($settings['theme_layers'])) {
2184
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2185
+		} else {
2186
+					$context['template_layers'] = array('html', 'body');
2187
+		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Initialize the theme.
2070 2191
 	loadSubTemplate('init', 'ignore');
2071 2192
 
2072 2193
 	// Allow overriding the board wide time/number formats.
2073
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2074
-		$user_info['time_format'] = $txt['time_format'];
2194
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2195
+			$user_info['time_format'] = $txt['time_format'];
2196
+	}
2075 2197
 
2076 2198
 	// Set the character set from the template.
2077 2199
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2079,12 +2201,14 @@  discard block
 block discarded – undo
2079 2201
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2080 2202
 
2081 2203
 	// Guests may still need a name.
2082
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2083
-		$context['user']['name'] = $txt['guest_title'];
2204
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2205
+			$context['user']['name'] = $txt['guest_title'];
2206
+	}
2084 2207
 
2085 2208
 	// Any theme-related strings that need to be loaded?
2086
-	if (!empty($settings['require_theme_strings']))
2087
-		loadLanguage('ThemeStrings', '', false);
2209
+	if (!empty($settings['require_theme_strings'])) {
2210
+			loadLanguage('ThemeStrings', '', false);
2211
+	}
2088 2212
 
2089 2213
 	// Make a special URL for the language.
2090 2214
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2095,8 +2219,9 @@  discard block
 block discarded – undo
2095 2219
 	// Here is my luvly Responsive CSS
2096 2220
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2097 2221
 
2098
-	if ($context['right_to_left'])
2099
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2222
+	if ($context['right_to_left']) {
2223
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2224
+	}
2100 2225
 
2101 2226
 	// We allow theme variants, because we're cool.
2102 2227
 	$context['theme_variant'] = '';
@@ -2104,14 +2229,17 @@  discard block
 block discarded – undo
2104 2229
 	if (!empty($settings['theme_variants']))
2105 2230
 	{
2106 2231
 		// Overriding - for previews and that ilk.
2107
-		if (!empty($_REQUEST['variant']))
2108
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2232
+		if (!empty($_REQUEST['variant'])) {
2233
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2234
+		}
2109 2235
 		// User selection?
2110
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2111
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2236
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2237
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2238
+		}
2112 2239
 		// If not a user variant, select the default.
2113
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2114
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2240
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2241
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2242
+		}
2115 2243
 
2116 2244
 		// Do this to keep things easier in the templates.
2117 2245
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2120,20 +2248,23 @@  discard block
 block discarded – undo
2120 2248
 		if (!empty($context['theme_variant']))
2121 2249
 		{
2122 2250
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2123
-			if ($context['right_to_left'])
2124
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2251
+			if ($context['right_to_left']) {
2252
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2253
+			}
2125 2254
 		}
2126 2255
 	}
2127 2256
 
2128 2257
 	// Let's be compatible with old themes!
2129
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2130
-		$context['template_layers'] = array('main');
2258
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2259
+			$context['template_layers'] = array('main');
2260
+	}
2131 2261
 
2132 2262
 	$context['tabindex'] = 1;
2133 2263
 
2134 2264
 	// Compatibility.
2135
-	if (!isset($settings['theme_version']))
2136
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2265
+	if (!isset($settings['theme_version'])) {
2266
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2267
+	}
2137 2268
 
2138 2269
 	// Default JS variables for use in every theme
2139 2270
 	$context['javascript_vars'] = array(
@@ -2152,18 +2283,18 @@  discard block
 block discarded – undo
2152 2283
 	);
2153 2284
 
2154 2285
 	// Add the JQuery library to the list of files to load.
2155
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2156
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2159
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2160
-
2161
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2162
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2286
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2287
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2288
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2289
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2290
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2291
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2292
+	}
2163 2293
 
2164 2294
 	// Auto loading? template_javascript() will take care of the local half of this.
2165
-	else
2166
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2295
+	else {
2296
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2297
+	}
2167 2298
 
2168 2299
 	// Queue our JQuery plugins!
2169 2300
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2186,12 +2317,12 @@  discard block
 block discarded – undo
2186 2317
 			require_once($sourcedir . '/ScheduledTasks.php');
2187 2318
 
2188 2319
 			// What to do, what to do?!
2189
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2190
-				AutoTask();
2191
-			else
2192
-				ReduceMailQueue();
2193
-		}
2194
-		else
2320
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2321
+							AutoTask();
2322
+			} else {
2323
+							ReduceMailQueue();
2324
+			}
2325
+		} else
2195 2326
 		{
2196 2327
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2197 2328
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2242,8 +2373,9 @@  discard block
 block discarded – undo
2242 2373
 		foreach ($theme_includes as $include)
2243 2374
 		{
2244 2375
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2245
-			if (file_exists($include))
2246
-				require_once($include);
2376
+			if (file_exists($include)) {
2377
+							require_once($include);
2378
+			}
2247 2379
 		}
2248 2380
 	}
2249 2381
 
@@ -2273,16 +2405,19 @@  discard block
 block discarded – undo
2273 2405
 	// Do any style sheets first, cause we're easy with those.
2274 2406
 	if (!empty($style_sheets))
2275 2407
 	{
2276
-		if (!is_array($style_sheets))
2277
-			$style_sheets = array($style_sheets);
2408
+		if (!is_array($style_sheets)) {
2409
+					$style_sheets = array($style_sheets);
2410
+		}
2278 2411
 
2279
-		foreach ($style_sheets as $sheet)
2280
-			loadCSSFile($sheet . '.css', array(), $sheet);
2412
+		foreach ($style_sheets as $sheet) {
2413
+					loadCSSFile($sheet . '.css', array(), $sheet);
2414
+		}
2281 2415
 	}
2282 2416
 
2283 2417
 	// No template to load?
2284
-	if ($template_name === false)
2285
-		return true;
2418
+	if ($template_name === false) {
2419
+			return true;
2420
+	}
2286 2421
 
2287 2422
 	$loaded = false;
2288 2423
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2297,12 +2432,14 @@  discard block
 block discarded – undo
2297 2432
 
2298 2433
 	if ($loaded)
2299 2434
 	{
2300
-		if ($db_show_debug === true)
2301
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2435
+		if ($db_show_debug === true) {
2436
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2437
+		}
2302 2438
 
2303 2439
 		// If they have specified an initialization function for this template, go ahead and call it now.
2304
-		if (function_exists('template_' . $template_name . '_init'))
2305
-			call_user_func('template_' . $template_name . '_init');
2440
+		if (function_exists('template_' . $template_name . '_init')) {
2441
+					call_user_func('template_' . $template_name . '_init');
2442
+		}
2306 2443
 	}
2307 2444
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2308 2445
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2322,13 +2459,14 @@  discard block
 block discarded – undo
2322 2459
 		loadTemplate($template_name);
2323 2460
 	}
2324 2461
 	// Cause an error otherwise.
2325
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2326
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2327
-	elseif ($fatal)
2328
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2329
-	else
2330
-		return false;
2331
-}
2462
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2463
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2464
+	} elseif ($fatal) {
2465
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2466
+	} else {
2467
+			return false;
2468
+	}
2469
+	}
2332 2470
 
2333 2471
 /**
2334 2472
  * Load a sub-template.
@@ -2346,17 +2484,19 @@  discard block
 block discarded – undo
2346 2484
 {
2347 2485
 	global $context, $txt, $db_show_debug;
2348 2486
 
2349
-	if ($db_show_debug === true)
2350
-		$context['debug']['sub_templates'][] = $sub_template_name;
2487
+	if ($db_show_debug === true) {
2488
+			$context['debug']['sub_templates'][] = $sub_template_name;
2489
+	}
2351 2490
 
2352 2491
 	// Figure out what the template function is named.
2353 2492
 	$theme_function = 'template_' . $sub_template_name;
2354
-	if (function_exists($theme_function))
2355
-		$theme_function();
2356
-	elseif ($fatal === false)
2357
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2358
-	elseif ($fatal !== 'ignore')
2359
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2493
+	if (function_exists($theme_function)) {
2494
+			$theme_function();
2495
+	} elseif ($fatal === false) {
2496
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2497
+	} elseif ($fatal !== 'ignore') {
2498
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2499
+	}
2360 2500
 
2361 2501
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2362 2502
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2393,8 +2533,9 @@  discard block
 block discarded – undo
2393 2533
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2394 2534
 
2395 2535
 	// If this is an external file, automatically set this to false.
2396
-	if (!empty($params['external']))
2397
-		$params['minimize'] = false;
2536
+	if (!empty($params['external'])) {
2537
+			$params['minimize'] = false;
2538
+	}
2398 2539
 
2399 2540
 	// Account for shorthand like admin.css?alp21 filenames
2400 2541
 	$has_seed = strpos($fileName, '.css?');
@@ -2411,13 +2552,10 @@  discard block
 block discarded – undo
2411 2552
 			{
2412 2553
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2413 2554
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2555
+			} else {
2556
+							$fileUrl = false;
2414 2557
 			}
2415
-
2416
-			else
2417
-				$fileUrl = false;
2418
-		}
2419
-
2420
-		else
2558
+		} else
2421 2559
 		{
2422 2560
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2423 2561
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2432,12 +2570,14 @@  discard block
 block discarded – undo
2432 2570
 	}
2433 2571
 
2434 2572
 	// Add it to the array for use in the template
2435
-	if (!empty($fileName))
2436
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2573
+	if (!empty($fileName)) {
2574
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2575
+	}
2437 2576
 
2438
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2439
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2440
-}
2577
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2578
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2579
+	}
2580
+	}
2441 2581
 
2442 2582
 /**
2443 2583
  * Add a block of inline css code to be executed later
@@ -2454,8 +2594,9 @@  discard block
 block discarded – undo
2454 2594
 	global $context;
2455 2595
 
2456 2596
 	// Gotta add something...
2457
-	if (empty($css))
2458
-		return false;
2597
+	if (empty($css)) {
2598
+			return false;
2599
+	}
2459 2600
 
2460 2601
 	$context['css_header'][] = $css;
2461 2602
 }
@@ -2490,8 +2631,9 @@  discard block
 block discarded – undo
2490 2631
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2491 2632
 
2492 2633
 	// If this is an external file, automatically set this to false.
2493
-	if (!empty($params['external']))
2494
-		$params['minimize'] = false;
2634
+	if (!empty($params['external'])) {
2635
+			$params['minimize'] = false;
2636
+	}
2495 2637
 
2496 2638
 	// Account for shorthand like admin.js?alp21 filenames
2497 2639
 	$has_seed = strpos($fileName, '.js?');
@@ -2508,16 +2650,12 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2510 2652
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2511
-			}
2512
-
2513
-			else
2653
+			} else
2514 2654
 			{
2515 2655
 				$fileUrl = false;
2516 2656
 				$filePath = false;
2517 2657
 			}
2518
-		}
2519
-
2520
-		else
2658
+		} else
2521 2659
 		{
2522 2660
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2523 2661
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2532,9 +2670,10 @@  discard block
 block discarded – undo
2532 2670
 	}
2533 2671
 
2534 2672
 	// Add it to the array for use in the template
2535
-	if (!empty($fileName))
2536
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2537
-}
2673
+	if (!empty($fileName)) {
2674
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2675
+	}
2676
+	}
2538 2677
 
2539 2678
 /**
2540 2679
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2548,9 +2687,10 @@  discard block
 block discarded – undo
2548 2687
 {
2549 2688
 	global $context;
2550 2689
 
2551
-	if (!empty($key) && (!empty($value) || $value === '0'))
2552
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2553
-}
2690
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2691
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2692
+	}
2693
+	}
2554 2694
 
2555 2695
 /**
2556 2696
  * Add a block of inline Javascript code to be executed later
@@ -2567,8 +2707,9 @@  discard block
 block discarded – undo
2567 2707
 {
2568 2708
 	global $context;
2569 2709
 
2570
-	if (empty($javascript))
2571
-		return false;
2710
+	if (empty($javascript)) {
2711
+			return false;
2712
+	}
2572 2713
 
2573 2714
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2574 2715
 }
@@ -2589,15 +2730,18 @@  discard block
 block discarded – undo
2589 2730
 	static $already_loaded = array();
2590 2731
 
2591 2732
 	// Default to the user's language.
2592
-	if ($lang == '')
2593
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2733
+	if ($lang == '') {
2734
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2735
+	}
2594 2736
 
2595 2737
 	// Do we want the English version of language file as fallback?
2596
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2597
-		loadLanguage($template_name, 'english', false);
2738
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2739
+			loadLanguage($template_name, 'english', false);
2740
+	}
2598 2741
 
2599
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2600
-		return $lang;
2742
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2743
+			return $lang;
2744
+	}
2601 2745
 
2602 2746
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2603 2747
 	if (empty($settings['default_theme_dir']))
@@ -2608,8 +2752,9 @@  discard block
 block discarded – undo
2608 2752
 
2609 2753
 	// What theme are we in?
2610 2754
 	$theme_name = basename($settings['theme_url']);
2611
-	if (empty($theme_name))
2612
-		$theme_name = 'unknown';
2755
+	if (empty($theme_name)) {
2756
+			$theme_name = 'unknown';
2757
+	}
2613 2758
 
2614 2759
 	// For each file open it up and write it out!
2615 2760
 	foreach (explode('+', $template_name) as $template)
@@ -2651,8 +2796,9 @@  discard block
 block discarded – undo
2651 2796
 				$found = true;
2652 2797
 
2653 2798
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2654
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2655
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2799
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2800
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2801
+				}
2656 2802
 				
2657 2803
 				break;
2658 2804
 			}
@@ -2692,8 +2838,9 @@  discard block
 block discarded – undo
2692 2838
 	}
2693 2839
 
2694 2840
 	// Keep track of what we're up to soldier.
2695
-	if ($db_show_debug === true)
2696
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2841
+	if ($db_show_debug === true) {
2842
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2843
+	}
2697 2844
 
2698 2845
 	// Remember what we have loaded, and in which language.
2699 2846
 	$already_loaded[$template_name] = $lang;
@@ -2739,8 +2886,9 @@  discard block
 block discarded – undo
2739 2886
 				)
2740 2887
 			);
2741 2888
 			// In the EXTREMELY unlikely event this happens, give an error message.
2742
-			if ($smcFunc['db_num_rows']($result) == 0)
2743
-				fatal_lang_error('parent_not_found', 'critical');
2889
+			if ($smcFunc['db_num_rows']($result) == 0) {
2890
+							fatal_lang_error('parent_not_found', 'critical');
2891
+			}
2744 2892
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2745 2893
 			{
2746 2894
 				if (!isset($boards[$row['id_board']]))
@@ -2757,8 +2905,8 @@  discard block
 block discarded – undo
2757 2905
 					);
2758 2906
 				}
2759 2907
 				// If a moderator exists for this board, add that moderator for all children too.
2760
-				if (!empty($row['id_moderator']))
2761
-					foreach ($boards as $id => $dummy)
2908
+				if (!empty($row['id_moderator'])) {
2909
+									foreach ($boards as $id => $dummy)
2762 2910
 					{
2763 2911
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2764 2912
 							'id' => $row['id_moderator'],
@@ -2766,11 +2914,12 @@  discard block
 block discarded – undo
2766 2914
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2767 2915
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2768 2916
 						);
2917
+				}
2769 2918
 					}
2770 2919
 
2771 2920
 				// If a moderator group exists for this board, add that moderator group for all children too
2772
-				if (!empty($row['id_moderator_group']))
2773
-					foreach ($boards as $id => $dummy)
2921
+				if (!empty($row['id_moderator_group'])) {
2922
+									foreach ($boards as $id => $dummy)
2774 2923
 					{
2775 2924
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2776 2925
 							'id' => $row['id_moderator_group'],
@@ -2778,6 +2927,7 @@  discard block
 block discarded – undo
2778 2927
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2779 2928
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2780 2929
 						);
2930
+				}
2781 2931
 					}
2782 2932
 			}
2783 2933
 			$smcFunc['db_free_result']($result);
@@ -2804,23 +2954,27 @@  discard block
 block discarded – undo
2804 2954
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2805 2955
 	{
2806 2956
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2807
-		if (empty($smcFunc['ucwords']))
2808
-			reloadSettings();
2957
+		if (empty($smcFunc['ucwords'])) {
2958
+					reloadSettings();
2959
+		}
2809 2960
 
2810 2961
 		// If we don't have our theme information yet, let's get it.
2811
-		if (empty($settings['default_theme_dir']))
2812
-			loadTheme(0, false);
2962
+		if (empty($settings['default_theme_dir'])) {
2963
+					loadTheme(0, false);
2964
+		}
2813 2965
 
2814 2966
 		// Default language directories to try.
2815 2967
 		$language_directories = array(
2816 2968
 			$settings['default_theme_dir'] . '/languages',
2817 2969
 		);
2818
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2819
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2970
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2971
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2972
+		}
2820 2973
 
2821 2974
 		// We possibly have a base theme directory.
2822
-		if (!empty($settings['base_theme_dir']))
2823
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2975
+		if (!empty($settings['base_theme_dir'])) {
2976
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2977
+		}
2824 2978
 
2825 2979
 		// Remove any duplicates.
2826 2980
 		$language_directories = array_unique($language_directories);
@@ -2834,20 +2988,21 @@  discard block
 block discarded – undo
2834 2988
 		foreach ($language_directories as $language_dir)
2835 2989
 		{
2836 2990
 			// Can't look in here... doesn't exist!
2837
-			if (!file_exists($language_dir))
2838
-				continue;
2991
+			if (!file_exists($language_dir)) {
2992
+							continue;
2993
+			}
2839 2994
 
2840 2995
 			$dir = dir($language_dir);
2841 2996
 			while ($entry = $dir->read())
2842 2997
 			{
2843 2998
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2844
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2845
-					continue;
2846
-
2847
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2848
-					$langName = $langList[$matches[1]];
2999
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3000
+									continue;
3001
+				}
2849 3002
 
2850
-				else
3003
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3004
+									$langName = $langList[$matches[1]];
3005
+				} else
2851 3006
 				{
2852 3007
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2853 3008
 
@@ -2888,12 +3043,14 @@  discard block
 block discarded – undo
2888 3043
 		}
2889 3044
 
2890 3045
 		// Do we need to store the lang list?
2891
-		if (empty($langList))
2892
-			updateSettings(array('langList' => json_encode($catchLang)));
3046
+		if (empty($langList)) {
3047
+					updateSettings(array('langList' => json_encode($catchLang)));
3048
+		}
2893 3049
 
2894 3050
 		// Let's cash in on this deal.
2895
-		if (!empty($modSettings['cache_enable']))
2896
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3051
+		if (!empty($modSettings['cache_enable'])) {
3052
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3053
+		}
2897 3054
 	}
2898 3055
 
2899 3056
 	return $context['languages'];
@@ -2916,8 +3073,9 @@  discard block
 block discarded – undo
2916 3073
 	global $modSettings, $options, $txt;
2917 3074
 	static $censor_vulgar = null, $censor_proper;
2918 3075
 
2919
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2920
-		return $text;
3076
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3077
+			return $text;
3078
+	}
2921 3079
 
2922 3080
 	// If they haven't yet been loaded, load them.
2923 3081
 	if ($censor_vulgar == null)
@@ -2945,9 +3103,9 @@  discard block
 block discarded – undo
2945 3103
 	{
2946 3104
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2947 3105
 		$text = $func($censor_vulgar, $censor_proper, $text);
3106
+	} else {
3107
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2948 3108
 	}
2949
-	else
2950
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2951 3109
 
2952 3110
 	return $text;
2953 3111
 }
@@ -2973,38 +3131,42 @@  discard block
 block discarded – undo
2973 3131
 	@ini_set('track_errors', '1');
2974 3132
 
2975 3133
 	// Don't include the file more than once, if $once is true.
2976
-	if ($once && in_array($filename, $templates))
2977
-		return;
3134
+	if ($once && in_array($filename, $templates)) {
3135
+			return;
3136
+	}
2978 3137
 	// Add this file to the include list, whether $once is true or not.
2979
-	else
2980
-		$templates[] = $filename;
3138
+	else {
3139
+			$templates[] = $filename;
3140
+	}
2981 3141
 
2982 3142
 	// Are we going to use eval?
2983 3143
 	if (empty($modSettings['disableTemplateEval']))
2984 3144
 	{
2985 3145
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2986 3146
 		$settings['current_include_filename'] = $filename;
2987
-	}
2988
-	else
3147
+	} else
2989 3148
 	{
2990 3149
 		$file_found = file_exists($filename);
2991 3150
 
2992
-		if ($once && $file_found)
2993
-			require_once($filename);
2994
-		elseif ($file_found)
2995
-			require($filename);
3151
+		if ($once && $file_found) {
3152
+					require_once($filename);
3153
+		} elseif ($file_found) {
3154
+					require($filename);
3155
+		}
2996 3156
 	}
2997 3157
 
2998 3158
 	if ($file_found !== true)
2999 3159
 	{
3000 3160
 		ob_end_clean();
3001
-		if (!empty($modSettings['enableCompressedOutput']))
3002
-			@ob_start('ob_gzhandler');
3003
-		else
3004
-			ob_start();
3161
+		if (!empty($modSettings['enableCompressedOutput'])) {
3162
+					@ob_start('ob_gzhandler');
3163
+		} else {
3164
+					ob_start();
3165
+		}
3005 3166
 
3006
-		if (isset($_GET['debug']))
3007
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3167
+		if (isset($_GET['debug'])) {
3168
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3169
+		}
3008 3170
 
3009 3171
 		// Don't cache error pages!!
3010 3172
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3023,12 +3185,13 @@  discard block
 block discarded – undo
3023 3185
 		echo '<!DOCTYPE html>
3024 3186
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3025 3187
 	<head>';
3026
-		if (isset($context['character_set']))
3027
-			echo '
3188
+		if (isset($context['character_set'])) {
3189
+					echo '
3028 3190
 		<meta charset="', $context['character_set'], '">';
3191
+		}
3029 3192
 
3030
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3031
-			echo '
3193
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3194
+					echo '
3032 3195
 		<title>', $mtitle, '</title>
3033 3196
 	</head>
3034 3197
 	<body>
@@ -3036,8 +3199,8 @@  discard block
 block discarded – undo
3036 3199
 		', $mmessage, '
3037 3200
 	</body>
3038 3201
 </html>';
3039
-		elseif (!allowedTo('admin_forum'))
3040
-			echo '
3202
+		} elseif (!allowedTo('admin_forum')) {
3203
+					echo '
3041 3204
 		<title>', $txt['template_parse_error'], '</title>
3042 3205
 	</head>
3043 3206
 	<body>
@@ -3045,15 +3208,17 @@  discard block
 block discarded – undo
3045 3208
 		', $txt['template_parse_error_message'], '
3046 3209
 	</body>
3047 3210
 </html>';
3048
-		else
3211
+		} else
3049 3212
 		{
3050 3213
 			require_once($sourcedir . '/Subs-Package.php');
3051 3214
 
3052 3215
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3053
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3054
-				$error = $php_errormsg;
3055
-			if (empty($error))
3056
-				$error = $txt['template_parse_errmsg'];
3216
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3217
+							$error = $php_errormsg;
3218
+			}
3219
+			if (empty($error)) {
3220
+							$error = $txt['template_parse_errmsg'];
3221
+			}
3057 3222
 
3058 3223
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3059 3224
 
@@ -3064,11 +3229,12 @@  discard block
 block discarded – undo
3064 3229
 		<h3>', $txt['template_parse_error'], '</h3>
3065 3230
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3066 3231
 
3067
-			if (!empty($error))
3068
-				echo '
3232
+			if (!empty($error)) {
3233
+							echo '
3069 3234
 		<hr>
3070 3235
 
3071 3236
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3237
+			}
3072 3238
 
3073 3239
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3074 3240
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3078,10 +3244,11 @@  discard block
 block discarded – undo
3078 3244
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3079 3245
 
3080 3246
 				// Fix the PHP code stuff...
3081
-				if (!isBrowser('gecko'))
3082
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3083
-				else
3084
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3247
+				if (!isBrowser('gecko')) {
3248
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3249
+				} else {
3250
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3251
+				}
3085 3252
 
3086 3253
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3087 3254
 				$j = -1;
@@ -3089,8 +3256,9 @@  discard block
 block discarded – undo
3089 3256
 				{
3090 3257
 					$j++;
3091 3258
 
3092
-					if (substr_count($line, '<br>') == 0)
3093
-						continue;
3259
+					if (substr_count($line, '<br>') == 0) {
3260
+											continue;
3261
+					}
3094 3262
 
3095 3263
 					$n = substr_count($line, '<br>');
3096 3264
 					for ($i = 0; $i < $n; $i++)
@@ -3109,38 +3277,42 @@  discard block
 block discarded – undo
3109 3277
 				// Figure out what the color coding was before...
3110 3278
 				$line = max($match[1] - 9, 1);
3111 3279
 				$last_line = '';
3112
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3113
-					if (strpos($data2[$line2], '<') !== false)
3280
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3281
+									if (strpos($data2[$line2], '<') !== false)
3114 3282
 					{
3115 3283
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3116 3284
 							$last_line = $color_match[1];
3285
+				}
3117 3286
 						break;
3118 3287
 					}
3119 3288
 
3120 3289
 				// Show the relevant lines...
3121 3290
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3122 3291
 				{
3123
-					if ($line == $match[1])
3124
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3292
+					if ($line == $match[1]) {
3293
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3294
+					}
3125 3295
 
3126 3296
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3127
-					if (isset($data2[$line]) && $data2[$line] != '')
3128
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3297
+					if (isset($data2[$line]) && $data2[$line] != '') {
3298
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3299
+					}
3129 3300
 
3130 3301
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3131 3302
 					{
3132 3303
 						$last_line = $color_match[1];
3133 3304
 						echo '</', substr($last_line, 1, 4), '>';
3305
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3306
+											$last_line = '';
3307
+					} elseif ($last_line != '' && $data2[$line] != '') {
3308
+											echo '</', substr($last_line, 1, 4), '>';
3134 3309
 					}
3135
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3136
-						$last_line = '';
3137
-					elseif ($last_line != '' && $data2[$line] != '')
3138
-						echo '</', substr($last_line, 1, 4), '>';
3139 3310
 
3140
-					if ($line == $match[1])
3141
-						echo '</pre></div><pre style="margin: 0;">';
3142
-					else
3143
-						echo "\n";
3311
+					if ($line == $match[1]) {
3312
+											echo '</pre></div><pre style="margin: 0;">';
3313
+					} else {
3314
+											echo "\n";
3315
+					}
3144 3316
 				}
3145 3317
 
3146 3318
 				echo '</pre></div>';
@@ -3164,8 +3336,9 @@  discard block
 block discarded – undo
3164 3336
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3165 3337
 
3166 3338
 	// Figure out what type of database we are using.
3167
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3168
-		$db_type = 'mysql';
3339
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3340
+			$db_type = 'mysql';
3341
+	}
3169 3342
 
3170 3343
 	// Load the file for the database.
3171 3344
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3173,8 +3346,9 @@  discard block
 block discarded – undo
3173 3346
 	$db_options = array();
3174 3347
 
3175 3348
 	// Add in the port if needed
3176
-	if (!empty($db_port))
3177
-		$db_options['port'] = $db_port;
3349
+	if (!empty($db_port)) {
3350
+			$db_options['port'] = $db_port;
3351
+	}
3178 3352
 
3179 3353
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3180 3354
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3193,13 +3367,15 @@  discard block
 block discarded – undo
3193 3367
 	}
3194 3368
 
3195 3369
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3196
-	if (!$db_connection)
3197
-		display_db_error();
3370
+	if (!$db_connection) {
3371
+			display_db_error();
3372
+	}
3198 3373
 
3199 3374
 	// If in SSI mode fix up the prefix.
3200
-	if (SMF == 'SSI')
3201
-		db_fix_prefix($db_prefix, $db_name);
3202
-}
3375
+	if (SMF == 'SSI') {
3376
+			db_fix_prefix($db_prefix, $db_name);
3377
+	}
3378
+	}
3203 3379
 
3204 3380
 /**
3205 3381
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3213,10 +3389,11 @@  discard block
 block discarded – undo
3213 3389
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3214 3390
 
3215 3391
 	// Not overriding this and we have a cacheAPI, send it back.
3216
-	if (empty($overrideCache) && is_object($cacheAPI))
3217
-		return $cacheAPI;
3218
-	elseif (is_null($cacheAPI))
3219
-		$cacheAPI = false;
3392
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3393
+			return $cacheAPI;
3394
+	} elseif (is_null($cacheAPI)) {
3395
+			$cacheAPI = false;
3396
+	}
3220 3397
 
3221 3398
 	// Make sure our class is in session.
3222 3399
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3237,8 +3414,9 @@  discard block
 block discarded – undo
3237 3414
 		if (!$testAPI->isSupported())
3238 3415
 		{
3239 3416
 			// Can we save ourselves?
3240
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3241
-				return loadCacheAccelerator(null, false);
3417
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3418
+							return loadCacheAccelerator(null, false);
3419
+			}
3242 3420
 			return false;
3243 3421
 		}
3244 3422
 
@@ -3250,9 +3428,9 @@  discard block
 block discarded – undo
3250 3428
 		{
3251 3429
 			$cacheAPI = $testAPI;
3252 3430
 			return $cacheAPI;
3431
+		} else {
3432
+					return $testAPI;
3253 3433
 		}
3254
-		else
3255
-			return $testAPI;
3256 3434
 	}
3257 3435
 }
3258 3436
 
@@ -3272,8 +3450,9 @@  discard block
 block discarded – undo
3272 3450
 
3273 3451
 	// @todo Why are we doing this if caching is disabled?
3274 3452
 
3275
-	if (function_exists('call_integration_hook'))
3276
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3453
+	if (function_exists('call_integration_hook')) {
3454
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3455
+	}
3277 3456
 
3278 3457
 	/* Refresh the cache if either:
3279 3458
 		1. Caching is disabled.
@@ -3287,16 +3466,19 @@  discard block
 block discarded – undo
3287 3466
 		require_once($sourcedir . '/' . $file);
3288 3467
 		$cache_block = call_user_func_array($function, $params);
3289 3468
 
3290
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3291
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3469
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3470
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3471
+		}
3292 3472
 	}
3293 3473
 
3294 3474
 	// Some cached data may need a freshening up after retrieval.
3295
-	if (!empty($cache_block['post_retri_eval']))
3296
-		eval($cache_block['post_retri_eval']);
3475
+	if (!empty($cache_block['post_retri_eval'])) {
3476
+			eval($cache_block['post_retri_eval']);
3477
+	}
3297 3478
 
3298
-	if (function_exists('call_integration_hook'))
3299
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3479
+	if (function_exists('call_integration_hook')) {
3480
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3481
+	}
3300 3482
 
3301 3483
 	return $cache_block['data'];
3302 3484
 }
@@ -3323,8 +3505,9 @@  discard block
 block discarded – undo
3323 3505
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3324 3506
 	global $cache_hits, $cache_count, $db_show_debug;
3325 3507
 
3326
-	if (empty($cache_enable) || empty($cacheAPI))
3327
-		return;
3508
+	if (empty($cache_enable) || empty($cacheAPI)) {
3509
+			return;
3510
+	}
3328 3511
 
3329 3512
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3330 3513
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3337,12 +3520,14 @@  discard block
 block discarded – undo
3337 3520
 	$value = $value === null ? null : json_encode($value);
3338 3521
 	$cacheAPI->putData($key, $value, $ttl);
3339 3522
 
3340
-	if (function_exists('call_integration_hook'))
3341
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3523
+	if (function_exists('call_integration_hook')) {
3524
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3525
+	}
3342 3526
 
3343
-	if (isset($db_show_debug) && $db_show_debug === true)
3344
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3345
-}
3527
+	if (isset($db_show_debug) && $db_show_debug === true) {
3528
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3529
+	}
3530
+	}
3346 3531
 
3347 3532
 /**
3348 3533
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3358,8 +3543,9 @@  discard block
 block discarded – undo
3358 3543
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3359 3544
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3360 3545
 
3361
-	if (empty($cache_enable) || empty($cacheAPI))
3362
-		return;
3546
+	if (empty($cache_enable) || empty($cacheAPI)) {
3547
+			return;
3548
+	}
3363 3549
 
3364 3550
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3365 3551
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3379,16 +3565,18 @@  discard block
 block discarded – undo
3379 3565
 
3380 3566
 		if (empty($value))
3381 3567
 		{
3382
-			if (!is_array($cache_misses))
3383
-				$cache_misses = array();
3568
+			if (!is_array($cache_misses)) {
3569
+							$cache_misses = array();
3570
+			}
3384 3571
 
3385 3572
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3386 3573
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3387 3574
 		}
3388 3575
 	}
3389 3576
 
3390
-	if (function_exists('call_integration_hook') && isset($value))
3391
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3577
+	if (function_exists('call_integration_hook') && isset($value)) {
3578
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3579
+	}
3392 3580
 
3393 3581
 	return empty($value) ? null : smf_json_decode($value, true);
3394 3582
 }
@@ -3410,8 +3598,9 @@  discard block
 block discarded – undo
3410 3598
 	global $cacheAPI;
3411 3599
 
3412 3600
 	// If we can't get to the API, can't do this.
3413
-	if (empty($cacheAPI))
3414
-		return;
3601
+	if (empty($cacheAPI)) {
3602
+			return;
3603
+	}
3415 3604
 
3416 3605
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3417 3606
 	$cacheAPI->cleanCache($type);
@@ -3436,8 +3625,9 @@  discard block
 block discarded – undo
3436 3625
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3437 3626
 
3438 3627
 	// Come on!
3439
-	if (empty($data))
3440
-		return array();
3628
+	if (empty($data)) {
3629
+			return array();
3630
+	}
3441 3631
 
3442 3632
 	// Set a nice default var.
3443 3633
 	$image = '';
@@ -3445,11 +3635,11 @@  discard block
 block discarded – undo
3445 3635
 	// Gravatar has been set as mandatory!
3446 3636
 	if (!empty($modSettings['gravatarOverride']))
3447 3637
 	{
3448
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3449
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3450
-
3451
-		else if (!empty($data['email']))
3452
-			$image = get_gravatar_url($data['email']);
3638
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3639
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3640
+		} else if (!empty($data['email'])) {
3641
+					$image = get_gravatar_url($data['email']);
3642
+		}
3453 3643
 	}
3454 3644
 
3455 3645
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3461,54 +3651,60 @@  discard block
 block discarded – undo
3461 3651
 			// Gravatar.
3462 3652
 			if (stristr($data['avatar'], 'gravatar://'))
3463 3653
 			{
3464
-				if ($data['avatar'] == 'gravatar://')
3465
-					$image = get_gravatar_url($data['email']);
3466
-
3467
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3468
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3654
+				if ($data['avatar'] == 'gravatar://') {
3655
+									$image = get_gravatar_url($data['email']);
3656
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3657
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+				}
3469 3659
 			}
3470 3660
 
3471 3661
 			// External url.
3472 3662
 			else
3473 3663
 			{
3474 3664
 				// Using ssl?
3475
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3476
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3665
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3666
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3667
+				}
3477 3668
 
3478 3669
 				// Just a plain external url.
3479
-				else
3480
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3670
+				else {
3671
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3672
+				}
3481 3673
 			}
3482 3674
 		}
3483 3675
 
3484 3676
 		// Perhaps this user has an attachment as avatar...
3485
-		else if (!empty($data['filename']))
3486
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3677
+		else if (!empty($data['filename'])) {
3678
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3679
+		}
3487 3680
 
3488 3681
 		// Right... no avatar... use our default image.
3489
-		else
3490
-			$image = $modSettings['avatar_url'] . '/default.png';
3682
+		else {
3683
+					$image = $modSettings['avatar_url'] . '/default.png';
3684
+		}
3491 3685
 	}
3492 3686
 
3493 3687
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3494 3688
 
3495 3689
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3496
-	if (!empty($image))
3497
-		return array(
3690
+	if (!empty($image)) {
3691
+			return array(
3498 3692
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3499 3693
 			'image' => '<img class="avatar" src="' . $image . '" />',
3500 3694
 			'href' => $image,
3501 3695
 			'url' => $image,
3502 3696
 		);
3697
+	}
3503 3698
 
3504 3699
 	// Fallback to make life easier for everyone...
3505
-	else
3506
-		return array(
3700
+	else {
3701
+			return array(
3507 3702
 			'name' => '',
3508 3703
 			'image' => '',
3509 3704
 			'href' => '',
3510 3705
 			'url' => '',
3511 3706
 		);
3512
-}
3707
+	}
3708
+	}
3513 3709
 
3514 3710
 ?>
3515 3711
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +219 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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',
@@ -60,11 +61,13 @@  discard block
 block discarded – undo
60 61
 			'db_is_resource' => 'is_resource',
61 62
 			'db_mb4' => true,
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
66
-	else
67
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
66
+	if (!empty($db_options['persist'])) {
67
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
68
+	} else {
69
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
70
+	}
68 71
 
69 72
 	// Something's wrong, show an error if its fatal (which we assume it is)
70 73
 	if (!$connection)
@@ -72,8 +75,7 @@  discard block
 block discarded – undo
72 75
 		if (!empty($db_options['non_fatal']))
73 76
 		{
74 77
 			return null;
75
-		}
76
-		else
78
+		} else
77 79
 		{
78 80
 			display_db_error();
79 81
 		}
@@ -124,34 +126,42 @@  discard block
 block discarded – undo
124 126
 
125 127
 	list ($values, $connection) = $db_callback;
126 128
 
127
-	if ($matches[1] === 'db_prefix')
128
-		return $db_prefix;
129
+	if ($matches[1] === 'db_prefix') {
130
+			return $db_prefix;
131
+	}
129 132
 
130
-	if ($matches[1] === 'query_see_board')
131
-		return $user_info['query_see_board'];
133
+	if ($matches[1] === 'query_see_board') {
134
+			return $user_info['query_see_board'];
135
+	}
132 136
 
133
-	if ($matches[1] === 'query_wanna_see_board')
134
-		return $user_info['query_wanna_see_board'];
137
+	if ($matches[1] === 'query_wanna_see_board') {
138
+			return $user_info['query_wanna_see_board'];
139
+	}
135 140
 
136
-	if ($matches[1] === 'empty')
137
-		return '\'\'';
141
+	if ($matches[1] === 'empty') {
142
+			return '\'\'';
143
+	}
138 144
 
139
-	if (!isset($matches[2]))
140
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
145
+	if (!isset($matches[2])) {
146
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
147
+	}
141 148
 
142
-	if ($matches[1] === 'literal')
143
-		return '\'' . pg_escape_string($matches[2]) . '\'';
149
+	if ($matches[1] === 'literal') {
150
+			return '\'' . pg_escape_string($matches[2]) . '\'';
151
+	}
144 152
 
145
-	if (!isset($values[$matches[2]]))
146
-		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__);
153
+	if (!isset($values[$matches[2]])) {
154
+			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__);
155
+	}
147 156
 
148 157
 	$replacement = $values[$matches[2]];
149 158
 
150 159
 	switch ($matches[1])
151 160
 	{
152 161
 		case 'int':
153
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
154
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
162
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
163
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
164
+			}
155 165
 			return (string) (int) $replacement;
156 166
 		break;
157 167
 
@@ -163,65 +173,73 @@  discard block
 block discarded – undo
163 173
 		case 'array_int':
164 174
 			if (is_array($replacement))
165 175
 			{
166
-				if (empty($replacement))
167
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
176
+				if (empty($replacement)) {
177
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
178
+				}
168 179
 
169 180
 				foreach ($replacement as $key => $value)
170 181
 				{
171
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
172
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
182
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
183
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
184
+					}
173 185
 
174 186
 					$replacement[$key] = (string) (int) $value;
175 187
 				}
176 188
 
177 189
 				return implode(', ', $replacement);
190
+			} else {
191
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
178 192
 			}
179
-			else
180
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181 193
 
182 194
 		break;
183 195
 
184 196
 		case 'array_string':
185 197
 			if (is_array($replacement))
186 198
 			{
187
-				if (empty($replacement))
188
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
199
+				if (empty($replacement)) {
200
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+				}
189 202
 
190
-				foreach ($replacement as $key => $value)
191
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
203
+				foreach ($replacement as $key => $value) {
204
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
205
+				}
192 206
 
193 207
 				return implode(', ', $replacement);
208
+			} else {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 210
 			}
195
-			else
196
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197 211
 		break;
198 212
 
199 213
 		case 'date':
200
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
201
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
202
-			else
203
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
214
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
215
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
216
+			} else {
217
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+			}
204 219
 		break;
205 220
 
206 221
 		case 'time':
207
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
208
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
209
-			else
210
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
223
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
224
+			} else {
225
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+			}
211 227
 		break;
212 228
 		
213 229
 		case 'datetime':
214
-			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)
215
-				return 'to_timestamp('.
230
+			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) {
231
+							return 'to_timestamp('.
216 232
 					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 233
 					',\'YYYY-MM-DD HH24:MI:SS\')';
218
-			else
219
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			}
220 237
 		break;
221 238
 
222 239
 		case 'float':
223
-			if (!is_numeric($replacement))
224
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240
+			if (!is_numeric($replacement)) {
241
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242
+			}
225 243
 			return (string) (float) $replacement;
226 244
 		break;
227 245
 
@@ -234,31 +252,36 @@  discard block
 block discarded – undo
234 252
 		break;
235 253
 
236 254
 		case 'inet':
237
-			if ($replacement == 'null' || $replacement == '')
238
-				return 'null';
239
-			if (inet_pton($replacement) === false)
240
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+			if ($replacement == 'null' || $replacement == '') {
256
+							return 'null';
257
+			}
258
+			if (inet_pton($replacement) === false) {
259
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			}
241 261
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
242 262
 
243 263
 		case 'array_inet':
244 264
 			if (is_array($replacement))
245 265
 			{
246
-				if (empty($replacement))
247
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+				if (empty($replacement)) {
267
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+				}
248 269
 
249 270
 				foreach ($replacement as $key => $value)
250 271
 				{
251
-					if ($replacement == 'null' || $replacement == '')
252
-						$replacement[$key] = 'null';
253
-					if (!isValidIP($value))
254
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+					if ($replacement == 'null' || $replacement == '') {
273
+											$replacement[$key] = 'null';
274
+					}
275
+					if (!isValidIP($value)) {
276
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+					}
255 278
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
256 279
 				}
257 280
 
258 281
 				return implode(', ', $replacement);
282
+			} else {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
259 284
 			}
260
-			else
261
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262 285
 		break;
263 286
 
264 287
 		default:
@@ -342,14 +365,16 @@  discard block
 block discarded – undo
342 365
 		),
343 366
 	);
344 367
 
345
-	if (isset($replacements[$identifier]))
346
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
368
+	if (isset($replacements[$identifier])) {
369
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
370
+	}
347 371
 
348 372
 	// Limits need to be a little different.
349 373
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
350 374
 
351
-	if (trim($db_string) == '')
352
-		return false;
375
+	if (trim($db_string) == '') {
376
+			return false;
377
+	}
353 378
 
354 379
 	// Comments that are allowed in a query are preg_removed.
355 380
 	static $allowed_comments_from = array(
@@ -369,8 +394,9 @@  discard block
 block discarded – undo
369 394
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
370 395
 	$db_replace_result = 0;
371 396
 
372
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
373
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
397
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
398
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
399
+	}
374 400
 
375 401
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
376 402
 	{
@@ -391,8 +417,9 @@  discard block
 block discarded – undo
391 417
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
392 418
 
393 419
 		// Initialize $db_cache if not already initialized.
394
-		if (!isset($db_cache))
395
-			$db_cache = array();
420
+		if (!isset($db_cache)) {
421
+					$db_cache = array();
422
+		}
396 423
 
397 424
 		if (!empty($_SESSION['debug_redirect']))
398 425
 		{
@@ -418,17 +445,18 @@  discard block
 block discarded – undo
418 445
 		while (true)
419 446
 		{
420 447
 			$pos = strpos($db_string, '\'', $pos + 1);
421
-			if ($pos === false)
422
-				break;
448
+			if ($pos === false) {
449
+							break;
450
+			}
423 451
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
424 452
 
425 453
 			while (true)
426 454
 			{
427 455
 				$pos1 = strpos($db_string, '\'', $pos + 1);
428 456
 				$pos2 = strpos($db_string, '\\', $pos + 1);
429
-				if ($pos1 === false)
430
-					break;
431
-				elseif ($pos2 === false || $pos2 > $pos1)
457
+				if ($pos1 === false) {
458
+									break;
459
+				} elseif ($pos2 === false || $pos2 > $pos1)
432 460
 				{
433 461
 					$pos = $pos1;
434 462
 					break;
@@ -444,26 +472,31 @@  discard block
 block discarded – undo
444 472
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
445 473
 
446 474
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
447
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
448
-			$fail = true;
475
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
476
+					$fail = true;
477
+		}
449 478
 		// Trying to change passwords, slow us down, or something?
450
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
451
-			$fail = true;
452
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
453
-			$fail = true;
479
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
480
+					$fail = true;
481
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
482
+					$fail = true;
483
+		}
454 484
 
455
-		if (!empty($fail) && function_exists('log_error'))
456
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
485
+		if (!empty($fail) && function_exists('log_error')) {
486
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
487
+		}
457 488
 	}
458 489
 
459 490
 	$db_last_result = @pg_query($connection, $db_string);
460 491
 
461
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
462
-		$db_last_result = smf_db_error($db_string, $connection);
492
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
493
+			$db_last_result = smf_db_error($db_string, $connection);
494
+	}
463 495
 
464 496
 	// Debugging.
465
-	if (isset($db_show_debug) && $db_show_debug === true)
466
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
497
+	if (isset($db_show_debug) && $db_show_debug === true) {
498
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
499
+	}
467 500
 
468 501
 	return $db_last_result;
469 502
 }
@@ -476,10 +509,11 @@  discard block
 block discarded – undo
476 509
 {
477 510
 	global $db_last_result, $db_replace_result;
478 511
 
479
-	if ($db_replace_result)
480
-		return $db_replace_result;
481
-	elseif ($result === null && !$db_last_result)
482
-		return 0;
512
+	if ($db_replace_result) {
513
+			return $db_replace_result;
514
+	} elseif ($result === null && !$db_last_result) {
515
+			return 0;
516
+	}
483 517
 
484 518
 	return pg_affected_rows($result === null ? $db_last_result : $result);
485 519
 }
@@ -503,8 +537,9 @@  discard block
 block discarded – undo
503 537
 		array(
504 538
 		)
505 539
 	);
506
-	if (!$request)
507
-		return false;
540
+	if (!$request) {
541
+			return false;
542
+	}
508 543
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
509 544
 	$smcFunc['db_free_result']($request);
510 545
 
@@ -525,12 +560,13 @@  discard block
 block discarded – undo
525 560
 	// Decide which connection to use
526 561
 	$connection = $connection === null ? $db_connection : $connection;
527 562
 
528
-	if ($type == 'begin')
529
-		return @pg_query($connection, 'BEGIN');
530
-	elseif ($type == 'rollback')
531
-		return @pg_query($connection, 'ROLLBACK');
532
-	elseif ($type == 'commit')
533
-		return @pg_query($connection, 'COMMIT');
563
+	if ($type == 'begin') {
564
+			return @pg_query($connection, 'BEGIN');
565
+	} elseif ($type == 'rollback') {
566
+			return @pg_query($connection, 'ROLLBACK');
567
+	} elseif ($type == 'commit') {
568
+			return @pg_query($connection, 'COMMIT');
569
+	}
534 570
 
535 571
 	return false;
536 572
 }
@@ -558,19 +594,22 @@  discard block
 block discarded – undo
558 594
 	$query_error = @pg_last_error($connection);
559 595
 
560 596
 	// Log the error.
561
-	if (function_exists('log_error'))
562
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
597
+	if (function_exists('log_error')) {
598
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
599
+	}
563 600
 
564 601
 	// Nothing's defined yet... just die with it.
565
-	if (empty($context) || empty($txt))
566
-		die($query_error);
602
+	if (empty($context) || empty($txt)) {
603
+			die($query_error);
604
+	}
567 605
 
568 606
 	// Show an error message, if possible.
569 607
 	$context['error_title'] = $txt['database_error'];
570
-	if (allowedTo('admin_forum'))
571
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
572
-	else
573
-		$context['error_message'] = $txt['try_again'];
608
+	if (allowedTo('admin_forum')) {
609
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
610
+	} else {
611
+			$context['error_message'] = $txt['try_again'];
612
+	}
574 613
 
575 614
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
576 615
 	{
@@ -592,12 +631,14 @@  discard block
 block discarded – undo
592 631
 {
593 632
 	global $db_row_count;
594 633
 
595
-	if ($counter !== false)
596
-		return pg_fetch_row($request, $counter);
634
+	if ($counter !== false) {
635
+			return pg_fetch_row($request, $counter);
636
+	}
597 637
 
598 638
 	// Reset the row counter...
599
-	if (!isset($db_row_count[(int) $request]))
600
-		$db_row_count[(int) $request] = 0;
639
+	if (!isset($db_row_count[(int) $request])) {
640
+			$db_row_count[(int) $request] = 0;
641
+	}
601 642
 
602 643
 	// Return the right row.
603 644
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -614,12 +655,14 @@  discard block
 block discarded – undo
614 655
 {
615 656
 	global $db_row_count;
616 657
 
617
-	if ($counter !== false)
618
-		return pg_fetch_assoc($request, $counter);
658
+	if ($counter !== false) {
659
+			return pg_fetch_assoc($request, $counter);
660
+	}
619 661
 
620 662
 	// Reset the row counter...
621
-	if (!isset($db_row_count[(int) $request]))
622
-		$db_row_count[(int) $request] = 0;
663
+	if (!isset($db_row_count[(int) $request])) {
664
+			$db_row_count[(int) $request] = 0;
665
+	}
623 666
 
624 667
 	// Return the right row.
625 668
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -672,11 +715,13 @@  discard block
 block discarded – undo
672 715
 
673 716
 	$replace = '';
674 717
 
675
-	if (empty($data))
676
-		return;
718
+	if (empty($data)) {
719
+			return;
720
+	}
677 721
 
678
-	if (!is_array($data[array_rand($data)]))
679
-		$data = array($data);
722
+	if (!is_array($data[array_rand($data)])) {
723
+			$data = array($data);
724
+	}
680 725
 
681 726
 	// Replace the prefix holder with the actual prefix.
682 727
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -695,11 +740,13 @@  discard block
 block discarded – undo
695 740
 			//pg 9.5 got replace support
696 741
 			$pg_version = $smcFunc['db_get_version']();
697 742
 			// if we got a Beta Version
698
-			if (stripos($pg_version, 'beta') !== false)
699
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
743
+			if (stripos($pg_version, 'beta') !== false) {
744
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
745
+			}
700 746
 			// or RC
701
-			if (stripos($pg_version, 'rc') !== false)
702
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
747
+			if (stripos($pg_version, 'rc') !== false) {
748
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
749
+			}
703 750
 
704 751
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
705 752
 		}
@@ -718,8 +765,7 @@  discard block
 block discarded – undo
718 765
 					$key_str .= ($count_pk > 0 ? ',' : '');
719 766
 					$key_str .= $columnName;
720 767
 					$count_pk++;
721
-				}
722
-				else //normal field
768
+				} else //normal field
723 769
 				{
724 770
 					$col_str .= ($count > 0 ? ',' : '');
725 771
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -727,20 +773,21 @@  discard block
 block discarded – undo
727 773
 				}
728 774
 			}
729 775
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
730
-		}
731
-		else
776
+		} else
732 777
 		{
733 778
 			foreach ($columns as $columnName => $type)
734 779
 			{
735 780
 				// Are we restricting the length?
736
-				if (strpos($type, 'string-') !== false)
737
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
738
-				else
739
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
781
+				if (strpos($type, 'string-') !== false) {
782
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
783
+				} else {
784
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
785
+				}
740 786
 
741 787
 				// A key? That's what we were looking for.
742
-				if (in_array($columnName, $keys))
743
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
788
+				if (in_array($columnName, $keys)) {
789
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
790
+				}
744 791
 				$count++;
745 792
 			}
746 793
 
@@ -776,10 +823,11 @@  discard block
 block discarded – undo
776 823
 		foreach ($columns as $columnName => $type)
777 824
 		{
778 825
 			// Are we restricting the length?
779
-			if (strpos($type, 'string-') !== false)
780
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
781
-			else
782
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
826
+			if (strpos($type, 'string-') !== false) {
827
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
828
+			} else {
829
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
830
+			}
783 831
 		}
784 832
 		$insertData = substr($insertData, 0, -2) . ')';
785 833
 
@@ -788,8 +836,9 @@  discard block
 block discarded – undo
788 836
 
789 837
 		// Here's where the variables are injected to the query.
790 838
 		$insertRows = array();
791
-		foreach ($data as $dataRow)
792
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
839
+		foreach ($data as $dataRow) {
840
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
841
+		}
793 842
 
794 843
 		// Do the insert.
795 844
 		$request = $smcFunc['db_query']('', '
@@ -806,19 +855,21 @@  discard block
 block discarded – undo
806 855
 
807 856
 		if ($with_returning && $request !== false)
808 857
 		{
809
-			if ($returnmode === 2)
810
-				$return_var = array();
858
+			if ($returnmode === 2) {
859
+							$return_var = array();
860
+			}
811 861
 
812 862
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
813 863
 			{
814
-				if (is_numeric($row[0])) // try to emulate mysql limitation
864
+				if (is_numeric($row[0])) {
865
+					// try to emulate mysql limitation
815 866
 				{
816 867
 					if ($returnmode === 1)
817 868
 						$return_var = $row[0];
818
-					elseif ($returnmode === 2)
819
-						$return_var[] = $row[0];
820
-				}
821
-				else
869
+				} elseif ($returnmode === 2) {
870
+											$return_var[] = $row[0];
871
+					}
872
+				} else
822 873
 				{
823 874
 					$with_returning = false;
824 875
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -827,9 +878,10 @@  discard block
 block discarded – undo
827 878
 		}
828 879
 	}
829 880
 	
830
-	if ($with_returning && !empty($return_var))
831
-		return $return_var; 
832
-}
881
+	if ($with_returning && !empty($return_var)) {
882
+			return $return_var;
883
+	}
884
+	}
833 885
 
834 886
 /**
835 887
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -866,8 +918,9 @@  discard block
 block discarded – undo
866 918
  */
867 919
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
868 920
 {
869
-	if (empty($log_message))
870
-		$log_message = $error_message;
921
+	if (empty($log_message)) {
922
+			$log_message = $error_message;
923
+	}
871 924
 
872 925
 	foreach (debug_backtrace() as $step)
873 926
 	{
@@ -886,12 +939,14 @@  discard block
 block discarded – undo
886 939
 	}
887 940
 
888 941
 	// A special case - we want the file and line numbers for debugging.
889
-	if ($error_type == 'return')
890
-		return array($file, $line);
942
+	if ($error_type == 'return') {
943
+			return array($file, $line);
944
+	}
891 945
 
892 946
 	// Is always a critical error.
893
-	if (function_exists('log_error'))
894
-		log_error($log_message, 'critical', $file, $line);
947
+	if (function_exists('log_error')) {
948
+			log_error($log_message, 'critical', $file, $line);
949
+	}
895 950
 
896 951
 	if (function_exists('fatal_error'))
897 952
 	{
@@ -899,12 +954,12 @@  discard block
 block discarded – undo
899 954
 
900 955
 		// Cannot continue...
901 956
 		exit;
957
+	} elseif ($error_type) {
958
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
959
+	} else {
960
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
961
+	}
902 962
 	}
903
-	elseif ($error_type)
904
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
905
-	else
906
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
907
-}
908 963
 
909 964
 /**
910 965
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -921,10 +976,11 @@  discard block
 block discarded – undo
921 976
 		'\\' => '\\\\',
922 977
 	);
923 978
 
924
-	if ($translate_human_wildcards)
925
-		$replacements += array(
979
+	if ($translate_human_wildcards) {
980
+			$replacements += array(
926 981
 			'*' => '%',
927 982
 		);
983
+	}
928 984
 
929 985
 	return strtr($string, $replacements);
930 986
 }
Please login to merge, or discard this patch.
Sources/DbSearch-postgresql.php 1 patch
Braces   +22 added lines, -16 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Add the file functions to the $smcFunc array.
@@ -23,28 +24,32 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') {
28
+			$smcFunc += array(
28 29
 			'db_search_query' => 'smf_db_search_query',
29 30
 			'db_search_support' => 'smf_db_search_support',
30 31
 			'db_create_word_search' => 'smf_db_create_word_search',
31 32
 			'db_support_ignore' => false,
32 33
 		);
34
+	}
33 35
 
34 36
 	db_extend();
35 37
 
36 38
 	//pg 9.5 got ignore support
37 39
 	$version = $smcFunc['db_get_version']();
38 40
 	// if we got a Beta Version
39
-	if (stripos($version, 'beta') !== false)
40
-		$version = substr($version, 0, stripos($version, 'beta')).'.0';
41
+	if (stripos($version, 'beta') !== false) {
42
+			$version = substr($version, 0, stripos($version, 'beta')).'.0';
43
+	}
41 44
 	// or RC
42
-	if (stripos($version, 'rc') !== false)
43
-		$version = substr($version, 0, stripos($version, 'rc')).'.0';
45
+	if (stripos($version, 'rc') !== false) {
46
+			$version = substr($version, 0, stripos($version, 'rc')).'.0';
47
+	}
44 48
 
45
-	if (version_compare($version,'9.5.0','>='))
46
-		$smcFunc['db_support_ignore'] = true;
47
-}
49
+	if (version_compare($version,'9.5.0','>=')) {
50
+			$smcFunc['db_support_ignore'] = true;
51
+	}
52
+	}
48 53
 
49 54
 /**
50 55
  * This function will tell you whether this database type supports this search type.
@@ -103,16 +108,16 @@  discard block
 block discarded – undo
103 108
 		),
104 109
 	);
105 110
 
106
-	if (isset($replacements[$identifier]))
107
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
111
+	if (isset($replacements[$identifier])) {
112
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
113
+	}
108 114
 	if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0)
109 115
 	{
110 116
 		$db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string);
111 117
 		if ($smcFunc['db_support_ignore']){
112 118
 			//pg style "INSERT INTO.... ON CONFLICT DO NOTHING"
113 119
 			$db_string = $db_string.' ON CONFLICT DO NOTHING';
114
-		}
115
-		else
120
+		} else
116 121
 		{
117 122
 			// Don't error on multi-insert.
118 123
 			$db_values['db_error_skip'] = true;
@@ -120,8 +125,9 @@  discard block
 block discarded – undo
120 125
 	}
121 126
 	
122 127
 	//fix double quotes
123
-	if ($identifier == 'insert_into_log_messages_fulltext')
124
-		$db_values = str_replace('"', "'", $db_values);
128
+	if ($identifier == 'insert_into_log_messages_fulltext') {
129
+			$db_values = str_replace('"', "'", $db_values);
130
+	}
125 131
 
126 132
 	$return = $smcFunc['db_query']('', $db_string,
127 133
 		$db_values, $connection
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +870 added lines, -637 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
 $upcontext['inactive_timeout'] = 10;
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
84
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
85 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 88
 require_once($upgrade_path . '/upgrade-helper.php');
88 89
 
@@ -106,11 +107,14 @@  discard block
 block discarded – undo
106 107
 	ini_set('default_socket_timeout', 900);
107 108
 }
108 109
 // Clean the upgrade path if this is from the client.
109
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
110
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
110
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
111
+	for ($i = 1;
112
+}
113
+$i < $_SERVER['argc']; $i++)
111 114
 	{
112
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
113
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
115
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
116
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
117
+		}
114 118
 	}
115 119
 
116 120
 // Are we from the client?
@@ -118,16 +122,17 @@  discard block
 block discarded – undo
118 122
 {
119 123
 	$command_line = true;
120 124
 	$disable_security = true;
121
-}
122
-else
125
+} else {
123 126
 	$command_line = false;
127
+}
124 128
 
125 129
 // Load this now just because we can.
126 130
 require_once($upgrade_path . '/Settings.php');
127 131
 
128 132
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
129
-if (isset($language))
133
+if (isset($language)) {
130 134
 	$language = str_ireplace('-utf8', '', $language);
135
+}
131 136
 
132 137
 // Are we logged in?
133 138
 if (isset($upgradeData))
@@ -135,10 +140,12 @@  discard block
 block discarded – undo
135 140
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
136 141
 
137 142
 	// Check for sensible values.
138
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
139
-		$upcontext['user']['started'] = time();
140
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
141
-		$upcontext['user']['updated'] = 0;
143
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
144
+			$upcontext['user']['started'] = time();
145
+	}
146
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
147
+			$upcontext['user']['updated'] = 0;
148
+	}
142 149
 
143 150
 	$upcontext['started'] = $upcontext['user']['started'];
144 151
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -196,8 +203,9 @@  discard block
 block discarded – undo
196 203
 			'db_error_skip' => true,
197 204
 		)
198 205
 	);
199
-	while ($row = $smcFunc['db_fetch_assoc']($request))
200
-		$modSettings[$row['variable']] = $row['value'];
206
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
207
+			$modSettings[$row['variable']] = $row['value'];
208
+	}
201 209
 	$smcFunc['db_free_result']($request);
202 210
 }
203 211
 
@@ -207,10 +215,12 @@  discard block
 block discarded – undo
207 215
 	$modSettings['theme_url'] = 'Themes/default';
208 216
 	$modSettings['images_url'] = 'Themes/default/images';
209 217
 }
210
-if (!isset($settings['default_theme_url']))
218
+if (!isset($settings['default_theme_url'])) {
211 219
 	$settings['default_theme_url'] = $modSettings['theme_url'];
212
-if (!isset($settings['default_theme_dir']))
220
+}
221
+if (!isset($settings['default_theme_dir'])) {
213 222
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
223
+}
214 224
 
215 225
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
216 226
 // Default title...
@@ -228,13 +238,15 @@  discard block
 block discarded – undo
228 238
 	$support_js = $upcontext['upgrade_status']['js'];
229 239
 
230 240
 	// Only set this if the upgrader status says so.
231
-	if (empty($is_debug))
232
-		$is_debug = $upcontext['upgrade_status']['debug'];
241
+	if (empty($is_debug)) {
242
+			$is_debug = $upcontext['upgrade_status']['debug'];
243
+	}
233 244
 
234 245
 	// Load the language.
235
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
236
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
237
-}
246
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
247
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
248
+	}
249
+	}
238 250
 // Set the defaults.
239 251
 else
240 252
 {
@@ -252,15 +264,18 @@  discard block
 block discarded – undo
252 264
 }
253 265
 
254 266
 // If this isn't the first stage see whether they are logging in and resuming.
255
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
267
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
256 268
 	checkLogin();
269
+}
257 270
 
258
-if ($command_line)
271
+if ($command_line) {
259 272
 	cmdStep0();
273
+}
260 274
 
261 275
 // Don't error if we're using xml.
262
-if (isset($_GET['xml']))
276
+if (isset($_GET['xml'])) {
263 277
 	$upcontext['return_error'] = true;
278
+}
264 279
 
265 280
 // Loop through all the steps doing each one as required.
266 281
 $upcontext['overall_percent'] = 0;
@@ -281,10 +296,11 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 
283 298
 		// Call the step and if it returns false that means pause!
284
-		if (function_exists($step[2]) && $step[2]() === false)
285
-			break;
286
-		elseif (function_exists($step[2]))
287
-			$upcontext['current_step']++;
299
+		if (function_exists($step[2]) && $step[2]() === false) {
300
+					break;
301
+		} elseif (function_exists($step[2])) {
302
+					$upcontext['current_step']++;
303
+		}
288 304
 	}
289 305
 	$upcontext['overall_percent'] += $step[3];
290 306
 }
@@ -323,17 +339,18 @@  discard block
 block discarded – undo
323 339
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 340
 		if (!empty($command_line))
325 341
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
342
+			if (function_exists('debug_print_backtrace')) {
343
+							debug_print_backtrace();
344
+			}
328 345
 
329 346
 			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 347
 			flush();
331 348
 			die();
332 349
 		}
333 350
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
351
+		if (!isset($_GET['xml'])) {
352
+					template_upgrade_above();
353
+		} else
337 354
 		{
338 355
 			header('Content-Type: text/xml; charset=UTF-8');
339 356
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,21 +372,24 @@  discard block
 block discarded – undo
355 372
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 373
 
357 374
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
375
+			if (!empty($upcontext['query_string'])) {
376
+							$upcontext['form_url'] .= $upcontext['query_string'];
377
+			}
360 378
 
361 379
 			call_user_func('template_' . $upcontext['sub_template']);
362 380
 		}
363 381
 
364 382
 		// Was there an error?
365
-		if (!empty($upcontext['forced_error_message']))
366
-			echo $upcontext['forced_error_message'];
383
+		if (!empty($upcontext['forced_error_message'])) {
384
+					echo $upcontext['forced_error_message'];
385
+		}
367 386
 
368 387
 		// Show the footer.
369
-		if (!isset($_GET['xml']))
370
-			template_upgrade_below();
371
-		else
372
-			template_xml_below();
388
+		if (!isset($_GET['xml'])) {
389
+					template_upgrade_below();
390
+		} else {
391
+					template_xml_below();
392
+		}
373 393
 	}
374 394
 
375 395
 
@@ -381,15 +401,19 @@  discard block
 block discarded – undo
381 401
 		$seconds = intval($active % 60);
382 402
 
383 403
 		$totalTime = '';
384
-		if ($hours > 0)
385
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
386
-		if ($minutes > 0)
387
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
388
-		if ($seconds > 0)
389
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
404
+		if ($hours > 0) {
405
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
406
+		}
407
+		if ($minutes > 0) {
408
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
409
+		}
410
+		if ($seconds > 0) {
411
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
412
+		}
390 413
 
391
-		if (!empty($totalTime))
392
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
414
+		if (!empty($totalTime)) {
415
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		}
393 417
 	}
394 418
 
395 419
 	// Bang - gone!
@@ -402,8 +426,9 @@  discard block
 block discarded – undo
402 426
 	global $upgradeurl, $upcontext, $command_line;
403 427
 
404 428
 	// Command line users can't be redirected.
405
-	if ($command_line)
406
-		upgradeExit(true);
429
+	if ($command_line) {
430
+			upgradeExit(true);
431
+	}
407 432
 
408 433
 	// Are we providing the core info?
409 434
 	if ($addForm)
@@ -426,19 +451,22 @@  discard block
 block discarded – undo
426 451
 	global $modSettings, $sourcedir, $smcFunc;
427 452
 
428 453
 	// Do the non-SSI stuff...
429
-	if (function_exists('set_magic_quotes_runtime'))
430
-		@set_magic_quotes_runtime(0);
454
+	if (function_exists('set_magic_quotes_runtime')) {
455
+			@set_magic_quotes_runtime(0);
456
+	}
431 457
 
432 458
 	error_reporting(E_ALL);
433 459
 	define('SMF', 1);
434 460
 
435 461
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
462
+	if (@ini_get('session.save_handler') == 'user') {
463
+			@ini_set('session.save_handler', 'files');
464
+	}
438 465
 	@session_start();
439 466
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
467
+	if (empty($smcFunc)) {
468
+			$smcFunc = array();
469
+	}
442 470
 
443 471
 	// We need this for authentication and some upgrade code
444 472
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -450,8 +478,9 @@  discard block
 block discarded – undo
450 478
 	initialize_inputs();
451 479
 
452 480
 	// Get the database going!
453
-	if (empty($db_type) || $db_type == 'mysqli')
454
-		$db_type = 'mysql';
481
+	if (empty($db_type) || $db_type == 'mysqli') {
482
+			$db_type = 'mysql';
483
+	}
455 484
 
456 485
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
457 486
 	{
@@ -461,17 +490,19 @@  discard block
 block discarded – undo
461 490
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
462 491
 
463 492
 		// Oh dear god!!
464
-		if ($db_connection === null)
465
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
493
+		if ($db_connection === null) {
494
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		}
466 496
 
467
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
468
-			$smcFunc['db_query']('', '
497
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
498
+					$smcFunc['db_query']('', '
469 499
 			SET NAMES {string:db_character_set}',
470 500
 			array(
471 501
 				'db_error_skip' => true,
472 502
 				'db_character_set' => $db_character_set,
473 503
 			)
474 504
 		);
505
+		}
475 506
 
476 507
 		// Load the modSettings data...
477 508
 		$request = $smcFunc['db_query']('', '
@@ -482,11 +513,11 @@  discard block
 block discarded – undo
482 513
 			)
483 514
 		);
484 515
 		$modSettings = array();
485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
486
-			$modSettings[$row['variable']] = $row['value'];
516
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
517
+					$modSettings[$row['variable']] = $row['value'];
518
+		}
487 519
 		$smcFunc['db_free_result']($request);
488
-	}
489
-	else
520
+	} else
490 521
 	{
491 522
 		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.');
492 523
 	}
@@ -500,9 +531,10 @@  discard block
 block discarded – undo
500 531
 		cleanRequest();
501 532
 	}
502 533
 
503
-	if (!isset($_GET['substep']))
504
-		$_GET['substep'] = 0;
505
-}
534
+	if (!isset($_GET['substep'])) {
535
+			$_GET['substep'] = 0;
536
+	}
537
+	}
506 538
 
507 539
 function initialize_inputs()
508 540
 {
@@ -532,8 +564,9 @@  discard block
 block discarded – undo
532 564
 		$dh = opendir(dirname(__FILE__));
533 565
 		while ($file = readdir($dh))
534 566
 		{
535
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
536
-				@unlink(dirname(__FILE__) . '/' . $file);
567
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
568
+							@unlink(dirname(__FILE__) . '/' . $file);
569
+			}
537 570
 		}
538 571
 		closedir($dh);
539 572
 
@@ -563,8 +596,9 @@  discard block
 block discarded – undo
563 596
 	{
564 597
 		$upcontext['remote_files_available'] = false;
565 598
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
566
-		if ($test)
567
-			$upcontext['remote_files_available'] = true;
599
+		if ($test) {
600
+					$upcontext['remote_files_available'] = true;
601
+		}
568 602
 		@fclose($test);
569 603
 	}
570 604
 
@@ -572,8 +606,9 @@  discard block
 block discarded – undo
572 606
 	$temp = 'upgrade_php?step';
573 607
 	while (strlen($temp) > 4)
574 608
 	{
575
-		if (isset($_GET[$temp]))
576
-			unset($_GET[$temp]);
609
+		if (isset($_GET[$temp])) {
610
+					unset($_GET[$temp]);
611
+		}
577 612
 		$temp = substr($temp, 1);
578 613
 	}
579 614
 
@@ -600,32 +635,39 @@  discard block
 block discarded – undo
600 635
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
601 636
 
602 637
 	// Need legacy scripts?
603
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
604
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
605
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
606
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
607
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
608
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
638
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
639
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
640
+	}
641
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
642
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
643
+	}
644
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
645
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
646
+	}
609 647
 
610 648
 	// We don't need "-utf8" files anymore...
611 649
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
612 650
 
613 651
 	// This needs to exist!
614
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
615
-		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>]');
616
-	else
617
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
652
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
653
+			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>]');
654
+	} else {
655
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
656
+	}
618 657
 
619
-	if (!$check)
620
-		// 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.
658
+	if (!$check) {
659
+			// 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.
621 660
 		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.');
661
+	}
622 662
 
623 663
 	// Do they meet the install requirements?
624
-	if (!php_version_check())
625
-		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.');
664
+	if (!php_version_check()) {
665
+			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.');
666
+	}
626 667
 
627
-	if (!db_version_check())
628
-		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.');
668
+	if (!db_version_check()) {
669
+			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.');
670
+	}
629 671
 
630 672
 	// Do some checks to make sure they have proper privileges
631 673
 	db_extend('packages');
@@ -640,14 +682,16 @@  discard block
 block discarded – undo
640 682
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
641 683
 
642 684
 	// Sorry... we need CREATE, ALTER and DROP
643
-	if (!$create || !$alter || !$drop)
644
-		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.');
685
+	if (!$create || !$alter || !$drop) {
686
+			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.');
687
+	}
645 688
 
646 689
 	// Do a quick version spot check.
647 690
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
648 691
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
649
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
650
-		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.');
692
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
693
+			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.');
694
+	}
651 695
 
652 696
 	// What absolutely needs to be writable?
653 697
 	$writable_files = array(
@@ -669,12 +713,13 @@  discard block
 block discarded – undo
669 713
 	quickFileWritable($custom_av_dir);
670 714
 
671 715
 	// Are we good now?
672
-	if (!is_writable($custom_av_dir))
673
-		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));
674
-	elseif ($need_settings_update)
716
+	if (!is_writable($custom_av_dir)) {
717
+			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));
718
+	} elseif ($need_settings_update)
675 719
 	{
676
-		if (!function_exists('cache_put_data'))
677
-			require_once($sourcedir . '/Load.php');
720
+		if (!function_exists('cache_put_data')) {
721
+					require_once($sourcedir . '/Load.php');
722
+		}
678 723
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
679 724
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
680 725
 	}
@@ -683,28 +728,33 @@  discard block
 block discarded – undo
683 728
 
684 729
 	// Check the cache directory.
685 730
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
686
-	if (!file_exists($cachedir_temp))
687
-		@mkdir($cachedir_temp);
688
-	if (!file_exists($cachedir_temp))
689
-		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.');
690
-
691
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
692
-		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>.');
693
-	elseif (!isset($_GET['skiplang']))
731
+	if (!file_exists($cachedir_temp)) {
732
+			@mkdir($cachedir_temp);
733
+	}
734
+	if (!file_exists($cachedir_temp)) {
735
+			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.');
736
+	}
737
+
738
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
739
+			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>.');
740
+	} elseif (!isset($_GET['skiplang']))
694 741
 	{
695 742
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
696 743
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
697 744
 
698
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
699
-			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>]');
745
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
746
+					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>]');
747
+		}
700 748
 	}
701 749
 
702
-	if (!makeFilesWritable($writable_files))
703
-		return false;
750
+	if (!makeFilesWritable($writable_files)) {
751
+			return false;
752
+	}
704 753
 
705 754
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
706
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
707
-		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.');
755
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
756
+			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.');
757
+	}
708 758
 
709 759
 	// Upgrade the agreement.
710 760
 	elseif (isset($modSettings['agreement']))
@@ -715,8 +765,8 @@  discard block
 block discarded – undo
715 765
 	}
716 766
 
717 767
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
718
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
719
-		$upcontext['warning'] = '
768
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
769
+			$upcontext['warning'] = '
720 770
 			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>
721 771
 			<ul>
722 772
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -724,10 +774,12 @@  discard block
 block discarded – undo
724 774
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
725 775
 			</ul>
726 776
 			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="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
777
+	}
727 778
 
728 779
 	// Either we're logged in or we're going to present the login.
729
-	if (checkLogin())
730
-		return true;
780
+	if (checkLogin()) {
781
+			return true;
782
+	}
731 783
 
732 784
 	$upcontext += createToken('login');
733 785
 
@@ -741,15 +793,17 @@  discard block
 block discarded – undo
741 793
 	global $smcFunc, $db_type, $support_js;
742 794
 
743 795
 	// Don't bother if the security is disabled.
744
-	if ($disable_security)
745
-		return true;
796
+	if ($disable_security) {
797
+			return true;
798
+	}
746 799
 
747 800
 	// Are we trying to login?
748 801
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
749 802
 	{
750 803
 		// If we've disabled security pick a suitable name!
751
-		if (empty($_POST['user']))
752
-			$_POST['user'] = 'Administrator';
804
+		if (empty($_POST['user'])) {
805
+					$_POST['user'] = 'Administrator';
806
+		}
753 807
 
754 808
 		// Before 2.0 these column names were different!
755 809
 		$oldDB = false;
@@ -764,16 +818,17 @@  discard block
 block discarded – undo
764 818
 					'db_error_skip' => true,
765 819
 				)
766 820
 			);
767
-			if ($smcFunc['db_num_rows']($request) != 0)
768
-				$oldDB = true;
821
+			if ($smcFunc['db_num_rows']($request) != 0) {
822
+							$oldDB = true;
823
+			}
769 824
 			$smcFunc['db_free_result']($request);
770 825
 		}
771 826
 
772 827
 		// Get what we believe to be their details.
773 828
 		if (!$disable_security)
774 829
 		{
775
-			if ($oldDB)
776
-				$request = $smcFunc['db_query']('', '
830
+			if ($oldDB) {
831
+							$request = $smcFunc['db_query']('', '
777 832
 					SELECT id_member, memberName AS member_name, passwd, id_group,
778 833
 					additionalGroups AS additional_groups, lngfile
779 834
 					FROM {db_prefix}members
@@ -783,8 +838,8 @@  discard block
 block discarded – undo
783 838
 						'db_error_skip' => true,
784 839
 					)
785 840
 				);
786
-			else
787
-				$request = $smcFunc['db_query']('', '
841
+			} else {
842
+							$request = $smcFunc['db_query']('', '
788 843
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
789 844
 					FROM {db_prefix}members
790 845
 					WHERE member_name = {string:member_name}',
@@ -793,6 +848,7 @@  discard block
 block discarded – undo
793 848
 						'db_error_skip' => true,
794 849
 					)
795 850
 				);
851
+			}
796 852
 			if ($smcFunc['db_num_rows']($request) != 0)
797 853
 			{
798 854
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -800,16 +856,17 @@  discard block
 block discarded – undo
800 856
 				$groups = explode(',', $addGroups);
801 857
 				$groups[] = $id_group;
802 858
 
803
-				foreach ($groups as $k => $v)
804
-					$groups[$k] = (int) $v;
859
+				foreach ($groups as $k => $v) {
860
+									$groups[$k] = (int) $v;
861
+				}
805 862
 
806 863
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
807 864
 
808 865
 				// We don't use "-utf8" anymore...
809 866
 				$user_language = str_ireplace('-utf8', '', $user_language);
867
+			} else {
868
+							$upcontext['username_incorrect'] = true;
810 869
 			}
811
-			else
812
-				$upcontext['username_incorrect'] = true;
813 870
 			$smcFunc['db_free_result']($request);
814 871
 		}
815 872
 		$upcontext['username'] = $_POST['user'];
@@ -819,13 +876,14 @@  discard block
 block discarded – undo
819 876
 		{
820 877
 			$upcontext['upgrade_status']['js'] = 1;
821 878
 			$support_js = 1;
879
+		} else {
880
+					$support_js = 0;
822 881
 		}
823
-		else
824
-			$support_js = 0;
825 882
 
826 883
 		// Note down the version we are coming from.
827
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
828
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
884
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
885
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
886
+		}
829 887
 
830 888
 		// Didn't get anywhere?
831 889
 		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']))
@@ -859,15 +917,15 @@  discard block
 block discarded – undo
859 917
 							'db_error_skip' => true,
860 918
 						)
861 919
 					);
862
-					if ($smcFunc['db_num_rows']($request) == 0)
863
-						return throw_error('You need to be an admin to perform an upgrade!');
920
+					if ($smcFunc['db_num_rows']($request) == 0) {
921
+											return throw_error('You need to be an admin to perform an upgrade!');
922
+					}
864 923
 					$smcFunc['db_free_result']($request);
865 924
 				}
866 925
 
867 926
 				$upcontext['user']['id'] = $id_member;
868 927
 				$upcontext['user']['name'] = $name;
869
-			}
870
-			else
928
+			} else
871 929
 			{
872 930
 				$upcontext['user']['id'] = 1;
873 931
 				$upcontext['user']['name'] = 'Administrator';
@@ -883,11 +941,11 @@  discard block
 block discarded – undo
883 941
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
884 942
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
885 943
 
886
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
887
-					$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'] . '.';
888
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
889
-					$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'] . '.';
890
-				else
944
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
945
+									$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'] . '.';
946
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
947
+									$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'] . '.';
948
+				} else
891 949
 				{
892 950
 					// Set this as the new language.
893 951
 					$upcontext['language'] = $user_language;
@@ -931,8 +989,9 @@  discard block
 block discarded – undo
931 989
 	unset($member_columns);
932 990
 
933 991
 	// If we've not submitted then we're done.
934
-	if (empty($_POST['upcont']))
935
-		return false;
992
+	if (empty($_POST['upcont'])) {
993
+			return false;
994
+	}
936 995
 
937 996
 	// Firstly, if they're enabling SM stat collection just do it.
938 997
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -947,25 +1006,26 @@  discard block
 block discarded – undo
947 1006
 			fwrite($fp, $out);
948 1007
 
949 1008
 			$return_data = '';
950
-			while (!feof($fp))
951
-				$return_data .= fgets($fp, 128);
1009
+			while (!feof($fp)) {
1010
+							$return_data .= fgets($fp, 128);
1011
+			}
952 1012
 
953 1013
 			fclose($fp);
954 1014
 
955 1015
 			// Get the unique site ID.
956 1016
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
957 1017
 
958
-			if (!empty($ID[1]))
959
-				$smcFunc['db_insert']('replace',
1018
+			if (!empty($ID[1])) {
1019
+							$smcFunc['db_insert']('replace',
960 1020
 					$db_prefix . 'settings',
961 1021
 					array('variable' => 'string', 'value' => 'string'),
962 1022
 					array('allow_sm_stats', $ID[1]),
963 1023
 					array('variable')
964 1024
 				);
1025
+			}
965 1026
 		}
966
-	}
967
-	else
968
-		$smcFunc['db_query']('', '
1027
+	} else {
1028
+			$smcFunc['db_query']('', '
969 1029
 			DELETE FROM {db_prefix}settings
970 1030
 			WHERE variable = {string:allow_sm_stats}',
971 1031
 			array(
@@ -973,6 +1033,7 @@  discard block
 block discarded – undo
973 1033
 				'db_error_skip' => true,
974 1034
 			)
975 1035
 		);
1036
+	}
976 1037
 
977 1038
 	// Deleting old karma stuff?
978 1039
 	if (!empty($_POST['delete_karma']))
@@ -987,20 +1048,22 @@  discard block
 block discarded – undo
987 1048
 		);
988 1049
 
989 1050
 		// Cleaning up old karma member settings.
990
-		if ($upcontext['karma_installed']['good'])
991
-			$smcFunc['db_query']('', '
1051
+		if ($upcontext['karma_installed']['good']) {
1052
+					$smcFunc['db_query']('', '
992 1053
 				ALTER TABLE {db_prefix}members
993 1054
 				DROP karma_good',
994 1055
 				array()
995 1056
 			);
1057
+		}
996 1058
 
997 1059
 		// Does karma bad was enable?
998
-		if ($upcontext['karma_installed']['bad'])
999
-			$smcFunc['db_query']('', '
1060
+		if ($upcontext['karma_installed']['bad']) {
1061
+					$smcFunc['db_query']('', '
1000 1062
 				ALTER TABLE {db_prefix}members
1001 1063
 				DROP karma_bad',
1002 1064
 				array()
1003 1065
 			);
1066
+		}
1004 1067
 
1005 1068
 		// Cleaning up old karma permissions.
1006 1069
 		$smcFunc['db_query']('', '
@@ -1013,26 +1076,29 @@  discard block
 block discarded – undo
1013 1076
 	}
1014 1077
 
1015 1078
 	// Emptying the error log?
1016
-	if (!empty($_POST['empty_error']))
1017
-		$smcFunc['db_query']('truncate_table', '
1079
+	if (!empty($_POST['empty_error'])) {
1080
+			$smcFunc['db_query']('truncate_table', '
1018 1081
 			TRUNCATE {db_prefix}log_errors',
1019 1082
 			array(
1020 1083
 			)
1021 1084
 		);
1085
+	}
1022 1086
 
1023 1087
 	$changes = array();
1024 1088
 
1025 1089
 	// Add proxy settings.
1026
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1027
-		$changes += array(
1090
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1091
+			$changes += array(
1028 1092
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1029 1093
 			'image_proxy_maxsize' => 5190,
1030 1094
 			'image_proxy_enabled' => 0,
1031 1095
 		);
1096
+	}
1032 1097
 
1033 1098
 	// If we're overriding the language follow it through.
1034
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1035
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1099
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1100
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1101
+	}
1036 1102
 
1037 1103
 	if (!empty($_POST['maint']))
1038 1104
 	{
@@ -1044,30 +1110,34 @@  discard block
 block discarded – undo
1044 1110
 		{
1045 1111
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1046 1112
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1047
-		}
1048
-		else
1113
+		} else
1049 1114
 		{
1050 1115
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1051 1116
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1052 1117
 		}
1053 1118
 	}
1054 1119
 
1055
-	if ($command_line)
1056
-		echo ' * Updating Settings.php...';
1120
+	if ($command_line) {
1121
+			echo ' * Updating Settings.php...';
1122
+	}
1057 1123
 
1058 1124
 	// Fix some old paths.
1059
-	if (substr($boarddir, 0, 1) == '.')
1060
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1125
+	if (substr($boarddir, 0, 1) == '.') {
1126
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1127
+	}
1061 1128
 
1062
-	if (substr($sourcedir, 0, 1) == '.')
1063
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1129
+	if (substr($sourcedir, 0, 1) == '.') {
1130
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1131
+	}
1064 1132
 
1065
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1066
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1133
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1134
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1135
+	}
1067 1136
 
1068 1137
 	// Not had the database type added before?
1069
-	if (empty($db_type))
1070
-		$changes['db_type'] = 'mysql';
1138
+	if (empty($db_type)) {
1139
+			$changes['db_type'] = 'mysql';
1140
+	}
1071 1141
 
1072 1142
 	// If they have a "host:port" setup for the host, split that into separate values
1073 1143
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1078,32 +1148,36 @@  discard block
 block discarded – undo
1078 1148
 		$changes['db_server'] = '\'' . $db_server . '\'';
1079 1149
 
1080 1150
 		// Only set this if we're not using the default port
1081
-		if ($db_port != ini_get('mysqli.default_port'))
1082
-			$changes['db_port'] = (int) $db_port;
1083
-	}
1084
-	elseif (!empty($db_port))
1151
+		if ($db_port != ini_get('mysqli.default_port')) {
1152
+					$changes['db_port'] = (int) $db_port;
1153
+		}
1154
+	} elseif (!empty($db_port))
1085 1155
 	{
1086 1156
 		// If db_port is set and is the same as the default, set it to ''
1087 1157
 		if ($db_type == 'mysql')
1088 1158
 		{
1089
-			if ($db_port == ini_get('mysqli.default_port'))
1090
-				$changes['db_port'] = '\'\'';
1091
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1092
-				$changes['db_port'] = '\'\'';
1159
+			if ($db_port == ini_get('mysqli.default_port')) {
1160
+							$changes['db_port'] = '\'\'';
1161
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1162
+							$changes['db_port'] = '\'\'';
1163
+			}
1093 1164
 		}
1094 1165
 	}
1095 1166
 
1096 1167
 	// Maybe we haven't had this option yet?
1097
-	if (empty($packagesdir))
1098
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1168
+	if (empty($packagesdir)) {
1169
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1170
+	}
1099 1171
 
1100 1172
 	// Add support for $tasksdir var.
1101
-	if (empty($tasksdir))
1102
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1173
+	if (empty($tasksdir)) {
1174
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1175
+	}
1103 1176
 
1104 1177
 	// Make sure we fix the language as well.
1105
-	if (stristr($language, '-utf8'))
1106
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1178
+	if (stristr($language, '-utf8')) {
1179
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1180
+	}
1107 1181
 
1108 1182
 	// @todo Maybe change the cookie name if going to 1.1, too?
1109 1183
 
@@ -1111,8 +1185,9 @@  discard block
 block discarded – undo
1111 1185
 	require_once($sourcedir . '/Subs-Admin.php');
1112 1186
 	updateSettingsFile($changes);
1113 1187
 
1114
-	if ($command_line)
1115
-		echo ' Successful.' . "\n";
1188
+	if ($command_line) {
1189
+			echo ' Successful.' . "\n";
1190
+	}
1116 1191
 
1117 1192
 	// Are we doing debug?
1118 1193
 	if (isset($_POST['debug']))
@@ -1122,8 +1197,9 @@  discard block
 block discarded – undo
1122 1197
 	}
1123 1198
 
1124 1199
 	// If we're not backing up then jump one.
1125
-	if (empty($_POST['backup']))
1126
-		$upcontext['current_step']++;
1200
+	if (empty($_POST['backup'])) {
1201
+			$upcontext['current_step']++;
1202
+	}
1127 1203
 
1128 1204
 	// If we've got here then let's proceed to the next step!
1129 1205
 	return true;
@@ -1138,8 +1214,9 @@  discard block
 block discarded – undo
1138 1214
 	$upcontext['page_title'] = 'Backup Database';
1139 1215
 
1140 1216
 	// Done it already - js wise?
1141
-	if (!empty($_POST['backup_done']))
1142
-		return true;
1217
+	if (!empty($_POST['backup_done'])) {
1218
+			return true;
1219
+	}
1143 1220
 
1144 1221
 	// Some useful stuff here.
1145 1222
 	db_extend();
@@ -1153,9 +1230,10 @@  discard block
 block discarded – undo
1153 1230
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1154 1231
 
1155 1232
 	$table_names = array();
1156
-	foreach ($tables as $table)
1157
-		if (substr($table, 0, 7) !== 'backup_')
1233
+	foreach ($tables as $table) {
1234
+			if (substr($table, 0, 7) !== 'backup_')
1158 1235
 			$table_names[] = $table;
1236
+	}
1159 1237
 
1160 1238
 	$upcontext['table_count'] = count($table_names);
1161 1239
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1165,12 +1243,14 @@  discard block
 block discarded – undo
1165 1243
 	$file_steps = $upcontext['table_count'];
1166 1244
 
1167 1245
 	// What ones have we already done?
1168
-	foreach ($table_names as $id => $table)
1169
-		if ($id < $_GET['substep'])
1246
+	foreach ($table_names as $id => $table) {
1247
+			if ($id < $_GET['substep'])
1170 1248
 			$upcontext['previous_tables'][] = $table;
1249
+	}
1171 1250
 
1172
-	if ($command_line)
1173
-		echo 'Backing Up Tables.';
1251
+	if ($command_line) {
1252
+			echo 'Backing Up Tables.';
1253
+	}
1174 1254
 
1175 1255
 	// If we don't support javascript we backup here.
1176 1256
 	if (!$support_js || isset($_GET['xml']))
@@ -1189,8 +1269,9 @@  discard block
 block discarded – undo
1189 1269
 			backupTable($table_names[$substep]);
1190 1270
 
1191 1271
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1192
-			if (isset($_GET['xml']))
1193
-				return upgradeExit();
1272
+			if (isset($_GET['xml'])) {
1273
+							return upgradeExit();
1274
+			}
1194 1275
 		}
1195 1276
 
1196 1277
 		if ($command_line)
@@ -1223,9 +1304,10 @@  discard block
 block discarded – undo
1223 1304
 
1224 1305
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1225 1306
 
1226
-	if ($command_line)
1227
-		echo ' done.';
1228
-}
1307
+	if ($command_line) {
1308
+			echo ' done.';
1309
+	}
1310
+	}
1229 1311
 
1230 1312
 // Step 2: Everything.
1231 1313
 function DatabaseChanges()
@@ -1234,8 +1316,9 @@  discard block
 block discarded – undo
1234 1316
 	global $upcontext, $support_js, $db_type;
1235 1317
 
1236 1318
 	// Have we just completed this?
1237
-	if (!empty($_POST['database_done']))
1238
-		return true;
1319
+	if (!empty($_POST['database_done'])) {
1320
+			return true;
1321
+	}
1239 1322
 
1240 1323
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1241 1324
 	$upcontext['page_title'] = 'Database Changes';
@@ -1250,15 +1333,16 @@  discard block
 block discarded – undo
1250 1333
 	);
1251 1334
 
1252 1335
 	// How many files are there in total?
1253
-	if (isset($_GET['filecount']))
1254
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1255
-	else
1336
+	if (isset($_GET['filecount'])) {
1337
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1338
+	} else
1256 1339
 	{
1257 1340
 		$upcontext['file_count'] = 0;
1258 1341
 		foreach ($files as $file)
1259 1342
 		{
1260
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1261
-				$upcontext['file_count']++;
1343
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1344
+							$upcontext['file_count']++;
1345
+			}
1262 1346
 		}
1263 1347
 	}
1264 1348
 
@@ -1268,9 +1352,9 @@  discard block
 block discarded – undo
1268 1352
 	$upcontext['cur_file_num'] = 0;
1269 1353
 	foreach ($files as $file)
1270 1354
 	{
1271
-		if ($did_not_do)
1272
-			$did_not_do--;
1273
-		else
1355
+		if ($did_not_do) {
1356
+					$did_not_do--;
1357
+		} else
1274 1358
 		{
1275 1359
 			$upcontext['cur_file_num']++;
1276 1360
 			$upcontext['cur_file_name'] = $file[0];
@@ -1297,12 +1381,13 @@  discard block
 block discarded – undo
1297 1381
 					// Flag to move on to the next.
1298 1382
 					$upcontext['completed_step'] = true;
1299 1383
 					// Did we complete the whole file?
1300
-					if ($nextFile)
1301
-						$upcontext['current_debug_item_num'] = -1;
1384
+					if ($nextFile) {
1385
+											$upcontext['current_debug_item_num'] = -1;
1386
+					}
1302 1387
 					return upgradeExit();
1388
+				} elseif ($support_js) {
1389
+									break;
1303 1390
 				}
1304
-				elseif ($support_js)
1305
-					break;
1306 1391
 			}
1307 1392
 			// Set the progress bar to be right as if we had - even if we hadn't...
1308 1393
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1327,8 +1412,9 @@  discard block
 block discarded – undo
1327 1412
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1328 1413
 
1329 1414
 	// Now it's nice to have some of the basic SMF source files.
1330
-	if (!isset($_GET['ssi']) && !$command_line)
1331
-		redirectLocation('&ssi=1');
1415
+	if (!isset($_GET['ssi']) && !$command_line) {
1416
+			redirectLocation('&ssi=1');
1417
+	}
1332 1418
 
1333 1419
 	$upcontext['sub_template'] = 'upgrade_complete';
1334 1420
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1344,14 +1430,16 @@  discard block
 block discarded – undo
1344 1430
 	// Are we in maintenance mode?
1345 1431
 	if (isset($upcontext['user']['main']))
1346 1432
 	{
1347
-		if ($command_line)
1348
-			echo ' * ';
1433
+		if ($command_line) {
1434
+					echo ' * ';
1435
+		}
1349 1436
 		$upcontext['removed_maintenance'] = true;
1350 1437
 		$changes['maintenance'] = $upcontext['user']['main'];
1351 1438
 	}
1352 1439
 	// Otherwise if somehow we are in 2 let's go to 1.
1353
-	elseif (!empty($maintenance) && $maintenance == 2)
1354
-		$changes['maintenance'] = 1;
1440
+	elseif (!empty($maintenance) && $maintenance == 2) {
1441
+			$changes['maintenance'] = 1;
1442
+	}
1355 1443
 
1356 1444
 	// Wipe this out...
1357 1445
 	$upcontext['user'] = array();
@@ -1366,9 +1454,9 @@  discard block
 block discarded – undo
1366 1454
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1367 1455
 
1368 1456
 	// Now is the perfect time to fetch the SM files.
1369
-	if ($command_line)
1370
-		cli_scheduled_fetchSMfiles();
1371
-	else
1457
+	if ($command_line) {
1458
+			cli_scheduled_fetchSMfiles();
1459
+	} else
1372 1460
 	{
1373 1461
 		require_once($sourcedir . '/ScheduledTasks.php');
1374 1462
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1376,8 +1464,9 @@  discard block
 block discarded – undo
1376 1464
 	}
1377 1465
 
1378 1466
 	// Log what we've done.
1379
-	if (empty($user_info['id']))
1380
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1467
+	if (empty($user_info['id'])) {
1468
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1469
+	}
1381 1470
 
1382 1471
 	// Log the action manually, so CLI still works.
1383 1472
 	$smcFunc['db_insert']('',
@@ -1396,8 +1485,9 @@  discard block
 block discarded – undo
1396 1485
 
1397 1486
 	// Save the current database version.
1398 1487
 	$server_version = $smcFunc['db_server_info']();
1399
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1400
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1488
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1489
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1490
+	}
1401 1491
 
1402 1492
 	if ($command_line)
1403 1493
 	{
@@ -1409,8 +1499,9 @@  discard block
 block discarded – undo
1409 1499
 
1410 1500
 	// Make sure it says we're done.
1411 1501
 	$upcontext['overall_percent'] = 100;
1412
-	if (isset($upcontext['step_progress']))
1413
-		unset($upcontext['step_progress']);
1502
+	if (isset($upcontext['step_progress'])) {
1503
+			unset($upcontext['step_progress']);
1504
+	}
1414 1505
 
1415 1506
 	$_GET['substep'] = 0;
1416 1507
 	return false;
@@ -1421,8 +1512,9 @@  discard block
 block discarded – undo
1421 1512
 {
1422 1513
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1423 1514
 
1424
-	if (empty($modSettings['time_format']))
1425
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1515
+	if (empty($modSettings['time_format'])) {
1516
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1517
+	}
1426 1518
 
1427 1519
 	// What files do we want to get
1428 1520
 	$request = $smcFunc['db_query']('', '
@@ -1456,8 +1548,9 @@  discard block
 block discarded – undo
1456 1548
 		$file_data = fetch_web_data($url);
1457 1549
 
1458 1550
 		// If we got an error - give up - the site might be down.
1459
-		if ($file_data === false)
1460
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1551
+		if ($file_data === false) {
1552
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1553
+		}
1461 1554
 
1462 1555
 		// Save the file to the database.
1463 1556
 		$smcFunc['db_query']('substring', '
@@ -1499,8 +1592,9 @@  discard block
 block discarded – undo
1499 1592
 	$themeData = array();
1500 1593
 	foreach ($values as $variable => $value)
1501 1594
 	{
1502
-		if (!isset($value) || $value === null)
1503
-			$value = 0;
1595
+		if (!isset($value) || $value === null) {
1596
+					$value = 0;
1597
+		}
1504 1598
 
1505 1599
 		$themeData[] = array(0, 1, $variable, $value);
1506 1600
 	}
@@ -1529,8 +1623,9 @@  discard block
 block discarded – undo
1529 1623
 
1530 1624
 	foreach ($values as $variable => $value)
1531 1625
 	{
1532
-		if (empty($modSettings[$value[0]]))
1533
-			continue;
1626
+		if (empty($modSettings[$value[0]])) {
1627
+					continue;
1628
+		}
1534 1629
 
1535 1630
 		$smcFunc['db_query']('', '
1536 1631
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1616,10 +1711,11 @@  discard block
 block discarded – undo
1616 1711
 	set_error_handler(
1617 1712
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1618 1713
 		{
1619
-			if ($support_js)
1620
-				return true;
1621
-			else
1622
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1714
+			if ($support_js) {
1715
+							return true;
1716
+			} else {
1717
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1718
+			}
1623 1719
 		}
1624 1720
 	);
1625 1721
 
@@ -1634,8 +1730,9 @@  discard block
 block discarded – undo
1634 1730
 				'db_error_skip' => true,
1635 1731
 			)
1636 1732
 		);
1637
-		if ($smcFunc['db_num_rows']($request) === 0)
1638
-			die('Unable to find members table!');
1733
+		if ($smcFunc['db_num_rows']($request) === 0) {
1734
+					die('Unable to find members table!');
1735
+		}
1639 1736
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1640 1737
 		$smcFunc['db_free_result']($request);
1641 1738
 
@@ -1650,17 +1747,20 @@  discard block
 block discarded – undo
1650 1747
 				)
1651 1748
 			);
1652 1749
 			// Got something?
1653
-			if ($smcFunc['db_num_rows']($request) !== 0)
1654
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1750
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1751
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1752
+			}
1655 1753
 			$smcFunc['db_free_result']($request);
1656 1754
 
1657 1755
 			// Excellent!
1658
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1659
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1756
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1757
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1758
+			}
1660 1759
 		}
1661 1760
 	}
1662
-	if (empty($db_collation))
1663
-		$db_collation = '';
1761
+	if (empty($db_collation)) {
1762
+			$db_collation = '';
1763
+	}
1664 1764
 
1665 1765
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1666 1766
 
@@ -1672,8 +1772,9 @@  discard block
 block discarded – undo
1672 1772
 	$last_step = '';
1673 1773
 
1674 1774
 	// Make sure all newly created tables will have the proper characters set.
1675
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1676
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1775
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1776
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1777
+	}
1677 1778
 
1678 1779
 	// Count the total number of steps within this file - for progress.
1679 1780
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1693,15 +1794,18 @@  discard block
 block discarded – undo
1693 1794
 		$do_current = $substep >= $_GET['substep'];
1694 1795
 
1695 1796
 		// Get rid of any comments in the beginning of the line...
1696
-		if (substr(trim($line), 0, 2) === '/*')
1697
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1797
+		if (substr(trim($line), 0, 2) === '/*') {
1798
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1799
+		}
1698 1800
 
1699 1801
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1700
-		if ($is_debug && !$support_js && $command_line)
1701
-			flush();
1802
+		if ($is_debug && !$support_js && $command_line) {
1803
+					flush();
1804
+		}
1702 1805
 
1703
-		if (trim($line) === '')
1704
-			continue;
1806
+		if (trim($line) === '') {
1807
+					continue;
1808
+		}
1705 1809
 
1706 1810
 		if (trim(substr($line, 0, 3)) === '---')
1707 1811
 		{
@@ -1711,8 +1815,9 @@  discard block
 block discarded – undo
1711 1815
 			if (trim($current_data) != '' && $type !== '}')
1712 1816
 			{
1713 1817
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1714
-				if ($command_line)
1715
-					echo $upcontext['error_message'];
1818
+				if ($command_line) {
1819
+									echo $upcontext['error_message'];
1820
+				}
1716 1821
 			}
1717 1822
 
1718 1823
 			if ($type == ' ')
@@ -1730,17 +1835,18 @@  discard block
 block discarded – undo
1730 1835
 				if ($do_current)
1731 1836
 				{
1732 1837
 					$upcontext['actioned_items'][] = $last_step;
1733
-					if ($command_line)
1734
-						echo ' * ';
1838
+					if ($command_line) {
1839
+											echo ' * ';
1840
+					}
1735 1841
 				}
1736
-			}
1737
-			elseif ($type == '#')
1842
+			} elseif ($type == '#')
1738 1843
 			{
1739 1844
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1740 1845
 
1741 1846
 				$upcontext['current_debug_item_num']++;
1742
-				if (trim($line) != '---#')
1743
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1847
+				if (trim($line) != '---#') {
1848
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1849
+				}
1744 1850
 
1745 1851
 				// Have we already done something?
1746 1852
 				if (isset($_GET['xml']) && $done_something)
@@ -1751,34 +1857,36 @@  discard block
 block discarded – undo
1751 1857
 
1752 1858
 				if ($do_current)
1753 1859
 				{
1754
-					if (trim($line) == '---#' && $command_line)
1755
-						echo ' done.', $endl;
1756
-					elseif ($command_line)
1757
-						echo ' +++ ', rtrim(substr($line, 4));
1758
-					elseif (trim($line) != '---#')
1860
+					if (trim($line) == '---#' && $command_line) {
1861
+											echo ' done.', $endl;
1862
+					} elseif ($command_line) {
1863
+											echo ' +++ ', rtrim(substr($line, 4));
1864
+					} elseif (trim($line) != '---#')
1759 1865
 					{
1760
-						if ($is_debug)
1761
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1866
+						if ($is_debug) {
1867
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1868
+						}
1762 1869
 					}
1763 1870
 				}
1764 1871
 
1765 1872
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1766 1873
 				{
1767
-					if ($command_line)
1768
-						echo ' * ';
1769
-					else
1770
-						$upcontext['actioned_items'][] = $last_step;
1874
+					if ($command_line) {
1875
+											echo ' * ';
1876
+					} else {
1877
+											$upcontext['actioned_items'][] = $last_step;
1878
+					}
1771 1879
 				}
1772 1880
 
1773 1881
 				// Small step - only if we're actually doing stuff.
1774
-				if ($do_current)
1775
-					nextSubstep(++$substep);
1776
-				else
1777
-					$substep++;
1778
-			}
1779
-			elseif ($type == '{')
1780
-				$current_type = 'code';
1781
-			elseif ($type == '}')
1882
+				if ($do_current) {
1883
+									nextSubstep(++$substep);
1884
+				} else {
1885
+									$substep++;
1886
+				}
1887
+			} elseif ($type == '{') {
1888
+							$current_type = 'code';
1889
+			} elseif ($type == '}')
1782 1890
 			{
1783 1891
 				$current_type = 'sql';
1784 1892
 
@@ -1791,8 +1899,9 @@  discard block
 block discarded – undo
1791 1899
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1792 1900
 				{
1793 1901
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1794
-					if ($command_line)
1795
-						echo $upcontext['error_message'];
1902
+					if ($command_line) {
1903
+											echo $upcontext['error_message'];
1904
+					}
1796 1905
 				}
1797 1906
 
1798 1907
 				// Done with code!
@@ -1872,8 +1981,9 @@  discard block
 block discarded – undo
1872 1981
 	$db_unbuffered = false;
1873 1982
 
1874 1983
 	// Failure?!
1875
-	if ($result !== false)
1876
-		return $result;
1984
+	if ($result !== false) {
1985
+			return $result;
1986
+	}
1877 1987
 
1878 1988
 	$db_error_message = $smcFunc['db_error']($db_connection);
1879 1989
 	// If MySQL we do something more clever.
@@ -1901,54 +2011,61 @@  discard block
 block discarded – undo
1901 2011
 			{
1902 2012
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1903 2013
 				$result = mysqli_query($db_connection, $string);
1904
-				if ($result !== false)
1905
-					return $result;
2014
+				if ($result !== false) {
2015
+									return $result;
2016
+				}
1906 2017
 			}
1907
-		}
1908
-		elseif ($mysqli_errno == 2013)
2018
+		} elseif ($mysqli_errno == 2013)
1909 2019
 		{
1910 2020
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1911 2021
 			mysqli_select_db($db_connection, $db_name);
1912 2022
 			if ($db_connection)
1913 2023
 			{
1914 2024
 				$result = mysqli_query($db_connection, $string);
1915
-				if ($result !== false)
1916
-					return $result;
2025
+				if ($result !== false) {
2026
+									return $result;
2027
+				}
1917 2028
 			}
1918 2029
 		}
1919 2030
 		// Duplicate column name... should be okay ;).
1920
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1921
-			return false;
2031
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2032
+					return false;
2033
+		}
1922 2034
 		// Duplicate insert... make sure it's the proper type of query ;).
1923
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1924
-			return false;
2035
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2036
+					return false;
2037
+		}
1925 2038
 		// Creating an index on a non-existent column.
1926
-		elseif ($mysqli_errno == 1072)
1927
-			return false;
1928
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1929
-			return false;
2039
+		elseif ($mysqli_errno == 1072) {
2040
+					return false;
2041
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2042
+					return false;
2043
+		}
1930 2044
 	}
1931 2045
 	// If a table already exists don't go potty.
1932 2046
 	else
1933 2047
 	{
1934 2048
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1935 2049
 		{
1936
-			if (strpos($db_error_message, 'exist') !== false)
1937
-				return true;
1938
-		}
1939
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2050
+			if (strpos($db_error_message, 'exist') !== false) {
2051
+							return true;
2052
+			}
2053
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1940 2054
 		{
1941
-			if (strpos($db_error_message, 'duplicate') !== false)
1942
-				return true;
2055
+			if (strpos($db_error_message, 'duplicate') !== false) {
2056
+							return true;
2057
+			}
1943 2058
 		}
1944 2059
 	}
1945 2060
 
1946 2061
 	// Get the query string so we pass everything.
1947 2062
 	$query_string = '';
1948
-	foreach ($_GET as $k => $v)
1949
-		$query_string .= ';' . $k . '=' . $v;
1950
-	if (strlen($query_string) != 0)
1951
-		$query_string = '?' . substr($query_string, 1);
2063
+	foreach ($_GET as $k => $v) {
2064
+			$query_string .= ';' . $k . '=' . $v;
2065
+	}
2066
+	if (strlen($query_string) != 0) {
2067
+			$query_string = '?' . substr($query_string, 1);
2068
+	}
1952 2069
 
1953 2070
 	if ($command_line)
1954 2071
 	{
@@ -2003,16 +2120,18 @@  discard block
 block discarded – undo
2003 2120
 			{
2004 2121
 				$found |= 1;
2005 2122
 				// Do some checks on the data if we have it set.
2006
-				if (isset($change['col_type']))
2007
-					$found &= $change['col_type'] === $column['type'];
2008
-				if (isset($change['null_allowed']))
2009
-					$found &= $column['null'] == $change['null_allowed'];
2010
-				if (isset($change['default']))
2011
-					$found &= $change['default'] === $column['default'];
2123
+				if (isset($change['col_type'])) {
2124
+									$found &= $change['col_type'] === $column['type'];
2125
+				}
2126
+				if (isset($change['null_allowed'])) {
2127
+									$found &= $column['null'] == $change['null_allowed'];
2128
+				}
2129
+				if (isset($change['default'])) {
2130
+									$found &= $change['default'] === $column['default'];
2131
+				}
2012 2132
 			}
2013 2133
 		}
2014
-	}
2015
-	elseif ($change['type'] === 'index')
2134
+	} elseif ($change['type'] === 'index')
2016 2135
 	{
2017 2136
 		$request = upgrade_query('
2018 2137
 			SHOW INDEX
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 		{
2022 2141
 			$cur_index = array();
2023 2142
 
2024
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2025
-				if ($row['Key_name'] === $change['name'])
2143
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2144
+							if ($row['Key_name'] === $change['name'])
2026 2145
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2146
+			}
2027 2147
 
2028 2148
 			ksort($cur_index, SORT_NUMERIC);
2029 2149
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2033,14 +2153,17 @@  discard block
 block discarded – undo
2033 2153
 	}
2034 2154
 
2035 2155
 	// If we're trying to add and it's added, we're done.
2036
-	if ($found && in_array($change['method'], array('add', 'change')))
2037
-		return true;
2156
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2157
+			return true;
2158
+	}
2038 2159
 	// Otherwise if we're removing and it wasn't found we're also done.
2039
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2040
-		return true;
2160
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2161
+			return true;
2162
+	}
2041 2163
 	// Otherwise is it just a test?
2042
-	elseif ($is_test)
2043
-		return false;
2164
+	elseif ($is_test) {
2165
+			return false;
2166
+	}
2044 2167
 
2045 2168
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2046 2169
 	$running = false;
@@ -2051,8 +2174,9 @@  discard block
 block discarded – undo
2051 2174
 			SHOW FULL PROCESSLIST');
2052 2175
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2053 2176
 		{
2054
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2055
-				$found = true;
2177
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2178
+							$found = true;
2179
+			}
2056 2180
 		}
2057 2181
 
2058 2182
 		// Can't find it? Then we need to run it fools!
@@ -2064,8 +2188,9 @@  discard block
 block discarded – undo
2064 2188
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2065 2189
 				' . $change['text'], true) !== false;
2066 2190
 
2067
-			if (!$success)
2068
-				return false;
2191
+			if (!$success) {
2192
+							return false;
2193
+			}
2069 2194
 
2070 2195
 			// Return
2071 2196
 			$running = true;
@@ -2107,8 +2232,9 @@  discard block
 block discarded – undo
2107 2232
 			'db_error_skip' => true,
2108 2233
 		)
2109 2234
 	);
2110
-	if ($smcFunc['db_num_rows']($request) === 0)
2111
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2235
+	if ($smcFunc['db_num_rows']($request) === 0) {
2236
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2237
+	}
2112 2238
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2113 2239
 	$smcFunc['db_free_result']($request);
2114 2240
 
@@ -2130,18 +2256,19 @@  discard block
 block discarded – undo
2130 2256
 			)
2131 2257
 		);
2132 2258
 		// No results? Just forget it all together.
2133
-		if ($smcFunc['db_num_rows']($request) === 0)
2134
-			unset($table_row['Collation']);
2135
-		else
2136
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2259
+		if ($smcFunc['db_num_rows']($request) === 0) {
2260
+					unset($table_row['Collation']);
2261
+		} else {
2262
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2263
+		}
2137 2264
 		$smcFunc['db_free_result']($request);
2138 2265
 	}
2139 2266
 
2140 2267
 	if ($column_fix)
2141 2268
 	{
2142 2269
 		// Make sure there are no NULL's left.
2143
-		if ($null_fix)
2144
-			$smcFunc['db_query']('', '
2270
+		if ($null_fix) {
2271
+					$smcFunc['db_query']('', '
2145 2272
 				UPDATE {db_prefix}' . $change['table'] . '
2146 2273
 				SET ' . $change['column'] . ' = {string:default}
2147 2274
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2150,6 +2277,7 @@  discard block
 block discarded – undo
2150 2277
 					'db_error_skip' => true,
2151 2278
 				)
2152 2279
 			);
2280
+		}
2153 2281
 
2154 2282
 		// Do the actual alteration.
2155 2283
 		$smcFunc['db_query']('', '
@@ -2178,8 +2306,9 @@  discard block
 block discarded – undo
2178 2306
 	}
2179 2307
 
2180 2308
 	// Not a column we need to check on?
2181
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2182
-		return;
2309
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2310
+			return;
2311
+	}
2183 2312
 
2184 2313
 	// Break it up you (six|seven).
2185 2314
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2198,13 +2327,13 @@  discard block
 block discarded – undo
2198 2327
 				'new_name' => $temp[2],
2199 2328
 		));
2200 2329
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2201
-		if ($smcFunc['db_num_rows'] != 1)
2202
-			return;
2330
+		if ($smcFunc['db_num_rows'] != 1) {
2331
+					return;
2332
+		}
2203 2333
 
2204 2334
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2205 2335
 		$smcFunc['db_free_result']($request);
2206
-	}
2207
-	else
2336
+	} else
2208 2337
 	{
2209 2338
 		// Do this the old fashion, sure method way.
2210 2339
 		$request = $smcFunc['db_query']('', '
@@ -2215,21 +2344,24 @@  discard block
 block discarded – undo
2215 2344
 		));
2216 2345
 		// Mayday!
2217 2346
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2218
-		if ($smcFunc['db_num_rows'] == 0)
2219
-			return;
2347
+		if ($smcFunc['db_num_rows'] == 0) {
2348
+					return;
2349
+		}
2220 2350
 
2221 2351
 		// Oh where, oh where has my little field gone. Oh where can it be...
2222
-		while ($row = $smcFunc['db_query']($request))
2223
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2352
+		while ($row = $smcFunc['db_query']($request)) {
2353
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2224 2354
 			{
2225 2355
 				$current_type = $row['Type'];
2356
+		}
2226 2357
 				break;
2227 2358
 			}
2228 2359
 	}
2229 2360
 
2230 2361
 	// If this doesn't match, the column may of been altered for a reason.
2231
-	if (trim($current_type) != trim($temp[3]))
2232
-		$temp[3] = $current_type;
2362
+	if (trim($current_type) != trim($temp[3])) {
2363
+			$temp[3] = $current_type;
2364
+	}
2233 2365
 
2234 2366
 	// Piece this back together.
2235 2367
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2241,8 +2373,9 @@  discard block
 block discarded – undo
2241 2373
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2242 2374
 	global $step_progress, $is_debug, $upcontext;
2243 2375
 
2244
-	if ($_GET['substep'] < $substep)
2245
-		$_GET['substep'] = $substep;
2376
+	if ($_GET['substep'] < $substep) {
2377
+			$_GET['substep'] = $substep;
2378
+	}
2246 2379
 
2247 2380
 	if ($command_line)
2248 2381
 	{
@@ -2255,29 +2388,33 @@  discard block
 block discarded – undo
2255 2388
 	}
2256 2389
 
2257 2390
 	@set_time_limit(300);
2258
-	if (function_exists('apache_reset_timeout'))
2259
-		@apache_reset_timeout();
2391
+	if (function_exists('apache_reset_timeout')) {
2392
+			@apache_reset_timeout();
2393
+	}
2260 2394
 
2261
-	if (time() - $start_time <= $timeLimitThreshold)
2262
-		return;
2395
+	if (time() - $start_time <= $timeLimitThreshold) {
2396
+			return;
2397
+	}
2263 2398
 
2264 2399
 	// Do we have some custom step progress stuff?
2265 2400
 	if (!empty($step_progress))
2266 2401
 	{
2267 2402
 		$upcontext['substep_progress'] = 0;
2268 2403
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2269
-		if ($step_progress['current'] > $step_progress['total'])
2270
-			$upcontext['substep_progress'] = 99.9;
2271
-		else
2272
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2404
+		if ($step_progress['current'] > $step_progress['total']) {
2405
+					$upcontext['substep_progress'] = 99.9;
2406
+		} else {
2407
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2408
+		}
2273 2409
 
2274 2410
 		// Make it nicely rounded.
2275 2411
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2276 2412
 	}
2277 2413
 
2278 2414
 	// If this is XML we just exit right away!
2279
-	if (isset($_GET['xml']))
2280
-		return upgradeExit();
2415
+	if (isset($_GET['xml'])) {
2416
+			return upgradeExit();
2417
+	}
2281 2418
 
2282 2419
 	// We're going to pause after this!
2283 2420
 	$upcontext['pause'] = true;
@@ -2285,13 +2422,15 @@  discard block
 block discarded – undo
2285 2422
 	$upcontext['query_string'] = '';
2286 2423
 	foreach ($_GET as $k => $v)
2287 2424
 	{
2288
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2289
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2425
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2426
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2427
+		}
2290 2428
 	}
2291 2429
 
2292 2430
 	// Custom warning?
2293
-	if (!empty($custom_warning))
2294
-		$upcontext['custom_warning'] = $custom_warning;
2431
+	if (!empty($custom_warning)) {
2432
+			$upcontext['custom_warning'] = $custom_warning;
2433
+	}
2295 2434
 
2296 2435
 	upgradeExit();
2297 2436
 }
@@ -2306,25 +2445,26 @@  discard block
 block discarded – undo
2306 2445
 	ob_implicit_flush(true);
2307 2446
 	@set_time_limit(600);
2308 2447
 
2309
-	if (!isset($_SERVER['argv']))
2310
-		$_SERVER['argv'] = array();
2448
+	if (!isset($_SERVER['argv'])) {
2449
+			$_SERVER['argv'] = array();
2450
+	}
2311 2451
 	$_GET['maint'] = 1;
2312 2452
 
2313 2453
 	foreach ($_SERVER['argv'] as $i => $arg)
2314 2454
 	{
2315
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2316
-			$_GET['lang'] = $match[1];
2317
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2318
-			continue;
2319
-		elseif ($arg == '--no-maintenance')
2320
-			$_GET['maint'] = 0;
2321
-		elseif ($arg == '--debug')
2322
-			$is_debug = true;
2323
-		elseif ($arg == '--backup')
2324
-			$_POST['backup'] = 1;
2325
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2326
-			$_GET['conv'] = 1;
2327
-		elseif ($i != 0)
2455
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2456
+					$_GET['lang'] = $match[1];
2457
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2458
+					continue;
2459
+		} elseif ($arg == '--no-maintenance') {
2460
+					$_GET['maint'] = 0;
2461
+		} elseif ($arg == '--debug') {
2462
+					$is_debug = true;
2463
+		} elseif ($arg == '--backup') {
2464
+					$_POST['backup'] = 1;
2465
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2466
+					$_GET['conv'] = 1;
2467
+		} elseif ($i != 0)
2328 2468
 		{
2329 2469
 			echo 'SMF Command-line Upgrader
2330 2470
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2338,10 +2478,12 @@  discard block
 block discarded – undo
2338 2478
 		}
2339 2479
 	}
2340 2480
 
2341
-	if (!php_version_check())
2342
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2343
-	if (!db_version_check())
2344
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2481
+	if (!php_version_check()) {
2482
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2483
+	}
2484
+	if (!db_version_check()) {
2485
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2486
+	}
2345 2487
 
2346 2488
 	// Do some checks to make sure they have proper privileges
2347 2489
 	db_extend('packages');
@@ -2356,34 +2498,39 @@  discard block
 block discarded – undo
2356 2498
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2357 2499
 
2358 2500
 	// Sorry... we need CREATE, ALTER and DROP
2359
-	if (!$create || !$alter || !$drop)
2360
-		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);
2501
+	if (!$create || !$alter || !$drop) {
2502
+			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);
2503
+	}
2361 2504
 
2362 2505
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2363 2506
 		&& @file_exists($sourcedir . '/QueryString.php')
2364 2507
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2365
-	if (!$check && !isset($modSettings['smfVersion']))
2366
-		print_error('Error: Some files are missing or out-of-date.', true);
2508
+	if (!$check && !isset($modSettings['smfVersion'])) {
2509
+			print_error('Error: Some files are missing or out-of-date.', true);
2510
+	}
2367 2511
 
2368 2512
 	// Do a quick version spot check.
2369 2513
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2370 2514
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2371
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2372
-		print_error('Error: Some files have not yet been updated properly.');
2515
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2516
+			print_error('Error: Some files have not yet been updated properly.');
2517
+	}
2373 2518
 
2374 2519
 	// Make sure Settings.php is writable.
2375 2520
 		quickFileWritable($boarddir . '/Settings.php');
2376
-	if (!is_writable($boarddir . '/Settings.php'))
2377
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2521
+	if (!is_writable($boarddir . '/Settings.php')) {
2522
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2523
+	}
2378 2524
 
2379 2525
 	// Make sure Settings_bak.php is writable.
2380 2526
 		quickFileWritable($boarddir . '/Settings_bak.php');
2381
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2382
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2527
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2528
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2529
+	}
2383 2530
 
2384
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2385
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2386
-	elseif (isset($modSettings['agreement']))
2531
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2532
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2533
+	} elseif (isset($modSettings['agreement']))
2387 2534
 	{
2388 2535
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2389 2536
 		fwrite($fp, $modSettings['agreement']);
@@ -2393,31 +2540,36 @@  discard block
 block discarded – undo
2393 2540
 	// Make sure Themes is writable.
2394 2541
 	quickFileWritable($modSettings['theme_dir']);
2395 2542
 
2396
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2397
-		print_error('Error: Unable to obtain write access to "Themes".');
2543
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2544
+			print_error('Error: Unable to obtain write access to "Themes".');
2545
+	}
2398 2546
 
2399 2547
 	// Make sure cache directory exists and is writable!
2400 2548
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2401
-	if (!file_exists($cachedir_temp))
2402
-		@mkdir($cachedir_temp);
2549
+	if (!file_exists($cachedir_temp)) {
2550
+			@mkdir($cachedir_temp);
2551
+	}
2403 2552
 
2404 2553
 	// Make sure the cache temp dir is writable.
2405 2554
 	quickFileWritable($cachedir_temp);
2406 2555
 
2407
-	if (!is_writable($cachedir_temp))
2408
-		print_error('Error: Unable to obtain write access to "cache".', true);
2556
+	if (!is_writable($cachedir_temp)) {
2557
+			print_error('Error: Unable to obtain write access to "cache".', true);
2558
+	}
2409 2559
 
2410
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2411
-		print_error('Error: Unable to find language files!', true);
2412
-	else
2560
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2561
+			print_error('Error: Unable to find language files!', true);
2562
+	} else
2413 2563
 	{
2414 2564
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2415 2565
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2416 2566
 
2417
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2418
-			print_error('Error: Language files out of date.', true);
2419
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2420
-			print_error('Error: Install language is missing for selected language.', true);
2567
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2568
+					print_error('Error: Language files out of date.', true);
2569
+		}
2570
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2571
+					print_error('Error: Install language is missing for selected language.', true);
2572
+		}
2421 2573
 
2422 2574
 		// Otherwise include it!
2423 2575
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2446,8 +2598,7 @@  discard block
 block discarded – undo
2446 2598
 		);
2447 2599
 
2448 2600
 		return true;
2449
-	}
2450
-	else
2601
+	} else
2451 2602
 	{
2452 2603
 		$upcontext['page_title'] = 'Converting to UTF8';
2453 2604
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2491,8 +2642,9 @@  discard block
 block discarded – undo
2491 2642
 			)
2492 2643
 		);
2493 2644
 		$db_charsets = array();
2494
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2495
-			$db_charsets[] = $row['Charset'];
2645
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2646
+					$db_charsets[] = $row['Charset'];
2647
+		}
2496 2648
 
2497 2649
 		$smcFunc['db_free_result']($request);
2498 2650
 
@@ -2528,13 +2680,15 @@  discard block
 block discarded – undo
2528 2680
 		// If there's a fulltext index, we need to drop it first...
2529 2681
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2530 2682
 		{
2531
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2532
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2683
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2684
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2533 2685
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2686
+			}
2534 2687
 			$smcFunc['db_free_result']($request);
2535 2688
 
2536
-			if (isset($upcontext['fulltext_index']))
2537
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2689
+			if (isset($upcontext['fulltext_index'])) {
2690
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2691
+			}
2538 2692
 		}
2539 2693
 
2540 2694
 		// Drop it and make a note...
@@ -2724,8 +2878,9 @@  discard block
 block discarded – undo
2724 2878
 			$replace = '%field%';
2725 2879
 
2726 2880
 			// Build a huge REPLACE statement...
2727
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2728
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2881
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2882
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2883
+			}
2729 2884
 		}
2730 2885
 
2731 2886
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2759,8 +2914,9 @@  discard block
 block discarded – undo
2759 2914
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2760 2915
 
2761 2916
 			// Just to make sure it doesn't time out.
2762
-			if (function_exists('apache_reset_timeout'))
2763
-				@apache_reset_timeout();
2917
+			if (function_exists('apache_reset_timeout')) {
2918
+							@apache_reset_timeout();
2919
+			}
2764 2920
 
2765 2921
 			$table_charsets = array();
2766 2922
 
@@ -2781,8 +2937,9 @@  discard block
 block discarded – undo
2781 2937
 					{
2782 2938
 						list($charset) = explode('_', $collation);
2783 2939
 
2784
-						if (!isset($table_charsets[$charset]))
2785
-							$table_charsets[$charset] = array();
2940
+						if (!isset($table_charsets[$charset])) {
2941
+													$table_charsets[$charset] = array();
2942
+						}
2786 2943
 
2787 2944
 						$table_charsets[$charset][] = $column_info;
2788 2945
 					}
@@ -2822,10 +2979,11 @@  discard block
 block discarded – undo
2822 2979
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2823 2980
 				{
2824 2981
 					$update = '';
2825
-					foreach ($table_charsets as $charset => $columns)
2826
-						foreach ($columns as $column)
2982
+					foreach ($table_charsets as $charset => $columns) {
2983
+											foreach ($columns as $column)
2827 2984
 							$update .= '
2828 2985
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2986
+					}
2829 2987
 
2830 2988
 					$smcFunc['db_query']('', '
2831 2989
 						UPDATE {raw:table_name}
@@ -2850,8 +3008,9 @@  discard block
 block discarded – undo
2850 3008
 			// Now do the actual conversion (if still needed).
2851 3009
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2852 3010
 			{
2853
-				if ($command_line)
2854
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3011
+				if ($command_line) {
3012
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3013
+				}
2855 3014
 
2856 3015
 				$smcFunc['db_query']('', '
2857 3016
 					ALTER TABLE {raw:table_name}
@@ -2861,8 +3020,9 @@  discard block
 block discarded – undo
2861 3020
 					)
2862 3021
 				);
2863 3022
 
2864
-				if ($command_line)
2865
-					echo " done.\n";
3023
+				if ($command_line) {
3024
+									echo " done.\n";
3025
+				}
2866 3026
 			}
2867 3027
 		}
2868 3028
 
@@ -2892,8 +3052,8 @@  discard block
 block discarded – undo
2892 3052
 		);
2893 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2894 3054
 		{
2895
-			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)
2896
-				$smcFunc['db_query']('', '
3055
+			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) {
3056
+							$smcFunc['db_query']('', '
2897 3057
 					UPDATE {db_prefix}log_actions
2898 3058
 					SET extra = {string:extra}
2899 3059
 					WHERE id_action = {int:current_action}',
@@ -2902,6 +3062,7 @@  discard block
 block discarded – undo
2902 3062
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2903 3063
 					)
2904 3064
 				);
3065
+			}
2905 3066
 		}
2906 3067
 		$smcFunc['db_free_result']($request);
2907 3068
 
@@ -2923,15 +3084,17 @@  discard block
 block discarded – undo
2923 3084
 	// First thing's first - did we already do this?
2924 3085
 	if (!empty($modSettings['json_done']))
2925 3086
 	{
2926
-		if ($command_line)
2927
-			return DeleteUpgrade();
2928
-		else
2929
-			return true;
3087
+		if ($command_line) {
3088
+					return DeleteUpgrade();
3089
+		} else {
3090
+					return true;
3091
+		}
2930 3092
 	}
2931 3093
 
2932 3094
 	// Done it already - js wise?
2933
-	if (!empty($_POST['json_done']))
2934
-		return true;
3095
+	if (!empty($_POST['json_done'])) {
3096
+			return true;
3097
+	}
2935 3098
 
2936 3099
 	// List of tables affected by this function
2937 3100
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2963,12 +3126,14 @@  discard block
 block discarded – undo
2963 3126
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2964 3127
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2965 3128
 
2966
-	foreach ($keys as $id => $table)
2967
-		if ($id < $_GET['substep'])
3129
+	foreach ($keys as $id => $table) {
3130
+			if ($id < $_GET['substep'])
2968 3131
 			$upcontext['previous_tables'][] = $table;
3132
+	}
2969 3133
 
2970
-	if ($command_line)
2971
-		echo 'Converting data from serialize() to json_encode().';
3134
+	if ($command_line) {
3135
+			echo 'Converting data from serialize() to json_encode().';
3136
+	}
2972 3137
 
2973 3138
 	if (!$support_js || isset($_GET['xml']))
2974 3139
 	{
@@ -3008,8 +3173,9 @@  discard block
 block discarded – undo
3008 3173
 
3009 3174
 				// Loop through and fix these...
3010 3175
 				$new_settings = array();
3011
-				if ($command_line)
3012
-					echo "\n" . 'Fixing some settings...';
3176
+				if ($command_line) {
3177
+									echo "\n" . 'Fixing some settings...';
3178
+				}
3013 3179
 
3014 3180
 				foreach ($serialized_settings as $var)
3015 3181
 				{
@@ -3017,22 +3183,24 @@  discard block
 block discarded – undo
3017 3183
 					{
3018 3184
 						// Attempt to unserialize the setting
3019 3185
 						$temp = @safe_unserialize($modSettings[$var]);
3020
-						if (!$temp && $command_line)
3021
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3022
-						elseif ($temp !== false)
3023
-							$new_settings[$var] = json_encode($temp);
3186
+						if (!$temp && $command_line) {
3187
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3188
+						} elseif ($temp !== false) {
3189
+													$new_settings[$var] = json_encode($temp);
3190
+						}
3024 3191
 					}
3025 3192
 				}
3026 3193
 
3027 3194
 				// Update everything at once
3028
-				if (!function_exists('cache_put_data'))
3029
-					require_once($sourcedir . '/Load.php');
3195
+				if (!function_exists('cache_put_data')) {
3196
+									require_once($sourcedir . '/Load.php');
3197
+				}
3030 3198
 				updateSettings($new_settings, true);
3031 3199
 
3032
-				if ($command_line)
3033
-					echo ' done.';
3034
-			}
3035
-			elseif ($table == 'themes')
3200
+				if ($command_line) {
3201
+									echo ' done.';
3202
+				}
3203
+			} elseif ($table == 'themes')
3036 3204
 			{
3037 3205
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3038 3206
 				$query = $smcFunc['db_query']('', '
@@ -3051,10 +3219,11 @@  discard block
 block discarded – undo
3051 3219
 
3052 3220
 						if ($command_line)
3053 3221
 						{
3054
-							if ($temp === false)
3055
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3056
-							else
3057
-								echo "\n" . 'Fixing admin preferences...';
3222
+							if ($temp === false) {
3223
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3224
+							} else {
3225
+															echo "\n" . 'Fixing admin preferences...';
3226
+							}
3058 3227
 						}
3059 3228
 
3060 3229
 						if ($temp !== false)
@@ -3076,15 +3245,15 @@  discard block
 block discarded – undo
3076 3245
 								)
3077 3246
 							);
3078 3247
 
3079
-							if ($command_line)
3080
-								echo ' done.';
3248
+							if ($command_line) {
3249
+															echo ' done.';
3250
+							}
3081 3251
 						}
3082 3252
 					}
3083 3253
 
3084 3254
 					$smcFunc['db_free_result']($query);
3085 3255
 				}
3086
-			}
3087
-			else
3256
+			} else
3088 3257
 			{
3089 3258
 				// First item is always the key...
3090 3259
 				$key = $info[0];
@@ -3095,8 +3264,7 @@  discard block
 block discarded – undo
3095 3264
 				{
3096 3265
 					$col_select = $info[1];
3097 3266
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3098
-				}
3099
-				else
3267
+				} else
3100 3268
 				{
3101 3269
 					$col_select = implode(', ', $info);
3102 3270
 				}
@@ -3129,8 +3297,7 @@  discard block
 block discarded – undo
3129 3297
 								if ($temp === false && $command_line)
3130 3298
 								{
3131 3299
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3132
-								}
3133
-								else
3300
+								} else
3134 3301
 								{
3135 3302
 									$row[$col] = json_encode($temp);
3136 3303
 
@@ -3155,16 +3322,18 @@  discard block
 block discarded – undo
3155 3322
 						}
3156 3323
 					}
3157 3324
 
3158
-					if ($command_line)
3159
-						echo ' done.';
3325
+					if ($command_line) {
3326
+											echo ' done.';
3327
+					}
3160 3328
 
3161 3329
 					// Free up some memory...
3162 3330
 					$smcFunc['db_free_result']($query);
3163 3331
 				}
3164 3332
 			}
3165 3333
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3166
-			if (isset($_GET['xml']))
3167
-				return upgradeExit();
3334
+			if (isset($_GET['xml'])) {
3335
+							return upgradeExit();
3336
+			}
3168 3337
 		}
3169 3338
 
3170 3339
 		if ($command_line)
@@ -3179,8 +3348,9 @@  discard block
 block discarded – undo
3179 3348
 
3180 3349
 		$_GET['substep'] = 0;
3181 3350
 		// Make sure we move on!
3182
-		if ($command_line)
3183
-			return DeleteUpgrade();
3351
+		if ($command_line) {
3352
+					return DeleteUpgrade();
3353
+		}
3184 3354
 
3185 3355
 		return true;
3186 3356
 	}
@@ -3200,14 +3370,16 @@  discard block
 block discarded – undo
3200 3370
 	global $upcontext, $txt, $settings;
3201 3371
 
3202 3372
 	// Don't call me twice!
3203
-	if (!empty($upcontext['chmod_called']))
3204
-		return;
3373
+	if (!empty($upcontext['chmod_called'])) {
3374
+			return;
3375
+	}
3205 3376
 
3206 3377
 	$upcontext['chmod_called'] = true;
3207 3378
 
3208 3379
 	// Nothing?
3209
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3210
-		return;
3380
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3381
+			return;
3382
+	}
3211 3383
 
3212 3384
 	// Was it a problem with Windows?
3213 3385
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3239,11 +3411,12 @@  discard block
 block discarded – undo
3239 3411
 					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\');
3240 3412
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3241 3413
 
3242
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3243
-		echo '
3414
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3415
+			echo '
3244 3416
 					content.write(\'<hr>\n\t\t\t\');
3245 3417
 					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\');
3246 3418
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3419
+	}
3247 3420
 
3248 3421
 	echo '
3249 3422
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3251,17 +3424,19 @@  discard block
 block discarded – undo
3251 3424
 				}
3252 3425
 		</script>';
3253 3426
 
3254
-	if (!empty($upcontext['chmod']['ftp_error']))
3255
-		echo '
3427
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3428
+			echo '
3256 3429
 			<div class="error_message red">
3257 3430
 				The following error was encountered when trying to connect:<br><br>
3258 3431
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3259 3432
 			</div>
3260 3433
 			<br>';
3434
+	}
3261 3435
 
3262
-	if (empty($upcontext['chmod_in_form']))
3263
-		echo '
3436
+	if (empty($upcontext['chmod_in_form'])) {
3437
+			echo '
3264 3438
 	<form action="', $upcontext['form_url'], '" method="post">';
3439
+	}
3265 3440
 
3266 3441
 	echo '
3267 3442
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3296,10 +3471,11 @@  discard block
 block discarded – undo
3296 3471
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3297 3472
 	</div>';
3298 3473
 
3299
-	if (empty($upcontext['chmod_in_form']))
3300
-		echo '
3474
+	if (empty($upcontext['chmod_in_form'])) {
3475
+			echo '
3301 3476
 	</form>';
3302
-}
3477
+	}
3478
+	}
3303 3479
 
3304 3480
 function template_upgrade_above()
3305 3481
 {
@@ -3359,9 +3535,10 @@  discard block
 block discarded – undo
3359 3535
 				<h2>', $txt['upgrade_progress'], '</h2>
3360 3536
 				<ul>';
3361 3537
 
3362
-	foreach ($upcontext['steps'] as $num => $step)
3363
-		echo '
3538
+	foreach ($upcontext['steps'] as $num => $step) {
3539
+			echo '
3364 3540
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3541
+	}
3365 3542
 
3366 3543
 	echo '
3367 3544
 					</ul>
@@ -3374,8 +3551,8 @@  discard block
 block discarded – undo
3374 3551
 				</div>
3375 3552
 			</div>';
3376 3553
 
3377
-	if (isset($upcontext['step_progress']))
3378
-		echo '
3554
+	if (isset($upcontext['step_progress'])) {
3555
+			echo '
3379 3556
 				<br>
3380 3557
 				<br>
3381 3558
 				<div id="progress_bar_step">
@@ -3384,6 +3561,7 @@  discard block
 block discarded – undo
3384 3561
 						<span>', $txt['upgrade_step_progress'], '</span>
3385 3562
 					</div>
3386 3563
 				</div>';
3564
+	}
3387 3565
 
3388 3566
 	echo '
3389 3567
 				<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>
@@ -3414,32 +3592,36 @@  discard block
 block discarded – undo
3414 3592
 {
3415 3593
 	global $upcontext, $txt;
3416 3594
 
3417
-	if (!empty($upcontext['pause']))
3418
-		echo '
3595
+	if (!empty($upcontext['pause'])) {
3596
+			echo '
3419 3597
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3420 3598
 
3421 3599
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3422 3600
 								<h3>
3423 3601
 									', $txt['upgrade_paused_overload'], '
3424 3602
 								</h3>';
3603
+	}
3425 3604
 
3426
-	if (!empty($upcontext['custom_warning']))
3427
-		echo '
3605
+	if (!empty($upcontext['custom_warning'])) {
3606
+			echo '
3428 3607
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3429 3608
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3430 3609
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3431 3610
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3432 3611
 								</div>';
3612
+	}
3433 3613
 
3434 3614
 	echo '
3435 3615
 								<div class="righttext" style="margin: 1ex;">';
3436 3616
 
3437
-	if (!empty($upcontext['continue']))
3438
-		echo '
3617
+	if (!empty($upcontext['continue'])) {
3618
+			echo '
3439 3619
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3440
-	if (!empty($upcontext['skip']))
3441
-		echo '
3620
+	}
3621
+	if (!empty($upcontext['skip'])) {
3622
+			echo '
3442 3623
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3624
+	}
3443 3625
 
3444 3626
 	echo '
3445 3627
 								</div>
@@ -3489,11 +3671,12 @@  discard block
 block discarded – undo
3489 3671
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3490 3672
 	<smf>';
3491 3673
 
3492
-	if (!empty($upcontext['get_data']))
3493
-		foreach ($upcontext['get_data'] as $k => $v)
3674
+	if (!empty($upcontext['get_data'])) {
3675
+			foreach ($upcontext['get_data'] as $k => $v)
3494 3676
 			echo '
3495 3677
 		<get key="', $k, '">', $v, '</get>';
3496
-}
3678
+	}
3679
+	}
3497 3680
 
3498 3681
 function template_xml_below()
3499 3682
 {
@@ -3534,8 +3717,8 @@  discard block
 block discarded – undo
3534 3717
 	template_chmod();
3535 3718
 
3536 3719
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3537
-	if ($upcontext['is_large_forum'])
3538
-		echo '
3720
+	if ($upcontext['is_large_forum']) {
3721
+			echo '
3539 3722
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3540 3723
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3541 3724
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3543,10 +3726,11 @@  discard block
 block discarded – undo
3543 3726
 				', $txt['upgrade_warning_lots_data'], '
3544 3727
 			</div>
3545 3728
 		</div>';
3729
+	}
3546 3730
 
3547 3731
 	// A warning message?
3548
-	if (!empty($upcontext['warning']))
3549
-		echo '
3732
+	if (!empty($upcontext['warning'])) {
3733
+			echo '
3550 3734
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3551 3735
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3552 3736
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3554,6 +3738,7 @@  discard block
 block discarded – undo
3554 3738
 				', $upcontext['warning'], '
3555 3739
 			</div>
3556 3740
 		</div>';
3741
+	}
3557 3742
 
3558 3743
 	// Paths are incorrect?
3559 3744
 	echo '
@@ -3569,20 +3754,22 @@  discard block
 block discarded – undo
3569 3754
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3570 3755
 	{
3571 3756
 		$ago = time() - $upcontext['started'];
3572
-		if ($ago < 60)
3573
-			$ago = $ago . ' seconds';
3574
-		elseif ($ago < 3600)
3575
-			$ago = (int) ($ago / 60) . ' minutes';
3576
-		else
3577
-			$ago = (int) ($ago / 3600) . ' hours';
3757
+		if ($ago < 60) {
3758
+					$ago = $ago . ' seconds';
3759
+		} elseif ($ago < 3600) {
3760
+					$ago = (int) ($ago / 60) . ' minutes';
3761
+		} else {
3762
+					$ago = (int) ($ago / 3600) . ' hours';
3763
+		}
3578 3764
 
3579 3765
 		$active = time() - $upcontext['updated'];
3580
-		if ($active < 60)
3581
-			$updated = $active . ' seconds';
3582
-		elseif ($active < 3600)
3583
-			$updated = (int) ($active / 60) . ' minutes';
3584
-		else
3585
-			$updated = (int) ($active / 3600) . ' hours';
3766
+		if ($active < 60) {
3767
+					$updated = $active . ' seconds';
3768
+		} elseif ($active < 3600) {
3769
+					$updated = (int) ($active / 60) . ' minutes';
3770
+		} else {
3771
+					$updated = (int) ($active / 3600) . ' hours';
3772
+		}
3586 3773
 
3587 3774
 		echo '
3588 3775
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3591,16 +3778,18 @@  discard block
 block discarded – undo
3591 3778
 			<div style="padding-left: 6ex;">
3592 3779
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3593 3780
 
3594
-		if ($active < 600)
3595
-			echo '
3781
+		if ($active < 600) {
3782
+					echo '
3596 3783
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3784
+		}
3597 3785
 
3598
-		if ($active > $upcontext['inactive_timeout'])
3599
-			echo '
3786
+		if ($active > $upcontext['inactive_timeout']) {
3787
+					echo '
3600 3788
 				<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.';
3601
-		else
3602
-			echo '
3789
+		} else {
3790
+					echo '
3603 3791
 				<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!');
3792
+		}
3604 3793
 
3605 3794
 		echo '
3606 3795
 			</div>
@@ -3616,9 +3805,10 @@  discard block
 block discarded – undo
3616 3805
 					<td>
3617 3806
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3618 3807
 
3619
-	if (!empty($upcontext['username_incorrect']))
3620
-		echo '
3808
+	if (!empty($upcontext['username_incorrect'])) {
3809
+			echo '
3621 3810
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3811
+	}
3622 3812
 
3623 3813
 	echo '
3624 3814
 					</td>
@@ -3629,9 +3819,10 @@  discard block
 block discarded – undo
3629 3819
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3630 3820
 						<input type="hidden" name="hash_passwrd" value="">';
3631 3821
 
3632
-	if (!empty($upcontext['password_failed']))
3633
-		echo '
3822
+	if (!empty($upcontext['password_failed'])) {
3823
+			echo '
3634 3824
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3825
+	}
3635 3826
 
3636 3827
 	echo '
3637 3828
 					</td>
@@ -3702,8 +3893,8 @@  discard block
 block discarded – undo
3702 3893
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3703 3894
 
3704 3895
 	// Warning message?
3705
-	if (!empty($upcontext['upgrade_options_warning']))
3706
-		echo '
3896
+	if (!empty($upcontext['upgrade_options_warning'])) {
3897
+			echo '
3707 3898
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3708 3899
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3709 3900
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3711,6 +3902,7 @@  discard block
 block discarded – undo
3711 3902
 				', $upcontext['upgrade_options_warning'], '
3712 3903
 			</div>
3713 3904
 		</div>';
3905
+	}
3714 3906
 
3715 3907
 	echo '
3716 3908
 				<table>
@@ -3753,8 +3945,8 @@  discard block
 block discarded – undo
3753 3945
 						</td>
3754 3946
 					</tr>';
3755 3947
 
3756
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3757
-		echo '
3948
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3949
+			echo '
3758 3950
 					<tr valign="top">
3759 3951
 						<td width="2%">
3760 3952
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3763,6 +3955,7 @@  discard block
 block discarded – undo
3763 3955
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3764 3956
 						</td>
3765 3957
 					</tr>';
3958
+	}
3766 3959
 
3767 3960
 	echo '
3768 3961
 					<tr valign="top">
@@ -3800,10 +3993,11 @@  discard block
 block discarded – undo
3800 3993
 			</div>';
3801 3994
 
3802 3995
 	// Dont any tables so far?
3803
-	if (!empty($upcontext['previous_tables']))
3804
-		foreach ($upcontext['previous_tables'] as $table)
3996
+	if (!empty($upcontext['previous_tables'])) {
3997
+			foreach ($upcontext['previous_tables'] as $table)
3805 3998
 			echo '
3806 3999
 			<br>Completed Table: &quot;', $table, '&quot;.';
4000
+	}
3807 4001
 
3808 4002
 	echo '
3809 4003
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3840,12 +4034,13 @@  discard block
 block discarded – undo
3840 4034
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3841 4035
 
3842 4036
 		// If debug flood the screen.
3843
-		if ($is_debug)
3844
-			echo '
4037
+		if ($is_debug) {
4038
+					echo '
3845 4039
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3846 4040
 
3847 4041
 				if (document.getElementById(\'debug_section\').scrollHeight)
3848 4042
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4043
+		}
3849 4044
 
3850 4045
 		echo '
3851 4046
 				// Get the next update...
@@ -3877,8 +4072,9 @@  discard block
 block discarded – undo
3877 4072
 {
3878 4073
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3879 4074
 
3880
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3881
-		$is_debug = true;
4075
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4076
+			$is_debug = true;
4077
+	}
3882 4078
 
3883 4079
 	echo '
3884 4080
 		<h3>Executing database changes</h3>
@@ -3893,8 +4089,9 @@  discard block
 block discarded – undo
3893 4089
 	{
3894 4090
 		foreach ($upcontext['actioned_items'] as $num => $item)
3895 4091
 		{
3896
-			if ($num != 0)
3897
-				echo ' Successful!';
4092
+			if ($num != 0) {
4093
+							echo ' Successful!';
4094
+			}
3898 4095
 			echo '<br>' . $item;
3899 4096
 		}
3900 4097
 		if (!empty($upcontext['changes_complete']))
@@ -3907,28 +4104,32 @@  discard block
 block discarded – undo
3907 4104
 				$seconds = intval($active % 60);
3908 4105
 
3909 4106
 				$totalTime = '';
3910
-				if ($hours > 0)
3911
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3912
-				if ($minutes > 0)
3913
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3914
-				if ($seconds > 0)
3915
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4107
+				if ($hours > 0) {
4108
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4109
+				}
4110
+				if ($minutes > 0) {
4111
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4112
+				}
4113
+				if ($seconds > 0) {
4114
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4115
+				}
3916 4116
 			}
3917 4117
 
3918
-			if ($is_debug && !empty($totalTime))
3919
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3920
-			else
3921
-				echo ' Successful!<br><br>';
4118
+			if ($is_debug && !empty($totalTime)) {
4119
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4120
+			} else {
4121
+							echo ' Successful!<br><br>';
4122
+			}
3922 4123
 
3923 4124
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3924 4125
 		}
3925
-	}
3926
-	else
4126
+	} else
3927 4127
 	{
3928 4128
 		// Tell them how many files we have in total.
3929
-		if ($upcontext['file_count'] > 1)
3930
-			echo '
4129
+		if ($upcontext['file_count'] > 1) {
4130
+					echo '
3931 4131
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4132
+		}
3932 4133
 
3933 4134
 		echo '
3934 4135
 		<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>
@@ -3944,19 +4145,23 @@  discard block
 block discarded – undo
3944 4145
 				$seconds = intval($active % 60);
3945 4146
 
3946 4147
 				$totalTime = '';
3947
-				if ($hours > 0)
3948
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3949
-				if ($minutes > 0)
3950
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3951
-				if ($seconds > 0)
3952
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4148
+				if ($hours > 0) {
4149
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4150
+				}
4151
+				if ($minutes > 0) {
4152
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4153
+				}
4154
+				if ($seconds > 0) {
4155
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4156
+				}
3953 4157
 			}
3954 4158
 
3955 4159
 			echo '
3956 4160
 			<br><span id="upgradeCompleted">';
3957 4161
 
3958
-			if (!empty($totalTime))
3959
-				echo 'Completed in ', $totalTime, '<br>';
4162
+			if (!empty($totalTime)) {
4163
+							echo 'Completed in ', $totalTime, '<br>';
4164
+			}
3960 4165
 
3961 4166
 			echo '</span>
3962 4167
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3993,9 +4198,10 @@  discard block
 block discarded – undo
3993 4198
 			var getData = "";
3994 4199
 			var debugItems = ', $upcontext['debug_items'], ';';
3995 4200
 
3996
-		if ($is_debug)
3997
-			echo '
4201
+		if ($is_debug) {
4202
+					echo '
3998 4203
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4204
+		}
3999 4205
 
4000 4206
 		echo '
4001 4207
 			function getNextItem()
@@ -4035,9 +4241,10 @@  discard block
 block discarded – undo
4035 4241
 						document.getElementById("error_block").style.display = "";
4036 4242
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4037 4243
 
4038
-	if ($is_debug)
4039
-		echo '
4244
+	if ($is_debug) {
4245
+			echo '
4040 4246
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4247
+	}
4041 4248
 
4042 4249
 	echo '
4043 4250
 					}
@@ -4058,9 +4265,10 @@  discard block
 block discarded – undo
4058 4265
 						document.getElementById("error_block").style.display = "";
4059 4266
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4060 4267
 
4061
-	if ($is_debug)
4062
-		echo '
4268
+	if ($is_debug) {
4269
+			echo '
4063 4270
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4271
+	}
4064 4272
 
4065 4273
 	echo '
4066 4274
 					}
@@ -4119,8 +4327,8 @@  discard block
 block discarded – undo
4119 4327
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4120 4328
 				{';
4121 4329
 
4122
-		if ($is_debug)
4123
-			echo '
4330
+		if ($is_debug) {
4331
+					echo '
4124 4332
 					document.getElementById(\'debug_section\').style.display = "none";
4125 4333
 
4126 4334
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4138,6 +4346,7 @@  discard block
 block discarded – undo
4138 4346
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4139 4347
 
4140 4348
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4349
+		}
4141 4350
 
4142 4351
 		echo '
4143 4352
 
@@ -4145,9 +4354,10 @@  discard block
 block discarded – undo
4145 4354
 					document.getElementById(\'contbutt\').disabled = 0;
4146 4355
 					document.getElementById(\'database_done\').value = 1;';
4147 4356
 
4148
-		if ($upcontext['file_count'] > 1)
4149
-			echo '
4357
+		if ($upcontext['file_count'] > 1) {
4358
+					echo '
4150 4359
 					document.getElementById(\'info1\').style.display = "none";';
4360
+		}
4151 4361
 
4152 4362
 		echo '
4153 4363
 					document.getElementById(\'info2\').style.display = "none";
@@ -4160,9 +4370,10 @@  discard block
 block discarded – undo
4160 4370
 					lastItem = 0;
4161 4371
 					prevFile = curFile;';
4162 4372
 
4163
-		if ($is_debug)
4164
-			echo '
4373
+		if ($is_debug) {
4374
+					echo '
4165 4375
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4376
+		}
4166 4377
 
4167 4378
 		echo '
4168 4379
 					getNextItem();
@@ -4170,8 +4381,8 @@  discard block
 block discarded – undo
4170 4381
 				}';
4171 4382
 
4172 4383
 		// If debug scroll the screen.
4173
-		if ($is_debug)
4174
-			echo '
4384
+		if ($is_debug) {
4385
+					echo '
4175 4386
 				if (iLastSubStepProgress == -1)
4176 4387
 				{
4177 4388
 					// Give it consistent dots.
@@ -4190,6 +4401,7 @@  discard block
 block discarded – undo
4190 4401
 
4191 4402
 				if (document.getElementById(\'debug_section\').scrollHeight)
4192 4403
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4404
+		}
4193 4405
 
4194 4406
 		echo '
4195 4407
 				// Update the page.
@@ -4250,9 +4462,10 @@  discard block
 block discarded – undo
4250 4462
 			}';
4251 4463
 
4252 4464
 		// Start things off assuming we've not errored.
4253
-		if (empty($upcontext['error_message']))
4254
-			echo '
4465
+		if (empty($upcontext['error_message'])) {
4466
+					echo '
4255 4467
 			getNextItem();';
4468
+		}
4256 4469
 
4257 4470
 		echo '
4258 4471
 		</script>';
@@ -4269,18 +4482,21 @@  discard block
 block discarded – undo
4269 4482
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4270 4483
 	<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>';
4271 4484
 
4272
-	if (!empty($upcontext['error_message']))
4273
-		echo '
4485
+	if (!empty($upcontext['error_message'])) {
4486
+			echo '
4274 4487
 	<error>', $upcontext['error_message'], '</error>';
4488
+	}
4275 4489
 
4276
-	if (!empty($upcontext['error_string']))
4277
-		echo '
4490
+	if (!empty($upcontext['error_string'])) {
4491
+			echo '
4278 4492
 	<sql>', $upcontext['error_string'], '</sql>';
4493
+	}
4279 4494
 
4280
-	if ($is_debug)
4281
-		echo '
4495
+	if ($is_debug) {
4496
+			echo '
4282 4497
 	<curtime>', time(), '</curtime>';
4283
-}
4498
+	}
4499
+	}
4284 4500
 
4285 4501
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4286 4502
 function template_convert_utf8()
@@ -4297,18 +4513,20 @@  discard block
 block discarded – undo
4297 4513
 			<span id="debuginfo"></span>';
4298 4514
 
4299 4515
 	// Done any tables so far?
4300
-	if (!empty($upcontext['previous_tables']))
4301
-		foreach ($upcontext['previous_tables'] as $table)
4516
+	if (!empty($upcontext['previous_tables'])) {
4517
+			foreach ($upcontext['previous_tables'] as $table)
4302 4518
 			echo '
4303 4519
 			<br>Completed Table: &quot;', $table, '&quot;.';
4520
+	}
4304 4521
 
4305 4522
 	echo '
4306 4523
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4307 4524
 
4308 4525
 	// If we dropped their index, let's let them know
4309
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4310
-		echo '
4526
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4527
+			echo '
4311 4528
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4529
+	}
4312 4530
 
4313 4531
 	echo '
4314 4532
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4344,9 +4562,10 @@  discard block
 block discarded – undo
4344 4562
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4345 4563
 
4346 4564
 		// If debug flood the screen.
4347
-		if ($is_debug)
4348
-			echo '
4565
+		if ($is_debug) {
4566
+					echo '
4349 4567
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4568
+		}
4350 4569
 
4351 4570
 		echo '
4352 4571
 				// Get the next update...
@@ -4388,19 +4607,21 @@  discard block
 block discarded – undo
4388 4607
 			<span id="debuginfo"></span>';
4389 4608
 
4390 4609
 	// Dont any tables so far?
4391
-	if (!empty($upcontext['previous_tables']))
4392
-		foreach ($upcontext['previous_tables'] as $table)
4610
+	if (!empty($upcontext['previous_tables'])) {
4611
+			foreach ($upcontext['previous_tables'] as $table)
4393 4612
 			echo '
4394 4613
 			<br>Completed Table: &quot;', $table, '&quot;.';
4614
+	}
4395 4615
 
4396 4616
 	echo '
4397 4617
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4398 4618
 			<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>';
4399 4619
 
4400 4620
 	// Try to make sure substep was reset.
4401
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4402
-		echo '
4621
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4622
+			echo '
4403 4623
 			<input type="hidden" name="substep" id="substep" value="0">';
4624
+	}
4404 4625
 
4405 4626
 	// Continue please!
4406 4627
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4433,9 +4654,10 @@  discard block
 block discarded – undo
4433 4654
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4434 4655
 
4435 4656
 		// If debug flood the screen.
4436
-		if ($is_debug)
4437
-			echo '
4657
+		if ($is_debug) {
4658
+					echo '
4438 4659
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4660
+		}
4439 4661
 
4440 4662
 		echo '
4441 4663
 				// Get the next update...
@@ -4470,8 +4692,8 @@  discard block
 block discarded – undo
4470 4692
 	<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>
4471 4693
 	<form action="', $boardurl, '/index.php">';
4472 4694
 
4473
-	if (!empty($upcontext['can_delete_script']))
4474
-		echo '
4695
+	if (!empty($upcontext['can_delete_script'])) {
4696
+			echo '
4475 4697
 			<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>
4476 4698
 			<script>
4477 4699
 				function doTheDelete(theCheck)
@@ -4483,6 +4705,7 @@  discard block
 block discarded – undo
4483 4705
 				}
4484 4706
 			</script>
4485 4707
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4708
+	}
4486 4709
 
4487 4710
 	$active = time() - $upcontext['started'];
4488 4711
 	$hours = floor($active / 3600);
@@ -4492,16 +4715,20 @@  discard block
 block discarded – undo
4492 4715
 	if ($is_debug)
4493 4716
 	{
4494 4717
 		$totalTime = '';
4495
-		if ($hours > 0)
4496
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4497
-		if ($minutes > 0)
4498
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4499
-		if ($seconds > 0)
4500
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4718
+		if ($hours > 0) {
4719
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4720
+		}
4721
+		if ($minutes > 0) {
4722
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4723
+		}
4724
+		if ($seconds > 0) {
4725
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4726
+		}
4501 4727
 	}
4502 4728
 
4503
-	if ($is_debug && !empty($totalTime))
4504
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4729
+	if ($is_debug && !empty($totalTime)) {
4730
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4731
+	}
4505 4732
 
4506 4733
 	echo '<br>
4507 4734
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4528,8 +4755,9 @@  discard block
 block discarded – undo
4528 4755
 
4529 4756
 	$current_substep = $_GET['substep'];
4530 4757
 
4531
-	if (empty($_GET['a']))
4532
-		$_GET['a'] = 0;
4758
+	if (empty($_GET['a'])) {
4759
+			$_GET['a'] = 0;
4760
+	}
4533 4761
 	$step_progress['name'] = 'Converting ips';
4534 4762
 	$step_progress['current'] = $_GET['a'];
4535 4763
 
@@ -4572,16 +4800,19 @@  discard block
 block discarded – undo
4572 4800
 				'empty' => '',
4573 4801
 				'limit' => $limit,
4574 4802
 		));
4575
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4576
-			$arIp[] = $row[$oldCol];
4803
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4804
+					$arIp[] = $row[$oldCol];
4805
+		}
4577 4806
 		$smcFunc['db_free_result']($request);
4578 4807
 
4579 4808
 		// Special case, null ip could keep us in a loop.
4580
-		if (is_null($arIp[0]))
4581
-			unset($arIp[0]);
4809
+		if (is_null($arIp[0])) {
4810
+					unset($arIp[0]);
4811
+		}
4582 4812
 
4583
-		if (empty($arIp))
4584
-			$is_done = true;
4813
+		if (empty($arIp)) {
4814
+					$is_done = true;
4815
+		}
4585 4816
 
4586 4817
 		$updates = array();
4587 4818
 		$cases = array();
@@ -4590,16 +4821,18 @@  discard block
 block discarded – undo
4590 4821
 		{
4591 4822
 			$arIp[$i] = trim($arIp[$i]);
4592 4823
 
4593
-			if (empty($arIp[$i]))
4594
-				continue;
4824
+			if (empty($arIp[$i])) {
4825
+							continue;
4826
+			}
4595 4827
 
4596 4828
 			$updates['ip' . $i] = $arIp[$i];
4597 4829
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4598 4830
 
4599 4831
 			if ($setSize > 0 && $i % $setSize === 0)
4600 4832
 			{
4601
-				if (count($updates) == 1)
4602
-					continue;
4833
+				if (count($updates) == 1) {
4834
+									continue;
4835
+				}
4603 4836
 
4604 4837
 				$updates['whereSet'] = array_values($updates);
4605 4838
 				$smcFunc['db_query']('', '
@@ -4633,8 +4866,7 @@  discard block
 block discarded – undo
4633 4866
 							'ip' => $ip
4634 4867
 					));
4635 4868
 				}
4636
-			}
4637
-			else
4869
+			} else
4638 4870
 			{
4639 4871
 				$updates['whereSet'] = array_values($updates);
4640 4872
 				$smcFunc['db_query']('', '
@@ -4648,9 +4880,9 @@  discard block
 block discarded – undo
4648 4880
 					$updates
4649 4881
 				);
4650 4882
 			}
4883
+		} else {
4884
+					$is_done = true;
4651 4885
 		}
4652
-		else
4653
-			$is_done = true;
4654 4886
 
4655 4887
 		$_GET['a'] += $limit;
4656 4888
 		$step_progress['current'] = $_GET['a'];
@@ -4676,10 +4908,11 @@  discard block
 block discarded – undo
4676 4908
  
4677 4909
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4678 4910
 
4679
-	if (isset($columns[$column]))
4680
-		return $columns[$column];
4681
-	else
4682
-		return null;
4683
-}
4911
+	if (isset($columns[$column])) {
4912
+			return $columns[$column];
4913
+	} else {
4914
+			return null;
4915
+	}
4916
+	}
4684 4917
 
4685 4918
 ?>
4686 4919
\ No newline at end of file
Please login to merge, or discard this patch.