Completed
Push — release-2.1 ( 3bcfde...9b1f72 )
by Michael
18:23 queued 11:46
created
other/upgrade.php 1 patch
Braces   +1118 added lines, -821 removed lines patch added patch discarded remove patch
@@ -78,11 +78,14 @@  discard block
 block discarded – undo
78 78
 	ini_set('default_socket_timeout', 900);
79 79
 }
80 80
 // Clean the upgrade path if this is from the client.
81
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
82
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
81
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
82
+	for ($i = 1;
83
+}
84
+$i < $_SERVER['argc']; $i++)
83 85
 	{
84
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
85
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
86
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
87
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
88
+		}
86 89
 	}
87 90
 
88 91
 // Are we from the client?
@@ -90,9 +93,9 @@  discard block
 block discarded – undo
90 93
 {
91 94
 	$command_line = true;
92 95
 	$disable_security = 1;
93
-}
94
-else
96
+} else {
95 97
 	$command_line = false;
98
+}
96 99
 
97 100
 // Load this now just because we can.
98 101
 require_once($upgrade_path . '/Settings.php');
@@ -103,10 +106,12 @@  discard block
 block discarded – undo
103 106
 	$upcontext['user'] = unserialize(base64_decode($upgradeData));
104 107
 
105 108
 	// Check for sensible values.
106
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
107
-		$upcontext['user']['started'] = time();
108
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
109
-		$upcontext['user']['updated'] = 0;
109
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
110
+			$upcontext['user']['started'] = time();
111
+	}
112
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
113
+			$upcontext['user']['updated'] = 0;
114
+	}
110 115
 
111 116
 	$upcontext['started'] = $upcontext['user']['started'];
112 117
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -169,8 +174,9 @@  discard block
 block discarded – undo
169 174
 		{
170 175
 			$word = trim($word, '-_\'');
171 176
 
172
-			if ($word != '')
173
-				$returned_words[] = substr($word, 0, 20);
177
+			if ($word != '') {
178
+							$returned_words[] = substr($word, 0, 20);
179
+			}
174 180
 		}
175 181
 
176 182
 		return array_unique($returned_words);
@@ -185,15 +191,17 @@  discard block
 block discarded – undo
185 191
 		global $cachedir, $sourcedir;
186 192
 
187 193
 		// No directory = no game.
188
-		if (!is_dir($cachedir))
189
-			return;
194
+		if (!is_dir($cachedir)) {
195
+					return;
196
+		}
190 197
 
191 198
 		// Remove the files in SMF's own disk cache, if any
192 199
 		$dh = opendir($cachedir);
193 200
 		while ($file = readdir($dh))
194 201
 		{
195
-			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
196
-				@unlink($cachedir . '/' . $file);
202
+			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) {
203
+							@unlink($cachedir . '/' . $file);
204
+			}
197 205
 		}
198 206
 		closedir($dh);
199 207
 
@@ -209,8 +217,9 @@  discard block
 block discarded – undo
209 217
 {
210 218
 	function md5_hmac($data, $key)
211 219
 	{
212
-		if (strlen($key) > 64)
213
-			$key = pack('H*', md5($key));
220
+		if (strlen($key) > 64) {
221
+					$key = pack('H*', md5($key));
222
+		}
214 223
 		$key = str_pad($key, 64, chr(0x00));
215 224
 
216 225
 		$k_ipad = $key ^ str_repeat(chr(0x36), 64);
@@ -221,8 +230,9 @@  discard block
 block discarded – undo
221 230
 }
222 231
 
223 232
 // Don't do security check if on Yabbse
224
-if (!isset($modSettings['smfVersion']))
233
+if (!isset($modSettings['smfVersion'])) {
225 234
 	$disable_security = true;
235
+}
226 236
 
227 237
 // This only exists if we're on SMF ;)
228 238
 if (isset($modSettings['smfVersion']))
@@ -240,8 +250,9 @@  discard block
 block discarded – undo
240 250
 			'db_error_skip' => true,
241 251
 		)
242 252
 	);
243
-	while ($row = $smcFunc['db_fetch_assoc']($request))
244
-		$modSettings[$row['variable']] = $row['value'];
253
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
254
+			$modSettings[$row['variable']] = $row['value'];
255
+	}
245 256
 	$smcFunc['db_free_result']($request);
246 257
 }
247 258
 
@@ -251,10 +262,12 @@  discard block
 block discarded – undo
251 262
 	$modSettings['theme_url'] = 'Themes/default';
252 263
 	$modSettings['images_url'] = 'Themes/default/images';
253 264
 }
254
-if (!isset($settings['default_theme_url']))
265
+if (!isset($settings['default_theme_url'])) {
255 266
 	$settings['default_theme_url'] = $modSettings['theme_url'];
256
-if (!isset($settings['default_theme_dir']))
267
+}
268
+if (!isset($settings['default_theme_dir'])) {
257 269
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
270
+}
258 271
 
259 272
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
260 273
 // Default title...
@@ -272,13 +285,15 @@  discard block
 block discarded – undo
272 285
 	$support_js = $upcontext['upgrade_status']['js'];
273 286
 
274 287
 	// Only set this if the upgrader status says so.
275
-	if (empty($is_debug))
276
-		$is_debug = $upcontext['upgrade_status']['debug'];
288
+	if (empty($is_debug)) {
289
+			$is_debug = $upcontext['upgrade_status']['debug'];
290
+	}
277 291
 
278 292
 	// Load the language.
279
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
280
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
281
-}
293
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
294
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
295
+	}
296
+	}
282 297
 // Set the defaults.
283 298
 else
284 299
 {
@@ -296,15 +311,18 @@  discard block
 block discarded – undo
296 311
 }
297 312
 
298 313
 // If this isn't the first stage see whether they are logging in and resuming.
299
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
314
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
300 315
 	checkLogin();
316
+}
301 317
 
302
-if ($command_line)
318
+if ($command_line) {
303 319
 	cmdStep0();
320
+}
304 321
 
305 322
 // Don't error if we're using xml.
306
-if (isset($_GET['xml']))
323
+if (isset($_GET['xml'])) {
307 324
 	$upcontext['return_error'] = true;
325
+}
308 326
 
309 327
 // Loop through all the steps doing each one as required.
310 328
 $upcontext['overall_percent'] = 0;
@@ -325,10 +343,11 @@  discard block
 block discarded – undo
325 343
 		}
326 344
 
327 345
 		// Call the step and if it returns false that means pause!
328
-		if (function_exists($step[2]) && $step[2]() === false)
329
-			break;
330
-		elseif (function_exists($step[2]))
331
-			$upcontext['current_step']++;
346
+		if (function_exists($step[2]) && $step[2]() === false) {
347
+					break;
348
+		} elseif (function_exists($step[2])) {
349
+					$upcontext['current_step']++;
350
+		}
332 351
 	}
333 352
 	$upcontext['overall_percent'] += $step[3];
334 353
 }
@@ -367,17 +386,18 @@  discard block
 block discarded – undo
367 386
 		// This should not happen my dear... HELP ME DEVELOPERS!!
368 387
 		if (!empty($command_line))
369 388
 		{
370
-			if (function_exists('debug_print_backtrace'))
371
-				debug_print_backtrace();
389
+			if (function_exists('debug_print_backtrace')) {
390
+							debug_print_backtrace();
391
+			}
372 392
 
373 393
 			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.';
374 394
 			flush();
375 395
 			die();
376 396
 		}
377 397
 
378
-		if (!isset($_GET['xml']))
379
-			template_upgrade_above();
380
-		else
398
+		if (!isset($_GET['xml'])) {
399
+					template_upgrade_above();
400
+		} else
381 401
 		{
382 402
 			header('Content-Type: text/xml; charset=UTF-8');
383 403
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -399,21 +419,24 @@  discard block
 block discarded – undo
399 419
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(safe_serialize($upcontext['upgrade_status']));
400 420
 
401 421
 			// Custom stuff to pass back?
402
-			if (!empty($upcontext['query_string']))
403
-				$upcontext['form_url'] .= $upcontext['query_string'];
422
+			if (!empty($upcontext['query_string'])) {
423
+							$upcontext['form_url'] .= $upcontext['query_string'];
424
+			}
404 425
 
405 426
 			call_user_func('template_' . $upcontext['sub_template']);
406 427
 		}
407 428
 
408 429
 		// Was there an error?
409
-		if (!empty($upcontext['forced_error_message']))
410
-			echo $upcontext['forced_error_message'];
430
+		if (!empty($upcontext['forced_error_message'])) {
431
+					echo $upcontext['forced_error_message'];
432
+		}
411 433
 
412 434
 		// Show the footer.
413
-		if (!isset($_GET['xml']))
414
-			template_upgrade_below();
415
-		else
416
-			template_xml_below();
435
+		if (!isset($_GET['xml'])) {
436
+					template_upgrade_below();
437
+		} else {
438
+					template_xml_below();
439
+		}
417 440
 	}
418 441
 
419 442
 
@@ -425,15 +448,19 @@  discard block
 block discarded – undo
425 448
 		$seconds = intval($active % 60);
426 449
 
427 450
 		$totalTime = '';
428
-		if ($hours > 0)
429
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
430
-		if ($minutes > 0)
431
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
432
-		if ($seconds > 0)
433
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
451
+		if ($hours > 0) {
452
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
453
+		}
454
+		if ($minutes > 0) {
455
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
456
+		}
457
+		if ($seconds > 0) {
458
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
459
+		}
434 460
 
435
-		if (!empty($totalTime))
436
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
461
+		if (!empty($totalTime)) {
462
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
463
+		}
437 464
 	}
438 465
 
439 466
 	// Bang - gone!
@@ -446,8 +473,9 @@  discard block
 block discarded – undo
446 473
 	global $upgradeurl, $upcontext, $command_line;
447 474
 
448 475
 	// Command line users can't be redirected.
449
-	if ($command_line)
450
-		upgradeExit(true);
476
+	if ($command_line) {
477
+			upgradeExit(true);
478
+	}
451 479
 
452 480
 	// Are we providing the core info?
453 481
 	if ($addForm)
@@ -470,19 +498,22 @@  discard block
 block discarded – undo
470 498
 	global $modSettings, $sourcedir, $smcFunc;
471 499
 
472 500
 	// Do the non-SSI stuff...
473
-	if (function_exists('set_magic_quotes_runtime'))
474
-		@set_magic_quotes_runtime(0);
501
+	if (function_exists('set_magic_quotes_runtime')) {
502
+			@set_magic_quotes_runtime(0);
503
+	}
475 504
 
476 505
 	error_reporting(E_ALL);
477 506
 	define('SMF', 1);
478 507
 
479 508
 	// Start the session.
480
-	if (@ini_get('session.save_handler') == 'user')
481
-		@ini_set('session.save_handler', 'files');
509
+	if (@ini_get('session.save_handler') == 'user') {
510
+			@ini_set('session.save_handler', 'files');
511
+	}
482 512
 	@session_start();
483 513
 
484
-	if (empty($smcFunc))
485
-		$smcFunc = array();
514
+	if (empty($smcFunc)) {
515
+			$smcFunc = array();
516
+	}
486 517
 
487 518
 	// We need this for authentication and some upgrade code
488 519
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -495,8 +526,9 @@  discard block
 block discarded – undo
495 526
 	initialize_inputs();
496 527
 
497 528
 	// Get the database going!
498
-	if (empty($db_type))
499
-		$db_type = 'mysql';
529
+	if (empty($db_type)) {
530
+			$db_type = 'mysql';
531
+	}
500 532
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
501 533
 	{
502 534
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -505,17 +537,19 @@  discard block
 block discarded – undo
505 537
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
506 538
 
507 539
 		// Oh dear god!!
508
-		if ($db_connection === null)
509
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
540
+		if ($db_connection === null) {
541
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
542
+		}
510 543
 
511
-		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
512
-			$smcFunc['db_query']('', '
544
+		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
545
+					$smcFunc['db_query']('', '
513 546
 			SET NAMES {string:db_character_set}',
514 547
 			array(
515 548
 				'db_error_skip' => true,
516 549
 				'db_character_set' => $db_character_set,
517 550
 			)
518 551
 		);
552
+		}
519 553
 
520 554
 		// Load the modSettings data...
521 555
 		$request = $smcFunc['db_query']('', '
@@ -526,11 +560,11 @@  discard block
 block discarded – undo
526 560
 			)
527 561
 		);
528 562
 		$modSettings = array();
529
-		while ($row = $smcFunc['db_fetch_assoc']($request))
530
-			$modSettings[$row['variable']] = $row['value'];
563
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
564
+					$modSettings[$row['variable']] = $row['value'];
565
+		}
531 566
 		$smcFunc['db_free_result']($request);
532
-	}
533
-	else
567
+	} else
534 568
 	{
535 569
 		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.');
536 570
 	}
@@ -544,9 +578,10 @@  discard block
 block discarded – undo
544 578
 		cleanRequest();
545 579
 	}
546 580
 
547
-	if (!isset($_GET['substep']))
548
-		$_GET['substep'] = 0;
549
-}
581
+	if (!isset($_GET['substep'])) {
582
+			$_GET['substep'] = 0;
583
+	}
584
+	}
550 585
 
551 586
 function initialize_inputs()
552 587
 {
@@ -584,8 +619,9 @@  discard block
 block discarded – undo
584 619
 		$dh = opendir(dirname(__FILE__));
585 620
 		while ($file = readdir($dh))
586 621
 		{
587
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
588
-				@unlink(dirname(__FILE__) . '/' . $file);
622
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
623
+							@unlink(dirname(__FILE__) . '/' . $file);
624
+			}
589 625
 		}
590 626
 		closedir($dh);
591 627
 
@@ -615,8 +651,9 @@  discard block
 block discarded – undo
615 651
 	{
616 652
 		$upcontext['remote_files_available'] = false;
617 653
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
618
-		if ($test)
619
-			$upcontext['remote_files_available'] = true;
654
+		if ($test) {
655
+					$upcontext['remote_files_available'] = true;
656
+		}
620 657
 		@fclose($test);
621 658
 	}
622 659
 
@@ -624,8 +661,9 @@  discard block
 block discarded – undo
624 661
 	$temp = 'upgrade_php?step';
625 662
 	while (strlen($temp) > 4)
626 663
 	{
627
-		if (isset($_GET[$temp]))
628
-			unset($_GET[$temp]);
664
+		if (isset($_GET[$temp])) {
665
+					unset($_GET[$temp]);
666
+		}
629 667
 		$temp = substr($temp, 1);
630 668
 	}
631 669
 
@@ -651,29 +689,36 @@  discard block
 block discarded – undo
651 689
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $type . '.sql');
652 690
 
653 691
 	// Need legacy scripts?
654
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
655
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
656
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
657
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
658
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
659
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
692
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
693
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
694
+	}
695
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
696
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
697
+	}
698
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
699
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
700
+	}
660 701
 
661 702
 	// This needs to exist!
662
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
663
-		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>]');
664
-	else
665
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
703
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
704
+			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>]');
705
+	} else {
706
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
707
+	}
666 708
 
667
-	if (!$check)
668
-		// 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.
709
+	if (!$check) {
710
+			// 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.
669 711
 		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.');
712
+	}
670 713
 
671 714
 	// Do they meet the install requirements?
672
-	if (!php_version_check())
673
-		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.');
715
+	if (!php_version_check()) {
716
+			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.');
717
+	}
674 718
 
675
-	if (!db_version_check())
676
-		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.');
719
+	if (!db_version_check()) {
720
+			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.');
721
+	}
677 722
 
678 723
 	// Do some checks to make sure they have proper privileges
679 724
 	db_extend('packages');
@@ -688,14 +733,16 @@  discard block
 block discarded – undo
688 733
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
689 734
 
690 735
 	// Sorry... we need CREATE, ALTER and DROP
691
-	if (!$create || !$alter || !$drop)
692
-		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.');
736
+	if (!$create || !$alter || !$drop) {
737
+			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.');
738
+	}
693 739
 
694 740
 	// Do a quick version spot check.
695 741
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
696 742
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
697
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
698
-		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.');
743
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
744
+			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.');
745
+	}
699 746
 
700 747
 	// What absolutely needs to be writable?
701 748
 	$writable_files = array(
@@ -717,12 +764,13 @@  discard block
 block discarded – undo
717 764
 	quickFileWritable($custom_av_dir);
718 765
 
719 766
 	// Are we good now?
720
-	if (!is_writable($custom_av_dir))
721
-		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));
722
-	elseif ($need_settings_update)
767
+	if (!is_writable($custom_av_dir)) {
768
+			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));
769
+	} elseif ($need_settings_update)
723 770
 	{
724
-		if (!function_exists('cache_put_data'))
725
-			require_once($sourcedir . '/Load.php');
771
+		if (!function_exists('cache_put_data')) {
772
+					require_once($sourcedir . '/Load.php');
773
+		}
726 774
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
727 775
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
728 776
 	}
@@ -731,28 +779,33 @@  discard block
 block discarded – undo
731 779
 
732 780
 	// Check the cache directory.
733 781
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
734
-	if (!file_exists($cachedir_temp))
735
-		@mkdir($cachedir_temp);
736
-	if (!file_exists($cachedir_temp))
737
-		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.');
738
-
739
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
740
-		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>.');
741
-	elseif (!isset($_GET['skiplang']))
782
+	if (!file_exists($cachedir_temp)) {
783
+			@mkdir($cachedir_temp);
784
+	}
785
+	if (!file_exists($cachedir_temp)) {
786
+			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.');
787
+	}
788
+
789
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
790
+			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>.');
791
+	} elseif (!isset($_GET['skiplang']))
742 792
 	{
743 793
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
744 794
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
745 795
 
746
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
747
-			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>]');
796
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
797
+					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>]');
798
+		}
748 799
 	}
749 800
 
750
-	if (!makeFilesWritable($writable_files))
751
-		return false;
801
+	if (!makeFilesWritable($writable_files)) {
802
+			return false;
803
+	}
752 804
 
753 805
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
754
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
755
-		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.');
806
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
807
+			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.');
808
+	}
756 809
 
757 810
 	// Upgrade the agreement.
758 811
 	elseif (isset($modSettings['agreement']))
@@ -763,8 +816,8 @@  discard block
 block discarded – undo
763 816
 	}
764 817
 
765 818
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
766
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
767
-		$upcontext['warning'] = '
819
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
820
+			$upcontext['warning'] = '
768 821
 			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>
769 822
 			<ul>
770 823
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -772,10 +825,12 @@  discard block
 block discarded – undo
772 825
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
773 826
 			</ul>
774 827
 			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.';
828
+	}
775 829
 
776 830
 	// Either we're logged in or we're going to present the login.
777
-	if (checkLogin())
778
-		return true;
831
+	if (checkLogin()) {
832
+			return true;
833
+	}
779 834
 
780 835
 	$upcontext += createToken('login');
781 836
 
@@ -792,8 +847,9 @@  discard block
 block discarded – undo
792 847
 	if (isset($_POST['contbutt']) && (!empty($_POST['user']) || $disable_security))
793 848
 	{
794 849
 		// If we've disabled security pick a suitable name!
795
-		if (empty($_POST['user']))
796
-			$_POST['user'] = 'Administrator';
850
+		if (empty($_POST['user'])) {
851
+					$_POST['user'] = 'Administrator';
852
+		}
797 853
 
798 854
 		// Before 2.0 these column names were different!
799 855
 		$oldDB = false;
@@ -808,16 +864,17 @@  discard block
 block discarded – undo
808 864
 					'db_error_skip' => true,
809 865
 				)
810 866
 			);
811
-			if ($smcFunc['db_num_rows']($request) != 0)
812
-				$oldDB = true;
867
+			if ($smcFunc['db_num_rows']($request) != 0) {
868
+							$oldDB = true;
869
+			}
813 870
 			$smcFunc['db_free_result']($request);
814 871
 		}
815 872
 
816 873
 		// Get what we believe to be their details.
817 874
 		if (!$disable_security)
818 875
 		{
819
-			if ($oldDB)
820
-				$request = $smcFunc['db_query']('', '
876
+			if ($oldDB) {
877
+							$request = $smcFunc['db_query']('', '
821 878
 					SELECT id_member, memberName AS member_name, passwd, id_group,
822 879
 					additionalGroups AS additional_groups, lngfile
823 880
 					FROM {db_prefix}members
@@ -827,8 +884,8 @@  discard block
 block discarded – undo
827 884
 						'db_error_skip' => true,
828 885
 					)
829 886
 				);
830
-			else
831
-				$request = $smcFunc['db_query']('', '
887
+			} else {
888
+							$request = $smcFunc['db_query']('', '
832 889
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
833 890
 					FROM {db_prefix}members
834 891
 					WHERE member_name = {string:member_name}',
@@ -837,6 +894,7 @@  discard block
 block discarded – undo
837 894
 						'db_error_skip' => true,
838 895
 					)
839 896
 				);
897
+			}
840 898
 			if ($smcFunc['db_num_rows']($request) != 0)
841 899
 			{
842 900
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -844,13 +902,14 @@  discard block
 block discarded – undo
844 902
 				$groups = explode(',', $addGroups);
845 903
 				$groups[] = $id_group;
846 904
 
847
-				foreach ($groups as $k => $v)
848
-					$groups[$k] = (int) $v;
905
+				foreach ($groups as $k => $v) {
906
+									$groups[$k] = (int) $v;
907
+				}
849 908
 
850 909
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
910
+			} else {
911
+							$upcontext['username_incorrect'] = true;
851 912
 			}
852
-			else
853
-				$upcontext['username_incorrect'] = true;
854 913
 			$smcFunc['db_free_result']($request);
855 914
 		}
856 915
 		$upcontext['username'] = $_POST['user'];
@@ -860,13 +919,14 @@  discard block
 block discarded – undo
860 919
 		{
861 920
 			$upcontext['upgrade_status']['js'] = 1;
862 921
 			$support_js = 1;
922
+		} else {
923
+					$support_js = 0;
863 924
 		}
864
-		else
865
-			$support_js = 0;
866 925
 
867 926
 		// Note down the version we are coming from.
868
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
869
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
927
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
928
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
929
+		}
870 930
 
871 931
 		// Didn't get anywhere?
872 932
 		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']))
@@ -900,15 +960,15 @@  discard block
 block discarded – undo
900 960
 							'db_error_skip' => true,
901 961
 						)
902 962
 					);
903
-					if ($smcFunc['db_num_rows']($request) == 0)
904
-						return throw_error('You need to be an admin to perform an upgrade!');
963
+					if ($smcFunc['db_num_rows']($request) == 0) {
964
+											return throw_error('You need to be an admin to perform an upgrade!');
965
+					}
905 966
 					$smcFunc['db_free_result']($request);
906 967
 				}
907 968
 
908 969
 				$upcontext['user']['id'] = $id_member;
909 970
 				$upcontext['user']['name'] = $name;
910
-			}
911
-			else
971
+			} else
912 972
 			{
913 973
 				$upcontext['user']['id'] = 1;
914 974
 				$upcontext['user']['name'] = 'Administrator';
@@ -924,11 +984,11 @@  discard block
 block discarded – undo
924 984
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
925 985
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
926 986
 
927
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
928
-					$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'] . '.';
929
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
930
-					$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'] . '.';
931
-				else
987
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
988
+									$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'] . '.';
989
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
990
+									$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'] . '.';
991
+				} else
932 992
 				{
933 993
 					// Set this as the new language.
934 994
 					$upcontext['language'] = $user_language;
@@ -972,8 +1032,9 @@  discard block
 block discarded – undo
972 1032
 	unset($member_columns);
973 1033
 
974 1034
 	// If we've not submitted then we're done.
975
-	if (empty($_POST['upcont']))
976
-		return false;
1035
+	if (empty($_POST['upcont'])) {
1036
+			return false;
1037
+	}
977 1038
 
978 1039
 	require_once($sourcedir . '/Subs-Admin.php');
979 1040
 	updateSettingsFile(array('image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\''));
@@ -991,25 +1052,26 @@  discard block
 block discarded – undo
991 1052
 			fwrite($fp, $out);
992 1053
 
993 1054
 			$return_data = '';
994
-			while (!feof($fp))
995
-				$return_data .= fgets($fp, 128);
1055
+			while (!feof($fp)) {
1056
+							$return_data .= fgets($fp, 128);
1057
+			}
996 1058
 
997 1059
 			fclose($fp);
998 1060
 
999 1061
 			// Get the unique site ID.
1000 1062
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1001 1063
 
1002
-			if (!empty($ID[1]))
1003
-				$smcFunc['db_insert']('replace',
1064
+			if (!empty($ID[1])) {
1065
+							$smcFunc['db_insert']('replace',
1004 1066
 					$db_prefix . 'settings',
1005 1067
 					array('variable' => 'string', 'value' => 'string'),
1006 1068
 					array('allow_sm_stats', $ID[1]),
1007 1069
 					array('variable')
1008 1070
 				);
1071
+			}
1009 1072
 		}
1010
-	}
1011
-	else
1012
-		$smcFunc['db_query']('', '
1073
+	} else {
1074
+			$smcFunc['db_query']('', '
1013 1075
 			DELETE FROM {db_prefix}settings
1014 1076
 			WHERE variable = {string:allow_sm_stats}',
1015 1077
 			array(
@@ -1017,6 +1079,7 @@  discard block
 block discarded – undo
1017 1079
 				'db_error_skip' => true,
1018 1080
 			)
1019 1081
 		);
1082
+	}
1020 1083
 
1021 1084
 	// Deleting old karma stuff?
1022 1085
 	if (!empty($_POST['delete_karma']))
@@ -1031,20 +1094,22 @@  discard block
 block discarded – undo
1031 1094
 		);
1032 1095
 
1033 1096
 		// Cleaning up old karma member settings.
1034
-		if ($upcontext['karma_installed']['good'])
1035
-			$smcFunc['db_query']('', '
1097
+		if ($upcontext['karma_installed']['good']) {
1098
+					$smcFunc['db_query']('', '
1036 1099
 				ALTER TABLE {db_prefix}members
1037 1100
 				DROP karma_good',
1038 1101
 				array()
1039 1102
 			);
1103
+		}
1040 1104
 
1041 1105
 		// Does karma bad was enable?
1042
-		if ($upcontext['karma_installed']['bad'])
1043
-			$smcFunc['db_query']('', '
1106
+		if ($upcontext['karma_installed']['bad']) {
1107
+					$smcFunc['db_query']('', '
1044 1108
 				ALTER TABLE {db_prefix}members
1045 1109
 				DROP karma_bad',
1046 1110
 				array()
1047 1111
 			);
1112
+		}
1048 1113
 
1049 1114
 		// Cleaning up old karma permissions.
1050 1115
 		$smcFunc['db_query']('', '
@@ -1057,18 +1122,20 @@  discard block
 block discarded – undo
1057 1122
 	}
1058 1123
 
1059 1124
 	// Emptying the error log?
1060
-	if (!empty($_POST['empty_error']))
1061
-		$smcFunc['db_query']('truncate_table', '
1125
+	if (!empty($_POST['empty_error'])) {
1126
+			$smcFunc['db_query']('truncate_table', '
1062 1127
 			TRUNCATE {db_prefix}log_errors',
1063 1128
 			array(
1064 1129
 			)
1065 1130
 		);
1131
+	}
1066 1132
 
1067 1133
 	$changes = array();
1068 1134
 
1069 1135
 	// If we're overriding the language follow it through.
1070
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1071
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1136
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1137
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1138
+	}
1072 1139
 
1073 1140
 	if (!empty($_POST['maint']))
1074 1141
 	{
@@ -1080,37 +1147,42 @@  discard block
 block discarded – undo
1080 1147
 		{
1081 1148
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1082 1149
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1083
-		}
1084
-		else
1150
+		} else
1085 1151
 		{
1086 1152
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1087 1153
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1088 1154
 		}
1089 1155
 	}
1090 1156
 
1091
-	if ($command_line)
1092
-		echo ' * Updating Settings.php...';
1157
+	if ($command_line) {
1158
+			echo ' * Updating Settings.php...';
1159
+	}
1093 1160
 
1094 1161
 	// Backup the current one first.
1095 1162
 	copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
1096 1163
 
1097 1164
 	// Fix some old paths.
1098
-	if (substr($boarddir, 0, 1) == '.')
1099
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1165
+	if (substr($boarddir, 0, 1) == '.') {
1166
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1167
+	}
1100 1168
 
1101
-	if (substr($sourcedir, 0, 1) == '.')
1102
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1169
+	if (substr($sourcedir, 0, 1) == '.') {
1170
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1171
+	}
1103 1172
 
1104
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1105
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1173
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1174
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1175
+	}
1106 1176
 
1107 1177
 	// Not had the database type added before?
1108
-	if (empty($db_type))
1109
-		$changes['db_type'] = 'mysql';
1178
+	if (empty($db_type)) {
1179
+			$changes['db_type'] = 'mysql';
1180
+	}
1110 1181
 
1111 1182
 	// For now we offer a option, this may change in future versions when mysql is completely removed.
1112
-	if (!empty($_POST['convertMysql']) && $db_type == 'mysql')
1113
-		$changes['db_type'] = '\'mysqli\'';
1183
+	if (!empty($_POST['convertMysql']) && $db_type == 'mysql') {
1184
+			$changes['db_type'] = '\'mysqli\'';
1185
+	}
1114 1186
 
1115 1187
 	// If they have a "host:port" setup for the host, split that into separate values
1116 1188
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1121,28 +1193,31 @@  discard block
 block discarded – undo
1121 1193
 		$changes['db_server'] = '\'' . $db_server . '\'';
1122 1194
 
1123 1195
 		// Only set this if we're not using the default port
1124
-		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1125
-			$changes['db_port'] = (int) $db_port;
1126
-	}
1127
-	elseif (!empty($db_port))
1196
+		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1197
+					$changes['db_port'] = (int) $db_port;
1198
+		}
1199
+	} elseif (!empty($db_port))
1128 1200
 	{
1129 1201
 		// If db_port is set and is the same as the default, set it to ''
1130 1202
 		if ($db_type == 'mysql' || $db_type == 'mysqli')
1131 1203
 		{
1132
-			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1133
-				$changes['db_port'] = '\'\'';
1134
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1135
-				$changes['db_port'] = '\'\'';
1204
+			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1205
+							$changes['db_port'] = '\'\'';
1206
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1207
+							$changes['db_port'] = '\'\'';
1208
+			}
1136 1209
 		}
1137 1210
 	}
1138 1211
 
1139 1212
 	// Maybe we haven't had this option yet?
1140
-	if (empty($packagesdir))
1141
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1213
+	if (empty($packagesdir)) {
1214
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1215
+	}
1142 1216
 
1143 1217
 	// Add support for $tasksdir var.
1144
-	if (empty($tasksdir))
1145
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1218
+	if (empty($tasksdir)) {
1219
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1220
+	}
1146 1221
 
1147 1222
 	// @todo Maybe change the cookie name if going to 1.1, too?
1148 1223
 
@@ -1187,8 +1262,7 @@  discard block
 block discarded – undo
1187 1262
 			$found_old = true;
1188 1263
 			// Replace the old line with the new code
1189 1264
 			$settings_file = str_replace('$db_last_error = ' . $db_last_error . ';', $error_catching_header . $error_catching, $settings_file);
1190
-		}
1191
-		else
1265
+		} else
1192 1266
 		{
1193 1267
 			$found_old = false;
1194 1268
 			// We want the comments as well as the code...
@@ -1219,8 +1293,9 @@  discard block
 block discarded – undo
1219 1293
 		fclose($file);
1220 1294
 	}
1221 1295
 
1222
-	if ($command_line)
1223
-		echo ' Successful.' . "\n";
1296
+	if ($command_line) {
1297
+			echo ' Successful.' . "\n";
1298
+	}
1224 1299
 
1225 1300
 	// Are we doing debug?
1226 1301
 	if (isset($_POST['debug']))
@@ -1230,8 +1305,9 @@  discard block
 block discarded – undo
1230 1305
 	}
1231 1306
 
1232 1307
 	// If we're not backing up then jump one.
1233
-	if (empty($_POST['backup']))
1234
-		$upcontext['current_step']++;
1308
+	if (empty($_POST['backup'])) {
1309
+			$upcontext['current_step']++;
1310
+	}
1235 1311
 
1236 1312
 	// If we've got here then let's proceed to the next step!
1237 1313
 	return true;
@@ -1246,8 +1322,9 @@  discard block
 block discarded – undo
1246 1322
 	$upcontext['page_title'] = 'Backup Database';
1247 1323
 
1248 1324
 	// Done it already - js wise?
1249
-	if (!empty($_POST['backup_done']))
1250
-		return true;
1325
+	if (!empty($_POST['backup_done'])) {
1326
+			return true;
1327
+	}
1251 1328
 
1252 1329
 	// Some useful stuff here.
1253 1330
 	db_extend();
@@ -1261,9 +1338,10 @@  discard block
 block discarded – undo
1261 1338
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1262 1339
 
1263 1340
 	$table_names = array();
1264
-	foreach ($tables as $table)
1265
-		if (substr($table, 0, 7) !== 'backup_')
1341
+	foreach ($tables as $table) {
1342
+			if (substr($table, 0, 7) !== 'backup_')
1266 1343
 			$table_names[] = $table;
1344
+	}
1267 1345
 
1268 1346
 	$upcontext['table_count'] = count($table_names);
1269 1347
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1273,12 +1351,14 @@  discard block
 block discarded – undo
1273 1351
 	$file_steps = $upcontext['table_count'];
1274 1352
 
1275 1353
 	// What ones have we already done?
1276
-	foreach ($table_names as $id => $table)
1277
-		if ($id < $_GET['substep'])
1354
+	foreach ($table_names as $id => $table) {
1355
+			if ($id < $_GET['substep'])
1278 1356
 			$upcontext['previous_tables'][] = $table;
1357
+	}
1279 1358
 
1280
-	if ($command_line)
1281
-		echo 'Backing Up Tables.';
1359
+	if ($command_line) {
1360
+			echo 'Backing Up Tables.';
1361
+	}
1282 1362
 
1283 1363
 	// If we don't support javascript we backup here.
1284 1364
 	if (!$support_js || isset($_GET['xml']))
@@ -1297,8 +1377,9 @@  discard block
 block discarded – undo
1297 1377
 			backupTable($table_names[$substep]);
1298 1378
 
1299 1379
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1300
-			if (isset($_GET['xml']))
1301
-				return upgradeExit();
1380
+			if (isset($_GET['xml'])) {
1381
+							return upgradeExit();
1382
+			}
1302 1383
 		}
1303 1384
 
1304 1385
 		if ($command_line)
@@ -1331,9 +1412,10 @@  discard block
 block discarded – undo
1331 1412
 
1332 1413
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1333 1414
 
1334
-	if ($command_line)
1335
-		echo ' done.';
1336
-}
1415
+	if ($command_line) {
1416
+			echo ' done.';
1417
+	}
1418
+	}
1337 1419
 
1338 1420
 // Step 2: Everything.
1339 1421
 function DatabaseChanges()
@@ -1342,8 +1424,9 @@  discard block
 block discarded – undo
1342 1424
 	global $upcontext, $support_js, $db_type;
1343 1425
 
1344 1426
 	// Have we just completed this?
1345
-	if (!empty($_POST['database_done']))
1346
-		return true;
1427
+	if (!empty($_POST['database_done'])) {
1428
+			return true;
1429
+	}
1347 1430
 
1348 1431
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1349 1432
 	$upcontext['page_title'] = 'Database Changes';
@@ -1360,15 +1443,16 @@  discard block
 block discarded – undo
1360 1443
 	);
1361 1444
 
1362 1445
 	// How many files are there in total?
1363
-	if (isset($_GET['filecount']))
1364
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1365
-	else
1446
+	if (isset($_GET['filecount'])) {
1447
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1448
+	} else
1366 1449
 	{
1367 1450
 		$upcontext['file_count'] = 0;
1368 1451
 		foreach ($files as $file)
1369 1452
 		{
1370
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1371
-				$upcontext['file_count']++;
1453
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1454
+							$upcontext['file_count']++;
1455
+			}
1372 1456
 		}
1373 1457
 	}
1374 1458
 
@@ -1378,9 +1462,9 @@  discard block
 block discarded – undo
1378 1462
 	$upcontext['cur_file_num'] = 0;
1379 1463
 	foreach ($files as $file)
1380 1464
 	{
1381
-		if ($did_not_do)
1382
-			$did_not_do--;
1383
-		else
1465
+		if ($did_not_do) {
1466
+					$did_not_do--;
1467
+		} else
1384 1468
 		{
1385 1469
 			$upcontext['cur_file_num']++;
1386 1470
 			$upcontext['cur_file_name'] = $file[0];
@@ -1407,12 +1491,13 @@  discard block
 block discarded – undo
1407 1491
 					// Flag to move on to the next.
1408 1492
 					$upcontext['completed_step'] = true;
1409 1493
 					// Did we complete the whole file?
1410
-					if ($nextFile)
1411
-						$upcontext['current_debug_item_num'] = -1;
1494
+					if ($nextFile) {
1495
+											$upcontext['current_debug_item_num'] = -1;
1496
+					}
1412 1497
 					return upgradeExit();
1498
+				} elseif ($support_js) {
1499
+									break;
1413 1500
 				}
1414
-				elseif ($support_js)
1415
-					break;
1416 1501
 			}
1417 1502
 			// Set the progress bar to be right as if we had - even if we hadn't...
1418 1503
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1436,8 +1521,9 @@  discard block
 block discarded – undo
1436 1521
 	global $db_prefix, $upcontext, $boarddir, $packagesdir, $settings, $smcFunc, $command_line;
1437 1522
 
1438 1523
 	// Sorry. Not supported for command line users.
1439
-	if ($command_line)
1440
-		return true;
1524
+	if ($command_line) {
1525
+			return true;
1526
+	}
1441 1527
 
1442 1528
 	// Skipping first?
1443 1529
 	if (!empty($_POST['skip']))
@@ -1447,8 +1533,9 @@  discard block
 block discarded – undo
1447 1533
 	}
1448 1534
 
1449 1535
 	// If we get here withOUT SSI we need to redirect to ensure we get it!
1450
-	if (!isset($_GET['ssi']) || !function_exists('mktree'))
1451
-		redirectLocation('&ssi=1');
1536
+	if (!isset($_GET['ssi']) || !function_exists('mktree')) {
1537
+			redirectLocation('&ssi=1');
1538
+	}
1452 1539
 
1453 1540
 	$upcontext['sub_template'] = 'clean_mods';
1454 1541
 	$upcontext['page_title'] = 'Cleanup Modifications';
@@ -1457,8 +1544,9 @@  discard block
 block discarded – undo
1457 1544
 	$upcontext['skip'] = true;
1458 1545
 
1459 1546
 	// If we're on the second redirect continue...
1460
-	if (isset($_POST['cleandone2']))
1461
-		return true;
1547
+	if (isset($_POST['cleandone2'])) {
1548
+			return true;
1549
+	}
1462 1550
 
1463 1551
 	// Do we already know about some writable files?
1464 1552
 	if (isset($_POST['writable_files']))
@@ -1473,8 +1561,9 @@  discard block
 block discarded – undo
1473 1561
 	}
1474 1562
 
1475 1563
 	// Make sure we have some sort of packages directory.
1476
-	if (!isset($packagesdir))
1477
-		$packagesdir = $boarddir . '/Packages';
1564
+	if (!isset($packagesdir)) {
1565
+			$packagesdir = $boarddir . '/Packages';
1566
+	}
1478 1567
 
1479 1568
 	// Load all theme paths....
1480 1569
 	$request = $smcFunc['db_query']('', '
@@ -1492,10 +1581,11 @@  discard block
 block discarded – undo
1492 1581
 	$theme_paths = array();
1493 1582
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1494 1583
 	{
1495
-		if ($row['id_theme'] == 1)
1496
-			$settings['default_' . $row['variable']] = $row['value'];
1497
-		elseif ($row['variable'] == 'theme_dir')
1498
-			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1584
+		if ($row['id_theme'] == 1) {
1585
+					$settings['default_' . $row['variable']] = $row['value'];
1586
+		} elseif ($row['variable'] == 'theme_dir') {
1587
+					$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1588
+		}
1499 1589
 	}
1500 1590
 	$smcFunc['db_free_result']($request);
1501 1591
 
@@ -1519,8 +1609,7 @@  discard block
 block discarded – undo
1519 1609
 			$status = 'Missing';
1520 1610
 			$status_color = 'red';
1521 1611
 			$result = 'Removed';
1522
-		}
1523
-		else
1612
+		} else
1524 1613
 		{
1525 1614
 			$status = 'Installed';
1526 1615
 			$status_color = 'green';
@@ -1545,12 +1634,14 @@  discard block
 block discarded – undo
1545 1634
 	$smcFunc['db_free_result']($request);
1546 1635
 
1547 1636
 	// Don't carry on if there are none.
1548
-	if (empty($upcontext['packages']))
1549
-		return true;
1637
+	if (empty($upcontext['packages'])) {
1638
+			return true;
1639
+	}
1550 1640
 
1551 1641
 	// Setup some basics.
1552
-	if (!empty($upcontext['user']['version']))
1553
-		$_SESSION['version_emulate'] = $upcontext['user']['version'];
1642
+	if (!empty($upcontext['user']['version'])) {
1643
+			$_SESSION['version_emulate'] = $upcontext['user']['version'];
1644
+	}
1554 1645
 
1555 1646
 	// Before we get started, don't report notice errors.
1556 1647
 	$oldErrorReporting = error_reporting(E_ALL ^ E_NOTICE);
@@ -1573,34 +1664,40 @@  discard block
 block discarded – undo
1573 1664
 	foreach ($upcontext['packages'] as $id => $package)
1574 1665
 	{
1575 1666
 		// Can't do anything about this....
1576
-		if ($package['missing_file'])
1577
-			continue;
1667
+		if ($package['missing_file']) {
1668
+					continue;
1669
+		}
1578 1670
 
1579 1671
 		// Not testing *and* this wasn't checked?
1580
-		if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id])))
1581
-			continue;
1672
+		if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id]))) {
1673
+					continue;
1674
+		}
1582 1675
 
1583 1676
 		// What are the themes this was installed into?
1584 1677
 		$cur_theme_paths = array();
1585
-		foreach ($theme_paths as $tid => $data)
1586
-			if ($tid != 1 && in_array($tid, $package['themes']))
1678
+		foreach ($theme_paths as $tid => $data) {
1679
+					if ($tid != 1 && in_array($tid, $package['themes']))
1587 1680
 				$cur_theme_paths[$tid] = $data;
1681
+		}
1588 1682
 
1589 1683
 		// Get the modifications data if applicable.
1590 1684
 		$filename = $package['filename'];
1591 1685
 		$packageInfo = getPackageInfo($filename);
1592
-		if (!is_array($packageInfo))
1593
-			continue;
1686
+		if (!is_array($packageInfo)) {
1687
+					continue;
1688
+		}
1594 1689
 
1595 1690
 		$info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall');
1596 1691
 		// Also get the reinstall details...
1597
-		if (isset($_POST['remove']))
1598
-			$infoInstall = parsePackageInfo($packageInfo['xml'], true);
1692
+		if (isset($_POST['remove'])) {
1693
+					$infoInstall = parsePackageInfo($packageInfo['xml'], true);
1694
+		}
1599 1695
 
1600
-		if (is_file($packagesdir . '/' . $filename))
1601
-			read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp');
1602
-		else
1603
-			copytree($packagesdir . '/' . $filename, $packagesdir . '/temp');
1696
+		if (is_file($packagesdir . '/' . $filename)) {
1697
+					read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp');
1698
+		} else {
1699
+					copytree($packagesdir . '/' . $filename, $packagesdir . '/temp');
1700
+		}
1604 1701
 
1605 1702
 		// Work out how we uninstall...
1606 1703
 		$files = array();
@@ -1612,16 +1709,18 @@  discard block
 block discarded – undo
1612 1709
 			if ($change['type'] == 'modification')
1613 1710
 			{
1614 1711
 				$contents = @file_get_contents($packagesdir . '/temp/' . $upcontext['base_path'] . $change['filename']);
1615
-				if ($change['boardmod'])
1616
-					$results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths);
1617
-				else
1618
-					$results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths);
1712
+				if ($change['boardmod']) {
1713
+									$results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths);
1714
+				} else {
1715
+									$results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths);
1716
+				}
1619 1717
 
1620 1718
 				foreach ($results as $action)
1621 1719
 				{
1622 1720
 					// Something we can remove? Probably means it existed!
1623
-					if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files))
1624
-						$files[] = $action['filename'];
1721
+					if (($action['type'] == 'replace' || $action['type'] == 'append' || (!empty($action['filename']) && $action['type'] == 'failure')) && !in_array($action['filename'], $files)) {
1722
+											$files[] = $action['filename'];
1723
+					}
1625 1724
 					if ($action['type'] == 'failure')
1626 1725
 					{
1627 1726
 						$upcontext['packages'][$id]['needs_removing'] = true;
@@ -1637,17 +1736,19 @@  discard block
 block discarded – undo
1637 1736
 		$upcontext['packages'][$id]['file_count'] = count($files);
1638 1737
 
1639 1738
 		// If we've done something save the changes!
1640
-		if (!$test)
1641
-			package_flush_cache();
1739
+		if (!$test) {
1740
+					package_flush_cache();
1741
+		}
1642 1742
 
1643 1743
 		// Are we attempting to reinstall this thing?
1644 1744
 		if (isset($_POST['remove']) && !$test && isset($infoInstall))
1645 1745
 		{
1646 1746
 			// Need to extract again I'm afraid.
1647
-			if (is_file($packagesdir . '/' . $filename))
1648
-				read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp');
1649
-			else
1650
-				copytree($packagesdir . '/' . $filename, $packagesdir . '/temp');
1747
+			if (is_file($packagesdir . '/' . $filename)) {
1748
+							read_tgz_file($packagesdir . '/' . $filename, $packagesdir . '/temp');
1749
+			} else {
1750
+							copytree($packagesdir . '/' . $filename, $packagesdir . '/temp');
1751
+			}
1651 1752
 
1652 1753
 			$errors = false;
1653 1754
 			$upcontext['packages'][$id]['result'] = 'Removed';
@@ -1656,15 +1757,17 @@  discard block
 block discarded – undo
1656 1757
 				if ($change['type'] == 'modification')
1657 1758
 				{
1658 1759
 					$contents = @file_get_contents($packagesdir . '/temp/' . $upcontext['base_path'] . $change['filename']);
1659
-					if ($change['boardmod'])
1660
-						$results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths);
1661
-					else
1662
-						$results = parseModification($contents, true, $change['reverse'], $cur_theme_paths);
1760
+					if ($change['boardmod']) {
1761
+											$results = parseBoardMod($contents, true, $change['reverse'], $cur_theme_paths);
1762
+					} else {
1763
+											$results = parseModification($contents, true, $change['reverse'], $cur_theme_paths);
1764
+					}
1663 1765
 
1664 1766
 					// Are there any errors?
1665
-					foreach ($results as $action)
1666
-						if ($action['type'] == 'failure')
1767
+					foreach ($results as $action) {
1768
+											if ($action['type'] == 'failure')
1667 1769
 							$errors = true;
1770
+					}
1668 1771
 				}
1669 1772
 			}
1670 1773
 			if (!$errors)
@@ -1677,10 +1780,11 @@  discard block
 block discarded – undo
1677 1780
 					if ($change['type'] == 'modification')
1678 1781
 					{
1679 1782
 						$contents = @file_get_contents($packagesdir . '/temp/' . $upcontext['base_path'] . $change['filename']);
1680
-						if ($change['boardmod'])
1681
-							$results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths);
1682
-						else
1683
-							$results = parseModification($contents, false, $change['reverse'], $cur_theme_paths);
1783
+						if ($change['boardmod']) {
1784
+													$results = parseBoardMod($contents, false, $change['reverse'], $cur_theme_paths);
1785
+						} else {
1786
+													$results = parseModification($contents, false, $change['reverse'], $cur_theme_paths);
1787
+						}
1684 1788
 					}
1685 1789
 				}
1686 1790
 
@@ -1699,9 +1803,10 @@  discard block
 block discarded – undo
1699 1803
 		$writable_files = array();
1700 1804
 		foreach ($upcontext['packages'] as $package)
1701 1805
 		{
1702
-			if (!empty($package['files']))
1703
-				foreach ($package['files'] as $file)
1806
+			if (!empty($package['files'])) {
1807
+							foreach ($package['files'] as $file)
1704 1808
 					$writable_files[] = $file;
1809
+			}
1705 1810
 		}
1706 1811
 
1707 1812
 		if (!empty($writable_files))
@@ -1709,13 +1814,15 @@  discard block
 block discarded – undo
1709 1814
 			$writable_files = array_unique($writable_files);
1710 1815
 			$upcontext['writable_files'] = $writable_files;
1711 1816
 
1712
-			if (!makeFilesWritable($writable_files))
1713
-				return false;
1817
+			if (!makeFilesWritable($writable_files)) {
1818
+							return false;
1819
+			}
1714 1820
 		}
1715 1821
 	}
1716 1822
 
1717
-	if (file_exists($packagesdir . '/temp'))
1718
-		deltree($packagesdir . '/temp');
1823
+	if (file_exists($packagesdir . '/temp')) {
1824
+			deltree($packagesdir . '/temp');
1825
+	}
1719 1826
 
1720 1827
 	// Removing/Reinstalling any packages?
1721 1828
 	if (isset($_POST['remove']))
@@ -1723,32 +1830,35 @@  discard block
 block discarded – undo
1723 1830
 		$deletes = array();
1724 1831
 		foreach ($_POST['remove'] as $id => $dummy)
1725 1832
 		{
1726
-			if (!in_array((int) $id, $reinstall_worked))
1727
-				$deletes[] = (int) $id;
1833
+			if (!in_array((int) $id, $reinstall_worked)) {
1834
+							$deletes[] = (int) $id;
1835
+			}
1728 1836
 		}
1729 1837
 
1730
-		if (!empty($deletes))
1731
-			upgrade_query('
1838
+		if (!empty($deletes)) {
1839
+					upgrade_query('
1732 1840
 				UPDATE ' . $db_prefix . 'log_packages
1733 1841
 				SET install_state = 0
1734 1842
 				WHERE id_install IN (' . implode(',', $deletes) . ')');
1843
+		}
1735 1844
 
1736 1845
 		// Ensure we don't lose our changes!
1737 1846
 		package_put_contents($packagesdir . '/installed.list', time());
1738 1847
 
1739 1848
 		$upcontext['sub_template'] = 'cleanup_done';
1740 1849
 		return false;
1741
-	}
1742
-	else
1850
+	} else
1743 1851
 	{
1744 1852
 		$allgood = true;
1745 1853
 		// Is there actually anything that needs our attention?
1746
-		foreach ($upcontext['packages'] as $package)
1747
-			if ($package['color'] != 'green')
1854
+		foreach ($upcontext['packages'] as $package) {
1855
+					if ($package['color'] != 'green')
1748 1856
 				$allgood = false;
1857
+		}
1749 1858
 
1750
-		if ($allgood)
1751
-			return true;
1859
+		if ($allgood) {
1860
+					return true;
1861
+		}
1752 1862
 	}
1753 1863
 
1754 1864
 	$_GET['substep'] = 0;
@@ -1762,8 +1872,9 @@  discard block
 block discarded – undo
1762 1872
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1763 1873
 
1764 1874
 	// Now it's nice to have some of the basic SMF source files.
1765
-	if (!isset($_GET['ssi']) && !$command_line)
1766
-		redirectLocation('&ssi=1');
1875
+	if (!isset($_GET['ssi']) && !$command_line) {
1876
+			redirectLocation('&ssi=1');
1877
+	}
1767 1878
 
1768 1879
 	$upcontext['sub_template'] = 'upgrade_complete';
1769 1880
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1779,14 +1890,16 @@  discard block
 block discarded – undo
1779 1890
 	// Are we in maintenance mode?
1780 1891
 	if (isset($upcontext['user']['main']))
1781 1892
 	{
1782
-		if ($command_line)
1783
-			echo ' * ';
1893
+		if ($command_line) {
1894
+					echo ' * ';
1895
+		}
1784 1896
 		$upcontext['removed_maintenance'] = true;
1785 1897
 		$changes['maintenance'] = $upcontext['user']['main'];
1786 1898
 	}
1787 1899
 	// Otherwise if somehow we are in 2 let's go to 1.
1788
-	elseif (!empty($maintenance) && $maintenance == 2)
1789
-		$changes['maintenance'] = 1;
1900
+	elseif (!empty($maintenance) && $maintenance == 2) {
1901
+			$changes['maintenance'] = 1;
1902
+	}
1790 1903
 
1791 1904
 	// Wipe this out...
1792 1905
 	$upcontext['user'] = array();
@@ -1802,9 +1915,9 @@  discard block
 block discarded – undo
1802 1915
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1803 1916
 
1804 1917
 	// Now is the perfect time to fetch the SM files.
1805
-	if ($command_line)
1806
-		cli_scheduled_fetchSMfiles();
1807
-	else
1918
+	if ($command_line) {
1919
+			cli_scheduled_fetchSMfiles();
1920
+	} else
1808 1921
 	{
1809 1922
 		require_once($sourcedir . '/ScheduledTasks.php');
1810 1923
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1812,8 +1925,9 @@  discard block
 block discarded – undo
1812 1925
 	}
1813 1926
 
1814 1927
 	// Log what we've done.
1815
-	if (empty($user_info['id']))
1816
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1928
+	if (empty($user_info['id'])) {
1929
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1930
+	}
1817 1931
 
1818 1932
 	// Log the action manually, so CLI still works.
1819 1933
 	$smcFunc['db_insert']('',
@@ -1832,8 +1946,9 @@  discard block
 block discarded – undo
1832 1946
 
1833 1947
 	// Save the current database version.
1834 1948
 	$server_version = $smcFunc['db_server_info']();
1835
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1836
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1949
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1950
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1951
+	}
1837 1952
 
1838 1953
 	if ($command_line)
1839 1954
 	{
@@ -1845,8 +1960,9 @@  discard block
 block discarded – undo
1845 1960
 
1846 1961
 	// Make sure it says we're done.
1847 1962
 	$upcontext['overall_percent'] = 100;
1848
-	if (isset($upcontext['step_progress']))
1849
-		unset($upcontext['step_progress']);
1963
+	if (isset($upcontext['step_progress'])) {
1964
+			unset($upcontext['step_progress']);
1965
+	}
1850 1966
 
1851 1967
 	$_GET['substep'] = 0;
1852 1968
 	return false;
@@ -1857,8 +1973,9 @@  discard block
 block discarded – undo
1857 1973
 {
1858 1974
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1859 1975
 
1860
-	if (empty($modSettings['time_format']))
1861
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1976
+	if (empty($modSettings['time_format'])) {
1977
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1978
+	}
1862 1979
 
1863 1980
 	// What files do we want to get
1864 1981
 	$request = $smcFunc['db_query']('', '
@@ -1892,8 +2009,9 @@  discard block
 block discarded – undo
1892 2009
 		$file_data = fetch_web_data($url);
1893 2010
 
1894 2011
 		// If we got an error - give up - the site might be down.
1895
-		if ($file_data === false)
1896
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
2012
+		if ($file_data === false) {
2013
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
2014
+		}
1897 2015
 
1898 2016
 		// Save the file to the database.
1899 2017
 		$smcFunc['db_query']('substring', '
@@ -1935,8 +2053,9 @@  discard block
 block discarded – undo
1935 2053
 	$themeData = array();
1936 2054
 	foreach ($values as $variable => $value)
1937 2055
 	{
1938
-		if (!isset($value) || $value === null)
1939
-			$value = 0;
2056
+		if (!isset($value) || $value === null) {
2057
+					$value = 0;
2058
+		}
1940 2059
 
1941 2060
 		$themeData[] = array(0, 1, $variable, $value);
1942 2061
 	}
@@ -1965,8 +2084,9 @@  discard block
 block discarded – undo
1965 2084
 
1966 2085
 	foreach ($values as $variable => $value)
1967 2086
 	{
1968
-		if (empty($modSettings[$value[0]]))
1969
-			continue;
2087
+		if (empty($modSettings[$value[0]])) {
2088
+					continue;
2089
+		}
1970 2090
 
1971 2091
 		$smcFunc['db_query']('', '
1972 2092
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1999,8 +2119,9 @@  discard block
 block discarded – undo
1999 2119
 
2000 2120
 	$settingsArray = file($boarddir . '/Settings_bak.php');
2001 2121
 
2002
-	if (count($settingsArray) == 1)
2003
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
2122
+	if (count($settingsArray) == 1) {
2123
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
2124
+	}
2004 2125
 
2005 2126
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
2006 2127
 	{
@@ -2013,9 +2134,9 @@  discard block
 block discarded – undo
2013 2134
 			{
2014 2135
 				if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
2015 2136
 				{
2016
-					if ($val == '#remove#')
2017
-						unset($settingsArray[$i]);
2018
-					else
2137
+					if ($val == '#remove#') {
2138
+											unset($settingsArray[$i]);
2139
+					} else
2019 2140
 					{
2020 2141
 						$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
2021 2142
 						$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n");
@@ -2027,22 +2148,25 @@  discard block
 block discarded – undo
2027 2148
 		}
2028 2149
 		if (isset($settingsArray[$i]))
2029 2150
 		{
2030
-			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>')
2031
-				$end = $i;
2151
+			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') {
2152
+							$end = $i;
2153
+			}
2032 2154
 		}
2033 2155
 	}
2034 2156
 
2035 2157
 	// Assume end-of-file if the end wasn't found.
2036
-	if (empty($end) || $end < 10)
2037
-		$end = count($settingsArray);
2158
+	if (empty($end) || $end < 10) {
2159
+			$end = count($settingsArray);
2160
+	}
2038 2161
 
2039 2162
 	if (!empty($config_vars))
2040 2163
 	{
2041 2164
 		$settingsArray[$end++] = '';
2042 2165
 		foreach ($config_vars as $var => $val)
2043 2166
 		{
2044
-			if ($val != '#remove#')
2045
-				$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
2167
+			if ($val != '#remove#') {
2168
+							$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
2169
+			}
2046 2170
 		}
2047 2171
 	}
2048 2172
 	// This should be the last line and even last bytes of the file.
@@ -2055,8 +2179,9 @@  discard block
 block discarded – undo
2055 2179
 	$fp = fopen($boarddir . '/Settings.php', 'r+');
2056 2180
 	for ($i = 0; $i < $end; $i++)
2057 2181
 	{
2058
-		if (isset($settingsArray[$i]))
2059
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
2182
+		if (isset($settingsArray[$i])) {
2183
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
2184
+		}
2060 2185
 	}
2061 2186
 	fwrite($fp, rtrim($settingsArray[$i]));
2062 2187
 	fclose($fp);
@@ -2087,8 +2212,9 @@  discard block
 block discarded – undo
2087 2212
 	global $smcFunc;
2088 2213
 	static $member_groups = array();
2089 2214
 
2090
-	if (!empty($member_groups))
2091
-		return $member_groups;
2215
+	if (!empty($member_groups)) {
2216
+			return $member_groups;
2217
+	}
2092 2218
 
2093 2219
 	$request = $smcFunc['db_query']('', '
2094 2220
 		SELECT group_name, id_group
@@ -2113,8 +2239,9 @@  discard block
 block discarded – undo
2113 2239
 			)
2114 2240
 		);
2115 2241
 	}
2116
-	while ($row = $smcFunc['db_fetch_row']($request))
2117
-		$member_groups[trim($row[0])] = $row[1];
2242
+	while ($row = $smcFunc['db_fetch_row']($request)) {
2243
+			$member_groups[trim($row[0])] = $row[1];
2244
+	}
2118 2245
 	$smcFunc['db_free_result']($request);
2119 2246
 
2120 2247
 	return $member_groups;
@@ -2167,10 +2294,11 @@  discard block
 block discarded – undo
2167 2294
 		{
2168 2295
 			global $support_js;
2169 2296
 
2170
-			if ($support_js)
2171
-				return true;
2172
-			else
2173
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
2297
+			if ($support_js) {
2298
+							return true;
2299
+			} else {
2300
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
2301
+			}
2174 2302
 		}
2175 2303
 	}
2176 2304
 
@@ -2188,8 +2316,9 @@  discard block
 block discarded – undo
2188 2316
 				'db_error_skip' => true,
2189 2317
 			)
2190 2318
 		);
2191
-		if ($smcFunc['db_num_rows']($request) === 0)
2192
-			die('Unable to find members table!');
2319
+		if ($smcFunc['db_num_rows']($request) === 0) {
2320
+					die('Unable to find members table!');
2321
+		}
2193 2322
 		$table_status = $smcFunc['db_fetch_assoc']($request);
2194 2323
 		$smcFunc['db_free_result']($request);
2195 2324
 
@@ -2204,17 +2333,20 @@  discard block
 block discarded – undo
2204 2333
 				)
2205 2334
 			);
2206 2335
 			// Got something?
2207
-			if ($smcFunc['db_num_rows']($request) !== 0)
2208
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
2336
+			if ($smcFunc['db_num_rows']($request) !== 0) {
2337
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
2338
+			}
2209 2339
 			$smcFunc['db_free_result']($request);
2210 2340
 
2211 2341
 			// Excellent!
2212
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
2213
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
2342
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
2343
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
2344
+			}
2214 2345
 		}
2215 2346
 	}
2216
-	if (empty($db_collation))
2217
-		$db_collation = '';
2347
+	if (empty($db_collation)) {
2348
+			$db_collation = '';
2349
+	}
2218 2350
 
2219 2351
 	$endl = $command_line ? "\n" : '<br>' . "\n";
2220 2352
 
@@ -2226,8 +2358,9 @@  discard block
 block discarded – undo
2226 2358
 	$last_step = '';
2227 2359
 
2228 2360
 	// Make sure all newly created tables will have the proper characters set.
2229
-	if (isset($db_character_set) && $db_character_set === 'utf8')
2230
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
2361
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
2362
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
2363
+	}
2231 2364
 
2232 2365
 	// Count the total number of steps within this file - for progress.
2233 2366
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -2247,15 +2380,18 @@  discard block
 block discarded – undo
2247 2380
 		$do_current = $substep >= $_GET['substep'];
2248 2381
 
2249 2382
 		// Get rid of any comments in the beginning of the line...
2250
-		if (substr(trim($line), 0, 2) === '/*')
2251
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
2383
+		if (substr(trim($line), 0, 2) === '/*') {
2384
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
2385
+		}
2252 2386
 
2253 2387
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
2254
-		if ($is_debug && !$support_js && $command_line)
2255
-			flush();
2388
+		if ($is_debug && !$support_js && $command_line) {
2389
+					flush();
2390
+		}
2256 2391
 
2257
-		if (trim($line) === '')
2258
-			continue;
2392
+		if (trim($line) === '') {
2393
+					continue;
2394
+		}
2259 2395
 
2260 2396
 		if (trim(substr($line, 0, 3)) === '---')
2261 2397
 		{
@@ -2265,8 +2401,9 @@  discard block
 block discarded – undo
2265 2401
 			if (trim($current_data) != '' && $type !== '}')
2266 2402
 			{
2267 2403
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
2268
-				if ($command_line)
2269
-					echo $upcontext['error_message'];
2404
+				if ($command_line) {
2405
+									echo $upcontext['error_message'];
2406
+				}
2270 2407
 			}
2271 2408
 
2272 2409
 			if ($type == ' ')
@@ -2284,17 +2421,18 @@  discard block
 block discarded – undo
2284 2421
 				if ($do_current)
2285 2422
 				{
2286 2423
 					$upcontext['actioned_items'][] = $last_step;
2287
-					if ($command_line)
2288
-						echo ' * ';
2424
+					if ($command_line) {
2425
+											echo ' * ';
2426
+					}
2289 2427
 				}
2290
-			}
2291
-			elseif ($type == '#')
2428
+			} elseif ($type == '#')
2292 2429
 			{
2293 2430
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
2294 2431
 
2295 2432
 				$upcontext['current_debug_item_num']++;
2296
-				if (trim($line) != '---#')
2297
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2433
+				if (trim($line) != '---#') {
2434
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2435
+				}
2298 2436
 
2299 2437
 				// Have we already done something?
2300 2438
 				if (isset($_GET['xml']) && $done_something)
@@ -2305,34 +2443,36 @@  discard block
 block discarded – undo
2305 2443
 
2306 2444
 				if ($do_current)
2307 2445
 				{
2308
-					if (trim($line) == '---#' && $command_line)
2309
-						echo ' done.', $endl;
2310
-					elseif ($command_line)
2311
-						echo ' +++ ', rtrim(substr($line, 4));
2312
-					elseif (trim($line) != '---#')
2446
+					if (trim($line) == '---#' && $command_line) {
2447
+											echo ' done.', $endl;
2448
+					} elseif ($command_line) {
2449
+											echo ' +++ ', rtrim(substr($line, 4));
2450
+					} elseif (trim($line) != '---#')
2313 2451
 					{
2314
-						if ($is_debug)
2315
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2452
+						if ($is_debug) {
2453
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2454
+						}
2316 2455
 					}
2317 2456
 				}
2318 2457
 
2319 2458
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
2320 2459
 				{
2321
-					if ($command_line)
2322
-						echo ' * ';
2323
-					else
2324
-						$upcontext['actioned_items'][] = $last_step;
2460
+					if ($command_line) {
2461
+											echo ' * ';
2462
+					} else {
2463
+											$upcontext['actioned_items'][] = $last_step;
2464
+					}
2325 2465
 				}
2326 2466
 
2327 2467
 				// Small step - only if we're actually doing stuff.
2328
-				if ($do_current)
2329
-					nextSubstep(++$substep);
2330
-				else
2331
-					$substep++;
2332
-			}
2333
-			elseif ($type == '{')
2334
-				$current_type = 'code';
2335
-			elseif ($type == '}')
2468
+				if ($do_current) {
2469
+									nextSubstep(++$substep);
2470
+				} else {
2471
+									$substep++;
2472
+				}
2473
+			} elseif ($type == '{') {
2474
+							$current_type = 'code';
2475
+			} elseif ($type == '}')
2336 2476
 			{
2337 2477
 				$current_type = 'sql';
2338 2478
 
@@ -2345,8 +2485,9 @@  discard block
 block discarded – undo
2345 2485
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
2346 2486
 				{
2347 2487
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
2348
-					if ($command_line)
2349
-						echo $upcontext['error_message'];
2488
+					if ($command_line) {
2489
+											echo $upcontext['error_message'];
2490
+					}
2350 2491
 				}
2351 2492
 
2352 2493
 				// Done with code!
@@ -2426,8 +2567,9 @@  discard block
 block discarded – undo
2426 2567
 	$db_unbuffered = false;
2427 2568
 
2428 2569
 	// Failure?!
2429
-	if ($result !== false)
2430
-		return $result;
2570
+	if ($result !== false) {
2571
+			return $result;
2572
+	}
2431 2573
 
2432 2574
 	$db_error_message = $smcFunc['db_error']($db_connection);
2433 2575
 	// If MySQL we do something more clever.
@@ -2457,17 +2599,16 @@  discard block
 block discarded – undo
2457 2599
 				{
2458 2600
 					mysql_query('REPAIR TABLE `' . $match[1] . '`');
2459 2601
 					$result = mysql_query($string);
2460
-				}
2461
-				else
2602
+				} else
2462 2603
 				{
2463 2604
 					mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2464 2605
 					$result = mysqli_query($db_connection, $string);
2465 2606
 				}
2466
-				if ($result !== false)
2467
-					return $result;
2607
+				if ($result !== false) {
2608
+									return $result;
2609
+				}
2468 2610
 			}
2469
-		}
2470
-		elseif ($mysql_errno == 2013)
2611
+		} elseif ($mysql_errno == 2013)
2471 2612
 		{
2472 2613
 			$db_connection = mysql_connect($db_server, $db_user, $db_passwd);
2473 2614
 			if ($db_type == 'mysql')
@@ -2476,54 +2617,61 @@  discard block
 block discarded – undo
2476 2617
 				if ($db_connection)
2477 2618
 				{
2478 2619
 					$result = mysql_query($string);
2479
-					if ($result !== false)
2480
-						return $result;
2620
+					if ($result !== false) {
2621
+											return $result;
2622
+					}
2481 2623
 				}
2482
-			}
2483
-			else
2624
+			} else
2484 2625
 			{
2485 2626
 				mysqli_select_db($db_connection, $db_name);
2486 2627
 				if ($db_connection)
2487 2628
 				{
2488 2629
 					$result = mysqli_query($db_connection, $string);
2489
-					if ($result !== false)
2490
-						return $result;
2630
+					if ($result !== false) {
2631
+											return $result;
2632
+					}
2491 2633
 				}
2492 2634
 			}
2493 2635
 		}
2494 2636
 		// Duplicate column name... should be okay ;).
2495
-		elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091)))
2496
-			return false;
2637
+		elseif (in_array($mysql_errno, array(1060, 1061, 1068, 1091))) {
2638
+					return false;
2639
+		}
2497 2640
 		// Duplicate insert... make sure it's the proper type of query ;).
2498
-		elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query)
2499
-			return false;
2641
+		elseif (in_array($mysql_errno, array(1054, 1062, 1146)) && $error_query) {
2642
+					return false;
2643
+		}
2500 2644
 		// Creating an index on a non-existent column.
2501
-		elseif ($mysql_errno == 1072)
2502
-			return false;
2503
-		elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2504
-			return false;
2645
+		elseif ($mysql_errno == 1072) {
2646
+					return false;
2647
+		} elseif ($mysql_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2648
+					return false;
2649
+		}
2505 2650
 	}
2506 2651
 	// If a table already exists don't go potty.
2507 2652
 	else
2508 2653
 	{
2509 2654
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2510 2655
 		{
2511
-			if (strpos($db_error_message, 'exist') !== false)
2512
-				return true;
2513
-		}
2514
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2656
+			if (strpos($db_error_message, 'exist') !== false) {
2657
+							return true;
2658
+			}
2659
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2515 2660
 		{
2516
-			if (strpos($db_error_message, 'duplicate') !== false)
2517
-				return true;
2661
+			if (strpos($db_error_message, 'duplicate') !== false) {
2662
+							return true;
2663
+			}
2518 2664
 		}
2519 2665
 	}
2520 2666
 
2521 2667
 	// Get the query string so we pass everything.
2522 2668
 	$query_string = '';
2523
-	foreach ($_GET as $k => $v)
2524
-		$query_string .= ';' . $k . '=' . $v;
2525
-	if (strlen($query_string) != 0)
2526
-		$query_string = '?' . substr($query_string, 1);
2669
+	foreach ($_GET as $k => $v) {
2670
+			$query_string .= ';' . $k . '=' . $v;
2671
+	}
2672
+	if (strlen($query_string) != 0) {
2673
+			$query_string = '?' . substr($query_string, 1);
2674
+	}
2527 2675
 
2528 2676
 	if ($command_line)
2529 2677
 	{
@@ -2614,16 +2762,18 @@  discard block
 block discarded – undo
2614 2762
 			{
2615 2763
 				$found |= 1;
2616 2764
 				// Do some checks on the data if we have it set.
2617
-				if (isset($change['col_type']))
2618
-					$found &= $change['col_type'] === $column['type'];
2619
-				if (isset($change['null_allowed']))
2620
-					$found &= $column['null'] == $change['null_allowed'];
2621
-				if (isset($change['default']))
2622
-					$found &= $change['default'] === $column['default'];
2765
+				if (isset($change['col_type'])) {
2766
+									$found &= $change['col_type'] === $column['type'];
2767
+				}
2768
+				if (isset($change['null_allowed'])) {
2769
+									$found &= $column['null'] == $change['null_allowed'];
2770
+				}
2771
+				if (isset($change['default'])) {
2772
+									$found &= $change['default'] === $column['default'];
2773
+				}
2623 2774
 			}
2624 2775
 		}
2625
-	}
2626
-	elseif ($change['type'] === 'index')
2776
+	} elseif ($change['type'] === 'index')
2627 2777
 	{
2628 2778
 		$request = upgrade_query('
2629 2779
 			SHOW INDEX
@@ -2632,9 +2782,10 @@  discard block
 block discarded – undo
2632 2782
 		{
2633 2783
 			$cur_index = array();
2634 2784
 
2635
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2636
-				if ($row['Key_name'] === $change['name'])
2785
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2786
+							if ($row['Key_name'] === $change['name'])
2637 2787
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2788
+			}
2638 2789
 
2639 2790
 			ksort($cur_index, SORT_NUMERIC);
2640 2791
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2644,14 +2795,17 @@  discard block
 block discarded – undo
2644 2795
 	}
2645 2796
 
2646 2797
 	// If we're trying to add and it's added, we're done.
2647
-	if ($found && in_array($change['method'], array('add', 'change')))
2648
-		return true;
2798
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2799
+			return true;
2800
+	}
2649 2801
 	// Otherwise if we're removing and it wasn't found we're also done.
2650
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2651
-		return true;
2802
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2803
+			return true;
2804
+	}
2652 2805
 	// Otherwise is it just a test?
2653
-	elseif ($is_test)
2654
-		return false;
2806
+	elseif ($is_test) {
2807
+			return false;
2808
+	}
2655 2809
 
2656 2810
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2657 2811
 	$running = false;
@@ -2662,8 +2816,9 @@  discard block
 block discarded – undo
2662 2816
 			SHOW FULL PROCESSLIST');
2663 2817
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2664 2818
 		{
2665
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2666
-				$found = true;
2819
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2820
+							$found = true;
2821
+			}
2667 2822
 		}
2668 2823
 
2669 2824
 		// Can't find it? Then we need to run it fools!
@@ -2675,8 +2830,9 @@  discard block
 block discarded – undo
2675 2830
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2676 2831
 				' . $change['text'], true) !== false;
2677 2832
 
2678
-			if (!$success)
2679
-				return false;
2833
+			if (!$success) {
2834
+							return false;
2835
+			}
2680 2836
 
2681 2837
 			// Return
2682 2838
 			$running = true;
@@ -2709,8 +2865,7 @@  discard block
 block discarded – undo
2709 2865
 	{
2710 2866
 		$column_fix = true;
2711 2867
 		$null_fix = !$change['null_allowed'];
2712
-	}
2713
-	else
2868
+	} else
2714 2869
 	{
2715 2870
 		$request = $smcFunc['db_query']('', '
2716 2871
 			SHOW FULL COLUMNS
@@ -2721,8 +2876,9 @@  discard block
 block discarded – undo
2721 2876
 				'db_error_skip' => true,
2722 2877
 			)
2723 2878
 		);
2724
-		if ($smcFunc['db_num_rows']($request) === 0)
2725
-			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2879
+		if ($smcFunc['db_num_rows']($request) === 0) {
2880
+					die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2881
+		}
2726 2882
 		$table_row = $smcFunc['db_fetch_assoc']($request);
2727 2883
 		$smcFunc['db_free_result']($request);
2728 2884
 
@@ -2744,10 +2900,11 @@  discard block
 block discarded – undo
2744 2900
 				)
2745 2901
 			);
2746 2902
 			// No results? Just forget it all together.
2747
-			if ($smcFunc['db_num_rows']($request) === 0)
2748
-				unset($table_row['Collation']);
2749
-			else
2750
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
2903
+			if ($smcFunc['db_num_rows']($request) === 0) {
2904
+							unset($table_row['Collation']);
2905
+			} else {
2906
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
2907
+			}
2751 2908
 			$smcFunc['db_free_result']($request);
2752 2909
 		}
2753 2910
 	}
@@ -2755,8 +2912,8 @@  discard block
 block discarded – undo
2755 2912
 	if ($column_fix)
2756 2913
 	{
2757 2914
 		// Make sure there are no NULL's left.
2758
-		if ($null_fix)
2759
-			$smcFunc['db_query']('', '
2915
+		if ($null_fix) {
2916
+					$smcFunc['db_query']('', '
2760 2917
 				UPDATE {db_prefix}' . $change['table'] . '
2761 2918
 				SET ' . $change['column'] . ' = {string:default}
2762 2919
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2765,6 +2922,7 @@  discard block
 block discarded – undo
2765 2922
 					'db_error_skip' => true,
2766 2923
 				)
2767 2924
 			);
2925
+		}
2768 2926
 
2769 2927
 		// Do the actual alteration.
2770 2928
 		$smcFunc['db_query']('', '
@@ -2793,8 +2951,9 @@  discard block
 block discarded – undo
2793 2951
 	}
2794 2952
 
2795 2953
 	// Not a column we need to check on?
2796
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2797
-		return;
2954
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2955
+			return;
2956
+	}
2798 2957
 
2799 2958
 	// Break it up you (six|seven).
2800 2959
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2813,13 +2972,13 @@  discard block
 block discarded – undo
2813 2972
 				'new_name' => $temp[2],
2814 2973
 		));
2815 2974
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2816
-		if ($smcFunc['db_num_rows'] != 1)
2817
-			return;
2975
+		if ($smcFunc['db_num_rows'] != 1) {
2976
+					return;
2977
+		}
2818 2978
 
2819 2979
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2820 2980
 		$smcFunc['db_free_result']($request);
2821
-	}
2822
-	else
2981
+	} else
2823 2982
 	{
2824 2983
 		// Do this the old fashion, sure method way.
2825 2984
 		$request = $smcFunc['db_query']('', '
@@ -2830,21 +2989,24 @@  discard block
 block discarded – undo
2830 2989
 		));
2831 2990
 		// Mayday!
2832 2991
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2833
-		if ($smcFunc['db_num_rows'] == 0)
2834
-			return;
2992
+		if ($smcFunc['db_num_rows'] == 0) {
2993
+					return;
2994
+		}
2835 2995
 
2836 2996
 		// Oh where, oh where has my little field gone. Oh where can it be...
2837
-		while ($row = $smcFunc['db_query']($request))
2838
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2997
+		while ($row = $smcFunc['db_query']($request)) {
2998
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2839 2999
 			{
2840 3000
 				$current_type = $row['Type'];
3001
+		}
2841 3002
 				break;
2842 3003
 			}
2843 3004
 	}
2844 3005
 
2845 3006
 	// If this doesn't match, the column may of been altered for a reason.
2846
-	if (trim($current_type) != trim($temp[3]))
2847
-		$temp[3] = $current_type;
3007
+	if (trim($current_type) != trim($temp[3])) {
3008
+			$temp[3] = $current_type;
3009
+	}
2848 3010
 
2849 3011
 	// Piece this back together.
2850 3012
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2856,8 +3018,9 @@  discard block
 block discarded – undo
2856 3018
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2857 3019
 	global $step_progress, $is_debug, $upcontext;
2858 3020
 
2859
-	if ($_GET['substep'] < $substep)
2860
-		$_GET['substep'] = $substep;
3021
+	if ($_GET['substep'] < $substep) {
3022
+			$_GET['substep'] = $substep;
3023
+	}
2861 3024
 
2862 3025
 	if ($command_line)
2863 3026
 	{
@@ -2870,29 +3033,33 @@  discard block
 block discarded – undo
2870 3033
 	}
2871 3034
 
2872 3035
 	@set_time_limit(300);
2873
-	if (function_exists('apache_reset_timeout'))
2874
-		@apache_reset_timeout();
3036
+	if (function_exists('apache_reset_timeout')) {
3037
+			@apache_reset_timeout();
3038
+	}
2875 3039
 
2876
-	if (time() - $start_time <= $timeLimitThreshold)
2877
-		return;
3040
+	if (time() - $start_time <= $timeLimitThreshold) {
3041
+			return;
3042
+	}
2878 3043
 
2879 3044
 	// Do we have some custom step progress stuff?
2880 3045
 	if (!empty($step_progress))
2881 3046
 	{
2882 3047
 		$upcontext['substep_progress'] = 0;
2883 3048
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2884
-		if ($step_progress['current'] > $step_progress['total'])
2885
-			$upcontext['substep_progress'] = 99.9;
2886
-		else
2887
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
3049
+		if ($step_progress['current'] > $step_progress['total']) {
3050
+					$upcontext['substep_progress'] = 99.9;
3051
+		} else {
3052
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
3053
+		}
2888 3054
 
2889 3055
 		// Make it nicely rounded.
2890 3056
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2891 3057
 	}
2892 3058
 
2893 3059
 	// If this is XML we just exit right away!
2894
-	if (isset($_GET['xml']))
2895
-		return upgradeExit();
3060
+	if (isset($_GET['xml'])) {
3061
+			return upgradeExit();
3062
+	}
2896 3063
 
2897 3064
 	// We're going to pause after this!
2898 3065
 	$upcontext['pause'] = true;
@@ -2900,13 +3067,15 @@  discard block
 block discarded – undo
2900 3067
 	$upcontext['query_string'] = '';
2901 3068
 	foreach ($_GET as $k => $v)
2902 3069
 	{
2903
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2904
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
3070
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
3071
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
3072
+		}
2905 3073
 	}
2906 3074
 
2907 3075
 	// Custom warning?
2908
-	if (!empty($custom_warning))
2909
-		$upcontext['custom_warning'] = $custom_warning;
3076
+	if (!empty($custom_warning)) {
3077
+			$upcontext['custom_warning'] = $custom_warning;
3078
+	}
2910 3079
 
2911 3080
 	upgradeExit();
2912 3081
 }
@@ -2921,25 +3090,26 @@  discard block
 block discarded – undo
2921 3090
 	ob_implicit_flush(true);
2922 3091
 	@set_time_limit(600);
2923 3092
 
2924
-	if (!isset($_SERVER['argv']))
2925
-		$_SERVER['argv'] = array();
3093
+	if (!isset($_SERVER['argv'])) {
3094
+			$_SERVER['argv'] = array();
3095
+	}
2926 3096
 	$_GET['maint'] = 1;
2927 3097
 
2928 3098
 	foreach ($_SERVER['argv'] as $i => $arg)
2929 3099
 	{
2930
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2931
-			$_GET['lang'] = $match[1];
2932
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2933
-			continue;
2934
-		elseif ($arg == '--no-maintenance')
2935
-			$_GET['maint'] = 0;
2936
-		elseif ($arg == '--debug')
2937
-			$is_debug = true;
2938
-		elseif ($arg == '--backup')
2939
-			$_POST['backup'] = 1;
2940
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2941
-			$_GET['conv'] = 1;
2942
-		elseif ($i != 0)
3100
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
3101
+					$_GET['lang'] = $match[1];
3102
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
3103
+					continue;
3104
+		} elseif ($arg == '--no-maintenance') {
3105
+					$_GET['maint'] = 0;
3106
+		} elseif ($arg == '--debug') {
3107
+					$is_debug = true;
3108
+		} elseif ($arg == '--backup') {
3109
+					$_POST['backup'] = 1;
3110
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
3111
+					$_GET['conv'] = 1;
3112
+		} elseif ($i != 0)
2943 3113
 		{
2944 3114
 			echo 'SMF Command-line Upgrader
2945 3115
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2953,10 +3123,12 @@  discard block
 block discarded – undo
2953 3123
 		}
2954 3124
 	}
2955 3125
 
2956
-	if (!php_version_check())
2957
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2958
-	if (!db_version_check())
2959
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
3126
+	if (!php_version_check()) {
3127
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
3128
+	}
3129
+	if (!db_version_check()) {
3130
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
3131
+	}
2960 3132
 
2961 3133
 	// Do some checks to make sure they have proper privileges
2962 3134
 	db_extend('packages');
@@ -2971,34 +3143,39 @@  discard block
 block discarded – undo
2971 3143
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2972 3144
 
2973 3145
 	// Sorry... we need CREATE, ALTER and DROP
2974
-	if (!$create || !$alter || !$drop)
2975
-		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);
3146
+	if (!$create || !$alter || !$drop) {
3147
+			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);
3148
+	}
2976 3149
 
2977 3150
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2978 3151
 		&& @file_exists($sourcedir . '/QueryString.php')
2979 3152
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2980
-	if (!$check && !isset($modSettings['smfVersion']))
2981
-		print_error('Error: Some files are missing or out-of-date.', true);
3153
+	if (!$check && !isset($modSettings['smfVersion'])) {
3154
+			print_error('Error: Some files are missing or out-of-date.', true);
3155
+	}
2982 3156
 
2983 3157
 	// Do a quick version spot check.
2984 3158
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2985 3159
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2986
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2987
-		print_error('Error: Some files have not yet been updated properly.');
3160
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
3161
+			print_error('Error: Some files have not yet been updated properly.');
3162
+	}
2988 3163
 
2989 3164
 	// Make sure Settings.php is writable.
2990 3165
 		quickFileWritable($boarddir . '/Settings.php');
2991
-	if (!is_writable($boarddir . '/Settings.php'))
2992
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
3166
+	if (!is_writable($boarddir . '/Settings.php')) {
3167
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
3168
+	}
2993 3169
 
2994 3170
 	// Make sure Settings_bak.php is writable.
2995 3171
 		quickFileWritable($boarddir . '/Settings_bak.php');
2996
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2997
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
3172
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
3173
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
3174
+	}
2998 3175
 
2999
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
3000
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
3001
-	elseif (isset($modSettings['agreement']))
3176
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
3177
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
3178
+	} elseif (isset($modSettings['agreement']))
3002 3179
 	{
3003 3180
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
3004 3181
 		fwrite($fp, $modSettings['agreement']);
@@ -3008,31 +3185,36 @@  discard block
 block discarded – undo
3008 3185
 	// Make sure Themes is writable.
3009 3186
 	quickFileWritable($modSettings['theme_dir']);
3010 3187
 
3011
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
3012
-		print_error('Error: Unable to obtain write access to "Themes".');
3188
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
3189
+			print_error('Error: Unable to obtain write access to "Themes".');
3190
+	}
3013 3191
 
3014 3192
 	// Make sure cache directory exists and is writable!
3015 3193
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
3016
-	if (!file_exists($cachedir_temp))
3017
-		@mkdir($cachedir_temp);
3194
+	if (!file_exists($cachedir_temp)) {
3195
+			@mkdir($cachedir_temp);
3196
+	}
3018 3197
 
3019 3198
 	// Make sure the cache temp dir is writable.
3020 3199
 	quickFileWritable($cachedir_temp);
3021 3200
 
3022
-	if (!is_writable($cachedir_temp))
3023
-		print_error('Error: Unable to obtain write access to "cache".', true);
3201
+	if (!is_writable($cachedir_temp)) {
3202
+			print_error('Error: Unable to obtain write access to "cache".', true);
3203
+	}
3024 3204
 
3025
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
3026
-		print_error('Error: Unable to find language files!', true);
3027
-	else
3205
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
3206
+			print_error('Error: Unable to find language files!', true);
3207
+	} else
3028 3208
 	{
3029 3209
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
3030 3210
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
3031 3211
 
3032
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
3033
-			print_error('Error: Language files out of date.', true);
3034
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
3035
-			print_error('Error: Install language is missing for selected language.', true);
3212
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
3213
+					print_error('Error: Language files out of date.', true);
3214
+		}
3215
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
3216
+					print_error('Error: Install language is missing for selected language.', true);
3217
+		}
3036 3218
 
3037 3219
 		// Otherwise include it!
3038 3220
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -3047,14 +3229,16 @@  discard block
 block discarded – undo
3047 3229
 {
3048 3230
 	static $fp = null;
3049 3231
 
3050
-	if ($fp === null)
3051
-		$fp = fopen('php://stderr', 'wb');
3232
+	if ($fp === null) {
3233
+			$fp = fopen('php://stderr', 'wb');
3234
+	}
3052 3235
 
3053 3236
 	fwrite($fp, $message . "\n");
3054 3237
 
3055
-	if ($fatal)
3056
-		exit;
3057
-}
3238
+	if ($fatal) {
3239
+			exit;
3240
+	}
3241
+	}
3058 3242
 
3059 3243
 function throw_error($message)
3060 3244
 {
@@ -3071,8 +3255,9 @@  discard block
 block discarded – undo
3071 3255
 {
3072 3256
 	global $upcontext, $boarddir;
3073 3257
 
3074
-	if (empty($files))
3075
-		return true;
3258
+	if (empty($files)) {
3259
+			return true;
3260
+	}
3076 3261
 
3077 3262
 	$failure = false;
3078 3263
 	// On linux, it's easy - just use is_writable!
@@ -3087,14 +3272,16 @@  discard block
 block discarded – undo
3087 3272
 				@chmod($file, 0755);
3088 3273
 
3089 3274
 				// Well, 755 hopefully worked... if not, try 777.
3090
-				if (!is_writable($file) && !@chmod($file, 0777))
3091
-					$failure = true;
3275
+				if (!is_writable($file) && !@chmod($file, 0777)) {
3276
+									$failure = true;
3277
+				}
3092 3278
 				// Otherwise remove it as it's good!
3093
-				else
3094
-					unset($files[$k]);
3279
+				else {
3280
+									unset($files[$k]);
3281
+				}
3282
+			} else {
3283
+							unset($files[$k]);
3095 3284
 			}
3096
-			else
3097
-				unset($files[$k]);
3098 3285
 		}
3099 3286
 	}
3100 3287
 	// Windows is trickier.  Let's try opening for r+...
@@ -3105,30 +3292,35 @@  discard block
 block discarded – undo
3105 3292
 		foreach ($files as $k => $file)
3106 3293
 		{
3107 3294
 			// Folders can't be opened for write... but the index.php in them can ;).
3108
-			if (is_dir($file))
3109
-				$file .= '/index.php';
3295
+			if (is_dir($file)) {
3296
+							$file .= '/index.php';
3297
+			}
3110 3298
 
3111 3299
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
3112 3300
 			@chmod($file, 0777);
3113 3301
 			$fp = @fopen($file, 'r+');
3114 3302
 
3115 3303
 			// Hmm, okay, try just for write in that case...
3116
-			if (!$fp)
3117
-				$fp = @fopen($file, 'w');
3304
+			if (!$fp) {
3305
+							$fp = @fopen($file, 'w');
3306
+			}
3118 3307
 
3119
-			if (!$fp)
3120
-				$failure = true;
3121
-			else
3122
-				unset($files[$k]);
3308
+			if (!$fp) {
3309
+							$failure = true;
3310
+			} else {
3311
+							unset($files[$k]);
3312
+			}
3123 3313
 			@fclose($fp);
3124 3314
 		}
3125 3315
 	}
3126 3316
 
3127
-	if (empty($files))
3128
-		return true;
3317
+	if (empty($files)) {
3318
+			return true;
3319
+	}
3129 3320
 
3130
-	if (!isset($_SERVER))
3131
-		return !$failure;
3321
+	if (!isset($_SERVER)) {
3322
+			return !$failure;
3323
+	}
3132 3324
 
3133 3325
 	// What still needs to be done?
3134 3326
 	$upcontext['chmod']['files'] = $files;
@@ -3179,36 +3371,40 @@  discard block
 block discarded – undo
3179 3371
 
3180 3372
 		if (!isset($ftp) || $ftp->error !== false)
3181 3373
 		{
3182
-			if (!isset($ftp))
3183
-				$ftp = new ftp_connection(null);
3374
+			if (!isset($ftp)) {
3375
+							$ftp = new ftp_connection(null);
3376
+			}
3184 3377
 			// Save the error so we can mess with listing...
3185
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
3186
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
3378
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
3379
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
3380
+			}
3187 3381
 
3188 3382
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
3189 3383
 
3190
-			if ($found_path || !isset($upcontext['chmod']['path']))
3191
-				$upcontext['chmod']['path'] = $detect_path;
3384
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
3385
+							$upcontext['chmod']['path'] = $detect_path;
3386
+			}
3192 3387
 
3193
-			if (!isset($upcontext['chmod']['username']))
3194
-				$upcontext['chmod']['username'] = $username;
3388
+			if (!isset($upcontext['chmod']['username'])) {
3389
+							$upcontext['chmod']['username'] = $username;
3390
+			}
3195 3391
 
3196 3392
 			// Don't forget the login token.
3197 3393
 			$upcontext += createToken('login');
3198 3394
 
3199 3395
 			return false;
3200
-		}
3201
-		else
3396
+		} else
3202 3397
 		{
3203 3398
 			// We want to do a relative path for FTP.
3204 3399
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
3205 3400
 			{
3206 3401
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
3207
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
3208
-				$ftp_root = substr($ftp_root, 0, -1);
3402
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
3403
+								$ftp_root = substr($ftp_root, 0, -1);
3404
+				}
3405
+			} else {
3406
+							$ftp_root = $boarddir;
3209 3407
 			}
3210
-			else
3211
-				$ftp_root = $boarddir;
3212 3408
 
3213 3409
 			// Save the info for next time!
3214 3410
 			$_SESSION['installer_temp_ftp'] = array(
@@ -3222,10 +3418,12 @@  discard block
 block discarded – undo
3222 3418
 
3223 3419
 			foreach ($files as $k => $file)
3224 3420
 			{
3225
-				if (!is_writable($file))
3226
-					$ftp->chmod($file, 0755);
3227
-				if (!is_writable($file))
3228
-					$ftp->chmod($file, 0777);
3421
+				if (!is_writable($file)) {
3422
+									$ftp->chmod($file, 0755);
3423
+				}
3424
+				if (!is_writable($file)) {
3425
+									$ftp->chmod($file, 0777);
3426
+				}
3229 3427
 
3230 3428
 				// Assuming that didn't work calculate the path without the boarddir.
3231 3429
 				if (!is_writable($file))
@@ -3234,19 +3432,23 @@  discard block
 block discarded – undo
3234 3432
 					{
3235 3433
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
3236 3434
 						$ftp->chmod($ftp_file, 0755);
3237
-						if (!is_writable($file))
3238
-							$ftp->chmod($ftp_file, 0777);
3435
+						if (!is_writable($file)) {
3436
+													$ftp->chmod($ftp_file, 0777);
3437
+						}
3239 3438
 						// Sometimes an extra slash can help...
3240 3439
 						$ftp_file = '/' . $ftp_file;
3241
-						if (!is_writable($file))
3242
-							$ftp->chmod($ftp_file, 0755);
3243
-						if (!is_writable($file))
3244
-							$ftp->chmod($ftp_file, 0777);
3440
+						if (!is_writable($file)) {
3441
+													$ftp->chmod($ftp_file, 0755);
3442
+						}
3443
+						if (!is_writable($file)) {
3444
+													$ftp->chmod($ftp_file, 0777);
3445
+						}
3245 3446
 					}
3246 3447
 				}
3247 3448
 
3248
-				if (is_writable($file))
3249
-					unset($files[$k]);
3449
+				if (is_writable($file)) {
3450
+									unset($files[$k]);
3451
+				}
3250 3452
 			}
3251 3453
 
3252 3454
 			$ftp->close();
@@ -3256,16 +3458,18 @@  discard block
 block discarded – undo
3256 3458
 	// What remains?
3257 3459
 	$upcontext['chmod']['files'] = $files;
3258 3460
 
3259
-	if (empty($files))
3260
-		return true;
3461
+	if (empty($files)) {
3462
+			return true;
3463
+	}
3261 3464
 
3262 3465
 	return false;
3263 3466
 }
3264 3467
 
3265 3468
 function quickFileWritable($file)
3266 3469
 {
3267
-	if (is_writable($file))
3268
-		return true;
3470
+	if (is_writable($file)) {
3471
+			return true;
3472
+	}
3269 3473
 
3270 3474
 	@chmod($file, 0755);
3271 3475
 
@@ -3275,17 +3479,19 @@  discard block
 block discarded – undo
3275 3479
 	foreach ($chmod_values as $val)
3276 3480
 	{
3277 3481
 		// If it's writable, break out of the loop
3278
-		if (is_writable($file))
3279
-			break;
3280
-		else
3281
-			@chmod($file, $val);
3482
+		if (is_writable($file)) {
3483
+					break;
3484
+		} else {
3485
+					@chmod($file, $val);
3486
+		}
3282 3487
 	}
3283 3488
 }
3284 3489
 function smf_strtolower($string)
3285 3490
 {
3286 3491
 	global $sourcedir;
3287
-	if (function_exists('mb_strtolower'))
3288
-		return mb_strtolower($string, 'UTF-8');
3492
+	if (function_exists('mb_strtolower')) {
3493
+			return mb_strtolower($string, 'UTF-8');
3494
+	}
3289 3495
 	require_once($sourcedir . '/Subs-Charset.php');
3290 3496
 	return utf8_strtolower($string);
3291 3497
 }
@@ -3308,8 +3514,7 @@  discard block
 block discarded – undo
3308 3514
 		);
3309 3515
 		
3310 3516
 		return true;
3311
-	}
3312
-	else
3517
+	} else
3313 3518
 	{
3314 3519
 		$upcontext['page_title'] = 'Converting to UTF8';
3315 3520
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -3353,8 +3558,9 @@  discard block
 block discarded – undo
3353 3558
 			)
3354 3559
 		);
3355 3560
 		$db_charsets = array();
3356
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3357
-			$db_charsets[] = $row['Charset'];
3561
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3562
+					$db_charsets[] = $row['Charset'];
3563
+		}
3358 3564
 
3359 3565
 		$smcFunc['db_free_result']($request);
3360 3566
 
@@ -3390,13 +3596,15 @@  discard block
 block discarded – undo
3390 3596
 		// If there's a fulltext index, we need to drop it first...
3391 3597
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
3392 3598
 		{
3393
-			while ($row = $smcFunc['db_fetch_assoc']($request))
3394
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
3599
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
3600
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
3395 3601
 					$upcontext['fulltext_index'][] = $row['Key_name'];
3602
+			}
3396 3603
 			$smcFunc['db_free_result']($request);
3397 3604
 
3398
-			if (isset($upcontext['fulltext_index']))
3399
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
3605
+			if (isset($upcontext['fulltext_index'])) {
3606
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
3607
+			}
3400 3608
 		}
3401 3609
 
3402 3610
 		// Drop it and make a note...
@@ -3588,8 +3796,9 @@  discard block
 block discarded – undo
3588 3796
 			$replace = '%field%';
3589 3797
 
3590 3798
 			// Build a huge REPLACE statement...
3591
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
3592
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3799
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3800
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3801
+			}
3593 3802
 		}
3594 3803
 
3595 3804
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -3623,8 +3832,9 @@  discard block
 block discarded – undo
3623 3832
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3624 3833
 
3625 3834
 			// Just to make sure it doesn't time out.
3626
-			if (function_exists('apache_reset_timeout'))
3627
-				@apache_reset_timeout();
3835
+			if (function_exists('apache_reset_timeout')) {
3836
+							@apache_reset_timeout();
3837
+			}
3628 3838
 
3629 3839
 			$table_charsets = array();
3630 3840
 
@@ -3645,8 +3855,9 @@  discard block
 block discarded – undo
3645 3855
 					{
3646 3856
 						list($charset) = explode('_', $collation);
3647 3857
 
3648
-						if (!isset($table_charsets[$charset]))
3649
-							$table_charsets[$charset] = array();
3858
+						if (!isset($table_charsets[$charset])) {
3859
+													$table_charsets[$charset] = array();
3860
+						}
3650 3861
 
3651 3862
 						$table_charsets[$charset][] = $column_info;
3652 3863
 					}
@@ -3686,10 +3897,11 @@  discard block
 block discarded – undo
3686 3897
 				if (isset($translation_tables[$upcontext['charset_detected']]))
3687 3898
 				{
3688 3899
 					$update = '';
3689
-					foreach ($table_charsets as $charset => $columns)
3690
-						foreach ($columns as $column)
3900
+					foreach ($table_charsets as $charset => $columns) {
3901
+											foreach ($columns as $column)
3691 3902
 							$update .= '
3692 3903
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3904
+					}
3693 3905
 
3694 3906
 					$smcFunc['db_query']('', '
3695 3907
 						UPDATE {raw:table_name}
@@ -3714,8 +3926,9 @@  discard block
 block discarded – undo
3714 3926
 			// Now do the actual conversion (if still needed).
3715 3927
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3716 3928
 			{
3717
-				if ($command_line)
3718
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3929
+				if ($command_line) {
3930
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3931
+				}
3719 3932
 
3720 3933
 				$smcFunc['db_query']('', '
3721 3934
 					ALTER TABLE {raw:table_name}
@@ -3725,8 +3938,9 @@  discard block
 block discarded – undo
3725 3938
 						)
3726 3939
 				);
3727 3940
 
3728
-				if ($command_line)
3729
-					echo " done.\n";
3941
+				if ($command_line) {
3942
+									echo " done.\n";
3943
+				}
3730 3944
 			}
3731 3945
 		}
3732 3946
 
@@ -3756,8 +3970,8 @@  discard block
 block discarded – undo
3756 3970
 		);
3757 3971
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3758 3972
 		{
3759
-			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)
3760
-				$smcFunc['db_query']('', '
3973
+			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) {
3974
+							$smcFunc['db_query']('', '
3761 3975
 					UPDATE {db_prefix}log_actions
3762 3976
 					SET extra = {string:extra}
3763 3977
 					WHERE id_action = {int:current_action}',
@@ -3766,6 +3980,7 @@  discard block
 block discarded – undo
3766 3980
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3767 3981
 					)
3768 3982
 				);
3983
+			}
3769 3984
 		}
3770 3985
 		$smcFunc['db_free_result']($request);
3771 3986
 
@@ -3787,15 +4002,17 @@  discard block
 block discarded – undo
3787 4002
 	// First thing's first - did we already do this?
3788 4003
 	if (!empty($modSettings['json_done']))
3789 4004
 	{
3790
-		if ($command_line)
3791
-			return DeleteUpgrade();
3792
-		else
3793
-			return true;
4005
+		if ($command_line) {
4006
+					return DeleteUpgrade();
4007
+		} else {
4008
+					return true;
4009
+		}
3794 4010
 	}
3795 4011
 
3796 4012
 	// Done it already - js wise?
3797
-	if (!empty($_POST['json_done']))
3798
-		return true;
4013
+	if (!empty($_POST['json_done'])) {
4014
+			return true;
4015
+	}
3799 4016
 
3800 4017
 	// List of tables affected by this function
3801 4018
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3827,12 +4044,14 @@  discard block
 block discarded – undo
3827 4044
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3828 4045
 	$file_steps = $upcontext['table_count'];
3829 4046
 
3830
-	foreach ($keys as $id => $table)
3831
-		if ($id < $_GET['substep'])
4047
+	foreach ($keys as $id => $table) {
4048
+			if ($id < $_GET['substep'])
3832 4049
 			$upcontext['previous_tables'][] = $table;
4050
+	}
3833 4051
 
3834
-	if ($command_line)
3835
-		echo 'Converting data from serialize() to json_encode().';
4052
+	if ($command_line) {
4053
+			echo 'Converting data from serialize() to json_encode().';
4054
+	}
3836 4055
 
3837 4056
 	if (!$support_js || isset($_GET['xml']))
3838 4057
 	{
@@ -3872,8 +4091,9 @@  discard block
 block discarded – undo
3872 4091
 
3873 4092
 				// Loop through and fix these...
3874 4093
 				$new_settings = array();
3875
-				if ($command_line)
3876
-					echo "\n" . 'Fixing some settings...';
4094
+				if ($command_line) {
4095
+									echo "\n" . 'Fixing some settings...';
4096
+				}
3877 4097
 
3878 4098
 				foreach ($serialized_settings as $var)
3879 4099
 				{
@@ -3881,22 +4101,24 @@  discard block
 block discarded – undo
3881 4101
 					{
3882 4102
 						// Attempt to unserialize the setting
3883 4103
 						$temp = @safe_unserialize($modSettings[$var]);
3884
-						if (!$temp && $command_line)
3885
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3886
-						elseif ($temp !== false)
3887
-							$new_settings[$var] = json_encode($temp);
4104
+						if (!$temp && $command_line) {
4105
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
4106
+						} elseif ($temp !== false) {
4107
+													$new_settings[$var] = json_encode($temp);
4108
+						}
3888 4109
 					}
3889 4110
 				}
3890 4111
 
3891 4112
 				// Update everything at once
3892
-				if (!function_exists('cache_put_data'))
3893
-					require_once($sourcedir . '/Load.php');
4113
+				if (!function_exists('cache_put_data')) {
4114
+									require_once($sourcedir . '/Load.php');
4115
+				}
3894 4116
 				updateSettings($new_settings, true);
3895 4117
 
3896
-				if ($command_line)
3897
-					echo ' done.';
3898
-			}
3899
-			elseif ($table == 'themes')
4118
+				if ($command_line) {
4119
+									echo ' done.';
4120
+				}
4121
+			} elseif ($table == 'themes')
3900 4122
 			{
3901 4123
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3902 4124
 				$query = $smcFunc['db_query']('', '
@@ -3915,10 +4137,11 @@  discard block
 block discarded – undo
3915 4137
 
3916 4138
 						if ($command_line)
3917 4139
 						{
3918
-							if ($temp === false)
3919
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3920
-							else
3921
-								echo "\n" . 'Fixing admin preferences...';
4140
+							if ($temp === false) {
4141
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
4142
+							} else {
4143
+															echo "\n" . 'Fixing admin preferences...';
4144
+							}
3922 4145
 						}
3923 4146
 
3924 4147
 						if ($temp !== false)
@@ -3938,15 +4161,15 @@  discard block
 block discarded – undo
3938 4161
 								)
3939 4162
 							);
3940 4163
 
3941
-							if ($command_line)
3942
-								echo ' done.';
4164
+							if ($command_line) {
4165
+															echo ' done.';
4166
+							}
3943 4167
 						}
3944 4168
 					}
3945 4169
 
3946 4170
 					$smcFunc['db_free_result']($query);
3947 4171
 				}
3948
-			}
3949
-			else
4172
+			} else
3950 4173
 			{
3951 4174
 				// First item is always the key...
3952 4175
 				$key = $info[0];
@@ -3957,8 +4180,7 @@  discard block
 block discarded – undo
3957 4180
 				{
3958 4181
 					$col_select = $info[1];
3959 4182
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3960
-				}
3961
-				else
4183
+				} else
3962 4184
 				{
3963 4185
 					$col_select = implode(', ', $info);
3964 4186
 				}
@@ -3991,8 +4213,7 @@  discard block
 block discarded – undo
3991 4213
 								if ($temp === false && $command_line)
3992 4214
 								{
3993 4215
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3994
-								}
3995
-								else
4216
+								} else
3996 4217
 								{
3997 4218
 									$row[$col] = json_encode($temp);
3998 4219
 
@@ -4017,16 +4238,18 @@  discard block
 block discarded – undo
4017 4238
 						}
4018 4239
 					}
4019 4240
 
4020
-					if ($command_line)
4021
-						echo ' done.';
4241
+					if ($command_line) {
4242
+											echo ' done.';
4243
+					}
4022 4244
 
4023 4245
 					// Free up some memory...
4024 4246
 					$smcFunc['db_free_result']($query);
4025 4247
 				}
4026 4248
 			}
4027 4249
 			// If this is XML to keep it nice for the user do one table at a time anyway!
4028
-			if (isset($_GET['xml']))
4029
-				return upgradeExit();
4250
+			if (isset($_GET['xml'])) {
4251
+							return upgradeExit();
4252
+			}
4030 4253
 		}
4031 4254
 
4032 4255
 		if ($command_line)
@@ -4041,8 +4264,9 @@  discard block
 block discarded – undo
4041 4264
 
4042 4265
 		$_GET['substep'] = 0;
4043 4266
 		// Make sure we move on!
4044
-		if ($command_line)
4045
-			return DeleteUpgrade();
4267
+		if ($command_line) {
4268
+					return DeleteUpgrade();
4269
+		}
4046 4270
 
4047 4271
 		return true;
4048 4272
 	}
@@ -4062,14 +4286,16 @@  discard block
 block discarded – undo
4062 4286
 	global $upcontext, $txt, $settings;
4063 4287
 
4064 4288
 	// Don't call me twice!
4065
-	if (!empty($upcontext['chmod_called']))
4066
-		return;
4289
+	if (!empty($upcontext['chmod_called'])) {
4290
+			return;
4291
+	}
4067 4292
 
4068 4293
 	$upcontext['chmod_called'] = true;
4069 4294
 
4070 4295
 	// Nothing?
4071
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
4072
-		return;
4296
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
4297
+			return;
4298
+	}
4073 4299
 
4074 4300
 	// Was it a problem with Windows?
4075 4301
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -4101,11 +4327,12 @@  discard block
 block discarded – undo
4101 4327
 					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\');
4102 4328
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
4103 4329
 
4104
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
4105
-		echo '
4330
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
4331
+			echo '
4106 4332
 					content.write(\'<hr>\n\t\t\t\');
4107 4333
 					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\');
4108 4334
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
4335
+	}
4109 4336
 
4110 4337
 	echo '
4111 4338
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -4113,17 +4340,19 @@  discard block
 block discarded – undo
4113 4340
 				}
4114 4341
 		</script>';
4115 4342
 
4116
-	if (!empty($upcontext['chmod']['ftp_error']))
4117
-		echo '
4343
+	if (!empty($upcontext['chmod']['ftp_error'])) {
4344
+			echo '
4118 4345
 			<div class="error_message red">
4119 4346
 				The following error was encountered when trying to connect:<br><br>
4120 4347
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
4121 4348
 			</div>
4122 4349
 			<br>';
4350
+	}
4123 4351
 
4124
-	if (empty($upcontext['chmod_in_form']))
4125
-		echo '
4352
+	if (empty($upcontext['chmod_in_form'])) {
4353
+			echo '
4126 4354
 	<form action="', $upcontext['form_url'], '" method="post">';
4355
+	}
4127 4356
 
4128 4357
 	echo '
4129 4358
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -4158,10 +4387,11 @@  discard block
 block discarded – undo
4158 4387
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
4159 4388
 	</div>';
4160 4389
 
4161
-	if (empty($upcontext['chmod_in_form']))
4162
-		echo '
4390
+	if (empty($upcontext['chmod_in_form'])) {
4391
+			echo '
4163 4392
 	</form>';
4164
-}
4393
+	}
4394
+	}
4165 4395
 
4166 4396
 function template_upgrade_above()
4167 4397
 {
@@ -4221,9 +4451,10 @@  discard block
 block discarded – undo
4221 4451
 				<h2>', $txt['upgrade_progress'], '</h2>
4222 4452
 				<ul>';
4223 4453
 
4224
-	foreach ($upcontext['steps'] as $num => $step)
4225
-		echo '
4454
+	foreach ($upcontext['steps'] as $num => $step) {
4455
+			echo '
4226 4456
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
4457
+	}
4227 4458
 
4228 4459
 	echo '
4229 4460
 					</ul>
@@ -4236,8 +4467,8 @@  discard block
 block discarded – undo
4236 4467
 				</div>
4237 4468
 			</div>';
4238 4469
 
4239
-	if (isset($upcontext['step_progress']))
4240
-		echo '
4470
+	if (isset($upcontext['step_progress'])) {
4471
+			echo '
4241 4472
 				<br>
4242 4473
 				<br>
4243 4474
 				<div id="progress_bar_step">
@@ -4246,6 +4477,7 @@  discard block
 block discarded – undo
4246 4477
 						<span>', $txt['upgrade_step_progress'], '</span>
4247 4478
 					</div>
4248 4479
 				</div>';
4480
+	}
4249 4481
 
4250 4482
 	echo '
4251 4483
 				<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>
@@ -4276,32 +4508,36 @@  discard block
 block discarded – undo
4276 4508
 {
4277 4509
 	global $upcontext, $txt;
4278 4510
 
4279
-	if (!empty($upcontext['pause']))
4280
-		echo '
4511
+	if (!empty($upcontext['pause'])) {
4512
+			echo '
4281 4513
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
4282 4514
 
4283 4515
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
4284 4516
 								<h3>
4285 4517
 									', $txt['upgrade_paused_overload'], '
4286 4518
 								</h3>';
4519
+	}
4287 4520
 
4288
-	if (!empty($upcontext['custom_warning']))
4289
-		echo '
4521
+	if (!empty($upcontext['custom_warning'])) {
4522
+			echo '
4290 4523
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4291 4524
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4292 4525
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
4293 4526
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
4294 4527
 								</div>';
4528
+	}
4295 4529
 
4296 4530
 	echo '
4297 4531
 								<div class="righttext" style="margin: 1ex;">';
4298 4532
 
4299
-	if (!empty($upcontext['continue']))
4300
-		echo '
4533
+	if (!empty($upcontext['continue'])) {
4534
+			echo '
4301 4535
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
4302
-	if (!empty($upcontext['skip']))
4303
-		echo '
4536
+	}
4537
+	if (!empty($upcontext['skip'])) {
4538
+			echo '
4304 4539
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
4540
+	}
4305 4541
 
4306 4542
 	echo '
4307 4543
 								</div>
@@ -4351,11 +4587,12 @@  discard block
 block discarded – undo
4351 4587
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
4352 4588
 	<smf>';
4353 4589
 
4354
-	if (!empty($upcontext['get_data']))
4355
-		foreach ($upcontext['get_data'] as $k => $v)
4590
+	if (!empty($upcontext['get_data'])) {
4591
+			foreach ($upcontext['get_data'] as $k => $v)
4356 4592
 			echo '
4357 4593
 		<get key="', $k, '">', $v, '</get>';
4358
-}
4594
+	}
4595
+	}
4359 4596
 
4360 4597
 function template_xml_below()
4361 4598
 {
@@ -4396,8 +4633,8 @@  discard block
 block discarded – undo
4396 4633
 	template_chmod();
4397 4634
 
4398 4635
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
4399
-	if ($upcontext['is_large_forum'])
4400
-		echo '
4636
+	if ($upcontext['is_large_forum']) {
4637
+			echo '
4401 4638
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4402 4639
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4403 4640
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -4405,10 +4642,11 @@  discard block
 block discarded – undo
4405 4642
 				', $txt['upgrade_warning_lots_data'], '
4406 4643
 			</div>
4407 4644
 		</div>';
4645
+	}
4408 4646
 
4409 4647
 	// A warning message?
4410
-	if (!empty($upcontext['warning']))
4411
-		echo '
4648
+	if (!empty($upcontext['warning'])) {
4649
+			echo '
4412 4650
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4413 4651
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4414 4652
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -4416,6 +4654,7 @@  discard block
 block discarded – undo
4416 4654
 				', $upcontext['warning'], '
4417 4655
 			</div>
4418 4656
 		</div>';
4657
+	}
4419 4658
 
4420 4659
 	// Paths are incorrect?
4421 4660
 	echo '
@@ -4431,20 +4670,22 @@  discard block
 block discarded – undo
4431 4670
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
4432 4671
 	{
4433 4672
 		$ago = time() - $upcontext['started'];
4434
-		if ($ago < 60)
4435
-			$ago = $ago . ' seconds';
4436
-		elseif ($ago < 3600)
4437
-			$ago = (int) ($ago / 60) . ' minutes';
4438
-		else
4439
-			$ago = (int) ($ago / 3600) . ' hours';
4673
+		if ($ago < 60) {
4674
+					$ago = $ago . ' seconds';
4675
+		} elseif ($ago < 3600) {
4676
+					$ago = (int) ($ago / 60) . ' minutes';
4677
+		} else {
4678
+					$ago = (int) ($ago / 3600) . ' hours';
4679
+		}
4440 4680
 
4441 4681
 		$active = time() - $upcontext['updated'];
4442
-		if ($active < 60)
4443
-			$updated = $active . ' seconds';
4444
-		elseif ($active < 3600)
4445
-			$updated = (int) ($active / 60) . ' minutes';
4446
-		else
4447
-			$updated = (int) ($active / 3600) . ' hours';
4682
+		if ($active < 60) {
4683
+					$updated = $active . ' seconds';
4684
+		} elseif ($active < 3600) {
4685
+					$updated = (int) ($active / 60) . ' minutes';
4686
+		} else {
4687
+					$updated = (int) ($active / 3600) . ' hours';
4688
+		}
4448 4689
 
4449 4690
 		echo '
4450 4691
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -4453,16 +4694,18 @@  discard block
 block discarded – undo
4453 4694
 			<div style="padding-left: 6ex;">
4454 4695
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
4455 4696
 
4456
-		if ($active < 600)
4457
-			echo '
4697
+		if ($active < 600) {
4698
+					echo '
4458 4699
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
4700
+		}
4459 4701
 
4460
-		if ($active > $upcontext['inactive_timeout'])
4461
-			echo '
4702
+		if ($active > $upcontext['inactive_timeout']) {
4703
+					echo '
4462 4704
 				<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.';
4463
-		else
4464
-			echo '
4705
+		} else {
4706
+					echo '
4465 4707
 				<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!');
4708
+		}
4466 4709
 
4467 4710
 		echo '
4468 4711
 			</div>
@@ -4478,9 +4721,10 @@  discard block
 block discarded – undo
4478 4721
 					<td>
4479 4722
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
4480 4723
 
4481
-	if (!empty($upcontext['username_incorrect']))
4482
-		echo '
4724
+	if (!empty($upcontext['username_incorrect'])) {
4725
+			echo '
4483 4726
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
4727
+	}
4484 4728
 
4485 4729
 	echo '
4486 4730
 					</td>
@@ -4491,9 +4735,10 @@  discard block
 block discarded – undo
4491 4735
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
4492 4736
 						<input type="hidden" name="hash_passwrd" value="">';
4493 4737
 
4494
-	if (!empty($upcontext['password_failed']))
4495
-		echo '
4738
+	if (!empty($upcontext['password_failed'])) {
4739
+			echo '
4496 4740
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
4741
+	}
4497 4742
 
4498 4743
 	echo '
4499 4744
 					</td>
@@ -4564,8 +4809,8 @@  discard block
 block discarded – undo
4564 4809
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
4565 4810
 
4566 4811
 	// Warning message?
4567
-	if (!empty($upcontext['upgrade_options_warning']))
4568
-		echo '
4812
+	if (!empty($upcontext['upgrade_options_warning'])) {
4813
+			echo '
4569 4814
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
4570 4815
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4571 4816
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -4573,6 +4818,7 @@  discard block
 block discarded – undo
4573 4818
 				', $upcontext['upgrade_options_warning'], '
4574 4819
 			</div>
4575 4820
 		</div>';
4821
+	}
4576 4822
 
4577 4823
 	echo '
4578 4824
 				<table>
@@ -4600,8 +4846,8 @@  discard block
 block discarded – undo
4600 4846
 					</tr>';
4601 4847
 
4602 4848
 	// Offer mysql users to switch to mysqli
4603
-	if ($db_type == 'mysql' && function_exists('mysqli_query'))
4604
-		echo '
4849
+	if ($db_type == 'mysql' && function_exists('mysqli_query')) {
4850
+			echo '
4605 4851
 					<tr valign="top">
4606 4852
 						<td width="2%">
4607 4853
 							<input type="checkbox" name="convertMysql" id="convertMysql" value="1" checked class="input_check">
@@ -4611,6 +4857,7 @@  discard block
 block discarded – undo
4611 4857
 							<strong class="smalltext"><a href="http://wiki.simplemachines.org/smf/Upgrading-MySQLi-Functionality" target="_blank">More information about MySQLi</a></strong><br>
4612 4858
 						</td>
4613 4859
 					</tr>';
4860
+	}
4614 4861
 
4615 4862
 	echo '
4616 4863
 					<tr valign="top">
@@ -4630,8 +4877,8 @@  discard block
 block discarded – undo
4630 4877
 						</td>
4631 4878
 					</tr>';
4632 4879
 
4633
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
4634
-		echo '
4880
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4881
+			echo '
4635 4882
 					<tr valign="top">
4636 4883
 						<td width="2%">
4637 4884
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -4640,6 +4887,7 @@  discard block
 block discarded – undo
4640 4887
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
4641 4888
 						</td>
4642 4889
 					</tr>';
4890
+	}
4643 4891
 
4644 4892
 	echo '
4645 4893
 					<tr valign="top">
@@ -4675,10 +4923,11 @@  discard block
 block discarded – undo
4675 4923
 			<span id="debuginfo"></span>';
4676 4924
 
4677 4925
 	// Dont any tables so far?
4678
-	if (!empty($upcontext['previous_tables']))
4679
-		foreach ($upcontext['previous_tables'] as $table)
4926
+	if (!empty($upcontext['previous_tables'])) {
4927
+			foreach ($upcontext['previous_tables'] as $table)
4680 4928
 			echo '
4681 4929
 			<br>Completed Table: &quot;', $table, '&quot;.';
4930
+	}
4682 4931
 
4683 4932
 	echo '
4684 4933
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4715,12 +4964,13 @@  discard block
 block discarded – undo
4715 4964
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4716 4965
 
4717 4966
 		// If debug flood the screen.
4718
-		if ($is_debug)
4719
-			echo '
4967
+		if ($is_debug) {
4968
+					echo '
4720 4969
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4721 4970
 
4722 4971
 				if (document.getElementById(\'debuginfo\').scrollHeight)
4723 4972
 					document.getElementById(\'debuginfo\').scrollTop = document.getElementById(\'debuginfo\').scrollHeight;';
4973
+		}
4724 4974
 
4725 4975
 		echo '
4726 4976
 				// Get the next update...
@@ -4752,8 +5002,9 @@  discard block
 block discarded – undo
4752 5002
 {
4753 5003
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
4754 5004
 
4755
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4756
-		$is_debug = true;
5005
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
5006
+			$is_debug = true;
5007
+	}
4757 5008
 
4758 5009
 	echo '
4759 5010
 		<h3>Executing database changes</h3>
@@ -4768,8 +5019,9 @@  discard block
 block discarded – undo
4768 5019
 	{
4769 5020
 		foreach ($upcontext['actioned_items'] as $num => $item)
4770 5021
 		{
4771
-			if ($num != 0)
4772
-				echo ' Successful!';
5022
+			if ($num != 0) {
5023
+							echo ' Successful!';
5024
+			}
4773 5025
 			echo '<br>' . $item;
4774 5026
 		}
4775 5027
 		if (!empty($upcontext['changes_complete']))
@@ -4782,28 +5034,32 @@  discard block
 block discarded – undo
4782 5034
 				$seconds = intval($active % 60);
4783 5035
 
4784 5036
 				$totalTime = '';
4785
-				if ($hours > 0)
4786
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4787
-				if ($minutes > 0)
4788
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4789
-				if ($seconds > 0)
4790
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5037
+				if ($hours > 0) {
5038
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5039
+				}
5040
+				if ($minutes > 0) {
5041
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5042
+				}
5043
+				if ($seconds > 0) {
5044
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5045
+				}
4791 5046
 			}
4792 5047
 
4793
-			if ($is_debug && !empty($totalTime))
4794
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4795
-			else
4796
-				echo ' Successful!<br><br>';
5048
+			if ($is_debug && !empty($totalTime)) {
5049
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
5050
+			} else {
5051
+							echo ' Successful!<br><br>';
5052
+			}
4797 5053
 
4798 5054
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
4799 5055
 		}
4800
-	}
4801
-	else
5056
+	} else
4802 5057
 	{
4803 5058
 		// Tell them how many files we have in total.
4804
-		if ($upcontext['file_count'] > 1)
4805
-			echo '
5059
+		if ($upcontext['file_count'] > 1) {
5060
+					echo '
4806 5061
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
5062
+		}
4807 5063
 
4808 5064
 		echo '
4809 5065
 		<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>
@@ -4819,19 +5075,23 @@  discard block
 block discarded – undo
4819 5075
 				$seconds = intval($active % 60);
4820 5076
 
4821 5077
 				$totalTime = '';
4822
-				if ($hours > 0)
4823
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4824
-				if ($minutes > 0)
4825
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4826
-				if ($seconds > 0)
4827
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5078
+				if ($hours > 0) {
5079
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5080
+				}
5081
+				if ($minutes > 0) {
5082
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5083
+				}
5084
+				if ($seconds > 0) {
5085
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5086
+				}
4828 5087
 			}
4829 5088
 
4830 5089
 			echo '
4831 5090
 			<br><span id="upgradeCompleted">';
4832 5091
 
4833
-			if (!empty($totalTime))
4834
-				echo 'Completed in ', $totalTime, '<br>';
5092
+			if (!empty($totalTime)) {
5093
+							echo 'Completed in ', $totalTime, '<br>';
5094
+			}
4835 5095
 
4836 5096
 			echo '</span>
4837 5097
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -4868,9 +5128,10 @@  discard block
 block discarded – undo
4868 5128
 			var getData = "";
4869 5129
 			var debugItems = ', $upcontext['debug_items'], ';';
4870 5130
 
4871
-		if ($is_debug)
4872
-			echo '
5131
+		if ($is_debug) {
5132
+					echo '
4873 5133
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
5134
+		}
4874 5135
 
4875 5136
 		echo '
4876 5137
 			function getNextItem()
@@ -4910,9 +5171,10 @@  discard block
 block discarded – undo
4910 5171
 						document.getElementById("error_block").style.display = "";
4911 5172
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4912 5173
 
4913
-	if ($is_debug)
4914
-		echo '
5174
+	if ($is_debug) {
5175
+			echo '
4915 5176
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
5177
+	}
4916 5178
 
4917 5179
 	echo '
4918 5180
 					}
@@ -4933,9 +5195,10 @@  discard block
 block discarded – undo
4933 5195
 						document.getElementById("error_block").style.display = "";
4934 5196
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4935 5197
 
4936
-	if ($is_debug)
4937
-		echo '
5198
+	if ($is_debug) {
5199
+			echo '
4938 5200
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
5201
+	}
4939 5202
 
4940 5203
 	echo '
4941 5204
 					}
@@ -4994,8 +5257,8 @@  discard block
 block discarded – undo
4994 5257
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4995 5258
 				{';
4996 5259
 
4997
-		if ($is_debug)
4998
-			echo '
5260
+		if ($is_debug) {
5261
+					echo '
4999 5262
 					document.getElementById(\'debug_section\').style.display = "none";
5000 5263
 
5001 5264
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -5013,6 +5276,7 @@  discard block
 block discarded – undo
5013 5276
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
5014 5277
 
5015 5278
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
5279
+		}
5016 5280
 
5017 5281
 		echo '
5018 5282
 
@@ -5020,9 +5284,10 @@  discard block
 block discarded – undo
5020 5284
 					document.getElementById(\'contbutt\').disabled = 0;
5021 5285
 					document.getElementById(\'database_done\').value = 1;';
5022 5286
 
5023
-		if ($upcontext['file_count'] > 1)
5024
-			echo '
5287
+		if ($upcontext['file_count'] > 1) {
5288
+					echo '
5025 5289
 					document.getElementById(\'info1\').style.display = "none";';
5290
+		}
5026 5291
 
5027 5292
 		echo '
5028 5293
 					document.getElementById(\'info2\').style.display = "none";
@@ -5035,9 +5300,10 @@  discard block
 block discarded – undo
5035 5300
 					lastItem = 0;
5036 5301
 					prevFile = curFile;';
5037 5302
 
5038
-		if ($is_debug)
5039
-			echo '
5303
+		if ($is_debug) {
5304
+					echo '
5040 5305
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
5306
+		}
5041 5307
 
5042 5308
 		echo '
5043 5309
 					getNextItem();
@@ -5045,8 +5311,8 @@  discard block
 block discarded – undo
5045 5311
 				}';
5046 5312
 
5047 5313
 		// If debug scroll the screen.
5048
-		if ($is_debug)
5049
-			echo '
5314
+		if ($is_debug) {
5315
+					echo '
5050 5316
 				if (iLastSubStepProgress == -1)
5051 5317
 				{
5052 5318
 					// Give it consistent dots.
@@ -5065,6 +5331,7 @@  discard block
 block discarded – undo
5065 5331
 
5066 5332
 				if (document.getElementById(\'debug_section\').scrollHeight)
5067 5333
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
5334
+		}
5068 5335
 
5069 5336
 		echo '
5070 5337
 				// Update the page.
@@ -5125,9 +5392,10 @@  discard block
 block discarded – undo
5125 5392
 			}';
5126 5393
 
5127 5394
 		// Start things off assuming we've not errored.
5128
-		if (empty($upcontext['error_message']))
5129
-			echo '
5395
+		if (empty($upcontext['error_message'])) {
5396
+					echo '
5130 5397
 			getNextItem();';
5398
+		}
5131 5399
 
5132 5400
 		echo '
5133 5401
 		</script>';
@@ -5144,18 +5412,21 @@  discard block
 block discarded – undo
5144 5412
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
5145 5413
 	<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>';
5146 5414
 
5147
-	if (!empty($upcontext['error_message']))
5148
-		echo '
5415
+	if (!empty($upcontext['error_message'])) {
5416
+			echo '
5149 5417
 	<error>', $upcontext['error_message'], '</error>';
5418
+	}
5150 5419
 
5151
-	if (!empty($upcontext['error_string']))
5152
-		echo '
5420
+	if (!empty($upcontext['error_string'])) {
5421
+			echo '
5153 5422
 	<sql>', $upcontext['error_string'], '</sql>';
5423
+	}
5154 5424
 
5155
-	if ($is_debug)
5156
-		echo '
5425
+	if ($is_debug) {
5426
+			echo '
5157 5427
 	<curtime>', time(), '</curtime>';
5158
-}
5428
+	}
5429
+	}
5159 5430
 
5160 5431
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
5161 5432
 function template_convert_utf8()
@@ -5172,18 +5443,20 @@  discard block
 block discarded – undo
5172 5443
 			<span id="debuginfo"></span>';
5173 5444
 
5174 5445
 	// Done any tables so far?
5175
-	if (!empty($upcontext['previous_tables']))
5176
-		foreach ($upcontext['previous_tables'] as $table)
5446
+	if (!empty($upcontext['previous_tables'])) {
5447
+			foreach ($upcontext['previous_tables'] as $table)
5177 5448
 			echo '
5178 5449
 			<br>Completed Table: &quot;', $table, '&quot;.';
5450
+	}
5179 5451
 
5180 5452
 	echo '
5181 5453
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
5182 5454
 
5183 5455
 	// If we dropped their index, let's let them know
5184
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
5185
-		echo '
5456
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
5457
+			echo '
5186 5458
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
5459
+	}
5187 5460
 
5188 5461
 	echo '
5189 5462
 			<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>';
@@ -5219,9 +5492,10 @@  discard block
 block discarded – undo
5219 5492
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
5220 5493
 
5221 5494
 		// If debug flood the screen.
5222
-		if ($is_debug)
5223
-			echo '
5495
+		if ($is_debug) {
5496
+					echo '
5224 5497
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
5498
+		}
5225 5499
 
5226 5500
 		echo '
5227 5501
 				// Get the next update...
@@ -5290,14 +5564,16 @@  discard block
 block discarded – undo
5290 5564
 		<input type="hidden" name="cleandone" value="1">';
5291 5565
 
5292 5566
 	// Files to make writable?
5293
-	if (!empty($upcontext['writable_files']))
5294
-		echo '
5567
+	if (!empty($upcontext['writable_files'])) {
5568
+			echo '
5295 5569
 		<input type="hidden" name="writable_files" value="', base64_encode(safe_serialize($upcontext['writable_files'])), '">';
5570
+	}
5296 5571
 
5297 5572
 	// We'll want a continue button...
5298
-	if (empty($upcontext['chmod']['files']))
5299
-		$upcontext['continue'] = 1;
5300
-}
5573
+	if (empty($upcontext['chmod']['files'])) {
5574
+			$upcontext['continue'] = 1;
5575
+	}
5576
+	}
5301 5577
 
5302 5578
 // Finished with the mods - let them know what we've done.
5303 5579
 function template_cleanup_done()
@@ -5359,8 +5635,9 @@  discard block
 block discarded – undo
5359 5635
 						&quot;', $language['name'], '&quot; Language Pack
5360 5636
 						<div class="smalltext">(';
5361 5637
 
5362
-			foreach ($language['files'] as $k => $file)
5363
-				echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')';
5638
+			foreach ($language['files'] as $k => $file) {
5639
+							echo $file['name'], $k + 1 != count($language['files']) ? ', ' : ')';
5640
+			}
5364 5641
 
5365 5642
 			echo '
5366 5643
 						</div>
@@ -5377,8 +5654,9 @@  discard block
 block discarded – undo
5377 5654
 						&quot;', $theme['name'], '&quot; Theme
5378 5655
 						<div class="smalltext">(';
5379 5656
 
5380
-			foreach ($theme['files'] as $k => $file)
5381
-				echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')';
5657
+			foreach ($theme['files'] as $k => $file) {
5658
+							echo $file['name'], $k + 1 != count($theme['files']) ? ', ' : ')';
5659
+			}
5382 5660
 
5383 5661
 			echo '
5384 5662
 						</div>
@@ -5389,47 +5667,54 @@  discard block
 block discarded – undo
5389 5667
 
5390 5668
 		echo '
5391 5669
 		</table>';
5392
-	}
5393
-	else
5670
+	} else
5394 5671
 	{
5395 5672
 		$langFiles = 0;
5396 5673
 		$themeFiles = 0;
5397
-		if (!empty($upcontext['languages']))
5398
-			foreach ($upcontext['languages'] as $lang)
5674
+		if (!empty($upcontext['languages'])) {
5675
+					foreach ($upcontext['languages'] as $lang)
5399 5676
 				$langFiles += count($lang['files']);
5400
-		if (!empty($upcontext['themes']))
5401
-			foreach ($upcontext['themes'] as $theme)
5677
+		}
5678
+		if (!empty($upcontext['themes'])) {
5679
+					foreach ($upcontext['themes'] as $theme)
5402 5680
 				$themeFiles += count($theme['files']);
5681
+		}
5403 5682
 		echo sprintf('Found <strong>%d</strong> language files and <strong>%d</strong> templates requiring an update so far.', $langFiles, $themeFiles) . '<br>';
5404 5683
 
5405 5684
 		// What we're currently doing?
5406
-		if (!empty($upcontext['current_message']))
5407
-			echo '
5685
+		if (!empty($upcontext['current_message'])) {
5686
+					echo '
5408 5687
 				', $upcontext['current_message'];
5688
+		}
5409 5689
 	}
5410 5690
 
5411 5691
 	echo '
5412 5692
 		<input type="hidden" name="uptempdone" value="1">';
5413 5693
 
5414
-	if (!empty($upcontext['languages']))
5415
-		echo '
5694
+	if (!empty($upcontext['languages'])) {
5695
+			echo '
5416 5696
 		<input type="hidden" name="languages" value="', base64_encode(safe_serialize($upcontext['languages'])), '">';
5417
-	if (!empty($upcontext['themes']))
5418
-		echo '
5697
+	}
5698
+	if (!empty($upcontext['themes'])) {
5699
+			echo '
5419 5700
 		<input type="hidden" name="themes" value="', base64_encode(safe_serialize($upcontext['themes'])), '">';
5420
-	if (!empty($upcontext['writable_files']))
5421
-		echo '
5701
+	}
5702
+	if (!empty($upcontext['writable_files'])) {
5703
+			echo '
5422 5704
 		<input type="hidden" name="writable_files" value="', base64_encode(safe_serialize($upcontext['writable_files'])), '">';
5705
+	}
5423 5706
 
5424 5707
 	// Offer them the option to upgrade from YaBB SE?
5425
-	if (!empty($upcontext['can_upgrade_yabbse']))
5426
-		echo '
5708
+	if (!empty($upcontext['can_upgrade_yabbse'])) {
5709
+			echo '
5427 5710
 		<br><label for="conv"><input type="checkbox" name="conv" id="conv" value="1" class="input_check"> Convert the existing YaBB SE template and set it as default.</label><br>';
5711
+	}
5428 5712
 
5429 5713
 	// We'll want a continue button... assuming chmod is OK (Otherwise let them use connect!)
5430
-	if (empty($upcontext['chmod']['files']) || $upcontext['is_test'])
5431
-		$upcontext['continue'] = 1;
5432
-}
5714
+	if (empty($upcontext['chmod']['files']) || $upcontext['is_test']) {
5715
+			$upcontext['continue'] = 1;
5716
+	}
5717
+	}
5433 5718
 
5434 5719
 // Template for the database backup tool/
5435 5720
 function template_serialize_json()
@@ -5446,19 +5731,21 @@  discard block
 block discarded – undo
5446 5731
 			<span id="debuginfo"></span>';
5447 5732
 
5448 5733
 	// Dont any tables so far?
5449
-	if (!empty($upcontext['previous_tables']))
5450
-		foreach ($upcontext['previous_tables'] as $table)
5734
+	if (!empty($upcontext['previous_tables'])) {
5735
+			foreach ($upcontext['previous_tables'] as $table)
5451 5736
 			echo '
5452 5737
 			<br>Completed Table: &quot;', $table, '&quot;.';
5738
+	}
5453 5739
 
5454 5740
 	echo '
5455 5741
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
5456 5742
 			<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>';
5457 5743
 
5458 5744
 	// Try to make sure substep was reset.
5459
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
5460
-		echo '
5745
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
5746
+			echo '
5461 5747
 			<input type="hidden" name="substep" id="substep" value="0">';
5748
+	}
5462 5749
 
5463 5750
 	// Continue please!
5464 5751
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -5491,9 +5778,10 @@  discard block
 block discarded – undo
5491 5778
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
5492 5779
 
5493 5780
 		// If debug flood the screen.
5494
-		if ($is_debug)
5495
-			echo '
5781
+		if ($is_debug) {
5782
+					echo '
5496 5783
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
5784
+		}
5497 5785
 
5498 5786
 		echo '
5499 5787
 				// Get the next update...
@@ -5528,8 +5816,8 @@  discard block
 block discarded – undo
5528 5816
 	<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>
5529 5817
 	<form action="', $boardurl, '/index.php">';
5530 5818
 
5531
-	if (!empty($upcontext['can_delete_script']))
5532
-		echo '
5819
+	if (!empty($upcontext['can_delete_script'])) {
5820
+			echo '
5533 5821
 			<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>
5534 5822
 			<script>
5535 5823
 				function doTheDelete(theCheck)
@@ -5541,6 +5829,7 @@  discard block
 block discarded – undo
5541 5829
 				}
5542 5830
 			</script>
5543 5831
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
5832
+	}
5544 5833
 
5545 5834
 	$active = time() - $upcontext['started'];
5546 5835
 	$hours = floor($active / 3600);
@@ -5550,16 +5839,20 @@  discard block
 block discarded – undo
5550 5839
 	if ($is_debug)
5551 5840
 	{
5552 5841
 		$totalTime = '';
5553
-		if ($hours > 0)
5554
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5555
-		if ($minutes > 0)
5556
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5557
-		if ($seconds > 0)
5558
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5842
+		if ($hours > 0) {
5843
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5844
+		}
5845
+		if ($minutes > 0) {
5846
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5847
+		}
5848
+		if ($seconds > 0) {
5849
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5850
+		}
5559 5851
 	}
5560 5852
 
5561
-	if ($is_debug && !empty($totalTime))
5562
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
5853
+	if ($is_debug && !empty($totalTime)) {
5854
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
5855
+	}
5563 5856
 
5564 5857
 	echo '<br>
5565 5858
 			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>
@@ -5616,16 +5909,19 @@  discard block
 block discarded – undo
5616 5909
 				'empty' => '',
5617 5910
 				'limit' => $limit,
5618 5911
 		));
5619
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5620
-			$arIp[] = $row[$oldCol];
5912
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5913
+					$arIp[] = $row[$oldCol];
5914
+		}
5621 5915
 		$smcFunc['db_free_result']($request);
5622 5916
 
5623 5917
 		// Special case, null ip could keep us in a loop.
5624
-		if (is_null($arIp[0]))
5625
-			unset($arIp[0]);
5918
+		if (is_null($arIp[0])) {
5919
+					unset($arIp[0]);
5920
+		}
5626 5921
 
5627
-		if (empty($arIp))
5628
-			$is_done = true;
5922
+		if (empty($arIp)) {
5923
+					$is_done = true;
5924
+		}
5629 5925
 
5630 5926
 		$updates = array();
5631 5927
 		$cases = array();
@@ -5634,16 +5930,18 @@  discard block
 block discarded – undo
5634 5930
 		{
5635 5931
 			$arIp[$i] = trim($arIp[$i]);
5636 5932
 
5637
-			if (empty($arIp[$i]))
5638
-				continue;
5933
+			if (empty($arIp[$i])) {
5934
+							continue;
5935
+			}
5639 5936
 
5640 5937
 			$updates['ip' . $i] = $arIp[$i];
5641 5938
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
5642 5939
 
5643 5940
 			if ($setSize > 0 && $i % $setSize === 0)
5644 5941
 			{
5645
-				if (count($updates) == 1)
5646
-					continue;
5942
+				if (count($updates) == 1) {
5943
+									continue;
5944
+				}
5647 5945
 
5648 5946
 				$updates['whereSet'] = array_values($updates);
5649 5947
 				$smcFunc['db_query']('', '
@@ -5677,8 +5975,7 @@  discard block
 block discarded – undo
5677 5975
 							'ip' => $ip
5678 5976
 					));
5679 5977
 				}
5680
-			}
5681
-			else
5978
+			} else
5682 5979
 			{
5683 5980
 				$updates['whereSet'] = array_values($updates);
5684 5981
 				$request = $smcFunc['db_query']('', '
@@ -5692,9 +5989,9 @@  discard block
 block discarded – undo
5692 5989
 					$updates
5693 5990
 				);
5694 5991
 			}
5992
+		} else {
5993
+					$is_done = true;
5695 5994
 		}
5696
-		else
5697
-			$is_done = true;
5698 5995
 
5699 5996
 		$_GET['a'] += $limit;
5700 5997
 		$step_progress['current'] = $_GET['a'];
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -83,12 +84,14 @@  discard block
 block discarded – undo
83 84
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
84 85
 
85 86
 			// Is it reserved?
86
-			if ($value == 'pg_')
87
-				return $txt['error_db_prefix_reserved'];
87
+			if ($value == 'pg_') {
88
+							return $txt['error_db_prefix_reserved'];
89
+			}
88 90
 
89 91
 			// Is the prefix numeric?
90
-			if (preg_match('~^\d~', $value))
91
-				return $txt['error_db_prefix_numeric'];
92
+			if (preg_match('~^\d~', $value)) {
93
+							return $txt['error_db_prefix_numeric'];
94
+			}
92 95
 
93 96
 			return true;
94 97
 		},
@@ -135,10 +138,11 @@  discard block
 block discarded – undo
135 138
 		$incontext['skip'] = false;
136 139
 
137 140
 		// Call the step and if it returns false that means pause!
138
-		if (function_exists($step[2]) && $step[2]() === false)
139
-			break;
140
-		elseif (function_exists($step[2]))
141
-			$incontext['current_step']++;
141
+		if (function_exists($step[2]) && $step[2]() === false) {
142
+					break;
143
+		} elseif (function_exists($step[2])) {
144
+					$incontext['current_step']++;
145
+		}
142 146
 
143 147
 		// No warnings pass on.
144 148
 		$incontext['warning'] = '';
@@ -154,12 +158,14 @@  discard block
 block discarded – undo
154 158
 	global $databases, $incontext;
155 159
 
156 160
 	// Just so people using older versions of PHP aren't left in the cold.
157
-	if (!isset($_SERVER['PHP_SELF']))
158
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
161
+	if (!isset($_SERVER['PHP_SELF'])) {
162
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
163
+	}
159 164
 
160 165
 	// Turn off magic quotes runtime and enable error reporting.
161
-	if (function_exists('set_magic_quotes_runtime'))
162
-		@set_magic_quotes_runtime(0);
166
+	if (function_exists('set_magic_quotes_runtime')) {
167
+			@set_magic_quotes_runtime(0);
168
+	}
163 169
 	error_reporting(E_ALL);
164 170
 
165 171
 	// Fun.  Low PHP version...
@@ -173,21 +179,23 @@  discard block
 block discarded – undo
173 179
 	{
174 180
 		ob_start();
175 181
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
178
-		if (function_exists('session_start'))
179
-			@session_start();
180
-	}
181
-	else
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
185
+		if (function_exists('session_start')) {
186
+					@session_start();
187
+		}
188
+	} else
182 189
 	{
183 190
 		ob_start('ob_gzhandler');
184 191
 
185
-		if (ini_get('session.save_handler') == 'user')
186
-			@ini_set('session.save_handler', 'files');
192
+		if (ini_get('session.save_handler') == 'user') {
193
+					@ini_set('session.save_handler', 'files');
194
+		}
187 195
 		session_start();
188 196
 
189
-		if (!headers_sent())
190
-			echo '<!DOCTYPE html>
197
+		if (!headers_sent()) {
198
+					echo '<!DOCTYPE html>
191 199
 <html>
192 200
 	<head>
193 201
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -196,6 +204,7 @@  discard block
 block discarded – undo
196 204
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
197 205
 	</body>
198 206
 </html>';
207
+		}
199 208
 		exit;
200 209
 	}
201 210
 
@@ -204,16 +213,18 @@  discard block
 block discarded – undo
204 213
 	{
205 214
 		$incontext['remote_files_available'] = false;
206 215
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
207
-		if ($test)
208
-			$incontext['remote_files_available'] = true;
216
+		if ($test) {
217
+					$incontext['remote_files_available'] = true;
218
+		}
209 219
 		@fclose($test);
210 220
 	}
211 221
 
212 222
 	// Add slashes, as long as they aren't already being added.
213
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
214
-		foreach ($_POST as $k => $v)
223
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
224
+			foreach ($_POST as $k => $v)
215 225
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
216 226
 				$_POST[$k] = addslashes($v);
227
+	}
217 228
 
218 229
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
219 230
 	if (isset($_GET['delete']))
@@ -234,8 +245,7 @@  discard block
 block discarded – undo
234 245
 			$ftp->close();
235 246
 
236 247
 			unset($_SESSION['installer_temp_ftp']);
237
-		}
238
-		else
248
+		} else
239 249
 		{
240 250
 			@unlink(__FILE__);
241 251
 
@@ -256,10 +266,11 @@  discard block
 block discarded – undo
256 266
 	{
257 267
 		// Get PHP's default timezone, if set
258 268
 		$ini_tz = ini_get('date.timezone');
259
-		if (!empty($ini_tz))
260
-			$timezone_id = $ini_tz;
261
-		else
262
-			$timezone_id = '';
269
+		if (!empty($ini_tz)) {
270
+					$timezone_id = $ini_tz;
271
+		} else {
272
+					$timezone_id = '';
273
+		}
263 274
 
264 275
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
265 276
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -289,8 +300,9 @@  discard block
 block discarded – undo
289 300
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
290 301
 		while ($entry = $dir->read())
291 302
 		{
292
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
293
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
303
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
304
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
305
+			}
294 306
 		}
295 307
 		$dir->close();
296 308
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -351,15 +365,18 @@  discard block
 block discarded – undo
351 365
 	global $db_prefix, $db_connection, $sourcedir;
352 366
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
353 367
 
354
-	if (empty($sourcedir))
355
-		$sourcedir = dirname(__FILE__) . '/Sources';
368
+	if (empty($sourcedir)) {
369
+			$sourcedir = dirname(__FILE__) . '/Sources';
370
+	}
356 371
 
357 372
 	// Need this to check whether we need the database password.
358 373
 	require(dirname(__FILE__) . '/Settings.php');
359
-	if (!defined('SMF'))
360
-		define('SMF', 1);
361
-	if (empty($smcFunc))
362
-		$smcFunc = array();
374
+	if (!defined('SMF')) {
375
+			define('SMF', 1);
376
+	}
377
+	if (empty($smcFunc)) {
378
+			$smcFunc = array();
379
+	}
363 380
 
364 381
 	$modSettings['disableQueryCheck'] = true;
365 382
 
@@ -367,8 +384,9 @@  discard block
 block discarded – undo
367 384
 	if (!$db_connection)
368 385
 	{
369 386
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
370
-		if (version_compare(PHP_VERSION, '5', '<'))
371
-			require_once($sourcedir . '/Subs-Compat.php');
387
+		if (version_compare(PHP_VERSION, '5', '<')) {
388
+					require_once($sourcedir . '/Subs-Compat.php');
389
+		}
372 390
 
373 391
 		$db_options = array('persist' => $db_persist);
374 392
 		$port = '';
@@ -379,19 +397,20 @@  discard block
 block discarded – undo
379 397
 			if ($db_type == 'mysql' || $db_type == 'mysqli')
380 398
 			{
381 399
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
382
-			}
383
-			elseif ($db_type == 'postgresql')
400
+			} elseif ($db_type == 'postgresql')
384 401
 			{
385 402
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
386 403
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
387 404
 			}
388 405
 		}
389 406
 
390
-		if (!empty($port))
391
-			$db_options['port'] = $port;
407
+		if (!empty($port)) {
408
+					$db_options['port'] = $port;
409
+		}
392 410
 
393
-		if (!$db_connection)
394
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
411
+		if (!$db_connection) {
412
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
413
+		}
395 414
 	}
396 415
 }
397 416
 
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 		// @todo REMOVE THIS!!
420 439
 		else
421 440
 		{
422
-			if (function_exists('doStep' . $_GET['step']))
423
-				call_user_func('doStep' . $_GET['step']);
441
+			if (function_exists('doStep' . $_GET['step'])) {
442
+							call_user_func('doStep' . $_GET['step']);
443
+			}
424 444
 		}
425 445
 		// Show the footer.
426 446
 		template_install_below();
@@ -438,8 +458,9 @@  discard block
 block discarded – undo
438 458
 	$incontext['sub_template'] = 'welcome_message';
439 459
 
440 460
 	// Done the submission?
441
-	if (isset($_POST['contbutt']))
442
-		return true;
461
+	if (isset($_POST['contbutt'])) {
462
+			return true;
463
+	}
443 464
 
444 465
 	// See if we think they have already installed it?
445 466
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -447,14 +468,17 @@  discard block
 block discarded – undo
447 468
 		$probably_installed = 0;
448 469
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
449 470
 		{
450
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
451
-				$probably_installed++;
452
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
453
-				$probably_installed++;
471
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
472
+							$probably_installed++;
473
+			}
474
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
475
+							$probably_installed++;
476
+			}
454 477
 		}
455 478
 
456
-		if ($probably_installed == 2)
457
-			$incontext['warning'] = $txt['error_already_installed'];
479
+		if ($probably_installed == 2) {
480
+					$incontext['warning'] = $txt['error_already_installed'];
481
+		}
458 482
 	}
459 483
 
460 484
 	// Is some database support even compiled in?
@@ -469,8 +493,7 @@  discard block
 block discarded – undo
469 493
 				$databases[$key]['supported'] = false;
470 494
 				$notFoundSQLFile = true;
471 495
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
472
-			}
473
-			else
496
+			} else
474 497
 			{
475 498
 				$db_type = $key;
476 499
 				$incontext['supported_databases'][] = $db;
@@ -479,29 +502,36 @@  discard block
 block discarded – undo
479 502
 	}
480 503
 
481 504
 	// Check the PHP version.
482
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
483
-		$error = 'error_php_too_low';
505
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
506
+			$error = 'error_php_too_low';
507
+	}
484 508
 	// Make sure we have a supported database
485
-	elseif (empty($incontext['supported_databases']))
486
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
509
+	elseif (empty($incontext['supported_databases'])) {
510
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	}
487 512
 	// How about session support?  Some crazy sysadmin remove it?
488
-	elseif (!function_exists('session_start'))
489
-		$error = 'error_session_missing';
513
+	elseif (!function_exists('session_start')) {
514
+			$error = 'error_session_missing';
515
+	}
490 516
 	// Make sure they uploaded all the files.
491
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
492
-		$error = 'error_missing_files';
517
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
518
+			$error = 'error_missing_files';
519
+	}
493 520
 	// Very simple check on the session.save_path for Windows.
494 521
 	// @todo Move this down later if they don't use database-driven sessions?
495
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
496
-		$error = 'error_session_save_path';
522
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
523
+			$error = 'error_session_save_path';
524
+	}
497 525
 
498 526
 	// Since each of the three messages would look the same, anyway...
499
-	if (isset($error))
500
-		$incontext['error'] = $txt[$error];
527
+	if (isset($error)) {
528
+			$incontext['error'] = $txt[$error];
529
+	}
501 530
 
502 531
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
503
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
504
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
532
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
533
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
534
+	}
505 535
 
506 536
 	return false;
507 537
 }
@@ -524,15 +554,18 @@  discard block
 block discarded – undo
524 554
 		'agreement.txt',
525 555
 		'Settings.php'
526 556
 	);
527
-	if (file_exists(dirname(__FILE__) . '/Settings_bak.php'))
528
-		$writable_files[] = 'Settings_bak.php';
557
+	if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) {
558
+			$writable_files[] = 'Settings_bak.php';
559
+	}
529 560
 
530
-	foreach ($incontext['detected_languages'] as $lang => $temp)
531
-		$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
562
+			$extra_files[] = 'Themes/default/languages/' . $lang;
563
+	}
532 564
 
533 565
 	// With mod_security installed, we could attempt to fix it with .htaccess.
534
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
535
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
567
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
568
+	}
536 569
 
537 570
 	$failed_files = array();
538 571
 
@@ -548,12 +581,14 @@  discard block
 block discarded – undo
548 581
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
549 582
 
550 583
 				// Well, 755 hopefully worked... if not, try 777.
551
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
552
-					$failed_files[] = $file;
584
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
585
+									$failed_files[] = $file;
586
+				}
553 587
 			}
554 588
 		}
555
-		foreach ($extra_files as $file)
556
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
589
+		foreach ($extra_files as $file) {
590
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
591
+		}
557 592
 	}
558 593
 	// Windows is trickier.  Let's try opening for r+...
559 594
 	else
@@ -563,30 +598,35 @@  discard block
 block discarded – undo
563 598
 		foreach ($writable_files as $file)
564 599
 		{
565 600
 			// Folders can't be opened for write... but the index.php in them can ;)
566
-			if (is_dir(dirname(__FILE__) . '/' . $file))
567
-				$file .= '/index.php';
601
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
602
+							$file .= '/index.php';
603
+			}
568 604
 
569 605
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
570 606
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
571 607
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
572 608
 
573 609
 			// Hmm, okay, try just for write in that case...
574
-			if (!is_resource($fp))
575
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
610
+			if (!is_resource($fp)) {
611
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
612
+			}
576 613
 
577
-			if (!is_resource($fp))
578
-				$failed_files[] = $file;
614
+			if (!is_resource($fp)) {
615
+							$failed_files[] = $file;
616
+			}
579 617
 
580 618
 			@fclose($fp);
581 619
 		}
582
-		foreach ($extra_files as $file)
583
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
620
+		foreach ($extra_files as $file) {
621
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
622
+		}
584 623
 	}
585 624
 
586 625
 	$failure = count($failed_files) >= 1;
587 626
 
588
-	if (!isset($_SERVER))
589
-		return !$failure;
627
+	if (!isset($_SERVER)) {
628
+			return !$failure;
629
+	}
590 630
 
591 631
 	// Put the list into context.
592 632
 	$incontext['failed_files'] = $failed_files;
@@ -634,19 +674,23 @@  discard block
 block discarded – undo
634 674
 
635 675
 		if (!isset($ftp) || $ftp->error !== false)
636 676
 		{
637
-			if (!isset($ftp))
638
-				$ftp = new ftp_connection(null);
677
+			if (!isset($ftp)) {
678
+							$ftp = new ftp_connection(null);
679
+			}
639 680
 			// Save the error so we can mess with listing...
640
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
641
-				$incontext['ftp_errors'][] = $ftp->last_message;
681
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
682
+							$incontext['ftp_errors'][] = $ftp->last_message;
683
+			}
642 684
 
643 685
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
644 686
 
645
-			if (empty($_POST['ftp_path']) && $found_path)
646
-				$_POST['ftp_path'] = $detect_path;
687
+			if (empty($_POST['ftp_path']) && $found_path) {
688
+							$_POST['ftp_path'] = $detect_path;
689
+			}
647 690
 
648
-			if (!isset($_POST['ftp_username']))
649
-				$_POST['ftp_username'] = $username;
691
+			if (!isset($_POST['ftp_username'])) {
692
+							$_POST['ftp_username'] = $username;
693
+			}
650 694
 
651 695
 			// Set the username etc, into context.
652 696
 			$incontext['ftp'] = array(
@@ -658,8 +702,7 @@  discard block
 block discarded – undo
658 702
 			);
659 703
 
660 704
 			return false;
661
-		}
662
-		else
705
+		} else
663 706
 		{
664 707
 			$_SESSION['installer_temp_ftp'] = array(
665 708
 				'server' => $_POST['ftp_server'],
@@ -673,10 +716,12 @@  discard block
 block discarded – undo
673 716
 
674 717
 			foreach ($failed_files as $file)
675 718
 			{
676
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
677
-					$ftp->chmod($file, 0755);
678
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
679
-					$ftp->chmod($file, 0777);
719
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
720
+									$ftp->chmod($file, 0755);
721
+				}
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0777);
724
+				}
680 725
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
681 726
 				{
682 727
 					$failed_files_updated[] = $file;
@@ -731,15 +776,17 @@  discard block
 block discarded – undo
731 776
 
732 777
 			if (!$foundOne)
733 778
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
779
+				if (isset($db['default_host'])) {
780
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
781
+				}
736 782
 				if (isset($db['default_user']))
737 783
 				{
738 784
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 785
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 786
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
787
+				if (isset($db['default_password'])) {
788
+									$incontext['db']['pass'] = ini_get($db['default_password']);
789
+				}
743 790
 
744 791
 				// For simplicity and less confusion, leave the port blank by default
745 792
 				$incontext['db']['port'] = '';
@@ -758,10 +805,10 @@  discard block
 block discarded – undo
758 805
 		$incontext['db']['server'] = $_POST['db_server'];
759 806
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 807
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
808
+		if (!empty($_POST['db_port'])) {
809
+					$incontext['db']['port'] = $_POST['db_port'];
810
+		}
811
+	} else
765 812
 	{
766 813
 		$incontext['db']['prefix'] = 'smf_';
767 814
 	}
@@ -797,10 +844,11 @@  discard block
 block discarded – undo
797 844
 		if (!empty($_POST['db_port']))
798 845
 		{
799 846
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
847
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
848
+							$vars['db_port'] = (int) $_POST['db_port'];
849
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
850
+							$vars['db_port'] = (int) $_POST['db_port'];
851
+			}
804 852
 		}
805 853
 
806 854
 		// God I hope it saved!
@@ -813,8 +861,9 @@  discard block
 block discarded – undo
813 861
 		// Make sure it works.
814 862
 		require(dirname(__FILE__) . '/Settings.php');
815 863
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
864
+		if (empty($sourcedir)) {
865
+					$sourcedir = dirname(__FILE__) . '/Sources';
866
+		}
818 867
 
819 868
 		// Better find the database file!
820 869
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,18 +873,21 @@  discard block
 block discarded – undo
824 873
 		}
825 874
 
826 875
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
876
+		if (!defined('SMF')) {
877
+					define('SMF', 1);
878
+		}
829 879
 
830 880
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
881
+		if (empty($smcFunc)) {
882
+					$smcFunc = array();
883
+		}
833 884
 
834 885
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 886
 
836 887
 		// What - running PHP4? The shame!
837
-		if (version_compare(PHP_VERSION, '5', '<'))
838
-			require_once($sourcedir . '/Subs-Compat.php');
888
+		if (version_compare(PHP_VERSION, '5', '<')) {
889
+					require_once($sourcedir . '/Subs-Compat.php');
890
+		}
839 891
 
840 892
 		// Attempt a connection.
841 893
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -923,12 +975,14 @@  discard block
 block discarded – undo
923 975
 	$incontext['page_title'] = $txt['install_settings'];
924 976
 
925 977
 	// Let's see if we got the database type correct.
926
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
927
-		$db_type = $_POST['db_type'];
978
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
979
+			$db_type = $_POST['db_type'];
980
+	}
928 981
 
929 982
 	// Else we'd better be able to get the connection.
930
-	else
931
-		load_database();
983
+	else {
984
+			load_database();
985
+	}
932 986
 
933 987
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
934 988
 
@@ -948,12 +1002,14 @@  discard block
 block discarded – undo
948 1002
 	// Submitting?
949 1003
 	if (isset($_POST['boardurl']))
950 1004
 	{
951
-		if (substr($_POST['boardurl'], -10) == '/index.php')
952
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
953
-		elseif (substr($_POST['boardurl'], -1) == '/')
954
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
955
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
956
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1005
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1006
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1007
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1008
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1009
+		}
1010
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1011
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1012
+		}
957 1013
 
958 1014
 		// Save these variables.
959 1015
 		$vars = array(
@@ -984,10 +1040,10 @@  discard block
 block discarded – undo
984 1040
 			{
985 1041
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
986 1042
 				return false;
987
-			}
988
-			else
989
-				// Set the character set here.
1043
+			} else {
1044
+							// Set the character set here.
990 1045
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1046
+			}
991 1047
 		}
992 1048
 
993 1049
 		// Good, skip on.
@@ -1007,8 +1063,9 @@  discard block
 block discarded – undo
1007 1063
 	$incontext['continue'] = 1;
1008 1064
 
1009 1065
 	// Already done?
1010
-	if (isset($_POST['pop_done']))
1011
-		return true;
1066
+	if (isset($_POST['pop_done'])) {
1067
+			return true;
1068
+	}
1012 1069
 
1013 1070
 	// Reload settings.
1014 1071
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1026,8 +1083,9 @@  discard block
 block discarded – undo
1026 1083
 	$modSettings = array();
1027 1084
 	if ($result !== false)
1028 1085
 	{
1029
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1030
-			$modSettings[$row['variable']] = $row['value'];
1086
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1087
+					$modSettings[$row['variable']] = $row['value'];
1088
+		}
1031 1089
 		$smcFunc['db_free_result']($result);
1032 1090
 
1033 1091
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1040,20 +1098,22 @@  discard block
 block discarded – undo
1040 1098
 	$modSettings['disableQueryCheck'] = true;
1041 1099
 
1042 1100
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1043
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1044
-		$smcFunc['db_query']('', '
1101
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1102
+			$smcFunc['db_query']('', '
1045 1103
 			SET NAMES {string:utf8}',
1046 1104
 			array(
1047 1105
 				'db_error_skip' => true,
1048 1106
 				'utf8' => 'utf8',
1049 1107
 			)
1050 1108
 		);
1109
+	}
1051 1110
 
1052 1111
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1053
-	if (substr(__DIR__, -1) == '\\')
1054
-		$attachdir = __DIR__ . 'attachments';
1055
-	else
1056
-		$attachdir = __DIR__ . '/attachments';
1112
+	if (substr(__DIR__, -1) == '\\') {
1113
+			$attachdir = __DIR__ . 'attachments';
1114
+	} else {
1115
+			$attachdir = __DIR__ . '/attachments';
1116
+	}
1057 1117
 
1058 1118
 	$replaces = array(
1059 1119
 		'{$db_prefix}' => $db_prefix,
@@ -1070,8 +1130,9 @@  discard block
 block discarded – undo
1070 1130
 
1071 1131
 	foreach ($txt as $key => $value)
1072 1132
 	{
1073
-		if (substr($key, 0, 8) == 'default_')
1074
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1133
+		if (substr($key, 0, 8) == 'default_') {
1134
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1135
+		}
1075 1136
 	}
1076 1137
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1077 1138
 
@@ -1086,8 +1147,9 @@  discard block
 block discarded – undo
1086 1147
 
1087 1148
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1088 1149
 		{
1089
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1090
-				$engines[] = $row['Engine'];
1150
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1151
+							$engines[] = $row['Engine'];
1152
+			}
1091 1153
 		}
1092 1154
 
1093 1155
 		// Done with this now
@@ -1111,8 +1173,7 @@  discard block
 block discarded – undo
1111 1173
 			$replaces['START TRANSACTION;'] = '';
1112 1174
 			$replaces['COMMIT;'] = '';
1113 1175
 		}
1114
-	}
1115
-	else
1176
+	} else
1116 1177
 	{
1117 1178
 		$has_innodb = false;
1118 1179
 	}
@@ -1134,21 +1195,24 @@  discard block
 block discarded – undo
1134 1195
 	foreach ($sql_lines as $count => $line)
1135 1196
 	{
1136 1197
 		// No comments allowed!
1137
-		if (substr(trim($line), 0, 1) != '#')
1138
-			$current_statement .= "\n" . rtrim($line);
1198
+		if (substr(trim($line), 0, 1) != '#') {
1199
+					$current_statement .= "\n" . rtrim($line);
1200
+		}
1139 1201
 
1140 1202
 		// Is this the end of the query string?
1141
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1142
-			continue;
1203
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1204
+					continue;
1205
+		}
1143 1206
 
1144 1207
 		// Does this table already exist?  If so, don't insert more data into it!
1145 1208
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1146 1209
 		{
1147 1210
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1148
-			if (!empty($matches[0]))
1149
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1150
-			else
1151
-				$incontext['sql_results']['insert_dups']++;
1211
+			if (!empty($matches[0])) {
1212
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1213
+			} else {
1214
+							$incontext['sql_results']['insert_dups']++;
1215
+			}
1152 1216
 
1153 1217
 			$current_statement = '';
1154 1218
 			continue;
@@ -1157,8 +1221,9 @@  discard block
 block discarded – undo
1157 1221
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1158 1222
 		{
1159 1223
 			// Use the appropriate function based on the DB type
1160
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1161
-				$db_errorno = $db_type . '_errno';
1224
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1225
+							$db_errorno = $db_type . '_errno';
1226
+			}
1162 1227
 
1163 1228
 			// Error 1050: Table already exists!
1164 1229
 			// @todo Needs to be made better!
@@ -1173,18 +1238,18 @@  discard block
 block discarded – undo
1173 1238
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1174 1239
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1175 1240
 			}
1176
-		}
1177
-		else
1241
+		} else
1178 1242
 		{
1179
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1180
-				$incontext['sql_results']['tables']++;
1181
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1243
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1244
+							$incontext['sql_results']['tables']++;
1245
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1182 1246
 			{
1183 1247
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1184
-				if (!empty($matches[0]))
1185
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1186
-				else
1187
-					$incontext['sql_results']['inserts']++;
1248
+				if (!empty($matches[0])) {
1249
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1250
+				} else {
1251
+									$incontext['sql_results']['inserts']++;
1252
+				}
1188 1253
 			}
1189 1254
 		}
1190 1255
 
@@ -1197,15 +1262,17 @@  discard block
 block discarded – undo
1197 1262
 	// Sort out the context for the SQL.
1198 1263
 	foreach ($incontext['sql_results'] as $key => $number)
1199 1264
 	{
1200
-		if ($number == 0)
1201
-			unset($incontext['sql_results'][$key]);
1202
-		else
1203
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1265
+		if ($number == 0) {
1266
+					unset($incontext['sql_results'][$key]);
1267
+		} else {
1268
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1269
+		}
1204 1270
 	}
1205 1271
 
1206 1272
 	// Make sure UTF will be used globally.
1207
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1208
-		$newSettings[] = array('global_character_set', 'UTF-8');
1273
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1274
+			$newSettings[] = array('global_character_set', 'UTF-8');
1275
+	}
1209 1276
 
1210 1277
 	// Maybe we can auto-detect better cookie settings?
1211 1278
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1216,16 +1283,20 @@  discard block
 block discarded – undo
1216 1283
 		$globalCookies = false;
1217 1284
 
1218 1285
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1219
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1220
-			$globalCookies = true;
1286
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1287
+					$globalCookies = true;
1288
+		}
1221 1289
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1222
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1223
-			$localCookies = true;
1290
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1291
+					$localCookies = true;
1292
+		}
1224 1293
 
1225
-		if ($globalCookies)
1226
-			$newSettings[] = array('globalCookies', '1');
1227
-		if ($localCookies)
1228
-			$newSettings[] = array('localCookies', '1');
1294
+		if ($globalCookies) {
1295
+					$newSettings[] = array('globalCookies', '1');
1296
+		}
1297
+		if ($localCookies) {
1298
+					$newSettings[] = array('localCookies', '1');
1299
+		}
1229 1300
 	}
1230 1301
 
1231 1302
 	// Are we allowing stat collection?
@@ -1241,32 +1312,36 @@  discard block
 block discarded – undo
1241 1312
 			fwrite($fp, $out);
1242 1313
 
1243 1314
 			$return_data = '';
1244
-			while (!feof($fp))
1245
-				$return_data .= fgets($fp, 128);
1315
+			while (!feof($fp)) {
1316
+							$return_data .= fgets($fp, 128);
1317
+			}
1246 1318
 
1247 1319
 			fclose($fp);
1248 1320
 
1249 1321
 			// Get the unique site ID.
1250 1322
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1251 1323
 
1252
-			if (!empty($ID[1]))
1253
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1324
+			if (!empty($ID[1])) {
1325
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1326
+			}
1254 1327
 		}
1255 1328
 	}
1256 1329
 
1257 1330
 	// Are we enabling SSL?
1258
-	if (!empty($_POST['force_ssl']))
1259
-		$newSettings[] = array('force_ssl', 2);
1331
+	if (!empty($_POST['force_ssl'])) {
1332
+			$newSettings[] = array('force_ssl', 2);
1333
+	}
1260 1334
 
1261 1335
 	// Setting a timezone is required.
1262 1336
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1263 1337
 	{
1264 1338
 		// Get PHP's default timezone, if set
1265 1339
 		$ini_tz = ini_get('date.timezone');
1266
-		if (!empty($ini_tz))
1267
-			$timezone_id = $ini_tz;
1268
-		else
1269
-			$timezone_id = '';
1340
+		if (!empty($ini_tz)) {
1341
+					$timezone_id = $ini_tz;
1342
+		} else {
1343
+					$timezone_id = '';
1344
+		}
1270 1345
 
1271 1346
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1272 1347
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1275,8 +1350,9 @@  discard block
 block discarded – undo
1275 1350
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1276 1351
 		}
1277 1352
 
1278
-		if (date_default_timezone_set($timezone_id))
1279
-			$newSettings[] = array('default_timezone', $timezone_id);
1353
+		if (date_default_timezone_set($timezone_id)) {
1354
+					$newSettings[] = array('default_timezone', $timezone_id);
1355
+		}
1280 1356
 	}
1281 1357
 
1282 1358
 	if (!empty($newSettings))
@@ -1307,16 +1383,18 @@  discard block
 block discarded – undo
1307 1383
 	}
1308 1384
 
1309 1385
 	// MySQL specific stuff
1310
-	if (substr($db_type, 0, 5) != 'mysql')
1311
-		return false;
1386
+	if (substr($db_type, 0, 5) != 'mysql') {
1387
+			return false;
1388
+	}
1312 1389
 
1313 1390
 	// Find database user privileges.
1314 1391
 	$privs = array();
1315 1392
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1316 1393
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1317 1394
 	{
1318
-		if ($row['Privilege'] == 'Alter')
1319
-			$privs[] = $row['Privilege'];
1395
+		if ($row['Privilege'] == 'Alter') {
1396
+					$privs[] = $row['Privilege'];
1397
+		}
1320 1398
 	}
1321 1399
 	$smcFunc['db_free_result']($get_privs);
1322 1400
 
@@ -1346,8 +1424,9 @@  discard block
 block discarded – undo
1346 1424
 	$incontext['continue'] = 1;
1347 1425
 
1348 1426
 	// Skipping?
1349
-	if (!empty($_POST['skip']))
1350
-		return true;
1427
+	if (!empty($_POST['skip'])) {
1428
+			return true;
1429
+	}
1351 1430
 
1352 1431
 	// Need this to check whether we need the database password.
1353 1432
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1360,18 +1439,22 @@  discard block
 block discarded – undo
1360 1439
 	// We need this to properly hash the password for Admin
1361 1440
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1362 1441
 			global $sourcedir;
1363
-			if (function_exists('mb_strtolower'))
1364
-				return mb_strtolower($string, 'UTF-8');
1442
+			if (function_exists('mb_strtolower')) {
1443
+							return mb_strtolower($string, 'UTF-8');
1444
+			}
1365 1445
 			require_once($sourcedir . '/Subs-Charset.php');
1366 1446
 			return utf8_strtolower($string);
1367 1447
 		};
1368 1448
 
1369
-	if (!isset($_POST['username']))
1370
-		$_POST['username'] = '';
1371
-	if (!isset($_POST['email']))
1372
-		$_POST['email'] = '';
1373
-	if (!isset($_POST['server_email']))
1374
-		$_POST['server_email'] = '';
1449
+	if (!isset($_POST['username'])) {
1450
+			$_POST['username'] = '';
1451
+	}
1452
+	if (!isset($_POST['email'])) {
1453
+			$_POST['email'] = '';
1454
+	}
1455
+	if (!isset($_POST['server_email'])) {
1456
+			$_POST['server_email'] = '';
1457
+	}
1375 1458
 
1376 1459
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1377 1460
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1390,8 +1473,9 @@  discard block
 block discarded – undo
1390 1473
 			'admin_group' => 1,
1391 1474
 		)
1392 1475
 	);
1393
-	if ($smcFunc['db_num_rows']($request) != 0)
1394
-		$incontext['skip'] = 1;
1476
+	if ($smcFunc['db_num_rows']($request) != 0) {
1477
+			$incontext['skip'] = 1;
1478
+	}
1395 1479
 	$smcFunc['db_free_result']($request);
1396 1480
 
1397 1481
 	// Trying to create an account?
@@ -1422,8 +1506,9 @@  discard block
 block discarded – undo
1422 1506
 		}
1423 1507
 
1424 1508
 		// Update the webmaster's email?
1425
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1426
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1509
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1510
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1511
+		}
1427 1512
 
1428 1513
 		// Work out whether we're going to have dodgy characters and remove them.
1429 1514
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1446,32 +1531,27 @@  discard block
 block discarded – undo
1446 1531
 			$smcFunc['db_free_result']($result);
1447 1532
 
1448 1533
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1449
-		}
1450
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1534
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1451 1535
 		{
1452 1536
 			// Try the previous step again.
1453 1537
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1454 1538
 			return false;
1455
-		}
1456
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1539
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1457 1540
 		{
1458 1541
 			// Try the previous step again.
1459 1542
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1460 1543
 			return false;
1461
-		}
1462
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1544
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1463 1545
 		{
1464 1546
 			// One step back, this time fill out a proper admin email address.
1465 1547
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1466 1548
 			return false;
1467
-		}
1468
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1549
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1469 1550
 		{
1470 1551
 			// One step back, this time fill out a proper admin email address.
1471 1552
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1472 1553
 			return false;
1473
-		}
1474
-		elseif ($_POST['username'] != '')
1554
+		} elseif ($_POST['username'] != '')
1475 1555
 		{
1476 1556
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1477 1557
 
@@ -1546,17 +1626,19 @@  discard block
 block discarded – undo
1546 1626
 	require_once($sourcedir . '/Subs-Auth.php');
1547 1627
 
1548 1628
 	// Bring a warning over.
1549
-	if (!empty($incontext['account_existed']))
1550
-		$incontext['warning'] = $incontext['account_existed'];
1629
+	if (!empty($incontext['account_existed'])) {
1630
+			$incontext['warning'] = $incontext['account_existed'];
1631
+	}
1551 1632
 
1552
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1553
-		$smcFunc['db_query']('', '
1633
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1634
+			$smcFunc['db_query']('', '
1554 1635
 			SET NAMES {string:db_character_set}',
1555 1636
 			array(
1556 1637
 				'db_character_set' => $db_character_set,
1557 1638
 				'db_error_skip' => true,
1558 1639
 			)
1559 1640
 		);
1641
+	}
1560 1642
 
1561 1643
 	// As track stats is by default enabled let's add some activity.
1562 1644
 	$smcFunc['db_insert']('ignore',
@@ -1577,14 +1659,16 @@  discard block
 block discarded – undo
1577 1659
 	// Only proceed if we can load the data.
1578 1660
 	if ($request)
1579 1661
 	{
1580
-		while ($row = $smcFunc['db_fetch_row']($request))
1581
-			$modSettings[$row[0]] = $row[1];
1662
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1663
+					$modSettings[$row[0]] = $row[1];
1664
+		}
1582 1665
 		$smcFunc['db_free_result']($request);
1583 1666
 	}
1584 1667
 
1585 1668
 	// Automatically log them in ;)
1586
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1587
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1669
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1670
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1671
+	}
1588 1672
 
1589 1673
 	$result = $smcFunc['db_query']('', '
1590 1674
 		SELECT value
@@ -1595,13 +1679,14 @@  discard block
 block discarded – undo
1595 1679
 			'db_error_skip' => true,
1596 1680
 		)
1597 1681
 	);
1598
-	if ($smcFunc['db_num_rows']($result) != 0)
1599
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1682
+	if ($smcFunc['db_num_rows']($result) != 0) {
1683
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1684
+	}
1600 1685
 	$smcFunc['db_free_result']($result);
1601 1686
 
1602
-	if (empty($db_sessions))
1603
-		$_SESSION['admin_time'] = time();
1604
-	else
1687
+	if (empty($db_sessions)) {
1688
+			$_SESSION['admin_time'] = time();
1689
+	} else
1605 1690
 	{
1606 1691
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1607 1692
 
@@ -1625,8 +1710,9 @@  discard block
 block discarded – undo
1625 1710
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1626 1711
 		function($string){
1627 1712
 			global $sourcedir;
1628
-			if (function_exists('mb_strtolower'))
1629
-				return mb_strtolower($string, 'UTF-8');
1713
+			if (function_exists('mb_strtolower')) {
1714
+							return mb_strtolower($string, 'UTF-8');
1715
+			}
1630 1716
 			require_once($sourcedir . '/Subs-Charset.php');
1631 1717
 			return utf8_strtolower($string);
1632 1718
 		};
@@ -1642,8 +1728,9 @@  discard block
 block discarded – undo
1642 1728
 		)
1643 1729
 	);
1644 1730
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1645
-	if ($smcFunc['db_num_rows']($request) > 0)
1646
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1731
+	if ($smcFunc['db_num_rows']($request) > 0) {
1732
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1733
+	}
1647 1734
 	$smcFunc['db_free_result']($request);
1648 1735
 
1649 1736
 	// Now is the perfect time to fetch the SM files.
@@ -1662,8 +1749,9 @@  discard block
 block discarded – undo
1662 1749
 
1663 1750
 	// Check if we need some stupid MySQL fix.
1664 1751
 	$server_version = $smcFunc['db_server_info']();
1665
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1666
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1752
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1753
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1754
+	}
1667 1755
 
1668 1756
 	// Some final context for the template.
1669 1757
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1683,8 +1771,9 @@  discard block
 block discarded – undo
1683 1771
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1684 1772
 
1685 1773
 	// @todo Do we just want to read the file in clean, and split it this way always?
1686
-	if (count($settingsArray) == 1)
1687
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1774
+	if (count($settingsArray) == 1) {
1775
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1776
+	}
1688 1777
 
1689 1778
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1690 1779
 	{
@@ -1699,19 +1788,22 @@  discard block
 block discarded – undo
1699 1788
 			continue;
1700 1789
 		}
1701 1790
 
1702
-		if (trim($settingsArray[$i]) == '?' . '>')
1703
-			$settingsArray[$i] = '';
1791
+		if (trim($settingsArray[$i]) == '?' . '>') {
1792
+					$settingsArray[$i] = '';
1793
+		}
1704 1794
 
1705 1795
 		// Don't trim or bother with it if it's not a variable.
1706
-		if (substr($settingsArray[$i], 0, 1) != '$')
1707
-			continue;
1796
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1797
+					continue;
1798
+		}
1708 1799
 
1709 1800
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1710 1801
 
1711
-		foreach ($vars as $var => $val)
1712
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1802
+		foreach ($vars as $var => $val) {
1803
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1713 1804
 			{
1714 1805
 				$comment = strstr($settingsArray[$i], '#');
1806
+		}
1715 1807
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1716 1808
 				unset($vars[$var]);
1717 1809
 			}
@@ -1721,36 +1813,41 @@  discard block
 block discarded – undo
1721 1813
 	if (!empty($vars))
1722 1814
 	{
1723 1815
 		$settingsArray[$i++] = '';
1724
-		foreach ($vars as $var => $val)
1725
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1816
+		foreach ($vars as $var => $val) {
1817
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1818
+		}
1726 1819
 	}
1727 1820
 
1728 1821
 	// Blank out the file - done to fix a oddity with some servers.
1729 1822
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1730
-	if (!$fp)
1731
-		return false;
1823
+	if (!$fp) {
1824
+			return false;
1825
+	}
1732 1826
 	fclose($fp);
1733 1827
 
1734 1828
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1735 1829
 
1736 1830
 	// Gotta have one of these ;)
1737
-	if (trim($settingsArray[0]) != '<?php')
1738
-		fwrite($fp, "<?php\n");
1831
+	if (trim($settingsArray[0]) != '<?php') {
1832
+			fwrite($fp, "<?php\n");
1833
+	}
1739 1834
 
1740 1835
 	$lines = count($settingsArray);
1741 1836
 	for ($i = 0; $i < $lines - 1; $i++)
1742 1837
 	{
1743 1838
 		// Don't just write a bunch of blank lines.
1744
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1745
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1839
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1840
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1841
+		}
1746 1842
 	}
1747 1843
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1748 1844
 	fclose($fp);
1749 1845
 
1750 1846
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1751 1847
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1752
-	if (function_exists('opcache_invalidate'))
1753
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1848
+	if (function_exists('opcache_invalidate')) {
1849
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1850
+	}
1754 1851
 
1755 1852
 	return true;
1756 1853
 }
@@ -1775,9 +1872,9 @@  discard block
 block discarded – undo
1775 1872
 	SecFilterScanPOST Off
1776 1873
 </IfModule>';
1777 1874
 
1778
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1779
-		return true;
1780
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1875
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1876
+			return true;
1877
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1781 1878
 	{
1782 1879
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1783 1880
 
@@ -1789,29 +1886,28 @@  discard block
 block discarded – undo
1789 1886
 				fwrite($ht_handle, $htaccess_addition);
1790 1887
 				fclose($ht_handle);
1791 1888
 				return true;
1889
+			} else {
1890
+							return false;
1792 1891
 			}
1793
-			else
1794
-				return false;
1892
+		} else {
1893
+					return true;
1795 1894
 		}
1796
-		else
1797
-			return true;
1798
-	}
1799
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1800
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1801
-	elseif (is_writable(dirname(__FILE__)))
1895
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1896
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1897
+	} elseif (is_writable(dirname(__FILE__)))
1802 1898
 	{
1803 1899
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1804 1900
 		{
1805 1901
 			fwrite($ht_handle, $htaccess_addition);
1806 1902
 			fclose($ht_handle);
1807 1903
 			return true;
1904
+		} else {
1905
+					return false;
1808 1906
 		}
1809
-		else
1907
+	} else {
1810 1908
 			return false;
1811 1909
 	}
1812
-	else
1813
-		return false;
1814
-}
1910
+	}
1815 1911
 
1816 1912
 function template_install_above()
1817 1913
 {
@@ -1849,9 +1945,10 @@  discard block
 block discarded – undo
1849 1945
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1850 1946
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1851 1947
 
1852
-		foreach ($incontext['detected_languages'] as $lang => $name)
1853
-			echo '
1948
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1949
+					echo '
1854 1950
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1951
+		}
1855 1952
 
1856 1953
 		echo '
1857 1954
 								</select>
@@ -1871,9 +1968,10 @@  discard block
 block discarded – undo
1871 1968
 						<h2>', $txt['upgrade_progress'], '</h2>
1872 1969
 						<ul>';
1873 1970
 
1874
-	foreach ($incontext['steps'] as $num => $step)
1875
-		echo '
1971
+	foreach ($incontext['steps'] as $num => $step) {
1972
+			echo '
1876 1973
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1974
+	}
1877 1975
 
1878 1976
 	echo '
1879 1977
 						</ul>
@@ -1898,20 +1996,23 @@  discard block
 block discarded – undo
1898 1996
 		echo '
1899 1997
 								<div>';
1900 1998
 
1901
-		if (!empty($incontext['continue']))
1902
-			echo '
1999
+		if (!empty($incontext['continue'])) {
2000
+					echo '
1903 2001
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1904
-		if (!empty($incontext['skip']))
1905
-			echo '
2002
+		}
2003
+		if (!empty($incontext['skip'])) {
2004
+					echo '
1906 2005
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2006
+		}
1907 2007
 		echo '
1908 2008
 								</div>';
1909 2009
 	}
1910 2010
 
1911 2011
 	// Show the closing form tag and other data only if not in the last step
1912
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1913
-		echo '
2012
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2013
+			echo '
1914 2014
 							</form>';
2015
+	}
1915 2016
 
1916 2017
 	echo '
1917 2018
 						</div>
@@ -1946,13 +2047,15 @@  discard block
 block discarded – undo
1946 2047
 		</div>';
1947 2048
 
1948 2049
 	// Show the warnings, or not.
1949
-	if (template_warning_divs())
1950
-		echo '
2050
+	if (template_warning_divs()) {
2051
+			echo '
1951 2052
 		<h3>', $txt['install_all_lovely'], '</h3>';
2053
+	}
1952 2054
 
1953 2055
 	// Say we want the continue button!
1954
-	if (empty($incontext['error']))
1955
-		$incontext['continue'] = 1;
2056
+	if (empty($incontext['error'])) {
2057
+			$incontext['continue'] = 1;
2058
+	}
1956 2059
 
1957 2060
 	// For the latest version stuff.
1958 2061
 	echo '
@@ -1986,8 +2089,8 @@  discard block
 block discarded – undo
1986 2089
 	global $txt, $incontext;
1987 2090
 
1988 2091
 	// Errors are very serious..
1989
-	if (!empty($incontext['error']))
1990
-		echo '
2092
+	if (!empty($incontext['error'])) {
2093
+			echo '
1991 2094
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1992 2095
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1993 2096
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1995,9 +2098,10 @@  discard block
 block discarded – undo
1995 2098
 				', $incontext['error'], '
1996 2099
 			</div>
1997 2100
 		</div>';
2101
+	}
1998 2102
 	// A warning message?
1999
-	elseif (!empty($incontext['warning']))
2000
-		echo '
2103
+	elseif (!empty($incontext['warning'])) {
2104
+			echo '
2001 2105
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2002 2106
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2003 2107
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2005,6 +2109,7 @@  discard block
 block discarded – undo
2005 2109
 				', $incontext['warning'], '
2006 2110
 			</div>
2007 2111
 		</div>';
2112
+	}
2008 2113
 
2009 2114
 	return empty($incontext['error']) && empty($incontext['warning']);
2010 2115
 }
@@ -2020,27 +2125,30 @@  discard block
 block discarded – undo
2020 2125
 			<li>', $incontext['failed_files']), '</li>
2021 2126
 		</ul>';
2022 2127
 
2023
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2024
-		echo '
2128
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2129
+			echo '
2025 2130
 		<hr>
2026 2131
 		<p>', $txt['chmod_linux_info'], '</p>
2027 2132
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2133
+	}
2028 2134
 
2029 2135
 	// This is serious!
2030
-	if (!template_warning_divs())
2031
-		return;
2136
+	if (!template_warning_divs()) {
2137
+			return;
2138
+	}
2032 2139
 
2033 2140
 	echo '
2034 2141
 		<hr>
2035 2142
 		<p>', $txt['ftp_setup_info'], '</p>';
2036 2143
 
2037
-	if (!empty($incontext['ftp_errors']))
2038
-		echo '
2144
+	if (!empty($incontext['ftp_errors'])) {
2145
+			echo '
2039 2146
 		<div class="error_message">
2040 2147
 			', $txt['error_ftp_no_connect'], '<br><br>
2041 2148
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2042 2149
 		</div>
2043 2150
 		<br>';
2151
+	}
2044 2152
 
2045 2153
 	echo '
2046 2154
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2100,17 +2208,17 @@  discard block
 block discarded – undo
2100 2208
 				<td>
2101 2209
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2102 2210
 
2103
-	foreach ($incontext['supported_databases'] as $key => $db)
2104
-			echo '
2211
+	foreach ($incontext['supported_databases'] as $key => $db) {
2212
+				echo '
2105 2213
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2214
+	}
2106 2215
 
2107 2216
 	echo '
2108 2217
 					</select>
2109 2218
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2110 2219
 				</td>
2111 2220
 			</tr>';
2112
-	}
2113
-	else
2221
+	} else
2114 2222
 	{
2115 2223
 		echo '
2116 2224
 			<tr style="display: none;">
@@ -2302,9 +2410,10 @@  discard block
 block discarded – undo
2302 2410
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2303 2411
 				<ul>';
2304 2412
 
2305
-		foreach ($incontext['failures'] as $line => $fail)
2306
-			echo '
2413
+		foreach ($incontext['failures'] as $line => $fail) {
2414
+					echo '
2307 2415
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2416
+		}
2308 2417
 
2309 2418
 		echo '
2310 2419
 				</ul>';
@@ -2365,15 +2474,16 @@  discard block
 block discarded – undo
2365 2474
 			</tr>
2366 2475
 		</table>';
2367 2476
 
2368
-	if ($incontext['require_db_confirm'])
2369
-		echo '
2477
+	if ($incontext['require_db_confirm']) {
2478
+			echo '
2370 2479
 		<h2>', $txt['user_settings_database'], '</h2>
2371 2480
 		<p>', $txt['user_settings_database_info'], '</p>
2372 2481
 
2373 2482
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2374 2483
 			<input type="password" name="password3" size="30" class="input_password" />
2375 2484
 		</div>';
2376
-}
2485
+	}
2486
+	}
2377 2487
 
2378 2488
 // Tell them it's done, and to delete.
2379 2489
 function template_delete_install()
@@ -2386,14 +2496,15 @@  discard block
 block discarded – undo
2386 2496
 	template_warning_divs();
2387 2497
 
2388 2498
 	// Install directory still writable?
2389
-	if ($incontext['dir_still_writable'])
2390
-		echo '
2499
+	if ($incontext['dir_still_writable']) {
2500
+			echo '
2391 2501
 		<em>', $txt['still_writable'], '</em><br>
2392 2502
 		<br>';
2503
+	}
2393 2504
 
2394 2505
 	// Don't show the box if it's like 99% sure it won't work :P.
2395
-	if ($incontext['probably_delete_install'])
2396
-		echo '
2506
+	if ($incontext['probably_delete_install']) {
2507
+			echo '
2397 2508
 		<div style="margin: 1ex; font-weight: bold;">
2398 2509
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2399 2510
 		</div>
@@ -2409,6 +2520,7 @@  discard block
 block discarded – undo
2409 2520
 			}
2410 2521
 		</script>
2411 2522
 		<br>';
2523
+	}
2412 2524
 
2413 2525
 	echo '
2414 2526
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +37 added lines, -25 removed lines patch added patch discarded remove patch
@@ -25,8 +25,9 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Get everything started up...
27 27
 define('SMF', 1);
28
-if (function_exists('set_magic_quotes_runtime') && strnatcmp(phpversion(), '5.3.0') < 0)
28
+if (function_exists('set_magic_quotes_runtime') && strnatcmp(phpversion(), '5.3.0') < 0) {
29 29
 	@set_magic_quotes_runtime(0);
30
+}
30 31
 error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
31 32
 $time_start = microtime();
32 33
 
@@ -34,16 +35,18 @@  discard block
 block discarded – undo
34 35
 ob_start();
35 36
 
36 37
 // Do some cleaning, just in case.
37
-foreach (array('db_character_set', 'cachedir') as $variable)
38
+foreach (array('db_character_set', 'cachedir') as $variable) {
38 39
 	if (isset($GLOBALS[$variable]))
39 40
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
41
+}
40 42
 
41 43
 // Load the settings...
42 44
 require_once(dirname(__FILE__) . '/Settings.php');
43 45
 
44 46
 // Make absolutely sure the cache directory is defined.
45
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
47
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
46 48
 	$cachedir = $boarddir . '/cache';
49
+}
47 50
 
48 51
 // Without those we can't go anywhere
49 52
 require_once($sourcedir . '/QueryString.php');
@@ -53,8 +56,9 @@  discard block
 block discarded – undo
53 56
 require_once($sourcedir . '/Load.php');
54 57
 
55 58
 // If $maintenance is set specifically to 2, then we're upgrading or something.
56
-if (!empty($maintenance) && $maintenance == 2)
59
+if (!empty($maintenance) && $maintenance == 2) {
57 60
 	display_maintenance_message();
61
+}
58 62
 
59 63
 // Create a variable to store some SMF specific functions in.
60 64
 $smcFunc = array();
@@ -69,8 +73,9 @@  discard block
 block discarded – undo
69 73
 cleanRequest();
70 74
 
71 75
 // Seed the random generator.
72
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
76
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
73 77
 	smf_seed_generator();
78
+}
74 79
 
75 80
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
76 81
 if (isset($_GET['scheduled']))
@@ -90,9 +95,9 @@  discard block
 block discarded – undo
90 95
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
91 96
 {
92 97
 	// If zlib is being used, turn off output compression.
93
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
94
-		$modSettings['enableCompressedOutput'] = '0';
95
-	else
98
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
99
+			$modSettings['enableCompressedOutput'] = '0';
100
+	} else
96 101
 	{
97 102
 		ob_end_clean();
98 103
 		ob_start('ob_gzhandler');
@@ -141,18 +146,21 @@  discard block
 block discarded – undo
141 146
 	loadPermissions();
142 147
 
143 148
 	// Attachments don't require the entire theme to be loaded.
144
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
145
-		detectBrowser();
149
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
150
+			detectBrowser();
151
+	}
146 152
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
147
-	else
148
-		loadTheme();
153
+	else {
154
+			loadTheme();
155
+	}
149 156
 
150 157
 	// Check if the user should be disallowed access.
151 158
 	is_not_banned();
152 159
 
153 160
 	// If we are in a topic and don't have permission to approve it then duck out now.
154
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
155
-		fatal_lang_error('not_a_topic', false);
161
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
162
+			fatal_lang_error('not_a_topic', false);
163
+	}
156 164
 
157 165
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
158 166
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -163,8 +171,9 @@  discard block
 block discarded – undo
163 171
 		writeLog();
164 172
 
165 173
 		// Track forum statistics and hits...?
166
-		if (!empty($modSettings['hitStats']))
167
-			trackStats(array('hits' => '+'));
174
+		if (!empty($modSettings['hitStats'])) {
175
+					trackStats(array('hits' => '+'));
176
+		}
168 177
 	}
169 178
 	unset($no_stat_actions);
170 179
 
@@ -178,13 +187,14 @@  discard block
 block discarded – undo
178 187
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
179 188
 		}
180 189
 		// Don't even try it, sonny.
181
-		else
182
-			return 'InMaintenance';
190
+		else {
191
+					return 'InMaintenance';
192
+		}
183 193
 	}
184 194
 	// If guest access is off, a guest can only do one of the very few following actions.
185
-	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2'))))
186
-		return 'KickGuest';
187
-	elseif (empty($_REQUEST['action']))
195
+	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) {
196
+			return 'KickGuest';
197
+	} elseif (empty($_REQUEST['action']))
188 198
 	{
189 199
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
190 200
 		if (empty($board) && empty($topic))
@@ -200,8 +210,9 @@  discard block
 block discarded – undo
200 210
 
201 211
 				$call = call_helper($defaultAction, true);
202 212
 
203
-				if (!empty($call))
204
-					return $call;
213
+				if (!empty($call)) {
214
+									return $call;
215
+				}
205 216
 			}
206 217
 
207 218
 			// No default action huh? then go to our good old BoardIndex.
@@ -331,8 +342,9 @@  discard block
 block discarded – undo
331 342
 
332 343
 			$call = call_helper($fallbackAction, true);
333 344
 
334
-			if (!empty($call))
335
-				return $call;
345
+			if (!empty($call)) {
346
+							return $call;
347
+			}
336 348
 		}
337 349
 
338 350
 		// No fallback action, huh?
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 1 patch
Braces   +124 added lines, -93 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 				', template_show_week_grid('main'), '
41 41
 			</div>
42 42
 		';
43
-	}
44
-	else
43
+	} else
45 44
 	{
46 45
 		echo '
47 46
 			<div id="main_grid">
@@ -67,17 +66,19 @@  discard block
 block discarded – undo
67 66
 	global $context, $settings, $txt, $scripturl, $modSettings;
68 67
 
69 68
 	// If the grid doesn't exist, no point in proceeding.
70
-	if (!isset($context['calendar_grid_' . $grid_name]))
71
-		return false;
69
+	if (!isset($context['calendar_grid_' . $grid_name])) {
70
+			return false;
71
+	}
72 72
 
73 73
 	// A handy little pointer variable.
74 74
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
75 75
 
76 76
 	// Some conditions for whether or not we should show the week links *here*.
77
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
78
-		$show_week_links = true;
79
-	else
80
-		$show_week_links = false;
77
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
78
+			$show_week_links = true;
79
+	} else {
80
+			$show_week_links = false;
81
+	}
81 82
 
82 83
 	// Assuming that we've not disabled it, show the title block!
83 84
 	if (empty($calendar_data['disable_title']))
@@ -124,8 +125,9 @@  discard block
 block discarded – undo
124 125
 		echo '<tr>';
125 126
 
126 127
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
127
-		if ($show_week_links === true)
128
-			echo '<th>&nbsp;</th>';
128
+		if ($show_week_links === true) {
129
+					echo '<th>&nbsp;</th>';
130
+		}
129 131
 
130 132
 		// Now, loop through each actual day of the week.
131 133
 		foreach ($calendar_data['week_days'] as $day)
@@ -172,29 +174,32 @@  discard block
 block discarded – undo
172 174
 				// Additional classes are given for events, holidays, and birthdays.
173 175
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
174 176
 				{
175
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
176
-						$classes[] = 'events';
177
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
178
-						$classes[] = 'events';
177
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) {
178
+											$classes[] = 'events';
179
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) {
180
+											$classes[] = 'events';
181
+					}
179 182
 				}
180 183
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
181 184
 				{
182
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
183
-						$classes[] = 'holidays';
184
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
185
-						$classes[] = 'holidays';
185
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) {
186
+											$classes[] = 'holidays';
187
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) {
188
+											$classes[] = 'holidays';
189
+					}
186 190
 				}
187 191
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
188 192
 				{
189
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
190
-						$classes[] = 'birthdays';
191
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
192
-						$classes[] = 'birthdays';
193
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) {
194
+											$classes[] = 'birthdays';
195
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) {
196
+											$classes[] = 'birthdays';
197
+					}
193 198
 				}
194
-			}
195
-			else
196
-				// Default Classes (either compact or comfortable and disabled).
199
+			} else {
200
+							// Default Classes (either compact or comfortable and disabled).
197 201
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
202
+			}
198 203
 				$classes[] = 'disabled';
199 204
 
200 205
 			// Now, implode the classes for each day.
@@ -208,17 +213,19 @@  discard block
 block discarded – undo
208 213
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
209 214
 
210 215
 				// The actual day number - be it a link, or just plain old text!
211
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
212
-					echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
213
-				else
214
-					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
216
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
217
+									echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
218
+				} else {
219
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
220
+				}
215 221
 
216 222
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
217 223
 				if ($is_mini === false)
218 224
 				{
219 225
 					// Holidays are always fun, let's show them!
220
-					if (!empty($day['holidays']))
221
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
226
+					if (!empty($day['holidays'])) {
227
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
228
+					}
222 229
 
223 230
 					// Happy Birthday Dear, Member!
224 231
 					if (!empty($day['birthdays']))
@@ -236,14 +243,16 @@  discard block
 block discarded – undo
236 243
 							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
237 244
 
238 245
 							// 9...10! Let's stop there.
239
-							if ($birthday_count == 10 && $use_js_hide)
240
-								// !!TODO - Inline CSS and JavaScript should be moved.
246
+							if ($birthday_count == 10 && $use_js_hide) {
247
+															// !!TODO - Inline CSS and JavaScript should be moved.
241 248
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
249
+							}
242 250
 
243 251
 							++$birthday_count;
244 252
 						}
245
-						if ($use_js_hide)
246
-							echo '</span>';
253
+						if ($use_js_hide) {
254
+													echo '</span>';
255
+						}
247 256
 
248 257
 						echo '</div>';
249 258
 					}
@@ -253,8 +262,9 @@  discard block
 block discarded – undo
253 262
 					{
254 263
 						// Sort events by start time (all day events will be listed first)
255 264
 						uasort($day['events'], function($a, $b) {
256
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
257
-						        return 0;
265
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
266
+						    						        return 0;
267
+						    }
258 268
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
259 269
 						});
260 270
 
@@ -270,17 +280,19 @@  discard block
 block discarded – undo
270 280
 
271 281
 							echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
272 282
 
273
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
274
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
275
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
276
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
277
-							elseif (!empty($event['allday']))
278
-								echo $txt['calendar_allday'];
283
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
284
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
285
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
286
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
287
+							} elseif (!empty($event['allday'])) {
288
+															echo $txt['calendar_allday'];
289
+							}
279 290
 
280 291
 							echo '</span>';
281 292
 
282
-							if (!empty($event['location']))
283
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
293
+							if (!empty($event['location'])) {
294
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
295
+							}
284 296
 
285 297
 							if ($event['can_edit'] || $event['can_export'])
286 298
 							{
@@ -317,10 +329,11 @@  discard block
 block discarded – undo
317 329
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
318 330
 			elseif ($is_mini === false)
319 331
 			{
320
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
321
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
322
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
323
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
332
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
333
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
334
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
335
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
336
+				}
324 337
 			}
325 338
 
326 339
 			// Close this day and increase var count.
@@ -332,8 +345,9 @@  discard block
 block discarded – undo
332 345
 	}
333 346
 
334 347
 	// Quick Month Navigation + Post Event Link on Main Grids!
335
-	if ($is_mini === false)
336
-		template_calendar_base($show_week_links === true ? 8 : 7);
348
+	if ($is_mini === false) {
349
+			template_calendar_base($show_week_links === true ? 8 : 7);
350
+	}
337 351
 
338 352
 	// The end of our main table.
339 353
 	echo '</table>';
@@ -350,8 +364,9 @@  discard block
 block discarded – undo
350 364
 	global $context, $settings, $txt, $scripturl, $modSettings;
351 365
 
352 366
 	// We might have no reason to proceed, if the variable isn't there.
353
-	if (!isset($context['calendar_grid_' . $grid_name]))
354
-		return false;
367
+	if (!isset($context['calendar_grid_' . $grid_name])) {
368
+			return false;
369
+	}
355 370
 
356 371
 	// Handy pointer.
357 372
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -387,8 +402,9 @@  discard block
 block discarded – undo
387 402
 					}
388 403
 
389 404
 					// The Month Title + Week Number...
390
-					if (!empty($calendar_data['week_title']))
391
-							echo $calendar_data['week_title'];
405
+					if (!empty($calendar_data['week_title'])) {
406
+												echo $calendar_data['week_title'];
407
+					}
392 408
 
393 409
 					echo '
394 410
 					</h3>
@@ -424,10 +440,11 @@  discard block
 block discarded – undo
424 440
 						<tr class="days_wrapper">
425 441
 							<td class="', implode(' ', $classes), ' act_day">';
426 442
 							// Should the day number be a link?
427
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
428
-								echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
429
-							else
430
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
443
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
444
+															echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
445
+							} else {
446
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
447
+							}
431 448
 
432 449
 							echo '</td>
433 450
 							<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
@@ -436,8 +453,9 @@  discard block
 block discarded – undo
436 453
 							{
437 454
 								// Sort events by start time (all day events will be listed first)
438 455
 								uasort($day['events'], function($a, $b) {
439
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
440
-								        return 0;
456
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
457
+								    								        return 0;
458
+								    }
441 459
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
442 460
 								});
443 461
 
@@ -449,15 +467,17 @@  discard block
 block discarded – undo
449 467
 
450 468
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
451 469
 
452
-									if (!empty($event['start_time_local']))
453
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
454
-									else
455
-										echo $txt['calendar_allday'];
470
+									if (!empty($event['start_time_local'])) {
471
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
472
+									} else {
473
+																			echo $txt['calendar_allday'];
474
+									}
456 475
 
457 476
 									echo '</span>';
458 477
 
459
-									if (!empty($event['location']))
460
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
478
+									if (!empty($event['location'])) {
479
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
480
+									}
461 481
 
462 482
 									if (!empty($event_icons_needed))
463 483
 									{
@@ -494,8 +514,7 @@  discard block
 block discarded – undo
494 514
 									</div>
495 515
 									<br class="clear">';
496 516
 								}
497
-							}
498
-							else
517
+							} else
499 518
 							{
500 519
 								if (!empty($context['can_post']))
501 520
 								{
@@ -508,8 +527,9 @@  discard block
 block discarded – undo
508 527
 							echo '</td>
509 528
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
510 529
 							// Show any holidays!
511
-							if (!empty($day['holidays']))
512
-								echo implode('<br>', $day['holidays']);
530
+							if (!empty($day['holidays'])) {
531
+															echo implode('<br>', $day['holidays']);
532
+							}
513 533
 
514 534
 							echo '</td>
515 535
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -529,8 +549,9 @@  discard block
 block discarded – undo
529 549
 				}
530 550
 
531 551
 				// We'll show the lower column after our last month is shown.
532
-				if ($iteration == $num_months)
533
-					template_calendar_base(4);
552
+				if ($iteration == $num_months) {
553
+									template_calendar_base(4);
554
+				}
534 555
 
535 556
 				// Increase iteration for loop counting.
536 557
 				++$iteration;
@@ -592,8 +613,9 @@  discard block
 block discarded – undo
592 613
 	echo '
593 614
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
594 615
 
595
-	if (!empty($context['event']['new']))
596
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
616
+	if (!empty($context['event']['new'])) {
617
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
618
+	}
597 619
 
598 620
 	// Start the main table.
599 621
 	echo '
@@ -643,9 +665,10 @@  discard block
 block discarded – undo
643 665
 		{
644 666
 			echo '
645 667
 								<optgroup label="', $category['name'], '">';
646
-			foreach ($category['boards'] as $board)
647
-				echo '
668
+			foreach ($category['boards'] as $board) {
669
+							echo '
648 670
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
671
+			}
649 672
 			echo '
650 673
 								</optgroup>';
651 674
 		}
@@ -681,9 +704,10 @@  discard block
 block discarded – undo
681 704
 							<span class="label">', $txt['calendar_timezone'], '</span>
682 705
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
683 706
 
684
-	foreach ($context['all_timezones'] as $tz => $tzname)
685
-		echo '
707
+	foreach ($context['all_timezones'] as $tz => $tzname) {
708
+			echo '
686 709
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
710
+	}
687 711
 
688 712
 	echo '
689 713
 							</select>
@@ -698,9 +722,10 @@  discard block
 block discarded – undo
698 722
 	echo '
699 723
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
700 724
 	// Delete button?
701
-	if (empty($context['event']['new']))
702
-		echo '
725
+	if (empty($context['event']['new'])) {
726
+			echo '
703 727
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
728
+	}
704 729
 
705 730
 	echo '
706 731
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -744,9 +769,10 @@  discard block
 block discarded – undo
744 769
 
745 770
 		foreach ($context['clockicons'] as $t => $v)
746 771
 		{
747
-			foreach ($v as $i)
748
-				echo '
772
+			foreach ($v as $i) {
773
+							echo '
749 774
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
775
+			}
750 776
 		}
751 777
 
752 778
 		echo '
@@ -771,13 +797,14 @@  discard block
 block discarded – undo
771 797
 
772 798
 		foreach ($context['clockicons'] as $t => $v)
773 799
 		{
774
-			foreach ($v as $i)
775
-				echo '
800
+			foreach ($v as $i) {
801
+							echo '
776 802
 			if (', $t, ' >= ', $i, ')
777 803
 			{
778 804
 				turnon.push("', $t, '_', $i, '");
779 805
 				', $t, ' -= ', $i, ';
780 806
 			}';
807
+			}
781 808
 		}
782 809
 
783 810
 		echo '
@@ -841,9 +868,10 @@  discard block
 block discarded – undo
841 868
 
842 869
 	foreach ($context['clockicons'] as $t => $v)
843 870
 	{
844
-		foreach ($v as $i)
845
-			echo '
871
+		foreach ($v as $i) {
872
+					echo '
846 873
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
874
+		}
847 875
 	}
848 876
 
849 877
 	echo '
@@ -860,13 +888,14 @@  discard block
 block discarded – undo
860 888
 
861 889
 	foreach ($context['clockicons'] as $t => $v)
862 890
 	{
863
-		foreach ($v as $i)
864
-			echo '
891
+		foreach ($v as $i) {
892
+					echo '
865 893
 		if (', $t, ' >= ', $i, ')
866 894
 		{
867 895
 			turnon.push("', $t, '_', $i, '");
868 896
 			', $t, ' -= ', $i, ';
869 897
 		}';
898
+		}
870 899
 	}
871 900
 
872 901
 	echo '
@@ -925,9 +954,10 @@  discard block
 block discarded – undo
925 954
 
926 955
 	foreach ($context['clockicons'] as $t => $v)
927 956
 	{
928
-		foreach ($v as $i)
929
-			echo '
957
+		foreach ($v as $i) {
958
+					echo '
930 959
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
960
+		}
931 961
 	}
932 962
 
933 963
 	echo '
@@ -948,13 +978,14 @@  discard block
 block discarded – undo
948 978
 
949 979
 	foreach ($context['clockicons'] as $t => $v)
950 980
 	{
951
-		foreach ($v as $i)
952
-		echo '
981
+		foreach ($v as $i) {
982
+				echo '
953 983
 		if (', $t, ' >= ', $i, ')
954 984
 		{
955 985
 			turnon.push("', $t, '_', $i, '");
956 986
 			', $t, ' -= ', $i, ';
957 987
 		}';
988
+		}
958 989
 	}
959 990
 
960 991
 	echo '
Please login to merge, or discard this patch.
Themes/default/GenericMenu.template.php 1 patch
Braces   +50 added lines, -37 removed lines patch added patch discarded remove patch
@@ -89,8 +89,9 @@  discard block
 block discarded – undo
89 89
 		foreach ($section['areas'] as $i => $area)
90 90
 		{
91 91
 			// Not supposed to be printed?
92
-			if (empty($area['label']))
93
-				continue;
92
+			if (empty($area['label'])) {
93
+							continue;
94
+			}
94 95
 
95 96
 			echo '
96 97
 								<li', !empty($area['subsections']) ? ' class="subsections"' : '', '>';
@@ -99,8 +100,9 @@  discard block
 block discarded – undo
99 100
 									<a class="', $area['icon_class'], !empty($area['selected']) ? ' chosen ' : '', '" href="', (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i), $menu_context['extra_parameters'], '">', $area['icon'], $area['label'], '</a>';
100 101
 
101 102
 			// Is this the current area, or just some area?
102
-			if (!empty($area['selected']) && empty($context['tabs']))
103
-					$context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
103
+			if (!empty($area['selected']) && empty($context['tabs'])) {
104
+								$context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
105
+			}
104 106
 
105 107
 			// Are there any subsections?
106 108
 			if (!empty($area['subsections']))
@@ -110,8 +112,9 @@  discard block
 block discarded – undo
110 112
 
111 113
 				foreach ($area['subsections'] as $sa => $sub)
112 114
 				{
113
-					if (!empty($sub['disabled']))
114
-						continue;
115
+					if (!empty($sub['disabled'])) {
116
+											continue;
117
+					}
115 118
 
116 119
 					$url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
117 120
 
@@ -158,8 +161,9 @@  discard block
 block discarded – undo
158 161
 							<h3 class="catbg">';
159 162
 
160 163
 		// The function is in Admin.template.php, but since this template is used elsewhere too better check if the function is available
161
-		if (function_exists('template_admin_quick_search'))
162
-			template_admin_quick_search();
164
+		if (function_exists('template_admin_quick_search')) {
165
+					template_admin_quick_search();
166
+		}
163 167
 
164 168
 		// Exactly how many tabs do we have?
165 169
 		if (!empty($context['tabs']))
@@ -174,30 +178,36 @@  discard block
 block discarded – undo
174 178
 				}
175 179
 
176 180
 				// Did this not even exist - or do we not have a label?
177
-				if (!isset($tab_context['tabs'][$id]))
178
-					$tab_context['tabs'][$id] = array('label' => $tab['label']);
179
-				elseif (!isset($tab_context['tabs'][$id]['label']))
180
-					$tab_context['tabs'][$id]['label'] = $tab['label'];
181
+				if (!isset($tab_context['tabs'][$id])) {
182
+									$tab_context['tabs'][$id] = array('label' => $tab['label']);
183
+				} elseif (!isset($tab_context['tabs'][$id]['label'])) {
184
+									$tab_context['tabs'][$id]['label'] = $tab['label'];
185
+				}
181 186
 
182 187
 				// Has a custom URL defined in the main admin structure?
183
-				if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
184
-					$tab_context['tabs'][$id]['url'] = $tab['url'];
188
+				if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url'])) {
189
+									$tab_context['tabs'][$id]['url'] = $tab['url'];
190
+				}
185 191
 
186 192
 				// Any additional paramaters for the url?
187
-				if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
188
-					$tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
193
+				if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params'])) {
194
+									$tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
195
+				}
189 196
 
190 197
 				// Has it been deemed selected?
191
-				if (!empty($tab['is_selected']))
192
-					$tab_context['tabs'][$id]['is_selected'] = true;
198
+				if (!empty($tab['is_selected'])) {
199
+									$tab_context['tabs'][$id]['is_selected'] = true;
200
+				}
193 201
 
194 202
 				// Does it have its own help?
195
-				if (!empty($tab['help']))
196
-					$tab_context['tabs'][$id]['help'] = $tab['help'];
203
+				if (!empty($tab['help'])) {
204
+									$tab_context['tabs'][$id]['help'] = $tab['help'];
205
+				}
197 206
 
198 207
 				// Is this the last one?
199
-				if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
200
-					$tab_context['tabs'][$id]['is_last'] = true;
208
+				if (!empty($tab['is_last']) && !isset($tab_context['override_last'])) {
209
+									$tab_context['tabs'][$id]['is_last'] = true;
210
+				}
201 211
 			}
202 212
 
203 213
 			// Find the selected tab
@@ -214,17 +224,18 @@  discard block
 block discarded – undo
214 224
 		// Show an icon and/or a help item?
215 225
 		if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']) || !empty($selected_tab['icon']) || !empty($tab_context['icon']) || !empty($selected_tab['help']) || !empty($tab_context['help']))
216 226
 		{
217
-			if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class']))
218
-				echo '<span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>';
219
-			elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
220
-				echo '<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">';
227
+			if (!empty($selected_tab['icon_class']) || !empty($tab_context['icon_class'])) {
228
+							echo '<span class="', !empty($selected_tab['icon_class']) ? $selected_tab['icon_class'] : $tab_context['icon_class'], ' icon"></span>';
229
+			} elseif (!empty($selected_tab['icon']) || !empty($tab_context['icon'])) {
230
+							echo '<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon">';
231
+			}
221 232
 
222
-			if (!empty($selected_tab['help']) || !empty($tab_context['help']))
223
-				echo '<a href="', $scripturl, '?action=helpadmin;help=', !empty($selected_tab['help']) ? $selected_tab['help'] : $tab_context['help'], '" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a>';
233
+			if (!empty($selected_tab['help']) || !empty($tab_context['help'])) {
234
+							echo '<a href="', $scripturl, '?action=helpadmin;help=', !empty($selected_tab['help']) ? $selected_tab['help'] : $tab_context['help'], '" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a>';
235
+			}
224 236
 
225 237
 			echo $tab_context['title'];
226
-		}
227
-		else
238
+		} else
228 239
 		{
229 240
 			echo '
230 241
 							', $tab_context['title'];
@@ -237,11 +248,12 @@  discard block
 block discarded – undo
237 248
 	}
238 249
 
239 250
 	// Shall we use the tabs? Yes, it's the only known way!
240
-	if (!empty($selected_tab['description']) || !empty($tab_context['description']))
241
-		echo '
251
+	if (!empty($selected_tab['description']) || !empty($tab_context['description'])) {
252
+			echo '
242 253
 					<p class="information">
243 254
 						', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
244 255
 					</p>';
256
+	}
245 257
 
246 258
 	// Print out all the items in this tab (if any).
247 259
 	if (!empty($context['tabs']))
@@ -253,8 +265,9 @@  discard block
 block discarded – undo
253 265
 
254 266
 		foreach ($tab_context['tabs'] as $sa => $tab)
255 267
 		{
256
-			if (!empty($tab['disabled']))
257
-				continue;
268
+			if (!empty($tab['disabled'])) {
269
+							continue;
270
+			}
258 271
 
259 272
 			if (!empty($tab['is_selected']))
260 273
 			{
@@ -262,12 +275,12 @@  discard block
 block discarded – undo
262 275
 							<li>
263 276
 								<a class="active" href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">', $tab['label'], '</a>
264 277
 							</li>';
265
-			}
266
-			else
267
-				echo '
278
+			} else {
279
+							echo '
268 280
 							<li>
269 281
 								<a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">', $tab['label'], '</a>
270 282
 							</li>';
283
+			}
271 284
 		}
272 285
 
273 286
 		// the end of tabs
Please login to merge, or discard this patch.
Sources/Subs-Db-mysqli.php 1 patch
Braces   +246 added lines, -180 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,56 +222,63 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
272
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
273
+			} else {
274
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+			}
254 276
 		break;
255 277
 
256 278
 		case 'float':
257
-			if (!is_numeric($replacement))
258
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if (!is_numeric($replacement)) {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
259 282
 			return (string) (float) $replacement;
260 283
 		break;
261 284
 
@@ -269,32 +292,37 @@  discard block
 block discarded – undo
269 292
 		break;
270 293
 
271 294
 		case 'inet':
272
-			if ($replacement == 'null' || $replacement == '')
273
-				return 'null';
274
-			if (!isValidIP($replacement))
275
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if ($replacement == 'null' || $replacement == '') {
296
+							return 'null';
297
+			}
298
+			if (!isValidIP($replacement)) {
299
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			}
276 301
 			//we don't use the native support of mysql > 5.6.2
277 302
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
278 303
 
279 304
 		case 'array_inet':
280 305
 			if (is_array($replacement))
281 306
 			{
282
-				if (empty($replacement))
283
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+				if (empty($replacement)) {
308
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+				}
284 310
 
285 311
 				foreach ($replacement as $key => $value)
286 312
 				{
287
-					if ($replacement == 'null' || $replacement == '')
288
-						$replacement[$key] = 'null';
289
-					if (!isValidIP($value))
290
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+					if ($replacement == 'null' || $replacement == '') {
314
+											$replacement[$key] = 'null';
315
+					}
316
+					if (!isValidIP($value)) {
317
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					}
291 319
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
292 320
 				}
293 321
 
294 322
 				return implode(', ', $replacement);
323
+			} else {
324
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295 325
 			}
296
-			else
297
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298 326
 		break;
299 327
 
300 328
 		default:
@@ -370,22 +398,25 @@  discard block
 block discarded – undo
370 398
 		// Are we in SSI mode?  If so try that username and password first
371 399
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
372 400
 		{
373
-			if (empty($db_persist))
374
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
375
-			else
376
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
401
+			if (empty($db_persist)) {
402
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
403
+			} else {
404
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
405
+			}
377 406
 		}
378 407
 		// Fall back to the regular username and password if need be
379 408
 		if (!$db_connection)
380 409
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
414
+			}
385 415
 		}
386 416
 
387
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
388
-			$db_connection = false;
417
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
418
+					$db_connection = false;
419
+		}
389 420
 
390 421
 		$connection = $db_connection;
391 422
 	}
@@ -393,18 +424,20 @@  discard block
 block discarded – undo
393 424
 	// One more query....
394 425
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
395 426
 
396
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
397
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
427
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
428
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
429
+	}
398 430
 
399 431
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
400 432
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
401 433
 	{
402 434
 		// Add before LIMIT
403
-		if ($pos = strpos($db_string, 'LIMIT '))
404
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
405
-		else
406
-			// Append it.
435
+		if ($pos = strpos($db_string, 'LIMIT ')) {
436
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
437
+		} else {
438
+					// Append it.
407 439
 			$db_string .= "\n\t\t\tORDER BY null";
440
+		}
408 441
 	}
409 442
 
410 443
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -426,8 +459,9 @@  discard block
 block discarded – undo
426 459
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
427 460
 
428 461
 		// Initialize $db_cache if not already initialized.
429
-		if (!isset($db_cache))
430
-			$db_cache = array();
462
+		if (!isset($db_cache)) {
463
+					$db_cache = array();
464
+		}
431 465
 
432 466
 		if (!empty($_SESSION['debug_redirect']))
433 467
 		{
@@ -453,17 +487,18 @@  discard block
 block discarded – undo
453 487
 		while (true)
454 488
 		{
455 489
 			$pos = strpos($db_string, '\'', $pos + 1);
456
-			if ($pos === false)
457
-				break;
490
+			if ($pos === false) {
491
+							break;
492
+			}
458 493
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
459 494
 
460 495
 			while (true)
461 496
 			{
462 497
 				$pos1 = strpos($db_string, '\'', $pos + 1);
463 498
 				$pos2 = strpos($db_string, '\\', $pos + 1);
464
-				if ($pos1 === false)
465
-					break;
466
-				elseif ($pos2 === false || $pos2 > $pos1)
499
+				if ($pos1 === false) {
500
+									break;
501
+				} elseif ($pos2 === false || $pos2 > $pos1)
467 502
 				{
468 503
 					$pos = $pos1;
469 504
 					break;
@@ -479,29 +514,35 @@  discard block
 block discarded – undo
479 514
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
480 515
 
481 516
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
482
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
483
-			$fail = true;
517
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
518
+					$fail = true;
519
+		}
484 520
 		// Trying to change passwords, slow us down, or something?
485
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
486
-			$fail = true;
487
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
488
-			$fail = true;
521
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
522
+					$fail = true;
523
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
524
+					$fail = true;
525
+		}
489 526
 
490
-		if (!empty($fail) && function_exists('log_error'))
491
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
527
+		if (!empty($fail) && function_exists('log_error')) {
528
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
529
+		}
492 530
 	}
493 531
 
494
-	if (empty($db_unbuffered))
495
-		$ret = @mysqli_query($connection, $db_string);
496
-	else
497
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
532
+	if (empty($db_unbuffered)) {
533
+			$ret = @mysqli_query($connection, $db_string);
534
+	} else {
535
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
536
+	}
498 537
 
499
-	if ($ret === false && empty($db_values['db_error_skip']))
500
-		$ret = smf_db_error($db_string, $connection);
538
+	if ($ret === false && empty($db_values['db_error_skip'])) {
539
+			$ret = smf_db_error($db_string, $connection);
540
+	}
501 541
 
502 542
 	// Debugging.
503
-	if (isset($db_show_debug) && $db_show_debug === true)
504
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
543
+	if (isset($db_show_debug) && $db_show_debug === true) {
544
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
545
+	}
505 546
 
506 547
 	return $ret;
507 548
 }
@@ -550,12 +591,13 @@  discard block
 block discarded – undo
550 591
 	// Decide which connection to use
551 592
 	$connection = $connection === null ? $db_connection : $connection;
552 593
 
553
-	if ($type == 'begin')
554
-		return @mysqli_query($connection, 'BEGIN');
555
-	elseif ($type == 'rollback')
556
-		return @mysqli_query($connection, 'ROLLBACK');
557
-	elseif ($type == 'commit')
558
-		return @mysqli_query($connection, 'COMMIT');
594
+	if ($type == 'begin') {
595
+			return @mysqli_query($connection, 'BEGIN');
596
+	} elseif ($type == 'rollback') {
597
+			return @mysqli_query($connection, 'ROLLBACK');
598
+	} elseif ($type == 'commit') {
599
+			return @mysqli_query($connection, 'COMMIT');
600
+	}
559 601
 
560 602
 	return false;
561 603
 }
@@ -595,8 +637,9 @@  discard block
 block discarded – undo
595 637
 	//    2013: Lost connection to server during query.
596 638
 
597 639
 	// Log the error.
598
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
599
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
640
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
641
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
642
+	}
600 643
 
601 644
 	// Database error auto fixing ;).
602 645
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -605,8 +648,9 @@  discard block
 block discarded – undo
605 648
 		$old_cache = @$modSettings['cache_enable'];
606 649
 		$modSettings['cache_enable'] = '1';
607 650
 
608
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
609
-			$db_last_error = max(@$db_last_error, $temp);
651
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
652
+					$db_last_error = max(@$db_last_error, $temp);
653
+		}
610 654
 
611 655
 		if (@$db_last_error < time() - 3600 * 24 * 3)
612 656
 		{
@@ -622,8 +666,9 @@  discard block
 block discarded – undo
622 666
 					foreach ($tables as $table)
623 667
 					{
624 668
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
625
-						if (trim($table) != '')
626
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
669
+						if (trim($table) != '') {
670
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
671
+						}
627 672
 					}
628 673
 				}
629 674
 
@@ -632,8 +677,9 @@  discard block
 block discarded – undo
632 677
 			// Table crashed.  Let's try to fix it.
633 678
 			elseif ($query_errno == 1016)
634 679
 			{
635
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
636
-					$fix_tables = array('`' . $match[1] . '`');
680
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
681
+									$fix_tables = array('`' . $match[1] . '`');
682
+				}
637 683
 			}
638 684
 			// Indexes crashed.  Should be easy to fix!
639 685
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -652,13 +698,15 @@  discard block
 block discarded – undo
652 698
 
653 699
 			// Make a note of the REPAIR...
654 700
 			cache_put_data('db_last_error', time(), 600);
655
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
656
-				updateSettingsFile(array('db_last_error' => time()));
701
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
702
+							updateSettingsFile(array('db_last_error' => time()));
703
+			}
657 704
 
658 705
 			// Attempt to find and repair the broken table.
659
-			foreach ($fix_tables as $table)
660
-				$smcFunc['db_query']('', "
706
+			foreach ($fix_tables as $table) {
707
+							$smcFunc['db_query']('', "
661 708
 					REPAIR TABLE $table", false, false);
709
+			}
662 710
 
663 711
 			// And send off an email!
664 712
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -667,11 +715,12 @@  discard block
 block discarded – undo
667 715
 
668 716
 			// Try the query again...?
669 717
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
670
-			if ($ret !== false)
671
-				return $ret;
718
+			if ($ret !== false) {
719
+							return $ret;
720
+			}
721
+		} else {
722
+					$modSettings['cache_enable'] = $old_cache;
672 723
 		}
673
-		else
674
-			$modSettings['cache_enable'] = $old_cache;
675 724
 
676 725
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
677 726
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -681,22 +730,25 @@  discard block
 block discarded – undo
681 730
 				// Are we in SSI mode?  If so try that username and password first
682 731
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
683 732
 				{
684
-					if (empty($db_persist))
685
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
686
-					else
687
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
733
+					if (empty($db_persist)) {
734
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
735
+					} else {
736
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
737
+					}
688 738
 				}
689 739
 				// Fall back to the regular username and password if need be
690 740
 				if (!$db_connection)
691 741
 				{
692
-					if (empty($db_persist))
693
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
694
-					else
695
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
742
+					if (empty($db_persist)) {
743
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
744
+					} else {
745
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
746
+					}
696 747
 				}
697 748
 
698
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
699
-					$db_connection = false;
749
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
750
+									$db_connection = false;
751
+				}
700 752
 			}
701 753
 
702 754
 			if ($db_connection)
@@ -707,24 +759,27 @@  discard block
 block discarded – undo
707 759
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
708 760
 
709 761
 					$new_errno = mysqli_errno($db_connection);
710
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
711
-						break;
762
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
763
+											break;
764
+					}
712 765
 				}
713 766
 
714 767
 				// If it failed again, shucks to be you... we're not trying it over and over.
715
-				if ($ret !== false)
716
-					return $ret;
768
+				if ($ret !== false) {
769
+									return $ret;
770
+				}
717 771
 			}
718 772
 		}
719 773
 		// Are they out of space, perhaps?
720 774
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
721 775
 		{
722
-			if (!isset($txt))
723
-				$query_error .= ' - check database storage space.';
724
-			else
776
+			if (!isset($txt)) {
777
+							$query_error .= ' - check database storage space.';
778
+			} else
725 779
 			{
726
-				if (!isset($txt['mysql_error_space']))
727
-					loadLanguage('Errors');
780
+				if (!isset($txt['mysql_error_space'])) {
781
+									loadLanguage('Errors');
782
+				}
728 783
 
729 784
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
730 785
 			}
@@ -732,15 +787,17 @@  discard block
 block discarded – undo
732 787
 	}
733 788
 
734 789
 	// Nothing's defined yet... just die with it.
735
-	if (empty($context) || empty($txt))
736
-		die($query_error);
790
+	if (empty($context) || empty($txt)) {
791
+			die($query_error);
792
+	}
737 793
 
738 794
 	// Show an error message, if possible.
739 795
 	$context['error_title'] = $txt['database_error'];
740
-	if (allowedTo('admin_forum'))
741
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
742
-	else
743
-		$context['error_message'] = $txt['try_again'];
796
+	if (allowedTo('admin_forum')) {
797
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
798
+	} else {
799
+			$context['error_message'] = $txt['try_again'];
800
+	}
744 801
 
745 802
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
746 803
 	{
@@ -769,25 +826,28 @@  discard block
 block discarded – undo
769 826
 	$connection = $connection === null ? $db_connection : $connection;
770 827
 
771 828
 	// With nothing to insert, simply return.
772
-	if (empty($data))
773
-		return;
829
+	if (empty($data)) {
830
+			return;
831
+	}
774 832
 
775 833
 	// Replace the prefix holder with the actual prefix.
776 834
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
777 835
 
778 836
 	// Inserting data as a single row can be done as a single array.
779
-	if (!is_array($data[array_rand($data)]))
780
-		$data = array($data);
837
+	if (!is_array($data[array_rand($data)])) {
838
+			$data = array($data);
839
+	}
781 840
 
782 841
 	// Create the mold for a single row insert.
783 842
 	$insertData = '(';
784 843
 	foreach ($columns as $columnName => $type)
785 844
 	{
786 845
 		// Are we restricting the length?
787
-		if (strpos($type, 'string-') !== false)
788
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
789
-		else
790
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
846
+		if (strpos($type, 'string-') !== false) {
847
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
848
+		} else {
849
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+		}
791 851
 	}
792 852
 	$insertData = substr($insertData, 0, -2) . ')';
793 853
 
@@ -796,8 +856,9 @@  discard block
 block discarded – undo
796 856
 
797 857
 	// Here's where the variables are injected to the query.
798 858
 	$insertRows = array();
799
-	foreach ($data as $dataRow)
800
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
859
+	foreach ($data as $dataRow) {
860
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
861
+	}
801 862
 
802 863
 	// Determine the method of insertion.
803 864
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -828,8 +889,9 @@  discard block
 block discarded – undo
828 889
  */
829 890
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
830 891
 {
831
-	if (empty($log_message))
832
-		$log_message = $error_message;
892
+	if (empty($log_message)) {
893
+			$log_message = $error_message;
894
+	}
833 895
 
834 896
 	foreach (debug_backtrace() as $step)
835 897
 	{
@@ -848,12 +910,14 @@  discard block
 block discarded – undo
848 910
 	}
849 911
 
850 912
 	// A special case - we want the file and line numbers for debugging.
851
-	if ($error_type == 'return')
852
-		return array($file, $line);
913
+	if ($error_type == 'return') {
914
+			return array($file, $line);
915
+	}
853 916
 
854 917
 	// Is always a critical error.
855
-	if (function_exists('log_error'))
856
-		log_error($log_message, 'critical', $file, $line);
918
+	if (function_exists('log_error')) {
919
+			log_error($log_message, 'critical', $file, $line);
920
+	}
857 921
 
858 922
 	if (function_exists('fatal_error'))
859 923
 	{
@@ -861,12 +925,12 @@  discard block
 block discarded – undo
861 925
 
862 926
 		// Cannot continue...
863 927
 		exit;
928
+	} elseif ($error_type) {
929
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
930
+	} else {
931
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
932
+	}
864 933
 	}
865
-	elseif ($error_type)
866
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
867
-	else
868
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
869
-}
870 934
 
871 935
 /**
872 936
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -883,10 +947,11 @@  discard block
 block discarded – undo
883 947
 		'\\' => '\\\\',
884 948
 	);
885 949
 
886
-	if ($translate_human_wildcards)
887
-		$replacements += array(
950
+	if ($translate_human_wildcards) {
951
+			$replacements += array(
888 952
 			'*' => '%',
889 953
 		);
954
+	}
890 955
 
891 956
 	return strtr($string, $replacements);
892 957
 }
@@ -900,8 +965,9 @@  discard block
 block discarded – undo
900 965
  */
901 966
 function smf_is_resource($result)
902 967
 {
903
-	if ($result instanceof mysqli_result)
904
-		return true;
968
+	if ($result instanceof mysqli_result) {
969
+			return true;
970
+	}
905 971
 
906 972
 	return false;
907 973
 }
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 1 patch
Braces   +63 added lines, -54 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
  * Shows an avatar based on $_GET['attach']
@@ -35,11 +36,11 @@  discard block
 block discarded – undo
35 36
 
36 37
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
37 38
 	{
38
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
39
-			$modSettings['enableCompressedOutput'] = 0;
40
-
41
-		else
42
-			ob_start('ob_gzhandler');
39
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
40
+					$modSettings['enableCompressedOutput'] = 0;
41
+		} else {
42
+					ob_start('ob_gzhandler');
43
+		}
43 44
 	}
44 45
 
45 46
 	if (empty($modSettings['enableCompressedOutput']))
@@ -71,8 +72,9 @@  discard block
 block discarded – undo
71 72
 	}
72 73
 
73 74
 	// Use cache when possible.
74
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
75
-		list($file, $thumbFile) = $cache;
75
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
76
+			list($file, $thumbFile) = $cache;
77
+	}
76 78
 
77 79
 	// Get the info from the DB.
78 80
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -80,10 +82,9 @@  discard block
 block discarded – undo
80 82
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
81 83
 		$attachRequest = null;
82 84
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
83
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
84
-			$request = $attachRequest;
85
-
86
-		else
85
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
86
+					$request = $attachRequest;
87
+		} else
87 88
 		{
88 89
 			// Make sure this attachment is on this board and load its info while we are at it.
89 90
 			$request = $smcFunc['db_query']('', '
@@ -176,13 +177,14 @@  discard block
 block discarded – undo
176 177
 		}
177 178
 
178 179
 		// Cache it.
179
-		if (!empty($file) || !empty($thumbFile))
180
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
180
+		if (!empty($file) || !empty($thumbFile)) {
181
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
182
+		}
181 183
 	}
182 184
 
183 185
 	// Update the download counter (unless it's a thumbnail).
184
-	if ($file['attachment_type'] != 3 && empty($showThumb))
185
-		$smcFunc['db_query']('attach_download_increase', '
186
+	if ($file['attachment_type'] != 3 && empty($showThumb)) {
187
+			$smcFunc['db_query']('attach_download_increase', '
186 188
 			UPDATE LOW_PRIORITY {db_prefix}attachments
187 189
 			SET downloads = downloads + 1
188 190
 			WHERE id_attach = {int:id_attach}',
@@ -190,10 +192,12 @@  discard block
 block discarded – undo
190 192
 				'id_attach' => $attachId,
191 193
 			)
192 194
 		);
195
+	}
193 196
 
194 197
 	// Replace the normal file with its thumbnail if it has one!
195
-	if (!empty($showThumb) && !empty($thumbFile))
196
-		$file = $thumbFile;
198
+	if (!empty($showThumb) && !empty($thumbFile)) {
199
+			$file = $thumbFile;
200
+	}
197 201
 
198 202
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
199 203
 	if (!file_exists($file['filePath']))
@@ -232,8 +236,9 @@  discard block
 block discarded – undo
232 236
 	// Send the attachment headers.
233 237
 	header('Pragma: ');
234 238
 
235
-	if (!isBrowser('gecko'))
236
-		header('Content-Transfer-Encoding: binary');
239
+	if (!isBrowser('gecko')) {
240
+			header('Content-Transfer-Encoding: binary');
241
+	}
237 242
 
238 243
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
239 244
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -242,18 +247,19 @@  discard block
 block discarded – undo
242 247
 	header('ETag: ' . $eTag);
243 248
 
244 249
 	// Make sure the mime type warrants an inline display.
245
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
246
-		unset($_REQUEST['image']);
250
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
251
+			unset($_REQUEST['image']);
252
+	}
247 253
 
248 254
 	// Does this have a mime type?
249
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
250
-		header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
251
-
252
-	else
255
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
256
+			header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
257
+	} else
253 258
 	{
254 259
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
255
-		if (isset($_REQUEST['image']))
256
-			unset($_REQUEST['image']);
260
+		if (isset($_REQUEST['image'])) {
261
+					unset($_REQUEST['image']);
262
+		}
257 263
 	}
258 264
 
259 265
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -261,24 +267,22 @@  discard block
 block discarded – undo
261 267
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
262 268
 
263 269
 	// Different browsers like different standards...
264
-	if (isBrowser('firefox'))
265
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
266
-
267
-	elseif (isBrowser('opera'))
268
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
269
-
270
-	elseif (isBrowser('ie'))
271
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
272
-
273
-	else
274
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
270
+	if (isBrowser('firefox')) {
271
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
272
+	} elseif (isBrowser('opera')) {
273
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
274
+	} elseif (isBrowser('ie')) {
275
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
276
+	} else {
277
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
278
+	}
275 279
 
276 280
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
277
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
278
-		header('Cache-Control: no-cache');
279
-
280
-	else
281
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
281
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
282
+			header('Cache-Control: no-cache');
283
+	} else {
284
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
285
+	}
282 286
 
283 287
 	header('Content-Length: ' . filesize($file['filePath']));
284 288
 
@@ -288,20 +292,23 @@  discard block
 block discarded – undo
288 292
 	// Recode line endings for text files, if enabled.
289 293
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file['fileext'], array('txt', 'css', 'htm', 'html', 'php', 'xml')))
290 294
 	{
291
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
292
-			$callback = function($buffer)
295
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
296
+					$callback = function($buffer)
293 297
 			{
294 298
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
299
+		}
295 300
 			};
296
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
297
-			$callback = function($buffer)
301
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
302
+					$callback = function($buffer)
298 303
 			{
299 304
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
305
+		}
300 306
 			};
301
-		else
302
-			$callback = function($buffer)
307
+		else {
308
+					$callback = function($buffer)
303 309
 			{
304 310
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
311
+		}
305 312
 			};
306 313
 	}
307 314
 
@@ -309,8 +316,9 @@  discard block
 block discarded – undo
309 316
 	if (filesize($file['filePath']) > 4194304)
310 317
 	{
311 318
 		// Forcibly end any output buffering going on.
312
-		while (@ob_get_level() > 0)
313
-			@ob_end_clean();
319
+		while (@ob_get_level() > 0) {
320
+					@ob_end_clean();
321
+		}
314 322
 
315 323
 		$fp = fopen($file['filePath'], 'rb');
316 324
 		while (!feof($fp))
@@ -322,8 +330,9 @@  discard block
 block discarded – undo
322 330
 	}
323 331
 
324 332
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
325
-	elseif (@readfile($file['filePath']) === null)
326
-		echo file_get_contents($file['filePath']);
333
+	elseif (@readfile($file['filePath']) === null) {
334
+			echo file_get_contents($file['filePath']);
335
+	}
327 336
 
328 337
 	die();
329 338
 }
Please login to merge, or discard this patch.
Sources/Groups.php 1 patch
Braces   +80 added lines, -59 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
  * Entry point function, permission checks, admin bars, etc.
@@ -99,27 +100,27 @@  discard block
 block discarded – undo
99 100
 					'function' => function($rowData) use ($scripturl)
100 101
 					{
101 102
 						// Since the moderator group has no explicit members, no link is needed.
102
-						if ($rowData['id_group'] == 3)
103
-							$group_name = $rowData['group_name'];
104
-						else
103
+						if ($rowData['id_group'] == 3) {
104
+													$group_name = $rowData['group_name'];
105
+						} else
105 106
 						{
106 107
 							$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']);
107 108
 
108 109
 							if (allowedTo('manage_membergroups'))
109 110
 							{
110 111
 								$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
111
-							}
112
-							else
112
+							} else
113 113
 							{
114 114
 								$group_name = sprintf('<a href="%1$s?action=groups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']);
115 115
 							}
116 116
 						}
117 117
 
118 118
 						// Add a help option for moderator and administrator.
119
-						if ($rowData['id_group'] == 1)
120
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
121
-						elseif ($rowData['id_group'] == 3)
122
-							$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
119
+						if ($rowData['id_group'] == 1) {
120
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
121
+						} elseif ($rowData['id_group'] == 3) {
122
+													$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl);
123
+						}
123 124
 
124 125
 						return $group_name;
125 126
 					},
@@ -198,8 +199,9 @@  discard block
 block discarded – undo
198 199
 	$_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0;
199 200
 
200 201
 	// No browsing of guests, membergroup 0 or moderators.
201
-	if (in_array($_REQUEST['group'], array(-1, 0, 3)))
202
-		fatal_lang_error('membergroup_does_not_exist', false);
202
+	if (in_array($_REQUEST['group'], array(-1, 0, 3))) {
203
+			fatal_lang_error('membergroup_does_not_exist', false);
204
+	}
203 205
 
204 206
 	// Load up the group details.
205 207
 	$request = $smcFunc['db_query']('', '
@@ -214,8 +216,9 @@  discard block
 block discarded – undo
214 216
 		)
215 217
 	);
216 218
 	// Doesn't exist?
217
-	if ($smcFunc['db_num_rows']($request) == 0)
218
-		fatal_lang_error('membergroup_does_not_exist', false);
219
+	if ($smcFunc['db_num_rows']($request) == 0) {
220
+			fatal_lang_error('membergroup_does_not_exist', false);
221
+	}
219 222
 	$context['group'] = $smcFunc['db_fetch_assoc']($request);
220 223
 	$smcFunc['db_free_result']($request);
221 224
 
@@ -248,21 +251,25 @@  discard block
 block discarded – undo
248 251
 			'name' => $row['real_name']
249 252
 		);
250 253
 
251
-		if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1)
252
-			$context['group']['can_moderate'] = true;
254
+		if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) {
255
+					$context['group']['can_moderate'] = true;
256
+		}
253 257
 	}
254 258
 	$smcFunc['db_free_result']($request);
255 259
 
256 260
 	// If this group is hidden then it can only "exists" if the user can moderate it!
257
-	if ($context['group']['hidden'] && !$context['group']['can_moderate'])
258
-		fatal_lang_error('membergroup_does_not_exist', false);
261
+	if ($context['group']['hidden'] && !$context['group']['can_moderate']) {
262
+			fatal_lang_error('membergroup_does_not_exist', false);
263
+	}
259 264
 
260 265
 	// You can only assign membership if you are the moderator and/or can manage groups!
261
-	if (!$context['group']['can_moderate'])
262
-		$context['group']['assignable'] = 0;
266
+	if (!$context['group']['can_moderate']) {
267
+			$context['group']['assignable'] = 0;
268
+	}
263 269
 	// Non-admins cannot assign admins.
264
-	elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum'))
265
-		$context['group']['assignable'] = 0;
270
+	elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) {
271
+			$context['group']['assignable'] = 0;
272
+	}
266 273
 
267 274
 	// Removing member from group?
268 275
 	if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $context['group']['assignable'])
@@ -271,8 +278,9 @@  discard block
 block discarded – undo
271 278
 		validateToken('mod-mgm');
272 279
 
273 280
 		// Make sure we're dealing with integers only.
274
-		foreach ($_REQUEST['rem'] as $key => $group)
275
-			$_REQUEST['rem'][$key] = (int) $group;
281
+		foreach ($_REQUEST['rem'] as $key => $group) {
282
+					$_REQUEST['rem'][$key] = (int) $group;
283
+		}
276 284
 
277 285
 		require_once($sourcedir . '/Subs-Membergroups.php');
278 286
 		removeMembersFromGroups($_REQUEST['rem'], $_REQUEST['group'], true);
@@ -295,16 +303,18 @@  discard block
 block discarded – undo
295 303
 		{
296 304
 			$member_names[$index] = trim($smcFunc['strtolower']($member_names[$index]));
297 305
 
298
-			if (strlen($member_names[$index]) == 0)
299
-				unset($member_names[$index]);
306
+			if (strlen($member_names[$index]) == 0) {
307
+							unset($member_names[$index]);
308
+			}
300 309
 		}
301 310
 
302 311
 		// Any passed by ID?
303 312
 		$member_ids = array();
304
-		if (!empty($_REQUEST['member_add']))
305
-			foreach ($_REQUEST['member_add'] as $id)
313
+		if (!empty($_REQUEST['member_add'])) {
314
+					foreach ($_REQUEST['member_add'] as $id)
306 315
 				if ($id > 0)
307 316
 					$member_ids[] = (int) $id;
317
+		}
308 318
 
309 319
 		// Construct the query pelements.
310 320
 		if (!empty($member_ids))
@@ -332,8 +342,9 @@  discard block
 block discarded – undo
332 342
 					'id_group' => $_REQUEST['group'],
333 343
 				))
334 344
 			);
335
-			while ($row = $smcFunc['db_fetch_assoc']($request))
336
-				$members[] = $row['id_member'];
345
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
346
+							$members[] = $row['id_member'];
347
+			}
337 348
 			$smcFunc['db_free_result']($request);
338 349
 		}
339 350
 
@@ -372,10 +383,11 @@  discard block
 block discarded – undo
372 383
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
373 384
 
374 385
 	// The where on the query is interesting. Non-moderators should only see people who are in this group as primary.
375
-	if ($context['group']['can_moderate'])
376
-		$where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0';
377
-	else
378
-		$where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}';
386
+	if ($context['group']['can_moderate']) {
387
+			$where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0';
388
+	} else {
389
+			$where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}';
390
+	}
379 391
 
380 392
 	// Count members of the group.
381 393
 	$request = $smcFunc['db_query']('', '
@@ -416,8 +428,9 @@  discard block
 block discarded – undo
416 428
 		$last_online = empty($row['last_login']) ? $txt['never'] : timeformat($row['last_login']);
417 429
 
418 430
 		// Italicize the online note if they aren't activated.
419
-		if ($row['is_activated'] % 10 != 1)
420
-			$last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>';
431
+		if ($row['is_activated'] % 10 != 1) {
432
+					$last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>';
433
+		}
421 434
 
422 435
 		$context['members'][] = array(
423 436
 			'id' => $row['id_member'],
@@ -437,9 +450,10 @@  discard block
 block discarded – undo
437 450
 	$context['page_title'] = $txt['membergroups_members_title'] . ': ' . $context['group']['name'];
438 451
 	createToken('mod-mgm');
439 452
 
440
-	if ($context['group']['assignable'])
441
-		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
442
-}
453
+	if ($context['group']['assignable']) {
454
+			loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
455
+	}
456
+	}
443 457
 
444 458
 /**
445 459
  * Show and manage all group requests.
@@ -453,16 +467,18 @@  discard block
 block discarded – undo
453 467
 	$context['sub_template'] = 'show_list';
454 468
 
455 469
 	// Verify we can be here.
456
-	if ($user_info['mod_cache']['gq'] == '0=1')
457
-		isAllowedTo('manage_membergroups');
470
+	if ($user_info['mod_cache']['gq'] == '0=1') {
471
+			isAllowedTo('manage_membergroups');
472
+	}
458 473
 
459 474
 	// Normally, we act normally...
460 475
 	$where = ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']);
461 476
 
462
-	if (isset($_GET['closed']))
463
-		$where .= ' AND lgr.status != {int:status_open}';
464
-	else
465
-		$where .= ' AND lgr.status = {int:status_open}';
477
+	if (isset($_GET['closed'])) {
478
+			$where .= ' AND lgr.status != {int:status_open}';
479
+	} else {
480
+			$where .= ' AND lgr.status = {int:status_open}';
481
+	}
466 482
 
467 483
 	$where_parameters = array(
468 484
 		'status_open' => 0,
@@ -475,8 +491,9 @@  discard block
 block discarded – undo
475 491
 		validateToken('mod-gr');
476 492
 
477 493
 		// Clean the values.
478
-		foreach ($_POST['groupr'] as $k => $request)
479
-			$_POST['groupr'][$k] = (int) $request;
494
+		foreach ($_POST['groupr'] as $k => $request) {
495
+					$_POST['groupr'][$k] = (int) $request;
496
+		}
480 497
 
481 498
 		$log_changes = array();
482 499
 
@@ -513,8 +530,8 @@  discard block
 block discarded – undo
513 530
 			$request_list = array();
514 531
 			while ($row = $smcFunc['db_fetch_assoc']($request))
515 532
 			{
516
-				if (!isset($log_changes[$row['id_request']]))
517
-					$log_changes[$row['id_request']] = array(
533
+				if (!isset($log_changes[$row['id_request']])) {
534
+									$log_changes[$row['id_request']] = array(
518 535
 						'id_request' => $row['id_request'],
519 536
 						'status' => $_POST['req_action'] == 'approve' ? 1 : 2, // 1 = approved, 2 = rejected
520 537
 						'id_member_acted' => $user_info['id'],
@@ -522,6 +539,7 @@  discard block
 block discarded – undo
522 539
 						'time_acted' => time(),
523 540
 						'act_reason' => $_POST['req_action'] != 'approve' && !empty($_POST['groupreason']) && !empty($_POST['groupreason'][$row['id_request']]) ? $smcFunc['htmlspecialchars']($_POST['groupreason'][$row['id_request']], ENT_QUOTES) : '',
524 541
 					);
542
+				}
525 543
 				$request_list[] = $row['id_request'];
526 544
 			}
527 545
 			$smcFunc['db_free_result']($request);
@@ -744,21 +762,24 @@  discard block
 block discarded – undo
744 762
 	$group_requests = array();
745 763
 	while ($row = $smcFunc['db_fetch_assoc']($request))
746 764
 	{
747
-		if (empty($row['reason']))
748
-			$reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>';
749
-		else
750
-			$reason = censorText($row['reason']);
765
+		if (empty($row['reason'])) {
766
+					$reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>';
767
+		} else {
768
+					$reason = censorText($row['reason']);
769
+		}
751 770
 
752 771
 		if (isset($_GET['closed']))
753 772
 		{
754
-			if ($row['status'] == 1)
755
-				$reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>';
756
-			elseif ($row['status'] == 2)
757
-				$reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>';
773
+			if ($row['status'] == 1) {
774
+							$reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>';
775
+			} elseif ($row['status'] == 2) {
776
+							$reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>';
777
+			}
758 778
 
759 779
 				$reason .= ' (' . timeformat($row['time_acted']) . ')';
760
-			if (!empty($row['act_reason']))
761
-				$reason .= '<br><br>' . censorText($row['act_reason']);
780
+			if (!empty($row['act_reason'])) {
781
+							$reason .= '<br><br>' . censorText($row['act_reason']);
782
+			}
762 783
 		}
763 784
 
764 785
 		$group_requests[] = array(
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +664 added lines, -515 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	$context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']);
56 59
 
57 60
 	// You must be posting to *some* board.
58
-	if (empty($board) && !$context['make_event'])
59
-		fatal_lang_error('no_board', false);
61
+	if (empty($board) && !$context['make_event']) {
62
+			fatal_lang_error('no_board', false);
63
+	}
60 64
 
61 65
 	require_once($sourcedir . '/Subs-Post.php');
62 66
 
@@ -79,10 +83,11 @@  discard block
 block discarded – undo
79 83
 			array(
80 84
 				'msg' => (int) $_REQUEST['msg'],
81 85
 		));
82
-		if ($smcFunc['db_num_rows']($request) != 1)
83
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
84
-		else
85
-			list ($topic) = $smcFunc['db_fetch_row']($request);
86
+		if ($smcFunc['db_num_rows']($request) != 1) {
87
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
88
+		} else {
89
+					list ($topic) = $smcFunc['db_fetch_row']($request);
90
+		}
86 91
 		$smcFunc['db_free_result']($request);
87 92
 	}
88 93
 
@@ -109,33 +114,36 @@  discard block
 block discarded – undo
109 114
 		$smcFunc['db_free_result']($request);
110 115
 
111 116
 		// If this topic already has a poll, they sure can't add another.
112
-		if (isset($_REQUEST['poll']) && $pollID > 0)
113
-			unset($_REQUEST['poll']);
117
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
118
+					unset($_REQUEST['poll']);
119
+		}
114 120
 
115 121
 		if (empty($_REQUEST['msg']))
116 122
 		{
117
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
118
-				is_not_guest();
123
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
124
+							is_not_guest();
125
+			}
119 126
 
120 127
 			// By default the reply will be approved...
121 128
 			$context['becomes_approved'] = true;
122 129
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
123 130
 			{
124
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
125
-					$context['becomes_approved'] = false;
126
-				else
127
-					isAllowedTo('post_reply_any');
128
-			}
129
-			elseif (!allowedTo('post_reply_any'))
131
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
132
+									$context['becomes_approved'] = false;
133
+				} else {
134
+									isAllowedTo('post_reply_any');
135
+				}
136
+			} elseif (!allowedTo('post_reply_any'))
130 137
 			{
131
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
132
-					$context['becomes_approved'] = false;
133
-				else
134
-					isAllowedTo('post_reply_own');
138
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
139
+									$context['becomes_approved'] = false;
140
+				} else {
141
+									isAllowedTo('post_reply_own');
142
+				}
135 143
 			}
144
+		} else {
145
+					$context['becomes_approved'] = true;
136 146
 		}
137
-		else
138
-			$context['becomes_approved'] = true;
139 147
 
140 148
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
141 149
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -147,18 +155,19 @@  discard block
 block discarded – undo
147 155
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
148 156
 
149 157
 		// Check whether this is a really old post being bumped...
150
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
151
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
152
-	}
153
-	else
158
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
159
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
160
+		}
161
+	} else
154 162
 	{
155 163
 		$context['becomes_approved'] = true;
156 164
 		if ((!$context['make_event'] || !empty($board)))
157 165
 		{
158
-			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
159
-				$context['becomes_approved'] = false;
160
-			else
161
-				isAllowedTo('post_new');
166
+			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
167
+							$context['becomes_approved'] = false;
168
+			} else {
169
+							isAllowedTo('post_new');
170
+			}
162 171
 		}
163 172
 
164 173
 		$locked = 0;
@@ -196,20 +205,24 @@  discard block
 block discarded – undo
196 205
 	}
197 206
 
198 207
 	// Don't allow a post if it's locked and you aren't all powerful.
199
-	if ($locked && !allowedTo('moderate_board'))
200
-		fatal_lang_error('topic_locked', false);
208
+	if ($locked && !allowedTo('moderate_board')) {
209
+			fatal_lang_error('topic_locked', false);
210
+	}
201 211
 	// Check the users permissions - is the user allowed to add or post a poll?
202 212
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
203 213
 	{
204 214
 		// New topic, new poll.
205
-		if (empty($topic))
206
-			isAllowedTo('poll_post');
215
+		if (empty($topic)) {
216
+					isAllowedTo('poll_post');
217
+		}
207 218
 		// This is an old topic - but it is yours!  Can you add to it?
208
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
209
-			isAllowedTo('poll_add_own');
219
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
220
+					isAllowedTo('poll_add_own');
221
+		}
210 222
 		// If you're not the owner, can you add to any poll?
211
-		else
212
-			isAllowedTo('poll_add_any');
223
+		else {
224
+					isAllowedTo('poll_add_any');
225
+		}
213 226
 
214 227
 		require_once($sourcedir . '/Subs-Members.php');
215 228
 		$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
@@ -238,8 +251,9 @@  discard block
 block discarded – undo
238 251
 	if ($context['make_event'])
239 252
 	{
240 253
 		// They might want to pick a board.
241
-		if (!isset($context['current_board']))
242
-			$context['current_board'] = 0;
254
+		if (!isset($context['current_board'])) {
255
+					$context['current_board'] = 0;
256
+		}
243 257
 
244 258
 		// Start loading up the event info.
245 259
 		$context['event'] = array();
@@ -253,10 +267,11 @@  discard block
 block discarded – undo
253 267
 		isAllowedTo('calendar_post');
254 268
 
255 269
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
256
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
257
-			$time_string = '%k:%M';
258
-		else
259
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
270
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
271
+					$time_string = '%k:%M';
272
+		} else {
273
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
274
+		}
260 275
 
261 276
 		$js_time_string = str_replace(
262 277
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -278,8 +293,7 @@  discard block
 block discarded – undo
278 293
 			require_once($sourcedir . '/Subs-Calendar.php');
279 294
 			$eventProperties = getEventProperties($context['event']['id']);
280 295
 			$context['event'] = array_merge($context['event'], $eventProperties);
281
-		}
282
-		else
296
+		} else
283 297
 		{
284 298
 			// Get the current event information.
285 299
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -287,15 +301,18 @@  discard block
 block discarded – undo
287 301
 			$context['event'] = array_merge($context['event'], $eventProperties);
288 302
 
289 303
 			// Make sure the year and month are in the valid range.
290
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
291
-				fatal_lang_error('invalid_month', false);
292
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
293
-				fatal_lang_error('invalid_year', false);
304
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
305
+							fatal_lang_error('invalid_month', false);
306
+			}
307
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
308
+							fatal_lang_error('invalid_year', false);
309
+			}
294 310
 
295 311
 			// Get a list of boards they can post in.
296 312
 			$boards = boardsAllowedTo('post_new');
297
-			if (empty($boards))
298
-				fatal_lang_error('cannot_post_new', 'user');
313
+			if (empty($boards)) {
314
+							fatal_lang_error('cannot_post_new', 'user');
315
+			}
299 316
 
300 317
 			// Load a list of boards for this event in the context.
301 318
 			require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -414,10 +431,11 @@  discard block
 block discarded – undo
414 431
 
415 432
 			if (!empty($context['new_replies']))
416 433
 			{
417
-				if ($context['new_replies'] == 1)
418
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
419
-				else
420
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
434
+				if ($context['new_replies'] == 1) {
435
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
436
+				} else {
437
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
438
+				}
421 439
 
422 440
 				$post_errors[] = 'new_replies';
423 441
 
@@ -429,9 +447,9 @@  discard block
 block discarded – undo
429 447
 	// Get a response prefix (like 'Re:') in the default forum language.
430 448
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
431 449
 	{
432
-		if ($language === $user_info['language'])
433
-			$context['response_prefix'] = $txt['response_prefix'];
434
-		else
450
+		if ($language === $user_info['language']) {
451
+					$context['response_prefix'] = $txt['response_prefix'];
452
+		} else
435 453
 		{
436 454
 			loadLanguage('index', $language, false);
437 455
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -444,8 +462,9 @@  discard block
 block discarded – undo
444 462
 	// Do we have a body, but an error happened.
445 463
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
446 464
 	{
447
-		if (isset($_REQUEST['quickReply']))
448
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
465
+		if (isset($_REQUEST['quickReply'])) {
466
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
467
+		}
449 468
 
450 469
 		// Validate inputs.
451 470
 		if (empty($context['post_error']))
@@ -453,15 +472,17 @@  discard block
 block discarded – undo
453 472
 			// This means they didn't click Post and get an error.
454 473
 			$really_previewing = true;
455 474
 
456
-		}
457
-		else
475
+		} else
458 476
 		{
459
-			if (!isset($_REQUEST['subject']))
460
-				$_REQUEST['subject'] = '';
461
-			if (!isset($_REQUEST['message']))
462
-				$_REQUEST['message'] = '';
463
-			if (!isset($_REQUEST['icon']))
464
-				$_REQUEST['icon'] = 'xx';
477
+			if (!isset($_REQUEST['subject'])) {
478
+							$_REQUEST['subject'] = '';
479
+			}
480
+			if (!isset($_REQUEST['message'])) {
481
+							$_REQUEST['message'] = '';
482
+			}
483
+			if (!isset($_REQUEST['icon'])) {
484
+							$_REQUEST['icon'] = 'xx';
485
+			}
465 486
 
466 487
 			// They are previewing if they asked to preview (i.e. came from quick reply).
467 488
 			$really_previewing = !empty($_POST['preview']);
@@ -477,8 +498,9 @@  discard block
 block discarded – undo
477 498
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
478 499
 
479 500
 		// Make sure the subject isn't too long - taking into account special characters.
480
-		if ($smcFunc['strlen']($form_subject) > 100)
481
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
501
+		if ($smcFunc['strlen']($form_subject) > 100) {
502
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
503
+		}
482 504
 
483 505
 		if (isset($_REQUEST['poll']))
484 506
 		{
@@ -490,8 +512,9 @@  discard block
 block discarded – undo
490 512
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
491 513
 			foreach ($_POST['options'] as $option)
492 514
 			{
493
-				if (trim($option) == '')
494
-					continue;
515
+				if (trim($option) == '') {
516
+									continue;
517
+				}
495 518
 
496 519
 				$context['choices'][] = array(
497 520
 					'id' => $choice_id++,
@@ -553,13 +576,14 @@  discard block
 block discarded – undo
553 576
 				$context['preview_subject'] = $form_subject;
554 577
 
555 578
 				censorText($context['preview_subject']);
579
+			} else {
580
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
556 581
 			}
557
-			else
558
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
559 582
 
560 583
 			// Protect any CDATA blocks.
561
-			if (isset($_REQUEST['xml']))
562
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
584
+			if (isset($_REQUEST['xml'])) {
585
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
586
+			}
563 587
 		}
564 588
 
565 589
 		// Set up the checkboxes.
@@ -598,29 +622,32 @@  discard block
 block discarded – undo
598 622
 			);
599 623
 			// The message they were trying to edit was most likely deleted.
600 624
 			// @todo Change this error message?
601
-			if ($smcFunc['db_num_rows']($request) == 0)
602
-				fatal_lang_error('no_board', false);
625
+			if ($smcFunc['db_num_rows']($request) == 0) {
626
+							fatal_lang_error('no_board', false);
627
+			}
603 628
 			$row = $smcFunc['db_fetch_assoc']($request);
604 629
 
605 630
 			$attachment_stuff = array($row);
606
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
607
-				$attachment_stuff[] = $row2;
631
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
632
+							$attachment_stuff[] = $row2;
633
+			}
608 634
 			$smcFunc['db_free_result']($request);
609 635
 
610 636
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
611 637
 			{
612 638
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
613
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
614
-					fatal_lang_error('modify_post_time_passed', false);
615
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
616
-					isAllowedTo('modify_replies');
617
-				else
618
-					isAllowedTo('modify_own');
639
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
640
+									fatal_lang_error('modify_post_time_passed', false);
641
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
642
+									isAllowedTo('modify_replies');
643
+				} else {
644
+									isAllowedTo('modify_own');
645
+				}
646
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
647
+							isAllowedTo('modify_replies');
648
+			} else {
649
+							isAllowedTo('modify_any');
619 650
 			}
620
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
621
-				isAllowedTo('modify_replies');
622
-			else
623
-				isAllowedTo('modify_any');
624 651
 
625 652
 			if ($context['can_announce'] && !empty($row['id_action']))
626 653
 			{
@@ -644,8 +671,9 @@  discard block
 block discarded – undo
644 671
 
645 672
 				while ($row = $smcFunc['db_fetch_assoc']($request))
646 673
 				{
647
-					if ($row['filesize'] <= 0)
648
-						continue;
674
+					if ($row['filesize'] <= 0) {
675
+											continue;
676
+					}
649 677
 					$context['current_attachments'][$row['id_attach']] = array(
650 678
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
651 679
 						'size' => $row['filesize'],
@@ -715,29 +743,32 @@  discard block
 block discarded – undo
715 743
 			)
716 744
 		);
717 745
 		// The message they were trying to edit was most likely deleted.
718
-		if ($smcFunc['db_num_rows']($request) == 0)
719
-			fatal_lang_error('no_message', false);
746
+		if ($smcFunc['db_num_rows']($request) == 0) {
747
+					fatal_lang_error('no_message', false);
748
+		}
720 749
 		$row = $smcFunc['db_fetch_assoc']($request);
721 750
 
722 751
 		$attachment_stuff = array($row);
723
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
724
-			$attachment_stuff[] = $row2;
752
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
753
+					$attachment_stuff[] = $row2;
754
+		}
725 755
 		$smcFunc['db_free_result']($request);
726 756
 
727 757
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
728 758
 		{
729 759
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
730
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
731
-				fatal_lang_error('modify_post_time_passed', false);
732
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
733
-				isAllowedTo('modify_replies');
734
-			else
735
-				isAllowedTo('modify_own');
760
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
761
+							fatal_lang_error('modify_post_time_passed', false);
762
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
763
+							isAllowedTo('modify_replies');
764
+			} else {
765
+							isAllowedTo('modify_own');
766
+			}
767
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
768
+					isAllowedTo('modify_replies');
769
+		} else {
770
+					isAllowedTo('modify_any');
736 771
 		}
737
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
738
-			isAllowedTo('modify_replies');
739
-		else
740
-			isAllowedTo('modify_any');
741 772
 
742 773
 		if ($context['can_announce'] && !empty($row['id_action']))
743 774
 		{
@@ -764,15 +795,17 @@  discard block
 block discarded – undo
764 795
 		$context['icon'] = $row['icon'];
765 796
 
766 797
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
767
-		if (!$row['approved'] && !$context['show_approval'])
768
-			$context['show_approval'] = allowedTo('approve_posts');
798
+		if (!$row['approved'] && !$context['show_approval']) {
799
+					$context['show_approval'] = allowedTo('approve_posts');
800
+		}
769 801
 
770 802
 		// Sort the attachments so they are in the order saved
771 803
 		$temp = array();
772 804
 		foreach ($attachment_stuff as $attachment)
773 805
 		{
774
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
775
-				$temp[$attachment['id_attach']] = $attachment;
806
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
807
+							$temp[$attachment['id_attach']] = $attachment;
808
+			}
776 809
 
777 810
 		}
778 811
 		ksort($temp);
@@ -834,14 +867,16 @@  discard block
 block discarded – undo
834 867
 					'is_approved' => 1,
835 868
 				)
836 869
 			);
837
-			if ($smcFunc['db_num_rows']($request) == 0)
838
-				fatal_lang_error('quoted_post_deleted', false);
870
+			if ($smcFunc['db_num_rows']($request) == 0) {
871
+							fatal_lang_error('quoted_post_deleted', false);
872
+			}
839 873
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
840 874
 			$smcFunc['db_free_result']($request);
841 875
 
842 876
 			// Add 'Re: ' to the front of the quoted subject.
843
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
844
-				$form_subject = $context['response_prefix'] . $form_subject;
877
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
878
+							$form_subject = $context['response_prefix'] . $form_subject;
879
+			}
845 880
 
846 881
 			// Censor the message and subject.
847 882
 			censorText($form_message);
@@ -854,10 +889,11 @@  discard block
 block discarded – undo
854 889
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
855 890
 				{
856 891
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
857
-					if ($i % 4 == 0)
858
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
892
+					if ($i % 4 == 0) {
893
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
859 894
 						{
860 895
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
896
+					}
861 897
 						}, $parts[$i]);
862 898
 				}
863 899
 				$form_message = implode('', $parts);
@@ -866,8 +902,9 @@  discard block
 block discarded – undo
866 902
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
867 903
 
868 904
 			// Remove any nested quotes, if necessary.
869
-			if (!empty($modSettings['removeNestedQuotes']))
870
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
905
+			if (!empty($modSettings['removeNestedQuotes'])) {
906
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
907
+			}
871 908
 
872 909
 			// Add a quote string on the front and end.
873 910
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -879,15 +916,15 @@  discard block
 block discarded – undo
879 916
 			$form_subject = $first_subject;
880 917
 
881 918
 			// Add 'Re: ' to the front of the subject.
882
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
883
-				$form_subject = $context['response_prefix'] . $form_subject;
919
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
920
+							$form_subject = $context['response_prefix'] . $form_subject;
921
+			}
884 922
 
885 923
 			// Censor the subject.
886 924
 			censorText($form_subject);
887 925
 
888 926
 			$form_message = '';
889
-		}
890
-		else
927
+		} else
891 928
 		{
892 929
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
893 930
 			$form_message = '';
@@ -905,13 +942,15 @@  discard block
 block discarded – undo
905 942
 		if (isset($_REQUEST['msg']))
906 943
 		{
907 944
 			$context['attachments']['quantity'] = count($context['current_attachments']);
908
-			foreach ($context['current_attachments'] as $attachment)
909
-				$context['attachments']['total_size'] += $attachment['size'];
945
+			foreach ($context['current_attachments'] as $attachment) {
946
+							$context['attachments']['total_size'] += $attachment['size'];
947
+			}
910 948
 		}
911 949
 
912 950
 		// A bit of house keeping first.
913
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
914
-			unset($_SESSION['temp_attachments']);
951
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
952
+					unset($_SESSION['temp_attachments']);
953
+		}
915 954
 
916 955
 		if (!empty($_SESSION['temp_attachments']))
917 956
 		{
@@ -920,9 +959,10 @@  discard block
 block discarded – undo
920 959
 			{
921 960
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
922 961
 				{
923
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
924
-						if (file_exists($attachment['tmp_name']))
962
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
963
+											if (file_exists($attachment['tmp_name']))
925 964
 							unlink($attachment['tmp_name']);
965
+					}
926 966
 				}
927 967
 				$post_errors[] = 'temp_attachments_gone';
928 968
 				$_SESSION['temp_attachments'] = array();
@@ -936,8 +976,9 @@  discard block
 block discarded – undo
936 976
 					// See if any files still exist before showing the warning message and the files attached.
937 977
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 978
 					{
939
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
940
-							continue;
979
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
980
+													continue;
981
+						}
941 982
 
942 983
 						if (file_exists($attachment['tmp_name']))
943 984
 						{
@@ -947,20 +988,21 @@  discard block
 block discarded – undo
947 988
 							break;
948 989
 						}
949 990
 					}
950
-				}
951
-				else
991
+				} else
952 992
 				{
953 993
 					// Since, they don't belong here. Let's inform the user that they exist..
954
-					if (!empty($topic))
955
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
956
-					else
957
-						$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
994
+					if (!empty($topic)) {
995
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
996
+					} else {
997
+											$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
998
+					}
958 999
 
959 1000
 					// Compile a list of the files to show the user.
960 1001
 					$file_list = array();
961
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
962
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1002
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1003
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
963 1004
 							$file_list[] = $attachment['name'];
1005
+					}
964 1006
 
965 1007
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
966 1008
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -972,8 +1014,7 @@  discard block
 block discarded – undo
972 1014
 
973 1015
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
974 1016
 						$context['ignore_temp_attachments'] = true;
975
-					}
976
-					else
1017
+					} else
977 1018
 					{
978 1019
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
979 1020
 						$context['ignore_temp_attachments'] = true;
@@ -981,16 +1022,19 @@  discard block
 block discarded – undo
981 1022
 				}
982 1023
 			}
983 1024
 
984
-			if (!empty($context['we_are_history']))
985
-				$post_errors[] = $context['we_are_history'];
1025
+			if (!empty($context['we_are_history'])) {
1026
+							$post_errors[] = $context['we_are_history'];
1027
+			}
986 1028
 
987 1029
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
988 1030
 			{
989
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
990
-					break;
1031
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1032
+									break;
1033
+				}
991 1034
 
992
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
993
-					continue;
1035
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1036
+									continue;
1037
+				}
994 1038
 
995 1039
 				if ($attachID == 'initial_error')
996 1040
 				{
@@ -1005,15 +1049,17 @@  discard block
 block discarded – undo
1005 1049
 				{
1006 1050
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1007 1051
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1008
-					foreach ($attachment['errors'] as $error)
1009
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1052
+					foreach ($attachment['errors'] as $error) {
1053
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1054
+					}
1010 1055
 					$txt['error_attach_errors'] .= '</div>';
1011 1056
 					$post_errors[] = 'attach_errors';
1012 1057
 
1013 1058
 					// Take out the trash.
1014 1059
 					unset($_SESSION['temp_attachments'][$attachID]);
1015
-					if (file_exists($attachment['tmp_name']))
1016
-						unlink($attachment['tmp_name']);
1060
+					if (file_exists($attachment['tmp_name'])) {
1061
+											unlink($attachment['tmp_name']);
1062
+					}
1017 1063
 					continue;
1018 1064
 				}
1019 1065
 
@@ -1026,8 +1072,9 @@  discard block
 block discarded – undo
1026 1072
 
1027 1073
 				$context['attachments']['quantity']++;
1028 1074
 				$context['attachments']['total_size'] += $attachment['size'];
1029
-				if (!isset($context['files_in_session_warning']))
1030
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1075
+				if (!isset($context['files_in_session_warning'])) {
1076
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1077
+				}
1031 1078
 
1032 1079
 				$context['current_attachments'][$attachID] = array(
1033 1080
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1055,8 +1102,9 @@  discard block
 block discarded – undo
1055 1102
 	}
1056 1103
 
1057 1104
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1058
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1059
-		$post_errors[] = 'need_qr_verification';
1105
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1106
+			$post_errors[] = 'need_qr_verification';
1107
+	}
1060 1108
 
1061 1109
 	/*
1062 1110
 	 * There are two error types: serious and minor. Serious errors
@@ -1073,52 +1121,56 @@  discard block
 block discarded – undo
1073 1121
 	{
1074 1122
 		loadLanguage('Errors');
1075 1123
 		$context['error_type'] = 'minor';
1076
-		foreach ($post_errors as $post_error)
1077
-			if (is_array($post_error))
1124
+		foreach ($post_errors as $post_error) {
1125
+					if (is_array($post_error))
1078 1126
 			{
1079 1127
 				$post_error_id = $post_error[0];
1128
+		}
1080 1129
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1081 1130
 
1082 1131
 				// If it's not a minor error flag it as such.
1083
-				if (!in_array($post_error_id, $minor_errors))
1084
-					$context['error_type'] = 'serious';
1085
-			}
1086
-			else
1132
+				if (!in_array($post_error_id, $minor_errors)) {
1133
+									$context['error_type'] = 'serious';
1134
+				}
1135
+			} else
1087 1136
 			{
1088 1137
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1089 1138
 
1090 1139
 				// If it's not a minor error flag it as such.
1091
-				if (!in_array($post_error, $minor_errors))
1092
-					$context['error_type'] = 'serious';
1140
+				if (!in_array($post_error, $minor_errors)) {
1141
+									$context['error_type'] = 'serious';
1142
+				}
1093 1143
 			}
1094 1144
 	}
1095 1145
 
1096 1146
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1097
-	if (isset($_REQUEST['poll']))
1098
-		$context['page_title'] = $txt['new_poll'];
1099
-	elseif ($context['make_event'])
1100
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1101
-	elseif (isset($_REQUEST['msg']))
1102
-		$context['page_title'] = $txt['modify_msg'];
1103
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1104
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1105
-	elseif (empty($topic))
1106
-		$context['page_title'] = $txt['start_new_topic'];
1107
-	else
1108
-		$context['page_title'] = $txt['post_reply'];
1147
+	if (isset($_REQUEST['poll'])) {
1148
+			$context['page_title'] = $txt['new_poll'];
1149
+	} elseif ($context['make_event']) {
1150
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1151
+	} elseif (isset($_REQUEST['msg'])) {
1152
+			$context['page_title'] = $txt['modify_msg'];
1153
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1154
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1155
+	} elseif (empty($topic)) {
1156
+			$context['page_title'] = $txt['start_new_topic'];
1157
+	} else {
1158
+			$context['page_title'] = $txt['post_reply'];
1159
+	}
1109 1160
 
1110 1161
 	// Build the link tree.
1111
-	if (empty($topic))
1112
-		$context['linktree'][] = array(
1162
+	if (empty($topic)) {
1163
+			$context['linktree'][] = array(
1113 1164
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1114 1165
 		);
1115
-	else
1116
-		$context['linktree'][] = array(
1166
+	} else {
1167
+			$context['linktree'][] = array(
1117 1168
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1118 1169
 			'name' => $form_subject,
1119 1170
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1120 1171
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1121 1172
 		);
1173
+	}
1122 1174
 
1123 1175
 	$context['subject'] = addcslashes($form_subject, '"');
1124 1176
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1162,8 +1214,9 @@  discard block
 block discarded – undo
1162 1214
 	// Message icons - customized icons are off?
1163 1215
 	$context['icons'] = getMessageIcons($board);
1164 1216
 
1165
-	if (!empty($context['icons']))
1166
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1217
+	if (!empty($context['icons'])) {
1218
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1219
+	}
1167 1220
 
1168 1221
 	// Are we starting a poll? if set the poll icon as selected if its available
1169 1222
 	if (isset($_REQUEST['poll']))
@@ -1183,8 +1236,9 @@  discard block
 block discarded – undo
1183 1236
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1184 1237
 	{
1185 1238
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1186
-		if ($context['icons'][$i]['selected'])
1187
-			$context['icon_url'] = $context['icons'][$i]['url'];
1239
+		if ($context['icons'][$i]['selected']) {
1240
+					$context['icon_url'] = $context['icons'][$i]['url'];
1241
+		}
1188 1242
 	}
1189 1243
 	if (empty($context['icon_url']))
1190 1244
 	{
@@ -1198,8 +1252,9 @@  discard block
 block discarded – undo
1198 1252
 		));
1199 1253
 	}
1200 1254
 
1201
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1202
-		getTopic();
1255
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1256
+			getTopic();
1257
+	}
1203 1258
 
1204 1259
 	// If the user can post attachments prepare the warning labels.
1205 1260
 	if ($context['can_post_attachment'])
@@ -1210,15 +1265,17 @@  discard block
 block discarded – undo
1210 1265
 		$context['attachment_restrictions'] = array();
1211 1266
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1212 1267
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1213
-		foreach ($attachmentRestrictionTypes as $type)
1214
-			if (!empty($modSettings[$type]))
1268
+		foreach ($attachmentRestrictionTypes as $type) {
1269
+					if (!empty($modSettings[$type]))
1215 1270
 			{
1216 1271
 				$context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0));
1272
+		}
1217 1273
 				// Show some numbers. If they exist.
1218
-				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
1219
-					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1220
-				elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
1221
-					$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1274
+				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) {
1275
+									$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1276
+				} elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) {
1277
+									$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1278
+				}
1222 1279
 			}
1223 1280
 	}
1224 1281
 
@@ -1252,8 +1309,8 @@  discard block
 block discarded – undo
1252 1309
 
1253 1310
 	if (!empty($context['current_attachments']))
1254 1311
 	{
1255
-		foreach ($context['current_attachments'] as $key => $mock)
1256
-			addInlineJavaScript('
1312
+		foreach ($context['current_attachments'] as $key => $mock) {
1313
+					addInlineJavaScript('
1257 1314
 	current_attachments.push({
1258 1315
 		name: '. JavaScriptEscape($mock['name']) . ',
1259 1316
 		size: '. $mock['size'] . ',
@@ -1262,6 +1319,7 @@  discard block
 block discarded – undo
1262 1319
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1263 1320
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1264 1321
 	});', true);
1322
+		}
1265 1323
 	}
1266 1324
 
1267 1325
 	// File Upload.
@@ -1306,8 +1364,9 @@  discard block
 block discarded – undo
1306 1364
 	var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false);
1307 1365
 
1308 1366
 	// Finally, load the template.
1309
-	if (!isset($_REQUEST['xml']))
1310
-		loadTemplate('Post');
1367
+	if (!isset($_REQUEST['xml'])) {
1368
+			loadTemplate('Post');
1369
+	}
1311 1370
 
1312 1371
 	call_integration_hook('integrate_post_end');
1313 1372
 }
@@ -1328,13 +1387,14 @@  discard block
 block discarded – undo
1328 1387
 	// Sneaking off, are we?
1329 1388
 	if (empty($_POST) && empty($topic))
1330 1389
 	{
1331
-		if (empty($_SERVER['CONTENT_LENGTH']))
1332
-			redirectexit('action=post;board=' . $board . '.0');
1333
-		else
1334
-			fatal_lang_error('post_upload_error', false);
1390
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1391
+					redirectexit('action=post;board=' . $board . '.0');
1392
+		} else {
1393
+					fatal_lang_error('post_upload_error', false);
1394
+		}
1395
+	} elseif (empty($_POST) && !empty($topic)) {
1396
+			redirectexit('action=post;topic=' . $topic . '.0');
1335 1397
 	}
1336
-	elseif (empty($_POST) && !empty($topic))
1337
-		redirectexit('action=post;topic=' . $topic . '.0');
1338 1398
 
1339 1399
 	// No need!
1340 1400
 	$context['robot_no_index'] = true;
@@ -1346,8 +1406,9 @@  discard block
 block discarded – undo
1346 1406
 	$post_errors = array();
1347 1407
 
1348 1408
 	// If the session has timed out, let the user re-submit their form.
1349
-	if (checkSession('post', '', false) != '')
1350
-		$post_errors[] = 'session_timeout';
1409
+	if (checkSession('post', '', false) != '') {
1410
+			$post_errors[] = 'session_timeout';
1411
+	}
1351 1412
 
1352 1413
 	// Wrong verification code?
1353 1414
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1357,33 +1418,38 @@  discard block
 block discarded – undo
1357 1418
 			'id' => 'post',
1358 1419
 		);
1359 1420
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1360
-		if (is_array($context['require_verification']))
1361
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1421
+		if (is_array($context['require_verification'])) {
1422
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1423
+		}
1362 1424
 	}
1363 1425
 
1364 1426
 	require_once($sourcedir . '/Subs-Post.php');
1365 1427
 	loadLanguage('Post');
1366 1428
 
1367 1429
 	// Drafts enabled and needed?
1368
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1369
-		require_once($sourcedir . '/Drafts.php');
1430
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1431
+			require_once($sourcedir . '/Drafts.php');
1432
+	}
1370 1433
 
1371 1434
 	// First check to see if they are trying to delete any current attachments.
1372 1435
 	if (isset($_POST['attach_del']))
1373 1436
 	{
1374 1437
 		$keep_temp = array();
1375 1438
 		$keep_ids = array();
1376
-		foreach ($_POST['attach_del'] as $dummy)
1377
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1439
+		foreach ($_POST['attach_del'] as $dummy) {
1440
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1378 1441
 				$keep_temp[] = $dummy;
1379
-			else
1380
-				$keep_ids[] = (int) $dummy;
1442
+		}
1443
+			else {
1444
+							$keep_ids[] = (int) $dummy;
1445
+			}
1381 1446
 
1382
-		if (isset($_SESSION['temp_attachments']))
1383
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1447
+		if (isset($_SESSION['temp_attachments'])) {
1448
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1384 1449
 			{
1385 1450
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1386 1451
 					continue;
1452
+		}
1387 1453
 
1388 1454
 				unset($_SESSION['temp_attachments'][$attachID]);
1389 1455
 				unlink($attachment['tmp_name']);
@@ -1425,24 +1491,28 @@  discard block
 block discarded – undo
1425 1491
 		$smcFunc['db_free_result']($request);
1426 1492
 
1427 1493
 		// Though the topic should be there, it might have vanished.
1428
-		if (!is_array($topic_info))
1429
-			fatal_lang_error('topic_doesnt_exist', 404);
1494
+		if (!is_array($topic_info)) {
1495
+					fatal_lang_error('topic_doesnt_exist', 404);
1496
+		}
1430 1497
 
1431 1498
 		// Did this topic suddenly move? Just checking...
1432
-		if ($topic_info['id_board'] != $board)
1433
-			fatal_lang_error('not_a_topic');
1499
+		if ($topic_info['id_board'] != $board) {
1500
+					fatal_lang_error('not_a_topic');
1501
+		}
1434 1502
 	}
1435 1503
 
1436 1504
 	// Replying to a topic?
1437 1505
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1438 1506
 	{
1439 1507
 		// Don't allow a post if it's locked.
1440
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1441
-			fatal_lang_error('topic_locked', false);
1508
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1509
+					fatal_lang_error('topic_locked', false);
1510
+		}
1442 1511
 
1443 1512
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1444
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1445
-			unset($_REQUEST['poll']);
1513
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1514
+					unset($_REQUEST['poll']);
1515
+		}
1446 1516
 
1447 1517
 		// Do the permissions and approval stuff...
1448 1518
 		$becomesApproved = true;
@@ -1458,44 +1528,43 @@  discard block
 block discarded – undo
1458 1528
 
1459 1529
 			// Set a nice session var...
1460 1530
 			$_SESSION['becomesUnapproved'] = true;
1461
-		}
1462
-
1463
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1531
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1464 1532
 		{
1465
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1466
-				$becomesApproved = false;
1467
-
1468
-			else
1469
-				isAllowedTo('post_reply_any');
1470
-		}
1471
-		elseif (!allowedTo('post_reply_any'))
1533
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1534
+							$becomesApproved = false;
1535
+			} else {
1536
+							isAllowedTo('post_reply_any');
1537
+			}
1538
+		} elseif (!allowedTo('post_reply_any'))
1472 1539
 		{
1473
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1474
-				$becomesApproved = false;
1475
-
1476
-			else
1477
-				isAllowedTo('post_reply_own');
1540
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1541
+							$becomesApproved = false;
1542
+			} else {
1543
+							isAllowedTo('post_reply_own');
1544
+			}
1478 1545
 		}
1479 1546
 
1480 1547
 		if (isset($_POST['lock']))
1481 1548
 		{
1482 1549
 			// Nothing is changed to the lock.
1483
-			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1484
-				unset($_POST['lock']);
1550
+			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1551
+							unset($_POST['lock']);
1552
+			}
1485 1553
 
1486 1554
 			// You're have no permission to lock this topic.
1487
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1488
-				unset($_POST['lock']);
1555
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1556
+							unset($_POST['lock']);
1557
+			}
1489 1558
 
1490 1559
 			// You are allowed to (un)lock your own topic only.
1491 1560
 			elseif (!allowedTo('lock_any'))
1492 1561
 			{
1493 1562
 				// You cannot override a moderator lock.
1494
-				if ($topic_info['locked'] == 1)
1495
-					unset($_POST['lock']);
1496
-
1497
-				else
1498
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1563
+				if ($topic_info['locked'] == 1) {
1564
+									unset($_POST['lock']);
1565
+				} else {
1566
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1567
+				}
1499 1568
 			}
1500 1569
 			// Hail mighty moderator, (un)lock this topic immediately.
1501 1570
 			else
@@ -1503,19 +1572,21 @@  discard block
 block discarded – undo
1503 1572
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1504 1573
 
1505 1574
 				// Did someone (un)lock this while you were posting?
1506
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1507
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1575
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1576
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1577
+				}
1508 1578
 			}
1509 1579
 		}
1510 1580
 
1511 1581
 		// So you wanna (un)sticky this...let's see.
1512
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1513
-			unset($_POST['sticky']);
1514
-		elseif (isset($_POST['sticky']))
1582
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1583
+					unset($_POST['sticky']);
1584
+		} elseif (isset($_POST['sticky']))
1515 1585
 		{
1516 1586
 			// Did someone (un)sticky this while you were posting?
1517
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1518
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1587
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1588
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1589
+			}
1519 1590
 		}
1520 1591
 
1521 1592
 		// If drafts are enabled, then pass this off
@@ -1542,26 +1613,31 @@  discard block
 block discarded – undo
1542 1613
 
1543 1614
 		// Do like, the permissions, for safety and stuff...
1544 1615
 		$becomesApproved = true;
1545
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1546
-			$becomesApproved = false;
1547
-		else
1548
-			isAllowedTo('post_new');
1616
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1617
+					$becomesApproved = false;
1618
+		} else {
1619
+					isAllowedTo('post_new');
1620
+		}
1549 1621
 
1550 1622
 		if (isset($_POST['lock']))
1551 1623
 		{
1552 1624
 			// New topics are by default not locked.
1553
-			if (empty($_POST['lock']))
1554
-				unset($_POST['lock']);
1625
+			if (empty($_POST['lock'])) {
1626
+							unset($_POST['lock']);
1627
+			}
1555 1628
 			// Besides, you need permission.
1556
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1557
-				unset($_POST['lock']);
1629
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1630
+							unset($_POST['lock']);
1631
+			}
1558 1632
 			// A moderator-lock (1) can override a user-lock (2).
1559
-			else
1560
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1633
+			else {
1634
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1635
+			}
1561 1636
 		}
1562 1637
 
1563
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1564
-			unset($_POST['sticky']);
1638
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1639
+					unset($_POST['sticky']);
1640
+		}
1565 1641
 
1566 1642
 		// Saving your new topic as a draft first?
1567 1643
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1586,31 +1662,37 @@  discard block
 block discarded – undo
1586 1662
 				'id_msg' => $_REQUEST['msg'],
1587 1663
 			)
1588 1664
 		);
1589
-		if ($smcFunc['db_num_rows']($request) == 0)
1590
-			fatal_lang_error('cant_find_messages', false);
1665
+		if ($smcFunc['db_num_rows']($request) == 0) {
1666
+					fatal_lang_error('cant_find_messages', false);
1667
+		}
1591 1668
 		$row = $smcFunc['db_fetch_assoc']($request);
1592 1669
 		$smcFunc['db_free_result']($request);
1593 1670
 
1594
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1595
-			fatal_lang_error('topic_locked', false);
1671
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1672
+					fatal_lang_error('topic_locked', false);
1673
+		}
1596 1674
 
1597 1675
 		if (isset($_POST['lock']))
1598 1676
 		{
1599 1677
 			// Nothing changes to the lock status.
1600
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1601
-				unset($_POST['lock']);
1678
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1679
+							unset($_POST['lock']);
1680
+			}
1602 1681
 			// You're simply not allowed to (un)lock this.
1603
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1604
-				unset($_POST['lock']);
1682
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1683
+							unset($_POST['lock']);
1684
+			}
1605 1685
 			// You're only allowed to lock your own topics.
1606 1686
 			elseif (!allowedTo('lock_any'))
1607 1687
 			{
1608 1688
 				// You're not allowed to break a moderator's lock.
1609
-				if ($topic_info['locked'] == 1)
1610
-					unset($_POST['lock']);
1689
+				if ($topic_info['locked'] == 1) {
1690
+									unset($_POST['lock']);
1691
+				}
1611 1692
 				// Lock it with a soft lock or unlock it.
1612
-				else
1613
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1693
+				else {
1694
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1695
+				}
1614 1696
 			}
1615 1697
 			// You must be the moderator.
1616 1698
 			else
@@ -1618,44 +1700,46 @@  discard block
 block discarded – undo
1618 1700
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1619 1701
 
1620 1702
 				// Did someone (un)lock this while you were posting?
1621
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1622
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1703
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1704
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1705
+				}
1623 1706
 			}
1624 1707
 		}
1625 1708
 
1626 1709
 		// Change the sticky status of this topic?
1627
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1628
-			unset($_POST['sticky']);
1629
-		elseif (isset($_POST['sticky']))
1710
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1711
+					unset($_POST['sticky']);
1712
+		} elseif (isset($_POST['sticky']))
1630 1713
 		{
1631 1714
 			// Did someone (un)sticky this while you were posting?
1632
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1633
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1715
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1716
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1717
+			}
1634 1718
 		}
1635 1719
 
1636 1720
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1637 1721
 		{
1638
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1639
-				fatal_lang_error('modify_post_time_passed', false);
1640
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1641
-				isAllowedTo('modify_replies');
1642
-			else
1643
-				isAllowedTo('modify_own');
1644
-		}
1645
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1722
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1723
+							fatal_lang_error('modify_post_time_passed', false);
1724
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1725
+							isAllowedTo('modify_replies');
1726
+			} else {
1727
+							isAllowedTo('modify_own');
1728
+			}
1729
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1646 1730
 		{
1647 1731
 			isAllowedTo('modify_replies');
1648 1732
 
1649 1733
 			// If you're modifying a reply, I say it better be logged...
1650 1734
 			$moderationAction = true;
1651
-		}
1652
-		else
1735
+		} else
1653 1736
 		{
1654 1737
 			isAllowedTo('modify_any');
1655 1738
 
1656 1739
 			// Log it, assuming you're not modifying your own post.
1657
-			if ($row['id_member'] != $user_info['id'])
1658
-				$moderationAction = true;
1740
+			if ($row['id_member'] != $user_info['id']) {
1741
+							$moderationAction = true;
1742
+			}
1659 1743
 		}
1660 1744
 
1661 1745
 		// If drafts are enabled, then lets send this off to save
@@ -1692,20 +1776,24 @@  discard block
 block discarded – undo
1692 1776
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1693 1777
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1694 1778
 
1695
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1696
-			$post_errors[] = 'no_name';
1697
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1698
-			$post_errors[] = 'long_name';
1779
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1780
+					$post_errors[] = 'no_name';
1781
+		}
1782
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1783
+					$post_errors[] = 'long_name';
1784
+		}
1699 1785
 
1700 1786
 		if (empty($modSettings['guest_post_no_email']))
1701 1787
 		{
1702 1788
 			// Only check if they changed it!
1703 1789
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1704 1790
 			{
1705
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1706
-					$post_errors[] = 'no_email';
1707
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1708
-					$post_errors[] = 'bad_email';
1791
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1792
+									$post_errors[] = 'no_email';
1793
+				}
1794
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1795
+									$post_errors[] = 'bad_email';
1796
+				}
1709 1797
 			}
1710 1798
 
1711 1799
 			// Now make sure this email address is not banned from posting.
@@ -1721,75 +1809,89 @@  discard block
 block discarded – undo
1721 1809
 	}
1722 1810
 
1723 1811
 	// Coming from the quickReply?
1724
-	if (isset($_POST['quickReply']))
1725
-		$_POST['message'] = $_POST['quickReply'];
1812
+	if (isset($_POST['quickReply'])) {
1813
+			$_POST['message'] = $_POST['quickReply'];
1814
+	}
1726 1815
 
1727 1816
 	// Check the subject and message.
1728
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1729
-		$post_errors[] = 'no_subject';
1730
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1731
-		$post_errors[] = 'no_message';
1732
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1733
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1734
-	else
1817
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1818
+			$post_errors[] = 'no_subject';
1819
+	}
1820
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1821
+			$post_errors[] = 'no_message';
1822
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1823
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1824
+	} else
1735 1825
 	{
1736 1826
 		// Prepare the message a bit for some additional testing.
1737 1827
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1738 1828
 
1739 1829
 		// Preparse code. (Zef)
1740
-		if ($user_info['is_guest'])
1741
-			$user_info['name'] = $_POST['guestname'];
1830
+		if ($user_info['is_guest']) {
1831
+					$user_info['name'] = $_POST['guestname'];
1832
+		}
1742 1833
 		preparsecode($_POST['message']);
1743 1834
 
1744 1835
 		// Let's see if there's still some content left without the tags.
1745
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1746
-			$post_errors[] = 'no_message';
1836
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1837
+					$post_errors[] = 'no_message';
1838
+		}
1839
+	}
1840
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1841
+			$post_errors[] = 'no_event';
1747 1842
 	}
1748
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1749
-		$post_errors[] = 'no_event';
1750 1843
 	// You are not!
1751
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1752
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1844
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1845
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1846
+	}
1753 1847
 
1754 1848
 	// Validate the poll...
1755 1849
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1756 1850
 	{
1757
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1758
-			fatal_lang_error('no_access', false);
1851
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1852
+					fatal_lang_error('no_access', false);
1853
+		}
1759 1854
 
1760 1855
 		// This is a new topic... so it's a new poll.
1761
-		if (empty($topic))
1762
-			isAllowedTo('poll_post');
1856
+		if (empty($topic)) {
1857
+					isAllowedTo('poll_post');
1858
+		}
1763 1859
 		// Can you add to your own topics?
1764
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1765
-			isAllowedTo('poll_add_own');
1860
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1861
+					isAllowedTo('poll_add_own');
1862
+		}
1766 1863
 		// Can you add polls to any topic, then?
1767
-		else
1768
-			isAllowedTo('poll_add_any');
1864
+		else {
1865
+					isAllowedTo('poll_add_any');
1866
+		}
1769 1867
 
1770
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1771
-			$post_errors[] = 'no_question';
1868
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1869
+					$post_errors[] = 'no_question';
1870
+		}
1772 1871
 
1773 1872
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1774 1873
 
1775 1874
 		// Get rid of empty ones.
1776
-		foreach ($_POST['options'] as $k => $option)
1777
-			if ($option == '')
1875
+		foreach ($_POST['options'] as $k => $option) {
1876
+					if ($option == '')
1778 1877
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1878
+		}
1779 1879
 
1780 1880
 		// What are you going to vote between with one choice?!?
1781
-		if (count($_POST['options']) < 2)
1782
-			$post_errors[] = 'poll_few';
1783
-		elseif (count($_POST['options']) > 256)
1784
-			$post_errors[] = 'poll_many';
1881
+		if (count($_POST['options']) < 2) {
1882
+					$post_errors[] = 'poll_few';
1883
+		} elseif (count($_POST['options']) > 256) {
1884
+					$post_errors[] = 'poll_many';
1885
+		}
1785 1886
 	}
1786 1887
 
1787 1888
 	if ($posterIsGuest)
1788 1889
 	{
1789 1890
 		// If user is a guest, make sure the chosen name isn't taken.
1790 1891
 		require_once($sourcedir . '/Subs-Members.php');
1791
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1792
-			$post_errors[] = 'bad_name';
1892
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1893
+					$post_errors[] = 'bad_name';
1894
+		}
1793 1895
 	}
1794 1896
 	// If the user isn't a guest, get his or her name and email.
1795 1897
 	elseif (!isset($_REQUEST['msg']))
@@ -1820,8 +1922,9 @@  discard block
 block discarded – undo
1820 1922
 	}
1821 1923
 
1822 1924
 	// Make sure the user isn't spamming the board.
1823
-	if (!isset($_REQUEST['msg']))
1824
-		spamProtection('post');
1925
+	if (!isset($_REQUEST['msg'])) {
1926
+			spamProtection('post');
1927
+	}
1825 1928
 
1826 1929
 	// At about this point, we're posting and that's that.
1827 1930
 	ignore_user_abort(true);
@@ -1834,32 +1937,36 @@  discard block
 block discarded – undo
1834 1937
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1835 1938
 
1836 1939
 	// At this point, we want to make sure the subject isn't too long.
1837
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1838
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1940
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
1941
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1942
+	}
1839 1943
 
1840 1944
 	// Same with the "why did you edit this" text.
1841
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1842
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1945
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
1946
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1947
+	}
1843 1948
 
1844 1949
 	// Make the poll...
1845 1950
 	if (isset($_REQUEST['poll']))
1846 1951
 	{
1847 1952
 		// Make sure that the user has not entered a ridiculous number of options..
1848
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1849
-			$_POST['poll_max_votes'] = 1;
1850
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1851
-			$_POST['poll_max_votes'] = count($_POST['options']);
1852
-		else
1853
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1953
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
1954
+					$_POST['poll_max_votes'] = 1;
1955
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
1956
+					$_POST['poll_max_votes'] = count($_POST['options']);
1957
+		} else {
1958
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1959
+		}
1854 1960
 
1855 1961
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1856 1962
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1857 1963
 
1858 1964
 		// Just set it to zero if it's not there..
1859
-		if (!isset($_POST['poll_hide']))
1860
-			$_POST['poll_hide'] = 0;
1861
-		else
1862
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1965
+		if (!isset($_POST['poll_hide'])) {
1966
+					$_POST['poll_hide'] = 0;
1967
+		} else {
1968
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1969
+		}
1863 1970
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1864 1971
 
1865 1972
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1868,16 +1975,19 @@  discard block
 block discarded – undo
1868 1975
 		{
1869 1976
 			require_once($sourcedir . '/Subs-Members.php');
1870 1977
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1871
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1872
-				$_POST['poll_guest_vote'] = 0;
1978
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
1979
+							$_POST['poll_guest_vote'] = 0;
1980
+			}
1873 1981
 		}
1874 1982
 
1875 1983
 		// If the user tries to set the poll too far in advance, don't let them.
1876
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1877
-			fatal_lang_error('poll_range_error', false);
1984
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
1985
+					fatal_lang_error('poll_range_error', false);
1986
+		}
1878 1987
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1879
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1880
-			$_POST['poll_hide'] = 1;
1988
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
1989
+					$_POST['poll_hide'] = 1;
1990
+		}
1881 1991
 
1882 1992
 		// Clean up the question and answers.
1883 1993
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1891,13 +2001,15 @@  discard block
 block discarded – undo
1891 2001
 	{
1892 2002
 		$attachIDs = array();
1893 2003
 		$attach_errors = array();
1894
-		if (!empty($context['we_are_history']))
1895
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2004
+		if (!empty($context['we_are_history'])) {
2005
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2006
+		}
1896 2007
 
1897 2008
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1898 2009
 		{
1899
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1900
-				continue;
2010
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2011
+							continue;
2012
+			}
1901 2013
 
1902 2014
 			// If there was an initial error just show that message.
1903 2015
 			if ($attachID == 'initial_error')
@@ -1926,12 +2038,13 @@  discard block
 block discarded – undo
1926 2038
 				if (createAttachment($attachmentOptions))
1927 2039
 				{
1928 2040
 					$attachIDs[] = $attachmentOptions['id'];
1929
-					if (!empty($attachmentOptions['thumb']))
1930
-						$attachIDs[] = $attachmentOptions['thumb'];
2041
+					if (!empty($attachmentOptions['thumb'])) {
2042
+											$attachIDs[] = $attachmentOptions['thumb'];
2043
+					}
1931 2044
 				}
2045
+			} else {
2046
+							$attach_errors[] = '<dt>&nbsp;</dt>';
1932 2047
 			}
1933
-			else
1934
-				$attach_errors[] = '<dt>&nbsp;</dt>';
1935 2048
 
1936 2049
 			if (!empty($attachmentOptions['errors']))
1937 2050
 			{
@@ -1943,14 +2056,16 @@  discard block
 block discarded – undo
1943 2056
 					if (!is_array($error))
1944 2057
 					{
1945 2058
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
1946
-						if (in_array($error, $log_these))
1947
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2059
+						if (in_array($error, $log_these)) {
2060
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2061
+						}
2062
+					} else {
2063
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1948 2064
 					}
1949
-					else
1950
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1951 2065
 				}
1952
-				if (file_exists($attachment['tmp_name']))
1953
-					unlink($attachment['tmp_name']);
2066
+				if (file_exists($attachment['tmp_name'])) {
2067
+									unlink($attachment['tmp_name']);
2068
+				}
1954 2069
 			}
1955 2070
 		}
1956 2071
 		unset($_SESSION['temp_attachments']);
@@ -1991,24 +2106,24 @@  discard block
 block discarded – undo
1991 2106
 		);
1992 2107
 
1993 2108
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2109
+	} else {
2110
+			$id_poll = 0;
1994 2111
 	}
1995
-	else
1996
-		$id_poll = 0;
1997 2112
 
1998 2113
 	// Creating a new topic?
1999 2114
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2000 2115
 
2001 2116
 	// Check the icon.
2002
-	if (!isset($_POST['icon']))
2003
-		$_POST['icon'] = 'xx';
2004
-
2005
-	else
2117
+	if (!isset($_POST['icon'])) {
2118
+			$_POST['icon'] = 'xx';
2119
+	} else
2006 2120
 	{
2007 2121
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2008 2122
 
2009 2123
 		// Need to figure it out if this is a valid icon name.
2010
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2011
-			$_POST['icon'] = 'xx';
2124
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2125
+					$_POST['icon'] = 'xx';
2126
+		}
2012 2127
 	}
2013 2128
 
2014 2129
 	// Collect all parameters for the creation or modification of a post.
@@ -2049,8 +2164,9 @@  discard block
 block discarded – undo
2049 2164
 		}
2050 2165
 
2051 2166
 		// This will save some time...
2052
-		if (empty($approve_has_changed))
2053
-			unset($msgOptions['approved']);
2167
+		if (empty($approve_has_changed)) {
2168
+					unset($msgOptions['approved']);
2169
+		}
2054 2170
 
2055 2171
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2056 2172
 	}
@@ -2059,8 +2175,9 @@  discard block
 block discarded – undo
2059 2175
 	{
2060 2176
 		createPost($msgOptions, $topicOptions, $posterOptions);
2061 2177
 
2062
-		if (isset($topicOptions['id']))
2063
-			$topic = $topicOptions['id'];
2178
+		if (isset($topicOptions['id'])) {
2179
+					$topic = $topicOptions['id'];
2180
+		}
2064 2181
 	}
2065 2182
 
2066 2183
 	// Assign the previously uploaded attachments to the brand new message.
@@ -2072,8 +2189,9 @@  discard block
 block discarded – undo
2072 2189
 	}
2073 2190
 
2074 2191
 	// If we had a draft for this, its time to remove it since it was just posted
2075
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2076
-		DeleteDraft($_POST['id_draft']);
2192
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2193
+			DeleteDraft($_POST['id_draft']);
2194
+	}
2077 2195
 
2078 2196
 	// Editing or posting an event?
2079 2197
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2092,8 +2210,7 @@  discard block
 block discarded – undo
2092 2210
 			'member' => $user_info['id'],
2093 2211
 		);
2094 2212
 		insertEvent($eventOptions);
2095
-	}
2096
-	elseif (isset($_POST['calendar']))
2213
+	} elseif (isset($_POST['calendar']))
2097 2214
 	{
2098 2215
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2099 2216
 
@@ -2121,14 +2238,15 @@  discard block
 block discarded – undo
2121 2238
 		}
2122 2239
 
2123 2240
 		// Delete it?
2124
-		if (isset($_REQUEST['deleteevent']))
2125
-			$smcFunc['db_query']('', '
2241
+		if (isset($_REQUEST['deleteevent'])) {
2242
+					$smcFunc['db_query']('', '
2126 2243
 				DELETE FROM {db_prefix}calendar
2127 2244
 				WHERE id_event = {int:id_event}',
2128 2245
 				array(
2129 2246
 					'id_event' => $_REQUEST['eventid'],
2130 2247
 				)
2131 2248
 			);
2249
+		}
2132 2250
 		// ... or just update it?
2133 2251
 		else
2134 2252
 		{
@@ -2170,9 +2288,8 @@  discard block
 block discarded – undo
2170 2288
 			array($user_info['id'], $topic, 0),
2171 2289
 			array('id_member', 'id_topic', 'id_board')
2172 2290
 		);
2173
-	}
2174
-	elseif (!$newTopic)
2175
-		$smcFunc['db_query']('', '
2291
+	} elseif (!$newTopic) {
2292
+			$smcFunc['db_query']('', '
2176 2293
 			DELETE FROM {db_prefix}log_notify
2177 2294
 			WHERE id_member = {int:current_member}
2178 2295
 				AND id_topic = {int:current_topic}',
@@ -2181,16 +2298,20 @@  discard block
 block discarded – undo
2181 2298
 				'current_topic' => $topic,
2182 2299
 			)
2183 2300
 		);
2301
+	}
2184 2302
 
2185 2303
 	// Log an act of moderation - modifying.
2186
-	if (!empty($moderationAction))
2187
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2304
+	if (!empty($moderationAction)) {
2305
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2306
+	}
2188 2307
 
2189
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2190
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2308
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2309
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2310
+	}
2191 2311
 
2192
-	if (isset($_POST['sticky']))
2193
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2312
+	if (isset($_POST['sticky'])) {
2313
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2314
+	}
2194 2315
 
2195 2316
 	// Returning to the topic?
2196 2317
 	if (!empty($_REQUEST['goback']))
@@ -2209,26 +2330,31 @@  discard block
 block discarded – undo
2209 2330
 		);
2210 2331
 	}
2211 2332
 
2212
-	if ($board_info['num_topics'] == 0)
2213
-		cache_put_data('board-' . $board, null, 120);
2333
+	if ($board_info['num_topics'] == 0) {
2334
+			cache_put_data('board-' . $board, null, 120);
2335
+	}
2214 2336
 
2215 2337
 	call_integration_hook('integrate_post2_end');
2216 2338
 
2217
-	if (!empty($_POST['announce_topic']))
2218
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2339
+	if (!empty($_POST['announce_topic'])) {
2340
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2341
+	}
2219 2342
 
2220
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2221
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2343
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2344
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2345
+	}
2222 2346
 
2223 2347
 	// Return to post if the mod is on.
2224
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2225
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2226
-	elseif (!empty($_REQUEST['goback']))
2227
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2348
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2349
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2350
+	} elseif (!empty($_REQUEST['goback'])) {
2351
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2352
+	}
2228 2353
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2229
-	else
2230
-		redirectexit('board=' . $board . '.0');
2231
-}
2354
+	else {
2355
+			redirectexit('board=' . $board . '.0');
2356
+	}
2357
+	}
2232 2358
 
2233 2359
 /**
2234 2360
  * Handle the announce topic function (action=announce).
@@ -2246,8 +2372,9 @@  discard block
 block discarded – undo
2246 2372
 
2247 2373
 	validateSession();
2248 2374
 
2249
-	if (empty($topic))
2250
-		fatal_lang_error('topic_gone', false);
2375
+	if (empty($topic)) {
2376
+			fatal_lang_error('topic_gone', false);
2377
+	}
2251 2378
 
2252 2379
 	loadLanguage('Post');
2253 2380
 	loadTemplate('Post');
@@ -2274,8 +2401,9 @@  discard block
 block discarded – undo
2274 2401
 	global $txt, $context, $topic, $board, $board_info, $smcFunc;
2275 2402
 
2276 2403
 	$groups = array_merge($board_info['groups'], array(1));
2277
-	foreach ($groups as $id => $group)
2278
-		$groups[$id] = (int) $group;
2404
+	foreach ($groups as $id => $group) {
2405
+			$groups[$id] = (int) $group;
2406
+	}
2279 2407
 
2280 2408
 	$context['groups'] = array();
2281 2409
 	if (in_array(0, $groups))
@@ -2318,8 +2446,9 @@  discard block
 block discarded – undo
2318 2446
 			'group_list' => $groups,
2319 2447
 		)
2320 2448
 	);
2321
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2322
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2449
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2450
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2451
+	}
2323 2452
 	$smcFunc['db_free_result']($request);
2324 2453
 
2325 2454
 	// Get the subject of the topic we're about to announce.
@@ -2361,16 +2490,19 @@  discard block
 block discarded – undo
2361 2490
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2362 2491
 	$groups = array_merge($board_info['groups'], array(1));
2363 2492
 
2364
-	if (isset($_POST['membergroups']))
2365
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2493
+	if (isset($_POST['membergroups'])) {
2494
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2495
+	}
2366 2496
 
2367 2497
 	// Check whether at least one membergroup was selected.
2368
-	if (empty($_POST['who']))
2369
-		fatal_lang_error('no_membergroup_selected');
2498
+	if (empty($_POST['who'])) {
2499
+			fatal_lang_error('no_membergroup_selected');
2500
+	}
2370 2501
 
2371 2502
 	// Make sure all membergroups are integers and can access the board of the announcement.
2372
-	foreach ($_POST['who'] as $id => $mg)
2373
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2503
+	foreach ($_POST['who'] as $id => $mg) {
2504
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2505
+	}
2374 2506
 
2375 2507
 	// Get the topic subject and censor it.
2376 2508
 	$request = $smcFunc['db_query']('', '
@@ -2416,12 +2548,13 @@  discard block
 block discarded – undo
2416 2548
 	if ($smcFunc['db_num_rows']($request) == 0)
2417 2549
 	{
2418 2550
 		logAction('announce_topic', array('topic' => $topic), 'user');
2419
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2420
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2421
-		elseif (!empty($_REQUEST['goback']))
2422
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2423
-		else
2424
-			redirectexit('board=' . $board . '.0');
2551
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2552
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2553
+		} elseif (!empty($_REQUEST['goback'])) {
2554
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2555
+		} else {
2556
+					redirectexit('board=' . $board . '.0');
2557
+		}
2425 2558
 	}
2426 2559
 
2427 2560
 	$announcements = array();
@@ -2440,8 +2573,9 @@  discard block
 block discarded – undo
2440 2573
 	foreach ($rows as $row)
2441 2574
 	{
2442 2575
 		// Force them to have it?
2443
-		if (empty($prefs[$row['id_member']]['announcements']))
2444
-			continue;
2576
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2577
+					continue;
2578
+		}
2445 2579
 
2446 2580
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2447 2581
 
@@ -2469,8 +2603,9 @@  discard block
 block discarded – undo
2469 2603
 	}
2470 2604
 
2471 2605
 	// For each language send a different mail - low priority...
2472
-	foreach ($announcements as $lang => $mail)
2473
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2606
+	foreach ($announcements as $lang => $mail) {
2607
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2608
+	}
2474 2609
 
2475 2610
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2476 2611
 
@@ -2480,9 +2615,10 @@  discard block
 block discarded – undo
2480 2615
 	$context['sub_template'] = 'announcement_send';
2481 2616
 
2482 2617
 	// Go back to the correct language for the user ;).
2483
-	if (!empty($modSettings['userLanguage']))
2484
-		loadLanguage('Post');
2485
-}
2618
+	if (!empty($modSettings['userLanguage'])) {
2619
+			loadLanguage('Post');
2620
+	}
2621
+	}
2486 2622
 
2487 2623
 /**
2488 2624
  * Get the topic for display purposes.
@@ -2495,12 +2631,13 @@  discard block
 block discarded – undo
2495 2631
 {
2496 2632
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2497 2633
 
2498
-	if (isset($_REQUEST['xml']))
2499
-		$limit = '
2634
+	if (isset($_REQUEST['xml'])) {
2635
+			$limit = '
2500 2636
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2501
-	else
2502
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2637
+	} else {
2638
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2503 2639
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2640
+	}
2504 2641
 
2505 2642
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2506 2643
 	$request = $smcFunc['db_query']('', '
@@ -2538,8 +2675,9 @@  discard block
 block discarded – undo
2538 2675
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2539 2676
 		);
2540 2677
 
2541
-		if (!empty($context['new_replies']))
2542
-			$context['new_replies']--;
2678
+		if (!empty($context['new_replies'])) {
2679
+					$context['new_replies']--;
2680
+		}
2543 2681
 	}
2544 2682
 	$smcFunc['db_free_result']($request);
2545 2683
 }
@@ -2556,8 +2694,9 @@  discard block
 block discarded – undo
2556 2694
 	global $sourcedir, $smcFunc;
2557 2695
 
2558 2696
 	loadLanguage('Post');
2559
-	if (!isset($_REQUEST['xml']))
2560
-		loadTemplate('Post');
2697
+	if (!isset($_REQUEST['xml'])) {
2698
+			loadTemplate('Post');
2699
+	}
2561 2700
 
2562 2701
 	include_once($sourcedir . '/Subs-Post.php');
2563 2702
 
@@ -2588,8 +2727,9 @@  discard block
 block discarded – undo
2588 2727
 	$smcFunc['db_free_result']($request);
2589 2728
 
2590 2729
 	$context['sub_template'] = 'quotefast';
2591
-	if (!empty($row))
2592
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2730
+	if (!empty($row)) {
2731
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2732
+	}
2593 2733
 
2594 2734
 	if (!empty($can_view_post))
2595 2735
 	{
@@ -2622,8 +2762,9 @@  discard block
 block discarded – undo
2622 2762
 		}
2623 2763
 
2624 2764
 		// Remove any nested quotes.
2625
-		if (!empty($modSettings['removeNestedQuotes']))
2626
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2765
+		if (!empty($modSettings['removeNestedQuotes'])) {
2766
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2767
+		}
2627 2768
 
2628 2769
 		$lb = "\n";
2629 2770
 
@@ -2649,14 +2790,14 @@  discard block
 block discarded – undo
2649 2790
 				'time' => '',
2650 2791
 			),
2651 2792
 		);
2652
-	}
2653
-	else
2654
-		$context['quote'] = array(
2793
+	} else {
2794
+			$context['quote'] = array(
2655 2795
 			'xml' => '',
2656 2796
 			'mozilla' => '',
2657 2797
 			'text' => '',
2658 2798
 		);
2659
-}
2799
+	}
2800
+	}
2660 2801
 
2661 2802
 /**
2662 2803
  * Used to edit the body or subject of a message inline
@@ -2668,8 +2809,9 @@  discard block
 block discarded – undo
2668 2809
 	global $user_info, $context, $smcFunc, $language, $board_info;
2669 2810
 
2670 2811
 	// We have to have a topic!
2671
-	if (empty($topic))
2672
-		obExit(false);
2812
+	if (empty($topic)) {
2813
+			obExit(false);
2814
+	}
2673 2815
 
2674 2816
 	checkSession('get');
2675 2817
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2695,31 +2837,35 @@  discard block
 block discarded – undo
2695 2837
 			'guest_id' => 0,
2696 2838
 		)
2697 2839
 	);
2698
-	if ($smcFunc['db_num_rows']($request) == 0)
2699
-		fatal_lang_error('no_board', false);
2840
+	if ($smcFunc['db_num_rows']($request) == 0) {
2841
+			fatal_lang_error('no_board', false);
2842
+	}
2700 2843
 	$row = $smcFunc['db_fetch_assoc']($request);
2701 2844
 	$smcFunc['db_free_result']($request);
2702 2845
 
2703 2846
 	// Change either body or subject requires permissions to modify messages.
2704 2847
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2705 2848
 	{
2706
-		if (!empty($row['locked']))
2707
-			isAllowedTo('moderate_board');
2849
+		if (!empty($row['locked'])) {
2850
+					isAllowedTo('moderate_board');
2851
+		}
2708 2852
 
2709 2853
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2710 2854
 		{
2711
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2712
-				fatal_lang_error('modify_post_time_passed', false);
2713
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2714
-				isAllowedTo('modify_replies');
2715
-			else
2716
-				isAllowedTo('modify_own');
2855
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2856
+							fatal_lang_error('modify_post_time_passed', false);
2857
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2858
+							isAllowedTo('modify_replies');
2859
+			} else {
2860
+							isAllowedTo('modify_own');
2861
+			}
2717 2862
 		}
2718 2863
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2719
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2720
-			isAllowedTo('modify_replies');
2721
-		else
2722
-			isAllowedTo('modify_any');
2864
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2865
+					isAllowedTo('modify_replies');
2866
+		} else {
2867
+					isAllowedTo('modify_any');
2868
+		}
2723 2869
 
2724 2870
 		// Only log this action if it wasn't your message.
2725 2871
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2731,10 +2877,10 @@  discard block
 block discarded – undo
2731 2877
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2732 2878
 
2733 2879
 		// Maximum number of characters.
2734
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2735
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2736
-	}
2737
-	elseif (isset($_POST['subject']))
2880
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2881
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2882
+		}
2883
+	} elseif (isset($_POST['subject']))
2738 2884
 	{
2739 2885
 		$post_errors[] = 'no_subject';
2740 2886
 		unset($_POST['subject']);
@@ -2746,13 +2892,11 @@  discard block
 block discarded – undo
2746 2892
 		{
2747 2893
 			$post_errors[] = 'no_message';
2748 2894
 			unset($_POST['message']);
2749
-		}
2750
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2895
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2751 2896
 		{
2752 2897
 			$post_errors[] = 'long_message';
2753 2898
 			unset($_POST['message']);
2754
-		}
2755
-		else
2899
+		} else
2756 2900
 		{
2757 2901
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2758 2902
 
@@ -2768,31 +2912,34 @@  discard block
 block discarded – undo
2768 2912
 
2769 2913
 	if (isset($_POST['lock']))
2770 2914
 	{
2771
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2772
-			unset($_POST['lock']);
2773
-		elseif (!allowedTo('lock_any'))
2915
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
2916
+					unset($_POST['lock']);
2917
+		} elseif (!allowedTo('lock_any'))
2774 2918
 		{
2775
-			if ($row['locked'] == 1)
2776
-				unset($_POST['lock']);
2777
-			else
2778
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2919
+			if ($row['locked'] == 1) {
2920
+							unset($_POST['lock']);
2921
+			} else {
2922
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2923
+			}
2924
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
2925
+					unset($_POST['lock']);
2926
+		} else {
2927
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2779 2928
 		}
2780
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2781
-			unset($_POST['lock']);
2782
-		else
2783
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2784 2929
 	}
2785 2930
 
2786
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2787
-		unset($_POST['sticky']);
2931
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
2932
+			unset($_POST['sticky']);
2933
+	}
2788 2934
 
2789 2935
 	if (isset($_POST['modify_reason']))
2790 2936
 	{
2791 2937
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2792 2938
 
2793 2939
 		// Maximum number of characters.
2794
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2795
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2940
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2941
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2942
+		}
2796 2943
 	}
2797 2944
 
2798 2945
 	if (empty($post_errors))
@@ -2829,8 +2976,9 @@  discard block
 block discarded – undo
2829 2976
 			}
2830 2977
 		}
2831 2978
 		// If nothing was changed there's no need to add an entry to the moderation log.
2832
-		else
2833
-			$moderationAction = false;
2979
+		else {
2980
+					$moderationAction = false;
2981
+		}
2834 2982
 
2835 2983
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2836 2984
 
@@ -2848,9 +2996,9 @@  discard block
 block discarded – undo
2848 2996
 			// Get the proper (default language) response prefix first.
2849 2997
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2850 2998
 			{
2851
-				if ($language === $user_info['language'])
2852
-					$context['response_prefix'] = $txt['response_prefix'];
2853
-				else
2999
+				if ($language === $user_info['language']) {
3000
+									$context['response_prefix'] = $txt['response_prefix'];
3001
+				} else
2854 3002
 				{
2855 3003
 					loadLanguage('index', $language, false);
2856 3004
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2872,8 +3020,9 @@  discard block
 block discarded – undo
2872 3020
 			);
2873 3021
 		}
2874 3022
 
2875
-		if (!empty($moderationAction))
2876
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3023
+		if (!empty($moderationAction)) {
3024
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3025
+		}
2877 3026
 	}
2878 3027
 
2879 3028
 	if (isset($_REQUEST['xml']))
@@ -2914,8 +3063,7 @@  discard block
 block discarded – undo
2914 3063
 			);
2915 3064
 
2916 3065
 			censorText($context['message']['subject']);
2917
-		}
2918
-		else
3066
+		} else
2919 3067
 		{
2920 3068
 			$context['message'] = array(
2921 3069
 				'id' => $row['id_msg'],
@@ -2927,15 +3075,16 @@  discard block
 block discarded – undo
2927 3075
 			loadLanguage('Errors');
2928 3076
 			foreach ($post_errors as $post_error)
2929 3077
 			{
2930
-				if ($post_error == 'long_message')
2931
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
2932
-				else
2933
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3078
+				if ($post_error == 'long_message') {
3079
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3080
+				} else {
3081
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3082
+				}
2934 3083
 			}
2935 3084
 		}
3085
+	} else {
3086
+			obExit(false);
3087
+	}
2936 3088
 	}
2937
-	else
2938
-		obExit(false);
2939
-}
2940 3089
 
2941 3090
 ?>
2942 3091
\ No newline at end of file
Please login to merge, or discard this patch.