Completed
Push — release-2.1 ( 2dc2a3...f7f069 )
by Michael
04:25 queued 04:17
created
other/upgrade.php 1 patch
Braces   +865 added lines, -634 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,9 +122,9 @@  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');
@@ -131,10 +135,12 @@  discard block
 block discarded – undo
131 135
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
132 136
 
133 137
 	// Check for sensible values.
134
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
135
-		$upcontext['user']['started'] = time();
136
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
137
-		$upcontext['user']['updated'] = 0;
138
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
139
+			$upcontext['user']['started'] = time();
140
+	}
141
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
142
+			$upcontext['user']['updated'] = 0;
143
+	}
138 144
 
139 145
 	$upcontext['started'] = $upcontext['user']['started'];
140 146
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -192,8 +198,9 @@  discard block
 block discarded – undo
192 198
 			'db_error_skip' => true,
193 199
 		)
194 200
 	);
195
-	while ($row = $smcFunc['db_fetch_assoc']($request))
196
-		$modSettings[$row['variable']] = $row['value'];
201
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
202
+			$modSettings[$row['variable']] = $row['value'];
203
+	}
197 204
 	$smcFunc['db_free_result']($request);
198 205
 }
199 206
 
@@ -203,10 +210,12 @@  discard block
 block discarded – undo
203 210
 	$modSettings['theme_url'] = 'Themes/default';
204 211
 	$modSettings['images_url'] = 'Themes/default/images';
205 212
 }
206
-if (!isset($settings['default_theme_url']))
213
+if (!isset($settings['default_theme_url'])) {
207 214
 	$settings['default_theme_url'] = $modSettings['theme_url'];
208
-if (!isset($settings['default_theme_dir']))
215
+}
216
+if (!isset($settings['default_theme_dir'])) {
209 217
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
218
+}
210 219
 
211 220
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
212 221
 // Default title...
@@ -224,13 +233,15 @@  discard block
 block discarded – undo
224 233
 	$support_js = $upcontext['upgrade_status']['js'];
225 234
 
226 235
 	// Only set this if the upgrader status says so.
227
-	if (empty($is_debug))
228
-		$is_debug = $upcontext['upgrade_status']['debug'];
236
+	if (empty($is_debug)) {
237
+			$is_debug = $upcontext['upgrade_status']['debug'];
238
+	}
229 239
 
230 240
 	// Load the language.
231
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
232
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
233
-}
241
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
242
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
243
+	}
244
+	}
234 245
 // Set the defaults.
235 246
 else
236 247
 {
@@ -248,15 +259,18 @@  discard block
 block discarded – undo
248 259
 }
249 260
 
250 261
 // If this isn't the first stage see whether they are logging in and resuming.
251
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
262
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
252 263
 	checkLogin();
264
+}
253 265
 
254
-if ($command_line)
266
+if ($command_line) {
255 267
 	cmdStep0();
268
+}
256 269
 
257 270
 // Don't error if we're using xml.
258
-if (isset($_GET['xml']))
271
+if (isset($_GET['xml'])) {
259 272
 	$upcontext['return_error'] = true;
273
+}
260 274
 
261 275
 // Loop through all the steps doing each one as required.
262 276
 $upcontext['overall_percent'] = 0;
@@ -277,10 +291,11 @@  discard block
 block discarded – undo
277 291
 		}
278 292
 
279 293
 		// Call the step and if it returns false that means pause!
280
-		if (function_exists($step[2]) && $step[2]() === false)
281
-			break;
282
-		elseif (function_exists($step[2]))
283
-			$upcontext['current_step']++;
294
+		if (function_exists($step[2]) && $step[2]() === false) {
295
+					break;
296
+		} elseif (function_exists($step[2])) {
297
+					$upcontext['current_step']++;
298
+		}
284 299
 	}
285 300
 	$upcontext['overall_percent'] += $step[3];
286 301
 }
@@ -319,17 +334,18 @@  discard block
 block discarded – undo
319 334
 		// This should not happen my dear... HELP ME DEVELOPERS!!
320 335
 		if (!empty($command_line))
321 336
 		{
322
-			if (function_exists('debug_print_backtrace'))
323
-				debug_print_backtrace();
337
+			if (function_exists('debug_print_backtrace')) {
338
+							debug_print_backtrace();
339
+			}
324 340
 
325 341
 			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.';
326 342
 			flush();
327 343
 			die();
328 344
 		}
329 345
 
330
-		if (!isset($_GET['xml']))
331
-			template_upgrade_above();
332
-		else
346
+		if (!isset($_GET['xml'])) {
347
+					template_upgrade_above();
348
+		} else
333 349
 		{
334 350
 			header('Content-Type: text/xml; charset=UTF-8');
335 351
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -351,21 +367,24 @@  discard block
 block discarded – undo
351 367
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
352 368
 
353 369
 			// Custom stuff to pass back?
354
-			if (!empty($upcontext['query_string']))
355
-				$upcontext['form_url'] .= $upcontext['query_string'];
370
+			if (!empty($upcontext['query_string'])) {
371
+							$upcontext['form_url'] .= $upcontext['query_string'];
372
+			}
356 373
 
357 374
 			call_user_func('template_' . $upcontext['sub_template']);
358 375
 		}
359 376
 
360 377
 		// Was there an error?
361
-		if (!empty($upcontext['forced_error_message']))
362
-			echo $upcontext['forced_error_message'];
378
+		if (!empty($upcontext['forced_error_message'])) {
379
+					echo $upcontext['forced_error_message'];
380
+		}
363 381
 
364 382
 		// Show the footer.
365
-		if (!isset($_GET['xml']))
366
-			template_upgrade_below();
367
-		else
368
-			template_xml_below();
383
+		if (!isset($_GET['xml'])) {
384
+					template_upgrade_below();
385
+		} else {
386
+					template_xml_below();
387
+		}
369 388
 	}
370 389
 
371 390
 
@@ -377,15 +396,19 @@  discard block
 block discarded – undo
377 396
 		$seconds = intval($active % 60);
378 397
 
379 398
 		$totalTime = '';
380
-		if ($hours > 0)
381
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
382
-		if ($minutes > 0)
383
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
384
-		if ($seconds > 0)
385
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
399
+		if ($hours > 0) {
400
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
401
+		}
402
+		if ($minutes > 0) {
403
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
404
+		}
405
+		if ($seconds > 0) {
406
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
407
+		}
386 408
 
387
-		if (!empty($totalTime))
388
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
409
+		if (!empty($totalTime)) {
410
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
411
+		}
389 412
 	}
390 413
 
391 414
 	// Bang - gone!
@@ -398,8 +421,9 @@  discard block
 block discarded – undo
398 421
 	global $upgradeurl, $upcontext, $command_line;
399 422
 
400 423
 	// Command line users can't be redirected.
401
-	if ($command_line)
402
-		upgradeExit(true);
424
+	if ($command_line) {
425
+			upgradeExit(true);
426
+	}
403 427
 
404 428
 	// Are we providing the core info?
405 429
 	if ($addForm)
@@ -422,19 +446,22 @@  discard block
 block discarded – undo
422 446
 	global $modSettings, $sourcedir, $smcFunc;
423 447
 
424 448
 	// Do the non-SSI stuff...
425
-	if (function_exists('set_magic_quotes_runtime'))
426
-		@set_magic_quotes_runtime(0);
449
+	if (function_exists('set_magic_quotes_runtime')) {
450
+			@set_magic_quotes_runtime(0);
451
+	}
427 452
 
428 453
 	error_reporting(E_ALL);
429 454
 	define('SMF', 1);
430 455
 
431 456
 	// Start the session.
432
-	if (@ini_get('session.save_handler') == 'user')
433
-		@ini_set('session.save_handler', 'files');
457
+	if (@ini_get('session.save_handler') == 'user') {
458
+			@ini_set('session.save_handler', 'files');
459
+	}
434 460
 	@session_start();
435 461
 
436
-	if (empty($smcFunc))
437
-		$smcFunc = array();
462
+	if (empty($smcFunc)) {
463
+			$smcFunc = array();
464
+	}
438 465
 
439 466
 	// We need this for authentication and some upgrade code
440 467
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -446,8 +473,9 @@  discard block
 block discarded – undo
446 473
 	initialize_inputs();
447 474
 
448 475
 	// Get the database going!
449
-	if (empty($db_type) || $db_type == 'mysqli')
450
-		$db_type = 'mysql';
476
+	if (empty($db_type) || $db_type == 'mysqli') {
477
+			$db_type = 'mysql';
478
+	}
451 479
 
452 480
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
453 481
 	{
@@ -457,17 +485,19 @@  discard block
 block discarded – undo
457 485
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
458 486
 
459 487
 		// Oh dear god!!
460
-		if ($db_connection === null)
461
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
488
+		if ($db_connection === null) {
489
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
490
+		}
462 491
 
463
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
464
-			$smcFunc['db_query']('', '
492
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
493
+					$smcFunc['db_query']('', '
465 494
 			SET NAMES {string:db_character_set}',
466 495
 			array(
467 496
 				'db_error_skip' => true,
468 497
 				'db_character_set' => $db_character_set,
469 498
 			)
470 499
 		);
500
+		}
471 501
 
472 502
 		// Load the modSettings data...
473 503
 		$request = $smcFunc['db_query']('', '
@@ -478,11 +508,11 @@  discard block
 block discarded – undo
478 508
 			)
479 509
 		);
480 510
 		$modSettings = array();
481
-		while ($row = $smcFunc['db_fetch_assoc']($request))
482
-			$modSettings[$row['variable']] = $row['value'];
511
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
512
+					$modSettings[$row['variable']] = $row['value'];
513
+		}
483 514
 		$smcFunc['db_free_result']($request);
484
-	}
485
-	else
515
+	} else
486 516
 	{
487 517
 		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.');
488 518
 	}
@@ -496,9 +526,10 @@  discard block
 block discarded – undo
496 526
 		cleanRequest();
497 527
 	}
498 528
 
499
-	if (!isset($_GET['substep']))
500
-		$_GET['substep'] = 0;
501
-}
529
+	if (!isset($_GET['substep'])) {
530
+			$_GET['substep'] = 0;
531
+	}
532
+	}
502 533
 
503 534
 function initialize_inputs()
504 535
 {
@@ -528,8 +559,9 @@  discard block
 block discarded – undo
528 559
 		$dh = opendir(dirname(__FILE__));
529 560
 		while ($file = readdir($dh))
530 561
 		{
531
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
532
-				@unlink(dirname(__FILE__) . '/' . $file);
562
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
563
+							@unlink(dirname(__FILE__) . '/' . $file);
564
+			}
533 565
 		}
534 566
 		closedir($dh);
535 567
 
@@ -559,8 +591,9 @@  discard block
 block discarded – undo
559 591
 	{
560 592
 		$upcontext['remote_files_available'] = false;
561 593
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
562
-		if ($test)
563
-			$upcontext['remote_files_available'] = true;
594
+		if ($test) {
595
+					$upcontext['remote_files_available'] = true;
596
+		}
564 597
 		@fclose($test);
565 598
 	}
566 599
 
@@ -568,8 +601,9 @@  discard block
 block discarded – undo
568 601
 	$temp = 'upgrade_php?step';
569 602
 	while (strlen($temp) > 4)
570 603
 	{
571
-		if (isset($_GET[$temp]))
572
-			unset($_GET[$temp]);
604
+		if (isset($_GET[$temp])) {
605
+					unset($_GET[$temp]);
606
+		}
573 607
 		$temp = substr($temp, 1);
574 608
 	}
575 609
 
@@ -596,32 +630,39 @@  discard block
 block discarded – undo
596 630
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
597 631
 
598 632
 	// Need legacy scripts?
599
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
600
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
601
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
602
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
603
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
604
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
633
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
634
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
635
+	}
636
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
637
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
638
+	}
639
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
640
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
641
+	}
605 642
 
606 643
 	// We don't need "-utf8" files anymore...
607 644
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
608 645
 
609 646
 	// This needs to exist!
610
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
611
-		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>]');
612
-	else
613
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
647
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
648
+			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>]');
649
+	} else {
650
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
651
+	}
614 652
 
615
-	if (!$check)
616
-		// 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.
653
+	if (!$check) {
654
+			// 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.
617 655
 		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.');
656
+	}
618 657
 
619 658
 	// Do they meet the install requirements?
620
-	if (!php_version_check())
621
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
659
+	if (!php_version_check()) {
660
+			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.');
661
+	}
622 662
 
623
-	if (!db_version_check())
624
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
663
+	if (!db_version_check()) {
664
+			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.');
665
+	}
625 666
 
626 667
 	// Do some checks to make sure they have proper privileges
627 668
 	db_extend('packages');
@@ -636,14 +677,16 @@  discard block
 block discarded – undo
636 677
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
637 678
 
638 679
 	// Sorry... we need CREATE, ALTER and DROP
639
-	if (!$create || !$alter || !$drop)
640
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
680
+	if (!$create || !$alter || !$drop) {
681
+			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.');
682
+	}
641 683
 
642 684
 	// Do a quick version spot check.
643 685
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
644 686
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
645
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
646
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
687
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
688
+			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.');
689
+	}
647 690
 
648 691
 	// What absolutely needs to be writable?
649 692
 	$writable_files = array(
@@ -665,12 +708,13 @@  discard block
 block discarded – undo
665 708
 	quickFileWritable($custom_av_dir);
666 709
 
667 710
 	// Are we good now?
668
-	if (!is_writable($custom_av_dir))
669
-		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));
670
-	elseif ($need_settings_update)
711
+	if (!is_writable($custom_av_dir)) {
712
+			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));
713
+	} elseif ($need_settings_update)
671 714
 	{
672
-		if (!function_exists('cache_put_data'))
673
-			require_once($sourcedir . '/Load.php');
715
+		if (!function_exists('cache_put_data')) {
716
+					require_once($sourcedir . '/Load.php');
717
+		}
674 718
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
675 719
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
676 720
 	}
@@ -679,28 +723,33 @@  discard block
 block discarded – undo
679 723
 
680 724
 	// Check the cache directory.
681 725
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
682
-	if (!file_exists($cachedir_temp))
683
-		@mkdir($cachedir_temp);
684
-	if (!file_exists($cachedir_temp))
685
-		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.');
686
-
687
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
688
-		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>.');
689
-	elseif (!isset($_GET['skiplang']))
726
+	if (!file_exists($cachedir_temp)) {
727
+			@mkdir($cachedir_temp);
728
+	}
729
+	if (!file_exists($cachedir_temp)) {
730
+			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.');
731
+	}
732
+
733
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
734
+			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>.');
735
+	} elseif (!isset($_GET['skiplang']))
690 736
 	{
691 737
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
692 738
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
693 739
 
694
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
695
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
740
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
741
+					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>]');
742
+		}
696 743
 	}
697 744
 
698
-	if (!makeFilesWritable($writable_files))
699
-		return false;
745
+	if (!makeFilesWritable($writable_files)) {
746
+			return false;
747
+	}
700 748
 
701 749
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
702
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
703
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
750
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
751
+			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.');
752
+	}
704 753
 
705 754
 	// Upgrade the agreement.
706 755
 	elseif (isset($modSettings['agreement']))
@@ -711,8 +760,8 @@  discard block
 block discarded – undo
711 760
 	}
712 761
 
713 762
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
714
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
715
-		$upcontext['warning'] = '
763
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
764
+			$upcontext['warning'] = '
716 765
 			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>
717 766
 			<ul>
718 767
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -720,10 +769,12 @@  discard block
 block discarded – undo
720 769
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
721 770
 			</ul>
722 771
 			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.';
772
+	}
723 773
 
724 774
 	// Either we're logged in or we're going to present the login.
725
-	if (checkLogin())
726
-		return true;
775
+	if (checkLogin()) {
776
+			return true;
777
+	}
727 778
 
728 779
 	$upcontext += createToken('login');
729 780
 
@@ -737,15 +788,17 @@  discard block
 block discarded – undo
737 788
 	global $smcFunc, $db_type, $support_js;
738 789
 
739 790
 	// Don't bother if the security is disabled.
740
-	if ($disable_security)
741
-		return true;
791
+	if ($disable_security) {
792
+			return true;
793
+	}
742 794
 
743 795
 	// Are we trying to login?
744 796
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
745 797
 	{
746 798
 		// If we've disabled security pick a suitable name!
747
-		if (empty($_POST['user']))
748
-			$_POST['user'] = 'Administrator';
799
+		if (empty($_POST['user'])) {
800
+					$_POST['user'] = 'Administrator';
801
+		}
749 802
 
750 803
 		// Before 2.0 these column names were different!
751 804
 		$oldDB = false;
@@ -760,16 +813,17 @@  discard block
 block discarded – undo
760 813
 					'db_error_skip' => true,
761 814
 				)
762 815
 			);
763
-			if ($smcFunc['db_num_rows']($request) != 0)
764
-				$oldDB = true;
816
+			if ($smcFunc['db_num_rows']($request) != 0) {
817
+							$oldDB = true;
818
+			}
765 819
 			$smcFunc['db_free_result']($request);
766 820
 		}
767 821
 
768 822
 		// Get what we believe to be their details.
769 823
 		if (!$disable_security)
770 824
 		{
771
-			if ($oldDB)
772
-				$request = $smcFunc['db_query']('', '
825
+			if ($oldDB) {
826
+							$request = $smcFunc['db_query']('', '
773 827
 					SELECT id_member, memberName AS member_name, passwd, id_group,
774 828
 					additionalGroups AS additional_groups, lngfile
775 829
 					FROM {db_prefix}members
@@ -779,8 +833,8 @@  discard block
 block discarded – undo
779 833
 						'db_error_skip' => true,
780 834
 					)
781 835
 				);
782
-			else
783
-				$request = $smcFunc['db_query']('', '
836
+			} else {
837
+							$request = $smcFunc['db_query']('', '
784 838
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
785 839
 					FROM {db_prefix}members
786 840
 					WHERE member_name = {string:member_name}',
@@ -789,6 +843,7 @@  discard block
 block discarded – undo
789 843
 						'db_error_skip' => true,
790 844
 					)
791 845
 				);
846
+			}
792 847
 			if ($smcFunc['db_num_rows']($request) != 0)
793 848
 			{
794 849
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -796,13 +851,14 @@  discard block
 block discarded – undo
796 851
 				$groups = explode(',', $addGroups);
797 852
 				$groups[] = $id_group;
798 853
 
799
-				foreach ($groups as $k => $v)
800
-					$groups[$k] = (int) $v;
854
+				foreach ($groups as $k => $v) {
855
+									$groups[$k] = (int) $v;
856
+				}
801 857
 
802 858
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
859
+			} else {
860
+							$upcontext['username_incorrect'] = true;
803 861
 			}
804
-			else
805
-				$upcontext['username_incorrect'] = true;
806 862
 			$smcFunc['db_free_result']($request);
807 863
 		}
808 864
 		$upcontext['username'] = $_POST['user'];
@@ -812,13 +868,14 @@  discard block
 block discarded – undo
812 868
 		{
813 869
 			$upcontext['upgrade_status']['js'] = 1;
814 870
 			$support_js = 1;
871
+		} else {
872
+					$support_js = 0;
815 873
 		}
816
-		else
817
-			$support_js = 0;
818 874
 
819 875
 		// Note down the version we are coming from.
820
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
821
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
876
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
877
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
878
+		}
822 879
 
823 880
 		// Didn't get anywhere?
824 881
 		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']))
@@ -852,15 +909,15 @@  discard block
 block discarded – undo
852 909
 							'db_error_skip' => true,
853 910
 						)
854 911
 					);
855
-					if ($smcFunc['db_num_rows']($request) == 0)
856
-						return throw_error('You need to be an admin to perform an upgrade!');
912
+					if ($smcFunc['db_num_rows']($request) == 0) {
913
+											return throw_error('You need to be an admin to perform an upgrade!');
914
+					}
857 915
 					$smcFunc['db_free_result']($request);
858 916
 				}
859 917
 
860 918
 				$upcontext['user']['id'] = $id_member;
861 919
 				$upcontext['user']['name'] = $name;
862
-			}
863
-			else
920
+			} else
864 921
 			{
865 922
 				$upcontext['user']['id'] = 1;
866 923
 				$upcontext['user']['name'] = 'Administrator';
@@ -876,11 +933,11 @@  discard block
 block discarded – undo
876 933
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
877 934
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
878 935
 
879
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
880
-					$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'] . '.';
881
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
882
-					$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'] . '.';
883
-				else
936
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
937
+									$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'] . '.';
938
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
939
+									$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'] . '.';
940
+				} else
884 941
 				{
885 942
 					// Set this as the new language.
886 943
 					$upcontext['language'] = $user_language;
@@ -924,8 +981,9 @@  discard block
 block discarded – undo
924 981
 	unset($member_columns);
925 982
 
926 983
 	// If we've not submitted then we're done.
927
-	if (empty($_POST['upcont']))
928
-		return false;
984
+	if (empty($_POST['upcont'])) {
985
+			return false;
986
+	}
929 987
 
930 988
 	// Firstly, if they're enabling SM stat collection just do it.
931 989
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -940,25 +998,26 @@  discard block
 block discarded – undo
940 998
 			fwrite($fp, $out);
941 999
 
942 1000
 			$return_data = '';
943
-			while (!feof($fp))
944
-				$return_data .= fgets($fp, 128);
1001
+			while (!feof($fp)) {
1002
+							$return_data .= fgets($fp, 128);
1003
+			}
945 1004
 
946 1005
 			fclose($fp);
947 1006
 
948 1007
 			// Get the unique site ID.
949 1008
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
950 1009
 
951
-			if (!empty($ID[1]))
952
-				$smcFunc['db_insert']('replace',
1010
+			if (!empty($ID[1])) {
1011
+							$smcFunc['db_insert']('replace',
953 1012
 					$db_prefix . 'settings',
954 1013
 					array('variable' => 'string', 'value' => 'string'),
955 1014
 					array('allow_sm_stats', $ID[1]),
956 1015
 					array('variable')
957 1016
 				);
1017
+			}
958 1018
 		}
959
-	}
960
-	else
961
-		$smcFunc['db_query']('', '
1019
+	} else {
1020
+			$smcFunc['db_query']('', '
962 1021
 			DELETE FROM {db_prefix}settings
963 1022
 			WHERE variable = {string:allow_sm_stats}',
964 1023
 			array(
@@ -966,6 +1025,7 @@  discard block
 block discarded – undo
966 1025
 				'db_error_skip' => true,
967 1026
 			)
968 1027
 		);
1028
+	}
969 1029
 
970 1030
 	// Deleting old karma stuff?
971 1031
 	if (!empty($_POST['delete_karma']))
@@ -980,20 +1040,22 @@  discard block
 block discarded – undo
980 1040
 		);
981 1041
 
982 1042
 		// Cleaning up old karma member settings.
983
-		if ($upcontext['karma_installed']['good'])
984
-			$smcFunc['db_query']('', '
1043
+		if ($upcontext['karma_installed']['good']) {
1044
+					$smcFunc['db_query']('', '
985 1045
 				ALTER TABLE {db_prefix}members
986 1046
 				DROP karma_good',
987 1047
 				array()
988 1048
 			);
1049
+		}
989 1050
 
990 1051
 		// Does karma bad was enable?
991
-		if ($upcontext['karma_installed']['bad'])
992
-			$smcFunc['db_query']('', '
1052
+		if ($upcontext['karma_installed']['bad']) {
1053
+					$smcFunc['db_query']('', '
993 1054
 				ALTER TABLE {db_prefix}members
994 1055
 				DROP karma_bad',
995 1056
 				array()
996 1057
 			);
1058
+		}
997 1059
 
998 1060
 		// Cleaning up old karma permissions.
999 1061
 		$smcFunc['db_query']('', '
@@ -1006,26 +1068,29 @@  discard block
 block discarded – undo
1006 1068
 	}
1007 1069
 
1008 1070
 	// Emptying the error log?
1009
-	if (!empty($_POST['empty_error']))
1010
-		$smcFunc['db_query']('truncate_table', '
1071
+	if (!empty($_POST['empty_error'])) {
1072
+			$smcFunc['db_query']('truncate_table', '
1011 1073
 			TRUNCATE {db_prefix}log_errors',
1012 1074
 			array(
1013 1075
 			)
1014 1076
 		);
1077
+	}
1015 1078
 
1016 1079
 	$changes = array();
1017 1080
 
1018 1081
 	// Add proxy settings.
1019
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1020
-		$changes += array(
1082
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1083
+			$changes += array(
1021 1084
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1022 1085
 			'image_proxy_maxsize' => 5190,
1023 1086
 			'image_proxy_enabled' => 0,
1024 1087
 		);
1088
+	}
1025 1089
 
1026 1090
 	// If we're overriding the language follow it through.
1027
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1028
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1091
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1092
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1093
+	}
1029 1094
 
1030 1095
 	if (!empty($_POST['maint']))
1031 1096
 	{
@@ -1037,30 +1102,34 @@  discard block
 block discarded – undo
1037 1102
 		{
1038 1103
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1039 1104
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1040
-		}
1041
-		else
1105
+		} else
1042 1106
 		{
1043 1107
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1044 1108
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1045 1109
 		}
1046 1110
 	}
1047 1111
 
1048
-	if ($command_line)
1049
-		echo ' * Updating Settings.php...';
1112
+	if ($command_line) {
1113
+			echo ' * Updating Settings.php...';
1114
+	}
1050 1115
 
1051 1116
 	// Fix some old paths.
1052
-	if (substr($boarddir, 0, 1) == '.')
1053
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1117
+	if (substr($boarddir, 0, 1) == '.') {
1118
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1119
+	}
1054 1120
 
1055
-	if (substr($sourcedir, 0, 1) == '.')
1056
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1121
+	if (substr($sourcedir, 0, 1) == '.') {
1122
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1123
+	}
1057 1124
 
1058
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1059
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1125
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1126
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1127
+	}
1060 1128
 
1061 1129
 	// Not had the database type added before?
1062
-	if (empty($db_type))
1063
-		$changes['db_type'] = 'mysql';
1130
+	if (empty($db_type)) {
1131
+			$changes['db_type'] = 'mysql';
1132
+	}
1064 1133
 
1065 1134
 	// If they have a "host:port" setup for the host, split that into separate values
1066 1135
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1071,32 +1140,36 @@  discard block
 block discarded – undo
1071 1140
 		$changes['db_server'] = '\'' . $db_server . '\'';
1072 1141
 
1073 1142
 		// Only set this if we're not using the default port
1074
-		if ($db_port != ini_get('mysqli.default_port'))
1075
-			$changes['db_port'] = (int) $db_port;
1076
-	}
1077
-	elseif (!empty($db_port))
1143
+		if ($db_port != ini_get('mysqli.default_port')) {
1144
+					$changes['db_port'] = (int) $db_port;
1145
+		}
1146
+	} elseif (!empty($db_port))
1078 1147
 	{
1079 1148
 		// If db_port is set and is the same as the default, set it to ''
1080 1149
 		if ($db_type == 'mysql')
1081 1150
 		{
1082
-			if ($db_port == ini_get('mysqli.default_port'))
1083
-				$changes['db_port'] = '\'\'';
1084
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1085
-				$changes['db_port'] = '\'\'';
1151
+			if ($db_port == ini_get('mysqli.default_port')) {
1152
+							$changes['db_port'] = '\'\'';
1153
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1154
+							$changes['db_port'] = '\'\'';
1155
+			}
1086 1156
 		}
1087 1157
 	}
1088 1158
 
1089 1159
 	// Maybe we haven't had this option yet?
1090
-	if (empty($packagesdir))
1091
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1160
+	if (empty($packagesdir)) {
1161
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1162
+	}
1092 1163
 
1093 1164
 	// Add support for $tasksdir var.
1094
-	if (empty($tasksdir))
1095
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1165
+	if (empty($tasksdir)) {
1166
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1167
+	}
1096 1168
 
1097 1169
 	// Make sure we fix the language as well.
1098
-	if (stristr($language, '-utf8'))
1099
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1170
+	if (stristr($language, '-utf8')) {
1171
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1172
+	}
1100 1173
 
1101 1174
 	// @todo Maybe change the cookie name if going to 1.1, too?
1102 1175
 
@@ -1104,8 +1177,9 @@  discard block
 block discarded – undo
1104 1177
 	require_once($sourcedir . '/Subs-Admin.php');
1105 1178
 	updateSettingsFile($changes);
1106 1179
 
1107
-	if ($command_line)
1108
-		echo ' Successful.' . "\n";
1180
+	if ($command_line) {
1181
+			echo ' Successful.' . "\n";
1182
+	}
1109 1183
 
1110 1184
 	// Are we doing debug?
1111 1185
 	if (isset($_POST['debug']))
@@ -1115,8 +1189,9 @@  discard block
 block discarded – undo
1115 1189
 	}
1116 1190
 
1117 1191
 	// If we're not backing up then jump one.
1118
-	if (empty($_POST['backup']))
1119
-		$upcontext['current_step']++;
1192
+	if (empty($_POST['backup'])) {
1193
+			$upcontext['current_step']++;
1194
+	}
1120 1195
 
1121 1196
 	// If we've got here then let's proceed to the next step!
1122 1197
 	return true;
@@ -1131,8 +1206,9 @@  discard block
 block discarded – undo
1131 1206
 	$upcontext['page_title'] = 'Backup Database';
1132 1207
 
1133 1208
 	// Done it already - js wise?
1134
-	if (!empty($_POST['backup_done']))
1135
-		return true;
1209
+	if (!empty($_POST['backup_done'])) {
1210
+			return true;
1211
+	}
1136 1212
 
1137 1213
 	// Some useful stuff here.
1138 1214
 	db_extend();
@@ -1146,9 +1222,10 @@  discard block
 block discarded – undo
1146 1222
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1147 1223
 
1148 1224
 	$table_names = array();
1149
-	foreach ($tables as $table)
1150
-		if (substr($table, 0, 7) !== 'backup_')
1225
+	foreach ($tables as $table) {
1226
+			if (substr($table, 0, 7) !== 'backup_')
1151 1227
 			$table_names[] = $table;
1228
+	}
1152 1229
 
1153 1230
 	$upcontext['table_count'] = count($table_names);
1154 1231
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1158,12 +1235,14 @@  discard block
 block discarded – undo
1158 1235
 	$file_steps = $upcontext['table_count'];
1159 1236
 
1160 1237
 	// What ones have we already done?
1161
-	foreach ($table_names as $id => $table)
1162
-		if ($id < $_GET['substep'])
1238
+	foreach ($table_names as $id => $table) {
1239
+			if ($id < $_GET['substep'])
1163 1240
 			$upcontext['previous_tables'][] = $table;
1241
+	}
1164 1242
 
1165
-	if ($command_line)
1166
-		echo 'Backing Up Tables.';
1243
+	if ($command_line) {
1244
+			echo 'Backing Up Tables.';
1245
+	}
1167 1246
 
1168 1247
 	// If we don't support javascript we backup here.
1169 1248
 	if (!$support_js || isset($_GET['xml']))
@@ -1182,8 +1261,9 @@  discard block
 block discarded – undo
1182 1261
 			backupTable($table_names[$substep]);
1183 1262
 
1184 1263
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1185
-			if (isset($_GET['xml']))
1186
-				return upgradeExit();
1264
+			if (isset($_GET['xml'])) {
1265
+							return upgradeExit();
1266
+			}
1187 1267
 		}
1188 1268
 
1189 1269
 		if ($command_line)
@@ -1216,9 +1296,10 @@  discard block
 block discarded – undo
1216 1296
 
1217 1297
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1218 1298
 
1219
-	if ($command_line)
1220
-		echo ' done.';
1221
-}
1299
+	if ($command_line) {
1300
+			echo ' done.';
1301
+	}
1302
+	}
1222 1303
 
1223 1304
 // Step 2: Everything.
1224 1305
 function DatabaseChanges()
@@ -1227,8 +1308,9 @@  discard block
 block discarded – undo
1227 1308
 	global $upcontext, $support_js, $db_type;
1228 1309
 
1229 1310
 	// Have we just completed this?
1230
-	if (!empty($_POST['database_done']))
1231
-		return true;
1311
+	if (!empty($_POST['database_done'])) {
1312
+			return true;
1313
+	}
1232 1314
 
1233 1315
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1234 1316
 	$upcontext['page_title'] = 'Database Changes';
@@ -1243,15 +1325,16 @@  discard block
 block discarded – undo
1243 1325
 	);
1244 1326
 
1245 1327
 	// How many files are there in total?
1246
-	if (isset($_GET['filecount']))
1247
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1248
-	else
1328
+	if (isset($_GET['filecount'])) {
1329
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1330
+	} else
1249 1331
 	{
1250 1332
 		$upcontext['file_count'] = 0;
1251 1333
 		foreach ($files as $file)
1252 1334
 		{
1253
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1254
-				$upcontext['file_count']++;
1335
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1336
+							$upcontext['file_count']++;
1337
+			}
1255 1338
 		}
1256 1339
 	}
1257 1340
 
@@ -1261,9 +1344,9 @@  discard block
 block discarded – undo
1261 1344
 	$upcontext['cur_file_num'] = 0;
1262 1345
 	foreach ($files as $file)
1263 1346
 	{
1264
-		if ($did_not_do)
1265
-			$did_not_do--;
1266
-		else
1347
+		if ($did_not_do) {
1348
+					$did_not_do--;
1349
+		} else
1267 1350
 		{
1268 1351
 			$upcontext['cur_file_num']++;
1269 1352
 			$upcontext['cur_file_name'] = $file[0];
@@ -1290,12 +1373,13 @@  discard block
 block discarded – undo
1290 1373
 					// Flag to move on to the next.
1291 1374
 					$upcontext['completed_step'] = true;
1292 1375
 					// Did we complete the whole file?
1293
-					if ($nextFile)
1294
-						$upcontext['current_debug_item_num'] = -1;
1376
+					if ($nextFile) {
1377
+											$upcontext['current_debug_item_num'] = -1;
1378
+					}
1295 1379
 					return upgradeExit();
1380
+				} elseif ($support_js) {
1381
+									break;
1296 1382
 				}
1297
-				elseif ($support_js)
1298
-					break;
1299 1383
 			}
1300 1384
 			// Set the progress bar to be right as if we had - even if we hadn't...
1301 1385
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1320,8 +1404,9 @@  discard block
 block discarded – undo
1320 1404
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1321 1405
 
1322 1406
 	// Now it's nice to have some of the basic SMF source files.
1323
-	if (!isset($_GET['ssi']) && !$command_line)
1324
-		redirectLocation('&ssi=1');
1407
+	if (!isset($_GET['ssi']) && !$command_line) {
1408
+			redirectLocation('&ssi=1');
1409
+	}
1325 1410
 
1326 1411
 	$upcontext['sub_template'] = 'upgrade_complete';
1327 1412
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1337,14 +1422,16 @@  discard block
 block discarded – undo
1337 1422
 	// Are we in maintenance mode?
1338 1423
 	if (isset($upcontext['user']['main']))
1339 1424
 	{
1340
-		if ($command_line)
1341
-			echo ' * ';
1425
+		if ($command_line) {
1426
+					echo ' * ';
1427
+		}
1342 1428
 		$upcontext['removed_maintenance'] = true;
1343 1429
 		$changes['maintenance'] = $upcontext['user']['main'];
1344 1430
 	}
1345 1431
 	// Otherwise if somehow we are in 2 let's go to 1.
1346
-	elseif (!empty($maintenance) && $maintenance == 2)
1347
-		$changes['maintenance'] = 1;
1432
+	elseif (!empty($maintenance) && $maintenance == 2) {
1433
+			$changes['maintenance'] = 1;
1434
+	}
1348 1435
 
1349 1436
 	// Wipe this out...
1350 1437
 	$upcontext['user'] = array();
@@ -1359,9 +1446,9 @@  discard block
 block discarded – undo
1359 1446
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1360 1447
 
1361 1448
 	// Now is the perfect time to fetch the SM files.
1362
-	if ($command_line)
1363
-		cli_scheduled_fetchSMfiles();
1364
-	else
1449
+	if ($command_line) {
1450
+			cli_scheduled_fetchSMfiles();
1451
+	} else
1365 1452
 	{
1366 1453
 		require_once($sourcedir . '/ScheduledTasks.php');
1367 1454
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1369,8 +1456,9 @@  discard block
 block discarded – undo
1369 1456
 	}
1370 1457
 
1371 1458
 	// Log what we've done.
1372
-	if (empty($user_info['id']))
1373
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1459
+	if (empty($user_info['id'])) {
1460
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1461
+	}
1374 1462
 
1375 1463
 	// Log the action manually, so CLI still works.
1376 1464
 	$smcFunc['db_insert']('',
@@ -1389,8 +1477,9 @@  discard block
 block discarded – undo
1389 1477
 
1390 1478
 	// Save the current database version.
1391 1479
 	$server_version = $smcFunc['db_server_info']();
1392
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1393
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1480
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1482
+	}
1394 1483
 
1395 1484
 	if ($command_line)
1396 1485
 	{
@@ -1402,8 +1491,9 @@  discard block
 block discarded – undo
1402 1491
 
1403 1492
 	// Make sure it says we're done.
1404 1493
 	$upcontext['overall_percent'] = 100;
1405
-	if (isset($upcontext['step_progress']))
1406
-		unset($upcontext['step_progress']);
1494
+	if (isset($upcontext['step_progress'])) {
1495
+			unset($upcontext['step_progress']);
1496
+	}
1407 1497
 
1408 1498
 	$_GET['substep'] = 0;
1409 1499
 	return false;
@@ -1414,8 +1504,9 @@  discard block
 block discarded – undo
1414 1504
 {
1415 1505
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1416 1506
 
1417
-	if (empty($modSettings['time_format']))
1418
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1507
+	if (empty($modSettings['time_format'])) {
1508
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1509
+	}
1419 1510
 
1420 1511
 	// What files do we want to get
1421 1512
 	$request = $smcFunc['db_query']('', '
@@ -1449,8 +1540,9 @@  discard block
 block discarded – undo
1449 1540
 		$file_data = fetch_web_data($url);
1450 1541
 
1451 1542
 		// If we got an error - give up - the site might be down.
1452
-		if ($file_data === false)
1453
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1543
+		if ($file_data === false) {
1544
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1545
+		}
1454 1546
 
1455 1547
 		// Save the file to the database.
1456 1548
 		$smcFunc['db_query']('substring', '
@@ -1492,8 +1584,9 @@  discard block
 block discarded – undo
1492 1584
 	$themeData = array();
1493 1585
 	foreach ($values as $variable => $value)
1494 1586
 	{
1495
-		if (!isset($value) || $value === null)
1496
-			$value = 0;
1587
+		if (!isset($value) || $value === null) {
1588
+					$value = 0;
1589
+		}
1497 1590
 
1498 1591
 		$themeData[] = array(0, 1, $variable, $value);
1499 1592
 	}
@@ -1522,8 +1615,9 @@  discard block
 block discarded – undo
1522 1615
 
1523 1616
 	foreach ($values as $variable => $value)
1524 1617
 	{
1525
-		if (empty($modSettings[$value[0]]))
1526
-			continue;
1618
+		if (empty($modSettings[$value[0]])) {
1619
+					continue;
1620
+		}
1527 1621
 
1528 1622
 		$smcFunc['db_query']('', '
1529 1623
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1609,10 +1703,11 @@  discard block
 block discarded – undo
1609 1703
 	set_error_handler(
1610 1704
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1611 1705
 		{
1612
-			if ($support_js)
1613
-				return true;
1614
-			else
1615
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1706
+			if ($support_js) {
1707
+							return true;
1708
+			} else {
1709
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1710
+			}
1616 1711
 		}
1617 1712
 	);
1618 1713
 
@@ -1627,8 +1722,9 @@  discard block
 block discarded – undo
1627 1722
 				'db_error_skip' => true,
1628 1723
 			)
1629 1724
 		);
1630
-		if ($smcFunc['db_num_rows']($request) === 0)
1631
-			die('Unable to find members table!');
1725
+		if ($smcFunc['db_num_rows']($request) === 0) {
1726
+					die('Unable to find members table!');
1727
+		}
1632 1728
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1633 1729
 		$smcFunc['db_free_result']($request);
1634 1730
 
@@ -1643,17 +1739,20 @@  discard block
 block discarded – undo
1643 1739
 				)
1644 1740
 			);
1645 1741
 			// Got something?
1646
-			if ($smcFunc['db_num_rows']($request) !== 0)
1647
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1742
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1743
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1744
+			}
1648 1745
 			$smcFunc['db_free_result']($request);
1649 1746
 
1650 1747
 			// Excellent!
1651
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1652
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1748
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1749
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1750
+			}
1653 1751
 		}
1654 1752
 	}
1655
-	if (empty($db_collation))
1656
-		$db_collation = '';
1753
+	if (empty($db_collation)) {
1754
+			$db_collation = '';
1755
+	}
1657 1756
 
1658 1757
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1659 1758
 
@@ -1665,8 +1764,9 @@  discard block
 block discarded – undo
1665 1764
 	$last_step = '';
1666 1765
 
1667 1766
 	// Make sure all newly created tables will have the proper characters set.
1668
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1669
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1767
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1768
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1769
+	}
1670 1770
 
1671 1771
 	// Count the total number of steps within this file - for progress.
1672 1772
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1686,15 +1786,18 @@  discard block
 block discarded – undo
1686 1786
 		$do_current = $substep >= $_GET['substep'];
1687 1787
 
1688 1788
 		// Get rid of any comments in the beginning of the line...
1689
-		if (substr(trim($line), 0, 2) === '/*')
1690
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1789
+		if (substr(trim($line), 0, 2) === '/*') {
1790
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1791
+		}
1691 1792
 
1692 1793
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1693
-		if ($is_debug && !$support_js && $command_line)
1694
-			flush();
1794
+		if ($is_debug && !$support_js && $command_line) {
1795
+					flush();
1796
+		}
1695 1797
 
1696
-		if (trim($line) === '')
1697
-			continue;
1798
+		if (trim($line) === '') {
1799
+					continue;
1800
+		}
1698 1801
 
1699 1802
 		if (trim(substr($line, 0, 3)) === '---')
1700 1803
 		{
@@ -1704,8 +1807,9 @@  discard block
 block discarded – undo
1704 1807
 			if (trim($current_data) != '' && $type !== '}')
1705 1808
 			{
1706 1809
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1707
-				if ($command_line)
1708
-					echo $upcontext['error_message'];
1810
+				if ($command_line) {
1811
+									echo $upcontext['error_message'];
1812
+				}
1709 1813
 			}
1710 1814
 
1711 1815
 			if ($type == ' ')
@@ -1723,17 +1827,18 @@  discard block
 block discarded – undo
1723 1827
 				if ($do_current)
1724 1828
 				{
1725 1829
 					$upcontext['actioned_items'][] = $last_step;
1726
-					if ($command_line)
1727
-						echo ' * ';
1830
+					if ($command_line) {
1831
+											echo ' * ';
1832
+					}
1728 1833
 				}
1729
-			}
1730
-			elseif ($type == '#')
1834
+			} elseif ($type == '#')
1731 1835
 			{
1732 1836
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1733 1837
 
1734 1838
 				$upcontext['current_debug_item_num']++;
1735
-				if (trim($line) != '---#')
1736
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1839
+				if (trim($line) != '---#') {
1840
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1841
+				}
1737 1842
 
1738 1843
 				// Have we already done something?
1739 1844
 				if (isset($_GET['xml']) && $done_something)
@@ -1744,34 +1849,36 @@  discard block
 block discarded – undo
1744 1849
 
1745 1850
 				if ($do_current)
1746 1851
 				{
1747
-					if (trim($line) == '---#' && $command_line)
1748
-						echo ' done.', $endl;
1749
-					elseif ($command_line)
1750
-						echo ' +++ ', rtrim(substr($line, 4));
1751
-					elseif (trim($line) != '---#')
1852
+					if (trim($line) == '---#' && $command_line) {
1853
+											echo ' done.', $endl;
1854
+					} elseif ($command_line) {
1855
+											echo ' +++ ', rtrim(substr($line, 4));
1856
+					} elseif (trim($line) != '---#')
1752 1857
 					{
1753
-						if ($is_debug)
1754
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1858
+						if ($is_debug) {
1859
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1860
+						}
1755 1861
 					}
1756 1862
 				}
1757 1863
 
1758 1864
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1759 1865
 				{
1760
-					if ($command_line)
1761
-						echo ' * ';
1762
-					else
1763
-						$upcontext['actioned_items'][] = $last_step;
1866
+					if ($command_line) {
1867
+											echo ' * ';
1868
+					} else {
1869
+											$upcontext['actioned_items'][] = $last_step;
1870
+					}
1764 1871
 				}
1765 1872
 
1766 1873
 				// Small step - only if we're actually doing stuff.
1767
-				if ($do_current)
1768
-					nextSubstep(++$substep);
1769
-				else
1770
-					$substep++;
1771
-			}
1772
-			elseif ($type == '{')
1773
-				$current_type = 'code';
1774
-			elseif ($type == '}')
1874
+				if ($do_current) {
1875
+									nextSubstep(++$substep);
1876
+				} else {
1877
+									$substep++;
1878
+				}
1879
+			} elseif ($type == '{') {
1880
+							$current_type = 'code';
1881
+			} elseif ($type == '}')
1775 1882
 			{
1776 1883
 				$current_type = 'sql';
1777 1884
 
@@ -1784,8 +1891,9 @@  discard block
 block discarded – undo
1784 1891
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1785 1892
 				{
1786 1893
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1787
-					if ($command_line)
1788
-						echo $upcontext['error_message'];
1894
+					if ($command_line) {
1895
+											echo $upcontext['error_message'];
1896
+					}
1789 1897
 				}
1790 1898
 
1791 1899
 				// Done with code!
@@ -1865,8 +1973,9 @@  discard block
 block discarded – undo
1865 1973
 	$db_unbuffered = false;
1866 1974
 
1867 1975
 	// Failure?!
1868
-	if ($result !== false)
1869
-		return $result;
1976
+	if ($result !== false) {
1977
+			return $result;
1978
+	}
1870 1979
 
1871 1980
 	$db_error_message = $smcFunc['db_error']($db_connection);
1872 1981
 	// If MySQL we do something more clever.
@@ -1894,54 +2003,61 @@  discard block
 block discarded – undo
1894 2003
 			{
1895 2004
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1896 2005
 				$result = mysqli_query($db_connection, $string);
1897
-				if ($result !== false)
1898
-					return $result;
2006
+				if ($result !== false) {
2007
+									return $result;
2008
+				}
1899 2009
 			}
1900
-		}
1901
-		elseif ($mysqli_errno == 2013)
2010
+		} elseif ($mysqli_errno == 2013)
1902 2011
 		{
1903 2012
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1904 2013
 			mysqli_select_db($db_connection, $db_name);
1905 2014
 			if ($db_connection)
1906 2015
 			{
1907 2016
 				$result = mysqli_query($db_connection, $string);
1908
-				if ($result !== false)
1909
-					return $result;
2017
+				if ($result !== false) {
2018
+									return $result;
2019
+				}
1910 2020
 			}
1911 2021
 		}
1912 2022
 		// Duplicate column name... should be okay ;).
1913
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1914
-			return false;
2023
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2024
+					return false;
2025
+		}
1915 2026
 		// Duplicate insert... make sure it's the proper type of query ;).
1916
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1917
-			return false;
2027
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2028
+					return false;
2029
+		}
1918 2030
 		// Creating an index on a non-existent column.
1919
-		elseif ($mysqli_errno == 1072)
1920
-			return false;
1921
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1922
-			return false;
2031
+		elseif ($mysqli_errno == 1072) {
2032
+					return false;
2033
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2034
+					return false;
2035
+		}
1923 2036
 	}
1924 2037
 	// If a table already exists don't go potty.
1925 2038
 	else
1926 2039
 	{
1927 2040
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1928 2041
 		{
1929
-			if (strpos($db_error_message, 'exist') !== false)
1930
-				return true;
1931
-		}
1932
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2042
+			if (strpos($db_error_message, 'exist') !== false) {
2043
+							return true;
2044
+			}
2045
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1933 2046
 		{
1934
-			if (strpos($db_error_message, 'duplicate') !== false)
1935
-				return true;
2047
+			if (strpos($db_error_message, 'duplicate') !== false) {
2048
+							return true;
2049
+			}
1936 2050
 		}
1937 2051
 	}
1938 2052
 
1939 2053
 	// Get the query string so we pass everything.
1940 2054
 	$query_string = '';
1941
-	foreach ($_GET as $k => $v)
1942
-		$query_string .= ';' . $k . '=' . $v;
1943
-	if (strlen($query_string) != 0)
1944
-		$query_string = '?' . substr($query_string, 1);
2055
+	foreach ($_GET as $k => $v) {
2056
+			$query_string .= ';' . $k . '=' . $v;
2057
+	}
2058
+	if (strlen($query_string) != 0) {
2059
+			$query_string = '?' . substr($query_string, 1);
2060
+	}
1945 2061
 
1946 2062
 	if ($command_line)
1947 2063
 	{
@@ -1996,16 +2112,18 @@  discard block
 block discarded – undo
1996 2112
 			{
1997 2113
 				$found |= 1;
1998 2114
 				// Do some checks on the data if we have it set.
1999
-				if (isset($change['col_type']))
2000
-					$found &= $change['col_type'] === $column['type'];
2001
-				if (isset($change['null_allowed']))
2002
-					$found &= $column['null'] == $change['null_allowed'];
2003
-				if (isset($change['default']))
2004
-					$found &= $change['default'] === $column['default'];
2115
+				if (isset($change['col_type'])) {
2116
+									$found &= $change['col_type'] === $column['type'];
2117
+				}
2118
+				if (isset($change['null_allowed'])) {
2119
+									$found &= $column['null'] == $change['null_allowed'];
2120
+				}
2121
+				if (isset($change['default'])) {
2122
+									$found &= $change['default'] === $column['default'];
2123
+				}
2005 2124
 			}
2006 2125
 		}
2007
-	}
2008
-	elseif ($change['type'] === 'index')
2126
+	} elseif ($change['type'] === 'index')
2009 2127
 	{
2010 2128
 		$request = upgrade_query('
2011 2129
 			SHOW INDEX
@@ -2014,9 +2132,10 @@  discard block
 block discarded – undo
2014 2132
 		{
2015 2133
 			$cur_index = array();
2016 2134
 
2017
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2018
-				if ($row['Key_name'] === $change['name'])
2135
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2136
+							if ($row['Key_name'] === $change['name'])
2019 2137
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2138
+			}
2020 2139
 
2021 2140
 			ksort($cur_index, SORT_NUMERIC);
2022 2141
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2026,14 +2145,17 @@  discard block
 block discarded – undo
2026 2145
 	}
2027 2146
 
2028 2147
 	// If we're trying to add and it's added, we're done.
2029
-	if ($found && in_array($change['method'], array('add', 'change')))
2030
-		return true;
2148
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2149
+			return true;
2150
+	}
2031 2151
 	// Otherwise if we're removing and it wasn't found we're also done.
2032
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2033
-		return true;
2152
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2153
+			return true;
2154
+	}
2034 2155
 	// Otherwise is it just a test?
2035
-	elseif ($is_test)
2036
-		return false;
2156
+	elseif ($is_test) {
2157
+			return false;
2158
+	}
2037 2159
 
2038 2160
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2039 2161
 	$running = false;
@@ -2044,8 +2166,9 @@  discard block
 block discarded – undo
2044 2166
 			SHOW FULL PROCESSLIST');
2045 2167
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2046 2168
 		{
2047
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2048
-				$found = true;
2169
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2170
+							$found = true;
2171
+			}
2049 2172
 		}
2050 2173
 
2051 2174
 		// Can't find it? Then we need to run it fools!
@@ -2057,8 +2180,9 @@  discard block
 block discarded – undo
2057 2180
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2058 2181
 				' . $change['text'], true) !== false;
2059 2182
 
2060
-			if (!$success)
2061
-				return false;
2183
+			if (!$success) {
2184
+							return false;
2185
+			}
2062 2186
 
2063 2187
 			// Return
2064 2188
 			$running = true;
@@ -2100,8 +2224,9 @@  discard block
 block discarded – undo
2100 2224
 			'db_error_skip' => true,
2101 2225
 		)
2102 2226
 	);
2103
-	if ($smcFunc['db_num_rows']($request) === 0)
2104
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2227
+	if ($smcFunc['db_num_rows']($request) === 0) {
2228
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2229
+	}
2105 2230
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2106 2231
 	$smcFunc['db_free_result']($request);
2107 2232
 
@@ -2123,18 +2248,19 @@  discard block
 block discarded – undo
2123 2248
 			)
2124 2249
 		);
2125 2250
 		// No results? Just forget it all together.
2126
-		if ($smcFunc['db_num_rows']($request) === 0)
2127
-			unset($table_row['Collation']);
2128
-		else
2129
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2251
+		if ($smcFunc['db_num_rows']($request) === 0) {
2252
+					unset($table_row['Collation']);
2253
+		} else {
2254
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2255
+		}
2130 2256
 		$smcFunc['db_free_result']($request);
2131 2257
 	}
2132 2258
 
2133 2259
 	if ($column_fix)
2134 2260
 	{
2135 2261
 		// Make sure there are no NULL's left.
2136
-		if ($null_fix)
2137
-			$smcFunc['db_query']('', '
2262
+		if ($null_fix) {
2263
+					$smcFunc['db_query']('', '
2138 2264
 				UPDATE {db_prefix}' . $change['table'] . '
2139 2265
 				SET ' . $change['column'] . ' = {string:default}
2140 2266
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2143,6 +2269,7 @@  discard block
 block discarded – undo
2143 2269
 					'db_error_skip' => true,
2144 2270
 				)
2145 2271
 			);
2272
+		}
2146 2273
 
2147 2274
 		// Do the actual alteration.
2148 2275
 		$smcFunc['db_query']('', '
@@ -2171,8 +2298,9 @@  discard block
 block discarded – undo
2171 2298
 	}
2172 2299
 
2173 2300
 	// Not a column we need to check on?
2174
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2175
-		return;
2301
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2302
+			return;
2303
+	}
2176 2304
 
2177 2305
 	// Break it up you (six|seven).
2178 2306
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2191,13 +2319,13 @@  discard block
 block discarded – undo
2191 2319
 				'new_name' => $temp[2],
2192 2320
 		));
2193 2321
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2194
-		if ($smcFunc['db_num_rows'] != 1)
2195
-			return;
2322
+		if ($smcFunc['db_num_rows'] != 1) {
2323
+					return;
2324
+		}
2196 2325
 
2197 2326
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2198 2327
 		$smcFunc['db_free_result']($request);
2199
-	}
2200
-	else
2328
+	} else
2201 2329
 	{
2202 2330
 		// Do this the old fashion, sure method way.
2203 2331
 		$request = $smcFunc['db_query']('', '
@@ -2208,21 +2336,24 @@  discard block
 block discarded – undo
2208 2336
 		));
2209 2337
 		// Mayday!
2210 2338
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2211
-		if ($smcFunc['db_num_rows'] == 0)
2212
-			return;
2339
+		if ($smcFunc['db_num_rows'] == 0) {
2340
+					return;
2341
+		}
2213 2342
 
2214 2343
 		// Oh where, oh where has my little field gone. Oh where can it be...
2215
-		while ($row = $smcFunc['db_query']($request))
2216
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2344
+		while ($row = $smcFunc['db_query']($request)) {
2345
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2217 2346
 			{
2218 2347
 				$current_type = $row['Type'];
2348
+		}
2219 2349
 				break;
2220 2350
 			}
2221 2351
 	}
2222 2352
 
2223 2353
 	// If this doesn't match, the column may of been altered for a reason.
2224
-	if (trim($current_type) != trim($temp[3]))
2225
-		$temp[3] = $current_type;
2354
+	if (trim($current_type) != trim($temp[3])) {
2355
+			$temp[3] = $current_type;
2356
+	}
2226 2357
 
2227 2358
 	// Piece this back together.
2228 2359
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2234,8 +2365,9 @@  discard block
 block discarded – undo
2234 2365
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2235 2366
 	global $step_progress, $is_debug, $upcontext;
2236 2367
 
2237
-	if ($_GET['substep'] < $substep)
2238
-		$_GET['substep'] = $substep;
2368
+	if ($_GET['substep'] < $substep) {
2369
+			$_GET['substep'] = $substep;
2370
+	}
2239 2371
 
2240 2372
 	if ($command_line)
2241 2373
 	{
@@ -2248,29 +2380,33 @@  discard block
 block discarded – undo
2248 2380
 	}
2249 2381
 
2250 2382
 	@set_time_limit(300);
2251
-	if (function_exists('apache_reset_timeout'))
2252
-		@apache_reset_timeout();
2383
+	if (function_exists('apache_reset_timeout')) {
2384
+			@apache_reset_timeout();
2385
+	}
2253 2386
 
2254
-	if (time() - $start_time <= $timeLimitThreshold)
2255
-		return;
2387
+	if (time() - $start_time <= $timeLimitThreshold) {
2388
+			return;
2389
+	}
2256 2390
 
2257 2391
 	// Do we have some custom step progress stuff?
2258 2392
 	if (!empty($step_progress))
2259 2393
 	{
2260 2394
 		$upcontext['substep_progress'] = 0;
2261 2395
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2262
-		if ($step_progress['current'] > $step_progress['total'])
2263
-			$upcontext['substep_progress'] = 99.9;
2264
-		else
2265
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2396
+		if ($step_progress['current'] > $step_progress['total']) {
2397
+					$upcontext['substep_progress'] = 99.9;
2398
+		} else {
2399
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2400
+		}
2266 2401
 
2267 2402
 		// Make it nicely rounded.
2268 2403
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2269 2404
 	}
2270 2405
 
2271 2406
 	// If this is XML we just exit right away!
2272
-	if (isset($_GET['xml']))
2273
-		return upgradeExit();
2407
+	if (isset($_GET['xml'])) {
2408
+			return upgradeExit();
2409
+	}
2274 2410
 
2275 2411
 	// We're going to pause after this!
2276 2412
 	$upcontext['pause'] = true;
@@ -2278,13 +2414,15 @@  discard block
 block discarded – undo
2278 2414
 	$upcontext['query_string'] = '';
2279 2415
 	foreach ($_GET as $k => $v)
2280 2416
 	{
2281
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2282
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2417
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2418
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2419
+		}
2283 2420
 	}
2284 2421
 
2285 2422
 	// Custom warning?
2286
-	if (!empty($custom_warning))
2287
-		$upcontext['custom_warning'] = $custom_warning;
2423
+	if (!empty($custom_warning)) {
2424
+			$upcontext['custom_warning'] = $custom_warning;
2425
+	}
2288 2426
 
2289 2427
 	upgradeExit();
2290 2428
 }
@@ -2299,25 +2437,26 @@  discard block
 block discarded – undo
2299 2437
 	ob_implicit_flush(true);
2300 2438
 	@set_time_limit(600);
2301 2439
 
2302
-	if (!isset($_SERVER['argv']))
2303
-		$_SERVER['argv'] = array();
2440
+	if (!isset($_SERVER['argv'])) {
2441
+			$_SERVER['argv'] = array();
2442
+	}
2304 2443
 	$_GET['maint'] = 1;
2305 2444
 
2306 2445
 	foreach ($_SERVER['argv'] as $i => $arg)
2307 2446
 	{
2308
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2309
-			$_GET['lang'] = $match[1];
2310
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2311
-			continue;
2312
-		elseif ($arg == '--no-maintenance')
2313
-			$_GET['maint'] = 0;
2314
-		elseif ($arg == '--debug')
2315
-			$is_debug = true;
2316
-		elseif ($arg == '--backup')
2317
-			$_POST['backup'] = 1;
2318
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2319
-			$_GET['conv'] = 1;
2320
-		elseif ($i != 0)
2447
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2448
+					$_GET['lang'] = $match[1];
2449
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2450
+					continue;
2451
+		} elseif ($arg == '--no-maintenance') {
2452
+					$_GET['maint'] = 0;
2453
+		} elseif ($arg == '--debug') {
2454
+					$is_debug = true;
2455
+		} elseif ($arg == '--backup') {
2456
+					$_POST['backup'] = 1;
2457
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2458
+					$_GET['conv'] = 1;
2459
+		} elseif ($i != 0)
2321 2460
 		{
2322 2461
 			echo 'SMF Command-line Upgrader
2323 2462
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2331,10 +2470,12 @@  discard block
 block discarded – undo
2331 2470
 		}
2332 2471
 	}
2333 2472
 
2334
-	if (!php_version_check())
2335
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2336
-	if (!db_version_check())
2337
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2473
+	if (!php_version_check()) {
2474
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2475
+	}
2476
+	if (!db_version_check()) {
2477
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2478
+	}
2338 2479
 
2339 2480
 	// Do some checks to make sure they have proper privileges
2340 2481
 	db_extend('packages');
@@ -2349,34 +2490,39 @@  discard block
 block discarded – undo
2349 2490
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2350 2491
 
2351 2492
 	// Sorry... we need CREATE, ALTER and DROP
2352
-	if (!$create || !$alter || !$drop)
2353
-		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);
2493
+	if (!$create || !$alter || !$drop) {
2494
+			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);
2495
+	}
2354 2496
 
2355 2497
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2356 2498
 		&& @file_exists($sourcedir . '/QueryString.php')
2357 2499
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2358
-	if (!$check && !isset($modSettings['smfVersion']))
2359
-		print_error('Error: Some files are missing or out-of-date.', true);
2500
+	if (!$check && !isset($modSettings['smfVersion'])) {
2501
+			print_error('Error: Some files are missing or out-of-date.', true);
2502
+	}
2360 2503
 
2361 2504
 	// Do a quick version spot check.
2362 2505
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2363 2506
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2364
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2365
-		print_error('Error: Some files have not yet been updated properly.');
2507
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2508
+			print_error('Error: Some files have not yet been updated properly.');
2509
+	}
2366 2510
 
2367 2511
 	// Make sure Settings.php is writable.
2368 2512
 		quickFileWritable($boarddir . '/Settings.php');
2369
-	if (!is_writable($boarddir . '/Settings.php'))
2370
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2513
+	if (!is_writable($boarddir . '/Settings.php')) {
2514
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2515
+	}
2371 2516
 
2372 2517
 	// Make sure Settings_bak.php is writable.
2373 2518
 		quickFileWritable($boarddir . '/Settings_bak.php');
2374
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2375
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2519
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2520
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2521
+	}
2376 2522
 
2377
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2378
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2379
-	elseif (isset($modSettings['agreement']))
2523
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2524
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2525
+	} elseif (isset($modSettings['agreement']))
2380 2526
 	{
2381 2527
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2382 2528
 		fwrite($fp, $modSettings['agreement']);
@@ -2386,31 +2532,36 @@  discard block
 block discarded – undo
2386 2532
 	// Make sure Themes is writable.
2387 2533
 	quickFileWritable($modSettings['theme_dir']);
2388 2534
 
2389
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2390
-		print_error('Error: Unable to obtain write access to "Themes".');
2535
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2536
+			print_error('Error: Unable to obtain write access to "Themes".');
2537
+	}
2391 2538
 
2392 2539
 	// Make sure cache directory exists and is writable!
2393 2540
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2394
-	if (!file_exists($cachedir_temp))
2395
-		@mkdir($cachedir_temp);
2541
+	if (!file_exists($cachedir_temp)) {
2542
+			@mkdir($cachedir_temp);
2543
+	}
2396 2544
 
2397 2545
 	// Make sure the cache temp dir is writable.
2398 2546
 	quickFileWritable($cachedir_temp);
2399 2547
 
2400
-	if (!is_writable($cachedir_temp))
2401
-		print_error('Error: Unable to obtain write access to "cache".', true);
2548
+	if (!is_writable($cachedir_temp)) {
2549
+			print_error('Error: Unable to obtain write access to "cache".', true);
2550
+	}
2402 2551
 
2403
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2404
-		print_error('Error: Unable to find language files!', true);
2405
-	else
2552
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2553
+			print_error('Error: Unable to find language files!', true);
2554
+	} else
2406 2555
 	{
2407 2556
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2408 2557
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2409 2558
 
2410
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2411
-			print_error('Error: Language files out of date.', true);
2412
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2413
-			print_error('Error: Install language is missing for selected language.', true);
2559
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2560
+					print_error('Error: Language files out of date.', true);
2561
+		}
2562
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2563
+					print_error('Error: Install language is missing for selected language.', true);
2564
+		}
2414 2565
 
2415 2566
 		// Otherwise include it!
2416 2567
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2439,8 +2590,7 @@  discard block
 block discarded – undo
2439 2590
 		);
2440 2591
 
2441 2592
 		return true;
2442
-	}
2443
-	else
2593
+	} else
2444 2594
 	{
2445 2595
 		$upcontext['page_title'] = 'Converting to UTF8';
2446 2596
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2484,8 +2634,9 @@  discard block
 block discarded – undo
2484 2634
 			)
2485 2635
 		);
2486 2636
 		$db_charsets = array();
2487
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2488
-			$db_charsets[] = $row['Charset'];
2637
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2638
+					$db_charsets[] = $row['Charset'];
2639
+		}
2489 2640
 
2490 2641
 		$smcFunc['db_free_result']($request);
2491 2642
 
@@ -2521,13 +2672,15 @@  discard block
 block discarded – undo
2521 2672
 		// If there's a fulltext index, we need to drop it first...
2522 2673
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2523 2674
 		{
2524
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2525
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2675
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2676
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2526 2677
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2678
+			}
2527 2679
 			$smcFunc['db_free_result']($request);
2528 2680
 
2529
-			if (isset($upcontext['fulltext_index']))
2530
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2681
+			if (isset($upcontext['fulltext_index'])) {
2682
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2683
+			}
2531 2684
 		}
2532 2685
 
2533 2686
 		// Drop it and make a note...
@@ -2717,8 +2870,9 @@  discard block
 block discarded – undo
2717 2870
 			$replace = '%field%';
2718 2871
 
2719 2872
 			// Build a huge REPLACE statement...
2720
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2721
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2873
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2874
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2875
+			}
2722 2876
 		}
2723 2877
 
2724 2878
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2752,8 +2906,9 @@  discard block
 block discarded – undo
2752 2906
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2753 2907
 
2754 2908
 			// Just to make sure it doesn't time out.
2755
-			if (function_exists('apache_reset_timeout'))
2756
-				@apache_reset_timeout();
2909
+			if (function_exists('apache_reset_timeout')) {
2910
+							@apache_reset_timeout();
2911
+			}
2757 2912
 
2758 2913
 			$table_charsets = array();
2759 2914
 
@@ -2774,8 +2929,9 @@  discard block
 block discarded – undo
2774 2929
 					{
2775 2930
 						list($charset) = explode('_', $collation);
2776 2931
 
2777
-						if (!isset($table_charsets[$charset]))
2778
-							$table_charsets[$charset] = array();
2932
+						if (!isset($table_charsets[$charset])) {
2933
+													$table_charsets[$charset] = array();
2934
+						}
2779 2935
 
2780 2936
 						$table_charsets[$charset][] = $column_info;
2781 2937
 					}
@@ -2815,10 +2971,11 @@  discard block
 block discarded – undo
2815 2971
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2816 2972
 				{
2817 2973
 					$update = '';
2818
-					foreach ($table_charsets as $charset => $columns)
2819
-						foreach ($columns as $column)
2974
+					foreach ($table_charsets as $charset => $columns) {
2975
+											foreach ($columns as $column)
2820 2976
 							$update .= '
2821 2977
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2978
+					}
2822 2979
 
2823 2980
 					$smcFunc['db_query']('', '
2824 2981
 						UPDATE {raw:table_name}
@@ -2843,8 +3000,9 @@  discard block
 block discarded – undo
2843 3000
 			// Now do the actual conversion (if still needed).
2844 3001
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2845 3002
 			{
2846
-				if ($command_line)
2847
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3003
+				if ($command_line) {
3004
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3005
+				}
2848 3006
 
2849 3007
 				$smcFunc['db_query']('', '
2850 3008
 					ALTER TABLE {raw:table_name}
@@ -2854,8 +3012,9 @@  discard block
 block discarded – undo
2854 3012
 					)
2855 3013
 				);
2856 3014
 
2857
-				if ($command_line)
2858
-					echo " done.\n";
3015
+				if ($command_line) {
3016
+									echo " done.\n";
3017
+				}
2859 3018
 			}
2860 3019
 		}
2861 3020
 
@@ -2885,8 +3044,8 @@  discard block
 block discarded – undo
2885 3044
 		);
2886 3045
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2887 3046
 		{
2888
-			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)
2889
-				$smcFunc['db_query']('', '
3047
+			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) {
3048
+							$smcFunc['db_query']('', '
2890 3049
 					UPDATE {db_prefix}log_actions
2891 3050
 					SET extra = {string:extra}
2892 3051
 					WHERE id_action = {int:current_action}',
@@ -2895,6 +3054,7 @@  discard block
 block discarded – undo
2895 3054
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2896 3055
 					)
2897 3056
 				);
3057
+			}
2898 3058
 		}
2899 3059
 		$smcFunc['db_free_result']($request);
2900 3060
 
@@ -2916,15 +3076,17 @@  discard block
 block discarded – undo
2916 3076
 	// First thing's first - did we already do this?
2917 3077
 	if (!empty($modSettings['json_done']))
2918 3078
 	{
2919
-		if ($command_line)
2920
-			return DeleteUpgrade();
2921
-		else
2922
-			return true;
3079
+		if ($command_line) {
3080
+					return DeleteUpgrade();
3081
+		} else {
3082
+					return true;
3083
+		}
2923 3084
 	}
2924 3085
 
2925 3086
 	// Done it already - js wise?
2926
-	if (!empty($_POST['json_done']))
2927
-		return true;
3087
+	if (!empty($_POST['json_done'])) {
3088
+			return true;
3089
+	}
2928 3090
 
2929 3091
 	// List of tables affected by this function
2930 3092
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2955,12 +3117,14 @@  discard block
 block discarded – undo
2955 3117
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2956 3118
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2957 3119
 
2958
-	foreach ($keys as $id => $table)
2959
-		if ($id < $_GET['substep'])
3120
+	foreach ($keys as $id => $table) {
3121
+			if ($id < $_GET['substep'])
2960 3122
 			$upcontext['previous_tables'][] = $table;
3123
+	}
2961 3124
 
2962
-	if ($command_line)
2963
-		echo 'Converting data from serialize() to json_encode().';
3125
+	if ($command_line) {
3126
+			echo 'Converting data from serialize() to json_encode().';
3127
+	}
2964 3128
 
2965 3129
 	if (!$support_js || isset($_GET['xml']))
2966 3130
 	{
@@ -3000,8 +3164,9 @@  discard block
 block discarded – undo
3000 3164
 
3001 3165
 				// Loop through and fix these...
3002 3166
 				$new_settings = array();
3003
-				if ($command_line)
3004
-					echo "\n" . 'Fixing some settings...';
3167
+				if ($command_line) {
3168
+									echo "\n" . 'Fixing some settings...';
3169
+				}
3005 3170
 
3006 3171
 				foreach ($serialized_settings as $var)
3007 3172
 				{
@@ -3009,22 +3174,24 @@  discard block
 block discarded – undo
3009 3174
 					{
3010 3175
 						// Attempt to unserialize the setting
3011 3176
 						$temp = @safe_unserialize($modSettings[$var]);
3012
-						if (!$temp && $command_line)
3013
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3014
-						elseif ($temp !== false)
3015
-							$new_settings[$var] = json_encode($temp);
3177
+						if (!$temp && $command_line) {
3178
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3179
+						} elseif ($temp !== false) {
3180
+													$new_settings[$var] = json_encode($temp);
3181
+						}
3016 3182
 					}
3017 3183
 				}
3018 3184
 
3019 3185
 				// Update everything at once
3020
-				if (!function_exists('cache_put_data'))
3021
-					require_once($sourcedir . '/Load.php');
3186
+				if (!function_exists('cache_put_data')) {
3187
+									require_once($sourcedir . '/Load.php');
3188
+				}
3022 3189
 				updateSettings($new_settings, true);
3023 3190
 
3024
-				if ($command_line)
3025
-					echo ' done.';
3026
-			}
3027
-			elseif ($table == 'themes')
3191
+				if ($command_line) {
3192
+									echo ' done.';
3193
+				}
3194
+			} elseif ($table == 'themes')
3028 3195
 			{
3029 3196
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3030 3197
 				$query = $smcFunc['db_query']('', '
@@ -3043,10 +3210,11 @@  discard block
 block discarded – undo
3043 3210
 
3044 3211
 						if ($command_line)
3045 3212
 						{
3046
-							if ($temp === false)
3047
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3048
-							else
3049
-								echo "\n" . 'Fixing admin preferences...';
3213
+							if ($temp === false) {
3214
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3215
+							} else {
3216
+															echo "\n" . 'Fixing admin preferences...';
3217
+							}
3050 3218
 						}
3051 3219
 
3052 3220
 						if ($temp !== false)
@@ -3068,15 +3236,15 @@  discard block
 block discarded – undo
3068 3236
 								)
3069 3237
 							);
3070 3238
 
3071
-							if ($command_line)
3072
-								echo ' done.';
3239
+							if ($command_line) {
3240
+															echo ' done.';
3241
+							}
3073 3242
 						}
3074 3243
 					}
3075 3244
 
3076 3245
 					$smcFunc['db_free_result']($query);
3077 3246
 				}
3078
-			}
3079
-			else
3247
+			} else
3080 3248
 			{
3081 3249
 				// First item is always the key...
3082 3250
 				$key = $info[0];
@@ -3087,8 +3255,7 @@  discard block
 block discarded – undo
3087 3255
 				{
3088 3256
 					$col_select = $info[1];
3089 3257
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3090
-				}
3091
-				else
3258
+				} else
3092 3259
 				{
3093 3260
 					$col_select = implode(', ', $info);
3094 3261
 				}
@@ -3121,8 +3288,7 @@  discard block
 block discarded – undo
3121 3288
 								if ($temp === false && $command_line)
3122 3289
 								{
3123 3290
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3124
-								}
3125
-								else
3291
+								} else
3126 3292
 								{
3127 3293
 									$row[$col] = json_encode($temp);
3128 3294
 
@@ -3147,16 +3313,18 @@  discard block
 block discarded – undo
3147 3313
 						}
3148 3314
 					}
3149 3315
 
3150
-					if ($command_line)
3151
-						echo ' done.';
3316
+					if ($command_line) {
3317
+											echo ' done.';
3318
+					}
3152 3319
 
3153 3320
 					// Free up some memory...
3154 3321
 					$smcFunc['db_free_result']($query);
3155 3322
 				}
3156 3323
 			}
3157 3324
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3158
-			if (isset($_GET['xml']))
3159
-				return upgradeExit();
3325
+			if (isset($_GET['xml'])) {
3326
+							return upgradeExit();
3327
+			}
3160 3328
 		}
3161 3329
 
3162 3330
 		if ($command_line)
@@ -3171,8 +3339,9 @@  discard block
 block discarded – undo
3171 3339
 
3172 3340
 		$_GET['substep'] = 0;
3173 3341
 		// Make sure we move on!
3174
-		if ($command_line)
3175
-			return DeleteUpgrade();
3342
+		if ($command_line) {
3343
+					return DeleteUpgrade();
3344
+		}
3176 3345
 
3177 3346
 		return true;
3178 3347
 	}
@@ -3192,14 +3361,16 @@  discard block
 block discarded – undo
3192 3361
 	global $upcontext, $txt, $settings;
3193 3362
 
3194 3363
 	// Don't call me twice!
3195
-	if (!empty($upcontext['chmod_called']))
3196
-		return;
3364
+	if (!empty($upcontext['chmod_called'])) {
3365
+			return;
3366
+	}
3197 3367
 
3198 3368
 	$upcontext['chmod_called'] = true;
3199 3369
 
3200 3370
 	// Nothing?
3201
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3202
-		return;
3371
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3372
+			return;
3373
+	}
3203 3374
 
3204 3375
 	// Was it a problem with Windows?
3205 3376
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3231,11 +3402,12 @@  discard block
 block discarded – undo
3231 3402
 					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\');
3232 3403
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3233 3404
 
3234
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3235
-		echo '
3405
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3406
+			echo '
3236 3407
 					content.write(\'<hr>\n\t\t\t\');
3237 3408
 					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\');
3238 3409
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3410
+	}
3239 3411
 
3240 3412
 	echo '
3241 3413
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3243,17 +3415,19 @@  discard block
 block discarded – undo
3243 3415
 				}
3244 3416
 		</script>';
3245 3417
 
3246
-	if (!empty($upcontext['chmod']['ftp_error']))
3247
-		echo '
3418
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3419
+			echo '
3248 3420
 			<div class="error_message red">
3249 3421
 				The following error was encountered when trying to connect:<br><br>
3250 3422
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3251 3423
 			</div>
3252 3424
 			<br>';
3425
+	}
3253 3426
 
3254
-	if (empty($upcontext['chmod_in_form']))
3255
-		echo '
3427
+	if (empty($upcontext['chmod_in_form'])) {
3428
+			echo '
3256 3429
 	<form action="', $upcontext['form_url'], '" method="post">';
3430
+	}
3257 3431
 
3258 3432
 	echo '
3259 3433
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3288,10 +3462,11 @@  discard block
 block discarded – undo
3288 3462
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3289 3463
 	</div>';
3290 3464
 
3291
-	if (empty($upcontext['chmod_in_form']))
3292
-		echo '
3465
+	if (empty($upcontext['chmod_in_form'])) {
3466
+			echo '
3293 3467
 	</form>';
3294
-}
3468
+	}
3469
+	}
3295 3470
 
3296 3471
 function template_upgrade_above()
3297 3472
 {
@@ -3351,9 +3526,10 @@  discard block
 block discarded – undo
3351 3526
 				<h2>', $txt['upgrade_progress'], '</h2>
3352 3527
 				<ul>';
3353 3528
 
3354
-	foreach ($upcontext['steps'] as $num => $step)
3355
-		echo '
3529
+	foreach ($upcontext['steps'] as $num => $step) {
3530
+			echo '
3356 3531
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3532
+	}
3357 3533
 
3358 3534
 	echo '
3359 3535
 					</ul>
@@ -3366,8 +3542,8 @@  discard block
 block discarded – undo
3366 3542
 				</div>
3367 3543
 			</div>';
3368 3544
 
3369
-	if (isset($upcontext['step_progress']))
3370
-		echo '
3545
+	if (isset($upcontext['step_progress'])) {
3546
+			echo '
3371 3547
 				<br>
3372 3548
 				<br>
3373 3549
 				<div id="progress_bar_step">
@@ -3376,6 +3552,7 @@  discard block
 block discarded – undo
3376 3552
 						<span>', $txt['upgrade_step_progress'], '</span>
3377 3553
 					</div>
3378 3554
 				</div>';
3555
+	}
3379 3556
 
3380 3557
 	echo '
3381 3558
 				<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>
@@ -3406,32 +3583,36 @@  discard block
 block discarded – undo
3406 3583
 {
3407 3584
 	global $upcontext, $txt;
3408 3585
 
3409
-	if (!empty($upcontext['pause']))
3410
-		echo '
3586
+	if (!empty($upcontext['pause'])) {
3587
+			echo '
3411 3588
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3412 3589
 
3413 3590
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3414 3591
 								<h3>
3415 3592
 									', $txt['upgrade_paused_overload'], '
3416 3593
 								</h3>';
3594
+	}
3417 3595
 
3418
-	if (!empty($upcontext['custom_warning']))
3419
-		echo '
3596
+	if (!empty($upcontext['custom_warning'])) {
3597
+			echo '
3420 3598
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3421 3599
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3422 3600
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3423 3601
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3424 3602
 								</div>';
3603
+	}
3425 3604
 
3426 3605
 	echo '
3427 3606
 								<div class="righttext" style="margin: 1ex;">';
3428 3607
 
3429
-	if (!empty($upcontext['continue']))
3430
-		echo '
3608
+	if (!empty($upcontext['continue'])) {
3609
+			echo '
3431 3610
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3432
-	if (!empty($upcontext['skip']))
3433
-		echo '
3611
+	}
3612
+	if (!empty($upcontext['skip'])) {
3613
+			echo '
3434 3614
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3615
+	}
3435 3616
 
3436 3617
 	echo '
3437 3618
 								</div>
@@ -3481,11 +3662,12 @@  discard block
 block discarded – undo
3481 3662
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3482 3663
 	<smf>';
3483 3664
 
3484
-	if (!empty($upcontext['get_data']))
3485
-		foreach ($upcontext['get_data'] as $k => $v)
3665
+	if (!empty($upcontext['get_data'])) {
3666
+			foreach ($upcontext['get_data'] as $k => $v)
3486 3667
 			echo '
3487 3668
 		<get key="', $k, '">', $v, '</get>';
3488
-}
3669
+	}
3670
+	}
3489 3671
 
3490 3672
 function template_xml_below()
3491 3673
 {
@@ -3526,8 +3708,8 @@  discard block
 block discarded – undo
3526 3708
 	template_chmod();
3527 3709
 
3528 3710
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3529
-	if ($upcontext['is_large_forum'])
3530
-		echo '
3711
+	if ($upcontext['is_large_forum']) {
3712
+			echo '
3531 3713
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3532 3714
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3533 3715
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3535,10 +3717,11 @@  discard block
 block discarded – undo
3535 3717
 				', $txt['upgrade_warning_lots_data'], '
3536 3718
 			</div>
3537 3719
 		</div>';
3720
+	}
3538 3721
 
3539 3722
 	// A warning message?
3540
-	if (!empty($upcontext['warning']))
3541
-		echo '
3723
+	if (!empty($upcontext['warning'])) {
3724
+			echo '
3542 3725
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3543 3726
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3544 3727
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3546,6 +3729,7 @@  discard block
 block discarded – undo
3546 3729
 				', $upcontext['warning'], '
3547 3730
 			</div>
3548 3731
 		</div>';
3732
+	}
3549 3733
 
3550 3734
 	// Paths are incorrect?
3551 3735
 	echo '
@@ -3561,20 +3745,22 @@  discard block
 block discarded – undo
3561 3745
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3562 3746
 	{
3563 3747
 		$ago = time() - $upcontext['started'];
3564
-		if ($ago < 60)
3565
-			$ago = $ago . ' seconds';
3566
-		elseif ($ago < 3600)
3567
-			$ago = (int) ($ago / 60) . ' minutes';
3568
-		else
3569
-			$ago = (int) ($ago / 3600) . ' hours';
3748
+		if ($ago < 60) {
3749
+					$ago = $ago . ' seconds';
3750
+		} elseif ($ago < 3600) {
3751
+					$ago = (int) ($ago / 60) . ' minutes';
3752
+		} else {
3753
+					$ago = (int) ($ago / 3600) . ' hours';
3754
+		}
3570 3755
 
3571 3756
 		$active = time() - $upcontext['updated'];
3572
-		if ($active < 60)
3573
-			$updated = $active . ' seconds';
3574
-		elseif ($active < 3600)
3575
-			$updated = (int) ($active / 60) . ' minutes';
3576
-		else
3577
-			$updated = (int) ($active / 3600) . ' hours';
3757
+		if ($active < 60) {
3758
+					$updated = $active . ' seconds';
3759
+		} elseif ($active < 3600) {
3760
+					$updated = (int) ($active / 60) . ' minutes';
3761
+		} else {
3762
+					$updated = (int) ($active / 3600) . ' hours';
3763
+		}
3578 3764
 
3579 3765
 		echo '
3580 3766
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3583,16 +3769,18 @@  discard block
 block discarded – undo
3583 3769
 			<div style="padding-left: 6ex;">
3584 3770
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3585 3771
 
3586
-		if ($active < 600)
3587
-			echo '
3772
+		if ($active < 600) {
3773
+					echo '
3588 3774
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3775
+		}
3589 3776
 
3590
-		if ($active > $upcontext['inactive_timeout'])
3591
-			echo '
3777
+		if ($active > $upcontext['inactive_timeout']) {
3778
+					echo '
3592 3779
 				<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.';
3593
-		else
3594
-			echo '
3780
+		} else {
3781
+					echo '
3595 3782
 				<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!');
3783
+		}
3596 3784
 
3597 3785
 		echo '
3598 3786
 			</div>
@@ -3608,9 +3796,10 @@  discard block
 block discarded – undo
3608 3796
 					<td>
3609 3797
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3610 3798
 
3611
-	if (!empty($upcontext['username_incorrect']))
3612
-		echo '
3799
+	if (!empty($upcontext['username_incorrect'])) {
3800
+			echo '
3613 3801
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3802
+	}
3614 3803
 
3615 3804
 	echo '
3616 3805
 					</td>
@@ -3621,9 +3810,10 @@  discard block
 block discarded – undo
3621 3810
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3622 3811
 						<input type="hidden" name="hash_passwrd" value="">';
3623 3812
 
3624
-	if (!empty($upcontext['password_failed']))
3625
-		echo '
3813
+	if (!empty($upcontext['password_failed'])) {
3814
+			echo '
3626 3815
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3816
+	}
3627 3817
 
3628 3818
 	echo '
3629 3819
 					</td>
@@ -3694,8 +3884,8 @@  discard block
 block discarded – undo
3694 3884
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3695 3885
 
3696 3886
 	// Warning message?
3697
-	if (!empty($upcontext['upgrade_options_warning']))
3698
-		echo '
3887
+	if (!empty($upcontext['upgrade_options_warning'])) {
3888
+			echo '
3699 3889
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3700 3890
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3701 3891
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3703,6 +3893,7 @@  discard block
 block discarded – undo
3703 3893
 				', $upcontext['upgrade_options_warning'], '
3704 3894
 			</div>
3705 3895
 		</div>';
3896
+	}
3706 3897
 
3707 3898
 	echo '
3708 3899
 				<table>
@@ -3745,8 +3936,8 @@  discard block
 block discarded – undo
3745 3936
 						</td>
3746 3937
 					</tr>';
3747 3938
 
3748
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3749
-		echo '
3939
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3940
+			echo '
3750 3941
 					<tr valign="top">
3751 3942
 						<td width="2%">
3752 3943
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3755,6 +3946,7 @@  discard block
 block discarded – undo
3755 3946
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3756 3947
 						</td>
3757 3948
 					</tr>';
3949
+	}
3758 3950
 
3759 3951
 	echo '
3760 3952
 					<tr valign="top">
@@ -3792,10 +3984,11 @@  discard block
 block discarded – undo
3792 3984
 			</div>';
3793 3985
 
3794 3986
 	// Dont any tables so far?
3795
-	if (!empty($upcontext['previous_tables']))
3796
-		foreach ($upcontext['previous_tables'] as $table)
3987
+	if (!empty($upcontext['previous_tables'])) {
3988
+			foreach ($upcontext['previous_tables'] as $table)
3797 3989
 			echo '
3798 3990
 			<br>Completed Table: &quot;', $table, '&quot;.';
3991
+	}
3799 3992
 
3800 3993
 	echo '
3801 3994
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3832,12 +4025,13 @@  discard block
 block discarded – undo
3832 4025
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3833 4026
 
3834 4027
 		// If debug flood the screen.
3835
-		if ($is_debug)
3836
-			echo '
4028
+		if ($is_debug) {
4029
+					echo '
3837 4030
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3838 4031
 
3839 4032
 				if (document.getElementById(\'debug_section\').scrollHeight)
3840 4033
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4034
+		}
3841 4035
 
3842 4036
 		echo '
3843 4037
 				// Get the next update...
@@ -3869,8 +4063,9 @@  discard block
 block discarded – undo
3869 4063
 {
3870 4064
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3871 4065
 
3872
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3873
-		$is_debug = true;
4066
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4067
+			$is_debug = true;
4068
+	}
3874 4069
 
3875 4070
 	echo '
3876 4071
 		<h3>Executing database changes</h3>
@@ -3885,8 +4080,9 @@  discard block
 block discarded – undo
3885 4080
 	{
3886 4081
 		foreach ($upcontext['actioned_items'] as $num => $item)
3887 4082
 		{
3888
-			if ($num != 0)
3889
-				echo ' Successful!';
4083
+			if ($num != 0) {
4084
+							echo ' Successful!';
4085
+			}
3890 4086
 			echo '<br>' . $item;
3891 4087
 		}
3892 4088
 		if (!empty($upcontext['changes_complete']))
@@ -3899,28 +4095,32 @@  discard block
 block discarded – undo
3899 4095
 				$seconds = intval($active % 60);
3900 4096
 
3901 4097
 				$totalTime = '';
3902
-				if ($hours > 0)
3903
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3904
-				if ($minutes > 0)
3905
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3906
-				if ($seconds > 0)
3907
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4098
+				if ($hours > 0) {
4099
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4100
+				}
4101
+				if ($minutes > 0) {
4102
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4103
+				}
4104
+				if ($seconds > 0) {
4105
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4106
+				}
3908 4107
 			}
3909 4108
 
3910
-			if ($is_debug && !empty($totalTime))
3911
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3912
-			else
3913
-				echo ' Successful!<br><br>';
4109
+			if ($is_debug && !empty($totalTime)) {
4110
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4111
+			} else {
4112
+							echo ' Successful!<br><br>';
4113
+			}
3914 4114
 
3915 4115
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3916 4116
 		}
3917
-	}
3918
-	else
4117
+	} else
3919 4118
 	{
3920 4119
 		// Tell them how many files we have in total.
3921
-		if ($upcontext['file_count'] > 1)
3922
-			echo '
4120
+		if ($upcontext['file_count'] > 1) {
4121
+					echo '
3923 4122
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4123
+		}
3924 4124
 
3925 4125
 		echo '
3926 4126
 		<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>
@@ -3936,19 +4136,23 @@  discard block
 block discarded – undo
3936 4136
 				$seconds = intval($active % 60);
3937 4137
 
3938 4138
 				$totalTime = '';
3939
-				if ($hours > 0)
3940
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3941
-				if ($minutes > 0)
3942
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3943
-				if ($seconds > 0)
3944
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4139
+				if ($hours > 0) {
4140
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4141
+				}
4142
+				if ($minutes > 0) {
4143
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4144
+				}
4145
+				if ($seconds > 0) {
4146
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4147
+				}
3945 4148
 			}
3946 4149
 
3947 4150
 			echo '
3948 4151
 			<br><span id="upgradeCompleted">';
3949 4152
 
3950
-			if (!empty($totalTime))
3951
-				echo 'Completed in ', $totalTime, '<br>';
4153
+			if (!empty($totalTime)) {
4154
+							echo 'Completed in ', $totalTime, '<br>';
4155
+			}
3952 4156
 
3953 4157
 			echo '</span>
3954 4158
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3985,9 +4189,10 @@  discard block
 block discarded – undo
3985 4189
 			var getData = "";
3986 4190
 			var debugItems = ', $upcontext['debug_items'], ';';
3987 4191
 
3988
-		if ($is_debug)
3989
-			echo '
4192
+		if ($is_debug) {
4193
+					echo '
3990 4194
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4195
+		}
3991 4196
 
3992 4197
 		echo '
3993 4198
 			function getNextItem()
@@ -4027,9 +4232,10 @@  discard block
 block discarded – undo
4027 4232
 						document.getElementById("error_block").style.display = "";
4028 4233
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4029 4234
 
4030
-	if ($is_debug)
4031
-		echo '
4235
+	if ($is_debug) {
4236
+			echo '
4032 4237
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4238
+	}
4033 4239
 
4034 4240
 	echo '
4035 4241
 					}
@@ -4050,9 +4256,10 @@  discard block
 block discarded – undo
4050 4256
 						document.getElementById("error_block").style.display = "";
4051 4257
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4052 4258
 
4053
-	if ($is_debug)
4054
-		echo '
4259
+	if ($is_debug) {
4260
+			echo '
4055 4261
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4262
+	}
4056 4263
 
4057 4264
 	echo '
4058 4265
 					}
@@ -4111,8 +4318,8 @@  discard block
 block discarded – undo
4111 4318
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4112 4319
 				{';
4113 4320
 
4114
-		if ($is_debug)
4115
-			echo '
4321
+		if ($is_debug) {
4322
+					echo '
4116 4323
 					document.getElementById(\'debug_section\').style.display = "none";
4117 4324
 
4118 4325
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4130,6 +4337,7 @@  discard block
 block discarded – undo
4130 4337
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4131 4338
 
4132 4339
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4340
+		}
4133 4341
 
4134 4342
 		echo '
4135 4343
 
@@ -4137,9 +4345,10 @@  discard block
 block discarded – undo
4137 4345
 					document.getElementById(\'contbutt\').disabled = 0;
4138 4346
 					document.getElementById(\'database_done\').value = 1;';
4139 4347
 
4140
-		if ($upcontext['file_count'] > 1)
4141
-			echo '
4348
+		if ($upcontext['file_count'] > 1) {
4349
+					echo '
4142 4350
 					document.getElementById(\'info1\').style.display = "none";';
4351
+		}
4143 4352
 
4144 4353
 		echo '
4145 4354
 					document.getElementById(\'info2\').style.display = "none";
@@ -4152,9 +4361,10 @@  discard block
 block discarded – undo
4152 4361
 					lastItem = 0;
4153 4362
 					prevFile = curFile;';
4154 4363
 
4155
-		if ($is_debug)
4156
-			echo '
4364
+		if ($is_debug) {
4365
+					echo '
4157 4366
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4367
+		}
4158 4368
 
4159 4369
 		echo '
4160 4370
 					getNextItem();
@@ -4162,8 +4372,8 @@  discard block
 block discarded – undo
4162 4372
 				}';
4163 4373
 
4164 4374
 		// If debug scroll the screen.
4165
-		if ($is_debug)
4166
-			echo '
4375
+		if ($is_debug) {
4376
+					echo '
4167 4377
 				if (iLastSubStepProgress == -1)
4168 4378
 				{
4169 4379
 					// Give it consistent dots.
@@ -4182,6 +4392,7 @@  discard block
 block discarded – undo
4182 4392
 
4183 4393
 				if (document.getElementById(\'debug_section\').scrollHeight)
4184 4394
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4395
+		}
4185 4396
 
4186 4397
 		echo '
4187 4398
 				// Update the page.
@@ -4242,9 +4453,10 @@  discard block
 block discarded – undo
4242 4453
 			}';
4243 4454
 
4244 4455
 		// Start things off assuming we've not errored.
4245
-		if (empty($upcontext['error_message']))
4246
-			echo '
4456
+		if (empty($upcontext['error_message'])) {
4457
+					echo '
4247 4458
 			getNextItem();';
4459
+		}
4248 4460
 
4249 4461
 		echo '
4250 4462
 		</script>';
@@ -4261,18 +4473,21 @@  discard block
 block discarded – undo
4261 4473
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4262 4474
 	<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>';
4263 4475
 
4264
-	if (!empty($upcontext['error_message']))
4265
-		echo '
4476
+	if (!empty($upcontext['error_message'])) {
4477
+			echo '
4266 4478
 	<error>', $upcontext['error_message'], '</error>';
4479
+	}
4267 4480
 
4268
-	if (!empty($upcontext['error_string']))
4269
-		echo '
4481
+	if (!empty($upcontext['error_string'])) {
4482
+			echo '
4270 4483
 	<sql>', $upcontext['error_string'], '</sql>';
4484
+	}
4271 4485
 
4272
-	if ($is_debug)
4273
-		echo '
4486
+	if ($is_debug) {
4487
+			echo '
4274 4488
 	<curtime>', time(), '</curtime>';
4275
-}
4489
+	}
4490
+	}
4276 4491
 
4277 4492
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4278 4493
 function template_convert_utf8()
@@ -4289,18 +4504,20 @@  discard block
 block discarded – undo
4289 4504
 			<span id="debuginfo"></span>';
4290 4505
 
4291 4506
 	// Done any tables so far?
4292
-	if (!empty($upcontext['previous_tables']))
4293
-		foreach ($upcontext['previous_tables'] as $table)
4507
+	if (!empty($upcontext['previous_tables'])) {
4508
+			foreach ($upcontext['previous_tables'] as $table)
4294 4509
 			echo '
4295 4510
 			<br>Completed Table: &quot;', $table, '&quot;.';
4511
+	}
4296 4512
 
4297 4513
 	echo '
4298 4514
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4299 4515
 
4300 4516
 	// If we dropped their index, let's let them know
4301
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4302
-		echo '
4517
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4518
+			echo '
4303 4519
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4520
+	}
4304 4521
 
4305 4522
 	echo '
4306 4523
 			<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>';
@@ -4336,9 +4553,10 @@  discard block
 block discarded – undo
4336 4553
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4337 4554
 
4338 4555
 		// If debug flood the screen.
4339
-		if ($is_debug)
4340
-			echo '
4556
+		if ($is_debug) {
4557
+					echo '
4341 4558
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4559
+		}
4342 4560
 
4343 4561
 		echo '
4344 4562
 				// Get the next update...
@@ -4380,19 +4598,21 @@  discard block
 block discarded – undo
4380 4598
 			<span id="debuginfo"></span>';
4381 4599
 
4382 4600
 	// Dont any tables so far?
4383
-	if (!empty($upcontext['previous_tables']))
4384
-		foreach ($upcontext['previous_tables'] as $table)
4601
+	if (!empty($upcontext['previous_tables'])) {
4602
+			foreach ($upcontext['previous_tables'] as $table)
4385 4603
 			echo '
4386 4604
 			<br>Completed Table: &quot;', $table, '&quot;.';
4605
+	}
4387 4606
 
4388 4607
 	echo '
4389 4608
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4390 4609
 			<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>';
4391 4610
 
4392 4611
 	// Try to make sure substep was reset.
4393
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4394
-		echo '
4612
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4613
+			echo '
4395 4614
 			<input type="hidden" name="substep" id="substep" value="0">';
4615
+	}
4396 4616
 
4397 4617
 	// Continue please!
4398 4618
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4425,9 +4645,10 @@  discard block
 block discarded – undo
4425 4645
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4426 4646
 
4427 4647
 		// If debug flood the screen.
4428
-		if ($is_debug)
4429
-			echo '
4648
+		if ($is_debug) {
4649
+					echo '
4430 4650
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4651
+		}
4431 4652
 
4432 4653
 		echo '
4433 4654
 				// Get the next update...
@@ -4462,8 +4683,8 @@  discard block
 block discarded – undo
4462 4683
 	<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>
4463 4684
 	<form action="', $boardurl, '/index.php">';
4464 4685
 
4465
-	if (!empty($upcontext['can_delete_script']))
4466
-		echo '
4686
+	if (!empty($upcontext['can_delete_script'])) {
4687
+			echo '
4467 4688
 			<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>
4468 4689
 			<script>
4469 4690
 				function doTheDelete(theCheck)
@@ -4475,6 +4696,7 @@  discard block
 block discarded – undo
4475 4696
 				}
4476 4697
 			</script>
4477 4698
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4699
+	}
4478 4700
 
4479 4701
 	$active = time() - $upcontext['started'];
4480 4702
 	$hours = floor($active / 3600);
@@ -4484,16 +4706,20 @@  discard block
 block discarded – undo
4484 4706
 	if ($is_debug)
4485 4707
 	{
4486 4708
 		$totalTime = '';
4487
-		if ($hours > 0)
4488
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4489
-		if ($minutes > 0)
4490
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4491
-		if ($seconds > 0)
4492
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4709
+		if ($hours > 0) {
4710
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4711
+		}
4712
+		if ($minutes > 0) {
4713
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4714
+		}
4715
+		if ($seconds > 0) {
4716
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4717
+		}
4493 4718
 	}
4494 4719
 
4495
-	if ($is_debug && !empty($totalTime))
4496
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4720
+	if ($is_debug && !empty($totalTime)) {
4721
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4722
+	}
4497 4723
 
4498 4724
 	echo '<br>
4499 4725
 			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>
@@ -4560,16 +4786,19 @@  discard block
 block discarded – undo
4560 4786
 				'empty' => '',
4561 4787
 				'limit' => $limit,
4562 4788
 		));
4563
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4564
-			$arIp[] = $row[$oldCol];
4789
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4790
+					$arIp[] = $row[$oldCol];
4791
+		}
4565 4792
 		$smcFunc['db_free_result']($request);
4566 4793
 
4567 4794
 		// Special case, null ip could keep us in a loop.
4568
-		if (is_null($arIp[0]))
4569
-			unset($arIp[0]);
4795
+		if (is_null($arIp[0])) {
4796
+					unset($arIp[0]);
4797
+		}
4570 4798
 
4571
-		if (empty($arIp))
4572
-			$is_done = true;
4799
+		if (empty($arIp)) {
4800
+					$is_done = true;
4801
+		}
4573 4802
 
4574 4803
 		$updates = array();
4575 4804
 		$cases = array();
@@ -4578,16 +4807,18 @@  discard block
 block discarded – undo
4578 4807
 		{
4579 4808
 			$arIp[$i] = trim($arIp[$i]);
4580 4809
 
4581
-			if (empty($arIp[$i]))
4582
-				continue;
4810
+			if (empty($arIp[$i])) {
4811
+							continue;
4812
+			}
4583 4813
 
4584 4814
 			$updates['ip' . $i] = $arIp[$i];
4585 4815
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4586 4816
 
4587 4817
 			if ($setSize > 0 && $i % $setSize === 0)
4588 4818
 			{
4589
-				if (count($updates) == 1)
4590
-					continue;
4819
+				if (count($updates) == 1) {
4820
+									continue;
4821
+				}
4591 4822
 
4592 4823
 				$updates['whereSet'] = array_values($updates);
4593 4824
 				$smcFunc['db_query']('', '
@@ -4621,8 +4852,7 @@  discard block
 block discarded – undo
4621 4852
 							'ip' => $ip
4622 4853
 					));
4623 4854
 				}
4624
-			}
4625
-			else
4855
+			} else
4626 4856
 			{
4627 4857
 				$updates['whereSet'] = array_values($updates);
4628 4858
 				$smcFunc['db_query']('', '
@@ -4636,9 +4866,9 @@  discard block
 block discarded – undo
4636 4866
 					$updates
4637 4867
 				);
4638 4868
 			}
4869
+		} else {
4870
+					$is_done = true;
4639 4871
 		}
4640
-		else
4641
-			$is_done = true;
4642 4872
 
4643 4873
 		$_GET['a'] += $limit;
4644 4874
 		$step_progress['current'] = $_GET['a'];
@@ -4664,10 +4894,11 @@  discard block
 block discarded – undo
4664 4894
  
4665 4895
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4666 4896
 
4667
-	if (isset($columns[$column]))
4668
-		return $columns[$column];
4669
-	else
4670
-		return null;
4671
-}
4897
+	if (isset($columns[$column])) {
4898
+			return $columns[$column];
4899
+	} else {
4900
+			return null;
4901
+	}
4902
+	}
4672 4903
 
4673 4904
 ?>
4674 4905
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/GenericControls.template.php 1 patch
Braces   +76 added lines, -58 removed lines patch added patch discarded remove patch
@@ -53,14 +53,15 @@  discard block
 block discarded – undo
53 53
 			foreach ($context['smileys'] as $location => $smileyRows)
54 54
 			{
55 55
 				$countLocations--;
56
-				if ($location == 'postform')
57
-					echo '
56
+				if ($location == 'postform') {
57
+									echo '
58 58
 						dropdown:
59 59
 						{';
60
-				elseif ($location == 'popup')
61
-					echo '
60
+				} elseif ($location == 'popup') {
61
+									echo '
62 62
 						popup:
63 63
 						{';
64
+				}
64 65
 
65 66
 				$numRows = count($smileyRows);
66 67
 				// This is needed because otherwise the editor will remove all the duplicate (empty) keys and leave only 1 additional line
@@ -72,21 +73,22 @@  discard block
 block discarded – undo
72 73
 						echo '
73 74
 								', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), empty($smiley['isLast']) ? ',' : '';
74 75
 					}
75
-					if (empty($smileyRow['isLast']) && $numRows != 1)
76
-						echo ',
76
+					if (empty($smileyRow['isLast']) && $numRows != 1) {
77
+											echo ',
77 78
 						\'-', $emptyPlaceholder++, '\': \'\',';
79
+					}
78 80
 				}
79 81
 				echo '
80 82
 						}', $countLocations != 0 ? ',' : '';
81 83
 			}
82 84
 			echo '
83 85
 					}';
84
-		}
85
-		else
86
-			echo ',
86
+		} else {
87
+					echo ',
87 88
 					emoticons:
88 89
 					{},
89 90
 					emoticonsEnabled:false';
91
+		}
90 92
 
91 93
 		if ($context['show_bbc'] && $bbcContainer !== null)
92 94
 		{
@@ -97,15 +99,16 @@  discard block
 block discarded – undo
97 99
 			{
98 100
 				echo implode('|', $buttonRow);
99 101
 				$count_tags--;
100
-				if (!empty($count_tags))
101
-					echo '||';
102
+				if (!empty($count_tags)) {
103
+									echo '||';
104
+				}
102 105
 			}
103 106
 
104 107
 			echo '",';
105
-		}
106
-		else
107
-			echo ',
108
+		} else {
109
+					echo ',
108 110
 					toolbar: "",';
111
+		}
109 112
 
110 113
 		echo '
111 114
 				});
@@ -146,43 +149,48 @@  discard block
 block discarded – undo
146 149
 		</span>';
147 150
 
148 151
 	$tempTab = $context['tabindex'];
149
-	if (!empty($context['drafts_pm_save']))
150
-		$tempTab++;
151
-	elseif (!empty($context['drafts_save']))
152
-		$tempTab++;
153
-	elseif ($editor_context['preview_type'])
154
-		$tempTab++;
155
-	elseif ($context['show_spellchecking'])
156
-		$tempTab++;
152
+	if (!empty($context['drafts_pm_save'])) {
153
+			$tempTab++;
154
+	} elseif (!empty($context['drafts_save'])) {
155
+			$tempTab++;
156
+	} elseif ($editor_context['preview_type']) {
157
+			$tempTab++;
158
+	} elseif ($context['show_spellchecking']) {
159
+			$tempTab++;
160
+	}
157 161
 
158 162
 	$tempTab++;
159 163
 	$context['tabindex'] = $tempTab;
160 164
 
161
-	if (!empty($context['drafts_pm_save']))
162
-		echo '
165
+	if (!empty($context['drafts_pm_save'])) {
166
+			echo '
163 167
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="submitThisOnce(this);" accesskey="d" class="button_submit">
164 168
 		<input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '">';
169
+	}
165 170
 
166
-	if (!empty($context['drafts_save']))
167
-		echo '
171
+	if (!empty($context['drafts_save'])) {
172
+			echo '
168 173
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button_submit">
169 174
 		<input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '">';
175
+	}
170 176
 
171
-	if ($context['show_spellchecking'])
172
-		echo '
177
+	if ($context['show_spellchecking']) {
178
+			echo '
173 179
 		<input type="button" value="', $txt['spell_check'], '" tabindex="', --$tempTab, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit">';
180
+	}
174 181
 
175
-	if ($editor_context['preview_type'])
176
-		echo '
182
+	if ($editor_context['preview_type']) {
183
+			echo '
177 184
 		<input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', --$tempTab, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button_submit">';
185
+	}
178 186
 
179 187
 
180 188
 	echo '
181 189
 		<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" name="post" tabindex="', --$tempTab, '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit">';
182 190
 
183 191
 	// Load in the PM autosaver if it's enabled
184
-	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave']))
185
-		echo '
192
+	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) {
193
+			echo '
186 194
 		<span class="righttext padding" style="display: block">
187 195
 			<span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon">&nbsp;</span>
188 196
 			<span id="draft_lastautosave" ></span>
@@ -200,10 +208,11 @@  discard block
 block discarded – undo
200 208
 				iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), '
201 209
 			});
202 210
 		</script>';
211
+	}
203 212
 
204 213
 	// Start an instance of the auto saver if its enabled
205
-	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave']))
206
-		echo '
214
+	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) {
215
+			echo '
207 216
 		<span class="righttext padding" style="display: block">
208 217
 			<span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon">&nbsp;</span>
209 218
 			<span id="draft_lastautosave" ></span>
@@ -220,7 +229,8 @@  discard block
 block discarded – undo
220 229
 				iFreq: ', $context['drafts_autosave_frequency'], '
221 230
 			});
222 231
 		</script>';
223
-}
232
+	}
233
+	}
224 234
 
225 235
 /**
226 236
  * This template displays a verification form
@@ -237,51 +247,57 @@  discard block
 block discarded – undo
237 247
 	$verify_context = &$context['controls']['verification'][$verify_id];
238 248
 
239 249
 	// Keep track of where we are.
240
-	if (empty($verify_context['tracking']) || $reset)
241
-		$verify_context['tracking'] = 0;
250
+	if (empty($verify_context['tracking']) || $reset) {
251
+			$verify_context['tracking'] = 0;
252
+	}
242 253
 
243 254
 	// How many items are there to display in total.
244 255
 	$total_items = count($verify_context['questions']) + ($verify_context['show_visual'] || $verify_context['can_recaptcha'] ? 1 : 0);
245 256
 
246 257
 	// If we've gone too far, stop.
247
-	if ($verify_context['tracking'] > $total_items)
248
-		return false;
258
+	if ($verify_context['tracking'] > $total_items) {
259
+			return false;
260
+	}
249 261
 
250 262
 	// Loop through each item to show them.
251 263
 	for ($i = 0; $i < $total_items; $i++)
252 264
 	{
253 265
 		// If we're after a single item only show it if we're in the right place.
254
-		if ($display_type == 'single' && $verify_context['tracking'] != $i)
255
-			continue;
266
+		if ($display_type == 'single' && $verify_context['tracking'] != $i) {
267
+					continue;
268
+		}
256 269
 
257
-		if ($display_type != 'single')
258
-			echo '
270
+		if ($display_type != 'single') {
271
+					echo '
259 272
 			<div id="verification_control_', $i, '" class="verification_control">';
273
+		}
260 274
 
261 275
 		// Display empty field, but only if we have one, and it's the first time.
262
-		if ($verify_context['empty_field'] && empty($i))
263
-			echo '
276
+		if ($verify_context['empty_field'] && empty($i)) {
277
+					echo '
264 278
 				<div class="smalltext vv_special">
265 279
 					', $txt['visual_verification_hidden'], ':
266 280
 					<input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value="">
267 281
 				</div>';
282
+		}
268 283
 
269 284
 		// Do the actual stuff
270 285
 		if ($i == 0 && ($verify_context['show_visual'] || $verify_context['can_recaptcha']))
271 286
 		{
272 287
 			if ($verify_context['show_visual'])
273 288
 			{
274
-				if ($context['use_graphic_library'])
275
-					echo '
289
+				if ($context['use_graphic_library']) {
290
+									echo '
276 291
 				<img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '">';
277
-				else
278
-					echo '
292
+				} else {
293
+									echo '
279 294
 				<img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1">
280 295
 				<img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2">
281 296
 				<img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3">
282 297
 				<img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4">
283 298
 				<img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5">
284 299
 				<img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6">';
300
+				}
285 301
 
286 302
 				echo '
287 303
 				<div class="smalltext" style="margin: 4px 0 8px 0;">
@@ -297,8 +313,7 @@  discard block
 block discarded – undo
297 313
 				<div class="g-recaptcha centertext" data-sitekey="' . $verify_context['recaptcha_site_key'] . '" data-theme="' . $verify_context['recaptcha_theme'] . '"></div><br>
298 314
 				<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>';
299 315
 			}
300
-		}
301
-		else
316
+		} else
302 317
 		{
303 318
 			// Where in the question array is this question?
304 319
 			$qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
@@ -310,21 +325,24 @@  discard block
 block discarded – undo
310 325
 				</div>';
311 326
 		}
312 327
 
313
-		if ($display_type != 'single')
314
-			echo '
328
+		if ($display_type != 'single') {
329
+					echo '
315 330
 			</div>';
331
+		}
316 332
 
317 333
 		// If we were displaying just one and we did it, break.
318
-		if ($display_type == 'single' && $verify_context['tracking'] == $i)
319
-			break;
334
+		if ($display_type == 'single' && $verify_context['tracking'] == $i) {
335
+					break;
336
+		}
320 337
 	}
321 338
 
322 339
 	// Assume we found something, always,
323 340
 	$verify_context['tracking']++;
324 341
 
325 342
 	// Tell something displaying piecemeal to keep going.
326
-	if ($display_type == 'single')
327
-		return true;
328
-}
343
+	if ($display_type == 'single') {
344
+			return true;
345
+	}
346
+	}
329 347
 
330 348
 ?>
331 349
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Admin.template.php 1 patch
Braces   +173 added lines, -125 removed lines patch added patch discarded remove patch
@@ -64,9 +64,10 @@  discard block
 block discarded – undo
64 64
 										<strong>', $txt['administrators'], ':</strong>
65 65
 										', implode(', ', $context['administrators']);
66 66
 	// If we have lots of admins... don't show them all.
67
-	if (!empty($context['more_admins_link']))
68
-		echo '
67
+	if (!empty($context['more_admins_link'])) {
68
+			echo '
69 69
 							(', $context['more_admins_link'], ')';
70
+	}
70 71
 
71 72
 	echo '
72 73
 									</div>
@@ -83,16 +84,18 @@  discard block
 block discarded – undo
83 84
 		foreach ($area['areas'] as $item_id => $item)
84 85
 		{
85 86
 			// No point showing the 'home' page here, we're already on it!
86
-			if ($area_id == 'forum' && $item_id == 'index')
87
-				continue;
87
+			if ($area_id == 'forum' && $item_id == 'index') {
88
+							continue;
89
+			}
88 90
 
89 91
 			$url = isset($item['url']) ? $item['url'] : $scripturl . '?action=admin;area=' . $item_id . (!empty($context[$context['admin_menu_name']]['extra_parameters']) ? $context[$context['admin_menu_name']]['extra_parameters'] : '');
90
-			if (!empty($item['icon_file']))
91
-				echo '
92
+			if (!empty($item['icon_file'])) {
93
+							echo '
92 94
 							<a href="', $url, '" class="admin_group', !empty($item['inactive']) ? ' inactive' : '', '"><img class="large_admin_menu_icon_file" src="', $item['icon_file'], '" alt="">', $item['label'], '</a>';
93
-			else
94
-				echo '
95
+			} else {
96
+							echo '
95 97
 							<a href="', $url, '"><span class="large_', $item['icon_class'], !empty($item['inactive']) ? ' inactive' : '', '"></span>', $item['label'], '</a>';
98
+			}
96 99
 		}
97 100
 
98 101
 		echo '
@@ -103,10 +106,11 @@  discard block
 block discarded – undo
103 106
 					</div>';
104 107
 
105 108
 	// The below functions include all the scripts needed from the simplemachines.org site. The language and format are passed for internationalization.
106
-	if (empty($modSettings['disable_smf_js']))
107
-		echo '
109
+	if (empty($modSettings['disable_smf_js'])) {
110
+			echo '
108 111
 					<script src="', $scripturl, '?action=viewsmfile;filename=current-version.js"></script>
109 112
 					<script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>';
113
+	}
110 114
 
111 115
 	// This sets the announcements and current versions themselves ;).
112 116
 	echo '
@@ -185,9 +189,10 @@  discard block
 block discarded – undo
185 189
 								<em>', $version['version'], '</em>';
186 190
 
187 191
 		// more details for this item, show them a link
188
-		if ($context['can_admin'] && isset($version['more']))
189
-			echo
192
+		if ($context['can_admin'] && isset($version['more'])) {
193
+					echo
190 194
 								' <a href="', $scripturl, $version['more'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['version_check_more'], '</a>';
195
+		}
191 196
 		echo '
192 197
 								<br>';
193 198
 	}
@@ -218,20 +223,22 @@  discard block
 block discarded – undo
218 223
 
219 224
 	foreach ($context['credits'] as $section)
220 225
 	{
221
-		if (isset($section['pretext']))
222
-			echo '
226
+		if (isset($section['pretext'])) {
227
+					echo '
223 228
 								<p>', $section['pretext'], '</p><hr>';
229
+		}
224 230
 
225 231
 		echo '
226 232
 								<dl>';
227 233
 
228 234
 		foreach ($section['groups'] as $group)
229 235
 		{
230
-			if (isset($group['title']))
231
-				echo '
236
+			if (isset($group['title'])) {
237
+							echo '
232 238
 									<dt>
233 239
 										<strong>', $group['title'], ':</strong>
234 240
 									</dt>';
241
+			}
235 242
 
236 243
 			echo '
237 244
 									<dd>', implode(', ', $group['members']), '</dd>';
@@ -240,10 +247,11 @@  discard block
 block discarded – undo
240 247
 		echo '
241 248
 								</dl>';
242 249
 
243
-		if (isset($section['posttext']))
244
-			echo '
250
+		if (isset($section['posttext'])) {
251
+					echo '
245 252
 								<hr>
246 253
 								<p>', $section['posttext'], '</p>';
254
+		}
247 255
 	}
248 256
 
249 257
 	echo '
@@ -259,9 +267,10 @@  discard block
 block discarded – undo
259 267
 							smfSupportVersions.forum = "', $context['forum_version'], '";';
260 268
 
261 269
 	// Don't worry, none of this is logged, it's just used to give information that might be of use.
262
-	foreach ($context['current_versions'] as $variable => $version)
263
-		echo '
270
+	foreach ($context['current_versions'] as $variable => $version) {
271
+			echo '
264 272
 							smfSupportVersions.', $variable, ' = "', $version['version'], '";';
273
+	}
265 274
 
266 275
 	// Now we just have to include the script and wait ;).
267 276
 	echo '
@@ -358,8 +367,8 @@  discard block
 block discarded – undo
358 367
 							<tbody>';
359 368
 
360 369
 	// Loop through every source file displaying its version - using javascript.
361
-	foreach ($context['file_versions'] as $filename => $version)
362
-		echo '
370
+	foreach ($context['file_versions'] as $filename => $version) {
371
+			echo '
363 372
 								<tr class="windowbg">
364 373
 									<td class="half_table">
365 374
 										', $filename, '
@@ -371,6 +380,7 @@  discard block
 block discarded – undo
371 380
 										<em id="currentSources', $filename, '">??</em>
372 381
 									</td>
373 382
 								</tr>';
383
+	}
374 384
 
375 385
 	// Default template files.
376 386
 	echo '
@@ -396,8 +406,8 @@  discard block
 block discarded – undo
396 406
 							<table id="Default" class="table_grid">
397 407
 								<tbody>';
398 408
 
399
-	foreach ($context['default_template_versions'] as $filename => $version)
400
-		echo '
409
+	foreach ($context['default_template_versions'] as $filename => $version) {
410
+			echo '
401 411
 									<tr class="windowbg">
402 412
 										<td class="half_table">
403 413
 											', $filename, '
@@ -409,6 +419,7 @@  discard block
 block discarded – undo
409 419
 											<em id="currentDefault', $filename, '">??</em>
410 420
 										</td>
411 421
 									</tr>';
422
+	}
412 423
 
413 424
 	// Now the language files...
414 425
 	echo '
@@ -436,8 +447,8 @@  discard block
 block discarded – undo
436 447
 
437 448
 	foreach ($context['default_language_versions'] as $language => $files)
438 449
 	{
439
-		foreach ($files as $filename => $version)
440
-			echo '
450
+		foreach ($files as $filename => $version) {
451
+					echo '
441 452
 									<tr class="windowbg">
442 453
 										<td class="half_table">
443 454
 											', $filename, '.<em>', $language, '</em>.php
@@ -449,6 +460,7 @@  discard block
 block discarded – undo
449 460
 											<em id="current', $filename, '.', $language, '">??</em>
450 461
 										</td>
451 462
 									</tr>';
463
+		}
452 464
 	}
453 465
 
454 466
 	echo '
@@ -478,8 +490,8 @@  discard block
 block discarded – undo
478 490
 							<table id="Templates" class="table_grid">
479 491
 								<tbody>';
480 492
 
481
-		foreach ($context['template_versions'] as $filename => $version)
482
-			echo '
493
+		foreach ($context['template_versions'] as $filename => $version) {
494
+					echo '
483 495
 									<tr class="windowbg">
484 496
 										<td class="half_table">
485 497
 											', $filename, '
@@ -491,6 +503,7 @@  discard block
 block discarded – undo
491 503
 											<em id="currentTemplates', $filename, '">??</em>
492 504
 										</td>
493 505
 									</tr>';
506
+		}
494 507
 
495 508
 		echo '
496 509
 								</tbody>
@@ -520,8 +533,8 @@  discard block
 block discarded – undo
520 533
 							<table id="Tasks" class="table_grid">
521 534
 								<tbody>';
522 535
 
523
-		foreach ($context['tasks_versions'] as $filename => $version)
524
-			echo '
536
+		foreach ($context['tasks_versions'] as $filename => $version) {
537
+					echo '
525 538
 									<tr class="windowbg">
526 539
 										<td class="half_table">
527 540
 											', $filename, '
@@ -533,6 +546,7 @@  discard block
 block discarded – undo
533 546
 											<em id="currentTasks', $filename, '">??</em>
534 547
 										</td>
535 548
 									</tr>';
549
+		}
536 550
 
537 551
 		echo '
538 552
 								</tbody>
@@ -574,9 +588,10 @@  discard block
 block discarded – undo
574 588
 {
575 589
 	global $context, $scripturl, $txt, $modSettings;
576 590
 
577
-	if (!empty($context['saved_successful']))
578
-		echo '
591
+	if (!empty($context['saved_successful'])) {
592
+			echo '
579 593
 					<div class="infobox">', $txt['settings_saved'], '</div>';
594
+	}
580 595
 
581 596
 	// First section is for adding/removing words from the censored list.
582 597
 	echo '
@@ -591,11 +606,12 @@  discard block
 block discarded – undo
591 606
 								<p>', $txt['admin_censored_where'], '</p>';
592 607
 
593 608
 	// Show text boxes for censoring [bad   ] => [good  ].
594
-	foreach ($context['censored_words'] as $vulgar => $proper)
595
-		echo '
609
+	foreach ($context['censored_words'] as $vulgar => $proper) {
610
+			echo '
596 611
 								<div class="block">
597 612
 									<input type="text" name="censor_vulgar[]" value="', $vulgar, '" size="30"> =&gt; <input type="text" name="censor_proper[]" value="', $proper, '" size="30">
598 613
 								</div>';
614
+	}
599 615
 
600 616
 	// Now provide a way to censor more words.
601 617
 	echo '
@@ -669,19 +685,21 @@  discard block
 block discarded – undo
669 685
 						<div class="windowbg2 noup">
670 686
 							', $txt['not_done_reason'];
671 687
 
672
-	if (!empty($context['continue_percent']))
673
-		echo '
688
+	if (!empty($context['continue_percent'])) {
689
+			echo '
674 690
 							<div class="progress_bar">
675 691
 								<div class="full_bar">', $context['continue_percent'], '%</div>
676 692
 								<div class="green_percent" style="width: ', $context['continue_percent'], '%;">&nbsp;</div>
677 693
 							</div>';
694
+	}
678 695
 
679
-	if (!empty($context['substep_enabled']))
680
-		echo '
696
+	if (!empty($context['substep_enabled'])) {
697
+			echo '
681 698
 							<div class="progress_bar">
682 699
 								<div class="full_bar">', $context['substep_title'], ' (', $context['substep_continue_percent'], '%)</div>
683 700
 								<div class="blue_percent" style="width: ', $context['substep_continue_percent'], '%;">&nbsp;</div>
684 701
 							</div>';
702
+	}
685 703
 
686 704
 	echo '
687 705
 							<form action="', $scripturl, $context['continue_get_data'], '" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
@@ -716,35 +734,40 @@  discard block
 block discarded – undo
716 734
 {
717 735
 	global $context, $txt, $settings, $scripturl;
718 736
 
719
-	if (!empty($context['saved_successful']))
720
-		echo '
737
+	if (!empty($context['saved_successful'])) {
738
+			echo '
721 739
 					<div class="infobox">', $txt['settings_saved'], '</div>';
722
-	elseif (!empty($context['saved_failed']))
723
-		echo '
740
+	} elseif (!empty($context['saved_failed'])) {
741
+			echo '
724 742
 					<div class="errorbox">', sprintf($txt['settings_not_saved'], $context['saved_failed']), '</div>';
743
+	}
725 744
 
726
-	if (!empty($context['settings_pre_javascript']))
727
-		echo '
745
+	if (!empty($context['settings_pre_javascript'])) {
746
+			echo '
728 747
 					<script>', $context['settings_pre_javascript'], '</script>';
748
+	}
729 749
 
730
-	if (!empty($context['settings_insert_above']))
731
-		echo $context['settings_insert_above'];
750
+	if (!empty($context['settings_insert_above'])) {
751
+			echo $context['settings_insert_above'];
752
+	}
732 753
 
733 754
 	echo '
734 755
 					<div id="admincenter">
735 756
 						<form id="admin_form_wrapper" action="', $context['post_url'], '" method="post" accept-charset="', $context['character_set'], '"', !empty($context['force_form_onsubmit']) ? ' onsubmit="' . $context['force_form_onsubmit'] . '"' : '', '>';
736 757
 
737 758
 	// Is there a custom title?
738
-	if (isset($context['settings_title']))
739
-		echo '
759
+	if (isset($context['settings_title'])) {
760
+			echo '
740 761
 							<div class="cat_bar">
741 762
 								<h3 class="catbg">', $context['settings_title'], '</h3>
742 763
 							</div>';
764
+	}
743 765
 
744 766
 	// Have we got a message to display?
745
-	if (!empty($context['settings_message']))
746
-		echo '
767
+	if (!empty($context['settings_message'])) {
768
+			echo '
747 769
 							<div class="information">', $context['settings_message'], '</div>';
770
+	}
748 771
 
749 772
 	// Now actually loop through all the variables.
750 773
 	$is_open = false;
@@ -797,8 +820,9 @@  discard block
 block discarded – undo
797 820
 		// Hang about? Are you pulling my leg - a callback?!
798 821
 		if (is_array($config_var) && $config_var['type'] == 'callback')
799 822
 		{
800
-			if (function_exists('template_callback_' . $config_var['name']))
801
-				call_user_func('template_callback_' . $config_var['name']);
823
+			if (function_exists('template_callback_' . $config_var['name'])) {
824
+							call_user_func('template_callback_' . $config_var['name']);
825
+			}
802 826
 
803 827
 			continue;
804 828
 		}
@@ -828,9 +852,10 @@  discard block
 block discarded – undo
828 852
 				$text_types = array('color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time');
829 853
 
830 854
 				// Show the [?] button.
831
-				if ($config_var['help'])
832
-					echo '
855
+				if ($config_var['help']) {
856
+									echo '
833 857
 							<a id="setting_', $config_var['name'], '_help" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help" title="', $txt['help'], '"></span></a> ';
858
+				}
834 859
 
835 860
 				echo '
836 861
 										<a id="setting_', $config_var['name'], '"></a> <span', ($config_var['disabled'] ? ' style="color: #777777;"' : ($config_var['invalid'] ? ' class="error"' : '')), '><label for="', $config_var['name'], '">', $config_var['label'], '</label>', $subtext, ($config_var['type'] == 'password' ? '<br><em>' . $txt['admin_confirm_password'] . '</em>' : ''), '</span>
@@ -839,22 +864,25 @@  discard block
 block discarded – undo
839 864
 										$config_var['preinput'];
840 865
 
841 866
 				// Show a check box.
842
-				if ($config_var['type'] == 'check')
843
-					echo '
867
+				if ($config_var['type'] == 'check') {
868
+									echo '
844 869
 										<input type="checkbox"', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '"', ($config_var['value'] ? ' checked' : ''), ' value="1" class="input_check">';
870
+				}
845 871
 				// Escape (via htmlspecialchars.) the text box.
846
-				elseif ($config_var['type'] == 'password')
847
-					echo '
872
+				elseif ($config_var['type'] == 'password') {
873
+									echo '
848 874
 										<input type="password"', $disabled, $javascript, ' name="', $config_var['name'], '[0]"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' value="*#fakepass#*" onfocus="this.value = \'\'; this.form.', $config_var['name'], '.disabled = false;" class="input_password"><br>
849 875
 										<input type="password" disabled id="', $config_var['name'], '" name="', $config_var['name'], '[1]"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' class="input_password">';
876
+				}
850 877
 				// Show a selection box.
851 878
 				elseif ($config_var['type'] == 'select')
852 879
 				{
853 880
 					echo '
854 881
 										<select name="', $config_var['name'], '" id="', $config_var['name'], '" ', $javascript, $disabled, (!empty($config_var['multiple']) ? ' multiple="multiple"' : ''), (!empty($config_var['multiple']) && !empty($config_var['size']) ? ' size="' . $config_var['size'] . '"' : ''), '>';
855
-					foreach ($config_var['data'] as $option)
856
-						echo '
882
+					foreach ($config_var['data'] as $option) {
883
+											echo '
857 884
 											<option value="', $option[0], '"', (!empty($config_var['value']) && ($option[0] == $config_var['value'] || (!empty($config_var['multiple']) && in_array($option[0], $config_var['value']))) ? ' selected' : ''), '>', $option[1], '</option>';
885
+					}
858 886
 					echo '
859 887
 										</select>';
860 888
 				}
@@ -868,15 +896,17 @@  discard block
 block discarded – undo
868 896
 												<legend class="board_selector"><a href="#">', $txt['select_boards_from_list'], '</a></legend>';
869 897
 					foreach ($context['board_list'] as $id_cat => $cat)
870 898
 					{
871
-						if (!$first)
872
-							echo '
899
+						if (!$first) {
900
+													echo '
873 901
 											<hr>';
902
+						}
874 903
 						echo '
875 904
 											<strong>', $cat['name'], '</strong>
876 905
 											<ul>';
877
-						foreach ($cat['boards'] as $id_board => $brd)
878
-							echo '
906
+						foreach ($cat['boards'] as $id_board => $brd) {
907
+													echo '
879 908
 												<li><label><input type="checkbox" name="', $config_var['name'], '[', $brd['id'], ']" value="1" class="input_check"', in_array($brd['id'], $config_var['value']) ? ' checked' : '', '> ', $brd['child_level'] > 0 ? str_repeat('&nbsp; &nbsp;', $brd['child_level']) : '', $brd['name'], '</label></li>';
909
+						}
880 910
 
881 911
 						echo '
882 912
 											</ul>';
@@ -886,12 +916,14 @@  discard block
 block discarded – undo
886 916
 											</fieldset>';
887 917
 				}
888 918
 				// Text area?
889
-				elseif ($config_var['type'] == 'large_text')
890
-					echo '
919
+				elseif ($config_var['type'] == 'large_text') {
920
+									echo '
891 921
 											<textarea rows="', (!empty($config_var['size']) ? $config_var['size'] : (!empty($config_var['rows']) ? $config_var['rows'] : 4)), '" cols="', (!empty($config_var['cols']) ? $config_var['cols'] : 30), '" ', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>';
922
+				}
892 923
 				// Permission group?
893
-				elseif ($config_var['type'] == 'permissions')
894
-					theme_inline_permissions($config_var['name']);
924
+				elseif ($config_var['type'] == 'permissions') {
925
+									theme_inline_permissions($config_var['name']);
926
+				}
895 927
 				// BBC selection?
896 928
 				elseif ($config_var['type'] == 'bbc')
897 929
 				{
@@ -902,20 +934,22 @@  discard block
 block discarded – undo
902 934
 
903 935
 					foreach ($context['bbc_columns'] as $bbcColumn)
904 936
 					{
905
-						foreach ($bbcColumn as $bbcTag)
906
-							echo '
937
+						foreach ($bbcColumn as $bbcTag) {
938
+													echo '
907 939
 														<li class="list_bbc floatleft">
908 940
 															<input type="checkbox" name="', $config_var['name'], '_enabledTags[]" id="tag_', $config_var['name'], '_', $bbcTag['tag'], '" value="', $bbcTag['tag'], '"', !in_array($bbcTag['tag'], $context['bbc_sections'][$config_var['name']]['disabled']) ? ' checked' : '', ' class="input_check"> <label for="tag_', $config_var['name'], '_', $bbcTag['tag'], '">', $bbcTag['tag'], '</label>', $bbcTag['show_help'] ? ' (<a href="' . $scripturl . '?action=helpadmin;help=tag_' . $bbcTag['tag'] . '" onclick="return reqOverlayDiv(this.href);">?</a>)' : '', '
909 941
 														</li>';
942
+						}
910 943
 					}
911 944
 					echo '							</ul>
912 945
 												<input type="checkbox" id="bbc_', $config_var['name'], '_select_all" onclick="invertAll(this, this.form, \'', $config_var['name'], '_enabledTags\');"', $context['bbc_sections'][$config_var['name']]['all_selected'] ? ' checked' : '', ' class="input_check"> <label for="bbc_', $config_var['name'], '_select_all"><em>', $txt['bbcTagsToUse_select_all'], '</em></label>
913 946
 											</fieldset>';
914 947
 				}
915 948
 				// A simple message?
916
-				elseif ($config_var['type'] == 'var_message')
917
-					echo '
949
+				elseif ($config_var['type'] == 'var_message') {
950
+									echo '
918 951
 											<div', !empty($config_var['name']) ? ' id="' . $config_var['name'] . '"' : '', '>', $config_var['var_message'], '</div>';
952
+				}
919 953
 				// Assume it must be a text box
920 954
 				else
921 955
 				{
@@ -940,63 +974,70 @@  discard block
 block discarded – undo
940 974
 											' . $config_var['postinput'] : '',
941 975
 										'</dd>';
942 976
 			}
943
-		}
944
-
945
-		else
977
+		} else
946 978
 		{
947 979
 			// Just show a separator.
948
-			if ($config_var == '')
949
-				echo '
980
+			if ($config_var == '') {
981
+							echo '
950 982
 								</dl>
951 983
 								<hr>
952 984
 								<dl class="settings">';
953
-			else
954
-				echo '
985
+			} else {
986
+							echo '
955 987
 									<dd>
956 988
 										<strong>' . $config_var . '</strong>
957 989
 									</dd>';
990
+			}
958 991
 		}
959 992
 	}
960 993
 
961
-	if ($is_open)
962
-		echo '
994
+	if ($is_open) {
995
+			echo '
963 996
 								</dl>';
997
+	}
964 998
 
965
-	if (empty($context['settings_save_dont_show']))
966
-		echo '
999
+	if (empty($context['settings_save_dont_show'])) {
1000
+			echo '
967 1001
 								<input type="submit" value="', $txt['save'], '"', (!empty($context['save_disabled']) ? ' disabled' : ''), (!empty($context['settings_save_onclick']) ? ' onclick="' . $context['settings_save_onclick'] . '"' : ''), ' class="button_submit">';
1002
+	}
968 1003
 
969
-	if ($is_open)
970
-		echo '
1004
+	if ($is_open) {
1005
+			echo '
971 1006
 							</div>';
1007
+	}
972 1008
 
973 1009
 
974 1010
 	// At least one token has to be used!
975
-	if (isset($context['admin-ssc_token']))
976
-		echo '
1011
+	if (isset($context['admin-ssc_token'])) {
1012
+			echo '
977 1013
 							<input type="hidden" name="', $context['admin-ssc_token_var'], '" value="', $context['admin-ssc_token'], '">';
1014
+	}
978 1015
 
979
-	if (isset($context['admin-dbsc_token']))
980
-		echo '
1016
+	if (isset($context['admin-dbsc_token'])) {
1017
+			echo '
981 1018
 							<input type="hidden" name="', $context['admin-dbsc_token_var'], '" value="', $context['admin-dbsc_token'], '">';
1019
+	}
982 1020
 
983
-	if (isset($context['admin-mp_token']))
984
-		echo '
1021
+	if (isset($context['admin-mp_token'])) {
1022
+			echo '
985 1023
 							<input type="hidden" name="', $context['admin-mp_token_var'], '" value="', $context['admin-mp_token'], '">';
1024
+	}
986 1025
 
987 1026
 	echo '
988 1027
 							<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
989 1028
 						</form>
990 1029
 					</div>';
991 1030
 
992
-	if (!empty($context['settings_post_javascript']))
993
-		echo '
1031
+	if (!empty($context['settings_post_javascript'])) {
1032
+			echo '
994 1033
 					<script>
995 1034
 					', $context['settings_post_javascript'], '
996 1035
 					</script>';
1036
+	}
997 1037
 
998
-	if (!empty($context['settings_insert_below']))
999
-		echo $context['settings_insert_below'];
1038
+	if (!empty($context['settings_insert_below'])) {
1039
+			echo $context['settings_insert_below'];
1040
+	}
1000 1041
 
1001 1042
 	// We may have added a board listing. If we did, we need to make it work.
1002 1043
 	addInlineJavascript('
@@ -1019,9 +1060,10 @@  discard block
 block discarded – undo
1019 1060
 {
1020 1061
 	global $context, $txt;
1021 1062
 
1022
-	if (!empty($context['saved_successful']))
1023
-		echo '
1063
+	if (!empty($context['saved_successful'])) {
1064
+			echo '
1024 1065
 					<div class="infobox">', $txt['settings_saved'], '</div>';
1066
+	}
1025 1067
 
1026 1068
 	// Standard fields.
1027 1069
 	template_show_list('standard_profile_fields');
@@ -1053,11 +1095,12 @@  discard block
 block discarded – undo
1053 1095
 	if (isset($_GET['msg']))
1054 1096
 	{
1055 1097
 		loadLanguage('Errors');
1056
-		if (isset($txt['custom_option_' . $_GET['msg']]))
1057
-			echo '
1098
+		if (isset($txt['custom_option_' . $_GET['msg']])) {
1099
+					echo '
1058 1100
 					<div class="errorbox">',
1059 1101
 						$txt['custom_option_' . $_GET['msg']], '
1060 1102
 					</div>';
1103
+		}
1061 1104
 	}
1062 1105
 
1063 1106
 	echo '
@@ -1123,9 +1166,10 @@  discard block
 block discarded – undo
1123 1166
 										<dd>
1124 1167
 											<select name="placement" id="placement">';
1125 1168
 
1126
-	foreach ($context['cust_profile_fields_placement'] as $order => $name)
1127
-		echo '
1169
+	foreach ($context['cust_profile_fields_placement'] as $order => $name) {
1170
+			echo '
1128 1171
 												<option value="', $order, '"', $context['field']['placement'] == $order ? ' selected' : '', '>', $txt['custom_profile_placement_' . $name], '</option>';
1172
+	}
1129 1173
 
1130 1174
 	echo '
1131 1175
 											</select>
@@ -1148,9 +1192,10 @@  discard block
 block discarded – undo
1148 1192
 										</dt>
1149 1193
 										<dd>
1150 1194
 											<select name="field_type" id="field_type" onchange="updateInputBoxes();">';
1151
-	foreach (array('text', 'textarea', 'select', 'radio', 'check') as $field_type)
1152
-		echo '
1195
+	foreach (array('text', 'textarea', 'select', 'radio', 'check') as $field_type) {
1196
+			echo '
1153 1197
 												<option value="', $field_type, '"', $context['field']['type'] == $field_type ? ' selected' : '', '>', $txt['custom_profile_type_' . $field_type], '</option>';
1198
+	}
1154 1199
 
1155 1200
 	echo '
1156 1201
 											</select>
@@ -1251,9 +1296,10 @@  discard block
 block discarded – undo
1251 1296
 								</fieldset>
1252 1297
 									<input type="submit" name="save" value="', $txt['save'], '" class="button_submit">';
1253 1298
 
1254
-	if ($context['fid'])
1255
-		echo '
1299
+	if ($context['fid']) {
1300
+			echo '
1256 1301
 									<input type="submit" name="delete" value="', $txt['delete'], '" data-confirm="', $txt['custom_edit_delete_sure'], '" class="button_submit you_sure">';
1302
+	}
1257 1303
 
1258 1304
 	echo '
1259 1305
 							</div>
@@ -1296,8 +1342,7 @@  discard block
 block discarded – undo
1296 1342
 	{
1297 1343
 		echo '
1298 1344
 						<p class="centertext"><strong>', $txt['admin_search_results_none'], '</strong></p>';
1299
-	}
1300
-	else
1345
+	} else
1301 1346
 	{
1302 1347
 		echo '
1303 1348
 						<ol class="search_results">';
@@ -1323,9 +1368,10 @@  discard block
 block discarded – undo
1323 1368
 							<li>
1324 1369
 								<a href="', $result['url'], '"><strong>', $result['name'], '</strong></a> [', isset($txt['admin_search_section_' . $result['type']]) ? $txt['admin_search_section_' . $result['type']] : $result['type'], ']';
1325 1370
 
1326
-				if ($result['help'])
1327
-					echo '
1371
+				if ($result['help']) {
1372
+									echo '
1328 1373
 								<p class="double_height">', $result['help'], '</p>';
1374
+				}
1329 1375
 
1330 1376
 				echo '
1331 1377
 							</li>';
@@ -1365,18 +1411,20 @@  discard block
 block discarded – undo
1365 1411
 									<strong>', $txt['setup_verification_answer'], '</strong>
1366 1412
 								</dd>';
1367 1413
 
1368
-		if (!empty($context['qa_by_lang'][$lang_id]))
1369
-			foreach ($context['qa_by_lang'][$lang_id] as $q_id)
1414
+		if (!empty($context['qa_by_lang'][$lang_id])) {
1415
+					foreach ($context['qa_by_lang'][$lang_id] as $q_id)
1370 1416
 			{
1371 1417
 				$question = $context['question_answers'][$q_id];
1418
+		}
1372 1419
 				echo '
1373 1420
 								<dt>
1374 1421
 									<input type="text" name="question[', $lang_id, '][', $q_id, ']" value="', $question['question'], '" size="50" class="input_text verification_question">
1375 1422
 								</dt>
1376 1423
 								<dd>';
1377
-				foreach ($question['answers'] as $answer)
1378
-					echo '
1424
+				foreach ($question['answers'] as $answer) {
1425
+									echo '
1379 1426
 									<input type="text" name="answer[', $lang_id, '][', $q_id, '][]" value="', $answer, '" size="50" class="input_text verification_answer">';
1427
+				}
1380 1428
 
1381 1429
 				echo '
1382 1430
 									<div class="qa_add_answer"><a href="javascript:void(0);" onclick="return addAnswer(this);">[ ', $txt['setup_verification_add_answer'], ' ]</a></div>
@@ -1415,11 +1463,12 @@  discard block
 block discarded – undo
1415 1463
 							', $txt['errors_found'], ':
1416 1464
 							<ul>';
1417 1465
 
1418
-			foreach ($context['repair_errors'] as $error)
1419
-				echo '
1466
+			foreach ($context['repair_errors'] as $error) {
1467
+							echo '
1420 1468
 								<li>
1421 1469
 									', $error, '
1422 1470
 								</li>';
1471
+			}
1423 1472
 
1424 1473
 			echo '
1425 1474
 							</ul>
@@ -1429,16 +1478,15 @@  discard block
 block discarded – undo
1429 1478
 							<p class="padding">
1430 1479
 								<strong><a href="', $scripturl, '?action=admin;area=repairboards;fixErrors;', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $scripturl, '?action=admin;area=maintain">', $txt['no'], '</a></strong>
1431 1480
 							</p>';
1432
-		}
1433
-		else
1434
-			echo '
1481
+		} else {
1482
+					echo '
1435 1483
 							<p>', $txt['maintain_no_errors'], '</p>
1436 1484
 							<p class="padding">
1437 1485
 								<a href="', $scripturl, '?action=admin;area=maintain;sa=routine">', $txt['maintain_return'], '</a>
1438 1486
 							</p>';
1487
+		}
1439 1488
 
1440
-	}
1441
-	else
1489
+	} else
1442 1490
 	{
1443 1491
 		if (!empty($context['redirect_to_recount']))
1444 1492
 		{
@@ -1450,8 +1498,7 @@  discard block
 block discarded – undo
1450 1498
 								<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1451 1499
 								<input type="submit" name="recount" id="recount_now" value="', $txt['errors_recount_now'], '">
1452 1500
 							</form>';
1453
-		}
1454
-		else
1501
+		} else
1455 1502
 		{
1456 1503
 			echo '
1457 1504
 							<p>', $txt['errors_fixed'], '</p>
@@ -1603,8 +1650,8 @@  discard block
 block discarded – undo
1603 1650
 function template_admin_quick_search()
1604 1651
 {
1605 1652
 	global $context, $txt, $scripturl;
1606
-	if ($context['user']['is_admin'])
1607
-		echo '
1653
+	if ($context['user']['is_admin']) {
1654
+			echo '
1608 1655
 								<span class="floatright">
1609 1656
 									<span class="generic_icons filter centericon"></span>
1610 1657
 									<input type="search" name="search_term" value="', $txt['admin_search'], '" onclick="if (this.value == \'', $txt['admin_search'], '\') this.value = \'\';" class="input_text">
@@ -1615,6 +1662,7 @@  discard block
 block discarded – undo
1615 1662
 									</select>
1616 1663
 									<input type="submit" name="search_go" id="search_go" value="', $txt['admin_search_go'], '" class="button_submit">
1617 1664
 								</span>';
1618
-}
1665
+	}
1666
+	}
1619 1667
 
1620 1668
 ?>
1621 1669
\ No newline at end of file
Please login to merge, or discard this patch.
other/buildtools/check-eof.php 1 patch
Braces   +15 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,18 +39,21 @@  discard block
 block discarded – undo
39 39
 );
40 40
 
41 41
 // No file? Thats bad.
42
-if (!isset($_SERVER['argv'], $_SERVER['argv'][1]))
42
+if (!isset($_SERVER['argv'], $_SERVER['argv'][1])) {
43 43
 	die('Error: No File specified' . "\n");
44
+}
44 45
 
45 46
 // The file has to exist.
46 47
 $currentFile = $_SERVER['argv'][1];
47
-if (!file_exists($currentFile))
48
+if (!file_exists($currentFile)) {
48 49
 	die('Error: File does not exist' . "\n");
50
+}
49 51
 
50 52
 // Is this ignored?
51
-foreach ($ignoreFiles as $if)
53
+foreach ($ignoreFiles as $if) {
52 54
 	if (preg_match('~' . $if . '~i', $currentFile))
53 55
 		die;
56
+}
54 57
 
55 58
 // Less efficent than opening a file with fopen, but we want to be sure to get the right end of the file. file_get_contents
56 59
 $file = fopen($currentFile, 'r');
@@ -60,17 +63,21 @@  discard block
 block discarded – undo
60 63
 $contents = fread($file, 100);
61 64
 
62 65
 // There is some white space here.
63
-if (preg_match('~\?>\s+$~', $contents, $matches))
66
+if (preg_match('~\?>\s+$~', $contents, $matches)) {
64 67
 	die('Error: End of File contains extra spaces in ' . $currentFile . "\n");
68
+}
65 69
 
66 70
 // Test to see if its there even, SMF 2.1 base package needs it there in our main files to allow package manager to properly handle end operations.  Customizations do not need it.
67
-if (!preg_match('~\?>$~', $contents, $matches))
71
+if (!preg_match('~\?>$~', $contents, $matches)) {
68 72
 	die('Error: End of File missing in ' . $currentFile . "\n");
73
+}
69 74
 
70 75
 // Test to see if a function/class ending is here but with no return (because we are OCD).
71
-if (preg_match('~}([\r]?\n)?\?>~', $contents, $matches))
76
+if (preg_match('~}([\r]?\n)?\?>~', $contents, $matches)) {
72 77
 	echo('Error: Incorrect return(s) after last function/class but before EOF in ' . $currentFile . "\n");
78
+}
73 79
 
74 80
 // Test to see if a string ending is here but with no return (because we are OCD).
75
-if (preg_match('~;([\r]?\n)?\?>~', $contents, $matches))
76
-	echo('Error: Incorrect return(s) after last string but before EOF in ' . $currentFile . "\n");
77 81
\ No newline at end of file
82
+if (preg_match('~;([\r]?\n)?\?>~', $contents, $matches)) {
83
+	echo('Error: Incorrect return(s) after last string but before EOF in ' . $currentFile . "\n");
84
+}
Please login to merge, or discard this patch.
Sources/ManageMail.php 1 patch
Braces   +26 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Main dispatcher. This function checks permissions and passes control through to the relevant section.
@@ -245,8 +246,9 @@  discard block
 block discarded – undo
245 246
 	while ($row = $smcFunc['db_fetch_assoc']($request))
246 247
 	{
247 248
 		// Private PM/email subjects and similar shouldn't be shown in the mailbox area.
248
-		if (!empty($row['private']))
249
-			$row['subject'] = $txt['personal_message'];
249
+		if (!empty($row['private'])) {
250
+					$row['subject'] = $txt['personal_message'];
251
+		}
250 252
 
251 253
 		$mails[] = $row;
252 254
 	}
@@ -300,8 +302,9 @@  discard block
 block discarded – undo
300 302
 		$element = substr($key, strrpos($key, '_') + 1);
301 303
 		$processedBirthdayEmails[$index][$element] = $value;
302 304
 	}
303
-	foreach ($processedBirthdayEmails as $index => $dummy)
304
-		$emails[$index] = $index;
305
+	foreach ($processedBirthdayEmails as $index => $dummy) {
306
+			$emails[$index] = $index;
307
+	}
305 308
 
306 309
 	$config_vars = array(
307 310
 			// Mail queue stuff, this rocks ;)
@@ -322,8 +325,9 @@  discard block
 block discarded – undo
322 325
 
323 326
 	call_integration_hook('integrate_modify_mail_settings', array(&$config_vars));
324 327
 
325
-	if ($return_config)
326
-		return $config_vars;
328
+	if ($return_config) {
329
+			return $config_vars;
330
+	}
327 331
 
328 332
 	// Saving?
329 333
 	if (isset($_GET['save']))
@@ -398,9 +402,9 @@  discard block
 block discarded – undo
398 402
 		);
399 403
 		list ($_GET['te']) = $smcFunc['db_fetch_row']($request);
400 404
 		$smcFunc['db_free_result']($request);
405
+	} else {
406
+			$_GET['te'] = (int) $_GET['te'];
401 407
 	}
402
-	else
403
-		$_GET['te'] = (int) $_GET['te'];
404 408
 
405 409
 	$_GET['sent'] = isset($_GET['sent']) ? (int) $_GET['sent'] : 0;
406 410
 
@@ -424,12 +428,14 @@  discard block
 block discarded – undo
424 428
 
425 429
 	// Try get more time...
426 430
 	@set_time_limit(600);
427
-	if (function_exists('apache_reset_timeout'))
428
-		@apache_reset_timeout();
431
+	if (function_exists('apache_reset_timeout')) {
432
+			@apache_reset_timeout();
433
+	}
429 434
 
430 435
 	// Have we already used our maximum time?
431
-	if (time() - array_sum(explode(' ', $time_start)) < 5)
432
-		return;
436
+	if (time() - array_sum(explode(' ', $time_start)) < 5) {
437
+			return;
438
+	}
433 439
 
434 440
 	$context['continue_get_data'] = '?action=admin;area=mailqueue;sa=clear;te=' . $_GET['te'] . ';sent=' . $_GET['sent'] . ';' . $context['session_var'] . '=' . $context['session_id'];
435 441
 	$context['page_title'] = $txt['not_done_title'];
@@ -459,8 +465,9 @@  discard block
 block discarded – undo
459 465
 {
460 466
 	global $txt;
461 467
 
462
-	if ($time_diff < 0)
463
-		$time_diff = 0;
468
+	if ($time_diff < 0) {
469
+			$time_diff = 0;
470
+	}
464 471
 
465 472
 	// Just do a bit of an if fest...
466 473
 	if ($time_diff > 86400)
@@ -481,8 +488,9 @@  discard block
 block discarded – undo
481 488
 		return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes);
482 489
 	}
483 490
 	// Otherwise must be second
484
-	else
485
-		return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
486
-}
491
+	else {
492
+			return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
493
+	}
494
+	}
487 495
 
488 496
 ?>
489 497
\ No newline at end of file
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)
88 98
 	{
89
-		if (!$utf8)
90
-			return $string;
99
+		if (!$utf8) {
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)
@@ -2688,8 +2833,9 @@  discard block
 block discarded – undo
2688 2833
 	}
2689 2834
 
2690 2835
 	// Keep track of what we're up to soldier.
2691
-	if ($db_show_debug === true)
2692
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2836
+	if ($db_show_debug === true) {
2837
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2838
+	}
2693 2839
 
2694 2840
 	// Remember what we have loaded, and in which language.
2695 2841
 	$already_loaded[$template_name] = $lang;
@@ -2735,8 +2881,9 @@  discard block
 block discarded – undo
2735 2881
 				)
2736 2882
 			);
2737 2883
 			// In the EXTREMELY unlikely event this happens, give an error message.
2738
-			if ($smcFunc['db_num_rows']($result) == 0)
2739
-				fatal_lang_error('parent_not_found', 'critical');
2884
+			if ($smcFunc['db_num_rows']($result) == 0) {
2885
+							fatal_lang_error('parent_not_found', 'critical');
2886
+			}
2740 2887
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2741 2888
 			{
2742 2889
 				if (!isset($boards[$row['id_board']]))
@@ -2753,8 +2900,8 @@  discard block
 block discarded – undo
2753 2900
 					);
2754 2901
 				}
2755 2902
 				// If a moderator exists for this board, add that moderator for all children too.
2756
-				if (!empty($row['id_moderator']))
2757
-					foreach ($boards as $id => $dummy)
2903
+				if (!empty($row['id_moderator'])) {
2904
+									foreach ($boards as $id => $dummy)
2758 2905
 					{
2759 2906
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2760 2907
 							'id' => $row['id_moderator'],
@@ -2762,11 +2909,12 @@  discard block
 block discarded – undo
2762 2909
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2763 2910
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2764 2911
 						);
2912
+				}
2765 2913
 					}
2766 2914
 
2767 2915
 				// If a moderator group exists for this board, add that moderator group for all children too
2768
-				if (!empty($row['id_moderator_group']))
2769
-					foreach ($boards as $id => $dummy)
2916
+				if (!empty($row['id_moderator_group'])) {
2917
+									foreach ($boards as $id => $dummy)
2770 2918
 					{
2771 2919
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2772 2920
 							'id' => $row['id_moderator_group'],
@@ -2774,6 +2922,7 @@  discard block
 block discarded – undo
2774 2922
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2775 2923
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2776 2924
 						);
2925
+				}
2777 2926
 					}
2778 2927
 			}
2779 2928
 			$smcFunc['db_free_result']($result);
@@ -2801,23 +2950,27 @@  discard block
 block discarded – undo
2801 2950
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2802 2951
 	{
2803 2952
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2804
-		if (empty($smcFunc['ucwords']))
2805
-			reloadSettings();
2953
+		if (empty($smcFunc['ucwords'])) {
2954
+					reloadSettings();
2955
+		}
2806 2956
 
2807 2957
 		// If we don't have our theme information yet, let's get it.
2808
-		if (empty($settings['default_theme_dir']))
2809
-			loadTheme(0, false);
2958
+		if (empty($settings['default_theme_dir'])) {
2959
+					loadTheme(0, false);
2960
+		}
2810 2961
 
2811 2962
 		// Default language directories to try.
2812 2963
 		$language_directories = array(
2813 2964
 			$settings['default_theme_dir'] . '/languages',
2814 2965
 		);
2815
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2816
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2966
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2967
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2968
+		}
2817 2969
 
2818 2970
 		// We possibly have a base theme directory.
2819
-		if (!empty($settings['base_theme_dir']))
2820
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2971
+		if (!empty($settings['base_theme_dir'])) {
2972
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2973
+		}
2821 2974
 
2822 2975
 		// Remove any duplicates.
2823 2976
 		$language_directories = array_unique($language_directories);
@@ -2831,20 +2984,21 @@  discard block
 block discarded – undo
2831 2984
 		foreach ($language_directories as $language_dir)
2832 2985
 		{
2833 2986
 			// Can't look in here... doesn't exist!
2834
-			if (!file_exists($language_dir))
2835
-				continue;
2987
+			if (!file_exists($language_dir)) {
2988
+							continue;
2989
+			}
2836 2990
 
2837 2991
 			$dir = dir($language_dir);
2838 2992
 			while ($entry = $dir->read())
2839 2993
 			{
2840 2994
 				// Look for the index language file....
2841
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2842
-					continue;
2843
-
2844
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2845
-					$langName = $langList[$matches[1]];
2995
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2996
+									continue;
2997
+				}
2846 2998
 
2847
-				else
2999
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3000
+									$langName = $langList[$matches[1]];
3001
+				} else
2848 3002
 				{
2849 3003
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2850 3004
 
@@ -2885,20 +3039,23 @@  discard block
 block discarded – undo
2885 3039
 		}
2886 3040
 
2887 3041
 		// Do we need to store the lang list?
2888
-		if (empty($langList))
2889
-			updateSettings(array('langList' => json_encode($catchLang)));
3042
+		if (empty($langList)) {
3043
+					updateSettings(array('langList' => json_encode($catchLang)));
3044
+		}
2890 3045
 
2891 3046
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2892 3047
 		if ($favor_utf8)
2893 3048
 		{
2894
-			foreach ($context['languages'] as $lang)
2895
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3049
+			foreach ($context['languages'] as $lang) {
3050
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2896 3051
 					unset($context['languages'][$lang['filename']]);
3052
+			}
2897 3053
 		}
2898 3054
 
2899 3055
 		// Let's cash in on this deal.
2900
-		if (!empty($modSettings['cache_enable']))
2901
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3056
+		if (!empty($modSettings['cache_enable'])) {
3057
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3058
+		}
2902 3059
 	}
2903 3060
 
2904 3061
 	return $context['languages'];
@@ -2921,8 +3078,9 @@  discard block
 block discarded – undo
2921 3078
 	global $modSettings, $options, $txt;
2922 3079
 	static $censor_vulgar = null, $censor_proper;
2923 3080
 
2924
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2925
-		return $text;
3081
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3082
+			return $text;
3083
+	}
2926 3084
 
2927 3085
 	// If they haven't yet been loaded, load them.
2928 3086
 	if ($censor_vulgar == null)
@@ -2950,9 +3108,9 @@  discard block
 block discarded – undo
2950 3108
 	{
2951 3109
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2952 3110
 		$text = $func($censor_vulgar, $censor_proper, $text);
3111
+	} else {
3112
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2953 3113
 	}
2954
-	else
2955
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2956 3114
 
2957 3115
 	return $text;
2958 3116
 }
@@ -2978,38 +3136,42 @@  discard block
 block discarded – undo
2978 3136
 	@ini_set('track_errors', '1');
2979 3137
 
2980 3138
 	// Don't include the file more than once, if $once is true.
2981
-	if ($once && in_array($filename, $templates))
2982
-		return;
3139
+	if ($once && in_array($filename, $templates)) {
3140
+			return;
3141
+	}
2983 3142
 	// Add this file to the include list, whether $once is true or not.
2984
-	else
2985
-		$templates[] = $filename;
3143
+	else {
3144
+			$templates[] = $filename;
3145
+	}
2986 3146
 
2987 3147
 	// Are we going to use eval?
2988 3148
 	if (empty($modSettings['disableTemplateEval']))
2989 3149
 	{
2990 3150
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2991 3151
 		$settings['current_include_filename'] = $filename;
2992
-	}
2993
-	else
3152
+	} else
2994 3153
 	{
2995 3154
 		$file_found = file_exists($filename);
2996 3155
 
2997
-		if ($once && $file_found)
2998
-			require_once($filename);
2999
-		elseif ($file_found)
3000
-			require($filename);
3156
+		if ($once && $file_found) {
3157
+					require_once($filename);
3158
+		} elseif ($file_found) {
3159
+					require($filename);
3160
+		}
3001 3161
 	}
3002 3162
 
3003 3163
 	if ($file_found !== true)
3004 3164
 	{
3005 3165
 		ob_end_clean();
3006
-		if (!empty($modSettings['enableCompressedOutput']))
3007
-			@ob_start('ob_gzhandler');
3008
-		else
3009
-			ob_start();
3166
+		if (!empty($modSettings['enableCompressedOutput'])) {
3167
+					@ob_start('ob_gzhandler');
3168
+		} else {
3169
+					ob_start();
3170
+		}
3010 3171
 
3011
-		if (isset($_GET['debug']))
3012
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3172
+		if (isset($_GET['debug'])) {
3173
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3174
+		}
3013 3175
 
3014 3176
 		// Don't cache error pages!!
3015 3177
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3028,12 +3190,13 @@  discard block
 block discarded – undo
3028 3190
 		echo '<!DOCTYPE html>
3029 3191
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3030 3192
 	<head>';
3031
-		if (isset($context['character_set']))
3032
-			echo '
3193
+		if (isset($context['character_set'])) {
3194
+					echo '
3033 3195
 		<meta charset="', $context['character_set'], '">';
3196
+		}
3034 3197
 
3035
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3036
-			echo '
3198
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3199
+					echo '
3037 3200
 		<title>', $mtitle, '</title>
3038 3201
 	</head>
3039 3202
 	<body>
@@ -3041,8 +3204,8 @@  discard block
 block discarded – undo
3041 3204
 		', $mmessage, '
3042 3205
 	</body>
3043 3206
 </html>';
3044
-		elseif (!allowedTo('admin_forum'))
3045
-			echo '
3207
+		} elseif (!allowedTo('admin_forum')) {
3208
+					echo '
3046 3209
 		<title>', $txt['template_parse_error'], '</title>
3047 3210
 	</head>
3048 3211
 	<body>
@@ -3050,15 +3213,17 @@  discard block
 block discarded – undo
3050 3213
 		', $txt['template_parse_error_message'], '
3051 3214
 	</body>
3052 3215
 </html>';
3053
-		else
3216
+		} else
3054 3217
 		{
3055 3218
 			require_once($sourcedir . '/Subs-Package.php');
3056 3219
 
3057 3220
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3058
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3059
-				$error = $php_errormsg;
3060
-			if (empty($error))
3061
-				$error = $txt['template_parse_errmsg'];
3221
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3222
+							$error = $php_errormsg;
3223
+			}
3224
+			if (empty($error)) {
3225
+							$error = $txt['template_parse_errmsg'];
3226
+			}
3062 3227
 
3063 3228
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3064 3229
 
@@ -3069,11 +3234,12 @@  discard block
 block discarded – undo
3069 3234
 		<h3>', $txt['template_parse_error'], '</h3>
3070 3235
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3071 3236
 
3072
-			if (!empty($error))
3073
-				echo '
3237
+			if (!empty($error)) {
3238
+							echo '
3074 3239
 		<hr>
3075 3240
 
3076 3241
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3242
+			}
3077 3243
 
3078 3244
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3079 3245
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3083,10 +3249,11 @@  discard block
 block discarded – undo
3083 3249
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3084 3250
 
3085 3251
 				// Fix the PHP code stuff...
3086
-				if (!isBrowser('gecko'))
3087
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3088
-				else
3089
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3252
+				if (!isBrowser('gecko')) {
3253
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3254
+				} else {
3255
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3256
+				}
3090 3257
 
3091 3258
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3092 3259
 				$j = -1;
@@ -3094,8 +3261,9 @@  discard block
 block discarded – undo
3094 3261
 				{
3095 3262
 					$j++;
3096 3263
 
3097
-					if (substr_count($line, '<br>') == 0)
3098
-						continue;
3264
+					if (substr_count($line, '<br>') == 0) {
3265
+											continue;
3266
+					}
3099 3267
 
3100 3268
 					$n = substr_count($line, '<br>');
3101 3269
 					for ($i = 0; $i < $n; $i++)
@@ -3114,38 +3282,42 @@  discard block
 block discarded – undo
3114 3282
 				// Figure out what the color coding was before...
3115 3283
 				$line = max($match[1] - 9, 1);
3116 3284
 				$last_line = '';
3117
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3118
-					if (strpos($data2[$line2], '<') !== false)
3285
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3286
+									if (strpos($data2[$line2], '<') !== false)
3119 3287
 					{
3120 3288
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3121 3289
 							$last_line = $color_match[1];
3290
+				}
3122 3291
 						break;
3123 3292
 					}
3124 3293
 
3125 3294
 				// Show the relevant lines...
3126 3295
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3127 3296
 				{
3128
-					if ($line == $match[1])
3129
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3297
+					if ($line == $match[1]) {
3298
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3299
+					}
3130 3300
 
3131 3301
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3132
-					if (isset($data2[$line]) && $data2[$line] != '')
3133
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3302
+					if (isset($data2[$line]) && $data2[$line] != '') {
3303
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3304
+					}
3134 3305
 
3135 3306
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3136 3307
 					{
3137 3308
 						$last_line = $color_match[1];
3138 3309
 						echo '</', substr($last_line, 1, 4), '>';
3310
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3311
+											$last_line = '';
3312
+					} elseif ($last_line != '' && $data2[$line] != '') {
3313
+											echo '</', substr($last_line, 1, 4), '>';
3139 3314
 					}
3140
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3141
-						$last_line = '';
3142
-					elseif ($last_line != '' && $data2[$line] != '')
3143
-						echo '</', substr($last_line, 1, 4), '>';
3144 3315
 
3145
-					if ($line == $match[1])
3146
-						echo '</pre></div><pre style="margin: 0;">';
3147
-					else
3148
-						echo "\n";
3316
+					if ($line == $match[1]) {
3317
+											echo '</pre></div><pre style="margin: 0;">';
3318
+					} else {
3319
+											echo "\n";
3320
+					}
3149 3321
 				}
3150 3322
 
3151 3323
 				echo '</pre></div>';
@@ -3169,8 +3341,9 @@  discard block
 block discarded – undo
3169 3341
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3170 3342
 
3171 3343
 	// Figure out what type of database we are using.
3172
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3173
-		$db_type = 'mysql';
3344
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3345
+			$db_type = 'mysql';
3346
+	}
3174 3347
 
3175 3348
 	// Load the file for the database.
3176 3349
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3178,8 +3351,9 @@  discard block
 block discarded – undo
3178 3351
 	$db_options = array();
3179 3352
 
3180 3353
 	// Add in the port if needed
3181
-	if (!empty($db_port))
3182
-		$db_options['port'] = $db_port;
3354
+	if (!empty($db_port)) {
3355
+			$db_options['port'] = $db_port;
3356
+	}
3183 3357
 
3184 3358
 	// 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.
3185 3359
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3198,13 +3372,15 @@  discard block
 block discarded – undo
3198 3372
 	}
3199 3373
 
3200 3374
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3201
-	if (!$db_connection)
3202
-		display_db_error();
3375
+	if (!$db_connection) {
3376
+			display_db_error();
3377
+	}
3203 3378
 
3204 3379
 	// If in SSI mode fix up the prefix.
3205
-	if (SMF == 'SSI')
3206
-		db_fix_prefix($db_prefix, $db_name);
3207
-}
3380
+	if (SMF == 'SSI') {
3381
+			db_fix_prefix($db_prefix, $db_name);
3382
+	}
3383
+	}
3208 3384
 
3209 3385
 /**
3210 3386
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3218,10 +3394,11 @@  discard block
 block discarded – undo
3218 3394
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3219 3395
 
3220 3396
 	// Not overriding this and we have a cacheAPI, send it back.
3221
-	if (empty($overrideCache) && is_object($cacheAPI))
3222
-		return $cacheAPI;
3223
-	elseif (is_null($cacheAPI))
3224
-		$cacheAPI = false;
3397
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3398
+			return $cacheAPI;
3399
+	} elseif (is_null($cacheAPI)) {
3400
+			$cacheAPI = false;
3401
+	}
3225 3402
 
3226 3403
 	// Make sure our class is in session.
3227 3404
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3242,8 +3419,9 @@  discard block
 block discarded – undo
3242 3419
 		if (!$testAPI->isSupported())
3243 3420
 		{
3244 3421
 			// Can we save ourselves?
3245
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3246
-				return loadCacheAccelerator(null, false);
3422
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3423
+							return loadCacheAccelerator(null, false);
3424
+			}
3247 3425
 			return false;
3248 3426
 		}
3249 3427
 
@@ -3255,9 +3433,9 @@  discard block
 block discarded – undo
3255 3433
 		{
3256 3434
 			$cacheAPI = $testAPI;
3257 3435
 			return $cacheAPI;
3436
+		} else {
3437
+					return $testAPI;
3258 3438
 		}
3259
-		else
3260
-			return $testAPI;
3261 3439
 	}
3262 3440
 }
3263 3441
 
@@ -3277,8 +3455,9 @@  discard block
 block discarded – undo
3277 3455
 
3278 3456
 	// @todo Why are we doing this if caching is disabled?
3279 3457
 
3280
-	if (function_exists('call_integration_hook'))
3281
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3458
+	if (function_exists('call_integration_hook')) {
3459
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3460
+	}
3282 3461
 
3283 3462
 	/* Refresh the cache if either:
3284 3463
 		1. Caching is disabled.
@@ -3292,16 +3471,19 @@  discard block
 block discarded – undo
3292 3471
 		require_once($sourcedir . '/' . $file);
3293 3472
 		$cache_block = call_user_func_array($function, $params);
3294 3473
 
3295
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3296
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3474
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3475
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3476
+		}
3297 3477
 	}
3298 3478
 
3299 3479
 	// Some cached data may need a freshening up after retrieval.
3300
-	if (!empty($cache_block['post_retri_eval']))
3301
-		eval($cache_block['post_retri_eval']);
3480
+	if (!empty($cache_block['post_retri_eval'])) {
3481
+			eval($cache_block['post_retri_eval']);
3482
+	}
3302 3483
 
3303
-	if (function_exists('call_integration_hook'))
3304
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3484
+	if (function_exists('call_integration_hook')) {
3485
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3486
+	}
3305 3487
 
3306 3488
 	return $cache_block['data'];
3307 3489
 }
@@ -3328,8 +3510,9 @@  discard block
 block discarded – undo
3328 3510
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3329 3511
 	global $cache_hits, $cache_count, $db_show_debug;
3330 3512
 
3331
-	if (empty($cache_enable) || empty($cacheAPI))
3332
-		return;
3513
+	if (empty($cache_enable) || empty($cacheAPI)) {
3514
+			return;
3515
+	}
3333 3516
 
3334 3517
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3335 3518
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3342,12 +3525,14 @@  discard block
 block discarded – undo
3342 3525
 	$value = $value === null ? null : json_encode($value);
3343 3526
 	$cacheAPI->putData($key, $value, $ttl);
3344 3527
 
3345
-	if (function_exists('call_integration_hook'))
3346
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3528
+	if (function_exists('call_integration_hook')) {
3529
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3530
+	}
3347 3531
 
3348
-	if (isset($db_show_debug) && $db_show_debug === true)
3349
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3350
-}
3532
+	if (isset($db_show_debug) && $db_show_debug === true) {
3533
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3534
+	}
3535
+	}
3351 3536
 
3352 3537
 /**
3353 3538
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3363,8 +3548,9 @@  discard block
 block discarded – undo
3363 3548
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3364 3549
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3365 3550
 
3366
-	if (empty($cache_enable) || empty($cacheAPI))
3367
-		return;
3551
+	if (empty($cache_enable) || empty($cacheAPI)) {
3552
+			return;
3553
+	}
3368 3554
 
3369 3555
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3370 3556
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3384,16 +3570,18 @@  discard block
 block discarded – undo
3384 3570
 
3385 3571
 		if (empty($value))
3386 3572
 		{
3387
-			if (!is_array($cache_misses))
3388
-				$cache_misses = array();
3573
+			if (!is_array($cache_misses)) {
3574
+							$cache_misses = array();
3575
+			}
3389 3576
 
3390 3577
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3391 3578
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3392 3579
 		}
3393 3580
 	}
3394 3581
 
3395
-	if (function_exists('call_integration_hook') && isset($value))
3396
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3582
+	if (function_exists('call_integration_hook') && isset($value)) {
3583
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3584
+	}
3397 3585
 
3398 3586
 	return empty($value) ? null : smf_json_decode($value, true);
3399 3587
 }
@@ -3415,8 +3603,9 @@  discard block
 block discarded – undo
3415 3603
 	global $cacheAPI;
3416 3604
 
3417 3605
 	// If we can't get to the API, can't do this.
3418
-	if (empty($cacheAPI))
3419
-		return;
3606
+	if (empty($cacheAPI)) {
3607
+			return;
3608
+	}
3420 3609
 
3421 3610
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3422 3611
 	$cacheAPI->cleanCache($type);
@@ -3441,8 +3630,9 @@  discard block
 block discarded – undo
3441 3630
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3442 3631
 
3443 3632
 	// Come on!
3444
-	if (empty($data))
3445
-		return array();
3633
+	if (empty($data)) {
3634
+			return array();
3635
+	}
3446 3636
 
3447 3637
 	// Set a nice default var.
3448 3638
 	$image = '';
@@ -3450,11 +3640,11 @@  discard block
 block discarded – undo
3450 3640
 	// Gravatar has been set as mandatory!
3451 3641
 	if (!empty($modSettings['gravatarOverride']))
3452 3642
 	{
3453
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3454
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3455
-
3456
-		else if (!empty($data['email']))
3457
-			$image = get_gravatar_url($data['email']);
3643
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3644
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3645
+		} else if (!empty($data['email'])) {
3646
+					$image = get_gravatar_url($data['email']);
3647
+		}
3458 3648
 	}
3459 3649
 
3460 3650
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3466,54 +3656,60 @@  discard block
 block discarded – undo
3466 3656
 			// Gravatar.
3467 3657
 			if (stristr($data['avatar'], 'gravatar://'))
3468 3658
 			{
3469
-				if ($data['avatar'] == 'gravatar://')
3470
-					$image = get_gravatar_url($data['email']);
3471
-
3472
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3473
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3659
+				if ($data['avatar'] == 'gravatar://') {
3660
+									$image = get_gravatar_url($data['email']);
3661
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3662
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3663
+				}
3474 3664
 			}
3475 3665
 
3476 3666
 			// External url.
3477 3667
 			else
3478 3668
 			{
3479 3669
 				// Using ssl?
3480
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3481
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3670
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3671
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3672
+				}
3482 3673
 
3483 3674
 				// Just a plain external url.
3484
-				else
3485
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3675
+				else {
3676
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3677
+				}
3486 3678
 			}
3487 3679
 		}
3488 3680
 
3489 3681
 		// Perhaps this user has an attachment as avatar...
3490
-		else if (!empty($data['filename']))
3491
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3682
+		else if (!empty($data['filename'])) {
3683
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3684
+		}
3492 3685
 
3493 3686
 		// Right... no avatar... use our default image.
3494
-		else
3495
-			$image = $modSettings['avatar_url'] . '/default.png';
3687
+		else {
3688
+					$image = $modSettings['avatar_url'] . '/default.png';
3689
+		}
3496 3690
 	}
3497 3691
 
3498 3692
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3499 3693
 
3500 3694
 	// 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.
3501
-	if (!empty($image))
3502
-		return array(
3695
+	if (!empty($image)) {
3696
+			return array(
3503 3697
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3504 3698
 			'image' => '<img class="avatar" src="' . $image . '" />',
3505 3699
 			'href' => $image,
3506 3700
 			'url' => $image,
3507 3701
 		);
3702
+	}
3508 3703
 
3509 3704
 	// Fallback to make life easier for everyone...
3510
-	else
3511
-		return array(
3705
+	else {
3706
+			return array(
3512 3707
 			'name' => '',
3513 3708
 			'image' => '',
3514 3709
 			'href' => '',
3515 3710
 			'url' => '',
3516 3711
 		);
3517
-}
3712
+	}
3713
+	}
3518 3714
 
3519 3715
 ?>
3520 3716
\ No newline at end of file
Please login to merge, or discard this patch.
other/buildtools/check-signed-off.php 1 patch
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -58,15 +58,16 @@
 block discarded – undo
58 58
 		// Parent hash.
59 59
 		'P' => shell_exec('git show -s --format=%P HEAD'),
60 60
 	)));
61
-}
62
-else
61
+} else {
63 62
 	$debugSecondary = base64_encode(json_encode(array(NULL)));
63
+}
64 64
 
65 65
 $result = stripos($lastLine, 'Signed-off-by:');
66 66
 if ($result === false)
67 67
 {
68 68
 	// Try 2.
69 69
 	$result2 = stripos($lastLine, 'Signed by');
70
-	if ($result2 === false)
71
-		die('Error: Signed-off-by not found in commit message [' . $lastLine . ']' . '[' . $message . ']' . '[' . $debugSecondary . '][' . $debugMaster . ']' . "\n");
72
-}
73 70
\ No newline at end of file
71
+	if ($result2 === false) {
72
+			die('Error: Signed-off-by not found in commit message [' . $lastLine . ']' . '[' . $message . ']' . '[' . $debugSecondary . '][' . $debugMaster . ']' . "\n");
73
+	}
74
+	}
74 75
\ No newline at end of file
Please login to merge, or discard this patch.