Completed
Pull Request — release-2.1 (#4090)
by Rick
08:20
created
other/upgrade.php 1 patch
Braces   +874 added lines, -642 removed lines patch added patch discarded remove patch
@@ -72,8 +72,9 @@  discard block
 block discarded – undo
72 72
 $upcontext['inactive_timeout'] = 10;
73 73
 
74 74
 // The helper is crucial. Include it first thing.
75
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
75
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
76 76
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
77
+}
77 78
 
78 79
 require_once($upgrade_path . '/upgrade-helper.php');
79 80
 
@@ -97,11 +98,14 @@  discard block
 block discarded – undo
97 98
 	ini_set('default_socket_timeout', 900);
98 99
 }
99 100
 // Clean the upgrade path if this is from the client.
100
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
101
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
101
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
102
+	for ($i = 1;
103
+}
104
+$i < $_SERVER['argc']; $i++)
102 105
 	{
103
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
104
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
106
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
107
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
108
+		}
105 109
 	}
106 110
 
107 111
 // Are we from the client?
@@ -109,16 +113,17 @@  discard block
 block discarded – undo
109 113
 {
110 114
 	$command_line = true;
111 115
 	$disable_security = true;
112
-}
113
-else
116
+} else {
114 117
 	$command_line = false;
118
+}
115 119
 
116 120
 // Load this now just because we can.
117 121
 require_once($upgrade_path . '/Settings.php');
118 122
 
119 123
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
120
-if (isset($language))
124
+if (isset($language)) {
121 125
 	$language = str_ireplace('-utf8', '', $language);
126
+}
122 127
 
123 128
 // Are we logged in?
124 129
 if (isset($upgradeData))
@@ -126,10 +131,12 @@  discard block
 block discarded – undo
126 131
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
127 132
 
128 133
 	// Check for sensible values.
129
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
130
-		$upcontext['user']['started'] = time();
131
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
132
-		$upcontext['user']['updated'] = 0;
134
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
135
+			$upcontext['user']['started'] = time();
136
+	}
137
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
138
+			$upcontext['user']['updated'] = 0;
139
+	}
133 140
 
134 141
 	$upcontext['started'] = $upcontext['user']['started'];
135 142
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -187,8 +194,9 @@  discard block
 block discarded – undo
187 194
 			'db_error_skip' => true,
188 195
 		)
189 196
 	);
190
-	while ($row = $smcFunc['db_fetch_assoc']($request))
191
-		$modSettings[$row['variable']] = $row['value'];
197
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
198
+			$modSettings[$row['variable']] = $row['value'];
199
+	}
192 200
 	$smcFunc['db_free_result']($request);
193 201
 }
194 202
 
@@ -198,10 +206,12 @@  discard block
 block discarded – undo
198 206
 	$modSettings['theme_url'] = 'Themes/default';
199 207
 	$modSettings['images_url'] = 'Themes/default/images';
200 208
 }
201
-if (!isset($settings['default_theme_url']))
209
+if (!isset($settings['default_theme_url'])) {
202 210
 	$settings['default_theme_url'] = $modSettings['theme_url'];
203
-if (!isset($settings['default_theme_dir']))
211
+}
212
+if (!isset($settings['default_theme_dir'])) {
204 213
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
214
+}
205 215
 
206 216
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
207 217
 // Default title...
@@ -219,13 +229,15 @@  discard block
 block discarded – undo
219 229
 	$support_js = $upcontext['upgrade_status']['js'];
220 230
 
221 231
 	// Only set this if the upgrader status says so.
222
-	if (empty($is_debug))
223
-		$is_debug = $upcontext['upgrade_status']['debug'];
232
+	if (empty($is_debug)) {
233
+			$is_debug = $upcontext['upgrade_status']['debug'];
234
+	}
224 235
 
225 236
 	// Load the language.
226
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
227
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
228
-}
237
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
238
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
239
+	}
240
+	}
229 241
 // Set the defaults.
230 242
 else
231 243
 {
@@ -243,15 +255,18 @@  discard block
 block discarded – undo
243 255
 }
244 256
 
245 257
 // If this isn't the first stage see whether they are logging in and resuming.
246
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
258
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
247 259
 	checkLogin();
260
+}
248 261
 
249
-if ($command_line)
262
+if ($command_line) {
250 263
 	cmdStep0();
264
+}
251 265
 
252 266
 // Don't error if we're using xml.
253
-if (isset($_GET['xml']))
267
+if (isset($_GET['xml'])) {
254 268
 	$upcontext['return_error'] = true;
269
+}
255 270
 
256 271
 // Loop through all the steps doing each one as required.
257 272
 $upcontext['overall_percent'] = 0;
@@ -272,9 +287,9 @@  discard block
 block discarded – undo
272 287
 		}
273 288
 
274 289
 		// Call the step and if it returns false that means pause!
275
-		if (function_exists($step[2]) && $step[2]() === false)
276
-			break;
277
-		elseif (function_exists($step[2])) {
290
+		if (function_exists($step[2]) && $step[2]() === false) {
291
+					break;
292
+		} elseif (function_exists($step[2])) {
278 293
 			//Start each new step with this unset, so the 'normal' template is called first
279 294
 			unset($_GET['xml']);
280 295
 			$_GET['substep'] = 0;
@@ -318,17 +333,18 @@  discard block
 block discarded – undo
318 333
 		// This should not happen my dear... HELP ME DEVELOPERS!!
319 334
 		if (!empty($command_line))
320 335
 		{
321
-			if (function_exists('debug_print_backtrace'))
322
-				debug_print_backtrace();
336
+			if (function_exists('debug_print_backtrace')) {
337
+							debug_print_backtrace();
338
+			}
323 339
 
324 340
 			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.';
325 341
 			flush();
326 342
 			die();
327 343
 		}
328 344
 
329
-		if (!isset($_GET['xml']))
330
-			template_upgrade_above();
331
-		else
345
+		if (!isset($_GET['xml'])) {
346
+					template_upgrade_above();
347
+		} else
332 348
 		{
333 349
 			header('Content-Type: text/xml; charset=UTF-8');
334 350
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -350,25 +366,29 @@  discard block
 block discarded – undo
350 366
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
351 367
 
352 368
 			// Custom stuff to pass back?
353
-			if (!empty($upcontext['query_string']))
354
-				$upcontext['form_url'] .= $upcontext['query_string'];
369
+			if (!empty($upcontext['query_string'])) {
370
+							$upcontext['form_url'] .= $upcontext['query_string'];
371
+			}
355 372
 
356 373
 			// Call the appropriate subtemplate
357
-			if (is_callable('template_' . $upcontext['sub_template']))
358
-				call_user_func('template_' . $upcontext['sub_template']);
359
-			else
360
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
374
+			if (is_callable('template_' . $upcontext['sub_template'])) {
375
+							call_user_func('template_' . $upcontext['sub_template']);
376
+			} else {
377
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
378
+			}
361 379
 		}
362 380
 
363 381
 		// Was there an error?
364
-		if (!empty($upcontext['forced_error_message']))
365
-			echo $upcontext['forced_error_message'];
382
+		if (!empty($upcontext['forced_error_message'])) {
383
+					echo $upcontext['forced_error_message'];
384
+		}
366 385
 
367 386
 		// Show the footer.
368
-		if (!isset($_GET['xml']))
369
-			template_upgrade_below();
370
-		else
371
-			template_xml_below();
387
+		if (!isset($_GET['xml'])) {
388
+					template_upgrade_below();
389
+		} else {
390
+					template_xml_below();
391
+		}
372 392
 	}
373 393
 
374 394
 
@@ -380,15 +400,19 @@  discard block
 block discarded – undo
380 400
 		$seconds = intval($active % 60);
381 401
 
382 402
 		$totalTime = '';
383
-		if ($hours > 0)
384
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
385
-		if ($minutes > 0)
386
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
387
-		if ($seconds > 0)
388
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
403
+		if ($hours > 0) {
404
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
405
+		}
406
+		if ($minutes > 0) {
407
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
408
+		}
409
+		if ($seconds > 0) {
410
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
411
+		}
389 412
 
390
-		if (!empty($totalTime))
391
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
413
+		if (!empty($totalTime)) {
414
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
415
+		}
392 416
 	}
393 417
 
394 418
 	// Bang - gone!
@@ -401,8 +425,9 @@  discard block
 block discarded – undo
401 425
 	global $upgradeurl, $upcontext, $command_line;
402 426
 
403 427
 	// Command line users can't be redirected.
404
-	if ($command_line)
405
-		upgradeExit(true);
428
+	if ($command_line) {
429
+			upgradeExit(true);
430
+	}
406 431
 
407 432
 	// Are we providing the core info?
408 433
 	if ($addForm)
@@ -429,12 +454,14 @@  discard block
 block discarded – undo
429 454
 	define('SMF', 1);
430 455
 
431 456
 	// Start the session.
432
-	if (@ini_get('session.save_handler') == 'user')
433
-		@ini_set('session.save_handler', 'files');
457
+	if (@ini_get('session.save_handler') == 'user') {
458
+			@ini_set('session.save_handler', 'files');
459
+	}
434 460
 	@session_start();
435 461
 
436
-	if (empty($smcFunc))
437
-		$smcFunc = array();
462
+	if (empty($smcFunc)) {
463
+			$smcFunc = array();
464
+	}
438 465
 
439 466
 	// We need this for authentication and some upgrade code
440 467
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -446,32 +473,36 @@  discard block
 block discarded – undo
446 473
 	initialize_inputs();
447 474
 
448 475
 	// Get the database going!
449
-	if (empty($db_type) || $db_type == 'mysqli')
450
-		$db_type = 'mysql';
476
+	if (empty($db_type) || $db_type == 'mysqli') {
477
+			$db_type = 'mysql';
478
+	}
451 479
 
452 480
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
453 481
 	{
454 482
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
455 483
 
456 484
 		// Make the connection...
457
-		if (empty($db_connection))
458
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
459
-		else
460
-			// If we've returned here, ping/reconnect to be safe
485
+		if (empty($db_connection)) {
486
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
487
+		} else {
488
+					// If we've returned here, ping/reconnect to be safe
461 489
 			$smcFunc['db_ping']($db_connection);
490
+		}
462 491
 
463 492
 		// Oh dear god!!
464
-		if ($db_connection === null)
465
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
493
+		if ($db_connection === null) {
494
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		}
466 496
 
467
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
468
-			$smcFunc['db_query']('', '
497
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
498
+					$smcFunc['db_query']('', '
469 499
 			SET NAMES {string:db_character_set}',
470 500
 			array(
471 501
 				'db_error_skip' => true,
472 502
 				'db_character_set' => $db_character_set,
473 503
 			)
474 504
 		);
505
+		}
475 506
 
476 507
 		// Load the modSettings data...
477 508
 		$request = $smcFunc['db_query']('', '
@@ -482,11 +513,11 @@  discard block
 block discarded – undo
482 513
 			)
483 514
 		);
484 515
 		$modSettings = array();
485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
486
-			$modSettings[$row['variable']] = $row['value'];
516
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
517
+					$modSettings[$row['variable']] = $row['value'];
518
+		}
487 519
 		$smcFunc['db_free_result']($request);
488
-	}
489
-	else
520
+	} else
490 521
 	{
491 522
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
492 523
 	}
@@ -500,9 +531,10 @@  discard block
 block discarded – undo
500 531
 		cleanRequest();
501 532
 	}
502 533
 
503
-	if (!isset($_GET['substep']))
504
-		$_GET['substep'] = 0;
505
-}
534
+	if (!isset($_GET['substep'])) {
535
+			$_GET['substep'] = 0;
536
+	}
537
+	}
506 538
 
507 539
 function initialize_inputs()
508 540
 {
@@ -532,8 +564,9 @@  discard block
 block discarded – undo
532 564
 		$dh = opendir(dirname(__FILE__));
533 565
 		while ($file = readdir($dh))
534 566
 		{
535
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
536
-				@unlink(dirname(__FILE__) . '/' . $file);
567
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
568
+							@unlink(dirname(__FILE__) . '/' . $file);
569
+			}
537 570
 		}
538 571
 		closedir($dh);
539 572
 
@@ -562,8 +595,9 @@  discard block
 block discarded – undo
562 595
 	$temp = 'upgrade_php?step';
563 596
 	while (strlen($temp) > 4)
564 597
 	{
565
-		if (isset($_GET[$temp]))
566
-			unset($_GET[$temp]);
598
+		if (isset($_GET[$temp])) {
599
+					unset($_GET[$temp]);
600
+		}
567 601
 		$temp = substr($temp, 1);
568 602
 	}
569 603
 
@@ -590,32 +624,39 @@  discard block
 block discarded – undo
590 624
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
591 625
 
592 626
 	// Need legacy scripts?
593
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
594
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
595
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
596
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
597
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
598
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
627
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
628
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
629
+	}
630
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
631
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
632
+	}
633
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
634
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
635
+	}
599 636
 
600 637
 	// We don't need "-utf8" files anymore...
601 638
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
602 639
 
603 640
 	// This needs to exist!
604
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
605
-		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>]');
606
-	else
607
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
641
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
642
+			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>]');
643
+	} else {
644
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
645
+	}
608 646
 
609
-	if (!$check)
610
-		// 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.
647
+	if (!$check) {
648
+			// 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.
611 649
 		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.');
650
+	}
612 651
 
613 652
 	// Do they meet the install requirements?
614
-	if (!php_version_check())
615
-		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.');
653
+	if (!php_version_check()) {
654
+			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.');
655
+	}
616 656
 
617
-	if (!db_version_check())
618
-		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.');
657
+	if (!db_version_check()) {
658
+			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.');
659
+	}
619 660
 
620 661
 	// Do some checks to make sure they have proper privileges
621 662
 	db_extend('packages');
@@ -630,14 +671,16 @@  discard block
 block discarded – undo
630 671
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
631 672
 
632 673
 	// Sorry... we need CREATE, ALTER and DROP
633
-	if (!$create || !$alter || !$drop)
634
-		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.');
674
+	if (!$create || !$alter || !$drop) {
675
+			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.');
676
+	}
635 677
 
636 678
 	// Do a quick version spot check.
637 679
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
638 680
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
639
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
640
-		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.');
681
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
682
+			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.');
683
+	}
641 684
 
642 685
 	// What absolutely needs to be writable?
643 686
 	$writable_files = array(
@@ -659,12 +702,13 @@  discard block
 block discarded – undo
659 702
 	quickFileWritable($custom_av_dir);
660 703
 
661 704
 	// Are we good now?
662
-	if (!is_writable($custom_av_dir))
663
-		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));
664
-	elseif ($need_settings_update)
705
+	if (!is_writable($custom_av_dir)) {
706
+			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));
707
+	} elseif ($need_settings_update)
665 708
 	{
666
-		if (!function_exists('cache_put_data'))
667
-			require_once($sourcedir . '/Load.php');
709
+		if (!function_exists('cache_put_data')) {
710
+					require_once($sourcedir . '/Load.php');
711
+		}
668 712
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
669 713
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
670 714
 	}
@@ -673,28 +717,33 @@  discard block
 block discarded – undo
673 717
 
674 718
 	// Check the cache directory.
675 719
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
676
-	if (!file_exists($cachedir_temp))
677
-		@mkdir($cachedir_temp);
678
-	if (!file_exists($cachedir_temp))
679
-		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.');
680
-
681
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
682
-		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>.');
683
-	elseif (!isset($_GET['skiplang']))
720
+	if (!file_exists($cachedir_temp)) {
721
+			@mkdir($cachedir_temp);
722
+	}
723
+	if (!file_exists($cachedir_temp)) {
724
+			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.');
725
+	}
726
+
727
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
728
+			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>.');
729
+	} elseif (!isset($_GET['skiplang']))
684 730
 	{
685 731
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
686 732
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
687 733
 
688
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
689
-			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>]');
734
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
735
+					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>]');
736
+		}
690 737
 	}
691 738
 
692
-	if (!makeFilesWritable($writable_files))
693
-		return false;
739
+	if (!makeFilesWritable($writable_files)) {
740
+			return false;
741
+	}
694 742
 
695 743
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
696
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
697
-		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.');
744
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
745
+			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.');
746
+	}
698 747
 
699 748
 	// Upgrade the agreement.
700 749
 	elseif (isset($modSettings['agreement']))
@@ -705,8 +754,8 @@  discard block
 block discarded – undo
705 754
 	}
706 755
 
707 756
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
708
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
709
-		$upcontext['warning'] = '
757
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
758
+			$upcontext['warning'] = '
710 759
 			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>
711 760
 			<ul>
712 761
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -714,10 +763,12 @@  discard block
 block discarded – undo
714 763
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
715 764
 			</ul>
716 765
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
766
+	}
717 767
 
718 768
 	// Either we're logged in or we're going to present the login.
719
-	if (checkLogin())
720
-		return true;
769
+	if (checkLogin()) {
770
+			return true;
771
+	}
721 772
 
722 773
 	$upcontext += createToken('login');
723 774
 
@@ -731,15 +782,17 @@  discard block
 block discarded – undo
731 782
 	global $smcFunc, $db_type, $support_js;
732 783
 
733 784
 	// Don't bother if the security is disabled.
734
-	if ($disable_security)
735
-		return true;
785
+	if ($disable_security) {
786
+			return true;
787
+	}
736 788
 
737 789
 	// Are we trying to login?
738 790
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
739 791
 	{
740 792
 		// If we've disabled security pick a suitable name!
741
-		if (empty($_POST['user']))
742
-			$_POST['user'] = 'Administrator';
793
+		if (empty($_POST['user'])) {
794
+					$_POST['user'] = 'Administrator';
795
+		}
743 796
 
744 797
 		// Before 2.0 these column names were different!
745 798
 		$oldDB = false;
@@ -754,16 +807,17 @@  discard block
 block discarded – undo
754 807
 					'db_error_skip' => true,
755 808
 				)
756 809
 			);
757
-			if ($smcFunc['db_num_rows']($request) != 0)
758
-				$oldDB = true;
810
+			if ($smcFunc['db_num_rows']($request) != 0) {
811
+							$oldDB = true;
812
+			}
759 813
 			$smcFunc['db_free_result']($request);
760 814
 		}
761 815
 
762 816
 		// Get what we believe to be their details.
763 817
 		if (!$disable_security)
764 818
 		{
765
-			if ($oldDB)
766
-				$request = $smcFunc['db_query']('', '
819
+			if ($oldDB) {
820
+							$request = $smcFunc['db_query']('', '
767 821
 					SELECT id_member, memberName AS member_name, passwd, id_group,
768 822
 					additionalGroups AS additional_groups, lngfile
769 823
 					FROM {db_prefix}members
@@ -773,8 +827,8 @@  discard block
 block discarded – undo
773 827
 						'db_error_skip' => true,
774 828
 					)
775 829
 				);
776
-			else
777
-				$request = $smcFunc['db_query']('', '
830
+			} else {
831
+							$request = $smcFunc['db_query']('', '
778 832
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
779 833
 					FROM {db_prefix}members
780 834
 					WHERE member_name = {string:member_name}',
@@ -783,6 +837,7 @@  discard block
 block discarded – undo
783 837
 						'db_error_skip' => true,
784 838
 					)
785 839
 				);
840
+			}
786 841
 			if ($smcFunc['db_num_rows']($request) != 0)
787 842
 			{
788 843
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -790,16 +845,17 @@  discard block
 block discarded – undo
790 845
 				$groups = explode(',', $addGroups);
791 846
 				$groups[] = $id_group;
792 847
 
793
-				foreach ($groups as $k => $v)
794
-					$groups[$k] = (int) $v;
848
+				foreach ($groups as $k => $v) {
849
+									$groups[$k] = (int) $v;
850
+				}
795 851
 
796 852
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
797 853
 
798 854
 				// We don't use "-utf8" anymore...
799 855
 				$user_language = str_ireplace('-utf8', '', $user_language);
856
+			} else {
857
+							$upcontext['username_incorrect'] = true;
800 858
 			}
801
-			else
802
-				$upcontext['username_incorrect'] = true;
803 859
 			$smcFunc['db_free_result']($request);
804 860
 		}
805 861
 		$upcontext['username'] = $_POST['user'];
@@ -809,13 +865,14 @@  discard block
 block discarded – undo
809 865
 		{
810 866
 			$upcontext['upgrade_status']['js'] = 1;
811 867
 			$support_js = 1;
868
+		} else {
869
+					$support_js = 0;
812 870
 		}
813
-		else
814
-			$support_js = 0;
815 871
 
816 872
 		// Note down the version we are coming from.
817
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
818
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
873
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
874
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
875
+		}
819 876
 
820 877
 		// Didn't get anywhere?
821 878
 		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']))
@@ -849,15 +906,15 @@  discard block
 block discarded – undo
849 906
 							'db_error_skip' => true,
850 907
 						)
851 908
 					);
852
-					if ($smcFunc['db_num_rows']($request) == 0)
853
-						return throw_error('You need to be an admin to perform an upgrade!');
909
+					if ($smcFunc['db_num_rows']($request) == 0) {
910
+											return throw_error('You need to be an admin to perform an upgrade!');
911
+					}
854 912
 					$smcFunc['db_free_result']($request);
855 913
 				}
856 914
 
857 915
 				$upcontext['user']['id'] = $id_member;
858 916
 				$upcontext['user']['name'] = $name;
859
-			}
860
-			else
917
+			} else
861 918
 			{
862 919
 				$upcontext['user']['id'] = 1;
863 920
 				$upcontext['user']['name'] = 'Administrator';
@@ -873,11 +930,11 @@  discard block
 block discarded – undo
873 930
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
874 931
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
875 932
 
876
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
877
-					$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'] . '.';
878
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
879
-					$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'] . '.';
880
-				else
933
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
934
+									$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'] . '.';
935
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
936
+									$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'] . '.';
937
+				} else
881 938
 				{
882 939
 					// Set this as the new language.
883 940
 					$upcontext['language'] = $user_language;
@@ -921,8 +978,9 @@  discard block
 block discarded – undo
921 978
 	unset($member_columns);
922 979
 
923 980
 	// If we've not submitted then we're done.
924
-	if (empty($_POST['upcont']))
925
-		return false;
981
+	if (empty($_POST['upcont'])) {
982
+			return false;
983
+	}
926 984
 
927 985
 	// Firstly, if they're enabling SM stat collection just do it.
928 986
 	if (!empty($_POST['stats']) && (substr($boardurl, 0, 16) != 'http://localhost' || substr($boardurl, 0, 16) != 'https://localhost') && empty($modSettings['allow_sm_stats']))
@@ -937,25 +995,26 @@  discard block
 block discarded – undo
937 995
 			fwrite($fp, $out);
938 996
 
939 997
 			$return_data = '';
940
-			while (!feof($fp))
941
-				$return_data .= fgets($fp, 128);
998
+			while (!feof($fp)) {
999
+							$return_data .= fgets($fp, 128);
1000
+			}
942 1001
 
943 1002
 			fclose($fp);
944 1003
 
945 1004
 			// Get the unique site ID.
946 1005
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
947 1006
 
948
-			if (!empty($ID[1]))
949
-				$smcFunc['db_insert']('replace',
1007
+			if (!empty($ID[1])) {
1008
+							$smcFunc['db_insert']('replace',
950 1009
 					$db_prefix . 'settings',
951 1010
 					array('variable' => 'string', 'value' => 'string'),
952 1011
 					array('allow_sm_stats', $ID[1]),
953 1012
 					array('variable')
954 1013
 				);
1014
+			}
955 1015
 		}
956
-	}
957
-	else
958
-		$smcFunc['db_query']('', '
1016
+	} else {
1017
+			$smcFunc['db_query']('', '
959 1018
 			DELETE FROM {db_prefix}settings
960 1019
 			WHERE variable = {string:allow_sm_stats}',
961 1020
 			array(
@@ -963,6 +1022,7 @@  discard block
 block discarded – undo
963 1022
 				'db_error_skip' => true,
964 1023
 			)
965 1024
 		);
1025
+	}
966 1026
 
967 1027
 	// Deleting old karma stuff?
968 1028
 	if (!empty($_POST['delete_karma']))
@@ -977,20 +1037,22 @@  discard block
 block discarded – undo
977 1037
 		);
978 1038
 
979 1039
 		// Cleaning up old karma member settings.
980
-		if ($upcontext['karma_installed']['good'])
981
-			$smcFunc['db_query']('', '
1040
+		if ($upcontext['karma_installed']['good']) {
1041
+					$smcFunc['db_query']('', '
982 1042
 				ALTER TABLE {db_prefix}members
983 1043
 				DROP karma_good',
984 1044
 				array()
985 1045
 			);
1046
+		}
986 1047
 
987 1048
 		// Does karma bad was enable?
988
-		if ($upcontext['karma_installed']['bad'])
989
-			$smcFunc['db_query']('', '
1049
+		if ($upcontext['karma_installed']['bad']) {
1050
+					$smcFunc['db_query']('', '
990 1051
 				ALTER TABLE {db_prefix}members
991 1052
 				DROP karma_bad',
992 1053
 				array()
993 1054
 			);
1055
+		}
994 1056
 
995 1057
 		// Cleaning up old karma permissions.
996 1058
 		$smcFunc['db_query']('', '
@@ -1003,26 +1065,29 @@  discard block
 block discarded – undo
1003 1065
 	}
1004 1066
 
1005 1067
 	// Emptying the error log?
1006
-	if (!empty($_POST['empty_error']))
1007
-		$smcFunc['db_query']('truncate_table', '
1068
+	if (!empty($_POST['empty_error'])) {
1069
+			$smcFunc['db_query']('truncate_table', '
1008 1070
 			TRUNCATE {db_prefix}log_errors',
1009 1071
 			array(
1010 1072
 			)
1011 1073
 		);
1074
+	}
1012 1075
 
1013 1076
 	$changes = array();
1014 1077
 
1015 1078
 	// Add proxy settings.
1016
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1017
-		$changes += array(
1079
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1080
+			$changes += array(
1018 1081
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1019 1082
 			'image_proxy_maxsize' => 5190,
1020 1083
 			'image_proxy_enabled' => 0,
1021 1084
 		);
1085
+	}
1022 1086
 
1023 1087
 	// If we're overriding the language follow it through.
1024
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1025
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1088
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1089
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1090
+	}
1026 1091
 
1027 1092
 	if (!empty($_POST['maint']))
1028 1093
 	{
@@ -1034,30 +1099,34 @@  discard block
 block discarded – undo
1034 1099
 		{
1035 1100
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1036 1101
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1037
-		}
1038
-		else
1102
+		} else
1039 1103
 		{
1040 1104
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1041 1105
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1042 1106
 		}
1043 1107
 	}
1044 1108
 
1045
-	if ($command_line)
1046
-		echo ' * Updating Settings.php...';
1109
+	if ($command_line) {
1110
+			echo ' * Updating Settings.php...';
1111
+	}
1047 1112
 
1048 1113
 	// Fix some old paths.
1049
-	if (substr($boarddir, 0, 1) == '.')
1050
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1114
+	if (substr($boarddir, 0, 1) == '.') {
1115
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1116
+	}
1051 1117
 
1052
-	if (substr($sourcedir, 0, 1) == '.')
1053
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1118
+	if (substr($sourcedir, 0, 1) == '.') {
1119
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1120
+	}
1054 1121
 
1055
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1056
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1122
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1123
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1124
+	}
1057 1125
 
1058 1126
 	// Not had the database type added before?
1059
-	if (empty($db_type))
1060
-		$changes['db_type'] = 'mysql';
1127
+	if (empty($db_type)) {
1128
+			$changes['db_type'] = 'mysql';
1129
+	}
1061 1130
 
1062 1131
 	// If they have a "host:port" setup for the host, split that into separate values
1063 1132
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1068,32 +1137,36 @@  discard block
 block discarded – undo
1068 1137
 		$changes['db_server'] = '\'' . $db_server . '\'';
1069 1138
 
1070 1139
 		// Only set this if we're not using the default port
1071
-		if ($db_port != ini_get('mysqli.default_port'))
1072
-			$changes['db_port'] = (int) $db_port;
1073
-	}
1074
-	elseif (!empty($db_port))
1140
+		if ($db_port != ini_get('mysqli.default_port')) {
1141
+					$changes['db_port'] = (int) $db_port;
1142
+		}
1143
+	} elseif (!empty($db_port))
1075 1144
 	{
1076 1145
 		// If db_port is set and is the same as the default, set it to ''
1077 1146
 		if ($db_type == 'mysql')
1078 1147
 		{
1079
-			if ($db_port == ini_get('mysqli.default_port'))
1080
-				$changes['db_port'] = '\'\'';
1081
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1082
-				$changes['db_port'] = '\'\'';
1148
+			if ($db_port == ini_get('mysqli.default_port')) {
1149
+							$changes['db_port'] = '\'\'';
1150
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1151
+							$changes['db_port'] = '\'\'';
1152
+			}
1083 1153
 		}
1084 1154
 	}
1085 1155
 
1086 1156
 	// Maybe we haven't had this option yet?
1087
-	if (empty($packagesdir))
1088
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1157
+	if (empty($packagesdir)) {
1158
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1159
+	}
1089 1160
 
1090 1161
 	// Add support for $tasksdir var.
1091
-	if (empty($tasksdir))
1092
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1162
+	if (empty($tasksdir)) {
1163
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1164
+	}
1093 1165
 
1094 1166
 	// Make sure we fix the language as well.
1095
-	if (stristr($language, '-utf8'))
1096
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1167
+	if (stristr($language, '-utf8')) {
1168
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1169
+	}
1097 1170
 
1098 1171
 	// @todo Maybe change the cookie name if going to 1.1, too?
1099 1172
 
@@ -1101,8 +1174,9 @@  discard block
 block discarded – undo
1101 1174
 	require_once($sourcedir . '/Subs-Admin.php');
1102 1175
 	updateSettingsFile($changes);
1103 1176
 
1104
-	if ($command_line)
1105
-		echo ' Successful.' . "\n";
1177
+	if ($command_line) {
1178
+			echo ' Successful.' . "\n";
1179
+	}
1106 1180
 
1107 1181
 	// Are we doing debug?
1108 1182
 	if (isset($_POST['debug']))
@@ -1112,8 +1186,9 @@  discard block
 block discarded – undo
1112 1186
 	}
1113 1187
 
1114 1188
 	// If we're not backing up then jump one.
1115
-	if (empty($_POST['backup']))
1116
-		$upcontext['current_step']++;
1189
+	if (empty($_POST['backup'])) {
1190
+			$upcontext['current_step']++;
1191
+	}
1117 1192
 
1118 1193
 	// If we've got here then let's proceed to the next step!
1119 1194
 	return true;
@@ -1128,8 +1203,9 @@  discard block
 block discarded – undo
1128 1203
 	$upcontext['page_title'] = 'Backup Database';
1129 1204
 
1130 1205
 	// Done it already - js wise?
1131
-	if (!empty($_POST['backup_done']))
1132
-		return true;
1206
+	if (!empty($_POST['backup_done'])) {
1207
+			return true;
1208
+	}
1133 1209
 
1134 1210
 	// Some useful stuff here.
1135 1211
 	db_extend();
@@ -1143,9 +1219,10 @@  discard block
 block discarded – undo
1143 1219
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1144 1220
 
1145 1221
 	$table_names = array();
1146
-	foreach ($tables as $table)
1147
-		if (substr($table, 0, 7) !== 'backup_')
1222
+	foreach ($tables as $table) {
1223
+			if (substr($table, 0, 7) !== 'backup_')
1148 1224
 			$table_names[] = $table;
1225
+	}
1149 1226
 
1150 1227
 	$upcontext['table_count'] = count($table_names);
1151 1228
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1155,12 +1232,14 @@  discard block
 block discarded – undo
1155 1232
 	$file_steps = $upcontext['table_count'];
1156 1233
 
1157 1234
 	// What ones have we already done?
1158
-	foreach ($table_names as $id => $table)
1159
-		if ($id < $_GET['substep'])
1235
+	foreach ($table_names as $id => $table) {
1236
+			if ($id < $_GET['substep'])
1160 1237
 			$upcontext['previous_tables'][] = $table;
1238
+	}
1161 1239
 
1162
-	if ($command_line)
1163
-		echo 'Backing Up Tables.';
1240
+	if ($command_line) {
1241
+			echo 'Backing Up Tables.';
1242
+	}
1164 1243
 
1165 1244
 	// If we don't support javascript we backup here.
1166 1245
 	if (!$support_js || isset($_GET['xml']))
@@ -1179,8 +1258,9 @@  discard block
 block discarded – undo
1179 1258
 			backupTable($table_names[$substep]);
1180 1259
 
1181 1260
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1182
-			if (isset($_GET['xml']))
1183
-				return upgradeExit();
1261
+			if (isset($_GET['xml'])) {
1262
+							return upgradeExit();
1263
+			}
1184 1264
 		}
1185 1265
 
1186 1266
 		if ($command_line)
@@ -1213,9 +1293,10 @@  discard block
 block discarded – undo
1213 1293
 
1214 1294
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1215 1295
 
1216
-	if ($command_line)
1217
-		echo ' done.';
1218
-}
1296
+	if ($command_line) {
1297
+			echo ' done.';
1298
+	}
1299
+	}
1219 1300
 
1220 1301
 // Step 2: Everything.
1221 1302
 function DatabaseChanges()
@@ -1224,8 +1305,9 @@  discard block
 block discarded – undo
1224 1305
 	global $upcontext, $support_js, $db_type;
1225 1306
 
1226 1307
 	// Have we just completed this?
1227
-	if (!empty($_POST['database_done']))
1228
-		return true;
1308
+	if (!empty($_POST['database_done'])) {
1309
+			return true;
1310
+	}
1229 1311
 
1230 1312
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1231 1313
 	$upcontext['page_title'] = 'Database Changes';
@@ -1240,15 +1322,16 @@  discard block
 block discarded – undo
1240 1322
 	);
1241 1323
 
1242 1324
 	// How many files are there in total?
1243
-	if (isset($_GET['filecount']))
1244
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1245
-	else
1325
+	if (isset($_GET['filecount'])) {
1326
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1327
+	} else
1246 1328
 	{
1247 1329
 		$upcontext['file_count'] = 0;
1248 1330
 		foreach ($files as $file)
1249 1331
 		{
1250
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1251
-				$upcontext['file_count']++;
1332
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1333
+							$upcontext['file_count']++;
1334
+			}
1252 1335
 		}
1253 1336
 	}
1254 1337
 
@@ -1258,9 +1341,9 @@  discard block
 block discarded – undo
1258 1341
 	$upcontext['cur_file_num'] = 0;
1259 1342
 	foreach ($files as $file)
1260 1343
 	{
1261
-		if ($did_not_do)
1262
-			$did_not_do--;
1263
-		else
1344
+		if ($did_not_do) {
1345
+					$did_not_do--;
1346
+		} else
1264 1347
 		{
1265 1348
 			$upcontext['cur_file_num']++;
1266 1349
 			$upcontext['cur_file_name'] = $file[0];
@@ -1287,12 +1370,13 @@  discard block
 block discarded – undo
1287 1370
 					// Flag to move on to the next.
1288 1371
 					$upcontext['completed_step'] = true;
1289 1372
 					// Did we complete the whole file?
1290
-					if ($nextFile)
1291
-						$upcontext['current_debug_item_num'] = -1;
1373
+					if ($nextFile) {
1374
+											$upcontext['current_debug_item_num'] = -1;
1375
+					}
1292 1376
 					return upgradeExit();
1377
+				} elseif ($support_js) {
1378
+									break;
1293 1379
 				}
1294
-				elseif ($support_js)
1295
-					break;
1296 1380
 			}
1297 1381
 			// Set the progress bar to be right as if we had - even if we hadn't...
1298 1382
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1317,8 +1401,9 @@  discard block
 block discarded – undo
1317 1401
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1318 1402
 
1319 1403
 	// Now it's nice to have some of the basic SMF source files.
1320
-	if (!isset($_GET['ssi']) && !$command_line)
1321
-		redirectLocation('&ssi=1');
1404
+	if (!isset($_GET['ssi']) && !$command_line) {
1405
+			redirectLocation('&ssi=1');
1406
+	}
1322 1407
 
1323 1408
 	$upcontext['sub_template'] = 'upgrade_complete';
1324 1409
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1334,14 +1419,16 @@  discard block
 block discarded – undo
1334 1419
 	// Are we in maintenance mode?
1335 1420
 	if (isset($upcontext['user']['main']))
1336 1421
 	{
1337
-		if ($command_line)
1338
-			echo ' * ';
1422
+		if ($command_line) {
1423
+					echo ' * ';
1424
+		}
1339 1425
 		$upcontext['removed_maintenance'] = true;
1340 1426
 		$changes['maintenance'] = $upcontext['user']['main'];
1341 1427
 	}
1342 1428
 	// Otherwise if somehow we are in 2 let's go to 1.
1343
-	elseif (!empty($maintenance) && $maintenance == 2)
1344
-		$changes['maintenance'] = 1;
1429
+	elseif (!empty($maintenance) && $maintenance == 2) {
1430
+			$changes['maintenance'] = 1;
1431
+	}
1345 1432
 
1346 1433
 	// Wipe this out...
1347 1434
 	$upcontext['user'] = array();
@@ -1356,9 +1443,9 @@  discard block
 block discarded – undo
1356 1443
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1357 1444
 
1358 1445
 	// Now is the perfect time to fetch the SM files.
1359
-	if ($command_line)
1360
-		cli_scheduled_fetchSMfiles();
1361
-	else
1446
+	if ($command_line) {
1447
+			cli_scheduled_fetchSMfiles();
1448
+	} else
1362 1449
 	{
1363 1450
 		require_once($sourcedir . '/ScheduledTasks.php');
1364 1451
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1366,8 +1453,9 @@  discard block
 block discarded – undo
1366 1453
 	}
1367 1454
 
1368 1455
 	// Log what we've done.
1369
-	if (empty($user_info['id']))
1370
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1456
+	if (empty($user_info['id'])) {
1457
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1458
+	}
1371 1459
 
1372 1460
 	// Log the action manually, so CLI still works.
1373 1461
 	$smcFunc['db_insert']('',
@@ -1386,8 +1474,9 @@  discard block
 block discarded – undo
1386 1474
 
1387 1475
 	// Save the current database version.
1388 1476
 	$server_version = $smcFunc['db_server_info']();
1389
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1390
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1477
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1478
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1479
+	}
1391 1480
 
1392 1481
 	if ($command_line)
1393 1482
 	{
@@ -1399,8 +1488,9 @@  discard block
 block discarded – undo
1399 1488
 
1400 1489
 	// Make sure it says we're done.
1401 1490
 	$upcontext['overall_percent'] = 100;
1402
-	if (isset($upcontext['step_progress']))
1403
-		unset($upcontext['step_progress']);
1491
+	if (isset($upcontext['step_progress'])) {
1492
+			unset($upcontext['step_progress']);
1493
+	}
1404 1494
 
1405 1495
 	$_GET['substep'] = 0;
1406 1496
 	return false;
@@ -1411,8 +1501,9 @@  discard block
 block discarded – undo
1411 1501
 {
1412 1502
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1413 1503
 
1414
-	if (empty($modSettings['time_format']))
1415
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1504
+	if (empty($modSettings['time_format'])) {
1505
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1506
+	}
1416 1507
 
1417 1508
 	// What files do we want to get
1418 1509
 	$request = $smcFunc['db_query']('', '
@@ -1446,8 +1537,9 @@  discard block
 block discarded – undo
1446 1537
 		$file_data = fetch_web_data($url);
1447 1538
 
1448 1539
 		// If we got an error - give up - the site might be down.
1449
-		if ($file_data === false)
1450
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1540
+		if ($file_data === false) {
1541
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1542
+		}
1451 1543
 
1452 1544
 		// Save the file to the database.
1453 1545
 		$smcFunc['db_query']('substring', '
@@ -1489,8 +1581,9 @@  discard block
 block discarded – undo
1489 1581
 	$themeData = array();
1490 1582
 	foreach ($values as $variable => $value)
1491 1583
 	{
1492
-		if (!isset($value) || $value === null)
1493
-			$value = 0;
1584
+		if (!isset($value) || $value === null) {
1585
+					$value = 0;
1586
+		}
1494 1587
 
1495 1588
 		$themeData[] = array(0, 1, $variable, $value);
1496 1589
 	}
@@ -1519,8 +1612,9 @@  discard block
 block discarded – undo
1519 1612
 
1520 1613
 	foreach ($values as $variable => $value)
1521 1614
 	{
1522
-		if (empty($modSettings[$value[0]]))
1523
-			continue;
1615
+		if (empty($modSettings[$value[0]])) {
1616
+					continue;
1617
+		}
1524 1618
 
1525 1619
 		$smcFunc['db_query']('', '
1526 1620
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1606,19 +1700,21 @@  discard block
 block discarded – undo
1606 1700
 	set_error_handler(
1607 1701
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1608 1702
 		{
1609
-			if ($support_js)
1610
-				return true;
1611
-			else
1612
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1703
+			if ($support_js) {
1704
+							return true;
1705
+			} else {
1706
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1707
+			}
1613 1708
 		}
1614 1709
 	);
1615 1710
 
1616 1711
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1617 1712
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1618
-	if ($db_type == 'mysql')
1619
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1620
-	else
1621
-		$db_collation = '';
1713
+	if ($db_type == 'mysql') {
1714
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1715
+	} else {
1716
+			$db_collation = '';
1717
+	}
1622 1718
 
1623 1719
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1624 1720
 
@@ -1630,8 +1726,9 @@  discard block
 block discarded – undo
1630 1726
 	$last_step = '';
1631 1727
 
1632 1728
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1633
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1634
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1729
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1730
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1731
+	}
1635 1732
 
1636 1733
 	// Count the total number of steps within this file - for progress.
1637 1734
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1651,15 +1748,18 @@  discard block
 block discarded – undo
1651 1748
 		$do_current = $substep >= $_GET['substep'];
1652 1749
 
1653 1750
 		// Get rid of any comments in the beginning of the line...
1654
-		if (substr(trim($line), 0, 2) === '/*')
1655
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1751
+		if (substr(trim($line), 0, 2) === '/*') {
1752
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1753
+		}
1656 1754
 
1657 1755
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1658
-		if ($is_debug && !$support_js && $command_line)
1659
-			flush();
1756
+		if ($is_debug && !$support_js && $command_line) {
1757
+					flush();
1758
+		}
1660 1759
 
1661
-		if (trim($line) === '')
1662
-			continue;
1760
+		if (trim($line) === '') {
1761
+					continue;
1762
+		}
1663 1763
 
1664 1764
 		if (trim(substr($line, 0, 3)) === '---')
1665 1765
 		{
@@ -1669,8 +1769,9 @@  discard block
 block discarded – undo
1669 1769
 			if (trim($current_data) != '' && $type !== '}')
1670 1770
 			{
1671 1771
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1672
-				if ($command_line)
1673
-					echo $upcontext['error_message'];
1772
+				if ($command_line) {
1773
+									echo $upcontext['error_message'];
1774
+				}
1674 1775
 			}
1675 1776
 
1676 1777
 			if ($type == ' ')
@@ -1688,17 +1789,18 @@  discard block
 block discarded – undo
1688 1789
 				if ($do_current)
1689 1790
 				{
1690 1791
 					$upcontext['actioned_items'][] = $last_step;
1691
-					if ($command_line)
1692
-						echo ' * ';
1792
+					if ($command_line) {
1793
+											echo ' * ';
1794
+					}
1693 1795
 				}
1694
-			}
1695
-			elseif ($type == '#')
1796
+			} elseif ($type == '#')
1696 1797
 			{
1697 1798
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1698 1799
 
1699 1800
 				$upcontext['current_debug_item_num']++;
1700
-				if (trim($line) != '---#')
1701
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1801
+				if (trim($line) != '---#') {
1802
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1803
+				}
1702 1804
 
1703 1805
 				// Have we already done something?
1704 1806
 				if (isset($_GET['xml']) && $done_something)
@@ -1709,34 +1811,36 @@  discard block
 block discarded – undo
1709 1811
 
1710 1812
 				if ($do_current)
1711 1813
 				{
1712
-					if (trim($line) == '---#' && $command_line)
1713
-						echo ' done.', $endl;
1714
-					elseif ($command_line)
1715
-						echo ' +++ ', rtrim(substr($line, 4));
1716
-					elseif (trim($line) != '---#')
1814
+					if (trim($line) == '---#' && $command_line) {
1815
+											echo ' done.', $endl;
1816
+					} elseif ($command_line) {
1817
+											echo ' +++ ', rtrim(substr($line, 4));
1818
+					} elseif (trim($line) != '---#')
1717 1819
 					{
1718
-						if ($is_debug)
1719
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1820
+						if ($is_debug) {
1821
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1822
+						}
1720 1823
 					}
1721 1824
 				}
1722 1825
 
1723 1826
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1724 1827
 				{
1725
-					if ($command_line)
1726
-						echo ' * ';
1727
-					else
1728
-						$upcontext['actioned_items'][] = $last_step;
1828
+					if ($command_line) {
1829
+											echo ' * ';
1830
+					} else {
1831
+											$upcontext['actioned_items'][] = $last_step;
1832
+					}
1729 1833
 				}
1730 1834
 
1731 1835
 				// Small step - only if we're actually doing stuff.
1732
-				if ($do_current)
1733
-					nextSubstep(++$substep);
1734
-				else
1735
-					$substep++;
1736
-			}
1737
-			elseif ($type == '{')
1738
-				$current_type = 'code';
1739
-			elseif ($type == '}')
1836
+				if ($do_current) {
1837
+									nextSubstep(++$substep);
1838
+				} else {
1839
+									$substep++;
1840
+				}
1841
+			} elseif ($type == '{') {
1842
+							$current_type = 'code';
1843
+			} elseif ($type == '}')
1740 1844
 			{
1741 1845
 				$current_type = 'sql';
1742 1846
 
@@ -1749,8 +1853,9 @@  discard block
 block discarded – undo
1749 1853
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1750 1854
 				{
1751 1855
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1752
-					if ($command_line)
1753
-						echo $upcontext['error_message'];
1856
+					if ($command_line) {
1857
+											echo $upcontext['error_message'];
1858
+					}
1754 1859
 				}
1755 1860
 
1756 1861
 				// Done with code!
@@ -1830,8 +1935,9 @@  discard block
 block discarded – undo
1830 1935
 	$db_unbuffered = false;
1831 1936
 
1832 1937
 	// Failure?!
1833
-	if ($result !== false)
1834
-		return $result;
1938
+	if ($result !== false) {
1939
+			return $result;
1940
+	}
1835 1941
 
1836 1942
 	$db_error_message = $smcFunc['db_error']($db_connection);
1837 1943
 	// If MySQL we do something more clever.
@@ -1859,54 +1965,61 @@  discard block
 block discarded – undo
1859 1965
 			{
1860 1966
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1861 1967
 				$result = mysqli_query($db_connection, $string);
1862
-				if ($result !== false)
1863
-					return $result;
1968
+				if ($result !== false) {
1969
+									return $result;
1970
+				}
1864 1971
 			}
1865
-		}
1866
-		elseif ($mysqli_errno == 2013)
1972
+		} elseif ($mysqli_errno == 2013)
1867 1973
 		{
1868 1974
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1869 1975
 			mysqli_select_db($db_connection, $db_name);
1870 1976
 			if ($db_connection)
1871 1977
 			{
1872 1978
 				$result = mysqli_query($db_connection, $string);
1873
-				if ($result !== false)
1874
-					return $result;
1979
+				if ($result !== false) {
1980
+									return $result;
1981
+				}
1875 1982
 			}
1876 1983
 		}
1877 1984
 		// Duplicate column name... should be okay ;).
1878
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1879
-			return false;
1985
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
1986
+					return false;
1987
+		}
1880 1988
 		// Duplicate insert... make sure it's the proper type of query ;).
1881
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1882
-			return false;
1989
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
1990
+					return false;
1991
+		}
1883 1992
 		// Creating an index on a non-existent column.
1884
-		elseif ($mysqli_errno == 1072)
1885
-			return false;
1886
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1887
-			return false;
1993
+		elseif ($mysqli_errno == 1072) {
1994
+					return false;
1995
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
1996
+					return false;
1997
+		}
1888 1998
 	}
1889 1999
 	// If a table already exists don't go potty.
1890 2000
 	else
1891 2001
 	{
1892 2002
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1893 2003
 		{
1894
-			if (strpos($db_error_message, 'exist') !== false)
1895
-				return true;
1896
-		}
1897
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2004
+			if (strpos($db_error_message, 'exist') !== false) {
2005
+							return true;
2006
+			}
2007
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1898 2008
 		{
1899
-			if (strpos($db_error_message, 'duplicate') !== false)
1900
-				return true;
2009
+			if (strpos($db_error_message, 'duplicate') !== false) {
2010
+							return true;
2011
+			}
1901 2012
 		}
1902 2013
 	}
1903 2014
 
1904 2015
 	// Get the query string so we pass everything.
1905 2016
 	$query_string = '';
1906
-	foreach ($_GET as $k => $v)
1907
-		$query_string .= ';' . $k . '=' . $v;
1908
-	if (strlen($query_string) != 0)
1909
-		$query_string = '?' . substr($query_string, 1);
2017
+	foreach ($_GET as $k => $v) {
2018
+			$query_string .= ';' . $k . '=' . $v;
2019
+	}
2020
+	if (strlen($query_string) != 0) {
2021
+			$query_string = '?' . substr($query_string, 1);
2022
+	}
1910 2023
 
1911 2024
 	if ($command_line)
1912 2025
 	{
@@ -1961,16 +2074,18 @@  discard block
 block discarded – undo
1961 2074
 			{
1962 2075
 				$found |= 1;
1963 2076
 				// Do some checks on the data if we have it set.
1964
-				if (isset($change['col_type']))
1965
-					$found &= $change['col_type'] === $column['type'];
1966
-				if (isset($change['null_allowed']))
1967
-					$found &= $column['null'] == $change['null_allowed'];
1968
-				if (isset($change['default']))
1969
-					$found &= $change['default'] === $column['default'];
2077
+				if (isset($change['col_type'])) {
2078
+									$found &= $change['col_type'] === $column['type'];
2079
+				}
2080
+				if (isset($change['null_allowed'])) {
2081
+									$found &= $column['null'] == $change['null_allowed'];
2082
+				}
2083
+				if (isset($change['default'])) {
2084
+									$found &= $change['default'] === $column['default'];
2085
+				}
1970 2086
 			}
1971 2087
 		}
1972
-	}
1973
-	elseif ($change['type'] === 'index')
2088
+	} elseif ($change['type'] === 'index')
1974 2089
 	{
1975 2090
 		$request = upgrade_query('
1976 2091
 			SHOW INDEX
@@ -1979,9 +2094,10 @@  discard block
 block discarded – undo
1979 2094
 		{
1980 2095
 			$cur_index = array();
1981 2096
 
1982
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1983
-				if ($row['Key_name'] === $change['name'])
2097
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2098
+							if ($row['Key_name'] === $change['name'])
1984 2099
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2100
+			}
1985 2101
 
1986 2102
 			ksort($cur_index, SORT_NUMERIC);
1987 2103
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -1991,14 +2107,17 @@  discard block
 block discarded – undo
1991 2107
 	}
1992 2108
 
1993 2109
 	// If we're trying to add and it's added, we're done.
1994
-	if ($found && in_array($change['method'], array('add', 'change')))
1995
-		return true;
2110
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2111
+			return true;
2112
+	}
1996 2113
 	// Otherwise if we're removing and it wasn't found we're also done.
1997
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
1998
-		return true;
2114
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2115
+			return true;
2116
+	}
1999 2117
 	// Otherwise is it just a test?
2000
-	elseif ($is_test)
2001
-		return false;
2118
+	elseif ($is_test) {
2119
+			return false;
2120
+	}
2002 2121
 
2003 2122
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2004 2123
 	$running = false;
@@ -2009,8 +2128,9 @@  discard block
 block discarded – undo
2009 2128
 			SHOW FULL PROCESSLIST');
2010 2129
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2011 2130
 		{
2012
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2013
-				$found = true;
2131
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2132
+							$found = true;
2133
+			}
2014 2134
 		}
2015 2135
 
2016 2136
 		// Can't find it? Then we need to run it fools!
@@ -2022,8 +2142,9 @@  discard block
 block discarded – undo
2022 2142
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2023 2143
 				' . $change['text'], true) !== false;
2024 2144
 
2025
-			if (!$success)
2026
-				return false;
2145
+			if (!$success) {
2146
+							return false;
2147
+			}
2027 2148
 
2028 2149
 			// Return
2029 2150
 			$running = true;
@@ -2065,8 +2186,9 @@  discard block
 block discarded – undo
2065 2186
 			'db_error_skip' => true,
2066 2187
 		)
2067 2188
 	);
2068
-	if ($smcFunc['db_num_rows']($request) === 0)
2069
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2189
+	if ($smcFunc['db_num_rows']($request) === 0) {
2190
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2191
+	}
2070 2192
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2071 2193
 	$smcFunc['db_free_result']($request);
2072 2194
 
@@ -2088,18 +2210,19 @@  discard block
 block discarded – undo
2088 2210
 			)
2089 2211
 		);
2090 2212
 		// No results? Just forget it all together.
2091
-		if ($smcFunc['db_num_rows']($request) === 0)
2092
-			unset($table_row['Collation']);
2093
-		else
2094
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2213
+		if ($smcFunc['db_num_rows']($request) === 0) {
2214
+					unset($table_row['Collation']);
2215
+		} else {
2216
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2217
+		}
2095 2218
 		$smcFunc['db_free_result']($request);
2096 2219
 	}
2097 2220
 
2098 2221
 	if ($column_fix)
2099 2222
 	{
2100 2223
 		// Make sure there are no NULL's left.
2101
-		if ($null_fix)
2102
-			$smcFunc['db_query']('', '
2224
+		if ($null_fix) {
2225
+					$smcFunc['db_query']('', '
2103 2226
 				UPDATE {db_prefix}' . $change['table'] . '
2104 2227
 				SET ' . $change['column'] . ' = {string:default}
2105 2228
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2108,6 +2231,7 @@  discard block
 block discarded – undo
2108 2231
 					'db_error_skip' => true,
2109 2232
 				)
2110 2233
 			);
2234
+		}
2111 2235
 
2112 2236
 		// Do the actual alteration.
2113 2237
 		$smcFunc['db_query']('', '
@@ -2136,8 +2260,9 @@  discard block
 block discarded – undo
2136 2260
 	}
2137 2261
 
2138 2262
 	// Not a column we need to check on?
2139
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2140
-		return;
2263
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2264
+			return;
2265
+	}
2141 2266
 
2142 2267
 	// Break it up you (six|seven).
2143 2268
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2156,13 +2281,13 @@  discard block
 block discarded – undo
2156 2281
 				'new_name' => $temp[2],
2157 2282
 		));
2158 2283
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2159
-		if ($smcFunc['db_num_rows'] != 1)
2160
-			return;
2284
+		if ($smcFunc['db_num_rows'] != 1) {
2285
+					return;
2286
+		}
2161 2287
 
2162 2288
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2163 2289
 		$smcFunc['db_free_result']($request);
2164
-	}
2165
-	else
2290
+	} else
2166 2291
 	{
2167 2292
 		// Do this the old fashion, sure method way.
2168 2293
 		$request = $smcFunc['db_query']('', '
@@ -2173,21 +2298,24 @@  discard block
 block discarded – undo
2173 2298
 		));
2174 2299
 		// Mayday!
2175 2300
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2176
-		if ($smcFunc['db_num_rows'] == 0)
2177
-			return;
2301
+		if ($smcFunc['db_num_rows'] == 0) {
2302
+					return;
2303
+		}
2178 2304
 
2179 2305
 		// Oh where, oh where has my little field gone. Oh where can it be...
2180
-		while ($row = $smcFunc['db_query']($request))
2181
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2306
+		while ($row = $smcFunc['db_query']($request)) {
2307
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2182 2308
 			{
2183 2309
 				$current_type = $row['Type'];
2310
+		}
2184 2311
 				break;
2185 2312
 			}
2186 2313
 	}
2187 2314
 
2188 2315
 	// If this doesn't match, the column may of been altered for a reason.
2189
-	if (trim($current_type) != trim($temp[3]))
2190
-		$temp[3] = $current_type;
2316
+	if (trim($current_type) != trim($temp[3])) {
2317
+			$temp[3] = $current_type;
2318
+	}
2191 2319
 
2192 2320
 	// Piece this back together.
2193 2321
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2199,8 +2327,9 @@  discard block
 block discarded – undo
2199 2327
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2200 2328
 	global $step_progress, $is_debug, $upcontext;
2201 2329
 
2202
-	if ($_GET['substep'] < $substep)
2203
-		$_GET['substep'] = $substep;
2330
+	if ($_GET['substep'] < $substep) {
2331
+			$_GET['substep'] = $substep;
2332
+	}
2204 2333
 
2205 2334
 	if ($command_line)
2206 2335
 	{
@@ -2213,29 +2342,33 @@  discard block
 block discarded – undo
2213 2342
 	}
2214 2343
 
2215 2344
 	@set_time_limit(300);
2216
-	if (function_exists('apache_reset_timeout'))
2217
-		@apache_reset_timeout();
2345
+	if (function_exists('apache_reset_timeout')) {
2346
+			@apache_reset_timeout();
2347
+	}
2218 2348
 
2219
-	if (time() - $start_time <= $timeLimitThreshold)
2220
-		return;
2349
+	if (time() - $start_time <= $timeLimitThreshold) {
2350
+			return;
2351
+	}
2221 2352
 
2222 2353
 	// Do we have some custom step progress stuff?
2223 2354
 	if (!empty($step_progress))
2224 2355
 	{
2225 2356
 		$upcontext['substep_progress'] = 0;
2226 2357
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2227
-		if ($step_progress['current'] > $step_progress['total'])
2228
-			$upcontext['substep_progress'] = 99.9;
2229
-		else
2230
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2358
+		if ($step_progress['current'] > $step_progress['total']) {
2359
+					$upcontext['substep_progress'] = 99.9;
2360
+		} else {
2361
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2362
+		}
2231 2363
 
2232 2364
 		// Make it nicely rounded.
2233 2365
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2234 2366
 	}
2235 2367
 
2236 2368
 	// If this is XML we just exit right away!
2237
-	if (isset($_GET['xml']))
2238
-		return upgradeExit();
2369
+	if (isset($_GET['xml'])) {
2370
+			return upgradeExit();
2371
+	}
2239 2372
 
2240 2373
 	// We're going to pause after this!
2241 2374
 	$upcontext['pause'] = true;
@@ -2243,13 +2376,15 @@  discard block
 block discarded – undo
2243 2376
 	$upcontext['query_string'] = '';
2244 2377
 	foreach ($_GET as $k => $v)
2245 2378
 	{
2246
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2247
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2379
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2380
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2381
+		}
2248 2382
 	}
2249 2383
 
2250 2384
 	// Custom warning?
2251
-	if (!empty($custom_warning))
2252
-		$upcontext['custom_warning'] = $custom_warning;
2385
+	if (!empty($custom_warning)) {
2386
+			$upcontext['custom_warning'] = $custom_warning;
2387
+	}
2253 2388
 
2254 2389
 	upgradeExit();
2255 2390
 }
@@ -2264,25 +2399,26 @@  discard block
 block discarded – undo
2264 2399
 	ob_implicit_flush(true);
2265 2400
 	@set_time_limit(600);
2266 2401
 
2267
-	if (!isset($_SERVER['argv']))
2268
-		$_SERVER['argv'] = array();
2402
+	if (!isset($_SERVER['argv'])) {
2403
+			$_SERVER['argv'] = array();
2404
+	}
2269 2405
 	$_GET['maint'] = 1;
2270 2406
 
2271 2407
 	foreach ($_SERVER['argv'] as $i => $arg)
2272 2408
 	{
2273
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2274
-			$_GET['lang'] = $match[1];
2275
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2276
-			continue;
2277
-		elseif ($arg == '--no-maintenance')
2278
-			$_GET['maint'] = 0;
2279
-		elseif ($arg == '--debug')
2280
-			$is_debug = true;
2281
-		elseif ($arg == '--backup')
2282
-			$_POST['backup'] = 1;
2283
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2284
-			$_GET['conv'] = 1;
2285
-		elseif ($i != 0)
2409
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2410
+					$_GET['lang'] = $match[1];
2411
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2412
+					continue;
2413
+		} elseif ($arg == '--no-maintenance') {
2414
+					$_GET['maint'] = 0;
2415
+		} elseif ($arg == '--debug') {
2416
+					$is_debug = true;
2417
+		} elseif ($arg == '--backup') {
2418
+					$_POST['backup'] = 1;
2419
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2420
+					$_GET['conv'] = 1;
2421
+		} elseif ($i != 0)
2286 2422
 		{
2287 2423
 			echo 'SMF Command-line Upgrader
2288 2424
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2296,10 +2432,12 @@  discard block
 block discarded – undo
2296 2432
 		}
2297 2433
 	}
2298 2434
 
2299
-	if (!php_version_check())
2300
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2301
-	if (!db_version_check())
2302
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2435
+	if (!php_version_check()) {
2436
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2437
+	}
2438
+	if (!db_version_check()) {
2439
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2440
+	}
2303 2441
 
2304 2442
 	// Do some checks to make sure they have proper privileges
2305 2443
 	db_extend('packages');
@@ -2314,34 +2452,39 @@  discard block
 block discarded – undo
2314 2452
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2315 2453
 
2316 2454
 	// Sorry... we need CREATE, ALTER and DROP
2317
-	if (!$create || !$alter || !$drop)
2318
-		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);
2455
+	if (!$create || !$alter || !$drop) {
2456
+			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);
2457
+	}
2319 2458
 
2320 2459
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2321 2460
 		&& @file_exists($sourcedir . '/QueryString.php')
2322 2461
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2323
-	if (!$check && !isset($modSettings['smfVersion']))
2324
-		print_error('Error: Some files are missing or out-of-date.', true);
2462
+	if (!$check && !isset($modSettings['smfVersion'])) {
2463
+			print_error('Error: Some files are missing or out-of-date.', true);
2464
+	}
2325 2465
 
2326 2466
 	// Do a quick version spot check.
2327 2467
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2328 2468
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2329
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2330
-		print_error('Error: Some files have not yet been updated properly.');
2469
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2470
+			print_error('Error: Some files have not yet been updated properly.');
2471
+	}
2331 2472
 
2332 2473
 	// Make sure Settings.php is writable.
2333 2474
 		quickFileWritable($boarddir . '/Settings.php');
2334
-	if (!is_writable($boarddir . '/Settings.php'))
2335
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2475
+	if (!is_writable($boarddir . '/Settings.php')) {
2476
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2477
+	}
2336 2478
 
2337 2479
 	// Make sure Settings_bak.php is writable.
2338 2480
 		quickFileWritable($boarddir . '/Settings_bak.php');
2339
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2340
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2481
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2482
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2483
+	}
2341 2484
 
2342
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2343
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2344
-	elseif (isset($modSettings['agreement']))
2485
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2486
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2487
+	} elseif (isset($modSettings['agreement']))
2345 2488
 	{
2346 2489
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2347 2490
 		fwrite($fp, $modSettings['agreement']);
@@ -2351,31 +2494,36 @@  discard block
 block discarded – undo
2351 2494
 	// Make sure Themes is writable.
2352 2495
 	quickFileWritable($modSettings['theme_dir']);
2353 2496
 
2354
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2355
-		print_error('Error: Unable to obtain write access to "Themes".');
2497
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2498
+			print_error('Error: Unable to obtain write access to "Themes".');
2499
+	}
2356 2500
 
2357 2501
 	// Make sure cache directory exists and is writable!
2358 2502
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2359
-	if (!file_exists($cachedir_temp))
2360
-		@mkdir($cachedir_temp);
2503
+	if (!file_exists($cachedir_temp)) {
2504
+			@mkdir($cachedir_temp);
2505
+	}
2361 2506
 
2362 2507
 	// Make sure the cache temp dir is writable.
2363 2508
 	quickFileWritable($cachedir_temp);
2364 2509
 
2365
-	if (!is_writable($cachedir_temp))
2366
-		print_error('Error: Unable to obtain write access to "cache".', true);
2510
+	if (!is_writable($cachedir_temp)) {
2511
+			print_error('Error: Unable to obtain write access to "cache".', true);
2512
+	}
2367 2513
 
2368
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2369
-		print_error('Error: Unable to find language files!', true);
2370
-	else
2514
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2515
+			print_error('Error: Unable to find language files!', true);
2516
+	} else
2371 2517
 	{
2372 2518
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2373 2519
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2374 2520
 
2375
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2376
-			print_error('Error: Language files out of date.', true);
2377
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2378
-			print_error('Error: Install language is missing for selected language.', true);
2521
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2522
+					print_error('Error: Language files out of date.', true);
2523
+		}
2524
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2525
+					print_error('Error: Install language is missing for selected language.', true);
2526
+		}
2379 2527
 
2380 2528
 		// Otherwise include it!
2381 2529
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2394,8 +2542,9 @@  discard block
 block discarded – undo
2394 2542
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2395 2543
 
2396 2544
 	// Done it already?
2397
-	if (!empty($_POST['utf8_done']))
2398
-		return true;
2545
+	if (!empty($_POST['utf8_done'])) {
2546
+			return true;
2547
+	}
2399 2548
 
2400 2549
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2401 2550
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2408,8 +2557,7 @@  discard block
 block discarded – undo
2408 2557
 		);
2409 2558
 
2410 2559
 		return true;
2411
-	}
2412
-	else
2560
+	} else
2413 2561
 	{
2414 2562
 		$upcontext['page_title'] = 'Converting to UTF8';
2415 2563
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2453,8 +2601,9 @@  discard block
 block discarded – undo
2453 2601
 			)
2454 2602
 		);
2455 2603
 		$db_charsets = array();
2456
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2457
-			$db_charsets[] = $row['Charset'];
2604
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2605
+					$db_charsets[] = $row['Charset'];
2606
+		}
2458 2607
 
2459 2608
 		$smcFunc['db_free_result']($request);
2460 2609
 
@@ -2490,13 +2639,15 @@  discard block
 block discarded – undo
2490 2639
 		// If there's a fulltext index, we need to drop it first...
2491 2640
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2492 2641
 		{
2493
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2494
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2642
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2643
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2495 2644
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2645
+			}
2496 2646
 			$smcFunc['db_free_result']($request);
2497 2647
 
2498
-			if (isset($upcontext['fulltext_index']))
2499
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2648
+			if (isset($upcontext['fulltext_index'])) {
2649
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2650
+			}
2500 2651
 		}
2501 2652
 
2502 2653
 		// Drop it and make a note...
@@ -2686,8 +2837,9 @@  discard block
 block discarded – undo
2686 2837
 			$replace = '%field%';
2687 2838
 
2688 2839
 			// Build a huge REPLACE statement...
2689
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2690
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2840
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2841
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2842
+			}
2691 2843
 		}
2692 2844
 
2693 2845
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2697,9 +2849,10 @@  discard block
 block discarded – undo
2697 2849
 		$upcontext['table_count'] = count($queryTables);
2698 2850
 	
2699 2851
 		// What ones have we already done?
2700
-		foreach ($queryTables as $id => $table)
2701
-			if ($id < $_GET['substep'])
2852
+		foreach ($queryTables as $id => $table) {
2853
+					if ($id < $_GET['substep'])
2702 2854
 				$upcontext['previous_tables'][] = $table;
2855
+		}
2703 2856
 
2704 2857
 		$upcontext['cur_table_num'] = $_GET['substep'];
2705 2858
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2736,8 +2889,9 @@  discard block
 block discarded – undo
2736 2889
 			nextSubstep($substep);
2737 2890
 
2738 2891
 			// Just to make sure it doesn't time out.
2739
-			if (function_exists('apache_reset_timeout'))
2740
-				@apache_reset_timeout();
2892
+			if (function_exists('apache_reset_timeout')) {
2893
+							@apache_reset_timeout();
2894
+			}
2741 2895
 
2742 2896
 			$table_charsets = array();
2743 2897
 
@@ -2758,8 +2912,9 @@  discard block
 block discarded – undo
2758 2912
 					{
2759 2913
 						list($charset) = explode('_', $collation);
2760 2914
 
2761
-						if (!isset($table_charsets[$charset]))
2762
-							$table_charsets[$charset] = array();
2915
+						if (!isset($table_charsets[$charset])) {
2916
+													$table_charsets[$charset] = array();
2917
+						}
2763 2918
 
2764 2919
 						$table_charsets[$charset][] = $column_info;
2765 2920
 					}
@@ -2799,10 +2954,11 @@  discard block
 block discarded – undo
2799 2954
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2800 2955
 				{
2801 2956
 					$update = '';
2802
-					foreach ($table_charsets as $charset => $columns)
2803
-						foreach ($columns as $column)
2957
+					foreach ($table_charsets as $charset => $columns) {
2958
+											foreach ($columns as $column)
2804 2959
 							$update .= '
2805 2960
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2961
+					}
2806 2962
 
2807 2963
 					$smcFunc['db_query']('', '
2808 2964
 						UPDATE {raw:table_name}
@@ -2827,8 +2983,9 @@  discard block
 block discarded – undo
2827 2983
 			// Now do the actual conversion (if still needed).
2828 2984
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2829 2985
 			{
2830
-				if ($command_line)
2831
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2986
+				if ($command_line) {
2987
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2988
+				}
2832 2989
 
2833 2990
 				$smcFunc['db_query']('', '
2834 2991
 					ALTER TABLE {raw:table_name}
@@ -2838,12 +2995,14 @@  discard block
 block discarded – undo
2838 2995
 					)
2839 2996
 				);
2840 2997
 
2841
-				if ($command_line)
2842
-					echo " done.\n";
2998
+				if ($command_line) {
2999
+									echo " done.\n";
3000
+				}
2843 3001
 			}
2844 3002
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2845
-			if (isset($_GET['xml']))
2846
-				return upgradeExit();
3003
+			if (isset($_GET['xml'])) {
3004
+							return upgradeExit();
3005
+			}
2847 3006
 		}
2848 3007
 
2849 3008
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2872,8 +3031,8 @@  discard block
 block discarded – undo
2872 3031
 		);
2873 3032
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2874 3033
 		{
2875
-			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)
2876
-				$smcFunc['db_query']('', '
3034
+			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) {
3035
+							$smcFunc['db_query']('', '
2877 3036
 					UPDATE {db_prefix}log_actions
2878 3037
 					SET extra = {string:extra}
2879 3038
 					WHERE id_action = {int:current_action}',
@@ -2882,6 +3041,7 @@  discard block
 block discarded – undo
2882 3041
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2883 3042
 					)
2884 3043
 				);
3044
+			}
2885 3045
 		}
2886 3046
 		$smcFunc['db_free_result']($request);
2887 3047
 
@@ -2903,15 +3063,17 @@  discard block
 block discarded – undo
2903 3063
 	// First thing's first - did we already do this?
2904 3064
 	if (!empty($modSettings['json_done']))
2905 3065
 	{
2906
-		if ($command_line)
2907
-			return DeleteUpgrade();
2908
-		else
2909
-			return true;
3066
+		if ($command_line) {
3067
+					return DeleteUpgrade();
3068
+		} else {
3069
+					return true;
3070
+		}
2910 3071
 	}
2911 3072
 
2912 3073
 	// Done it already - js wise?
2913
-	if (!empty($_POST['json_done']))
2914
-		return true;
3074
+	if (!empty($_POST['json_done'])) {
3075
+			return true;
3076
+	}
2915 3077
 
2916 3078
 	// List of tables affected by this function
2917 3079
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2943,12 +3105,14 @@  discard block
 block discarded – undo
2943 3105
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2944 3106
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2945 3107
 
2946
-	foreach ($keys as $id => $table)
2947
-		if ($id < $_GET['substep'])
3108
+	foreach ($keys as $id => $table) {
3109
+			if ($id < $_GET['substep'])
2948 3110
 			$upcontext['previous_tables'][] = $table;
3111
+	}
2949 3112
 
2950
-	if ($command_line)
2951
-		echo 'Converting data from serialize() to json_encode().';
3113
+	if ($command_line) {
3114
+			echo 'Converting data from serialize() to json_encode().';
3115
+	}
2952 3116
 
2953 3117
 	if (!$support_js || isset($_GET['xml']))
2954 3118
 	{
@@ -2988,8 +3152,9 @@  discard block
 block discarded – undo
2988 3152
 
2989 3153
 				// Loop through and fix these...
2990 3154
 				$new_settings = array();
2991
-				if ($command_line)
2992
-					echo "\n" . 'Fixing some settings...';
3155
+				if ($command_line) {
3156
+									echo "\n" . 'Fixing some settings...';
3157
+				}
2993 3158
 
2994 3159
 				foreach ($serialized_settings as $var)
2995 3160
 				{
@@ -2997,22 +3162,24 @@  discard block
 block discarded – undo
2997 3162
 					{
2998 3163
 						// Attempt to unserialize the setting
2999 3164
 						$temp = @safe_unserialize($modSettings[$var]);
3000
-						if (!$temp && $command_line)
3001
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3002
-						elseif ($temp !== false)
3003
-							$new_settings[$var] = json_encode($temp);
3165
+						if (!$temp && $command_line) {
3166
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3167
+						} elseif ($temp !== false) {
3168
+													$new_settings[$var] = json_encode($temp);
3169
+						}
3004 3170
 					}
3005 3171
 				}
3006 3172
 
3007 3173
 				// Update everything at once
3008
-				if (!function_exists('cache_put_data'))
3009
-					require_once($sourcedir . '/Load.php');
3174
+				if (!function_exists('cache_put_data')) {
3175
+									require_once($sourcedir . '/Load.php');
3176
+				}
3010 3177
 				updateSettings($new_settings, true);
3011 3178
 
3012
-				if ($command_line)
3013
-					echo ' done.';
3014
-			}
3015
-			elseif ($table == 'themes')
3179
+				if ($command_line) {
3180
+									echo ' done.';
3181
+				}
3182
+			} elseif ($table == 'themes')
3016 3183
 			{
3017 3184
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3018 3185
 				$query = $smcFunc['db_query']('', '
@@ -3031,10 +3198,11 @@  discard block
 block discarded – undo
3031 3198
 
3032 3199
 						if ($command_line)
3033 3200
 						{
3034
-							if ($temp === false)
3035
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3036
-							else
3037
-								echo "\n" . 'Fixing admin preferences...';
3201
+							if ($temp === false) {
3202
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3203
+							} else {
3204
+															echo "\n" . 'Fixing admin preferences...';
3205
+							}
3038 3206
 						}
3039 3207
 
3040 3208
 						if ($temp !== false)
@@ -3056,15 +3224,15 @@  discard block
 block discarded – undo
3056 3224
 								)
3057 3225
 							);
3058 3226
 
3059
-							if ($command_line)
3060
-								echo ' done.';
3227
+							if ($command_line) {
3228
+															echo ' done.';
3229
+							}
3061 3230
 						}
3062 3231
 					}
3063 3232
 
3064 3233
 					$smcFunc['db_free_result']($query);
3065 3234
 				}
3066
-			}
3067
-			else
3235
+			} else
3068 3236
 			{
3069 3237
 				// First item is always the key...
3070 3238
 				$key = $info[0];
@@ -3075,8 +3243,7 @@  discard block
 block discarded – undo
3075 3243
 				{
3076 3244
 					$col_select = $info[1];
3077 3245
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3078
-				}
3079
-				else
3246
+				} else
3080 3247
 				{
3081 3248
 					$col_select = implode(', ', $info);
3082 3249
 				}
@@ -3109,8 +3276,7 @@  discard block
 block discarded – undo
3109 3276
 								if ($temp === false && $command_line)
3110 3277
 								{
3111 3278
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3112
-								}
3113
-								else
3279
+								} else
3114 3280
 								{
3115 3281
 									$row[$col] = json_encode($temp);
3116 3282
 
@@ -3135,16 +3301,18 @@  discard block
 block discarded – undo
3135 3301
 						}
3136 3302
 					}
3137 3303
 
3138
-					if ($command_line)
3139
-						echo ' done.';
3304
+					if ($command_line) {
3305
+											echo ' done.';
3306
+					}
3140 3307
 
3141 3308
 					// Free up some memory...
3142 3309
 					$smcFunc['db_free_result']($query);
3143 3310
 				}
3144 3311
 			}
3145 3312
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3146
-			if (isset($_GET['xml']))
3147
-				return upgradeExit();
3313
+			if (isset($_GET['xml'])) {
3314
+							return upgradeExit();
3315
+			}
3148 3316
 		}
3149 3317
 
3150 3318
 		if ($command_line)
@@ -3159,8 +3327,9 @@  discard block
 block discarded – undo
3159 3327
 
3160 3328
 		$_GET['substep'] = 0;
3161 3329
 		// Make sure we move on!
3162
-		if ($command_line)
3163
-			return DeleteUpgrade();
3330
+		if ($command_line) {
3331
+					return DeleteUpgrade();
3332
+		}
3164 3333
 
3165 3334
 		return true;
3166 3335
 	}
@@ -3180,14 +3349,16 @@  discard block
 block discarded – undo
3180 3349
 	global $upcontext, $txt, $settings;
3181 3350
 
3182 3351
 	// Don't call me twice!
3183
-	if (!empty($upcontext['chmod_called']))
3184
-		return;
3352
+	if (!empty($upcontext['chmod_called'])) {
3353
+			return;
3354
+	}
3185 3355
 
3186 3356
 	$upcontext['chmod_called'] = true;
3187 3357
 
3188 3358
 	// Nothing?
3189
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3190
-		return;
3359
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3360
+			return;
3361
+	}
3191 3362
 
3192 3363
 	// Was it a problem with Windows?
3193 3364
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3219,11 +3390,12 @@  discard block
 block discarded – undo
3219 3390
 					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\');
3220 3391
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3221 3392
 
3222
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3223
-		echo '
3393
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3394
+			echo '
3224 3395
 					content.write(\'<hr>\n\t\t\t\');
3225 3396
 					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\');
3226 3397
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3398
+	}
3227 3399
 
3228 3400
 	echo '
3229 3401
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3231,17 +3403,19 @@  discard block
 block discarded – undo
3231 3403
 				}
3232 3404
 			</script>';
3233 3405
 
3234
-	if (!empty($upcontext['chmod']['ftp_error']))
3235
-		echo '
3406
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3407
+			echo '
3236 3408
 			<div class="error_message red">
3237 3409
 				The following error was encountered when trying to connect:<br><br>
3238 3410
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3239 3411
 			</div>
3240 3412
 			<br>';
3413
+	}
3241 3414
 
3242
-	if (empty($upcontext['chmod_in_form']))
3243
-		echo '
3415
+	if (empty($upcontext['chmod_in_form'])) {
3416
+			echo '
3244 3417
 	<form action="', $upcontext['form_url'], '" method="post">';
3418
+	}
3245 3419
 
3246 3420
 	echo '
3247 3421
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3276,10 +3450,11 @@  discard block
 block discarded – undo
3276 3450
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3277 3451
 	</div>';
3278 3452
 
3279
-	if (empty($upcontext['chmod_in_form']))
3280
-		echo '
3453
+	if (empty($upcontext['chmod_in_form'])) {
3454
+			echo '
3281 3455
 	</form>';
3282
-}
3456
+	}
3457
+	}
3283 3458
 
3284 3459
 function template_upgrade_above()
3285 3460
 {
@@ -3339,9 +3514,10 @@  discard block
 block discarded – undo
3339 3514
 				<h2>', $txt['upgrade_progress'], '</h2>
3340 3515
 				<ul>';
3341 3516
 
3342
-	foreach ($upcontext['steps'] as $num => $step)
3343
-		echo '
3517
+	foreach ($upcontext['steps'] as $num => $step) {
3518
+			echo '
3344 3519
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3520
+	}
3345 3521
 
3346 3522
 	echo '
3347 3523
 					</ul>
@@ -3354,8 +3530,8 @@  discard block
 block discarded – undo
3354 3530
 				</div>
3355 3531
 			</div>';
3356 3532
 
3357
-	if (isset($upcontext['step_progress']))
3358
-		echo '
3533
+	if (isset($upcontext['step_progress'])) {
3534
+			echo '
3359 3535
 				<br>
3360 3536
 				<br>
3361 3537
 				<div id="progress_bar_step">
@@ -3364,6 +3540,7 @@  discard block
 block discarded – undo
3364 3540
 						<span>', $txt['upgrade_step_progress'], '</span>
3365 3541
 					</div>
3366 3542
 				</div>';
3543
+	}
3367 3544
 
3368 3545
 	echo '
3369 3546
 				<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>
@@ -3394,32 +3571,36 @@  discard block
 block discarded – undo
3394 3571
 {
3395 3572
 	global $upcontext, $txt;
3396 3573
 
3397
-	if (!empty($upcontext['pause']))
3398
-		echo '
3574
+	if (!empty($upcontext['pause'])) {
3575
+			echo '
3399 3576
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3400 3577
 
3401 3578
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3402 3579
 								<h3>
3403 3580
 									', $txt['upgrade_paused_overload'], '
3404 3581
 								</h3>';
3582
+	}
3405 3583
 
3406
-	if (!empty($upcontext['custom_warning']))
3407
-		echo '
3584
+	if (!empty($upcontext['custom_warning'])) {
3585
+			echo '
3408 3586
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3409 3587
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3410 3588
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3411 3589
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3412 3590
 								</div>';
3591
+	}
3413 3592
 
3414 3593
 	echo '
3415 3594
 								<div class="righttext" style="margin: 1ex;">';
3416 3595
 
3417
-	if (!empty($upcontext['continue']))
3418
-		echo '
3596
+	if (!empty($upcontext['continue'])) {
3597
+			echo '
3419 3598
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3420
-	if (!empty($upcontext['skip']))
3421
-		echo '
3599
+	}
3600
+	if (!empty($upcontext['skip'])) {
3601
+			echo '
3422 3602
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3603
+	}
3423 3604
 
3424 3605
 	echo '
3425 3606
 								</div>
@@ -3469,11 +3650,12 @@  discard block
 block discarded – undo
3469 3650
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3470 3651
 	<smf>';
3471 3652
 
3472
-	if (!empty($upcontext['get_data']))
3473
-		foreach ($upcontext['get_data'] as $k => $v)
3653
+	if (!empty($upcontext['get_data'])) {
3654
+			foreach ($upcontext['get_data'] as $k => $v)
3474 3655
 			echo '
3475 3656
 		<get key="', $k, '">', $v, '</get>';
3476
-}
3657
+	}
3658
+	}
3477 3659
 
3478 3660
 function template_xml_below()
3479 3661
 {
@@ -3514,8 +3696,8 @@  discard block
 block discarded – undo
3514 3696
 	template_chmod();
3515 3697
 
3516 3698
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3517
-	if ($upcontext['is_large_forum'])
3518
-		echo '
3699
+	if ($upcontext['is_large_forum']) {
3700
+			echo '
3519 3701
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3520 3702
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3521 3703
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3523,10 +3705,11 @@  discard block
 block discarded – undo
3523 3705
 				', $txt['upgrade_warning_lots_data'], '
3524 3706
 			</div>
3525 3707
 		</div>';
3708
+	}
3526 3709
 
3527 3710
 	// A warning message?
3528
-	if (!empty($upcontext['warning']))
3529
-		echo '
3711
+	if (!empty($upcontext['warning'])) {
3712
+			echo '
3530 3713
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3531 3714
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3532 3715
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3534,6 +3717,7 @@  discard block
 block discarded – undo
3534 3717
 				', $upcontext['warning'], '
3535 3718
 			</div>
3536 3719
 		</div>';
3720
+	}
3537 3721
 
3538 3722
 	// Paths are incorrect?
3539 3723
 	echo '
@@ -3549,20 +3733,22 @@  discard block
 block discarded – undo
3549 3733
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3550 3734
 	{
3551 3735
 		$ago = time() - $upcontext['started'];
3552
-		if ($ago < 60)
3553
-			$ago = $ago . ' seconds';
3554
-		elseif ($ago < 3600)
3555
-			$ago = (int) ($ago / 60) . ' minutes';
3556
-		else
3557
-			$ago = (int) ($ago / 3600) . ' hours';
3736
+		if ($ago < 60) {
3737
+					$ago = $ago . ' seconds';
3738
+		} elseif ($ago < 3600) {
3739
+					$ago = (int) ($ago / 60) . ' minutes';
3740
+		} else {
3741
+					$ago = (int) ($ago / 3600) . ' hours';
3742
+		}
3558 3743
 
3559 3744
 		$active = time() - $upcontext['updated'];
3560
-		if ($active < 60)
3561
-			$updated = $active . ' seconds';
3562
-		elseif ($active < 3600)
3563
-			$updated = (int) ($active / 60) . ' minutes';
3564
-		else
3565
-			$updated = (int) ($active / 3600) . ' hours';
3745
+		if ($active < 60) {
3746
+					$updated = $active . ' seconds';
3747
+		} elseif ($active < 3600) {
3748
+					$updated = (int) ($active / 60) . ' minutes';
3749
+		} else {
3750
+					$updated = (int) ($active / 3600) . ' hours';
3751
+		}
3566 3752
 
3567 3753
 		echo '
3568 3754
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3571,16 +3757,18 @@  discard block
 block discarded – undo
3571 3757
 			<div style="padding-left: 6ex;">
3572 3758
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3573 3759
 
3574
-		if ($active < 600)
3575
-			echo '
3760
+		if ($active < 600) {
3761
+					echo '
3576 3762
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3763
+		}
3577 3764
 
3578
-		if ($active > $upcontext['inactive_timeout'])
3579
-			echo '
3765
+		if ($active > $upcontext['inactive_timeout']) {
3766
+					echo '
3580 3767
 				<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.';
3581
-		else
3582
-			echo '
3768
+		} else {
3769
+					echo '
3583 3770
 				<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!');
3771
+		}
3584 3772
 
3585 3773
 		echo '
3586 3774
 			</div>
@@ -3596,9 +3784,10 @@  discard block
 block discarded – undo
3596 3784
 					<td>
3597 3785
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3598 3786
 
3599
-	if (!empty($upcontext['username_incorrect']))
3600
-		echo '
3787
+	if (!empty($upcontext['username_incorrect'])) {
3788
+			echo '
3601 3789
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3790
+	}
3602 3791
 
3603 3792
 	echo '
3604 3793
 					</td>
@@ -3609,9 +3798,10 @@  discard block
 block discarded – undo
3609 3798
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3610 3799
 						<input type="hidden" name="hash_passwrd" value="">';
3611 3800
 
3612
-	if (!empty($upcontext['password_failed']))
3613
-		echo '
3801
+	if (!empty($upcontext['password_failed'])) {
3802
+			echo '
3614 3803
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3804
+	}
3615 3805
 
3616 3806
 	echo '
3617 3807
 					</td>
@@ -3682,8 +3872,8 @@  discard block
 block discarded – undo
3682 3872
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3683 3873
 
3684 3874
 	// Warning message?
3685
-	if (!empty($upcontext['upgrade_options_warning']))
3686
-		echo '
3875
+	if (!empty($upcontext['upgrade_options_warning'])) {
3876
+			echo '
3687 3877
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3688 3878
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3689 3879
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3691,6 +3881,7 @@  discard block
 block discarded – undo
3691 3881
 				', $upcontext['upgrade_options_warning'], '
3692 3882
 			</div>
3693 3883
 		</div>';
3884
+	}
3694 3885
 
3695 3886
 	echo '
3696 3887
 				<table>
@@ -3733,8 +3924,8 @@  discard block
 block discarded – undo
3733 3924
 						</td>
3734 3925
 					</tr>';
3735 3926
 
3736
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3737
-		echo '
3927
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3928
+			echo '
3738 3929
 					<tr valign="top">
3739 3930
 						<td width="2%">
3740 3931
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3743,6 +3934,7 @@  discard block
 block discarded – undo
3743 3934
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3744 3935
 						</td>
3745 3936
 					</tr>';
3937
+	}
3746 3938
 
3747 3939
 	echo '
3748 3940
 					<tr valign="top">
@@ -3780,10 +3972,11 @@  discard block
 block discarded – undo
3780 3972
 			</div>';
3781 3973
 
3782 3974
 	// Dont any tables so far?
3783
-	if (!empty($upcontext['previous_tables']))
3784
-		foreach ($upcontext['previous_tables'] as $table)
3975
+	if (!empty($upcontext['previous_tables'])) {
3976
+			foreach ($upcontext['previous_tables'] as $table)
3785 3977
 			echo '
3786 3978
 			<br>Completed Table: &quot;', $table, '&quot;.';
3979
+	}
3787 3980
 
3788 3981
 	echo '
3789 3982
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3820,12 +4013,13 @@  discard block
 block discarded – undo
3820 4013
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3821 4014
 
3822 4015
 		// If debug flood the screen.
3823
-		if ($is_debug)
3824
-			echo '
4016
+		if ($is_debug) {
4017
+					echo '
3825 4018
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3826 4019
 
3827 4020
 				if (document.getElementById(\'debug_section\').scrollHeight)
3828 4021
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4022
+		}
3829 4023
 
3830 4024
 		echo '
3831 4025
 				// Get the next update...
@@ -3858,8 +4052,9 @@  discard block
 block discarded – undo
3858 4052
 {
3859 4053
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3860 4054
 
3861
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3862
-		$is_debug = true;
4055
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4056
+			$is_debug = true;
4057
+	}
3863 4058
 
3864 4059
 	echo '
3865 4060
 		<h3>Executing database changes</h3>
@@ -3874,8 +4069,9 @@  discard block
 block discarded – undo
3874 4069
 	{
3875 4070
 		foreach ($upcontext['actioned_items'] as $num => $item)
3876 4071
 		{
3877
-			if ($num != 0)
3878
-				echo ' Successful!';
4072
+			if ($num != 0) {
4073
+							echo ' Successful!';
4074
+			}
3879 4075
 			echo '<br>' . $item;
3880 4076
 		}
3881 4077
 		if (!empty($upcontext['changes_complete']))
@@ -3888,28 +4084,32 @@  discard block
 block discarded – undo
3888 4084
 				$seconds = intval($active % 60);
3889 4085
 
3890 4086
 				$totalTime = '';
3891
-				if ($hours > 0)
3892
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3893
-				if ($minutes > 0)
3894
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3895
-				if ($seconds > 0)
3896
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4087
+				if ($hours > 0) {
4088
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4089
+				}
4090
+				if ($minutes > 0) {
4091
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4092
+				}
4093
+				if ($seconds > 0) {
4094
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4095
+				}
3897 4096
 			}
3898 4097
 
3899
-			if ($is_debug && !empty($totalTime))
3900
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3901
-			else
3902
-				echo ' Successful!<br><br>';
4098
+			if ($is_debug && !empty($totalTime)) {
4099
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4100
+			} else {
4101
+							echo ' Successful!<br><br>';
4102
+			}
3903 4103
 
3904 4104
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3905 4105
 		}
3906
-	}
3907
-	else
4106
+	} else
3908 4107
 	{
3909 4108
 		// Tell them how many files we have in total.
3910
-		if ($upcontext['file_count'] > 1)
3911
-			echo '
4109
+		if ($upcontext['file_count'] > 1) {
4110
+					echo '
3912 4111
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4112
+		}
3913 4113
 
3914 4114
 		echo '
3915 4115
 		<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>
@@ -3925,19 +4125,23 @@  discard block
 block discarded – undo
3925 4125
 				$seconds = intval($active % 60);
3926 4126
 
3927 4127
 				$totalTime = '';
3928
-				if ($hours > 0)
3929
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3930
-				if ($minutes > 0)
3931
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3932
-				if ($seconds > 0)
3933
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4128
+				if ($hours > 0) {
4129
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4130
+				}
4131
+				if ($minutes > 0) {
4132
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4133
+				}
4134
+				if ($seconds > 0) {
4135
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4136
+				}
3934 4137
 			}
3935 4138
 
3936 4139
 			echo '
3937 4140
 			<br><span id="upgradeCompleted">';
3938 4141
 
3939
-			if (!empty($totalTime))
3940
-				echo 'Completed in ', $totalTime, '<br>';
4142
+			if (!empty($totalTime)) {
4143
+							echo 'Completed in ', $totalTime, '<br>';
4144
+			}
3941 4145
 
3942 4146
 			echo '</span>
3943 4147
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -3974,9 +4178,10 @@  discard block
 block discarded – undo
3974 4178
 			var getData = "";
3975 4179
 			var debugItems = ', $upcontext['debug_items'], ';';
3976 4180
 
3977
-		if ($is_debug)
3978
-			echo '
4181
+		if ($is_debug) {
4182
+					echo '
3979 4183
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4184
+		}
3980 4185
 
3981 4186
 		echo '
3982 4187
 			function getNextItem()
@@ -4016,9 +4221,10 @@  discard block
 block discarded – undo
4016 4221
 						document.getElementById("error_block").style.display = "";
4017 4222
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4018 4223
 
4019
-	if ($is_debug)
4020
-		echo '
4224
+	if ($is_debug) {
4225
+			echo '
4021 4226
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4227
+	}
4022 4228
 
4023 4229
 	echo '
4024 4230
 					}
@@ -4039,9 +4245,10 @@  discard block
 block discarded – undo
4039 4245
 						document.getElementById("error_block").style.display = "";
4040 4246
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4041 4247
 
4042
-	if ($is_debug)
4043
-		echo '
4248
+	if ($is_debug) {
4249
+			echo '
4044 4250
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4251
+	}
4045 4252
 
4046 4253
 	echo '
4047 4254
 					}
@@ -4100,8 +4307,8 @@  discard block
 block discarded – undo
4100 4307
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4101 4308
 				{';
4102 4309
 
4103
-		if ($is_debug)
4104
-			echo '
4310
+		if ($is_debug) {
4311
+					echo '
4105 4312
 					document.getElementById(\'debug_section\').style.display = "none";
4106 4313
 
4107 4314
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4119,6 +4326,7 @@  discard block
 block discarded – undo
4119 4326
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4120 4327
 
4121 4328
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4329
+		}
4122 4330
 
4123 4331
 		echo '
4124 4332
 
@@ -4126,9 +4334,10 @@  discard block
 block discarded – undo
4126 4334
 					document.getElementById(\'contbutt\').disabled = 0;
4127 4335
 					document.getElementById(\'database_done\').value = 1;';
4128 4336
 
4129
-		if ($upcontext['file_count'] > 1)
4130
-			echo '
4337
+		if ($upcontext['file_count'] > 1) {
4338
+					echo '
4131 4339
 					document.getElementById(\'info1\').style.display = "none";';
4340
+		}
4132 4341
 
4133 4342
 		echo '
4134 4343
 					document.getElementById(\'info2\').style.display = "none";
@@ -4141,9 +4350,10 @@  discard block
 block discarded – undo
4141 4350
 					lastItem = 0;
4142 4351
 					prevFile = curFile;';
4143 4352
 
4144
-		if ($is_debug)
4145
-			echo '
4353
+		if ($is_debug) {
4354
+					echo '
4146 4355
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4356
+		}
4147 4357
 
4148 4358
 		echo '
4149 4359
 					getNextItem();
@@ -4151,8 +4361,8 @@  discard block
 block discarded – undo
4151 4361
 				}';
4152 4362
 
4153 4363
 		// If debug scroll the screen.
4154
-		if ($is_debug)
4155
-			echo '
4364
+		if ($is_debug) {
4365
+					echo '
4156 4366
 				if (iLastSubStepProgress == -1)
4157 4367
 				{
4158 4368
 					// Give it consistent dots.
@@ -4171,6 +4381,7 @@  discard block
 block discarded – undo
4171 4381
 
4172 4382
 				if (document.getElementById(\'debug_section\').scrollHeight)
4173 4383
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4384
+		}
4174 4385
 
4175 4386
 		echo '
4176 4387
 				// Update the page.
@@ -4231,9 +4442,10 @@  discard block
 block discarded – undo
4231 4442
 			}';
4232 4443
 
4233 4444
 		// Start things off assuming we've not errored.
4234
-		if (empty($upcontext['error_message']))
4235
-			echo '
4445
+		if (empty($upcontext['error_message'])) {
4446
+					echo '
4236 4447
 			getNextItem();';
4448
+		}
4237 4449
 
4238 4450
 		echo '
4239 4451
 		//# sourceURL=dynamicScript-dbch.js 
@@ -4251,18 +4463,21 @@  discard block
 block discarded – undo
4251 4463
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4252 4464
 	<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>';
4253 4465
 
4254
-	if (!empty($upcontext['error_message']))
4255
-		echo '
4466
+	if (!empty($upcontext['error_message'])) {
4467
+			echo '
4256 4468
 	<error>', $upcontext['error_message'], '</error>';
4469
+	}
4257 4470
 
4258
-	if (!empty($upcontext['error_string']))
4259
-		echo '
4471
+	if (!empty($upcontext['error_string'])) {
4472
+			echo '
4260 4473
 	<sql>', $upcontext['error_string'], '</sql>';
4474
+	}
4261 4475
 
4262
-	if ($is_debug)
4263
-		echo '
4476
+	if ($is_debug) {
4477
+			echo '
4264 4478
 	<curtime>', time(), '</curtime>';
4265
-}
4479
+	}
4480
+	}
4266 4481
 
4267 4482
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4268 4483
 function template_convert_utf8()
@@ -4281,18 +4496,20 @@  discard block
 block discarded – undo
4281 4496
 			</div>';
4282 4497
 
4283 4498
 	// Done any tables so far?
4284
-	if (!empty($upcontext['previous_tables']))
4285
-		foreach ($upcontext['previous_tables'] as $table)
4499
+	if (!empty($upcontext['previous_tables'])) {
4500
+			foreach ($upcontext['previous_tables'] as $table)
4286 4501
 			echo '
4287 4502
 			<br>Completed Table: &quot;', $table, '&quot;.';
4503
+	}
4288 4504
 
4289 4505
 	echo '
4290 4506
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4291 4507
 
4292 4508
 	// If we dropped their index, let's let them know
4293
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4294
-		echo '
4509
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4510
+			echo '
4295 4511
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4512
+	}
4296 4513
 
4297 4514
 	echo '
4298 4515
 			<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>';
@@ -4328,12 +4545,13 @@  discard block
 block discarded – undo
4328 4545
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4329 4546
 
4330 4547
 		// If debug flood the screen.
4331
-		if ($is_debug)
4332
-			echo '
4548
+		if ($is_debug) {
4549
+					echo '
4333 4550
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4334 4551
 
4335 4552
 				if (document.getElementById(\'debug_section\').scrollHeight)
4336 4553
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4554
+		}
4337 4555
 
4338 4556
 		echo '
4339 4557
 				// Get the next update...
@@ -4378,19 +4596,21 @@  discard block
 block discarded – undo
4378 4596
 			</div>';
4379 4597
 
4380 4598
 	// Dont any tables so far?
4381
-	if (!empty($upcontext['previous_tables']))
4382
-		foreach ($upcontext['previous_tables'] as $table)
4599
+	if (!empty($upcontext['previous_tables'])) {
4600
+			foreach ($upcontext['previous_tables'] as $table)
4383 4601
 			echo '
4384 4602
 			<br>Completed Table: &quot;', $table, '&quot;.';
4603
+	}
4385 4604
 
4386 4605
 	echo '
4387 4606
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4388 4607
 			<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>';
4389 4608
 
4390 4609
 	// Try to make sure substep was reset.
4391
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4392
-		echo '
4610
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4611
+			echo '
4393 4612
 			<input type="hidden" name="substep" id="substep" value="0">';
4613
+	}
4394 4614
 
4395 4615
 	// Continue please!
4396 4616
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4423,12 +4643,13 @@  discard block
 block discarded – undo
4423 4643
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4424 4644
 
4425 4645
 		// If debug flood the screen.
4426
-		if ($is_debug)
4427
-			echo '
4646
+		if ($is_debug) {
4647
+					echo '
4428 4648
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4429 4649
 
4430 4650
 				if (document.getElementById(\'debug_section\').scrollHeight)
4431 4651
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4652
+		}
4432 4653
 
4433 4654
 		echo '
4434 4655
 				// Get the next update...
@@ -4464,8 +4685,8 @@  discard block
 block discarded – undo
4464 4685
 	<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>
4465 4686
 	<form action="', $boardurl, '/index.php">';
4466 4687
 
4467
-	if (!empty($upcontext['can_delete_script']))
4468
-		echo '
4688
+	if (!empty($upcontext['can_delete_script'])) {
4689
+			echo '
4469 4690
 			<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>
4470 4691
 			<script>
4471 4692
 				function doTheDelete(theCheck)
@@ -4477,6 +4698,7 @@  discard block
 block discarded – undo
4477 4698
 				}
4478 4699
 			</script>
4479 4700
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4701
+	}
4480 4702
 
4481 4703
 	$active = time() - $upcontext['started'];
4482 4704
 	$hours = floor($active / 3600);
@@ -4486,16 +4708,20 @@  discard block
 block discarded – undo
4486 4708
 	if ($is_debug)
4487 4709
 	{
4488 4710
 		$totalTime = '';
4489
-		if ($hours > 0)
4490
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4491
-		if ($minutes > 0)
4492
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4493
-		if ($seconds > 0)
4494
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4711
+		if ($hours > 0) {
4712
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4713
+		}
4714
+		if ($minutes > 0) {
4715
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4716
+		}
4717
+		if ($seconds > 0) {
4718
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4719
+		}
4495 4720
 	}
4496 4721
 
4497
-	if ($is_debug && !empty($totalTime))
4498
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4722
+	if ($is_debug && !empty($totalTime)) {
4723
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4724
+	}
4499 4725
 
4500 4726
 	echo '<br>
4501 4727
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4522,8 +4748,9 @@  discard block
 block discarded – undo
4522 4748
 
4523 4749
 	$current_substep = $_GET['substep'];
4524 4750
 
4525
-	if (empty($_GET['a']))
4526
-		$_GET['a'] = 0;
4751
+	if (empty($_GET['a'])) {
4752
+			$_GET['a'] = 0;
4753
+	}
4527 4754
 	$step_progress['name'] = 'Converting ips';
4528 4755
 	$step_progress['current'] = $_GET['a'];
4529 4756
 
@@ -4566,16 +4793,19 @@  discard block
 block discarded – undo
4566 4793
 				'empty' => '',
4567 4794
 				'limit' => $limit,
4568 4795
 		));
4569
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4570
-			$arIp[] = $row[$oldCol];
4796
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4797
+					$arIp[] = $row[$oldCol];
4798
+		}
4571 4799
 		$smcFunc['db_free_result']($request);
4572 4800
 
4573 4801
 		// Special case, null ip could keep us in a loop.
4574
-		if (is_null($arIp[0]))
4575
-			unset($arIp[0]);
4802
+		if (is_null($arIp[0])) {
4803
+					unset($arIp[0]);
4804
+		}
4576 4805
 
4577
-		if (empty($arIp))
4578
-			$is_done = true;
4806
+		if (empty($arIp)) {
4807
+					$is_done = true;
4808
+		}
4579 4809
 
4580 4810
 		$updates = array();
4581 4811
 		$cases = array();
@@ -4584,16 +4814,18 @@  discard block
 block discarded – undo
4584 4814
 		{
4585 4815
 			$arIp[$i] = trim($arIp[$i]);
4586 4816
 
4587
-			if (empty($arIp[$i]))
4588
-				continue;
4817
+			if (empty($arIp[$i])) {
4818
+							continue;
4819
+			}
4589 4820
 
4590 4821
 			$updates['ip' . $i] = $arIp[$i];
4591 4822
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4592 4823
 
4593 4824
 			if ($setSize > 0 && $i % $setSize === 0)
4594 4825
 			{
4595
-				if (count($updates) == 1)
4596
-					continue;
4826
+				if (count($updates) == 1) {
4827
+									continue;
4828
+				}
4597 4829
 
4598 4830
 				$updates['whereSet'] = array_values($updates);
4599 4831
 				$smcFunc['db_query']('', '
@@ -4627,8 +4859,7 @@  discard block
 block discarded – undo
4627 4859
 							'ip' => $ip
4628 4860
 					));
4629 4861
 				}
4630
-			}
4631
-			else
4862
+			} else
4632 4863
 			{
4633 4864
 				$updates['whereSet'] = array_values($updates);
4634 4865
 				$smcFunc['db_query']('', '
@@ -4642,9 +4873,9 @@  discard block
 block discarded – undo
4642 4873
 					$updates
4643 4874
 				);
4644 4875
 			}
4876
+		} else {
4877
+					$is_done = true;
4645 4878
 		}
4646
-		else
4647
-			$is_done = true;
4648 4879
 
4649 4880
 		$_GET['a'] += $limit;
4650 4881
 		$step_progress['current'] = $_GET['a'];
@@ -4670,10 +4901,11 @@  discard block
 block discarded – undo
4670 4901
  
4671 4902
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4672 4903
 
4673
-	if (isset($columns[$column]))
4674
-		return $columns[$column];
4675
-	else
4676
-		return null;
4677
-}
4904
+	if (isset($columns[$column])) {
4905
+			return $columns[$column];
4906
+	} else {
4907
+			return null;
4908
+	}
4909
+	}
4678 4910
 
4679 4911
 ?>
4680 4912
\ No newline at end of file
Please login to merge, or discard this patch.
SSI.php 1 patch
Braces   +426 added lines, -304 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Don't do anything if SMF is already loaded.
15
-if (defined('SMF'))
15
+if (defined('SMF')) {
16 16
 	return true;
17
+}
17 18
 
18 19
 define('SMF', 'SSI');
19 20
 
@@ -28,16 +29,18 @@  discard block
 block discarded – undo
28 29
 $time_start = microtime();
29 30
 
30 31
 // Just being safe...
31
-foreach (array('db_character_set', 'cachedir') as $variable)
32
+foreach (array('db_character_set', 'cachedir') as $variable) {
32 33
 	if (isset($GLOBALS[$variable]))
33 34
 		unset($GLOBALS[$variable]);
35
+}
34 36
 
35 37
 // Get the forum's settings for database and file paths.
36 38
 require_once(dirname(__FILE__) . '/Settings.php');
37 39
 
38 40
 // Make absolutely sure the cache directory is defined.
39
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
41
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
40 42
 	$cachedir = $boarddir . '/cache';
43
+}
41 44
 
42 45
 $ssi_error_reporting = error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
43 46
 /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
@@ -48,12 +51,14 @@  discard block
 block discarded – undo
48 51
 $ssi_on_error_method = false;
49 52
 
50 53
 // Don't do john didley if the forum's been shut down completely.
51
-if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
54
+if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
52 55
 	die($mmessage);
56
+}
53 57
 
54 58
 // Fix for using the current directory as a path.
55
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
59
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
56 60
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
61
+}
57 62
 
58 63
 // Load the important includes.
59 64
 require_once($sourcedir . '/QueryString.php');
@@ -78,34 +83,38 @@  discard block
 block discarded – undo
78 83
 cleanRequest();
79 84
 
80 85
 // Seed the random generator?
81
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
86
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
82 87
 	smf_seed_generator();
88
+}
83 89
 
84 90
 // Check on any hacking attempts.
85
-if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
91
+if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
86 92
 	die('No direct access...');
87
-elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
93
+} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) {
88 94
 	die('No direct access...');
89
-elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
95
+} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) {
90 96
 	die('No direct access...');
91
-elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
97
+} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
92 98
 	die('No direct access...');
93
-if (isset($_REQUEST['context']))
99
+}
100
+if (isset($_REQUEST['context'])) {
94 101
 	die('No direct access...');
102
+}
95 103
 
96 104
 // Gzip output? (because it must be boolean and true, this can't be hacked.)
97
-if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>='))
105
+if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) {
98 106
 	ob_start('ob_gzhandler');
99
-else
107
+} else {
100 108
 	$modSettings['enableCompressedOutput'] = '0';
109
+}
101 110
 
102 111
 // Primarily, this is to fix the URLs...
103 112
 ob_start('ob_sessrewrite');
104 113
 
105 114
 // Start the session... known to scramble SSI includes in cases...
106
-if (!headers_sent())
115
+if (!headers_sent()) {
107 116
 	loadSession();
108
-else
117
+} else
109 118
 {
110 119
 	if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
111 120
 	{
@@ -139,12 +148,14 @@  discard block
 block discarded – undo
139 148
 loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
140 149
 
141 150
 // @todo: probably not the best place, but somewhere it should be set...
142
-if (!headers_sent())
151
+if (!headers_sent()) {
143 152
 	header('Content-Type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']));
153
+}
144 154
 
145 155
 // Take care of any banning that needs to be done.
146
-if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
156
+if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
147 157
 	is_not_banned();
158
+}
148 159
 
149 160
 // Do we allow guests in here?
150 161
 if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
@@ -159,17 +170,19 @@  discard block
 block discarded – undo
159 170
 {
160 171
 	$context['template_layers'] = $ssi_layers;
161 172
 	template_header();
162
-}
163
-else
173
+} else {
164 174
 	setupThemeContext();
175
+}
165 176
 
166 177
 // Make sure they didn't muss around with the settings... but only if it's not cli.
167
-if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
178
+if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
168 179
 	trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
180
+}
169 181
 
170 182
 // Without visiting the forum this session variable might not be set on submit.
171
-if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
183
+if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
172 184
 	$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
185
+}
173 186
 
174 187
 // Have the ability to easily add functions to SSI.
175 188
 call_integration_hook('integrate_SSI');
@@ -178,11 +191,13 @@  discard block
 block discarded – undo
178 191
 if (basename($_SERVER['PHP_SELF']) == 'SSI.php')
179 192
 {
180 193
 	// You shouldn't just access SSI.php directly by URL!!
181
-	if (!isset($_GET['ssi_function']))
182
-		die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
194
+	if (!isset($_GET['ssi_function'])) {
195
+			die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
196
+	}
183 197
 	// Call a function passed by GET.
184
-	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
185
-		call_user_func('ssi_' . $_GET['ssi_function']);
198
+	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) {
199
+			call_user_func('ssi_' . $_GET['ssi_function']);
200
+	}
186 201
 	exit;
187 202
 }
188 203
 
@@ -199,9 +214,10 @@  discard block
 block discarded – undo
199 214
  */
200 215
 function ssi_shutdown()
201 216
 {
202
-	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
203
-		template_footer();
204
-}
217
+	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') {
218
+			template_footer();
219
+	}
220
+	}
205 221
 
206 222
 /**
207 223
  * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
@@ -214,15 +230,17 @@  discard block
 block discarded – undo
214 230
 
215 231
 	if ($output_method == 'echo')
216 232
 	{
217
-		if ($context['user']['is_guest'])
218
-			echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
219
-		else
220
-			echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
233
+		if ($context['user']['is_guest']) {
234
+					echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
235
+		} else {
236
+					echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
237
+		}
221 238
 	}
222 239
 	// Don't echo... then do what?!
223
-	else
224
-		return $context['user'];
225
-}
240
+	else {
241
+			return $context['user'];
242
+	}
243
+	}
226 244
 
227 245
 /**
228 246
  * Display a menu bar, like is displayed at the top of the forum.
@@ -233,12 +251,14 @@  discard block
 block discarded – undo
233 251
 {
234 252
 	global $context;
235 253
 
236
-	if ($output_method == 'echo')
237
-		template_menu();
254
+	if ($output_method == 'echo') {
255
+			template_menu();
256
+	}
238 257
 	// What else could this do?
239
-	else
240
-		return $context['menu_buttons'];
241
-}
258
+	else {
259
+			return $context['menu_buttons'];
260
+	}
261
+	}
242 262
 
243 263
 /**
244 264
  * Show a logout link.
@@ -250,20 +270,23 @@  discard block
 block discarded – undo
250 270
 {
251 271
 	global $context, $txt, $scripturl;
252 272
 
253
-	if ($redirect_to != '')
254
-		$_SESSION['logout_url'] = $redirect_to;
273
+	if ($redirect_to != '') {
274
+			$_SESSION['logout_url'] = $redirect_to;
275
+	}
255 276
 
256 277
 	// Guests can't log out.
257
-	if ($context['user']['is_guest'])
258
-		return false;
278
+	if ($context['user']['is_guest']) {
279
+			return false;
280
+	}
259 281
 
260 282
 	$link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
261 283
 
262
-	if ($output_method == 'echo')
263
-		echo $link;
264
-	else
265
-		return $link;
266
-}
284
+	if ($output_method == 'echo') {
285
+			echo $link;
286
+	} else {
287
+			return $link;
288
+	}
289
+	}
267 290
 
268 291
 /**
269 292
  * Recent post list:   [board] Subject by Poster    Date
@@ -279,17 +302,17 @@  discard block
 block discarded – undo
279 302
 	global $modSettings, $context;
280 303
 
281 304
 	// Excluding certain boards...
282
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
283
-		$exclude_boards = array($modSettings['recycle_board']);
284
-	else
285
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
305
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
306
+			$exclude_boards = array($modSettings['recycle_board']);
307
+	} else {
308
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
309
+	}
286 310
 
287 311
 	// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
288 312
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
289 313
 	{
290 314
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
291
-	}
292
-	elseif ($include_boards != null)
315
+	} elseif ($include_boards != null)
293 316
 	{
294 317
 		$include_boards = array();
295 318
 	}
@@ -326,8 +349,9 @@  discard block
 block discarded – undo
326 349
 {
327 350
 	global $modSettings;
328 351
 
329
-	if (empty($post_ids))
330
-		return;
352
+	if (empty($post_ids)) {
353
+			return;
354
+	}
331 355
 
332 356
 	// Allow the user to request more than one - why not?
333 357
 	$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
@@ -362,8 +386,9 @@  discard block
 block discarded – undo
362 386
 	global $scripturl, $txt, $user_info;
363 387
 	global $modSettings, $smcFunc, $context;
364 388
 
365
-	if (!empty($modSettings['enable_likes']))
366
-		$context['can_like'] = allowedTo('likes_like');
389
+	if (!empty($modSettings['enable_likes'])) {
390
+			$context['can_like'] = allowedTo('likes_like');
391
+	}
367 392
 
368 393
 	// Find all the posts. Newer ones will have higher IDs.
369 394
 	$request = $smcFunc['db_query']('substring', '
@@ -429,12 +454,13 @@  discard block
 block discarded – undo
429 454
 		);
430 455
 
431 456
 		// Get the likes for each message.
432
-		if (!empty($modSettings['enable_likes']))
433
-			$posts[$row['id_msg']]['likes'] = array(
457
+		if (!empty($modSettings['enable_likes'])) {
458
+					$posts[$row['id_msg']]['likes'] = array(
434 459
 				'count' => $row['likes'],
435 460
 				'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
436 461
 				'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
437 462
 			);
463
+		}
438 464
 	}
439 465
 	$smcFunc['db_free_result']($request);
440 466
 
@@ -442,13 +468,14 @@  discard block
 block discarded – undo
442 468
 	call_integration_hook('integrate_ssi_queryPosts', array(&$posts));
443 469
 
444 470
 	// Just return it.
445
-	if ($output_method != 'echo' || empty($posts))
446
-		return $posts;
471
+	if ($output_method != 'echo' || empty($posts)) {
472
+			return $posts;
473
+	}
447 474
 
448 475
 	echo '
449 476
 		<table style="border: none" class="ssi_table">';
450
-	foreach ($posts as $post)
451
-		echo '
477
+	foreach ($posts as $post) {
478
+			echo '
452 479
 			<tr>
453 480
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
454 481
 					[', $post['board']['link'], ']
@@ -462,6 +489,7 @@  discard block
 block discarded – undo
462 489
 					', $post['time'], '
463 490
 				</td>
464 491
 			</tr>';
492
+	}
465 493
 	echo '
466 494
 		</table>';
467 495
 }
@@ -479,25 +507,26 @@  discard block
 block discarded – undo
479 507
 	global $settings, $scripturl, $txt, $user_info;
480 508
 	global $modSettings, $smcFunc, $context;
481 509
 
482
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
483
-		$exclude_boards = array($modSettings['recycle_board']);
484
-	else
485
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
510
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
511
+			$exclude_boards = array($modSettings['recycle_board']);
512
+	} else {
513
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
514
+	}
486 515
 
487 516
 	// Only some boards?.
488 517
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
489 518
 	{
490 519
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
491
-	}
492
-	elseif ($include_boards != null)
520
+	} elseif ($include_boards != null)
493 521
 	{
494 522
 		$output_method = $include_boards;
495 523
 		$include_boards = array();
496 524
 	}
497 525
 
498 526
 	$icon_sources = array();
499
-	foreach ($context['stable_icons'] as $icon)
500
-		$icon_sources[$icon] = 'images_url';
527
+	foreach ($context['stable_icons'] as $icon) {
528
+			$icon_sources[$icon] = 'images_url';
529
+	}
501 530
 
502 531
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
503 532
 	$request = $smcFunc['db_query']('substring', '
@@ -522,13 +551,15 @@  discard block
 block discarded – undo
522 551
 		)
523 552
 	);
524 553
 	$topics = array();
525
-	while ($row = $smcFunc['db_fetch_assoc']($request))
526
-		$topics[$row['id_topic']] = $row;
554
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
555
+			$topics[$row['id_topic']] = $row;
556
+	}
527 557
 	$smcFunc['db_free_result']($request);
528 558
 
529 559
 	// Did we find anything? If not, bail.
530
-	if (empty($topics))
531
-		return array();
560
+	if (empty($topics)) {
561
+			return array();
562
+	}
532 563
 
533 564
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
534 565
 
@@ -556,19 +587,22 @@  discard block
 block discarded – undo
556 587
 	while ($row = $smcFunc['db_fetch_assoc']($request))
557 588
 	{
558 589
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
559
-		if ($smcFunc['strlen']($row['body']) > 128)
560
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
590
+		if ($smcFunc['strlen']($row['body']) > 128) {
591
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
592
+		}
561 593
 
562 594
 		// Censor the subject.
563 595
 		censorText($row['subject']);
564 596
 		censorText($row['body']);
565 597
 
566 598
 		// Recycled icon
567
-		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
568
-			$row['icon'] = 'recycled';
599
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) {
600
+					$row['icon'] = 'recycled';
601
+		}
569 602
 
570
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
571
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
603
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
604
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
605
+		}
572 606
 
573 607
 		// Build the array.
574 608
 		$posts[] = array(
@@ -607,13 +641,14 @@  discard block
 block discarded – undo
607 641
 	call_integration_hook('integrate_ssi_recentTopics', array(&$posts));
608 642
 
609 643
 	// Just return it.
610
-	if ($output_method != 'echo' || empty($posts))
611
-		return $posts;
644
+	if ($output_method != 'echo' || empty($posts)) {
645
+			return $posts;
646
+	}
612 647
 
613 648
 	echo '
614 649
 		<table style="border: none" class="ssi_table">';
615
-	foreach ($posts as $post)
616
-		echo '
650
+	foreach ($posts as $post) {
651
+			echo '
617 652
 			<tr>
618 653
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
619 654
 					[', $post['board']['link'], ']
@@ -627,6 +662,7 @@  discard block
 block discarded – undo
627 662
 					', $post['time'], '
628 663
 				</td>
629 664
 			</tr>';
665
+	}
630 666
 	echo '
631 667
 		</table>';
632 668
 }
@@ -651,27 +687,30 @@  discard block
 block discarded – undo
651 687
 		)
652 688
 	);
653 689
 	$return = array();
654
-	while ($row = $smcFunc['db_fetch_assoc']($request))
655
-		$return[] = array(
690
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
691
+			$return[] = array(
656 692
 			'id' => $row['id_member'],
657 693
 			'name' => $row['real_name'],
658 694
 			'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
659 695
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
660 696
 			'posts' => $row['posts']
661 697
 		);
698
+	}
662 699
 	$smcFunc['db_free_result']($request);
663 700
 
664 701
 	// If mods want to do somthing with this list of members, let them do that now.
665 702
 	call_integration_hook('integrate_ssi_topPoster', array(&$return));
666 703
 
667 704
 	// Just return all the top posters.
668
-	if ($output_method != 'echo')
669
-		return $return;
705
+	if ($output_method != 'echo') {
706
+			return $return;
707
+	}
670 708
 
671 709
 	// Make a quick array to list the links in.
672 710
 	$temp_array = array();
673
-	foreach ($return as $member)
674
-		$temp_array[] = $member['link'];
711
+	foreach ($return as $member) {
712
+			$temp_array[] = $member['link'];
713
+	}
675 714
 
676 715
 	echo implode(', ', $temp_array);
677 716
 }
@@ -703,8 +742,8 @@  discard block
 block discarded – undo
703 742
 		)
704 743
 	);
705 744
 	$boards = array();
706
-	while ($row = $smcFunc['db_fetch_assoc']($request))
707
-		$boards[] = array(
745
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
746
+			$boards[] = array(
708 747
 			'id' => $row['id_board'],
709 748
 			'num_posts' => $row['num_posts'],
710 749
 			'num_topics' => $row['num_topics'],
@@ -713,14 +752,16 @@  discard block
 block discarded – undo
713 752
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
714 753
 			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
715 754
 		);
755
+	}
716 756
 	$smcFunc['db_free_result']($request);
717 757
 
718 758
 	// If mods want to do somthing with this list of boards, let them do that now.
719 759
 	call_integration_hook('integrate_ssi_topBoards', array(&$boards));
720 760
 
721 761
 	// If we shouldn't output or have nothing to output, just jump out.
722
-	if ($output_method != 'echo' || empty($boards))
723
-		return $boards;
762
+	if ($output_method != 'echo' || empty($boards)) {
763
+			return $boards;
764
+	}
724 765
 
725 766
 	echo '
726 767
 		<table class="ssi_table">
@@ -729,13 +770,14 @@  discard block
 block discarded – undo
729 770
 				<th style="text-align: left">', $txt['board_topics'], '</th>
730 771
 				<th style="text-align: left">', $txt['posts'], '</th>
731 772
 			</tr>';
732
-	foreach ($boards as $sBoard)
733
-		echo '
773
+	foreach ($boards as $sBoard) {
774
+			echo '
734 775
 			<tr>
735 776
 				<td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '</td>
736 777
 				<td style="text-align: right">', comma_format($sBoard['num_topics']), '</td>
737 778
 				<td style="text-align: right">', comma_format($sBoard['num_posts']), '</td>
738 779
 			</tr>';
780
+	}
739 781
 	echo '
740 782
 		</table>';
741 783
 }
@@ -768,12 +810,13 @@  discard block
 block discarded – undo
768 810
 			)
769 811
 		);
770 812
 		$topic_ids = array();
771
-		while ($row = $smcFunc['db_fetch_assoc']($request))
772
-			$topic_ids[] = $row['id_topic'];
813
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
814
+					$topic_ids[] = $row['id_topic'];
815
+		}
773 816
 		$smcFunc['db_free_result']($request);
817
+	} else {
818
+			$topic_ids = array();
774 819
 	}
775
-	else
776
-		$topic_ids = array();
777 820
 
778 821
 	$request = $smcFunc['db_query']('', '
779 822
 		SELECT m.subject, m.id_topic, t.num_views, t.num_replies
@@ -812,8 +855,9 @@  discard block
 block discarded – undo
812 855
 	// If mods want to do somthing with this list of topics, let them do that now.
813 856
 	call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type));
814 857
 
815
-	if ($output_method != 'echo' || empty($topics))
816
-		return $topics;
858
+	if ($output_method != 'echo' || empty($topics)) {
859
+			return $topics;
860
+	}
817 861
 
818 862
 	echo '
819 863
 		<table class="ssi_table">
@@ -822,8 +866,8 @@  discard block
 block discarded – undo
822 866
 				<th style="text-align: left">', $txt['views'], '</th>
823 867
 				<th style="text-align: left">', $txt['replies'], '</th>
824 868
 			</tr>';
825
-	foreach ($topics as $sTopic)
826
-		echo '
869
+	foreach ($topics as $sTopic) {
870
+			echo '
827 871
 			<tr>
828 872
 				<td style="text-align: left">
829 873
 					', $sTopic['link'], '
@@ -831,6 +875,7 @@  discard block
 block discarded – undo
831 875
 				<td style="text-align: right">', comma_format($sTopic['num_views']), '</td>
832 876
 				<td style="text-align: right">', comma_format($sTopic['num_replies']), '</td>
833 877
 			</tr>';
878
+	}
834 879
 	echo '
835 880
 		</table>';
836 881
 }
@@ -866,12 +911,13 @@  discard block
 block discarded – undo
866 911
 {
867 912
 	global $txt, $context;
868 913
 
869
-	if ($output_method == 'echo')
870
-		echo '
914
+	if ($output_method == 'echo') {
915
+			echo '
871 916
 	', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>';
872
-	else
873
-		return $context['common_stats']['latest_member'];
874
-}
917
+	} else {
918
+			return $context['common_stats']['latest_member'];
919
+	}
920
+	}
875 921
 
876 922
 /**
877 923
  * Fetches a random member.
@@ -920,8 +966,9 @@  discard block
 block discarded – undo
920 966
 	}
921 967
 
922 968
 	// Just to be sure put the random generator back to something... random.
923
-	if ($random_type != '')
924
-		mt_srand(time());
969
+	if ($random_type != '') {
970
+			mt_srand(time());
971
+	}
925 972
 
926 973
 	return $result;
927 974
 }
@@ -934,8 +981,9 @@  discard block
 block discarded – undo
934 981
  */
935 982
 function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
936 983
 {
937
-	if (empty($member_ids))
938
-		return;
984
+	if (empty($member_ids)) {
985
+			return;
986
+	}
939 987
 
940 988
 	// Can have more than one member if you really want...
941 989
 	$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
@@ -960,8 +1008,9 @@  discard block
 block discarded – undo
960 1008
  */
961 1009
 function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
962 1010
 {
963
-	if ($group_id === null)
964
-		return;
1011
+	if ($group_id === null) {
1012
+			return;
1013
+	}
965 1014
 
966 1015
 	$query_where = '
967 1016
 		id_group = {int:id_group}
@@ -988,8 +1037,9 @@  discard block
 block discarded – undo
988 1037
 {
989 1038
 	global $smcFunc, $memberContext;
990 1039
 
991
-	if ($query_where === null)
992
-		return;
1040
+	if ($query_where === null) {
1041
+			return;
1042
+	}
993 1043
 
994 1044
 	// Fetch the members in question.
995 1045
 	$request = $smcFunc['db_query']('', '
@@ -1002,12 +1052,14 @@  discard block
 block discarded – undo
1002 1052
 		))
1003 1053
 	);
1004 1054
 	$members = array();
1005
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1006
-		$members[] = $row['id_member'];
1055
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1056
+			$members[] = $row['id_member'];
1057
+	}
1007 1058
 	$smcFunc['db_free_result']($request);
1008 1059
 
1009
-	if (empty($members))
1010
-		return array();
1060
+	if (empty($members)) {
1061
+			return array();
1062
+	}
1011 1063
 
1012 1064
 	// If mods want to do somthing with this list of members, let them do that now.
1013 1065
 	call_integration_hook('integrate_ssi_queryMembers', array(&$members));
@@ -1016,23 +1068,25 @@  discard block
 block discarded – undo
1016 1068
 	loadMemberData($members);
1017 1069
 
1018 1070
 	// Draw the table!
1019
-	if ($output_method == 'echo')
1020
-		echo '
1071
+	if ($output_method == 'echo') {
1072
+			echo '
1021 1073
 		<table style="border: none" class="ssi_table">';
1074
+	}
1022 1075
 
1023 1076
 	$query_members = array();
1024 1077
 	foreach ($members as $member)
1025 1078
 	{
1026 1079
 		// Load their context data.
1027
-		if (!loadMemberContext($member))
1028
-			continue;
1080
+		if (!loadMemberContext($member)) {
1081
+					continue;
1082
+		}
1029 1083
 
1030 1084
 		// Store this member's information.
1031 1085
 		$query_members[$member] = $memberContext[$member];
1032 1086
 
1033 1087
 		// Only do something if we're echo'ing.
1034
-		if ($output_method == 'echo')
1035
-			echo '
1088
+		if ($output_method == 'echo') {
1089
+					echo '
1036 1090
 			<tr>
1037 1091
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
1038 1092
 					', $query_members[$member]['link'], '
@@ -1040,12 +1094,14 @@  discard block
 block discarded – undo
1040 1094
 					<br>', $query_members[$member]['avatar']['image'], '
1041 1095
 				</td>
1042 1096
 			</tr>';
1097
+		}
1043 1098
 	}
1044 1099
 
1045 1100
 	// End the table if appropriate.
1046
-	if ($output_method == 'echo')
1047
-		echo '
1101
+	if ($output_method == 'echo') {
1102
+			echo '
1048 1103
 		</table>';
1104
+	}
1049 1105
 
1050 1106
 	// Send back the data.
1051 1107
 	return $query_members;
@@ -1060,8 +1116,9 @@  discard block
 block discarded – undo
1060 1116
 {
1061 1117
 	global $txt, $scripturl, $modSettings, $smcFunc;
1062 1118
 
1063
-	if (!allowedTo('view_stats'))
1064
-		return;
1119
+	if (!allowedTo('view_stats')) {
1120
+			return;
1121
+	}
1065 1122
 
1066 1123
 	$totals = array(
1067 1124
 		'members' => $modSettings['totalMembers'],
@@ -1090,8 +1147,9 @@  discard block
 block discarded – undo
1090 1147
 	// If mods want to do somthing with the board stats, let them do that now.
1091 1148
 	call_integration_hook('integrate_ssi_boardStats', array(&$totals));
1092 1149
 
1093
-	if ($output_method != 'echo')
1094
-		return $totals;
1150
+	if ($output_method != 'echo') {
1151
+			return $totals;
1152
+	}
1095 1153
 
1096 1154
 	echo '
1097 1155
 		', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br>
@@ -1120,8 +1178,8 @@  discard block
 block discarded – undo
1120 1178
 	call_integration_hook('integrate_ssi_whosOnline', array(&$return));
1121 1179
 
1122 1180
 	// Add some redundancy for backwards compatibility reasons.
1123
-	if ($output_method != 'echo')
1124
-		return $return + array(
1181
+	if ($output_method != 'echo') {
1182
+			return $return + array(
1125 1183
 			'users' => $return['users_online'],
1126 1184
 			'guests' => $return['num_guests'],
1127 1185
 			'hidden' => $return['num_users_hidden'],
@@ -1129,29 +1187,35 @@  discard block
 block discarded – undo
1129 1187
 			'num_users' => $return['num_users_online'],
1130 1188
 			'total_users' => $return['num_users_online'] + $return['num_guests'],
1131 1189
 		);
1190
+	}
1132 1191
 
1133 1192
 	echo '
1134 1193
 		', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
1135 1194
 
1136 1195
 	$bracketList = array();
1137
-	if (!empty($user_info['buddies']))
1138
-		$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1139
-	if (!empty($return['num_spiders']))
1140
-		$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1141
-	if (!empty($return['num_users_hidden']))
1142
-		$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1196
+	if (!empty($user_info['buddies'])) {
1197
+			$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1198
+	}
1199
+	if (!empty($return['num_spiders'])) {
1200
+			$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1201
+	}
1202
+	if (!empty($return['num_users_hidden'])) {
1203
+			$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1204
+	}
1143 1205
 
1144
-	if (!empty($bracketList))
1145
-		echo ' (' . implode(', ', $bracketList) . ')';
1206
+	if (!empty($bracketList)) {
1207
+			echo ' (' . implode(', ', $bracketList) . ')';
1208
+	}
1146 1209
 
1147 1210
 	echo '<br>
1148 1211
 			', implode(', ', $return['list_users_online']);
1149 1212
 
1150 1213
 	// Showing membergroups?
1151
-	if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
1152
-		echo '<br>
1214
+	if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) {
1215
+			echo '<br>
1153 1216
 			[' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
1154
-}
1217
+	}
1218
+	}
1155 1219
 
1156 1220
 /**
1157 1221
  * Just like whosOnline except it also logs the online presence.
@@ -1162,11 +1226,12 @@  discard block
 block discarded – undo
1162 1226
 {
1163 1227
 	writeLog();
1164 1228
 
1165
-	if ($output_method != 'echo')
1166
-		return ssi_whosOnline($output_method);
1167
-	else
1168
-		ssi_whosOnline($output_method);
1169
-}
1229
+	if ($output_method != 'echo') {
1230
+			return ssi_whosOnline($output_method);
1231
+	} else {
1232
+			ssi_whosOnline($output_method);
1233
+	}
1234
+	}
1170 1235
 
1171 1236
 // Shows a login box.
1172 1237
 /**
@@ -1179,11 +1244,13 @@  discard block
 block discarded – undo
1179 1244
 {
1180 1245
 	global $scripturl, $txt, $user_info, $context;
1181 1246
 
1182
-	if ($redirect_to != '')
1183
-		$_SESSION['login_url'] = $redirect_to;
1247
+	if ($redirect_to != '') {
1248
+			$_SESSION['login_url'] = $redirect_to;
1249
+	}
1184 1250
 
1185
-	if ($output_method != 'echo' || !$user_info['is_guest'])
1186
-		return $user_info['is_guest'];
1251
+	if ($output_method != 'echo' || !$user_info['is_guest']) {
1252
+			return $user_info['is_guest'];
1253
+	}
1187 1254
 
1188 1255
 	// Create a login token
1189 1256
 	createToken('login');
@@ -1235,8 +1302,9 @@  discard block
 block discarded – undo
1235 1302
 
1236 1303
 	$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
1237 1304
 
1238
-	if (empty($boardsAllowed))
1239
-		return array();
1305
+	if (empty($boardsAllowed)) {
1306
+			return array();
1307
+	}
1240 1308
 
1241 1309
 	$request = $smcFunc['db_query']('', '
1242 1310
 		SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
@@ -1269,12 +1337,14 @@  discard block
 block discarded – undo
1269 1337
 	$smcFunc['db_free_result']($request);
1270 1338
 
1271 1339
 	// This user has voted on all the polls.
1272
-	if (empty($row) || !is_array($row))
1273
-		return array();
1340
+	if (empty($row) || !is_array($row)) {
1341
+			return array();
1342
+	}
1274 1343
 
1275 1344
 	// If this is a guest who's voted we'll through ourselves to show poll to show the results.
1276
-	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
1277
-		return ssi_showPoll($row['id_topic'], $output_method);
1345
+	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) {
1346
+			return ssi_showPoll($row['id_topic'], $output_method);
1347
+	}
1278 1348
 
1279 1349
 	$request = $smcFunc['db_query']('', '
1280 1350
 		SELECT COUNT(DISTINCT id_member)
@@ -1338,8 +1408,9 @@  discard block
 block discarded – undo
1338 1408
 	// If mods want to do somthing with this list of polls, let them do that now.
1339 1409
 	call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead));
1340 1410
 
1341
-	if ($output_method != 'echo')
1342
-		return $return;
1411
+	if ($output_method != 'echo') {
1412
+			return $return;
1413
+	}
1343 1414
 
1344 1415
 	if ($allow_view_results)
1345 1416
 	{
@@ -1348,19 +1419,20 @@  discard block
 block discarded – undo
1348 1419
 			<strong>', $return['question'], '</strong><br>
1349 1420
 			', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1350 1421
 
1351
-		foreach ($return['options'] as $option)
1352
-			echo '
1422
+		foreach ($return['options'] as $option) {
1423
+					echo '
1353 1424
 			<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1425
+		}
1354 1426
 
1355 1427
 		echo '
1356 1428
 			<input type="submit" value="', $txt['poll_vote'], '" class="button_submit">
1357 1429
 			<input type="hidden" name="poll" value="', $return['id'], '">
1358 1430
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1359 1431
 		</form>';
1432
+	} else {
1433
+			echo $txt['poll_cannot_see'];
1434
+	}
1360 1435
 	}
1361
-	else
1362
-		echo $txt['poll_cannot_see'];
1363
-}
1364 1436
 
1365 1437
 /**
1366 1438
  * Shows the poll from the specified topic
@@ -1374,13 +1446,15 @@  discard block
 block discarded – undo
1374 1446
 
1375 1447
 	$boardsAllowed = boardsAllowedTo('poll_view');
1376 1448
 
1377
-	if (empty($boardsAllowed))
1378
-		return array();
1449
+	if (empty($boardsAllowed)) {
1450
+			return array();
1451
+	}
1379 1452
 
1380
-	if ($topic === null && isset($_REQUEST['ssi_topic']))
1381
-		$topic = (int) $_REQUEST['ssi_topic'];
1382
-	else
1383
-		$topic = (int) $topic;
1453
+	if ($topic === null && isset($_REQUEST['ssi_topic'])) {
1454
+			$topic = (int) $_REQUEST['ssi_topic'];
1455
+	} else {
1456
+			$topic = (int) $topic;
1457
+	}
1384 1458
 
1385 1459
 	$request = $smcFunc['db_query']('', '
1386 1460
 		SELECT
@@ -1401,17 +1475,18 @@  discard block
 block discarded – undo
1401 1475
 	);
1402 1476
 
1403 1477
 	// Either this topic has no poll, or the user cannot view it.
1404
-	if ($smcFunc['db_num_rows']($request) == 0)
1405
-		return array();
1478
+	if ($smcFunc['db_num_rows']($request) == 0) {
1479
+			return array();
1480
+	}
1406 1481
 
1407 1482
 	$row = $smcFunc['db_fetch_assoc']($request);
1408 1483
 	$smcFunc['db_free_result']($request);
1409 1484
 
1410 1485
 	// Check if they can vote.
1411 1486
 	$already_voted = false;
1412
-	if (!empty($row['expire_time']) && $row['expire_time'] < time())
1413
-		$allow_vote = false;
1414
-	elseif ($user_info['is_guest'])
1487
+	if (!empty($row['expire_time']) && $row['expire_time'] < time()) {
1488
+			$allow_vote = false;
1489
+	} elseif ($user_info['is_guest'])
1415 1490
 	{
1416 1491
 		// There's a difference between "allowed to vote" and "already voted"...
1417 1492
 		$allow_vote = $row['guest_vote'];
@@ -1421,10 +1496,9 @@  discard block
 block discarded – undo
1421 1496
 		{
1422 1497
 			$already_voted = true;
1423 1498
 		}
1424
-	}
1425
-	elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
1426
-		$allow_vote = false;
1427
-	else
1499
+	} elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) {
1500
+			$allow_vote = false;
1501
+	} else
1428 1502
 	{
1429 1503
 		$request = $smcFunc['db_query']('', '
1430 1504
 			SELECT id_member
@@ -1506,8 +1580,9 @@  discard block
 block discarded – undo
1506 1580
 	// If mods want to do somthing with this poll, let them do that now.
1507 1581
 	call_integration_hook('integrate_ssi_showPoll', array(&$return));
1508 1582
 
1509
-	if ($output_method != 'echo')
1510
-		return $return;
1583
+	if ($output_method != 'echo') {
1584
+			return $return;
1585
+	}
1511 1586
 
1512 1587
 	if ($return['allow_vote'])
1513 1588
 	{
@@ -1516,17 +1591,17 @@  discard block
 block discarded – undo
1516 1591
 				<strong>', $return['question'], '</strong><br>
1517 1592
 				', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1518 1593
 
1519
-		foreach ($return['options'] as $option)
1520
-			echo '
1594
+		foreach ($return['options'] as $option) {
1595
+					echo '
1521 1596
 				<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1597
+		}
1522 1598
 
1523 1599
 		echo '
1524 1600
 				<input type="submit" value="', $txt['poll_vote'], '" class="button_submit">
1525 1601
 				<input type="hidden" name="poll" value="', $return['id'], '">
1526 1602
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1527 1603
 			</form>';
1528
-	}
1529
-	else
1604
+	} else
1530 1605
 	{
1531 1606
 		echo '
1532 1607
 			<div class="ssi_poll">
@@ -1606,27 +1681,32 @@  discard block
 block discarded – undo
1606 1681
 			'is_approved' => 1,
1607 1682
 		)
1608 1683
 	);
1609
-	if ($smcFunc['db_num_rows']($request) == 0)
1610
-		die;
1684
+	if ($smcFunc['db_num_rows']($request) == 0) {
1685
+			die;
1686
+	}
1611 1687
 	$row = $smcFunc['db_fetch_assoc']($request);
1612 1688
 	$smcFunc['db_free_result']($request);
1613 1689
 
1614
-	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
1615
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1690
+	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
1691
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1692
+	}
1616 1693
 
1617 1694
 	// Too many options checked?
1618
-	if (count($_REQUEST['options']) > $row['max_votes'])
1619
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1695
+	if (count($_REQUEST['options']) > $row['max_votes']) {
1696
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1697
+	}
1620 1698
 
1621 1699
 	// It's a guest who has already voted?
1622 1700
 	if ($user_info['is_guest'])
1623 1701
 	{
1624 1702
 		// Guest voting disabled?
1625
-		if (!$row['guest_vote'])
1626
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1703
+		if (!$row['guest_vote']) {
1704
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1705
+		}
1627 1706
 		// Already voted?
1628
-		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
1629
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1707
+		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
1708
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1709
+		}
1630 1710
 	}
1631 1711
 
1632 1712
 	$sOptions = array();
@@ -1680,11 +1760,13 @@  discard block
 block discarded – undo
1680 1760
 {
1681 1761
 	global $scripturl, $txt, $context;
1682 1762
 
1683
-	if (!allowedTo('search_posts'))
1684
-		return;
1763
+	if (!allowedTo('search_posts')) {
1764
+			return;
1765
+	}
1685 1766
 
1686
-	if ($output_method != 'echo')
1687
-		return $scripturl . '?action=search';
1767
+	if ($output_method != 'echo') {
1768
+			return $scripturl . '?action=search';
1769
+	}
1688 1770
 
1689 1771
 	echo '
1690 1772
 		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -1706,8 +1788,9 @@  discard block
 block discarded – undo
1706 1788
 	// If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context.
1707 1789
 	call_integration_hook('integrate_ssi_news');
1708 1790
 
1709
-	if ($output_method != 'echo')
1710
-		return $context['random_news_line'];
1791
+	if ($output_method != 'echo') {
1792
+			return $context['random_news_line'];
1793
+	}
1711 1794
 
1712 1795
 	echo $context['random_news_line'];
1713 1796
 }
@@ -1721,8 +1804,9 @@  discard block
 block discarded – undo
1721 1804
 {
1722 1805
 	global $scripturl, $modSettings, $user_info;
1723 1806
 
1724
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view'))
1725
-		return;
1807
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) {
1808
+			return;
1809
+	}
1726 1810
 
1727 1811
 	$eventOptions = array(
1728 1812
 		'include_birthdays' => true,
@@ -1733,13 +1817,15 @@  discard block
 block discarded – undo
1733 1817
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1734 1818
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1735 1819
 
1736
-	if ($output_method != 'echo')
1737
-		return $return['calendar_birthdays'];
1820
+	if ($output_method != 'echo') {
1821
+			return $return['calendar_birthdays'];
1822
+	}
1738 1823
 
1739
-	foreach ($return['calendar_birthdays'] as $member)
1740
-		echo '
1824
+	foreach ($return['calendar_birthdays'] as $member) {
1825
+			echo '
1741 1826
 			<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'] ? ', ' : '');
1742
-}
1827
+	}
1828
+	}
1743 1829
 
1744 1830
 /**
1745 1831
  * Shows today's holidays.
@@ -1750,8 +1836,9 @@  discard block
 block discarded – undo
1750 1836
 {
1751 1837
 	global $modSettings, $user_info;
1752 1838
 
1753
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1754
-		return;
1839
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1840
+			return;
1841
+	}
1755 1842
 
1756 1843
 	$eventOptions = array(
1757 1844
 		'include_holidays' => true,
@@ -1762,8 +1849,9 @@  discard block
 block discarded – undo
1762 1849
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1763 1850
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1764 1851
 
1765
-	if ($output_method != 'echo')
1766
-		return $return['calendar_holidays'];
1852
+	if ($output_method != 'echo') {
1853
+			return $return['calendar_holidays'];
1854
+	}
1767 1855
 
1768 1856
 	echo '
1769 1857
 		', implode(', ', $return['calendar_holidays']);
@@ -1777,8 +1865,9 @@  discard block
 block discarded – undo
1777 1865
 {
1778 1866
 	global $modSettings, $user_info;
1779 1867
 
1780
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1781
-		return;
1868
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1869
+			return;
1870
+	}
1782 1871
 
1783 1872
 	$eventOptions = array(
1784 1873
 		'include_events' => true,
@@ -1789,14 +1878,16 @@  discard block
 block discarded – undo
1789 1878
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1790 1879
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1791 1880
 
1792
-	if ($output_method != 'echo')
1793
-		return $return['calendar_events'];
1881
+	if ($output_method != 'echo') {
1882
+			return $return['calendar_events'];
1883
+	}
1794 1884
 
1795 1885
 	foreach ($return['calendar_events'] as $event)
1796 1886
 	{
1797
-		if ($event['can_edit'])
1798
-			echo '
1887
+		if ($event['can_edit']) {
1888
+					echo '
1799 1889
 	<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1890
+		}
1800 1891
 		echo '
1801 1892
 	' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1802 1893
 	}
@@ -1811,8 +1902,9 @@  discard block
 block discarded – undo
1811 1902
 {
1812 1903
 	global $modSettings, $txt, $scripturl, $user_info;
1813 1904
 
1814
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1815
-		return;
1905
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1906
+			return;
1907
+	}
1816 1908
 
1817 1909
 	$eventOptions = array(
1818 1910
 		'include_birthdays' => allowedTo('profile_view'),
@@ -1825,19 +1917,22 @@  discard block
 block discarded – undo
1825 1917
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1826 1918
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1827 1919
 
1828
-	if ($output_method != 'echo')
1829
-		return $return;
1920
+	if ($output_method != 'echo') {
1921
+			return $return;
1922
+	}
1830 1923
 
1831
-	if (!empty($return['calendar_holidays']))
1832
-		echo '
1924
+	if (!empty($return['calendar_holidays'])) {
1925
+			echo '
1833 1926
 			<span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>';
1927
+	}
1834 1928
 	if (!empty($return['calendar_birthdays']))
1835 1929
 	{
1836 1930
 		echo '
1837 1931
 			<span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
1838
-		foreach ($return['calendar_birthdays'] as $member)
1839
-			echo '
1932
+		foreach ($return['calendar_birthdays'] as $member) {
1933
+					echo '
1840 1934
 			<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'] ? ', ' : '';
1935
+		}
1841 1936
 		echo '
1842 1937
 			<br>';
1843 1938
 	}
@@ -1847,9 +1942,10 @@  discard block
 block discarded – undo
1847 1942
 			<span class="event">' . $txt['events_upcoming'] . '</span> ';
1848 1943
 		foreach ($return['calendar_events'] as $event)
1849 1944
 		{
1850
-			if ($event['can_edit'])
1851
-				echo '
1945
+			if ($event['can_edit']) {
1946
+							echo '
1852 1947
 			<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1948
+			}
1853 1949
 			echo '
1854 1950
 			' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1855 1951
 		}
@@ -1873,25 +1969,29 @@  discard block
 block discarded – undo
1873 1969
 	loadLanguage('Stats');
1874 1970
 
1875 1971
 	// Must be integers....
1876
-	if ($limit === null)
1877
-		$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1878
-	else
1879
-		$limit = (int) $limit;
1880
-
1881
-	if ($start === null)
1882
-		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1883
-	else
1884
-		$start = (int) $start;
1885
-
1886
-	if ($board !== null)
1887
-		$board = (int) $board;
1888
-	elseif (isset($_GET['board']))
1889
-		$board = (int) $_GET['board'];
1890
-
1891
-	if ($length === null)
1892
-		$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1893
-	else
1894
-		$length = (int) $length;
1972
+	if ($limit === null) {
1973
+			$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1974
+	} else {
1975
+			$limit = (int) $limit;
1976
+	}
1977
+
1978
+	if ($start === null) {
1979
+			$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1980
+	} else {
1981
+			$start = (int) $start;
1982
+	}
1983
+
1984
+	if ($board !== null) {
1985
+			$board = (int) $board;
1986
+	} elseif (isset($_GET['board'])) {
1987
+			$board = (int) $_GET['board'];
1988
+	}
1989
+
1990
+	if ($length === null) {
1991
+			$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1992
+	} else {
1993
+			$length = (int) $length;
1994
+	}
1895 1995
 
1896 1996
 	$limit = max(0, $limit);
1897 1997
 	$start = max(0, $start);
@@ -1909,17 +2009,19 @@  discard block
 block discarded – undo
1909 2009
 	);
1910 2010
 	if ($smcFunc['db_num_rows']($request) == 0)
1911 2011
 	{
1912
-		if ($output_method == 'echo')
1913
-			die($txt['ssi_no_guests']);
1914
-		else
1915
-			return array();
2012
+		if ($output_method == 'echo') {
2013
+					die($txt['ssi_no_guests']);
2014
+		} else {
2015
+					return array();
2016
+		}
1916 2017
 	}
1917 2018
 	list ($board) = $smcFunc['db_fetch_row']($request);
1918 2019
 	$smcFunc['db_free_result']($request);
1919 2020
 
1920 2021
 	$icon_sources = array();
1921
-	foreach ($context['stable_icons'] as $icon)
1922
-		$icon_sources[$icon] = 'images_url';
2022
+	foreach ($context['stable_icons'] as $icon) {
2023
+			$icon_sources[$icon] = 'images_url';
2024
+	}
1923 2025
 
1924 2026
 	if (!empty($modSettings['enable_likes']))
1925 2027
 	{
@@ -1943,12 +2045,14 @@  discard block
 block discarded – undo
1943 2045
 		)
1944 2046
 	);
1945 2047
 	$posts = array();
1946
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1947
-		$posts[] = $row['id_first_msg'];
2048
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2049
+			$posts[] = $row['id_first_msg'];
2050
+	}
1948 2051
 	$smcFunc['db_free_result']($request);
1949 2052
 
1950
-	if (empty($posts))
1951
-		return array();
2053
+	if (empty($posts)) {
2054
+			return array();
2055
+	}
1952 2056
 
1953 2057
 	// Find the posts.
1954 2058
 	$request = $smcFunc['db_query']('', '
@@ -1978,24 +2082,28 @@  discard block
 block discarded – undo
1978 2082
 			$last_space = strrpos($row['body'], ' ');
1979 2083
 			$last_open = strrpos($row['body'], '<');
1980 2084
 			$last_close = strrpos($row['body'], '>');
1981
-			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6)
1982
-				$cutoff = $last_open;
1983
-			elseif (empty($last_close) || $last_close < $last_open)
1984
-				$cutoff = $last_space;
2085
+			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) {
2086
+							$cutoff = $last_open;
2087
+			} elseif (empty($last_close) || $last_close < $last_open) {
2088
+							$cutoff = $last_space;
2089
+			}
1985 2090
 
1986
-			if ($cutoff !== false)
1987
-				$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2091
+			if ($cutoff !== false) {
2092
+							$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2093
+			}
1988 2094
 			$row['body'] .= '...';
1989 2095
 		}
1990 2096
 
1991 2097
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1992 2098
 
1993
-		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
1994
-			$row['icon'] = 'recycled';
2099
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
2100
+					$row['icon'] = 'recycled';
2101
+		}
1995 2102
 
1996 2103
 		// Check that this message icon is there...
1997
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
1998
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2104
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
2105
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2106
+		}
1999 2107
 
2000 2108
 		censorText($row['subject']);
2001 2109
 		censorText($row['body']);
@@ -2032,16 +2140,18 @@  discard block
 block discarded – undo
2032 2140
 	}
2033 2141
 	$smcFunc['db_free_result']($request);
2034 2142
 
2035
-	if (empty($return))
2036
-		return $return;
2143
+	if (empty($return)) {
2144
+			return $return;
2145
+	}
2037 2146
 
2038 2147
 	$return[count($return) - 1]['is_last'] = true;
2039 2148
 
2040 2149
 	// If mods want to do somthing with this list of posts, let them do that now.
2041 2150
 	call_integration_hook('integrate_ssi_boardNews', array(&$return));
2042 2151
 
2043
-	if ($output_method != 'echo')
2044
-		return $return;
2152
+	if ($output_method != 'echo') {
2153
+			return $return;
2154
+	}
2045 2155
 
2046 2156
 	foreach ($return as $news)
2047 2157
 	{
@@ -2093,9 +2203,10 @@  discard block
 block discarded – undo
2093 2203
 		echo '
2094 2204
 			</div>';
2095 2205
 
2096
-		if (!$news['is_last'])
2097
-			echo '
2206
+		if (!$news['is_last']) {
2207
+					echo '
2098 2208
 			<hr>';
2209
+		}
2099 2210
 	}
2100 2211
 }
2101 2212
 
@@ -2109,8 +2220,9 @@  discard block
 block discarded – undo
2109 2220
 {
2110 2221
 	global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
2111 2222
 
2112
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
2113
-		return;
2223
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
2224
+			return;
2225
+	}
2114 2226
 
2115 2227
 	// Find all events which are happening in the near future that the member can see.
2116 2228
 	$request = $smcFunc['db_query']('', '
@@ -2136,20 +2248,23 @@  discard block
 block discarded – undo
2136 2248
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2137 2249
 	{
2138 2250
 		// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
2139
-		if (!empty($duplicates[$row['title'] . $row['id_topic']]))
2140
-			continue;
2251
+		if (!empty($duplicates[$row['title'] . $row['id_topic']])) {
2252
+					continue;
2253
+		}
2141 2254
 
2142 2255
 		// Censor the title.
2143 2256
 		censorText($row['title']);
2144 2257
 
2145
-		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
2146
-			$date = strftime('%Y-%m-%d', forum_time(false));
2147
-		else
2148
-			$date = $row['start_date'];
2258
+		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) {
2259
+					$date = strftime('%Y-%m-%d', forum_time(false));
2260
+		} else {
2261
+					$date = $row['start_date'];
2262
+		}
2149 2263
 
2150 2264
 		// If the topic it is attached to is not approved then don't link it.
2151
-		if (!empty($row['id_first_msg']) && !$row['approved'])
2152
-			$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2265
+		if (!empty($row['id_first_msg']) && !$row['approved']) {
2266
+					$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2267
+		}
2153 2268
 
2154 2269
 		$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
2155 2270
 
@@ -2175,24 +2290,27 @@  discard block
 block discarded – undo
2175 2290
 	}
2176 2291
 	$smcFunc['db_free_result']($request);
2177 2292
 
2178
-	foreach ($return as $mday => $array)
2179
-		$return[$mday][count($array) - 1]['is_last'] = true;
2293
+	foreach ($return as $mday => $array) {
2294
+			$return[$mday][count($array) - 1]['is_last'] = true;
2295
+	}
2180 2296
 
2181 2297
 	// If mods want to do somthing with this list of events, let them do that now.
2182 2298
 	call_integration_hook('integrate_ssi_recentEvents', array(&$return));
2183 2299
 
2184
-	if ($output_method != 'echo' || empty($return))
2185
-		return $return;
2300
+	if ($output_method != 'echo' || empty($return)) {
2301
+			return $return;
2302
+	}
2186 2303
 
2187 2304
 	// Well the output method is echo.
2188 2305
 	echo '
2189 2306
 			<span class="event">' . $txt['events'] . '</span> ';
2190
-	foreach ($return as $mday => $array)
2191
-		foreach ($array as $event)
2307
+	foreach ($return as $mday => $array) {
2308
+			foreach ($array as $event)
2192 2309
 		{
2193 2310
 			if ($event['can_edit'])
2194 2311
 				echo '
2195 2312
 				<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
2313
+	}
2196 2314
 
2197 2315
 			echo '
2198 2316
 				' . $event['link'] . (!$event['is_last'] ? ', ' : '');
@@ -2211,8 +2329,9 @@  discard block
 block discarded – undo
2211 2329
 	global $smcFunc;
2212 2330
 
2213 2331
 	// If $id is null, this was most likely called from a query string and should do nothing.
2214
-	if ($id === null)
2215
-		return;
2332
+	if ($id === null) {
2333
+			return;
2334
+	}
2216 2335
 
2217 2336
 	$request = $smcFunc['db_query']('', '
2218 2337
 		SELECT passwd, member_name, is_activated
@@ -2244,8 +2363,9 @@  discard block
 block discarded – undo
2244 2363
 	$attachments_boards = boardsAllowedTo('view_attachments');
2245 2364
 
2246 2365
 	// No boards?  Adios amigo.
2247
-	if (empty($attachments_boards))
2248
-		return array();
2366
+	if (empty($attachments_boards)) {
2367
+			return array();
2368
+	}
2249 2369
 
2250 2370
 	// Is it an array?
2251 2371
 	$attachment_ext = (array) $attachment_ext;
@@ -2329,8 +2449,9 @@  discard block
 block discarded – undo
2329 2449
 	call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments));
2330 2450
 
2331 2451
 	// So you just want an array?  Here you can have it.
2332
-	if ($output_method == 'array' || empty($attachments))
2333
-		return $attachments;
2452
+	if ($output_method == 'array' || empty($attachments)) {
2453
+			return $attachments;
2454
+	}
2334 2455
 
2335 2456
 	// Give them the default.
2336 2457
 	echo '
@@ -2341,14 +2462,15 @@  discard block
 block discarded – undo
2341 2462
 				<th style="text-align: left; padding: 2">', $txt['downloads'], '</th>
2342 2463
 				<th style="text-align: left; padding: 2">', $txt['filesize'], '</th>
2343 2464
 			</tr>';
2344
-	foreach ($attachments as $attach)
2345
-		echo '
2465
+	foreach ($attachments as $attach) {
2466
+			echo '
2346 2467
 			<tr>
2347 2468
 				<td>', $attach['file']['link'], '</td>
2348 2469
 				<td>', $attach['member']['link'], '</td>
2349 2470
 				<td style="text-align: center">', $attach['file']['downloads'], '</td>
2350 2471
 				<td>', $attach['file']['filesize'], '</td>
2351 2472
 			</tr>';
2473
+	}
2352 2474
 	echo '
2353 2475
 		</table>';
2354 2476
 }
Please login to merge, or discard this patch.
Sources/Packages.php 1 patch
Braces   +599 added lines, -484 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
  * This is the notoriously defunct package manager..... :/.
@@ -57,10 +58,11 @@  discard block
 block discarded – undo
57 58
 	);
58 59
 
59 60
 	// Work out exactly who it is we are calling.
60
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
61
-		$context['sub_action'] = $_REQUEST['sa'];
62
-	else
63
-		$context['sub_action'] = 'browse';
61
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
62
+			$context['sub_action'] = $_REQUEST['sa'];
63
+	} else {
64
+			$context['sub_action'] = 'browse';
65
+	}
64 66
 
65 67
 	// Set up some tabs...
66 68
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -82,8 +84,9 @@  discard block
 block discarded – undo
82 84
 		),
83 85
 	);
84 86
 
85
-	if ($context['sub_action'] == 'browse')
86
-		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
87
+	if ($context['sub_action'] == 'browse') {
88
+			loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
89
+	}
87 90
 
88 91
 	call_integration_hook('integrate_manage_packages', array(&$subActions));
89 92
 
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings;
100 103
 
101 104
 	// You have to specify a file!!
102
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
103
-		redirectexit('action=admin;area=packages');
105
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
106
+			redirectexit('action=admin;area=packages');
107
+	}
104 108
 	$context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']);
105 109
 
106 110
 	// Do we have an existing id, for uninstalls and the like.
@@ -112,8 +116,9 @@  discard block
 block discarded – undo
112 116
 	create_chmod_control();
113 117
 
114 118
 	// Make sure temp directory exists and is empty.
115
-	if (file_exists($packagesdir . '/temp'))
116
-		deltree($packagesdir . '/temp', false);
119
+	if (file_exists($packagesdir . '/temp')) {
120
+			deltree($packagesdir . '/temp', false);
121
+	}
117 122
 
118 123
 	if (!mktree($packagesdir . '/temp', 0755))
119 124
 	{
@@ -124,8 +129,9 @@  discard block
 block discarded – undo
124 129
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true));
125 130
 
126 131
 			deltree($packagesdir . '/temp', false);
127
-			if (!mktree($packagesdir . '/temp', 0777))
128
-				fatal_lang_error('package_cant_download', false);
132
+			if (!mktree($packagesdir . '/temp', 0777)) {
133
+							fatal_lang_error('package_cant_download', false);
134
+			}
129 135
 		}
130 136
 	}
131 137
 
@@ -151,25 +157,26 @@  discard block
 block discarded – undo
151 157
 	{
152 158
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
153 159
 
154
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
155
-			foreach ($context['extracted_files'] as $file)
160
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
161
+					foreach ($context['extracted_files'] as $file)
156 162
 				if (basename($file['filename']) == 'package-info.xml')
157 163
 				{
158 164
 					$context['base_path'] = dirname($file['filename']) . '/';
165
+		}
159 166
 					break;
160 167
 				}
161 168
 
162
-		if (!isset($context['base_path']))
163
-			$context['base_path'] = '';
164
-	}
165
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
169
+		if (!isset($context['base_path'])) {
170
+					$context['base_path'] = '';
171
+		}
172
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
166 173
 	{
167 174
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
168 175
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
169 176
 		$context['base_path'] = '';
177
+	} else {
178
+			fatal_lang_error('no_access', false);
170 179
 	}
171
-	else
172
-		fatal_lang_error('no_access', false);
173 180
 
174 181
 	// Load up any custom themes we may want to install into...
175 182
 	$request = $smcFunc['db_query']('', '
@@ -185,15 +192,17 @@  discard block
 block discarded – undo
185 192
 		)
186 193
 	);
187 194
 	$theme_paths = array();
188
-	while ($row = $smcFunc['db_fetch_assoc']($request))
189
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
195
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
196
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
197
+	}
190 198
 	$smcFunc['db_free_result']($request);
191 199
 
192 200
 	// Get the package info...
193 201
 	$packageInfo = getPackageInfo($context['filename']);
194 202
 
195
-	if (!is_array($packageInfo))
196
-		fatal_lang_error($packageInfo);
203
+	if (!is_array($packageInfo)) {
204
+			fatal_lang_error($packageInfo);
205
+	}
197 206
 
198 207
 	$packageInfo['filename'] = $context['filename'];
199 208
 	$context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
@@ -227,18 +236,19 @@  discard block
 block discarded – undo
227 236
 	$smcFunc['db_free_result']($request);
228 237
 
229 238
 	$context['database_changes'] = array();
230
-	if (isset($packageInfo['uninstall']['database']))
231
-		$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
232
-	elseif (!empty($db_changes))
239
+	if (isset($packageInfo['uninstall']['database'])) {
240
+			$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
241
+	} elseif (!empty($db_changes))
233 242
 	{
234 243
 		foreach ($db_changes as $change)
235 244
 		{
236
-			if (isset($change[2]) && isset($txt['package_db_' . $change[0]]))
237
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
238
-			elseif (isset($txt['package_db_' . $change[0]]))
239
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
240
-			else
241
-				$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
245
+			if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
246
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
247
+			} elseif (isset($txt['package_db_' . $change[0]])) {
248
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
249
+			} else {
250
+							$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
251
+			}
242 252
 		}
243 253
 	}
244 254
 
@@ -265,31 +275,33 @@  discard block
 block discarded – undo
265 275
 		$context['themes_locked'] = true;
266 276
 
267 277
 		// Only let them uninstall themes it was installed into.
268
-		foreach ($theme_paths as $id => $data)
269
-			if ($id != 1 && !in_array($id, $old_themes))
278
+		foreach ($theme_paths as $id => $data) {
279
+					if ($id != 1 && !in_array($id, $old_themes))
270 280
 				unset($theme_paths[$id]);
271
-	}
272
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
281
+		}
282
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
273 283
 	{
274 284
 		// Look for an upgrade...
275 285
 		$actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version);
276 286
 
277 287
 		// There was no upgrade....
278
-		if (empty($actions))
279
-			$context['is_installed'] = true;
280
-		else
288
+		if (empty($actions)) {
289
+					$context['is_installed'] = true;
290
+		} else
281 291
 		{
282 292
 			// Otherwise they can only upgrade themes from the first time around.
283
-			foreach ($theme_paths as $id => $data)
284
-				if ($id != 1 && !in_array($id, $old_themes))
293
+			foreach ($theme_paths as $id => $data) {
294
+							if ($id != 1 && !in_array($id, $old_themes))
285 295
 					unset($theme_paths[$id]);
296
+			}
286 297
 		}
298
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
299
+			$context['is_installed'] = true;
287 300
 	}
288
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
289
-		$context['is_installed'] = true;
290 301
 
291
-	if (!isset($old_version) || $context['is_installed'])
292
-		$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
302
+	if (!isset($old_version) || $context['is_installed']) {
303
+			$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
304
+	}
293 305
 
294 306
 	$context['actions'] = array();
295 307
 	$context['ftp_needed'] = false;
@@ -297,8 +309,9 @@  discard block
 block discarded – undo
297 309
 	$chmod_files = array();
298 310
 
299 311
 	// no actions found, return so we can display an error
300
-	if (empty($actions))
301
-		return;
312
+	if (empty($actions)) {
313
+			return;
314
+	}
302 315
 
303 316
 	// This will hold data about anything that can be installed in other themes.
304 317
 	$themeFinds = array(
@@ -317,14 +330,14 @@  discard block
 block discarded – undo
317 330
 		{
318 331
 			$chmod_files[] = $action['filename'];
319 332
 			continue;
320
-		}
321
-		elseif ($action['type'] == 'readme' || $action['type'] == 'license')
333
+		} elseif ($action['type'] == 'readme' || $action['type'] == 'license')
322 334
 		{
323 335
 			$type = 'package_' . $action['type'];
324
-			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
325
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
326
-			elseif (file_exists($action['filename']))
327
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
336
+			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
337
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
338
+			} elseif (file_exists($action['filename'])) {
339
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
340
+			}
328 341
 
329 342
 			if (!empty($action['parse_bbc']))
330 343
 			{
@@ -332,24 +345,24 @@  discard block
 block discarded – undo
332 345
 				$context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]);
333 346
 				preparsecode($context[$type]);
334 347
 				$context[$type] = parse_bbc($context[$type]);
348
+			} else {
349
+							$context[$type] = nl2br($context[$type]);
335 350
 			}
336
-			else
337
-				$context[$type] = nl2br($context[$type]);
338 351
 
339 352
 			continue;
340 353
 		}
341 354
 		// Don't show redirects.
342
-		elseif ($action['type'] == 'redirect')
343
-			continue;
344
-		elseif ($action['type'] == 'error')
355
+		elseif ($action['type'] == 'redirect') {
356
+					continue;
357
+		} elseif ($action['type'] == 'error')
345 358
 		{
346 359
 			$context['has_failure'] = true;
347
-			if (isset($action['error_msg']) && isset($action['error_var']))
348
-				$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
349
-			elseif (isset($action['error_msg']))
350
-				$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
351
-		}
352
-		elseif ($action['type'] == 'modification')
360
+			if (isset($action['error_msg']) && isset($action['error_var'])) {
361
+							$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
362
+			} elseif (isset($action['error_msg'])) {
363
+							$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
364
+			}
365
+		} elseif ($action['type'] == 'modification')
353 366
 		{
354 367
 			if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
355 368
 			{
@@ -361,52 +374,54 @@  discard block
 block discarded – undo
361 374
 					'description' => $txt['package_action_missing'],
362 375
 					'failed' => true,
363 376
 				);
364
-			}
365
-			else
377
+			} else
366 378
 			{
367 379
 
368
-				if ($action['boardmod'])
369
-					$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
370
-				else
371
-					$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
380
+				if ($action['boardmod']) {
381
+									$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
382
+				} else {
383
+									$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
384
+				}
372 385
 
373
-				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-')
374
-					$mod_actions[0]['filename'] = $action['filename'];
386
+				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
387
+									$mod_actions[0]['filename'] = $action['filename'];
388
+				}
375 389
 
376 390
 				foreach ($mod_actions as $key => $mod_action)
377 391
 				{
378 392
 					// Lets get the last section of the file name.
379
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
380
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
381
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
382
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
383
-					else
384
-						$actual_filename = $key;
385
-
386
-					if ($mod_action['type'] == 'opened')
387
-						$failed = false;
388
-					elseif ($mod_action['type'] == 'failure')
393
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
394
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
395
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
396
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
397
+					} else {
398
+											$actual_filename = $key;
399
+					}
400
+
401
+					if ($mod_action['type'] == 'opened') {
402
+											$failed = false;
403
+					} elseif ($mod_action['type'] == 'failure')
389 404
 					{
390
-						if (empty($mod_action['is_custom']))
391
-							$context['has_failure'] = true;
405
+						if (empty($mod_action['is_custom'])) {
406
+													$context['has_failure'] = true;
407
+						}
392 408
 						$failed = true;
393
-					}
394
-					elseif ($mod_action['type'] == 'chmod')
409
+					} elseif ($mod_action['type'] == 'chmod')
395 410
 					{
396 411
 						$chmod_files[] = $mod_action['filename'];
397
-					}
398
-					elseif ($mod_action['type'] == 'saved')
412
+					} elseif ($mod_action['type'] == 'saved')
399 413
 					{
400 414
 						if (!empty($mod_action['is_custom']))
401 415
 						{
402
-							if (!isset($context['theme_actions'][$mod_action['is_custom']]))
403
-								$context['theme_actions'][$mod_action['is_custom']] = array(
416
+							if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
417
+															$context['theme_actions'][$mod_action['is_custom']] = array(
404 418
 									'name' => $theme_paths[$mod_action['is_custom']]['name'],
405 419
 									'actions' => array(),
406 420
 									'has_failure' => $failed,
407 421
 								);
408
-							else
409
-								$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
422
+							} else {
423
+															$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
424
+							}
410 425
 
411 426
 							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array(
412 427
 								'type' => $txt['execute_modification'],
@@ -414,8 +429,7 @@  discard block
 block discarded – undo
414 429
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
415 430
 								'failed' => $failed,
416 431
 							);
417
-						}
418
-						elseif (!isset($context['actions'][$actual_filename]))
432
+						} elseif (!isset($context['actions'][$actual_filename]))
419 433
 						{
420 434
 							$context['actions'][$actual_filename] = array(
421 435
 								'type' => $txt['execute_modification'],
@@ -423,22 +437,19 @@  discard block
 block discarded – undo
423 437
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
424 438
 								'failed' => $failed,
425 439
 							);
426
-						}
427
-						else
440
+						} else
428 441
 						{
429 442
 								$context['actions'][$actual_filename]['failed'] |= $failed;
430 443
 								$context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
431 444
 						}
432
-					}
433
-					elseif ($mod_action['type'] == 'skipping')
445
+					} elseif ($mod_action['type'] == 'skipping')
434 446
 					{
435 447
 						$context['actions'][$actual_filename] = array(
436 448
 							'type' => $txt['execute_modification'],
437 449
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
438 450
 							'description' => $txt['package_action_skipping']
439 451
 						);
440
-					}
441
-					elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
452
+					} elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
442 453
 					{
443 454
 						$context['has_failure'] = true;
444 455
 						$context['actions'][$actual_filename] = array(
@@ -447,32 +458,33 @@  discard block
 block discarded – undo
447 458
 							'description' => $txt['package_action_missing'],
448 459
 							'failed' => true,
449 460
 						);
450
-					}
451
-					elseif ($mod_action['type'] == 'error')
452
-						$context['actions'][$actual_filename] = array(
461
+					} elseif ($mod_action['type'] == 'error') {
462
+											$context['actions'][$actual_filename] = array(
453 463
 							'type' => $txt['execute_modification'],
454 464
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
455 465
 							'description' => $txt['package_action_error'],
456 466
 							'failed' => true,
457 467
 						);
468
+					}
458 469
 				}
459 470
 
460 471
 				// We need to loop again just to get the operations down correctly.
461 472
 				foreach ($mod_actions as $operation_key => $mod_action)
462 473
 				{
463 474
 					// Lets get the last section of the file name.
464
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
465
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
466
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
467
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
468
-					else
469
-						$actual_filename = $key;
475
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
476
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
477
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
478
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
479
+					} else {
480
+											$actual_filename = $key;
481
+					}
470 482
 
471 483
 					// We just need it for actual parse changes.
472 484
 					if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod')))
473 485
 					{
474
-						if (empty($mod_action['is_custom']))
475
-							$context['actions'][$actual_filename]['operations'][] = array(
486
+						if (empty($mod_action['is_custom'])) {
487
+													$context['actions'][$actual_filename]['operations'][] = array(
476 488
 								'type' => $txt['execute_modification'],
477 489
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
478 490
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -483,10 +495,11 @@  discard block
 block discarded – undo
483 495
 								'failed' => $mod_action['failed'],
484 496
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
485 497
 							);
498
+						}
486 499
 
487 500
 						// Themes are under the saved type.
488
-						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']]))
489
-							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
501
+						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
502
+													$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
490 503
 								'type' => $txt['execute_modification'],
491 504
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
492 505
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -497,59 +510,55 @@  discard block
 block discarded – undo
497 510
 								'failed' => $mod_action['failed'],
498 511
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
499 512
 							);
513
+						}
500 514
 					}
501 515
 				}
502 516
 			}
503
-		}
504
-		elseif ($action['type'] == 'code')
517
+		} elseif ($action['type'] == 'code')
505 518
 		{
506 519
 			$thisAction = array(
507 520
 				'type' => $txt['execute_code'],
508 521
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
509 522
 			);
510
-		}
511
-		elseif ($action['type'] == 'database')
523
+		} elseif ($action['type'] == 'database')
512 524
 		{
513 525
 			$thisAction = array(
514 526
 				'type' => $txt['execute_database_changes'],
515 527
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
516 528
 			);
517
-		}
518
-		elseif (in_array($action['type'], array('create-dir', 'create-file')))
529
+		} elseif (in_array($action['type'], array('create-dir', 'create-file')))
519 530
 		{
520 531
 			$thisAction = array(
521 532
 				'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']),
522 533
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
523 534
 			);
524
-		}
525
-		elseif ($action['type'] == 'hook')
535
+		} elseif ($action['type'] == 'hook')
526 536
 		{
527 537
 			$action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success'];
528 538
 
529
-			if (!isset($action['hook'], $action['function']))
530
-				$context['has_failure'] = true;
539
+			if (!isset($action['hook'], $action['function'])) {
540
+							$context['has_failure'] = true;
541
+			}
531 542
 
532 543
 			$thisAction = array(
533 544
 				'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'],
534 545
 				'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])),
535 546
 			);
536
-		}
537
-		elseif ($action['type'] == 'credits')
547
+		} elseif ($action['type'] == 'credits')
538 548
 		{
539 549
 			$thisAction = array(
540 550
 				'type' => $txt['execute_credits_add'],
541 551
 				'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])),
542 552
 			);
543
-		}
544
-		elseif ($action['type'] == 'requires')
553
+		} elseif ($action['type'] == 'requires')
545 554
 		{
546 555
 			$installed = false;
547 556
 			$version = true;
548 557
 
549 558
 			// package missing required values?
550
-			if (!isset($action['id']))
551
-				$context['has_failure'] = true;
552
-			else
559
+			if (!isset($action['id'])) {
560
+							$context['has_failure'] = true;
561
+			} else
553 562
 			{
554 563
 				// See if this dependancy is installed
555 564
 				$request = $smcFunc['db_query']('', '
@@ -565,8 +574,9 @@  discard block
 block discarded – undo
565 574
 					)
566 575
 				);
567 576
 				$installed = ($smcFunc['db_num_rows']($request) !== 0);
568
-				if ($installed)
569
-					list ($version) = $smcFunc['db_fetch_row']($request);
577
+				if ($installed) {
578
+									list ($version) = $smcFunc['db_fetch_row']($request);
579
+				}
570 580
 				$smcFunc['db_free_result']($request);
571 581
 
572 582
 				// do a version level check (if requested) in the most basic way
@@ -581,8 +591,7 @@  discard block
 block discarded – undo
581 591
 				'type' => $txt['package_requires'],
582 592
 				'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''),
583 593
 			);
584
-		}
585
-		elseif (in_array($action['type'], array('require-dir', 'require-file')))
594
+		} elseif (in_array($action['type'], array('require-dir', 'require-file')))
586 595
 		{
587 596
 			// Do this one...
588 597
 			$thisAction = array(
@@ -596,26 +605,29 @@  discard block
 block discarded – undo
596 605
 				// Is the action already stated?
597 606
 				$theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
598 607
 				// If it's not auto do we think we have something we can act upon?
599
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
600
-					$theme_action = '';
608
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
609
+									$theme_action = '';
610
+				}
601 611
 				// ... or if it's auto do we even want to do anything?
602
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
603
-					$theme_action = '';
612
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
613
+									$theme_action = '';
614
+				}
604 615
 
605 616
 				// So, we still want to do something?
606
-				if ($theme_action != '')
607
-					$themeFinds['candidates'][] = $action;
617
+				if ($theme_action != '') {
618
+									$themeFinds['candidates'][] = $action;
619
+				}
608 620
 				// Otherwise is this is going into another theme record it.
609
-				elseif ($matches[1] == 'themes_dir')
610
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
621
+				elseif ($matches[1] == 'themes_dir') {
622
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
623
+				}
611 624
 			}
612
-		}
613
-		elseif (in_array($action['type'], array('move-dir', 'move-file')))
614
-			$thisAction = array(
625
+		} elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
626
+					$thisAction = array(
615 627
 				'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']),
616 628
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
617 629
 			);
618
-		elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
630
+		} elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
619 631
 		{
620 632
 			$thisAction = array(
621 633
 				'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']),
@@ -631,30 +643,36 @@  discard block
 block discarded – undo
631 643
 				$action['unparsed_destination'] = $action['unparsed_filename'];
632 644
 
633 645
 				// If it's not auto do we think we have something we can act upon?
634
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
635
-					$theme_action = '';
646
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
647
+									$theme_action = '';
648
+				}
636 649
 				// ... or if it's auto do we even want to do anything?
637
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
638
-					$theme_action = '';
650
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
651
+									$theme_action = '';
652
+				}
639 653
 
640 654
 				// So, we still want to do something?
641
-				if ($theme_action != '')
642
-					$themeFinds['candidates'][] = $action;
655
+				if ($theme_action != '') {
656
+									$themeFinds['candidates'][] = $action;
657
+				}
643 658
 				// Otherwise is this is going into another theme record it.
644
-				elseif ($matches[1] == 'themes_dir')
645
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
659
+				elseif ($matches[1] == 'themes_dir') {
660
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
661
+				}
646 662
 			}
647 663
 		}
648 664
 
649
-		if (empty($thisAction))
650
-			continue;
665
+		if (empty($thisAction)) {
666
+					continue;
667
+		}
651 668
 
652 669
 		if (!in_array($action['type'], array('hook', 'credits')))
653 670
 		{
654
-			if ($context['uninstalling'])
655
-				$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
656
-			else
657
-				$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
671
+			if ($context['uninstalling']) {
672
+							$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
673
+			} else {
674
+							$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
675
+			}
658 676
 		}
659 677
 
660 678
 		// Don't fail if a file/directory we're trying to create doesn't exist...
@@ -669,8 +687,9 @@  discard block
 block discarded – undo
669 687
 		}
670 688
 
671 689
 		// @todo None given?
672
-		if (empty($thisAction['description']))
673
-			$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
690
+		if (empty($thisAction['description'])) {
691
+					$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
692
+		}
674 693
 
675 694
 		$context['actions'][] = $thisAction;
676 695
 	}
@@ -683,18 +702,21 @@  discard block
 block discarded – undo
683 702
 			// Get the part of the file we'll be dealing with.
684 703
 			preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
685 704
 
686
-			if ($matches[1] == 'imagesdir')
687
-				$path = '/' . basename($settings['default_images_url']);
688
-			elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir')
689
-				$path = '/languages';
690
-			else
691
-				$path = '';
705
+			if ($matches[1] == 'imagesdir') {
706
+							$path = '/' . basename($settings['default_images_url']);
707
+			} elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
708
+							$path = '/languages';
709
+			} else {
710
+							$path = '';
711
+			}
692 712
 
693
-			if (!empty($matches[3]))
694
-				$path .= $matches[3];
713
+			if (!empty($matches[3])) {
714
+							$path .= $matches[3];
715
+			}
695 716
 
696
-			if (!$context['uninstalling'])
697
-				$path .= '/' . basename($action_data['filename']);
717
+			if (!$context['uninstalling']) {
718
+							$path .= '/' . basename($action_data['filename']);
719
+			}
698 720
 
699 721
 			// Loop through each custom theme to note it's candidacy!
700 722
 			foreach ($theme_paths as $id => $theme_data)
@@ -710,36 +732,40 @@  discard block
 block discarded – undo
710 732
 						if (!mktree(dirname($real_path), false))
711 733
 						{
712 734
 							$temp = dirname($real_path);
713
-							while (!file_exists($temp) && strlen($temp) > 1)
714
-								$temp = dirname($temp);
735
+							while (!file_exists($temp) && strlen($temp) > 1) {
736
+															$temp = dirname($temp);
737
+							}
715 738
 							$chmod_files[] = $temp;
716 739
 						}
717 740
 
718
-						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path))))
719
-							$chmod_files[] = $real_path;
741
+						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
742
+													$chmod_files[] = $real_path;
743
+						}
720 744
 
721
-						if (!isset($context['theme_actions'][$id]))
722
-							$context['theme_actions'][$id] = array(
745
+						if (!isset($context['theme_actions'][$id])) {
746
+													$context['theme_actions'][$id] = array(
723 747
 								'name' => $theme_data['name'],
724 748
 								'actions' => array(),
725 749
 							);
750
+						}
726 751
 
727
-						if ($context['uninstalling'])
728
-							$context['theme_actions'][$id]['actions'][] = array(
752
+						if ($context['uninstalling']) {
753
+													$context['theme_actions'][$id]['actions'][] = array(
729 754
 								'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
730 755
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
731 756
 								'description' => '',
732 757
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))),
733 758
 								'not_mod' => true,
734 759
 							);
735
-						else
736
-							$context['theme_actions'][$id]['actions'][] = array(
760
+						} else {
761
+													$context['theme_actions'][$id]['actions'][] = array(
737 762
 								'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
738 763
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
739 764
 								'description' => '',
740 765
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))),
741 766
 								'not_mod' => true,
742 767
 							);
768
+						}
743 769
 					}
744 770
 				}
745 771
 			}
@@ -749,8 +775,9 @@  discard block
 block discarded – undo
749 775
 	// Trash the cache... which will also check permissions for us!
750 776
 	package_flush_cache(true);
751 777
 
752
-	if (file_exists($packagesdir . '/temp'))
753
-		deltree($packagesdir . '/temp');
778
+	if (file_exists($packagesdir . '/temp')) {
779
+			deltree($packagesdir . '/temp');
780
+	}
754 781
 
755 782
 	if (!empty($chmod_files))
756 783
 	{
@@ -775,8 +802,9 @@  discard block
 block discarded – undo
775 802
 	checkSession();
776 803
 
777 804
 	// If there's no file, what are we installing?
778
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
779
-		redirectexit('action=admin;area=packages');
805
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
806
+			redirectexit('action=admin;area=packages');
807
+	}
780 808
 	$context['filename'] = $_REQUEST['package'];
781 809
 
782 810
 	// If this is an uninstall, we'll have an id.
@@ -797,51 +825,55 @@  discard block
 block discarded – undo
797 825
 
798 826
 	$context['sub_template'] = 'extract_package';
799 827
 
800
-	if (!file_exists($packagesdir . '/' . $context['filename']))
801
-		fatal_lang_error('package_no_file', false);
828
+	if (!file_exists($packagesdir . '/' . $context['filename'])) {
829
+			fatal_lang_error('package_no_file', false);
830
+	}
802 831
 
803 832
 	// Load up the package FTP information?
804 833
 	create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
805 834
 
806 835
 	// Make sure temp directory exists and is empty!
807
-	if (file_exists($packagesdir . '/temp'))
808
-		deltree($packagesdir . '/temp', false);
809
-	else
810
-		mktree($packagesdir . '/temp', 0777);
836
+	if (file_exists($packagesdir . '/temp')) {
837
+			deltree($packagesdir . '/temp', false);
838
+	} else {
839
+			mktree($packagesdir . '/temp', 0777);
840
+	}
811 841
 
812 842
 	// Let the unpacker do the work.
813 843
 	if (is_file($packagesdir . '/' . $context['filename']))
814 844
 	{
815 845
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
816 846
 
817
-		if (!file_exists($packagesdir . '/temp/package-info.xml'))
818
-			foreach ($context['extracted_files'] as $file)
847
+		if (!file_exists($packagesdir . '/temp/package-info.xml')) {
848
+					foreach ($context['extracted_files'] as $file)
819 849
 				if (basename($file['filename']) == 'package-info.xml')
820 850
 				{
821 851
 					$context['base_path'] = dirname($file['filename']) . '/';
852
+		}
822 853
 					break;
823 854
 				}
824 855
 
825
-		if (!isset($context['base_path']))
826
-			$context['base_path'] = '';
827
-	}
828
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
856
+		if (!isset($context['base_path'])) {
857
+					$context['base_path'] = '';
858
+		}
859
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
829 860
 	{
830 861
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
831 862
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
832 863
 		$context['base_path'] = '';
864
+	} else {
865
+			fatal_lang_error('no_access', false);
833 866
 	}
834
-	else
835
-		fatal_lang_error('no_access', false);
836 867
 
837 868
 	// Are we installing this into any custom themes?
838 869
 	$custom_themes = array(1);
839 870
 	$known_themes = explode(',', $modSettings['knownThemes']);
840 871
 	if (!empty($_POST['custom_theme']))
841 872
 	{
842
-		foreach ($_POST['custom_theme'] as $tid)
843
-			if (in_array($tid, $known_themes))
873
+		foreach ($_POST['custom_theme'] as $tid) {
874
+					if (in_array($tid, $known_themes))
844 875
 				$custom_themes[] = (int) $tid;
876
+		}
845 877
 	}
846 878
 
847 879
 	// Now load up the paths of the themes that we need to know about.
@@ -858,8 +890,9 @@  discard block
 block discarded – undo
858 890
 	);
859 891
 	$theme_paths = array();
860 892
 	$themes_installed = array(1);
861
-	while ($row = $smcFunc['db_fetch_assoc']($request))
862
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
893
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
894
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
895
+	}
863 896
 	$smcFunc['db_free_result']($request);
864 897
 
865 898
 	// Are there any theme copying that we want to take place?
@@ -871,11 +904,13 @@  discard block
 block discarded – undo
871 904
 	{
872 905
 		foreach ($_POST['theme_changes'] as $change)
873 906
 		{
874
-			if (empty($change))
875
-				continue;
907
+			if (empty($change)) {
908
+							continue;
909
+			}
876 910
 			$theme_data = smf_json_decode(base64_decode($change), true);
877
-			if (empty($theme_data['type']))
878
-				continue;
911
+			if (empty($theme_data['type'])) {
912
+							continue;
913
+			}
879 914
 
880 915
 			$themes_installed[] = $theme_data['id'];
881 916
 			$context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
@@ -884,8 +919,9 @@  discard block
 block discarded – undo
884 919
 
885 920
 	// Get the package info...
886 921
 	$packageInfo = getPackageInfo($context['filename']);
887
-	if (!is_array($packageInfo))
888
-		fatal_lang_error($packageInfo);
922
+	if (!is_array($packageInfo)) {
923
+			fatal_lang_error($packageInfo);
924
+	}
889 925
 
890 926
 	$packageInfo['filename'] = $context['filename'];
891 927
 
@@ -897,8 +933,9 @@  discard block
 block discarded – undo
897 933
 	{
898 934
 		$_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
899 935
 		$result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
900
-		if (!$result)
901
-			fatal_lang_error('could_not_package_backup', false);
936
+		if (!$result) {
937
+					fatal_lang_error('could_not_package_backup', false);
938
+		}
902 939
 	}
903 940
 
904 941
 	// The mod isn't installed.... unless proven otherwise.
@@ -938,35 +975,38 @@  discard block
 block discarded – undo
938 975
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
939 976
 
940 977
 		// Gadzooks!  There's no uninstaller at all!?
941
-		if (empty($install_log))
942
-			fatal_lang_error('package_uninstall_cannot', false);
978
+		if (empty($install_log)) {
979
+					fatal_lang_error('package_uninstall_cannot', false);
980
+		}
943 981
 
944 982
 		// They can only uninstall from what it was originally installed into.
945
-		foreach ($theme_paths as $id => $data)
946
-			if ($id != 1 && !in_array($id, $old_themes))
983
+		foreach ($theme_paths as $id => $data) {
984
+					if ($id != 1 && !in_array($id, $old_themes))
947 985
 				unset($theme_paths[$id]);
948
-	}
949
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
986
+		}
987
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
950 988
 	{
951 989
 		// Look for an upgrade...
952 990
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version);
953 991
 
954 992
 		// There was no upgrade....
955
-		if (empty($install_log))
956
-			$context['is_installed'] = true;
957
-		else
993
+		if (empty($install_log)) {
994
+					$context['is_installed'] = true;
995
+		} else
958 996
 		{
959 997
 			// Upgrade previous themes only!
960
-			foreach ($theme_paths as $id => $data)
961
-				if ($id != 1 && !in_array($id, $old_themes))
998
+			foreach ($theme_paths as $id => $data) {
999
+							if ($id != 1 && !in_array($id, $old_themes))
962 1000
 					unset($theme_paths[$id]);
1001
+			}
963 1002
 		}
1003
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
1004
+			$context['is_installed'] = true;
964 1005
 	}
965
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
966
-		$context['is_installed'] = true;
967 1006
 
968
-	if (!isset($old_version) || $context['is_installed'])
969
-		$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1007
+	if (!isset($old_version) || $context['is_installed']) {
1008
+			$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1009
+	}
970 1010
 
971 1011
 	$context['install_finished'] = false;
972 1012
 
@@ -983,37 +1023,39 @@  discard block
 block discarded – undo
983 1023
 
984 1024
 			if ($action['type'] == 'modification' && !empty($action['filename']))
985 1025
 			{
986
-				if ($action['boardmod'])
987
-					$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
988
-				else
989
-					$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1026
+				if ($action['boardmod']) {
1027
+									$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1028
+				} else {
1029
+									$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1030
+				}
990 1031
 
991 1032
 				// Any errors worth noting?
992 1033
 				foreach ($mod_actions as $key => $modAction)
993 1034
 				{
994
-					if ($modAction['type'] == 'failure')
995
-						$failed_steps[] = array(
1035
+					if ($modAction['type'] == 'failure') {
1036
+											$failed_steps[] = array(
996 1037
 							'file' => $modAction['filename'],
997 1038
 							'large_step' => $failed_count,
998 1039
 							'sub_step' => $key,
999 1040
 							'theme' => 1,
1000 1041
 						);
1042
+					}
1001 1043
 
1002 1044
 					// Gather the themes we installed into.
1003
-					if (!empty($modAction['is_custom']))
1004
-						$themes_installed[] = $modAction['is_custom'];
1045
+					if (!empty($modAction['is_custom'])) {
1046
+											$themes_installed[] = $modAction['is_custom'];
1047
+					}
1005 1048
 				}
1006
-			}
1007
-			elseif ($action['type'] == 'code' && !empty($action['filename']))
1049
+			} elseif ($action['type'] == 'code' && !empty($action['filename']))
1008 1050
 			{
1009 1051
 				// This is just here as reference for what is available.
1010 1052
 				global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
1011 1053
 
1012 1054
 				// Now include the file and be done with it ;).
1013
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1014
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1015
-			}
1016
-			elseif ($action['type'] == 'credits')
1055
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1056
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1057
+				}
1058
+			} elseif ($action['type'] == 'credits')
1017 1059
 			{
1018 1060
 				// Time to build the billboard
1019 1061
 				$credits_tag = array(
@@ -1023,13 +1065,13 @@  discard block
 block discarded – undo
1023 1065
 					'copyright' => $action['copyright'],
1024 1066
 					'title' => $action['title'],
1025 1067
 				);
1026
-			}
1027
-			elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1068
+			} elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1028 1069
 			{
1029
-				if ($action['reverse'])
1030
-					remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1031
-				else
1032
-					add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1070
+				if ($action['reverse']) {
1071
+									remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1072
+				} else {
1073
+									add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1074
+				}
1033 1075
 			}
1034 1076
 			// Only do the database changes on uninstall if requested.
1035 1077
 			elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes'])))
@@ -1042,8 +1084,9 @@  discard block
 block discarded – undo
1042 1084
 				db_extend('packages');
1043 1085
 
1044 1086
 				// Let the file work its magic ;)
1045
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1046
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1087
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1088
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1089
+				}
1047 1090
 			}
1048 1091
 			// Handle a redirect...
1049 1092
 			elseif ($action['type'] == 'redirect' && !empty($action['redirect_url']))
@@ -1125,8 +1168,9 @@  discard block
 block discarded – undo
1125 1168
 			reloadSettings();
1126 1169
 
1127 1170
 			// Any db changes from older version?
1128
-			if (!empty($old_db_changes))
1129
-				$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1171
+			if (!empty($old_db_changes)) {
1172
+							$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1173
+			}
1130 1174
 
1131 1175
 			// If there are some database changes we might want to remove then filter them out.
1132 1176
 			if (!empty($db_package_log))
@@ -1142,22 +1186,24 @@  discard block
 block discarded – undo
1142 1186
 				 */
1143 1187
 				function sort_table_first($a, $b)
1144 1188
 				{
1145
-					if ($a[0] == $b[0])
1146
-						return 0;
1189
+					if ($a[0] == $b[0]) {
1190
+											return 0;
1191
+					}
1147 1192
 					return $a[0] == 'remove_table' ? -1 : 1;
1148 1193
 				}
1149 1194
 				usort($db_package_log, 'sort_table_first');
1150 1195
 				foreach ($db_package_log as $k => $log)
1151 1196
 				{
1152
-					if ($log[0] == 'remove_table')
1153
-						$tables[] = $log[1];
1154
-					elseif (in_array($log[1], $tables))
1155
-						unset($db_package_log[$k]);
1197
+					if ($log[0] == 'remove_table') {
1198
+											$tables[] = $log[1];
1199
+					} elseif (in_array($log[1], $tables)) {
1200
+											unset($db_package_log[$k]);
1201
+					}
1156 1202
 				}
1157 1203
 				$db_changes = json_encode($db_package_log);
1204
+			} else {
1205
+							$db_changes = '';
1158 1206
 			}
1159
-			else
1160
-				$db_changes = '';
1161 1207
 
1162 1208
 			// What themes did we actually install?
1163 1209
 			$themes_installed = array_unique($themes_installed);
@@ -1206,18 +1252,20 @@  discard block
 block discarded – undo
1206 1252
 
1207 1253
 		foreach ($db_changes as $change)
1208 1254
 		{
1209
-			if ($change[0] == 'remove_table' && isset($change[1]))
1210
-				$smcFunc['db_drop_table']($change[1]);
1211
-			elseif ($change[0] == 'remove_column' && isset($change[2]))
1212
-				$smcFunc['db_remove_column']($change[1], $change[2]);
1213
-			elseif ($change[0] == 'remove_index' && isset($change[2]))
1214
-				$smcFunc['db_remove_index']($change[1], $change[2]);
1255
+			if ($change[0] == 'remove_table' && isset($change[1])) {
1256
+							$smcFunc['db_drop_table']($change[1]);
1257
+			} elseif ($change[0] == 'remove_column' && isset($change[2])) {
1258
+							$smcFunc['db_remove_column']($change[1], $change[2]);
1259
+			} elseif ($change[0] == 'remove_index' && isset($change[2])) {
1260
+							$smcFunc['db_remove_index']($change[1], $change[2]);
1261
+			}
1215 1262
 		}
1216 1263
 	}
1217 1264
 
1218 1265
 	// Clean house... get rid of the evidence ;).
1219
-	if (file_exists($packagesdir . '/temp'))
1220
-		deltree($packagesdir . '/temp');
1266
+	if (file_exists($packagesdir . '/temp')) {
1267
+			deltree($packagesdir . '/temp');
1268
+	}
1221 1269
 
1222 1270
 	// Log what we just did.
1223 1271
 	logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin');
@@ -1239,8 +1287,9 @@  discard block
 block discarded – undo
1239 1287
 	require_once($sourcedir . '/Subs-Package.php');
1240 1288
 
1241 1289
 	// No package?  Show him or her the door.
1242
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1243
-		redirectexit('action=admin;area=packages');
1290
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1291
+			redirectexit('action=admin;area=packages');
1292
+	}
1244 1293
 
1245 1294
 	$context['linktree'][] = array(
1246 1295
 		'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'],
@@ -1253,11 +1302,12 @@  discard block
 block discarded – undo
1253 1302
 	$context['filename'] = $_REQUEST['package'];
1254 1303
 
1255 1304
 	// Let the unpacker do the work.
1256
-	if (is_file($packagesdir . '/' . $context['filename']))
1257
-		$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1258
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1259
-		$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1260
-}
1305
+	if (is_file($packagesdir . '/' . $context['filename'])) {
1306
+			$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1307
+	} elseif (is_dir($packagesdir . '/' . $context['filename'])) {
1308
+			$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1309
+	}
1310
+	}
1261 1311
 
1262 1312
 /**
1263 1313
  * Display one of the files in a package.
@@ -1269,22 +1319,25 @@  discard block
 block discarded – undo
1269 1319
 	require_once($sourcedir . '/Subs-Package.php');
1270 1320
 
1271 1321
 	// No package?  Show him or her the door.
1272
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1273
-		redirectexit('action=admin;area=packages');
1322
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1323
+			redirectexit('action=admin;area=packages');
1324
+	}
1274 1325
 
1275 1326
 	// No file?  Show him or her the door.
1276
-	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '')
1277
-		redirectexit('action=admin;area=packages');
1327
+	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') {
1328
+			redirectexit('action=admin;area=packages');
1329
+	}
1278 1330
 
1279 1331
 	$_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_')));
1280 1332
 	$_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']);
1281 1333
 
1282 1334
 	if (isset($_REQUEST['raw']))
1283 1335
 	{
1284
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1285
-			echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1286
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1287
-			echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1336
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1337
+					echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1338
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1339
+					echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1340
+		}
1288 1341
 
1289 1342
 		obExit(false);
1290 1343
 	}
@@ -1301,17 +1354,19 @@  discard block
 block discarded – undo
1301 1354
 	$context['filename'] = $_REQUEST['file'];
1302 1355
 
1303 1356
 	// Let the unpacker do the work.... but make sure we handle images properly.
1304
-	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png')))
1305
-		$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1306
-	else
1357
+	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) {
1358
+			$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1359
+	} else
1307 1360
 	{
1308
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1309
-			$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1310
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1311
-			$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1361
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1362
+					$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1363
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1364
+					$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1365
+		}
1312 1366
 
1313
-		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php')
1314
-			$context['filedata'] = highlight_php_code($context['filedata']);
1367
+		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') {
1368
+					$context['filedata'] = highlight_php_code($context['filedata']);
1369
+		}
1315 1370
 	}
1316 1371
 }
1317 1372
 
@@ -1326,8 +1381,9 @@  discard block
 block discarded – undo
1326 1381
 	checkSession('get');
1327 1382
 
1328 1383
 	// Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
1329
-	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups')
1330
-		redirectexit('action=admin;area=packages;sa=browse');
1384
+	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') {
1385
+			redirectexit('action=admin;area=packages;sa=browse');
1386
+	}
1331 1387
 	$_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
1332 1388
 
1333 1389
 	// Can't delete what's not there.
@@ -1335,9 +1391,9 @@  discard block
 block discarded – undo
1335 1391
 	{
1336 1392
 		create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true));
1337 1393
 
1338
-		if (is_dir($packagesdir . '/' . $_GET['package']))
1339
-			deltree($packagesdir . '/' . $_GET['package']);
1340
-		else
1394
+		if (is_dir($packagesdir . '/' . $_GET['package'])) {
1395
+					deltree($packagesdir . '/' . $_GET['package']);
1396
+		} else
1341 1397
 		{
1342 1398
 			smf_chmod($packagesdir . '/' . $_GET['package'], 0777);
1343 1399
 			unlink($packagesdir . '/' . $_GET['package']);
@@ -1385,8 +1441,9 @@  discard block
 block discarded – undo
1385 1441
 					'data' => array(
1386 1442
 						'function' => function($package_md5) use ($type, &$context)
1387 1443
 						{
1388
-							if (isset($context['available_' . $type . ''][$package_md5]))
1389
-								return $context['available_' . $type . ''][$package_md5]['sort_id'];
1444
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1445
+															return $context['available_' . $type . ''][$package_md5]['sort_id'];
1446
+							}
1390 1447
 						},
1391 1448
 					),
1392 1449
 					'sort' => array(
@@ -1402,8 +1459,9 @@  discard block
 block discarded – undo
1402 1459
 					'data' => array(
1403 1460
 						'function' => function($package_md5) use ($type, &$context)
1404 1461
 						{
1405
-							if (isset($context['available_' . $type . ''][$package_md5]))
1406
-								return $context['available_' . $type . ''][$package_md5]['name'];
1462
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1463
+															return $context['available_' . $type . ''][$package_md5]['name'];
1464
+							}
1407 1465
 						},
1408 1466
 					),
1409 1467
 					'sort' => array(
@@ -1418,8 +1476,9 @@  discard block
 block discarded – undo
1418 1476
 					'data' => array(
1419 1477
 						'function' => function($package_md5) use ($type, &$context)
1420 1478
 						{
1421
-							if (isset($context['available_' . $type . ''][$package_md5]))
1422
-								return $context['available_' . $type . ''][$package_md5]['version'];
1479
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1480
+															return $context['available_' . $type . ''][$package_md5]['version'];
1481
+							}
1423 1482
 						},
1424 1483
 					),
1425 1484
 					'sort' => array(
@@ -1434,8 +1493,9 @@  discard block
 block discarded – undo
1434 1493
 					'data' => array(
1435 1494
 						'function' => function($package_md5) use ($type, $txt, &$context)
1436 1495
 						{
1437
-							if (isset($context['available_' . $type . ''][$package_md5]))
1438
-								return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1496
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1497
+															return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1498
+							}
1439 1499
 						},
1440 1500
 						'class' => 'smalltext',
1441 1501
 					),
@@ -1451,28 +1511,30 @@  discard block
 block discarded – undo
1451 1511
 					'data' => array(
1452 1512
 						'function' => function($package_md5) use ($type, &$context, $scripturl, $txt)
1453 1513
 						{
1454
-							if (!isset($context['available_' . $type . ''][$package_md5]))
1455
-								return '';
1514
+							if (!isset($context['available_' . $type . ''][$package_md5])) {
1515
+															return '';
1516
+							}
1456 1517
 
1457 1518
 							// Rewrite shortcut
1458 1519
 							$package = $context['available_' . $type . ''][$package_md5];
1459 1520
 							$return = '';
1460 1521
 
1461
-							if ($package['can_uninstall'])
1462
-								$return = '
1522
+							if ($package['can_uninstall']) {
1523
+															$return = '
1463 1524
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>';
1464
-							elseif ($package['can_emulate_uninstall'])
1465
-								$return = '
1525
+							} elseif ($package['can_emulate_uninstall']) {
1526
+															$return = '
1466 1527
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>';
1467
-							elseif ($package['can_upgrade'])
1468
-								$return = '
1528
+							} elseif ($package['can_upgrade']) {
1529
+															$return = '
1469 1530
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>';
1470
-							elseif ($package['can_install'])
1471
-								$return = '
1531
+							} elseif ($package['can_install']) {
1532
+															$return = '
1472 1533
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>';
1473
-							elseif ($package['can_emulate_install'])
1474
-								$return = '
1534
+							} elseif ($package['can_emulate_install']) {
1535
+															$return = '
1475 1536
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>';
1537
+							}
1476 1538
 
1477 1539
 							return $return . '
1478 1540
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a>
@@ -1537,12 +1599,14 @@  discard block
 block discarded – undo
1537 1599
 	static $packages, $installed_mods;
1538 1600
 
1539 1601
 	// Start things up
1540
-	if (!isset($packages[$params]))
1541
-		$packages[$params] = array();
1602
+	if (!isset($packages[$params])) {
1603
+			$packages[$params] = array();
1604
+	}
1542 1605
 
1543 1606
 	// We need the packages directory to be writable for this.
1544
-	if (!@is_writable($packagesdir))
1545
-		create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1607
+	if (!@is_writable($packagesdir)) {
1608
+			create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1609
+	}
1546 1610
 
1547 1611
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1548 1612
 
@@ -1550,41 +1614,44 @@  discard block
 block discarded – undo
1550 1614
 	if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version)
1551 1615
 	{
1552 1616
 		unset($_SESSION['version_emulate']);
1553
-	}
1554
-	elseif (isset($_GET['version_emulate']))
1617
+	} elseif (isset($_GET['version_emulate']))
1555 1618
 	{
1556
-		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate']))
1557
-			unset($_SESSION['version_emulate']);
1558
-		elseif ($_GET['version_emulate'] !== 0)
1559
-			$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1619
+		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) {
1620
+					unset($_SESSION['version_emulate']);
1621
+		} elseif ($_GET['version_emulate'] !== 0) {
1622
+					$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1623
+		}
1560 1624
 	}
1561 1625
 	if (!empty($_SESSION['version_emulate']))
1562 1626
 	{
1563 1627
 		$context['forum_version'] = 'SMF ' . $_SESSION['version_emulate'];
1564 1628
 		$the_version = $_SESSION['version_emulate'];
1565 1629
 	}
1566
-	if (isset($_SESSION['single_version_emulate']))
1567
-		unset($_SESSION['single_version_emulate']);
1630
+	if (isset($_SESSION['single_version_emulate'])) {
1631
+			unset($_SESSION['single_version_emulate']);
1632
+	}
1568 1633
 
1569 1634
 	if (empty($installed_mods))
1570 1635
 	{
1571 1636
 		$instmods = loadInstalledPackages();
1572 1637
 		$installed_mods = array();
1573 1638
 		// Look through the list of installed mods...
1574
-		foreach ($instmods as $installed_mod)
1575
-			$installed_mods[$installed_mod['package_id']] = array(
1639
+		foreach ($instmods as $installed_mod) {
1640
+					$installed_mods[$installed_mod['package_id']] = array(
1576 1641
 				'id' => $installed_mod['id'],
1577 1642
 				'version' => $installed_mod['version'],
1578 1643
 				'time_installed' => $installed_mod['time_installed'],
1579 1644
 			);
1645
+		}
1580 1646
 
1581 1647
 		// Get a list of all the ids installed, so the latest packages won't include already installed ones.
1582 1648
 		$context['installed_mods'] = array_keys($installed_mods);
1583 1649
 	}
1584 1650
 
1585
-	if (empty($packages))
1586
-		foreach ($context['modification_types'] as $type)
1651
+	if (empty($packages)) {
1652
+			foreach ($context['modification_types'] as $type)
1587 1653
 			$packages[$type] = array();
1654
+	}
1588 1655
 
1589 1656
 	if ($dir = @opendir($packagesdir))
1590 1657
 	{
@@ -1600,50 +1667,56 @@  discard block
 block discarded – undo
1600 1667
 
1601 1668
 		while ($package = readdir($dir))
1602 1669
 		{
1603
-			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
1604
-				continue;
1670
+			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
1671
+							continue;
1672
+			}
1605 1673
 
1606 1674
 			$skip = false;
1607
-			foreach ($context['modification_types'] as $type)
1608
-				if (isset($context['available_' . $type][md5($package)]))
1675
+			foreach ($context['modification_types'] as $type) {
1676
+							if (isset($context['available_' . $type][md5($package)]))
1609 1677
 					$skip = true;
1678
+			}
1610 1679
 
1611
-			if ($skip)
1612
-				continue;
1680
+			if ($skip) {
1681
+							continue;
1682
+			}
1613 1683
 
1614 1684
 			// Skip directories or files that are named the same.
1615 1685
 			if (is_dir($packagesdir . '/' . $package))
1616 1686
 			{
1617
-				if (in_array($package, $dirs))
1618
-					continue;
1687
+				if (in_array($package, $dirs)) {
1688
+									continue;
1689
+				}
1619 1690
 				$dirs[] = $package;
1620
-			}
1621
-			elseif (substr(strtolower($package), -7) == '.tar.gz')
1691
+			} elseif (substr(strtolower($package), -7) == '.tar.gz')
1622 1692
 			{
1623
-				if (in_array(substr($package, 0, -7), $dirs))
1624
-					continue;
1693
+				if (in_array(substr($package, 0, -7), $dirs)) {
1694
+									continue;
1695
+				}
1625 1696
 				$dirs[] = substr($package, 0, -7);
1626
-			}
1627
-			elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1697
+			} elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1628 1698
 			{
1629
-				if (in_array(substr($package, 0, -4), $dirs))
1630
-					continue;
1699
+				if (in_array(substr($package, 0, -4), $dirs)) {
1700
+									continue;
1701
+				}
1631 1702
 				$dirs[] = substr($package, 0, -4);
1632 1703
 			}
1633 1704
 
1634 1705
 			$packageInfo = getPackageInfo($package);
1635
-			if (!is_array($packageInfo))
1636
-				continue;
1706
+			if (!is_array($packageInfo)) {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (!empty($packageInfo))
1639 1711
 			{
1640 1712
 				$packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0;
1641 1713
 				$packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0;
1642 1714
 
1643
-				if (!isset($sort_id[$packageInfo['type']]))
1644
-					$packageInfo['sort_id'] = $sort_id['unknown'];
1645
-				else
1646
-					$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1715
+				if (!isset($sort_id[$packageInfo['type']])) {
1716
+									$packageInfo['sort_id'] = $sort_id['unknown'];
1717
+				} else {
1718
+									$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1719
+				}
1647 1720
 
1648 1721
 				$packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]);
1649 1722
 				$packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']);
@@ -1692,10 +1765,11 @@  discard block
 block discarded – undo
1692 1765
 					foreach ($upgrades as $upgrade)
1693 1766
 					{
1694 1767
 						// Even if it is for this SMF, is it for the installed version of the mod?
1695
-						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for')))
1696
-							if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1768
+						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) {
1769
+													if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1697 1770
 							{
1698 1771
 								$packageInfo['can_upgrade'] = true;
1772
+						}
1699 1773
 								break;
1700 1774
 							}
1701 1775
 					}
@@ -1772,10 +1846,11 @@  discard block
 block discarded – undo
1772 1846
 
1773 1847
 	if (isset($_GET['type']) && $_GET['type'] == $params)
1774 1848
 	{
1775
-		if (isset($_GET['desc']))
1776
-			krsort($packages[$params]);
1777
-		else
1778
-			ksort($packages[$params]);
1849
+		if (isset($_GET['desc'])) {
1850
+					krsort($packages[$params]);
1851
+		} else {
1852
+					ksort($packages[$params]);
1853
+		}
1779 1854
 	}
1780 1855
 
1781 1856
 	return $packages[$params];
@@ -1804,10 +1879,11 @@  discard block
 block discarded – undo
1804 1879
 		redirectexit('action=admin;area=packages;sa=options');
1805 1880
 	}
1806 1881
 
1807
-	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1808
-		$default_username = $match[1];
1809
-	else
1810
-		$default_username = '';
1882
+	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) {
1883
+			$default_username = $match[1];
1884
+	} else {
1885
+			$default_username = '';
1886
+	}
1811 1887
 
1812 1888
 	$context['page_title'] = $txt['package_settings'];
1813 1889
 	$context['sub_template'] = 'install_options';
@@ -1836,8 +1912,9 @@  discard block
 block discarded – undo
1836 1912
 	isAllowedTo('admin_forum');
1837 1913
 
1838 1914
 	// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
1839
-	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key']))
1840
-		fatal_lang_error('operation_invalid', 'general');
1915
+	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
1916
+			fatal_lang_error('operation_invalid', 'general');
1917
+	}
1841 1918
 
1842 1919
 	// Load the required file.
1843 1920
 	require_once($sourcedir . '/Subs-Package.php');
@@ -1853,18 +1930,19 @@  discard block
 block discarded – undo
1853 1930
 	{
1854 1931
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1855 1932
 
1856
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
1857
-			foreach ($context['extracted_files'] as $file)
1933
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
1934
+					foreach ($context['extracted_files'] as $file)
1858 1935
 				if (basename($file['filename']) == 'package-info.xml')
1859 1936
 				{
1860 1937
 					$context['base_path'] = dirname($file['filename']) . '/';
1938
+		}
1861 1939
 					break;
1862 1940
 				}
1863 1941
 
1864
-		if (!isset($context['base_path']))
1865
-			$context['base_path'] = '';
1866
-	}
1867
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1942
+		if (!isset($context['base_path'])) {
1943
+					$context['base_path'] = '';
1944
+		}
1945
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
1868 1946
 	{
1869 1947
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1870 1948
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
@@ -1885,8 +1963,9 @@  discard block
 block discarded – undo
1885 1963
 		)
1886 1964
 	);
1887 1965
 	$theme_paths = array();
1888
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1889
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1968
+	}
1890 1969
 	$smcFunc['db_free_result']($request);
1891 1970
 
1892 1971
 	// If we're viewing uninstall operations, only consider themes that
@@ -1911,19 +1990,21 @@  discard block
 block discarded – undo
1911 1990
 				list ($old_themes) = $smcFunc['db_fetch_row']($request);
1912 1991
 				$old_themes = explode(',', $old_themes);
1913 1992
 
1914
-				foreach ($theme_paths as $id => $data)
1915
-					if ($id != 1 && !in_array($id, $old_themes))
1993
+				foreach ($theme_paths as $id => $data) {
1994
+									if ($id != 1 && !in_array($id, $old_themes))
1916 1995
 						unset($theme_paths[$id]);
1996
+				}
1917 1997
 			}
1918 1998
 			$smcFunc['db_free_result']($request);
1919 1999
 		}
1920 2000
 	}
1921 2001
 
1922 2002
 	// Boardmod?
1923
-	if (isset($_REQUEST['boardmod']))
1924
-		$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
1925
-	else
1926
-		$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2003
+	if (isset($_REQUEST['boardmod'])) {
2004
+			$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2005
+	} else {
2006
+			$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2007
+	}
1927 2008
 
1928 2009
 	// Ok lets get the content of the file.
1929 2010
 	$context['operations'] = array(
@@ -1979,9 +2060,9 @@  discard block
 block discarded – undo
1979 2060
 			'path' => $detect_path,
1980 2061
 			'form_elements_only' => true,
1981 2062
 		);
2063
+	} else {
2064
+			$context['ftp_connected'] = true;
1982 2065
 	}
1983
-	else
1984
-		$context['ftp_connected'] = true;
1985 2066
 
1986 2067
 	// Define the template.
1987 2068
 	$context['page_title'] = $txt['package_file_perms'];
@@ -2094,18 +2175,19 @@  discard block
 block discarded – undo
2094 2175
 	{
2095 2176
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2096 2177
 
2097
-		if (!is_array($modSettings['attachmentUploadDir']))
2098
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2178
+		if (!is_array($modSettings['attachmentUploadDir'])) {
2179
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2180
+		}
2099 2181
 
2100 2182
 		// @todo Should we suggest non-current directories be read only?
2101
-		foreach ($modSettings['attachmentUploadDir'] as $dir)
2102
-			$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2183
+		foreach ($modSettings['attachmentUploadDir'] as $dir) {
2184
+					$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2103 2185
 			'type' => 'dir',
2104 2186
 			'writable_on' => 'restrictive',
2105 2187
 		);
2188
+		}
2106 2189
 
2107
-	}
2108
-	elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2190
+	} elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2109 2191
 	{
2110 2192
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2111 2193
 		$context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array(
@@ -2155,8 +2237,8 @@  discard block
 block discarded – undo
2155 2237
 	);
2156 2238
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2157 2239
 	{
2158
-		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes'))
2159
-			$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2240
+		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) {
2241
+					$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2160 2242
 				'type' => 'dir_recursive',
2161 2243
 				'list_contents' => true,
2162 2244
 				'contents' => array(
@@ -2166,7 +2248,7 @@  discard block
 block discarded – undo
2166 2248
 					),
2167 2249
 				),
2168 2250
 			);
2169
-		else
2251
+		} else
2170 2252
 		{
2171 2253
 			$context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array(
2172 2254
 				'type' => 'dir_recursive',
@@ -2183,28 +2265,33 @@  discard block
 block discarded – undo
2183 2265
 	$smcFunc['db_free_result']($request);
2184 2266
 
2185 2267
 	// If we're submitting then let's move on to another function to keep things cleaner..
2186
-	if (isset($_POST['action_changes']))
2187
-		return PackagePermissionsAction();
2268
+	if (isset($_POST['action_changes'])) {
2269
+			return PackagePermissionsAction();
2270
+	}
2188 2271
 
2189 2272
 	$context['look_for'] = array();
2190 2273
 	// Are we looking for a particular tree - normally an expansion?
2191
-	if (!empty($_REQUEST['find']))
2192
-		$context['look_for'][] = base64_decode($_REQUEST['find']);
2274
+	if (!empty($_REQUEST['find'])) {
2275
+			$context['look_for'][] = base64_decode($_REQUEST['find']);
2276
+	}
2193 2277
 	// Only that tree?
2194 2278
 	$context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : '';
2195
-	if ($context['only_find'])
2196
-		$context['look_for'][] = $context['only_find'];
2279
+	if ($context['only_find']) {
2280
+			$context['look_for'][] = $context['only_find'];
2281
+	}
2197 2282
 
2198 2283
 	// Have we got a load of back-catalogue trees to expand from a submit etc?
2199 2284
 	if (!empty($_GET['back_look']))
2200 2285
 	{
2201 2286
 		$potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true);
2202
-		foreach ($potententialTrees as $tree)
2203
-			$context['look_for'][] = $tree;
2287
+		foreach ($potententialTrees as $tree) {
2288
+					$context['look_for'][] = $tree;
2289
+		}
2204 2290
 	}
2205 2291
 	// ... maybe posted?
2206
-	if (!empty($_POST['back_look']))
2207
-		$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2292
+	if (!empty($_POST['back_look'])) {
2293
+			$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2294
+	}
2208 2295
 
2209 2296
 	$context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15)));
2210 2297
 
@@ -2243,9 +2330,9 @@  discard block
 block discarded – undo
2243 2330
 				'chmod' => @is_writable($path),
2244 2331
 				'perms' => @fileperms($path),
2245 2332
 			);
2333
+		} else {
2334
+					unset($context['file_tree'][$path]);
2246 2335
 		}
2247
-		else
2248
-			unset($context['file_tree'][$path]);
2249 2336
 	}
2250 2337
 
2251 2338
 	// Is this actually xml?
@@ -2269,22 +2356,25 @@  discard block
 block discarded – undo
2269 2356
 	global $context;
2270 2357
 
2271 2358
 	$isLikelyPath = false;
2272
-	foreach ($context['look_for'] as $possiblePath)
2273
-		if (substr($possiblePath, 0, strlen($path)) == $path)
2359
+	foreach ($context['look_for'] as $possiblePath) {
2360
+			if (substr($possiblePath, 0, strlen($path)) == $path)
2274 2361
 			$isLikelyPath = true;
2362
+	}
2275 2363
 
2276 2364
 	// Is this where we stop?
2277
-	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath)
2278
-		return;
2279
-	elseif ($level > $context['default_level'] && !$isLikelyPath)
2280
-		return;
2365
+	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) {
2366
+			return;
2367
+	} elseif ($level > $context['default_level'] && !$isLikelyPath) {
2368
+			return;
2369
+	}
2281 2370
 
2282 2371
 	// Are we actually interested in saving this data?
2283 2372
 	$save_data = empty($context['only_find']) || $context['only_find'] == $path;
2284 2373
 
2285 2374
 	// @todo Shouldn't happen - but better error message?
2286
-	if (!is_dir($path))
2287
-		fatal_lang_error('no_access', false);
2375
+	if (!is_dir($path)) {
2376
+			fatal_lang_error('no_access', false);
2377
+	}
2288 2378
 
2289 2379
 	// This is where we put stuff we've found for sorting.
2290 2380
 	$foundData = array(
@@ -2299,11 +2389,13 @@  discard block
 block discarded – undo
2299 2389
 		if (is_file($path . '/' . $entry))
2300 2390
 		{
2301 2391
 			// Are we listing PHP files in this directory?
2302
-			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php')
2303
-				$foundData['files'][$entry] = true;
2392
+			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') {
2393
+							$foundData['files'][$entry] = true;
2394
+			}
2304 2395
 			// A file we were looking for.
2305
-			elseif ($save_data && isset($data['contents'][$entry]))
2306
-				$foundData['files'][$entry] = true;
2396
+			elseif ($save_data && isset($data['contents'][$entry])) {
2397
+							$foundData['files'][$entry] = true;
2398
+			}
2307 2399
 		}
2308 2400
 		// It's a directory - we're interested one way or another, probably...
2309 2401
 		elseif ($entry != '.' && $entry != '..')
@@ -2311,32 +2403,36 @@  discard block
 block discarded – undo
2311 2403
 			// Going further?
2312 2404
 			if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive'))))
2313 2405
 			{
2314
-				if (!isset($data['contents'][$entry]))
2315
-					$foundData['folders'][$entry] = 'dir_recursive';
2316
-				else
2317
-					$foundData['folders'][$entry] = true;
2406
+				if (!isset($data['contents'][$entry])) {
2407
+									$foundData['folders'][$entry] = 'dir_recursive';
2408
+				} else {
2409
+									$foundData['folders'][$entry] = true;
2410
+				}
2318 2411
 
2319 2412
 				// If this wasn't expected inherit the recusiveness...
2320
-				if (!isset($data['contents'][$entry]))
2321
-					// We need to do this as we will be going all recursive.
2413
+				if (!isset($data['contents'][$entry])) {
2414
+									// We need to do this as we will be going all recursive.
2322 2415
 					$data['contents'][$entry] = array(
2323 2416
 						'type' => 'dir_recursive',
2324 2417
 					);
2418
+				}
2325 2419
 
2326 2420
 				// Actually do the recursive stuff...
2327 2421
 				fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1);
2328 2422
 			}
2329 2423
 			// Maybe it is a folder we are not descending into.
2330
-			elseif (isset($data['contents'][$entry]))
2331
-				$foundData['folders'][$entry] = true;
2424
+			elseif (isset($data['contents'][$entry])) {
2425
+							$foundData['folders'][$entry] = true;
2426
+			}
2332 2427
 			// Otherwise we stop here.
2333 2428
 		}
2334 2429
 	}
2335 2430
 	closedir($dh);
2336 2431
 
2337 2432
 	// Nothing to see here?
2338
-	if (!$save_data)
2339
-		return;
2433
+	if (!$save_data) {
2434
+			return;
2435
+	}
2340 2436
 
2341 2437
 	// Now actually add the data, starting with the folders.
2342 2438
 	ksort($foundData['folders']);
@@ -2348,8 +2444,9 @@  discard block
 block discarded – undo
2348 2444
 				'perms' => @fileperms($path . '/' . $folder),
2349 2445
 			),
2350 2446
 		);
2351
-		if ($type !== true)
2352
-			$additional_data['type'] = $type;
2447
+		if ($type !== true) {
2448
+					$additional_data['type'] = $type;
2449
+		}
2353 2450
 
2354 2451
 		// If there's an offset ignore any folders in XML mode.
2355 2452
 		if (isset($_GET['xml']) && $context['file_offset'] == 0)
@@ -2368,13 +2465,13 @@  discard block
 block discarded – undo
2368 2465
 				),
2369 2466
 				'value' => $folder,
2370 2467
 			);
2371
-		}
2372
-		elseif (!isset($_GET['xml']))
2468
+		} elseif (!isset($_GET['xml']))
2373 2469
 		{
2374
-			if (isset($data['contents'][$folder]))
2375
-				$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2376
-			else
2377
-				$data['contents'][$folder] = $additional_data;
2470
+			if (isset($data['contents'][$folder])) {
2471
+							$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2472
+			} else {
2473
+							$data['contents'][$folder] = $additional_data;
2474
+			}
2378 2475
 		}
2379 2476
 	}
2380 2477
 
@@ -2386,11 +2483,13 @@  discard block
 block discarded – undo
2386 2483
 		$counter++;
2387 2484
 
2388 2485
 		// Have we reached our offset?
2389
-		if ($context['file_offset'] > $counter)
2390
-			continue;
2486
+		if ($context['file_offset'] > $counter) {
2487
+					continue;
2488
+		}
2391 2489
 		// Gone too far?
2392
-		if ($counter > ($context['file_offset'] + $context['file_limit']))
2393
-			continue;
2490
+		if ($counter > ($context['file_offset'] + $context['file_limit'])) {
2491
+					continue;
2492
+		}
2394 2493
 
2395 2494
 		$additional_data = array(
2396 2495
 			'perms' => array(
@@ -2416,13 +2515,13 @@  discard block
 block discarded – undo
2416 2515
 				),
2417 2516
 				'value' => $file,
2418 2517
 			);
2419
-		}
2420
-		elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2518
+		} elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2421 2519
 		{
2422
-			if (isset($data['contents'][$file]))
2423
-				$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2424
-			else
2425
-				$data['contents'][$file] = $additional_data;
2520
+			if (isset($data['contents'][$file])) {
2521
+							$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2522
+			} else {
2523
+							$data['contents'][$file] = $additional_data;
2524
+			}
2426 2525
 		}
2427 2526
 	}
2428 2527
 }
@@ -2444,8 +2543,9 @@  discard block
 block discarded – undo
2444 2543
 	$context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array();
2445 2544
 
2446 2545
 	// Skipping use of FTP?
2447
-	if (empty($package_ftp))
2448
-		$context['skip_ftp'] = true;
2546
+	if (empty($package_ftp)) {
2547
+			$context['skip_ftp'] = true;
2548
+	}
2449 2549
 
2450 2550
 	// We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place.
2451 2551
 	if ($context['method'] == 'individual')
@@ -2455,8 +2555,9 @@  discard block
 block discarded – undo
2455 2555
 		$context['custom_value'] = (int) $_POST['custom_value'];
2456 2556
 
2457 2557
 		// Continuing?
2458
-		if (isset($_POST['toProcess']))
2459
-			$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2558
+		if (isset($_POST['toProcess'])) {
2559
+					$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2560
+		}
2460 2561
 
2461 2562
 		if (isset($_POST['permStatus']))
2462 2563
 		{
@@ -2465,22 +2566,27 @@  discard block
 block discarded – undo
2465 2566
 			foreach ($_POST['permStatus'] as $path => $status)
2466 2567
 			{
2467 2568
 				// Nothing to see here?
2468
-				if ($status == 'no_change')
2469
-					continue;
2569
+				if ($status == 'no_change') {
2570
+									continue;
2571
+				}
2470 2572
 				$legal = false;
2471
-				foreach ($legal_roots as $root)
2472
-					if (substr($path, 0, strlen($root)) == $root)
2573
+				foreach ($legal_roots as $root) {
2574
+									if (substr($path, 0, strlen($root)) == $root)
2473 2575
 						$legal = true;
2576
+				}
2474 2577
 
2475
-				if (!$legal)
2476
-					continue;
2578
+				if (!$legal) {
2579
+									continue;
2580
+				}
2477 2581
 
2478 2582
 				// Check it exists.
2479
-				if (!file_exists($path))
2480
-					continue;
2583
+				if (!file_exists($path)) {
2584
+									continue;
2585
+				}
2481 2586
 
2482
-				if ($status == 'custom')
2483
-					$validate_custom = true;
2587
+				if ($status == 'custom') {
2588
+									$validate_custom = true;
2589
+				}
2484 2590
 
2485 2591
 				// Now add it.
2486 2592
 				$context['to_process'][$path] = $status;
@@ -2490,17 +2596,20 @@  discard block
 block discarded – undo
2490 2596
 			// Make sure the chmod status is valid?
2491 2597
 			if ($validate_custom)
2492 2598
 			{
2493
-				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false)
2494
-					fatal_error($txt['chmod_value_invalid']);
2599
+				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) {
2600
+									fatal_error($txt['chmod_value_invalid']);
2601
+				}
2495 2602
 			}
2496 2603
 
2497 2604
 			// Nothing to do?
2498
-			if (empty($context['to_process']))
2499
-				redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2605
+			if (empty($context['to_process'])) {
2606
+							redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2607
+			}
2500 2608
 		}
2501 2609
 		// Should never get here,
2502
-		else
2503
-			fatal_lang_error('no_access', false);
2610
+		else {
2611
+					fatal_lang_error('no_access', false);
2612
+		}
2504 2613
 
2505 2614
 		// Setup the custom value.
2506 2615
 		$custom_value = octdec('0' . $context['custom_value']);
@@ -2508,26 +2617,27 @@  discard block
 block discarded – undo
2508 2617
 		// Start processing items.
2509 2618
 		foreach ($context['to_process'] as $path => $status)
2510 2619
 		{
2511
-			if (in_array($status, array('execute', 'writable', 'read')))
2512
-				package_chmod($path, $status);
2513
-			elseif ($status == 'custom' && !empty($custom_value))
2620
+			if (in_array($status, array('execute', 'writable', 'read'))) {
2621
+							package_chmod($path, $status);
2622
+			} elseif ($status == 'custom' && !empty($custom_value))
2514 2623
 			{
2515 2624
 				// Use FTP if we have it.
2516 2625
 				if (!empty($package_ftp) && !empty($_SESSION['pack_ftp']))
2517 2626
 				{
2518 2627
 					$ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => ''));
2519 2628
 					$package_ftp->chmod($ftp_file, $custom_value);
2629
+				} else {
2630
+									smf_chmod($path, $custom_value);
2520 2631
 				}
2521
-				else
2522
-					smf_chmod($path, $custom_value);
2523 2632
 			}
2524 2633
 
2525 2634
 			// This fish is fried...
2526 2635
 			unset($context['to_process'][$path]);
2527 2636
 
2528 2637
 			// See if we're out of time?
2529
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2530
-				return false;
2638
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2639
+							return false;
2640
+			}
2531 2641
 		}
2532 2642
 	}
2533 2643
 	// If predefined this is a little different.
@@ -2595,23 +2705,27 @@  discard block
 block discarded – undo
2595 2705
 			{
2596 2706
 				global $context;
2597 2707
 
2598
-				if (!empty($data['writable_on']))
2599
-					if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2708
+				if (!empty($data['writable_on'])) {
2709
+									if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2600 2710
 						$context['special_files'][$path] = 1;
2711
+				}
2601 2712
 
2602
-				if (!empty($data['contents']))
2603
-					foreach ($data['contents'] as $name => $contents)
2713
+				if (!empty($data['contents'])) {
2714
+									foreach ($data['contents'] as $name => $contents)
2604 2715
 						build_special_files__recursive($path . '/' . $name, $contents);
2716
+				}
2605 2717
 			}
2606 2718
 
2607
-			foreach ($context['file_tree'] as $path => $data)
2608
-				build_special_files__recursive($path, $data);
2719
+			foreach ($context['file_tree'] as $path => $data) {
2720
+							build_special_files__recursive($path, $data);
2721
+			}
2609 2722
 		}
2610 2723
 		// Free doesn't need special files.
2611
-		elseif ($context['predefined_type'] == 'free')
2612
-			$context['special_files'] = array();
2613
-		else
2614
-			$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2724
+		elseif ($context['predefined_type'] == 'free') {
2725
+					$context['special_files'] = array();
2726
+		} else {
2727
+					$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2728
+		}
2615 2729
 
2616 2730
 		// Now we definitely know where we are, we need to go through again doing the chmod!
2617 2731
 		foreach ($context['directory_list'] as $path => $dummy)
@@ -2656,8 +2770,9 @@  discard block
 block discarded – undo
2656 2770
 			unset($context['directory_list'][$path]);
2657 2771
 
2658 2772
 			// See if we're out of time?
2659
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2660
-				return false;
2773
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2774
+							return false;
2775
+			}
2661 2776
 		}
2662 2777
 	}
2663 2778
 
Please login to merge, or discard this patch.
Sources/Search.php 1 patch
Braces   +414 added lines, -307 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
 // This defines two version types for checking the API's are compatible with this version of SMF.
20 21
 $GLOBALS['search_versions'] = array(
@@ -39,8 +40,9 @@  discard block
 block discarded – undo
39 40
 	global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir;
40 41
 
41 42
 	// Is the load average too high to allow searching just now?
42
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
43
-		fatal_lang_error('loadavg_search_disabled', false);
43
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
44
+			fatal_lang_error('loadavg_search_disabled', false);
45
+	}
44 46
 
45 47
 	loadLanguage('Search');
46 48
 	// Don't load this in XML mode.
@@ -88,23 +90,30 @@  discard block
 block discarded – undo
88 90
 			@list ($k, $v) = explode('|\'|', $data);
89 91
 			$context['search_params'][$k] = $v;
90 92
 		}
91
-		if (isset($context['search_params']['brd']))
92
-			$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
93
+		if (isset($context['search_params']['brd'])) {
94
+					$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
95
+		}
93 96
 	}
94 97
 
95
-	if (isset($_REQUEST['search']))
96
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
98
+	if (isset($_REQUEST['search'])) {
99
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
100
+	}
97 101
 
98
-	if (isset($context['search_params']['search']))
99
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
100
-	if (isset($context['search_params']['userspec']))
101
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
102
-	if (!empty($context['search_params']['searchtype']))
103
-		$context['search_params']['searchtype'] = 2;
104
-	if (!empty($context['search_params']['minage']))
105
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
106
-	if (!empty($context['search_params']['maxage']))
107
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
102
+	if (isset($context['search_params']['search'])) {
103
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
104
+	}
105
+	if (isset($context['search_params']['userspec'])) {
106
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
107
+	}
108
+	if (!empty($context['search_params']['searchtype'])) {
109
+			$context['search_params']['searchtype'] = 2;
110
+	}
111
+	if (!empty($context['search_params']['minage'])) {
112
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
113
+	}
114
+	if (!empty($context['search_params']['maxage'])) {
115
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
116
+	}
108 117
 
109 118
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
110 119
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
@@ -116,11 +125,13 @@  discard block
 block discarded – undo
116 125
 		$context['search_errors']['messages'] = array();
117 126
 		foreach ($context['search_errors'] as $search_error => $dummy)
118 127
 		{
119
-			if ($search_error === 'messages')
120
-				continue;
128
+			if ($search_error === 'messages') {
129
+							continue;
130
+			}
121 131
 
122
-			if ($search_error == 'string_too_long')
123
-				$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
132
+			if ($search_error == 'string_too_long') {
133
+							$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
134
+			}
124 135
 
125 136
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
126 137
 		}
@@ -143,12 +154,13 @@  discard block
 block discarded – undo
143 154
 	while ($row = $smcFunc['db_fetch_assoc']($request))
144 155
 	{
145 156
 		// This category hasn't been set up yet..
146
-		if (!isset($context['categories'][$row['id_cat']]))
147
-			$context['categories'][$row['id_cat']] = array(
157
+		if (!isset($context['categories'][$row['id_cat']])) {
158
+					$context['categories'][$row['id_cat']] = array(
148 159
 				'id' => $row['id_cat'],
149 160
 				'name' => $row['cat_name'],
150 161
 				'boards' => array()
151 162
 			);
163
+		}
152 164
 
153 165
 		// Set this board up, and let the template know when it's a child.  (indent them..)
154 166
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -159,8 +171,9 @@  discard block
 block discarded – undo
159 171
 		);
160 172
 
161 173
 		// If a board wasn't checked that probably should have been ensure the board selection is selected, yo!
162
-		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board']))
163
-			$context['boards_check_all'] = false;
174
+		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) {
175
+					$context['boards_check_all'] = false;
176
+		}
164 177
 	}
165 178
 	$smcFunc['db_free_result']($request);
166 179
 
@@ -182,18 +195,20 @@  discard block
 block discarded – undo
182 195
 	}
183 196
 
184 197
 	$max_boards = ceil(count($temp_boards) / 2);
185
-	if ($max_boards == 1)
186
-		$max_boards = 2;
198
+	if ($max_boards == 1) {
199
+			$max_boards = 2;
200
+	}
187 201
 
188 202
 	// Now, alternate them so they can be shown left and right ;).
189 203
 	$context['board_columns'] = array();
190 204
 	for ($i = 0; $i < $max_boards; $i++)
191 205
 	{
192 206
 		$context['board_columns'][] = $temp_boards[$i];
193
-		if (isset($temp_boards[$i + $max_boards]))
194
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
195
-		else
196
-			$context['board_columns'][] = array();
207
+		if (isset($temp_boards[$i + $max_boards])) {
208
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
209
+		} else {
210
+					$context['board_columns'][] = array();
211
+		}
197 212
 	}
198 213
 
199 214
 	if (!empty($_REQUEST['topic']))
@@ -225,8 +240,9 @@  discard block
 block discarded – undo
225 240
 			)
226 241
 		);
227 242
 
228
-		if ($smcFunc['db_num_rows']($request) == 0)
229
-			fatal_lang_error('topic_gone', false);
243
+		if ($smcFunc['db_num_rows']($request) == 0) {
244
+					fatal_lang_error('topic_gone', false);
245
+		}
230 246
 
231 247
 		list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request);
232 248
 		$smcFunc['db_free_result']($request);
@@ -256,11 +272,13 @@  discard block
 block discarded – undo
256 272
 	global $excludedWords, $participants, $smcFunc;
257 273
 
258 274
 	// if comming from the quick search box, and we want to search on members, well we need to do that ;)
259
-	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members')
260
-		redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
275
+	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') {
276
+			redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
277
+	}
261 278
 
262
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
263
-		fatal_lang_error('loadavg_search_disabled', false);
279
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
280
+			fatal_lang_error('loadavg_search_disabled', false);
281
+	}
264 282
 
265 283
 	// No, no, no... this is a bit hard on the server, so don't you go prefetching it!
266 284
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -307,8 +325,9 @@  discard block
 block discarded – undo
307 325
 	}
308 326
 
309 327
 	// Zero weight.  Weightless :P.
310
-	if (empty($weight_total))
311
-		fatal_lang_error('search_invalid_weights');
328
+	if (empty($weight_total)) {
329
+			fatal_lang_error('search_invalid_weights');
330
+	}
312 331
 
313 332
 	// These vars don't require an interface, they're just here for tweaking.
314 333
 	$recentPercentage = 0.30;
@@ -326,11 +345,13 @@  discard block
 block discarded – undo
326 345
 	$context['search_string_limit'] = 100;
327 346
 
328 347
 	loadLanguage('Search');
329
-	if (!isset($_REQUEST['xml']))
330
-		loadTemplate('Search');
348
+	if (!isset($_REQUEST['xml'])) {
349
+			loadTemplate('Search');
350
+	}
331 351
 	//If we're doing XML we need to use the results template regardless really.
332
-	else
333
-		$context['sub_template'] = 'results';
352
+	else {
353
+			$context['sub_template'] = 'results';
354
+	}
334 355
 
335 356
 	// Are you allowed?
336 357
 	isAllowedTo('search_posts');
@@ -363,34 +384,39 @@  discard block
 block discarded – undo
363 384
 			$search_params[$k] = $v;
364 385
 		}
365 386
 
366
-		if (isset($search_params['brd']))
367
-			$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
387
+		if (isset($search_params['brd'])) {
388
+					$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
389
+		}
368 390
 	}
369 391
 
370 392
 	// Store whether simple search was used (needed if the user wants to do another query).
371
-	if (!isset($search_params['advanced']))
372
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
393
+	if (!isset($search_params['advanced'])) {
394
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
395
+	}
373 396
 
374 397
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
375
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
376
-		$search_params['searchtype'] = 2;
398
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
399
+			$search_params['searchtype'] = 2;
400
+	}
377 401
 
378 402
 	// Minimum age of messages. Default to zero (don't set param in that case).
379
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
380
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
403
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
404
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
405
+	}
381 406
 
382 407
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
383
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999))
384
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
408
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) {
409
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
410
+	}
385 411
 
386 412
 	// Searching a specific topic?
387 413
 	if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic'))
388 414
 	{
389 415
 		$search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : '');
390 416
 		$search_params['show_complete'] = true;
417
+	} elseif (!empty($search_params['topic'])) {
418
+			$search_params['topic'] = (int) $search_params['topic'];
391 419
 	}
392
-	elseif (!empty($search_params['topic']))
393
-		$search_params['topic'] = (int) $search_params['topic'];
394 420
 
395 421
 	if (!empty($search_params['minage']) || !empty($search_params['maxage']))
396 422
 	{
@@ -408,19 +434,21 @@  discard block
 block discarded – undo
408 434
 			)
409 435
 		);
410 436
 		list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request);
411
-		if ($minMsgID < 0 || $maxMsgID < 0)
412
-			$context['search_errors']['no_messages_in_time_frame'] = true;
437
+		if ($minMsgID < 0 || $maxMsgID < 0) {
438
+					$context['search_errors']['no_messages_in_time_frame'] = true;
439
+		}
413 440
 		$smcFunc['db_free_result']($request);
414 441
 	}
415 442
 
416 443
 	// Default the user name to a wildcard matching every user (*).
417
-	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
418
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
444
+	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
445
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
446
+	}
419 447
 
420 448
 	// If there's no specific user, then don't mention it in the main query.
421
-	if (empty($search_params['userspec']))
422
-		$userQuery = '';
423
-	else
449
+	if (empty($search_params['userspec'])) {
450
+			$userQuery = '';
451
+	} else
424 452
 	{
425 453
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
426 454
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -432,19 +460,21 @@  discard block
 block discarded – undo
432 460
 		{
433 461
 			$possible_users[$k] = trim($possible_users[$k]);
434 462
 
435
-			if (strlen($possible_users[$k]) == 0)
436
-				unset($possible_users[$k]);
463
+			if (strlen($possible_users[$k]) == 0) {
464
+							unset($possible_users[$k]);
465
+			}
437 466
 		}
438 467
 
439 468
 		// Create a list of database-escaped search names.
440 469
 		$realNameMatches = array();
441
-		foreach ($possible_users as $possible_user)
442
-			$realNameMatches[] = $smcFunc['db_quote'](
470
+		foreach ($possible_users as $possible_user) {
471
+					$realNameMatches[] = $smcFunc['db_quote'](
443 472
 				'{string:possible_user}',
444 473
 				array(
445 474
 					'possible_user' => $possible_user
446 475
 				)
447 476
 			);
477
+		}
448 478
 
449 479
 		// Retrieve a list of possible members.
450 480
 		$request = $smcFunc['db_query']('', '
@@ -456,9 +486,9 @@  discard block
 block discarded – undo
456 486
 			)
457 487
 		);
458 488
 		// Simply do nothing if there're too many members matching the criteria.
459
-		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
460
-			$userQuery = '';
461
-		elseif ($smcFunc['db_num_rows']($request) == 0)
489
+		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
490
+					$userQuery = '';
491
+		} elseif ($smcFunc['db_num_rows']($request) == 0)
462 492
 		{
463 493
 			$userQuery = $smcFunc['db_quote'](
464 494
 				'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})',
@@ -467,12 +497,12 @@  discard block
 block discarded – undo
467 497
 					'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches),
468 498
 				)
469 499
 			);
470
-		}
471
-		else
500
+		} else
472 501
 		{
473 502
 			$memberlist = array();
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$memberlist[] = $row['id_member'];
503
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
504
+							$memberlist[] = $row['id_member'];
505
+			}
476 506
 			$userQuery = $smcFunc['db_quote'](
477 507
 				'(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))',
478 508
 				array(
@@ -486,22 +516,25 @@  discard block
 block discarded – undo
486 516
 	}
487 517
 
488 518
 	// If the boards were passed by URL (params=), temporarily put them back in $_REQUEST.
489
-	if (!empty($search_params['brd']) && is_array($search_params['brd']))
490
-		$_REQUEST['brd'] = $search_params['brd'];
519
+	if (!empty($search_params['brd']) && is_array($search_params['brd'])) {
520
+			$_REQUEST['brd'] = $search_params['brd'];
521
+	}
491 522
 
492 523
 	// Ensure that brd is an array.
493 524
 	if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board'))
494 525
 	{
495
-		if (!empty($_REQUEST['brd']))
496
-			$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
497
-		else
498
-			$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
526
+		if (!empty($_REQUEST['brd'])) {
527
+					$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
528
+		} else {
529
+					$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
530
+		}
499 531
 	}
500 532
 
501 533
 	// Make sure all boards are integers.
502
-	if (!empty($_REQUEST['brd']))
503
-		foreach ($_REQUEST['brd'] as $id => $brd)
534
+	if (!empty($_REQUEST['brd'])) {
535
+			foreach ($_REQUEST['brd'] as $id => $brd)
504 536
 			$_REQUEST['brd'][$id] = (int) $brd;
537
+	}
505 538
 
506 539
 	// Special case for boards: searching just one topic?
507 540
 	if (!empty($search_params['topic']))
@@ -520,17 +553,18 @@  discard block
 block discarded – undo
520 553
 			)
521 554
 		);
522 555
 
523
-		if ($smcFunc['db_num_rows']($request) == 0)
524
-			fatal_lang_error('topic_gone', false);
556
+		if ($smcFunc['db_num_rows']($request) == 0) {
557
+					fatal_lang_error('topic_gone', false);
558
+		}
525 559
 
526 560
 		$search_params['brd'] = array();
527 561
 		list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request);
528 562
 		$smcFunc['db_free_result']($request);
529 563
 	}
530 564
 	// Select all boards you've selected AND are allowed to see.
531
-	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
532
-		$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
533
-	else
565
+	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) {
566
+			$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
567
+	} else
534 568
 	{
535 569
 		$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
536 570
 		$request = $smcFunc['db_query']('', '
@@ -548,19 +582,22 @@  discard block
 block discarded – undo
548 582
 			)
549 583
 		);
550 584
 		$search_params['brd'] = array();
551
-		while ($row = $smcFunc['db_fetch_assoc']($request))
552
-			$search_params['brd'][] = $row['id_board'];
585
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
586
+					$search_params['brd'][] = $row['id_board'];
587
+		}
553 588
 		$smcFunc['db_free_result']($request);
554 589
 
555 590
 		// This error should pro'bly only happen for hackers.
556
-		if (empty($search_params['brd']))
557
-			$context['search_errors']['no_boards_selected'] = true;
591
+		if (empty($search_params['brd'])) {
592
+					$context['search_errors']['no_boards_selected'] = true;
593
+		}
558 594
 	}
559 595
 
560 596
 	if (count($search_params['brd']) != 0)
561 597
 	{
562
-		foreach ($search_params['brd'] as $k => $v)
563
-			$search_params['brd'][$k] = (int) $v;
598
+		foreach ($search_params['brd'] as $k => $v) {
599
+					$search_params['brd'][$k] = (int) $v;
600
+		}
564 601
 
565 602
 		// If we've selected all boards, this parameter can be left empty.
566 603
 		$request = $smcFunc['db_query']('', '
@@ -574,15 +611,16 @@  discard block
 block discarded – undo
574 611
 		list ($num_boards) = $smcFunc['db_fetch_row']($request);
575 612
 		$smcFunc['db_free_result']($request);
576 613
 
577
-		if (count($search_params['brd']) == $num_boards)
614
+		if (count($search_params['brd']) == $num_boards) {
615
+					$boardQuery = '';
616
+		} elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) {
617
+					$boardQuery = '!= ' . $modSettings['recycle_board'];
618
+		} else {
619
+					$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
620
+		}
621
+	} else {
578 622
 			$boardQuery = '';
579
-		elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd']))
580
-			$boardQuery = '!= ' . $modSettings['recycle_board'];
581
-		else
582
-			$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
583 623
 	}
584
-	else
585
-		$boardQuery = '';
586 624
 
587 625
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
588 626
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
@@ -596,11 +634,13 @@  discard block
 block discarded – undo
596 634
 		'id_msg',
597 635
 	);
598 636
 	call_integration_hook('integrate_search_sort_columns', array(&$sort_columns));
599
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
600
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
637
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
638
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
639
+	}
601 640
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance';
602
-	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies')
603
-		$search_params['sort'] = 'id_msg';
641
+	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') {
642
+			$search_params['sort'] = 'id_msg';
643
+	}
604 644
 
605 645
 	// Sorting direction: descending unless stated otherwise.
606 646
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
@@ -624,17 +664,19 @@  discard block
 block discarded – undo
624 664
 	// What are we searching for?
625 665
 	if (empty($search_params['search']))
626 666
 	{
627
-		if (isset($_GET['search']))
628
-			$search_params['search'] = un_htmlspecialchars($_GET['search']);
629
-		elseif (isset($_POST['search']))
630
-			$search_params['search'] = $_POST['search'];
631
-		else
632
-			$search_params['search'] = '';
667
+		if (isset($_GET['search'])) {
668
+					$search_params['search'] = un_htmlspecialchars($_GET['search']);
669
+		} elseif (isset($_POST['search'])) {
670
+					$search_params['search'] = $_POST['search'];
671
+		} else {
672
+					$search_params['search'] = '';
673
+		}
633 674
 	}
634 675
 
635 676
 	// Nothing??
636
-	if (!isset($search_params['search']) || $search_params['search'] == '')
637
-		$context['search_errors']['invalid_search_string'] = true;
677
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
678
+			$context['search_errors']['invalid_search_string'] = true;
679
+	}
638 680
 	// Too long?
639 681
 	elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit'])
640 682
 	{
@@ -648,8 +690,9 @@  discard block
 block discarded – undo
648 690
 	$stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query));
649 691
 
650 692
 	// This (hidden) setting will do fulltext searching in the most basic way.
651
-	if (!empty($modSettings['search_simple_fulltext']))
652
-		$stripped_query = strtr($stripped_query, array('"' => ''));
693
+	if (!empty($modSettings['search_simple_fulltext'])) {
694
+			$stripped_query = strtr($stripped_query, array('"' => ''));
695
+	}
653 696
 
654 697
 	$no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1;
655 698
 
@@ -672,8 +715,9 @@  discard block
 block discarded – undo
672 715
 	{
673 716
 		if ($word === '-')
674 717
 		{
675
-			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
676
-				$excludedWords[] = $word;
718
+			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
719
+							$excludedWords[] = $word;
720
+			}
677 721
 			unset($phraseArray[$index]);
678 722
 		}
679 723
 	}
@@ -683,8 +727,9 @@  discard block
 block discarded – undo
683 727
 	{
684 728
 		if (strpos(trim($word), '-') === 0)
685 729
 		{
686
-			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
687
-				$excludedWords[] = $word;
730
+			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
731
+							$excludedWords[] = $word;
732
+			}
688 733
 			unset($wordArray[$index]);
689 734
 		}
690 735
 	}
@@ -697,8 +742,9 @@  discard block
 block discarded – undo
697 742
 	foreach ($searchArray as $index => $value)
698 743
 	{
699 744
 		// Skip anything practically empty.
700
-		if (($searchArray[$index] = trim($value, '-_\' ')) === '')
701
-			unset($searchArray[$index]);
745
+		if (($searchArray[$index] = trim($value, '-_\' ')) === '') {
746
+					unset($searchArray[$index]);
747
+		}
702 748
 		// Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing.
703 749
 		elseif (in_array($searchArray[$index], $blacklisted_words))
704 750
 		{
@@ -716,31 +762,37 @@  discard block
 block discarded – undo
716 762
 
717 763
 	// Create an array of replacements for highlighting.
718 764
 	$context['mark'] = array();
719
-	foreach ($searchArray as $word)
720
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
765
+	foreach ($searchArray as $word) {
766
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
767
+	}
721 768
 
722 769
 	// Initialize two arrays storing the words that have to be searched for.
723 770
 	$orParts = array();
724 771
 	$searchWords = array();
725 772
 
726 773
 	// Make sure at least one word is being searched for.
727
-	if (empty($searchArray))
728
-		$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
774
+	if (empty($searchArray)) {
775
+			$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
776
+	}
729 777
 	// All words/sentences must match.
730
-	elseif (empty($search_params['searchtype']))
731
-		$orParts[0] = $searchArray;
778
+	elseif (empty($search_params['searchtype'])) {
779
+			$orParts[0] = $searchArray;
780
+	}
732 781
 	// Any word/sentence must match.
733
-	else
734
-		foreach ($searchArray as $index => $value)
782
+	else {
783
+			foreach ($searchArray as $index => $value)
735 784
 			$orParts[$index] = array($value);
785
+	}
736 786
 
737 787
 	// Don't allow duplicate error messages if one string is too short.
738
-	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string']))
739
-		unset($context['search_errors']['invalid_search_string']);
788
+	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) {
789
+			unset($context['search_errors']['invalid_search_string']);
790
+	}
740 791
 	// Make sure the excluded words are in all or-branches.
741
-	foreach ($orParts as $orIndex => $andParts)
742
-		foreach ($excludedWords as $word)
792
+	foreach ($orParts as $orIndex => $andParts) {
793
+			foreach ($excludedWords as $word)
743 794
 			$orParts[$orIndex][] = $word;
795
+	}
744 796
 
745 797
 	// Determine the or-branches and the fulltext search words.
746 798
 	foreach ($orParts as $orIndex => $andParts)
@@ -754,8 +806,9 @@  discard block
 block discarded – undo
754 806
 		);
755 807
 
756 808
 		// Sort the indexed words (large words -> small words -> excluded words).
757
-		if ($searchAPI->supportsMethod('searchSort'))
758
-			usort($orParts[$orIndex], 'searchSort');
809
+		if ($searchAPI->supportsMethod('searchSort')) {
810
+					usort($orParts[$orIndex], 'searchSort');
811
+		}
759 812
 
760 813
 		foreach ($orParts[$orIndex] as $word)
761 814
 		{
@@ -767,15 +820,17 @@  discard block
 block discarded – undo
767 820
 			if (!$is_excluded || count($subjectWords) === 1)
768 821
 			{
769 822
 				$searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords);
770
-				if ($is_excluded)
771
-					$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
823
+				if ($is_excluded) {
824
+									$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
825
+				}
826
+			} else {
827
+							$excludedPhrases[] = $word;
772 828
 			}
773
-			else
774
-				$excludedPhrases[] = $word;
775 829
 
776 830
 			// Have we got indexes to prepare?
777
-			if ($searchAPI->supportsMethod('prepareIndexes'))
778
-				$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
831
+			if ($searchAPI->supportsMethod('prepareIndexes')) {
832
+							$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
833
+			}
779 834
 		}
780 835
 
781 836
 		// Search_force_index requires all AND parts to have at least one fulltext word.
@@ -783,8 +838,7 @@  discard block
 block discarded – undo
783 838
 		{
784 839
 			$context['search_errors']['query_not_specific_enough'] = true;
785 840
 			break;
786
-		}
787
-		elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
841
+		} elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
788 842
 		{
789 843
 			$context['search_errors']['query_not_specific_enough'] = true;
790 844
 			break;
@@ -812,8 +866,9 @@  discard block
 block discarded – undo
812 866
 		$found_misspelling = false;
813 867
 		foreach ($searchArray as $word)
814 868
 		{
815
-			if (empty($link))
816
-				continue;
869
+			if (empty($link)) {
870
+							continue;
871
+			}
817 872
 
818 873
 			// Don't check phrases.
819 874
 			if (preg_match('~^\w+$~', $word) === 0)
@@ -828,8 +883,7 @@  discard block
 block discarded – undo
828 883
 				$did_you_mean['search'][] = $word;
829 884
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
830 885
 				continue;
831
-			}
832
-			elseif (spell_check($link, $word))
886
+			} elseif (spell_check($link, $word))
833 887
 			{
834 888
 				$did_you_mean['search'][] = $word;
835 889
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -840,11 +894,13 @@  discard block
 block discarded – undo
840 894
 			foreach ($suggestions as $i => $s)
841 895
 			{
842 896
 				// Search is case insensitive.
843
-				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word))
844
-					unset($suggestions[$i]);
897
+				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) {
898
+									unset($suggestions[$i]);
899
+				}
845 900
 				// Plus, don't suggest something the user thinks is rude!
846
-				elseif ($suggestions[$i] != censorText($s))
847
-					unset($suggestions[$i]);
901
+				elseif ($suggestions[$i] != censorText($s)) {
902
+									unset($suggestions[$i]);
903
+				}
848 904
 			}
849 905
 
850 906
 			// Anything found?  If so, correct it!
@@ -854,8 +910,7 @@  discard block
 block discarded – undo
854 910
 				$did_you_mean['search'][] = $suggestions[0];
855 911
 				$did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>';
856 912
 				$found_misspelling = true;
857
-			}
858
-			else
913
+			} else
859 914
 			{
860 915
 				$did_you_mean['search'][] = $word;
861 916
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -872,8 +927,7 @@  discard block
 block discarded – undo
872 927
 				{
873 928
 					$temp_excluded['search'][] = '-"' . $word . '"';
874 929
 					$temp_excluded['display'][] = '-&quot;' . $smcFunc['htmlspecialchars']($word) . '&quot;';
875
-				}
876
-				else
930
+				} else
877 931
 				{
878 932
 					$temp_excluded['search'][] = '-' . $word;
879 933
 					$temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word);
@@ -885,11 +939,13 @@  discard block
 block discarded – undo
885 939
 
886 940
 			$temp_params = $search_params;
887 941
 			$temp_params['search'] = implode(' ', $did_you_mean['search']);
888
-			if (isset($temp_params['brd']))
889
-				$temp_params['brd'] = implode(',', $temp_params['brd']);
942
+			if (isset($temp_params['brd'])) {
943
+							$temp_params['brd'] = implode(',', $temp_params['brd']);
944
+			}
890 945
 			$context['params'] = array();
891
-			foreach ($temp_params as $k => $v)
892
-				$context['did_you_mean_params'][] = $k . '|\'|' . $v;
946
+			foreach ($temp_params as $k => $v) {
947
+							$context['did_you_mean_params'][] = $k . '|\'|' . $v;
948
+			}
893 949
 			$context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params']));
894 950
 			$context['did_you_mean'] = implode(' ', $did_you_mean['display']);
895 951
 		}
@@ -897,18 +953,20 @@  discard block
 block discarded – undo
897 953
 
898 954
 	// Let the user adjust the search query, should they wish?
899 955
 	$context['search_params'] = $search_params;
900
-	if (isset($context['search_params']['search']))
901
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
902
-	if (isset($context['search_params']['userspec']))
903
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
956
+	if (isset($context['search_params']['search'])) {
957
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
958
+	}
959
+	if (isset($context['search_params']['userspec'])) {
960
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
961
+	}
904 962
 
905 963
 	// Do we have captcha enabled?
906 964
 	if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']))
907 965
 	{
908 966
 		// If we come from another search box tone down the error...
909
-		if (!isset($_REQUEST['search_vv']))
910
-			$context['search_errors']['need_verification_code'] = true;
911
-		else
967
+		if (!isset($_REQUEST['search_vv'])) {
968
+					$context['search_errors']['need_verification_code'] = true;
969
+		} else
912 970
 		{
913 971
 			require_once($sourcedir . '/Subs-Editor.php');
914 972
 			$verificationOptions = array(
@@ -918,12 +976,14 @@  discard block
 block discarded – undo
918 976
 
919 977
 			if (is_array($context['require_verification']))
920 978
 			{
921
-				foreach ($context['require_verification'] as $error)
922
-					$context['search_errors'][$error] = true;
979
+				foreach ($context['require_verification'] as $error) {
980
+									$context['search_errors'][$error] = true;
981
+				}
923 982
 			}
924 983
 			// Don't keep asking for it - they've proven themselves worthy.
925
-			else
926
-				$_SESSION['ss_vv_passed'] = true;
984
+			else {
985
+							$_SESSION['ss_vv_passed'] = true;
986
+			}
927 987
 		}
928 988
 	}
929 989
 
@@ -931,19 +991,22 @@  discard block
 block discarded – undo
931 991
 
932 992
 	// All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below.
933 993
 	$temp_params = $search_params;
934
-	if (isset($temp_params['brd']))
935
-		$temp_params['brd'] = implode(',', $temp_params['brd']);
994
+	if (isset($temp_params['brd'])) {
995
+			$temp_params['brd'] = implode(',', $temp_params['brd']);
996
+	}
936 997
 	$context['params'] = array();
937
-	foreach ($temp_params as $k => $v)
938
-		$context['params'][] = $k . '|\'|' . $v;
998
+	foreach ($temp_params as $k => $v) {
999
+			$context['params'][] = $k . '|\'|' . $v;
1000
+	}
939 1001
 
940 1002
 	if (!empty($context['params']))
941 1003
 	{
942 1004
 		// Due to old IE's 2083 character limit, we have to compress long search strings
943 1005
 		$params = @gzcompress(implode('|"|', $context['params']));
944 1006
 		// Gzcompress failed, use try non-gz
945
-		if (empty($params))
946
-			$params = implode('|"|', $context['params']);
1007
+		if (empty($params)) {
1008
+					$params = implode('|"|', $context['params']);
1009
+		}
947 1010
 		// Base64 encode, then replace +/= with uri safe ones that can be reverted
948 1011
 		$context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params));
949 1012
 	}
@@ -969,8 +1032,9 @@  discard block
 block discarded – undo
969 1032
 	}
970 1033
 
971 1034
 	// Spam me not, Spam-a-lot?
972
-	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])
973
-		spamProtection('search');
1035
+	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) {
1036
+			spamProtection('search');
1037
+	}
974 1038
 	// Store the last search string to allow pages of results to be browsed.
975 1039
 	$_SESSION['last_ss'] = $search_params['search'];
976 1040
 
@@ -1030,8 +1094,9 @@  discard block
 block discarded – undo
1030 1094
 						'where' => array(),
1031 1095
 					);
1032 1096
 
1033
-					if ($modSettings['postmod_active'])
1034
-						$subject_query['where'][] = 't.approved = {int:is_approved}';
1097
+					if ($modSettings['postmod_active']) {
1098
+											$subject_query['where'][] = 't.approved = {int:is_approved}';
1099
+					}
1035 1100
 
1036 1101
 					$numTables = 0;
1037 1102
 					$prev_join = 0;
@@ -1043,8 +1108,7 @@  discard block
 block discarded – undo
1043 1108
 						{
1044 1109
 							$subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)';
1045 1110
 							$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1046
-						}
1047
-						else
1111
+						} else
1048 1112
 						{
1049 1113
 							$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1050 1114
 							$subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}');
@@ -1062,14 +1126,18 @@  discard block
 block discarded – undo
1062 1126
 						}
1063 1127
 						$subject_query['where'][] = $userQuery;
1064 1128
 					}
1065
-					if (!empty($search_params['topic']))
1066
-						$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1067
-					if (!empty($minMsgID))
1068
-						$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1069
-					if (!empty($maxMsgID))
1070
-						$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1071
-					if (!empty($boardQuery))
1072
-						$subject_query['where'][] = 't.id_board ' . $boardQuery;
1129
+					if (!empty($search_params['topic'])) {
1130
+											$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1131
+					}
1132
+					if (!empty($minMsgID)) {
1133
+											$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1134
+					}
1135
+					if (!empty($maxMsgID)) {
1136
+											$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1137
+					}
1138
+					if (!empty($boardQuery)) {
1139
+											$subject_query['where'][] = 't.id_board ' . $boardQuery;
1140
+					}
1073 1141
 					if (!empty($excludedPhrases))
1074 1142
 					{
1075 1143
 						if ($subject_query['from'] != '{db_prefix}messages AS m')
@@ -1089,8 +1157,9 @@  discard block
 block discarded – undo
1089 1157
 					foreach ($weight_factors as $type => $value)
1090 1158
 					{
1091 1159
 						$relevance .= $weight[$type];
1092
-						if (!empty($value['results']))
1093
-							$relevance .= ' * ' . $value['results'];
1160
+						if (!empty($value['results'])) {
1161
+													$relevance .= ' * ' . $value['results'];
1162
+						}
1094 1163
 						$relevance .= ' + ';
1095 1164
 					}
1096 1165
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1128,20 +1197,23 @@  discard block
 block discarded – undo
1128 1197
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1129 1198
 						{
1130 1199
 							// No duplicates!
1131
-							if (isset($inserts[$row[1]]))
1132
-								continue;
1200
+							if (isset($inserts[$row[1]])) {
1201
+															continue;
1202
+							}
1133 1203
 
1134
-							foreach ($row as $key => $value)
1135
-								$inserts[$row[1]][] = (int) $row[$key];
1204
+							foreach ($row as $key => $value) {
1205
+															$inserts[$row[1]][] = (int) $row[$key];
1206
+							}
1136 1207
 						}
1137 1208
 						$smcFunc['db_free_result']($ignoreRequest);
1138 1209
 						$numSubjectResults = count($inserts);
1210
+					} else {
1211
+											$numSubjectResults += $smcFunc['db_affected_rows']();
1139 1212
 					}
1140
-					else
1141
-						$numSubjectResults += $smcFunc['db_affected_rows']();
1142 1213
 
1143
-					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1144
-						break;
1214
+					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1215
+											break;
1216
+					}
1145 1217
 				}
1146 1218
 
1147 1219
 				// If there's data to be inserted for non-IGNORE databases do it here!
@@ -1156,8 +1228,7 @@  discard block
 block discarded – undo
1156 1228
 				}
1157 1229
 
1158 1230
 				$_SESSION['search_cache']['num_results'] = $numSubjectResults;
1159
-			}
1160
-			else
1231
+			} else
1161 1232
 			{
1162 1233
 				$main_query = array(
1163 1234
 					'select' => array(
@@ -1189,8 +1260,7 @@  discard block
 block discarded – undo
1189 1260
 					$main_query['weights'] = $weight_factors;
1190 1261
 
1191 1262
 					$main_query['group_by'][] = 't.id_topic';
1192
-				}
1193
-				else
1263
+				} else
1194 1264
 				{
1195 1265
 					// This is outrageous!
1196 1266
 					$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';
@@ -1211,8 +1281,9 @@  discard block
 block discarded – undo
1211 1281
 						$main_query['where'][] = 't.id_topic = {int:topic}';
1212 1282
 						$main_query['parameters']['topic'] = $search_params['topic'];
1213 1283
 					}
1214
-					if (!empty($search_params['show_complete']))
1215
-						$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1284
+					if (!empty($search_params['show_complete'])) {
1285
+											$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1286
+					}
1216 1287
 				}
1217 1288
 
1218 1289
 				// *** Get the subject results.
@@ -1239,14 +1310,15 @@  discard block
 block discarded – undo
1239 1310
 					) !== false;
1240 1311
 
1241 1312
 					// Clean up some previous cache.
1242
-					if (!$createTemporary)
1243
-						$smcFunc['db_search_query']('delete_log_search_topics', '
1313
+					if (!$createTemporary) {
1314
+											$smcFunc['db_search_query']('delete_log_search_topics', '
1244 1315
 							DELETE FROM {db_prefix}log_search_topics
1245 1316
 							WHERE id_search = {int:search_id}',
1246 1317
 							array(
1247 1318
 								'search_id' => $_SESSION['search_cache']['id_search'],
1248 1319
 							)
1249 1320
 						);
1321
+					}
1250 1322
 
1251 1323
 					foreach ($searchWords as $orIndex => $words)
1252 1324
 					{
@@ -1278,8 +1350,7 @@  discard block
 block discarded – undo
1278 1350
 								$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1279 1351
 								$subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}';
1280 1352
 								$subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]';
1281
-							}
1282
-							else
1353
+							} else
1283 1354
 							{
1284 1355
 								$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1285 1356
 								$subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}';
@@ -1334,8 +1405,9 @@  discard block
 block discarded – undo
1334 1405
 						call_integration_hook('integrate_subject_search_query', array(&$subject_query));
1335 1406
 
1336 1407
 						// Nothing to search for?
1337
-						if (empty($subject_query['where']))
1338
-							continue;
1408
+						if (empty($subject_query['where'])) {
1409
+													continue;
1410
+						}
1339 1411
 
1340 1412
 						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( '
1341 1413
 							INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics
@@ -1358,19 +1430,21 @@  discard block
 block discarded – undo
1358 1430
 							{
1359 1431
 								$ind = $createTemporary ? 0 : 1;
1360 1432
 								// No duplicates!
1361
-								if (isset($inserts[$row[$ind]]))
1362
-									continue;
1433
+								if (isset($inserts[$row[$ind]])) {
1434
+																	continue;
1435
+								}
1363 1436
 
1364 1437
 								$inserts[$row[$ind]] = $row;
1365 1438
 							}
1366 1439
 							$smcFunc['db_free_result']($ignoreRequest);
1367 1440
 							$numSubjectResults = count($inserts);
1441
+						} else {
1442
+													$numSubjectResults += $smcFunc['db_affected_rows']();
1368 1443
 						}
1369
-						else
1370
-							$numSubjectResults += $smcFunc['db_affected_rows']();
1371 1444
 
1372
-						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1373
-							break;
1445
+						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1446
+													break;
1447
+						}
1374 1448
 					}
1375 1449
 
1376 1450
 					// Got some non-MySQL data to plonk in?
@@ -1388,8 +1462,9 @@  discard block
 block discarded – undo
1388 1462
 					{
1389 1463
 						$main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END';
1390 1464
 						$main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)';
1391
-						if (!$createTemporary)
1392
-							$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1465
+						if (!$createTemporary) {
1466
+													$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1467
+						}
1393 1468
 					}
1394 1469
 				}
1395 1470
 
@@ -1417,14 +1492,15 @@  discard block
 block discarded – undo
1417 1492
 					) !== false;
1418 1493
 
1419 1494
 					// Clear, all clear!
1420
-					if (!$createTemporary)
1421
-						$smcFunc['db_search_query']('delete_log_search_messages', '
1495
+					if (!$createTemporary) {
1496
+											$smcFunc['db_search_query']('delete_log_search_messages', '
1422 1497
 							DELETE FROM {db_prefix}log_search_messages
1423 1498
 							WHERE id_search = {int:id_search}',
1424 1499
 							array(
1425 1500
 								'id_search' => $_SESSION['search_cache']['id_search'],
1426 1501
 							)
1427 1502
 						);
1503
+					}
1428 1504
 
1429 1505
 					foreach ($searchWords as $orIndex => $words)
1430 1506
 					{
@@ -1458,19 +1534,21 @@  discard block
 block discarded – undo
1458 1534
 								while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1459 1535
 								{
1460 1536
 									// No duplicates!
1461
-									if (isset($inserts[$row[0]]))
1462
-										continue;
1537
+									if (isset($inserts[$row[0]])) {
1538
+																			continue;
1539
+									}
1463 1540
 
1464 1541
 									$inserts[$row[0]] = $row;
1465 1542
 								}
1466 1543
 								$smcFunc['db_free_result']($ignoreRequest);
1467 1544
 								$indexedResults = count($inserts);
1545
+							} else {
1546
+															$indexedResults += $smcFunc['db_affected_rows']();
1468 1547
 							}
1469
-							else
1470
-								$indexedResults += $smcFunc['db_affected_rows']();
1471 1548
 
1472
-							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults)
1473
-								break;
1549
+							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) {
1550
+															break;
1551
+							}
1474 1552
 						}
1475 1553
 					}
1476 1554
 
@@ -1490,8 +1568,7 @@  discard block
 block discarded – undo
1490 1568
 						$context['search_errors']['query_not_specific_enough'] = true;
1491 1569
 						$_REQUEST['params'] = $context['params'];
1492 1570
 						return PlushSearch1();
1493
-					}
1494
-					elseif (!empty($indexedResults))
1571
+					} elseif (!empty($indexedResults))
1495 1572
 					{
1496 1573
 						$main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)';
1497 1574
 						if (!$createTemporary)
@@ -1513,15 +1590,18 @@  discard block
 block discarded – undo
1513 1590
 						foreach ($words['all_words'] as $regularWord)
1514 1591
 						{
1515 1592
 							$where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1516
-							if (in_array($regularWord, $excludedWords))
1517
-								$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1593
+							if (in_array($regularWord, $excludedWords)) {
1594
+															$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1595
+							}
1518 1596
 							$main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
1519 1597
 						}
1520
-						if (!empty($where))
1521
-							$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1598
+						if (!empty($where)) {
1599
+													$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1600
+						}
1601
+					}
1602
+					if (!empty($orWhere)) {
1603
+											$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1522 1604
 					}
1523
-					if (!empty($orWhere))
1524
-						$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1525 1605
 
1526 1606
 					if (!empty($userQuery))
1527 1607
 					{
@@ -1559,8 +1639,9 @@  discard block
 block discarded – undo
1559 1639
 					foreach ($main_query['weights'] as $type => $value)
1560 1640
 					{
1561 1641
 						$relevance .= $weight[$type];
1562
-						if (!empty($value['search']))
1563
-							$relevance .= ' * ' . $value['search'];
1642
+						if (!empty($value['search'])) {
1643
+													$relevance .= ' * ' . $value['search'];
1644
+						}
1564 1645
 						$relevance .= ' + ';
1565 1646
 						$new_weight_total += $weight[$type];
1566 1647
 					}
@@ -1591,11 +1672,13 @@  discard block
 block discarded – undo
1591 1672
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1592 1673
 						{
1593 1674
 							// No duplicates!
1594
-							if (isset($inserts[$row[2]]))
1595
-								continue;
1675
+							if (isset($inserts[$row[2]])) {
1676
+															continue;
1677
+							}
1596 1678
 
1597
-							foreach ($row as $key => $value)
1598
-								$inserts[$row[2]][] = (int) $row[$key];
1679
+							foreach ($row as $key => $value) {
1680
+															$inserts[$row[2]][] = (int) $row[$key];
1681
+							}
1599 1682
 						}
1600 1683
 						$smcFunc['db_free_result']($ignoreRequest);
1601 1684
 
@@ -1603,8 +1686,9 @@  discard block
 block discarded – undo
1603 1686
 						if (!empty($inserts))
1604 1687
 						{
1605 1688
 							$query_columns = array();
1606
-							foreach ($main_query['select'] as $k => $v)
1607
-								$query_columns[$k] = 'int';
1689
+							foreach ($main_query['select'] as $k => $v) {
1690
+															$query_columns[$k] = 'int';
1691
+							}
1608 1692
 
1609 1693
 							$smcFunc['db_insert']('',
1610 1694
 								'{db_prefix}log_search_results',
@@ -1614,21 +1698,23 @@  discard block
 block discarded – undo
1614 1698
 							);
1615 1699
 						}
1616 1700
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1701
+					} else {
1702
+											$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1617 1703
 					}
1618
-					else
1619
-						$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1620 1704
 				}
1621 1705
 
1622 1706
 				// Insert subject-only matches.
1623 1707
 				if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0)
1624 1708
 				{
1625 1709
 					$relevance = '1000 * (';
1626
-					foreach ($weight_factors as $type => $value)
1627
-						if (isset($value['results']))
1710
+					foreach ($weight_factors as $type => $value) {
1711
+											if (isset($value['results']))
1628 1712
 						{
1629 1713
 							$relevance .= $weight[$type];
1630
-							if (!empty($value['results']))
1631
-								$relevance .= ' * ' . $value['results'];
1714
+					}
1715
+							if (!empty($value['results'])) {
1716
+															$relevance .= ' * ' . $value['results'];
1717
+							}
1632 1718
 							$relevance .= ' + ';
1633 1719
 						}
1634 1720
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1662,8 +1748,9 @@  discard block
 block discarded – undo
1662 1748
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1663 1749
 						{
1664 1750
 							// No duplicates!
1665
-							if (isset($usedIDs[$row[1]]))
1666
-								continue;
1751
+							if (isset($usedIDs[$row[1]])) {
1752
+															continue;
1753
+							}
1667 1754
 
1668 1755
 							$usedIDs[$row[1]] = true;
1669 1756
 							$inserts[] = $row;
@@ -1681,12 +1768,12 @@  discard block
 block discarded – undo
1681 1768
 							);
1682 1769
 						}
1683 1770
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1771
+					} else {
1772
+											$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1684 1773
 					}
1685
-					else
1686
-						$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1774
+				} elseif ($_SESSION['search_cache']['num_results'] == -1) {
1775
+									$_SESSION['search_cache']['num_results'] = 0;
1687 1776
 				}
1688
-				elseif ($_SESSION['search_cache']['num_results'] == -1)
1689
-					$_SESSION['search_cache']['num_results'] = 0;
1690 1777
 			}
1691 1778
 		}
1692 1779
 
@@ -1756,14 +1843,16 @@  discard block
 block discarded – undo
1756 1843
 			)
1757 1844
 		);
1758 1845
 		$posters = array();
1759
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1760
-			$posters[] = $row['id_member'];
1846
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1847
+					$posters[] = $row['id_member'];
1848
+		}
1761 1849
 		$smcFunc['db_free_result']($request);
1762 1850
 
1763 1851
 		call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters));
1764 1852
 
1765
-		if (!empty($posters))
1766
-			loadMemberData(array_unique($posters));
1853
+		if (!empty($posters)) {
1854
+					loadMemberData(array_unique($posters));
1855
+		}
1767 1856
 
1768 1857
 		// Get the messages out for the callback - select enough that it can be made to look just like Display.
1769 1858
 		$messages_request = $smcFunc['db_query']('', '
@@ -1797,8 +1886,9 @@  discard block
 block discarded – undo
1797 1886
 		);
1798 1887
 
1799 1888
 		// If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore.
1800
-		if ($smcFunc['db_num_rows']($messages_request) == 0)
1801
-			$context['topics'] = array();
1889
+		if ($smcFunc['db_num_rows']($messages_request) == 0) {
1890
+					$context['topics'] = array();
1891
+		}
1802 1892
 
1803 1893
 		// If we want to know who participated in what then load this now.
1804 1894
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
@@ -1816,8 +1906,9 @@  discard block
 block discarded – undo
1816 1906
 					'limit' => count($participants),
1817 1907
 				)
1818 1908
 			);
1819
-			while ($row = $smcFunc['db_fetch_assoc']($result))
1820
-				$participants[$row['id_topic']] = true;
1909
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
1910
+							$participants[$row['id_topic']] = true;
1911
+			}
1821 1912
 			$smcFunc['db_free_result']($result);
1822 1913
 		}
1823 1914
 	}
@@ -1826,15 +1917,17 @@  discard block
 block discarded – undo
1826 1917
 	$context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false);
1827 1918
 
1828 1919
 	// Consider the search complete!
1829
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1830
-		cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1920
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1921
+			cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1922
+	}
1831 1923
 
1832 1924
 	$context['key_words'] = &$searchArray;
1833 1925
 
1834 1926
 	// Setup the default topic icons... for checking they exist and the like!
1835 1927
 	$context['icon_sources'] = array();
1836
-	foreach ($context['stable_icons'] as $icon)
1837
-		$context['icon_sources'][$icon] = 'images_url';
1928
+	foreach ($context['stable_icons'] as $icon) {
1929
+			$context['icon_sources'][$icon] = 'images_url';
1930
+	}
1838 1931
 
1839 1932
 	$context['sub_template'] = 'results';
1840 1933
 	$context['page_title'] = $txt['search_results'];
@@ -1865,26 +1958,31 @@  discard block
 block discarded – undo
1865 1958
 	global $boards_can, $participants, $smcFunc;
1866 1959
 	static $recycle_board = null;
1867 1960
 
1868
-	if ($recycle_board === null)
1869
-		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1961
+	if ($recycle_board === null) {
1962
+			$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1963
+	}
1870 1964
 
1871 1965
 	// Remember which message this is.  (ie. reply #83)
1872 1966
 	static $counter = null;
1873
-	if ($counter == null || $reset)
1874
-		$counter = $_REQUEST['start'] + 1;
1967
+	if ($counter == null || $reset) {
1968
+			$counter = $_REQUEST['start'] + 1;
1969
+	}
1875 1970
 
1876 1971
 	// If the query returned false, bail.
1877
-	if ($messages_request == false)
1878
-		return false;
1972
+	if ($messages_request == false) {
1973
+			return false;
1974
+	}
1879 1975
 
1880 1976
 	// Start from the beginning...
1881
-	if ($reset)
1882
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1977
+	if ($reset) {
1978
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1979
+	}
1883 1980
 
1884 1981
 	// Attempt to get the next message.
1885 1982
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1886
-	if (!$message)
1887
-		return false;
1983
+	if (!$message) {
1984
+			return false;
1985
+	}
1888 1986
 
1889 1987
 	// Can't have an empty subject can we?
1890 1988
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1923,9 +2021,9 @@  discard block
 block discarded – undo
1923 2021
 
1924 2022
 		if ($smcFunc['strlen']($message['body']) > $charLimit)
1925 2023
 		{
1926
-			if (empty($context['key_words']))
1927
-				$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
1928
-			else
2024
+			if (empty($context['key_words'])) {
2025
+							$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
2026
+			} else
1929 2027
 			{
1930 2028
 				$matchString = '';
1931 2029
 				$force_partial_word = false;
@@ -1934,18 +2032,20 @@  discard block
 block discarded – undo
1934 2032
 					$keyword = un_htmlspecialchars($keyword);
1935 2033
 					$keyword = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
1936 2034
 
1937
-					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0)
1938
-						$force_partial_word = true;
2035
+					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) {
2036
+											$force_partial_word = true;
2037
+					}
1939 2038
 					$matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|';
1940 2039
 				}
1941 2040
 				$matchString = un_htmlspecialchars(substr($matchString, 0, -1));
1942 2041
 
1943 2042
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br>' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
1944 2043
 
1945
-				if (empty($modSettings['search_method']) || $force_partial_word)
1946
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
1947
-				else
1948
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2044
+				if (empty($modSettings['search_method']) || $force_partial_word) {
2045
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2046
+				} else {
2047
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2048
+				}
1949 2049
 
1950 2050
 				$message['body'] = '';
1951 2051
 				foreach ($matches[0] as $index => $match)
@@ -1958,8 +2058,7 @@  discard block
 block discarded – undo
1958 2058
 			// Re-fix the international characters.
1959 2059
 			$message['body'] = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']);
1960 2060
 		}
1961
-	}
1962
-	else
2061
+	} else
1963 2062
 	{
1964 2063
 		// Run BBC interpreter on the message.
1965 2064
 		$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
@@ -1978,21 +2077,26 @@  discard block
 block discarded – undo
1978 2077
 	// Sadly, we need to check the icon ain't broke.
1979 2078
 	if (!empty($modSettings['messageIconChecks_enable']))
1980 2079
 	{
1981
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1982
-			$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1983
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1984
-			$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1985
-		if (!isset($context['icon_sources'][$message['icon']]))
1986
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1987
-	}
1988
-	else
2080
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2081
+					$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
2082
+		}
2083
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2084
+					$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
2085
+		}
2086
+		if (!isset($context['icon_sources'][$message['icon']])) {
2087
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
2088
+		}
2089
+	} else
1989 2090
 	{
1990
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1991
-			$context['icon_sources'][$message['first_icon']] = 'images_url';
1992
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1993
-			$context['icon_sources'][$message['last_icon']] = 'images_url';
1994
-		if (!isset($context['icon_sources'][$message['icon']]))
1995
-			$context['icon_sources'][$message['icon']] = 'images_url';
2091
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2092
+					$context['icon_sources'][$message['first_icon']] = 'images_url';
2093
+		}
2094
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2095
+					$context['icon_sources'][$message['last_icon']] = 'images_url';
2096
+		}
2097
+		if (!isset($context['icon_sources'][$message['icon']])) {
2098
+					$context['icon_sources'][$message['icon']] = 'images_url';
2099
+		}
1996 2100
 	}
1997 2101
 
1998 2102
 	// Do we have quote tag enabled?
@@ -2002,12 +2106,14 @@  discard block
 block discarded – undo
2002 2106
 	$colorClass = 'windowbg';
2003 2107
 
2004 2108
 	// Sticky topics should get a different color, too.
2005
-	if ($message['is_sticky'])
2006
-		$colorClass .= ' sticky';
2109
+	if ($message['is_sticky']) {
2110
+			$colorClass .= ' sticky';
2111
+	}
2007 2112
 
2008 2113
 	// Locked topics get special treatment as well.
2009
-	if ($message['locked'])
2010
-		$colorClass .= ' locked';
2114
+	if ($message['locked']) {
2115
+			$colorClass .= ' locked';
2116
+	}
2011 2117
 
2012 2118
 	$output = array_merge($context['topics'][$message['id_msg']], array(
2013 2119
 		'id' => $message['id_topic'],
@@ -2151,8 +2257,9 @@  discard block
 block discarded – undo
2151 2257
 
2152 2258
 	// Load up the search API we are going to use.
2153 2259
 	$modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index'];
2154
-	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'))
2155
-		fatal_lang_error('search_api_missing');
2260
+	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) {
2261
+			fatal_lang_error('search_api_missing');
2262
+	}
2156 2263
 	require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php');
2157 2264
 
2158 2265
 	// Create an instance of the search API and check it is valid for this version of SMF.
Please login to merge, or discard this patch.
Sources/DbPackages-mysql.php 1 patch
Braces   +122 added lines, -97 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -105,8 +107,9 @@  discard block
 block discarded – undo
105 107
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
106 108
 
107 109
 	// First - no way do we touch SMF tables.
108
-	if (in_array(strtolower($table_name), $reservedTables))
109
-		return false;
110
+	if (in_array(strtolower($table_name), $reservedTables)) {
111
+			return false;
112
+	}
110 113
 
111 114
 	// Log that we'll want to remove this on uninstall.
112 115
 	$db_package_log[] = array('remove_table', $table_name);
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 	if (in_array($full_table_name, $tables))
117 120
 	{
118 121
 		// This is a sad day... drop the table? If not, return false (error) by default.
119
-		if ($if_exists == 'overwrite')
120
-			$smcFunc['db_drop_table']($table_name);
121
-		else
122
-			return $if_exists == 'ignore';
122
+		if ($if_exists == 'overwrite') {
123
+					$smcFunc['db_drop_table']($table_name);
124
+		} else {
125
+					return $if_exists == 'ignore';
126
+		}
123 127
 	}
124 128
 
125 129
 	// Righty - let's do the damn thing!
126 130
 	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '(';
127
-	foreach ($columns as $column)
128
-		$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
131
+	foreach ($columns as $column) {
132
+			$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
133
+	}
129 134
 
130 135
 	// Loop through the indexes next...
131 136
 	foreach ($indexes as $index)
@@ -133,19 +138,21 @@  discard block
 block discarded – undo
133 138
 		$columns = implode(',', $index['columns']);
134 139
 
135 140
 		// Is it the primary?
136
-		if (isset($index['type']) && $index['type'] == 'primary')
137
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
138
-		else
141
+		if (isset($index['type']) && $index['type'] == 'primary') {
142
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
143
+		} else
139 144
 		{
140
-			if (empty($index['name']))
141
-				$index['name'] = implode('_', $index['columns']);
145
+			if (empty($index['name'])) {
146
+							$index['name'] = implode('_', $index['columns']);
147
+			}
142 148
 			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),';
143 149
 		}
144 150
 	}
145 151
 
146 152
 	// No trailing commas!
147
-	if (substr($table_query, -1) == ',')
148
-		$table_query = substr($table_query, 0, -1);
153
+	if (substr($table_query, -1) == ',') {
154
+			$table_query = substr($table_query, 0, -1);
155
+	}
149 156
 
150 157
 	// Which engine do we want here?
151 158
 	if (empty($engines))
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 
156 163
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
157 164
 		{
158
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
159
-				$engines[] = $row['Engine'];
165
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
166
+							$engines[] = $row['Engine'];
167
+			}
160 168
 		}
161 169
 
162 170
 		$smcFunc['db_free_result']($get_engines);
@@ -170,8 +178,9 @@  discard block
 block discarded – undo
170 178
 	}
171 179
 
172 180
 	$table_query .= ') ENGINE=' . $parameters['engine'];
173
-	if (!empty($db_character_set) && $db_character_set == 'utf8')
174
-		$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
181
+	if (!empty($db_character_set) && $db_character_set == 'utf8') {
182
+			$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
183
+	}
175 184
 
176 185
 	// Create the table!
177 186
 	$smcFunc['db_query']('', $table_query,
@@ -203,8 +212,9 @@  discard block
 block discarded – undo
203 212
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
204 213
 
205 214
 	// God no - dropping one of these = bad.
206
-	if (in_array(strtolower($table_name), $reservedTables))
207
-		return false;
215
+	if (in_array(strtolower($table_name), $reservedTables)) {
216
+			return false;
217
+	}
208 218
 
209 219
 	// Does it exist?
210 220
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -245,14 +255,16 @@  discard block
 block discarded – undo
245 255
 
246 256
 	// Does it exist - if so don't add it again!
247 257
 	$columns = $smcFunc['db_list_columns']($table_name, false);
248
-	foreach ($columns as $column)
249
-		if ($column == $column_info['name'])
258
+	foreach ($columns as $column) {
259
+			if ($column == $column_info['name'])
250 260
 		{
251 261
 			// If we're going to overwrite then use change column.
252 262
 			if ($if_exists == 'update')
253 263
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
254
-			else
255
-				return false;
264
+	}
265
+			else {
266
+							return false;
267
+			}
256 268
 		}
257 269
 
258 270
 	// Get the specifics...
@@ -288,8 +300,8 @@  discard block
 block discarded – undo
288 300
 
289 301
 	// Does it exist?
290 302
 	$columns = $smcFunc['db_list_columns']($table_name, true);
291
-	foreach ($columns as $column)
292
-		if ($column['name'] == $column_name)
303
+	foreach ($columns as $column) {
304
+			if ($column['name'] == $column_name)
293 305
 		{
294 306
 			$smcFunc['db_query']('', '
295 307
 				ALTER TABLE ' . $table_name . '
@@ -298,6 +310,7 @@  discard block
 block discarded – undo
298 310
 					'security_override' => true,
299 311
 				)
300 312
 			);
313
+	}
301 314
 
302 315
 			return true;
303 316
 		}
@@ -323,37 +336,47 @@  discard block
 block discarded – undo
323 336
 	// Check it does exist!
324 337
 	$columns = $smcFunc['db_list_columns']($table_name, true);
325 338
 	$old_info = null;
326
-	foreach ($columns as $column)
327
-		if ($column['name'] == $old_column)
339
+	foreach ($columns as $column) {
340
+			if ($column['name'] == $old_column)
328 341
 			$old_info = $column;
342
+	}
329 343
 
330 344
 	// Nothing?
331
-	if ($old_info == null)
332
-		return false;
345
+	if ($old_info == null) {
346
+			return false;
347
+	}
333 348
 
334 349
 	// Get the right bits.
335
-	if (!isset($column_info['name']))
336
-		$column_info['name'] = $old_column;
337
-	if (!isset($column_info['default']))
338
-		$column_info['default'] = $old_info['default'];
339
-	if (!isset($column_info['null']))
340
-		$column_info['null'] = $old_info['null'];
341
-	if (!isset($column_info['auto']))
342
-		$column_info['auto'] = $old_info['auto'];
343
-	if (!isset($column_info['type']))
344
-		$column_info['type'] = $old_info['type'];
345
-	if (!isset($column_info['size']) || !is_numeric($column_info['size']))
346
-		$column_info['size'] = $old_info['size'];
347
-	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')))
348
-		$column_info['unsigned'] = '';
350
+	if (!isset($column_info['name'])) {
351
+			$column_info['name'] = $old_column;
352
+	}
353
+	if (!isset($column_info['default'])) {
354
+			$column_info['default'] = $old_info['default'];
355
+	}
356
+	if (!isset($column_info['null'])) {
357
+			$column_info['null'] = $old_info['null'];
358
+	}
359
+	if (!isset($column_info['auto'])) {
360
+			$column_info['auto'] = $old_info['auto'];
361
+	}
362
+	if (!isset($column_info['type'])) {
363
+			$column_info['type'] = $old_info['type'];
364
+	}
365
+	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) {
366
+			$column_info['size'] = $old_info['size'];
367
+	}
368
+	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) {
369
+			$column_info['unsigned'] = '';
370
+	}
349 371
 
350 372
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
351 373
 
352 374
 	// Allow for unsigned integers (mysql only)
353 375
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
354 376
 
355
-	if ($size !== null)
356
-		$type = $type . '(' . $size . ')';
377
+	if ($size !== null) {
378
+			$type = $type . '(' . $size . ')';
379
+	}
357 380
 
358 381
 	$smcFunc['db_query']('', '
359 382
 		ALTER TABLE ' . $table_name . '
@@ -383,18 +406,20 @@  discard block
 block discarded – undo
383 406
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
384 407
 
385 408
 	// No columns = no index.
386
-	if (empty($index_info['columns']))
387
-		return false;
409
+	if (empty($index_info['columns'])) {
410
+			return false;
411
+	}
388 412
 	$columns = implode(',', $index_info['columns']);
389 413
 
390 414
 	// No name - make it up!
391 415
 	if (empty($index_info['name']))
392 416
 	{
393 417
 		// No need for primary.
394
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
395
-			$index_info['name'] = '';
396
-		else
397
-			$index_info['name'] = implode('_', $index_info['columns']);
418
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
419
+					$index_info['name'] = '';
420
+		} else {
421
+					$index_info['name'] = implode('_', $index_info['columns']);
422
+		}
398 423
 	}
399 424
 
400 425
 	// Log that we are going to want to remove this!
@@ -408,10 +433,11 @@  discard block
 block discarded – undo
408 433
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
409 434
 		{
410 435
 			// If we want to overwrite simply remove the current one then continue.
411
-			if ($if_exists != 'update' || $index['type'] == 'primary')
412
-				return false;
413
-			else
414
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
436
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
437
+							return false;
438
+			} else {
439
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
440
+			}
415 441
 		}
416 442
 	}
417 443
 
@@ -425,8 +451,7 @@  discard block
 block discarded – undo
425 451
 				'security_override' => true,
426 452
 			)
427 453
 		);
428
-	}
429
-	else
454
+	} else
430 455
 	{
431 456
 		$smcFunc['db_query']('', '
432 457
 			ALTER TABLE ' . $table_name . '
@@ -510,8 +535,7 @@  discard block
 block discarded – undo
510 535
 		$types = array(
511 536
 			'inet' => 'varbinary',
512 537
 		);
513
-	}
514
-	else
538
+	} else
515 539
 	{
516 540
 		$types = array(
517 541
 			'varbinary' => 'inet',
@@ -525,16 +549,15 @@  discard block
 block discarded – undo
525 549
 		{
526 550
 			$type_size = 16;
527 551
 			$type_name = 'varbinary';
528
-		}
529
-		elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
552
+		} elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
530 553
 		{
531 554
 			$type_name = 'inet';
532 555
 			$type_size = null;
556
+		} elseif ($type_name == 'varbinary') {
557
+					$type_name = 'varbinary';
558
+		} else {
559
+					$type_name = $types[$type_name];
533 560
 		}
534
-		elseif ($type_name == 'varbinary')
535
-			$type_name = 'varbinary';
536
-		else
537
-			$type_name = $types[$type_name];
538 561
 	}
539 562
 
540 563
 	return array($type_name, $type_size);
@@ -602,8 +625,7 @@  discard block
 block discarded – undo
602 625
 		if (!$detail)
603 626
 		{
604 627
 			$columns[] = $row['Field'];
605
-		}
606
-		else
628
+		} else
607 629
 		{
608 630
 			// Is there an auto_increment?
609 631
 			$auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false;
@@ -613,10 +635,10 @@  discard block
 block discarded – undo
613 635
 			{
614 636
 				$type = $matches[1];
615 637
 				$size = $matches[2];
616
-				if (!empty($matches[3]) && $matches[3] == 'unsigned')
617
-					$unsigned = true;
618
-			}
619
-			else
638
+				if (!empty($matches[3]) && $matches[3] == 'unsigned') {
639
+									$unsigned = true;
640
+				}
641
+			} else
620 642
 			{
621 643
 				$type = $row['Type'];
622 644
 				$size = null;
@@ -667,19 +689,20 @@  discard block
 block discarded – undo
667 689
 	$indexes = array();
668 690
 	while ($row = $smcFunc['db_fetch_assoc']($result))
669 691
 	{
670
-		if (!$detail)
671
-			$indexes[] = $row['Key_name'];
672
-		else
692
+		if (!$detail) {
693
+					$indexes[] = $row['Key_name'];
694
+		} else
673 695
 		{
674 696
 			// What is the type?
675
-			if ($row['Key_name'] == 'PRIMARY')
676
-				$type = 'primary';
677
-			elseif (empty($row['Non_unique']))
678
-				$type = 'unique';
679
-			elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT')
680
-				$type = 'fulltext';
681
-			else
682
-				$type = 'index';
697
+			if ($row['Key_name'] == 'PRIMARY') {
698
+							$type = 'primary';
699
+			} elseif (empty($row['Non_unique'])) {
700
+							$type = 'unique';
701
+			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') {
702
+							$type = 'fulltext';
703
+			} else {
704
+							$type = 'index';
705
+			}
683 706
 
684 707
 			// This is the first column we've seen?
685 708
 			if (empty($indexes[$row['Key_name']]))
@@ -692,10 +715,11 @@  discard block
 block discarded – undo
692 715
 			}
693 716
 
694 717
 			// Is it a partial index?
695
-			if (!empty($row['Sub_part']))
696
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
697
-			else
698
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
718
+			if (!empty($row['Sub_part'])) {
719
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
720
+			} else {
721
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
722
+			}
699 723
 		}
700 724
 	}
701 725
 	$smcFunc['db_free_result']($result);
@@ -717,11 +741,11 @@  discard block
 block discarded – undo
717 741
 	if (!empty($column['auto']))
718 742
 	{
719 743
 		$default = 'auto_increment';
744
+	} elseif (isset($column['default']) && $column['default'] !== null) {
745
+			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
746
+	} else {
747
+			$default = '';
720 748
 	}
721
-	elseif (isset($column['default']) && $column['default'] !== null)
722
-		$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
723
-	else
724
-		$default = '';
725 749
 
726 750
 	// Sort out the size... and stuff...
727 751
 	$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
@@ -730,8 +754,9 @@  discard block
 block discarded – undo
730 754
 	// Allow unsigned integers (mysql only)
731 755
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : '';
732 756
 
733
-	if ($size !== null)
734
-		$type = $type . '(' . $size . ')';
757
+	if ($size !== null) {
758
+			$type = $type . '(' . $size . ')';
759
+	}
735 760
 
736 761
 	// Now just put it together!
737 762
 	return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default;
Please login to merge, or discard this patch.
Sources/Class-CurlFetchWeb.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
 	public $headers;
95 95
 
96 96
 	/**
97
-	* Start the curl object
98
-	* - allow for user override values
99
-	*
100
-	* @param array $options An array of cURL options
101
-	* @param int $max_redirect Maximum number of redirects
102
-	*/
97
+	 * Start the curl object
98
+	 * - allow for user override values
99
+	 *
100
+	 * @param array $options An array of cURL options
101
+	 * @param int $max_redirect Maximum number of redirects
102
+	 */
103 103
 	public function __construct($options = array(), $max_redirect = 3)
104 104
 	{
105 105
 		// Initialize class variables
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	}
109 109
 
110 110
 	/**
111
-	* Main calling function,
112
-	*  - will request the page data from a given $url
113
-	*  - optionally will post data to the page form if post data is supplied
114
-	*  - passed arrays will be converted to a post string joined with &'s
115
-	*  - calls set_options to set the curl opts array values based on the defaults and user input
116
-	*
117
-	* @param string $url the site we are going to fetch
118
-	* @param array $post_data any post data as form name => value
119
-	* @return object An instance of the curl_fetch_web_data class
120
-	*/
111
+	 * Main calling function,
112
+	 *  - will request the page data from a given $url
113
+	 *  - optionally will post data to the page form if post data is supplied
114
+	 *  - passed arrays will be converted to a post string joined with &'s
115
+	 *  - calls set_options to set the curl opts array values based on the defaults and user input
116
+	 *
117
+	 * @param string $url the site we are going to fetch
118
+	 * @param array $post_data any post data as form name => value
119
+	 * @return object An instance of the curl_fetch_web_data class
120
+	 */
121 121
 	public function get_url_data($url, $post_data = array())
122 122
 	{
123 123
 		// POSTing some data perhaps?
@@ -134,14 +134,14 @@  discard block
 block discarded – undo
134 134
 	}
135 135
 
136 136
 	/**
137
-	* Makes the actual cURL call
138
-	*  - stores responses (url, code, error, headers, body) in the response array
139
-	*  - detects 301, 302, 307 codes and will redirect to the given response header location
140
-	*
141
-	* @param string $url The site to fetch
142
-	* @param bool $redirect Whether or not this was a redirect request
143
-	* @return void|bool Sets various properties of the class or returns false if the URL isn't specified
144
-	*/
137
+	 * Makes the actual cURL call
138
+	 *  - stores responses (url, code, error, headers, body) in the response array
139
+	 *  - detects 301, 302, 307 codes and will redirect to the given response header location
140
+	 *
141
+	 * @param string $url The site to fetch
142
+	 * @param bool $redirect Whether or not this was a redirect request
143
+	 * @return void|bool Sets various properties of the class or returns false if the URL isn't specified
144
+	 */
145 145
 	private function curl_request($url, $redirect = false)
146 146
 	{
147 147
 		// we do have a url I hope
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 	}
194 194
 
195 195
 	/**
196
-	* Used if being redirected to ensure we have a fully qualified address
197
-	*
198
-	* @param string $last_url The URL we went to
199
-	* @param string $new_url The URL we were redirected to
200
-	* @return string The new URL that was in the HTTP header
201
-	*/
196
+	 * Used if being redirected to ensure we have a fully qualified address
197
+	 *
198
+	 * @param string $last_url The URL we went to
199
+	 * @param string $new_url The URL we were redirected to
200
+	 * @return string The new URL that was in the HTTP header
201
+	 */
202 202
 	private function get_redirect_url($last_url = '', $new_url = '')
203 203
 	{
204 204
 		// Get the elements for these urls
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 
218 218
 	/**
219
-	* Used to return the results to the calling program
220
-	*  - called as ->result() will return the full final array
221
-	*  - called as ->result('body') to just return the page source of the result
222
-	*
223
-	* @param string $area Used to return an area such as body, header, error
224
-	* @return string The response
225
-	*/
219
+	 * Used to return the results to the calling program
220
+	 *  - called as ->result() will return the full final array
221
+	 *  - called as ->result('body') to just return the page source of the result
222
+	 *
223
+	 * @param string $area Used to return an area such as body, header, error
224
+	 * @return string The response
225
+	 */
226 226
 	public function result($area = '')
227 227
 	{
228 228
 		$max_result = count($this->response) - 1;
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 	}
236 236
 
237 237
 	/**
238
-	* Will return all results from all loops (redirects)
239
-	*  - Can be called as ->result_raw(x) where x is a specific loop results.
240
-	*  - Call as ->result_raw() for everything.
241
-	*
242
-	* @param string $response_number Which response we want to get
243
-	* @return array|string The entire response array or just the specified response
244
-	*/
238
+	 * Will return all results from all loops (redirects)
239
+	 *  - Can be called as ->result_raw(x) where x is a specific loop results.
240
+	 *  - Call as ->result_raw() for everything.
241
+	 *
242
+	 * @param string $response_number Which response we want to get
243
+	 * @return array|string The entire response array or just the specified response
244
+	 */
245 245
 	public function result_raw($response_number = '')
246 246
 	{
247 247
 		if (!is_numeric($response_number))
@@ -254,13 +254,13 @@  discard block
 block discarded – undo
254 254
 	}
255 255
 
256 256
 	/**
257
-	* Takes supplied POST data and url encodes it
258
-	*  - forms the date (for post) in to a string var=xyz&var2=abc&var3=123
259
-	*  - drops vars with @ since we don't support sending files (uploading)
260
-	*
261
-	* @param array|string $post_data The raw POST data
262
-	* @return string A string of post data
263
-	*/
257
+	 * Takes supplied POST data and url encodes it
258
+	 *  - forms the date (for post) in to a string var=xyz&var2=abc&var3=123
259
+	 *  - drops vars with @ since we don't support sending files (uploading)
260
+	 *
261
+	 * @param array|string $post_data The raw POST data
262
+	 * @return string A string of post data
263
+	 */
264 264
 	private function build_post_data($post_data)
265 265
 	{
266 266
 		if (is_array($post_data))
@@ -279,11 +279,11 @@  discard block
 block discarded – undo
279 279
 	}
280 280
 
281 281
 	/**
282
-	* Sets the final cURL options for the current call
283
-	*  - overwrites our default values with user supplied ones or appends new user ones to what we have
284
-	*  - sets the callback function now that $this is existing
285
-	* @return void
286
-	*/
282
+	 * Sets the final cURL options for the current call
283
+	 *  - overwrites our default values with user supplied ones or appends new user ones to what we have
284
+	 *  - sets the callback function now that $this is existing
285
+	 * @return void
286
+	 */
287 287
 	private function set_options()
288 288
 	{
289 289
 		// Callback to parse the returned headers, if any
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
 	}
309 309
 
310 310
 	/**
311
-	* Called to initiate a redirect from a 301, 302 or 307 header
312
-	*  - resets the cURL options for the loop, sets the referrer flag
313
-	*
314
-	* @param string $target_url The URL we want to redirect to
315
-	* @param string $referer_url The URL that we're redirecting from
316
-	*/
311
+	 * Called to initiate a redirect from a 301, 302 or 307 header
312
+	 *  - resets the cURL options for the loop, sets the referrer flag
313
+	 *
314
+	 * @param string $target_url The URL we want to redirect to
315
+	 * @param string $referer_url The URL that we're redirecting from
316
+	 */
317 317
 	private function redirect($target_url, $referer_url)
318 318
 	{
319 319
 		// no no I last saw that over there ... really, 301, 302, 307
Please login to merge, or discard this patch.
Braces   +27 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,8 +10,9 @@  discard block
 block discarded – undo
10 10
  * @version 2.1 Beta 3
11 11
  */
12 12
 
13
-if (!defined('SMF'))
13
+if (!defined('SMF')) {
14 14
 	die('No direct access...');
15
+}
15 16
 
16 17
 /**
17 18
  * Class curl_fetch_web_data
@@ -121,10 +122,11 @@  discard block
 block discarded – undo
121 122
 	public function get_url_data($url, $post_data = array())
122 123
 	{
123 124
 		// POSTing some data perhaps?
124
-		if (!empty($post_data) && is_array($post_data))
125
-			$this->post_data = $this->build_post_data($post_data);
126
-		elseif (!empty($post_data))
127
-			$this->post_data = trim($post_data);
125
+		if (!empty($post_data) && is_array($post_data)) {
126
+					$this->post_data = $this->build_post_data($post_data);
127
+		} elseif (!empty($post_data)) {
128
+					$this->post_data = trim($post_data);
129
+		}
128 130
 
129 131
 		// set the options and get it
130 132
 		$this->set_options();
@@ -145,10 +147,11 @@  discard block
 block discarded – undo
145 147
 	private function curl_request($url, $redirect = false)
146 148
 	{
147 149
 		// we do have a url I hope
148
-		if ($url == '')
149
-			return false;
150
-		else
151
-			$this->options[CURLOPT_URL] = $url;
150
+		if ($url == '') {
151
+					return false;
152
+		} else {
153
+					$this->options[CURLOPT_URL] = $url;
154
+		}
152 155
 
153 156
 		// if we have not already been redirected, set it up so we can if needed
154 157
 		if (!$redirect)
@@ -228,10 +231,11 @@  discard block
 block discarded – undo
228 231
 		$max_result = count($this->response) - 1;
229 232
 
230 233
 		// just return a specifed area or the entire result?
231
-		if ($area == '')
232
-			return $this->response[$max_result];
233
-		else
234
-			return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
234
+		if ($area == '') {
235
+					return $this->response[$max_result];
236
+		} else {
237
+					return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
238
+		}
235 239
 	}
236 240
 
237 241
 	/**
@@ -244,9 +248,9 @@  discard block
 block discarded – undo
244 248
 	*/
245 249
 	public function result_raw($response_number = '')
246 250
 	{
247
-		if (!is_numeric($response_number))
248
-			return $this->response;
249
-		else
251
+		if (!is_numeric($response_number)) {
252
+					return $this->response;
253
+		} else
250 254
 		{
251 255
 			$response_number = min($response_number, count($this->response) - 1);
252 256
 			return $this->response[$response_number];
@@ -268,13 +272,14 @@  discard block
 block discarded – undo
268 272
 			$postvars = array();
269 273
 
270 274
 			// build the post data, drop ones with leading @'s since those can be used to send files, we don't support that.
271
-			foreach ($post_data as $name => $value)
272
-				$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
275
+			foreach ($post_data as $name => $value) {
276
+							$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
277
+			}
273 278
 
274 279
 			return implode('&', $postvars);
280
+		} else {
281
+					return $post_data;
275 282
 		}
276
-		else
277
-			return $post_data;
278 283
 
279 284
 	}
280 285
 
@@ -295,9 +300,9 @@  discard block
 block discarded – undo
295 300
 			$keys = array_merge(array_keys($this->default_options), array_keys($this->user_options));
296 301
 			$vals = array_merge($this->default_options, $this->user_options);
297 302
 			$this->options = array_combine($keys, $vals);
303
+		} else {
304
+					$this->options = $this->default_options;
298 305
 		}
299
-		else
300
-			$this->options = $this->default_options;
301 306
 
302 307
 		// POST data options, here we don't allow any overide
303 308
 		if (isset($this->post_data))
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +435 added lines, -324 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 			
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 			
66
-			if ($charcode == 'UTF8')			
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -74,12 +76,14 @@  discard block
 block discarded – undo
74 76
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
75 77
 
76 78
 			// Is it reserved?
77
-			if ($value == 'pg_')
78
-				return $txt['error_db_prefix_reserved'];
79
+			if ($value == 'pg_') {
80
+							return $txt['error_db_prefix_reserved'];
81
+			}
79 82
 
80 83
 			// Is the prefix numeric?
81
-			if (preg_match('~^\d~', $value))
82
-				return $txt['error_db_prefix_numeric'];
84
+			if (preg_match('~^\d~', $value)) {
85
+							return $txt['error_db_prefix_numeric'];
86
+			}
83 87
 
84 88
 			return true;
85 89
 		},
@@ -124,10 +128,11 @@  discard block
 block discarded – undo
124 128
 		$incontext['skip'] = false;
125 129
 
126 130
 		// Call the step and if it returns false that means pause!
127
-		if (function_exists($step[2]) && $step[2]() === false)
128
-			break;
129
-		elseif (function_exists($step[2]))
130
-			$incontext['current_step']++;
131
+		if (function_exists($step[2]) && $step[2]() === false) {
132
+					break;
133
+		} elseif (function_exists($step[2])) {
134
+					$incontext['current_step']++;
135
+		}
131 136
 
132 137
 		// No warnings pass on.
133 138
 		$incontext['warning'] = '';
@@ -143,8 +148,9 @@  discard block
 block discarded – undo
143 148
 	global $databases, $incontext;
144 149
 
145 150
 	// Just so people using older versions of PHP aren't left in the cold.
146
-	if (!isset($_SERVER['PHP_SELF']))
147
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
151
+	if (!isset($_SERVER['PHP_SELF'])) {
152
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
153
+	}
148 154
 
149 155
 	// Enable error reporting.
150 156
 	error_reporting(E_ALL);
@@ -160,21 +166,23 @@  discard block
 block discarded – undo
160 166
 	{
161 167
 		ob_start();
162 168
 
163
-		if (ini_get('session.save_handler') == 'user')
164
-			@ini_set('session.save_handler', 'files');
165
-		if (function_exists('session_start'))
166
-			@session_start();
167
-	}
168
-	else
169
+		if (ini_get('session.save_handler') == 'user') {
170
+					@ini_set('session.save_handler', 'files');
171
+		}
172
+		if (function_exists('session_start')) {
173
+					@session_start();
174
+		}
175
+	} else
169 176
 	{
170 177
 		ob_start('ob_gzhandler');
171 178
 
172
-		if (ini_get('session.save_handler') == 'user')
173
-			@ini_set('session.save_handler', 'files');
179
+		if (ini_get('session.save_handler') == 'user') {
180
+					@ini_set('session.save_handler', 'files');
181
+		}
174 182
 		session_start();
175 183
 
176
-		if (!headers_sent())
177
-			echo '<!DOCTYPE html>
184
+		if (!headers_sent()) {
185
+					echo '<!DOCTYPE html>
178 186
 <html>
179 187
 	<head>
180 188
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -183,14 +191,16 @@  discard block
 block discarded – undo
183 191
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
184 192
 	</body>
185 193
 </html>';
194
+		}
186 195
 		exit;
187 196
 	}
188 197
 
189 198
 	// Add slashes, as long as they aren't already being added.
190
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
191
-		foreach ($_POST as $k => $v)
199
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
200
+			foreach ($_POST as $k => $v)
192 201
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
193 202
 				$_POST[$k] = addslashes($v);
203
+	}
194 204
 
195 205
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
196 206
 	if (isset($_GET['delete']))
@@ -211,8 +221,7 @@  discard block
 block discarded – undo
211 221
 			$ftp->close();
212 222
 
213 223
 			unset($_SESSION['installer_temp_ftp']);
214
-		}
215
-		else
224
+		} else
216 225
 		{
217 226
 			@unlink(__FILE__);
218 227
 
@@ -233,10 +242,11 @@  discard block
 block discarded – undo
233 242
 	{
234 243
 		// Get PHP's default timezone, if set
235 244
 		$ini_tz = ini_get('date.timezone');
236
-		if (!empty($ini_tz))
237
-			$timezone_id = $ini_tz;
238
-		else
239
-			$timezone_id = '';
245
+		if (!empty($ini_tz)) {
246
+					$timezone_id = $ini_tz;
247
+		} else {
248
+					$timezone_id = '';
249
+		}
240 250
 
241 251
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
242 252
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -266,8 +276,9 @@  discard block
 block discarded – undo
266 276
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
267 277
 		while ($entry = $dir->read())
268 278
 		{
269
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
270
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
279
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
280
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
281
+			}
271 282
 		}
272 283
 		$dir->close();
273 284
 	}
@@ -302,10 +313,11 @@  discard block
 block discarded – undo
302 313
 	}
303 314
 
304 315
 	// Override the language file?
305
-	if (isset($_GET['lang_file']))
306
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
307
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
308
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
316
+	if (isset($_GET['lang_file'])) {
317
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
318
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
319
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	}
309 321
 
310 322
 	// Make sure it exists, if it doesn't reset it.
311 323
 	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']))
@@ -314,8 +326,9 @@  discard block
 block discarded – undo
314 326
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
315 327
 
316 328
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
317
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
318
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
329
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
330
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
331
+		}
319 332
 	}
320 333
 
321 334
 	// And now include the actual language file itself.
@@ -328,15 +341,18 @@  discard block
 block discarded – undo
328 341
 	global $db_prefix, $db_connection, $sourcedir;
329 342
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
330 343
 
331
-	if (empty($sourcedir))
332
-		$sourcedir = dirname(__FILE__) . '/Sources';
344
+	if (empty($sourcedir)) {
345
+			$sourcedir = dirname(__FILE__) . '/Sources';
346
+	}
333 347
 
334 348
 	// Need this to check whether we need the database password.
335 349
 	require(dirname(__FILE__) . '/Settings.php');
336
-	if (!defined('SMF'))
337
-		define('SMF', 1);
338
-	if (empty($smcFunc))
339
-		$smcFunc = array();
350
+	if (!defined('SMF')) {
351
+			define('SMF', 1);
352
+	}
353
+	if (empty($smcFunc)) {
354
+			$smcFunc = array();
355
+	}
340 356
 
341 357
 	$modSettings['disableQueryCheck'] = true;
342 358
 
@@ -344,8 +360,9 @@  discard block
 block discarded – undo
344 360
 	if (!$db_connection)
345 361
 	{
346 362
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
347
-		if (version_compare(PHP_VERSION, '5', '<'))
348
-			require_once($sourcedir . '/Subs-Compat.php');
363
+		if (version_compare(PHP_VERSION, '5', '<')) {
364
+					require_once($sourcedir . '/Subs-Compat.php');
365
+		}
349 366
 
350 367
 		$db_options = array('persist' => $db_persist);
351 368
 		$port = '';
@@ -356,19 +373,20 @@  discard block
 block discarded – undo
356 373
 			if ($db_type == 'mysql')
357 374
 			{
358 375
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
359
-			}
360
-			elseif ($db_type == 'postgresql')
376
+			} elseif ($db_type == 'postgresql')
361 377
 			{
362 378
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
363 379
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
364 380
 			}
365 381
 		}
366 382
 
367
-		if (!empty($port))
368
-			$db_options['port'] = $port;
383
+		if (!empty($port)) {
384
+					$db_options['port'] = $port;
385
+		}
369 386
 
370
-		if (!$db_connection)
371
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
387
+		if (!$db_connection) {
388
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
389
+		}
372 390
 	}
373 391
 }
374 392
 
@@ -396,8 +414,9 @@  discard block
 block discarded – undo
396 414
 		// @todo REMOVE THIS!!
397 415
 		else
398 416
 		{
399
-			if (function_exists('doStep' . $_GET['step']))
400
-				call_user_func('doStep' . $_GET['step']);
417
+			if (function_exists('doStep' . $_GET['step'])) {
418
+							call_user_func('doStep' . $_GET['step']);
419
+			}
401 420
 		}
402 421
 		// Show the footer.
403 422
 		template_install_below();
@@ -415,8 +434,9 @@  discard block
 block discarded – undo
415 434
 	$incontext['sub_template'] = 'welcome_message';
416 435
 
417 436
 	// Done the submission?
418
-	if (isset($_POST['contbutt']))
419
-		return true;
437
+	if (isset($_POST['contbutt'])) {
438
+			return true;
439
+	}
420 440
 
421 441
 	// See if we think they have already installed it?
422 442
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -424,14 +444,17 @@  discard block
 block discarded – undo
424 444
 		$probably_installed = 0;
425 445
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
426 446
 		{
427
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
428
-				$probably_installed++;
429
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
430
-				$probably_installed++;
447
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
448
+							$probably_installed++;
449
+			}
450
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
451
+							$probably_installed++;
452
+			}
431 453
 		}
432 454
 
433
-		if ($probably_installed == 2)
434
-			$incontext['warning'] = $txt['error_already_installed'];
455
+		if ($probably_installed == 2) {
456
+					$incontext['warning'] = $txt['error_already_installed'];
457
+		}
435 458
 	}
436 459
 
437 460
 	// Is some database support even compiled in?
@@ -446,36 +469,43 @@  discard block
 block discarded – undo
446 469
 				$databases[$key]['supported'] = false;
447 470
 				$notFoundSQLFile = true;
448 471
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
472
+			} else {
473
+							$incontext['supported_databases'][] = $db;
449 474
 			}
450
-			else
451
-				$incontext['supported_databases'][] = $db;
452 475
 		}
453 476
 	}
454 477
 
455 478
 	// Check the PHP version.
456
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
457
-		$error = 'error_php_too_low';
479
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
480
+			$error = 'error_php_too_low';
481
+	}
458 482
 	// Make sure we have a supported database
459
-	elseif (empty($incontext['supported_databases']))
460
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
483
+	elseif (empty($incontext['supported_databases'])) {
484
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
485
+	}
461 486
 	// How about session support?  Some crazy sysadmin remove it?
462
-	elseif (!function_exists('session_start'))
463
-		$error = 'error_session_missing';
487
+	elseif (!function_exists('session_start')) {
488
+			$error = 'error_session_missing';
489
+	}
464 490
 	// Make sure they uploaded all the files.
465
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
466
-		$error = 'error_missing_files';
491
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
492
+			$error = 'error_missing_files';
493
+	}
467 494
 	// Very simple check on the session.save_path for Windows.
468 495
 	// @todo Move this down later if they don't use database-driven sessions?
469
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
470
-		$error = 'error_session_save_path';
496
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
497
+			$error = 'error_session_save_path';
498
+	}
471 499
 
472 500
 	// Since each of the three messages would look the same, anyway...
473
-	if (isset($error))
474
-		$incontext['error'] = $txt[$error];
501
+	if (isset($error)) {
502
+			$incontext['error'] = $txt[$error];
503
+	}
475 504
 
476 505
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
477
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
478
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
506
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
507
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
508
+	}
479 509
 
480 510
 	return false;
481 511
 }
@@ -501,12 +531,14 @@  discard block
 block discarded – undo
501 531
 		'db_last_error.php',
502 532
 	);
503 533
 
504
-	foreach ($incontext['detected_languages'] as $lang => $temp)
505
-		$extra_files[] = 'Themes/default/languages/' . $lang;
534
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
535
+			$extra_files[] = 'Themes/default/languages/' . $lang;
536
+	}
506 537
 
507 538
 	// With mod_security installed, we could attempt to fix it with .htaccess.
508
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
509
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
539
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
540
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
541
+	}
510 542
 
511 543
 	$failed_files = array();
512 544
 
@@ -522,12 +554,14 @@  discard block
 block discarded – undo
522 554
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
523 555
 
524 556
 				// Well, 755 hopefully worked... if not, try 777.
525
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
526
-					$failed_files[] = $file;
557
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
558
+									$failed_files[] = $file;
559
+				}
527 560
 			}
528 561
 		}
529
-		foreach ($extra_files as $file)
530
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
562
+		foreach ($extra_files as $file) {
563
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
564
+		}
531 565
 	}
532 566
 	// Windows is trickier.  Let's try opening for r+...
533 567
 	else
@@ -537,30 +571,35 @@  discard block
 block discarded – undo
537 571
 		foreach ($writable_files as $file)
538 572
 		{
539 573
 			// Folders can't be opened for write... but the index.php in them can ;)
540
-			if (is_dir(dirname(__FILE__) . '/' . $file))
541
-				$file .= '/index.php';
574
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
575
+							$file .= '/index.php';
576
+			}
542 577
 
543 578
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
544 579
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
545 580
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
546 581
 
547 582
 			// Hmm, okay, try just for write in that case...
548
-			if (!is_resource($fp))
549
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
583
+			if (!is_resource($fp)) {
584
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
585
+			}
550 586
 
551
-			if (!is_resource($fp))
552
-				$failed_files[] = $file;
587
+			if (!is_resource($fp)) {
588
+							$failed_files[] = $file;
589
+			}
553 590
 
554 591
 			@fclose($fp);
555 592
 		}
556
-		foreach ($extra_files as $file)
557
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
593
+		foreach ($extra_files as $file) {
594
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
595
+		}
558 596
 	}
559 597
 
560 598
 	$failure = count($failed_files) >= 1;
561 599
 
562
-	if (!isset($_SERVER))
563
-		return !$failure;
600
+	if (!isset($_SERVER)) {
601
+			return !$failure;
602
+	}
564 603
 
565 604
 	// Put the list into context.
566 605
 	$incontext['failed_files'] = $failed_files;
@@ -608,19 +647,23 @@  discard block
 block discarded – undo
608 647
 
609 648
 		if (!isset($ftp) || $ftp->error !== false)
610 649
 		{
611
-			if (!isset($ftp))
612
-				$ftp = new ftp_connection(null);
650
+			if (!isset($ftp)) {
651
+							$ftp = new ftp_connection(null);
652
+			}
613 653
 			// Save the error so we can mess with listing...
614
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
615
-				$incontext['ftp_errors'][] = $ftp->last_message;
654
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
655
+							$incontext['ftp_errors'][] = $ftp->last_message;
656
+			}
616 657
 
617 658
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
618 659
 
619
-			if (empty($_POST['ftp_path']) && $found_path)
620
-				$_POST['ftp_path'] = $detect_path;
660
+			if (empty($_POST['ftp_path']) && $found_path) {
661
+							$_POST['ftp_path'] = $detect_path;
662
+			}
621 663
 
622
-			if (!isset($_POST['ftp_username']))
623
-				$_POST['ftp_username'] = $username;
664
+			if (!isset($_POST['ftp_username'])) {
665
+							$_POST['ftp_username'] = $username;
666
+			}
624 667
 
625 668
 			// Set the username etc, into context.
626 669
 			$incontext['ftp'] = array(
@@ -632,8 +675,7 @@  discard block
 block discarded – undo
632 675
 			);
633 676
 
634 677
 			return false;
635
-		}
636
-		else
678
+		} else
637 679
 		{
638 680
 			$_SESSION['installer_temp_ftp'] = array(
639 681
 				'server' => $_POST['ftp_server'],
@@ -647,10 +689,12 @@  discard block
 block discarded – undo
647 689
 
648 690
 			foreach ($failed_files as $file)
649 691
 			{
650
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
651
-					$ftp->chmod($file, 0755);
652
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
653
-					$ftp->chmod($file, 0777);
692
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
693
+									$ftp->chmod($file, 0755);
694
+				}
695
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
696
+									$ftp->chmod($file, 0777);
697
+				}
654 698
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
655 699
 				{
656 700
 					$failed_files_updated[] = $file;
@@ -705,15 +749,17 @@  discard block
 block discarded – undo
705 749
 
706 750
 			if (!$foundOne)
707 751
 			{
708
-				if (isset($db['default_host']))
709
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
752
+				if (isset($db['default_host'])) {
753
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
754
+				}
710 755
 				if (isset($db['default_user']))
711 756
 				{
712 757
 					$incontext['db']['user'] = ini_get($db['default_user']);
713 758
 					$incontext['db']['name'] = ini_get($db['default_user']);
714 759
 				}
715
-				if (isset($db['default_password']))
716
-					$incontext['db']['pass'] = ini_get($db['default_password']);
760
+				if (isset($db['default_password'])) {
761
+									$incontext['db']['pass'] = ini_get($db['default_password']);
762
+				}
717 763
 
718 764
 				// For simplicity and less confusion, leave the port blank by default
719 765
 				$incontext['db']['port'] = '';
@@ -732,10 +778,10 @@  discard block
 block discarded – undo
732 778
 		$incontext['db']['server'] = $_POST['db_server'];
733 779
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
734 780
 
735
-		if (!empty($_POST['db_port']))
736
-			$incontext['db']['port'] = $_POST['db_port'];
737
-	}
738
-	else
781
+		if (!empty($_POST['db_port'])) {
782
+					$incontext['db']['port'] = $_POST['db_port'];
783
+		}
784
+	} else
739 785
 	{
740 786
 		$incontext['db']['prefix'] = 'smf_';
741 787
 	}
@@ -771,10 +817,11 @@  discard block
 block discarded – undo
771 817
 		if (!empty($_POST['db_port']))
772 818
 		{
773 819
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
774
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
775
-				$vars['db_port'] = (int) $_POST['db_port'];
776
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
777
-				$vars['db_port'] = (int) $_POST['db_port'];
820
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
821
+							$vars['db_port'] = (int) $_POST['db_port'];
822
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
823
+							$vars['db_port'] = (int) $_POST['db_port'];
824
+			}
778 825
 		}
779 826
 
780 827
 		// God I hope it saved!
@@ -787,8 +834,9 @@  discard block
 block discarded – undo
787 834
 		// Make sure it works.
788 835
 		require(dirname(__FILE__) . '/Settings.php');
789 836
 
790
-		if (empty($sourcedir))
791
-			$sourcedir = dirname(__FILE__) . '/Sources';
837
+		if (empty($sourcedir)) {
838
+					$sourcedir = dirname(__FILE__) . '/Sources';
839
+		}
792 840
 
793 841
 		// Better find the database file!
794 842
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -798,18 +846,21 @@  discard block
 block discarded – undo
798 846
 		}
799 847
 
800 848
 		// Now include it for database functions!
801
-		if (!defined('SMF'))
802
-			define('SMF', 1);
849
+		if (!defined('SMF')) {
850
+					define('SMF', 1);
851
+		}
803 852
 
804 853
 		$modSettings['disableQueryCheck'] = true;
805
-		if (empty($smcFunc))
806
-			$smcFunc = array();
854
+		if (empty($smcFunc)) {
855
+					$smcFunc = array();
856
+		}
807 857
 
808 858
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
809 859
 
810 860
 		// What - running PHP4? The shame!
811
-		if (version_compare(PHP_VERSION, '5', '<'))
812
-			require_once($sourcedir . '/Subs-Compat.php');
861
+		if (version_compare(PHP_VERSION, '5', '<')) {
862
+					require_once($sourcedir . '/Subs-Compat.php');
863
+		}
813 864
 
814 865
 		// Attempt a connection.
815 866
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -897,12 +948,14 @@  discard block
 block discarded – undo
897 948
 	$incontext['page_title'] = $txt['install_settings'];
898 949
 
899 950
 	// Let's see if we got the database type correct.
900
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
901
-		$db_type = $_POST['db_type'];
951
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
952
+			$db_type = $_POST['db_type'];
953
+	}
902 954
 
903 955
 	// Else we'd better be able to get the connection.
904
-	else
905
-		load_database();
956
+	else {
957
+			load_database();
958
+	}
906 959
 
907 960
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
908 961
 
@@ -922,12 +975,14 @@  discard block
 block discarded – undo
922 975
 	// Submitting?
923 976
 	if (isset($_POST['boardurl']))
924 977
 	{
925
-		if (substr($_POST['boardurl'], -10) == '/index.php')
926
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
927
-		elseif (substr($_POST['boardurl'], -1) == '/')
928
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
929
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
930
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
978
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
979
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
980
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
981
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
982
+		}
983
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
984
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
985
+		}
931 986
 
932 987
 		// Save these variables.
933 988
 		$vars = array(
@@ -964,10 +1019,10 @@  discard block
 block discarded – undo
964 1019
 			{
965 1020
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
966 1021
 				return false;
967
-			}
968
-			else
969
-				// Set the character set here.
1022
+			} else {
1023
+							// Set the character set here.
970 1024
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1025
+			}
971 1026
 		}
972 1027
 
973 1028
 		// Good, skip on.
@@ -987,8 +1042,9 @@  discard block
 block discarded – undo
987 1042
 	$incontext['continue'] = 1;
988 1043
 
989 1044
 	// Already done?
990
-	if (isset($_POST['pop_done']))
991
-		return true;
1045
+	if (isset($_POST['pop_done'])) {
1046
+			return true;
1047
+	}
992 1048
 
993 1049
 	// Reload settings.
994 1050
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1006,8 +1062,9 @@  discard block
 block discarded – undo
1006 1062
 	$modSettings = array();
1007 1063
 	if ($result !== false)
1008 1064
 	{
1009
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1010
-			$modSettings[$row['variable']] = $row['value'];
1065
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1066
+					$modSettings[$row['variable']] = $row['value'];
1067
+		}
1011 1068
 		$smcFunc['db_free_result']($result);
1012 1069
 
1013 1070
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1020,20 +1077,22 @@  discard block
 block discarded – undo
1020 1077
 	$modSettings['disableQueryCheck'] = true;
1021 1078
 
1022 1079
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1023
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1024
-		$smcFunc['db_query']('', '
1080
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1081
+			$smcFunc['db_query']('', '
1025 1082
 			SET NAMES {string:utf8}',
1026 1083
 			array(
1027 1084
 				'db_error_skip' => true,
1028 1085
 				'utf8' => 'utf8',
1029 1086
 			)
1030 1087
 		);
1088
+	}
1031 1089
 
1032 1090
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1033
-	if (substr(__DIR__, -1) == '\\')
1034
-		$attachdir = __DIR__ . 'attachments';
1035
-	else
1036
-		$attachdir = __DIR__ . '/attachments';
1091
+	if (substr(__DIR__, -1) == '\\') {
1092
+			$attachdir = __DIR__ . 'attachments';
1093
+	} else {
1094
+			$attachdir = __DIR__ . '/attachments';
1095
+	}
1037 1096
 
1038 1097
 	$replaces = array(
1039 1098
 		'{$db_prefix}' => $db_prefix,
@@ -1050,8 +1109,9 @@  discard block
 block discarded – undo
1050 1109
 
1051 1110
 	foreach ($txt as $key => $value)
1052 1111
 	{
1053
-		if (substr($key, 0, 8) == 'default_')
1054
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1112
+		if (substr($key, 0, 8) == 'default_') {
1113
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1114
+		}
1055 1115
 	}
1056 1116
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1057 1117
 
@@ -1066,8 +1126,9 @@  discard block
 block discarded – undo
1066 1126
 
1067 1127
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1068 1128
 		{
1069
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1070
-				$engines[] = $row['Engine'];
1129
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1130
+							$engines[] = $row['Engine'];
1131
+			}
1071 1132
 		}
1072 1133
 
1073 1134
 		// Done with this now
@@ -1091,8 +1152,7 @@  discard block
 block discarded – undo
1091 1152
 			$replaces['START TRANSACTION;'] = '';
1092 1153
 			$replaces['COMMIT;'] = '';
1093 1154
 		}
1094
-	}
1095
-	else
1155
+	} else
1096 1156
 	{
1097 1157
 		$has_innodb = false;
1098 1158
 	}
@@ -1114,21 +1174,24 @@  discard block
 block discarded – undo
1114 1174
 	foreach ($sql_lines as $count => $line)
1115 1175
 	{
1116 1176
 		// No comments allowed!
1117
-		if (substr(trim($line), 0, 1) != '#')
1118
-			$current_statement .= "\n" . rtrim($line);
1177
+		if (substr(trim($line), 0, 1) != '#') {
1178
+					$current_statement .= "\n" . rtrim($line);
1179
+		}
1119 1180
 
1120 1181
 		// Is this the end of the query string?
1121
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1122
-			continue;
1182
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1183
+					continue;
1184
+		}
1123 1185
 
1124 1186
 		// Does this table already exist?  If so, don't insert more data into it!
1125 1187
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1126 1188
 		{
1127 1189
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1128
-			if (!empty($matches[0]))
1129
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1130
-			else
1131
-				$incontext['sql_results']['insert_dups']++;
1190
+			if (!empty($matches[0])) {
1191
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1192
+			} else {
1193
+							$incontext['sql_results']['insert_dups']++;
1194
+			}
1132 1195
 
1133 1196
 			$current_statement = '';
1134 1197
 			continue;
@@ -1137,8 +1200,9 @@  discard block
 block discarded – undo
1137 1200
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1138 1201
 		{
1139 1202
 			// Use the appropriate function based on the DB type
1140
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1141
-				$db_errorno = $db_type . '_errno';
1203
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1204
+							$db_errorno = $db_type . '_errno';
1205
+			}
1142 1206
 
1143 1207
 			// Error 1050: Table already exists!
1144 1208
 			// @todo Needs to be made better!
@@ -1153,18 +1217,18 @@  discard block
 block discarded – undo
1153 1217
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1154 1218
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1155 1219
 			}
1156
-		}
1157
-		else
1220
+		} else
1158 1221
 		{
1159
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1160
-				$incontext['sql_results']['tables']++;
1161
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1222
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1223
+							$incontext['sql_results']['tables']++;
1224
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1162 1225
 			{
1163 1226
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1164
-				if (!empty($matches[0]))
1165
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1166
-				else
1167
-					$incontext['sql_results']['inserts']++;
1227
+				if (!empty($matches[0])) {
1228
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1229
+				} else {
1230
+									$incontext['sql_results']['inserts']++;
1231
+				}
1168 1232
 			}
1169 1233
 		}
1170 1234
 
@@ -1177,15 +1241,17 @@  discard block
 block discarded – undo
1177 1241
 	// Sort out the context for the SQL.
1178 1242
 	foreach ($incontext['sql_results'] as $key => $number)
1179 1243
 	{
1180
-		if ($number == 0)
1181
-			unset($incontext['sql_results'][$key]);
1182
-		else
1183
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1244
+		if ($number == 0) {
1245
+					unset($incontext['sql_results'][$key]);
1246
+		} else {
1247
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1248
+		}
1184 1249
 	}
1185 1250
 
1186 1251
 	// Make sure UTF will be used globally.
1187
-	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'])))
1188
-		$newSettings[] = array('global_character_set', 'UTF-8');
1252
+	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']))) {
1253
+			$newSettings[] = array('global_character_set', 'UTF-8');
1254
+	}
1189 1255
 
1190 1256
 	// Maybe we can auto-detect better cookie settings?
1191 1257
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1196,16 +1262,20 @@  discard block
 block discarded – undo
1196 1262
 		$globalCookies = false;
1197 1263
 
1198 1264
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1199
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1200
-			$globalCookies = true;
1265
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1266
+					$globalCookies = true;
1267
+		}
1201 1268
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1202
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1203
-			$localCookies = true;
1269
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1270
+					$localCookies = true;
1271
+		}
1204 1272
 
1205
-		if ($globalCookies)
1206
-			$newSettings[] = array('globalCookies', '1');
1207
-		if ($localCookies)
1208
-			$newSettings[] = array('localCookies', '1');
1273
+		if ($globalCookies) {
1274
+					$newSettings[] = array('globalCookies', '1');
1275
+		}
1276
+		if ($localCookies) {
1277
+					$newSettings[] = array('localCookies', '1');
1278
+		}
1209 1279
 	}
1210 1280
 
1211 1281
 	// Are we allowing stat collection?
@@ -1221,32 +1291,36 @@  discard block
 block discarded – undo
1221 1291
 			fwrite($fp, $out);
1222 1292
 
1223 1293
 			$return_data = '';
1224
-			while (!feof($fp))
1225
-				$return_data .= fgets($fp, 128);
1294
+			while (!feof($fp)) {
1295
+							$return_data .= fgets($fp, 128);
1296
+			}
1226 1297
 
1227 1298
 			fclose($fp);
1228 1299
 
1229 1300
 			// Get the unique site ID.
1230 1301
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1231 1302
 
1232
-			if (!empty($ID[1]))
1233
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1303
+			if (!empty($ID[1])) {
1304
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1305
+			}
1234 1306
 		}
1235 1307
 	}
1236 1308
 
1237 1309
 	// Are we enabling SSL?
1238
-	if (!empty($_POST['force_ssl']))
1239
-		$newSettings[] = array('force_ssl', 2);
1310
+	if (!empty($_POST['force_ssl'])) {
1311
+			$newSettings[] = array('force_ssl', 2);
1312
+	}
1240 1313
 
1241 1314
 	// Setting a timezone is required.
1242 1315
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1243 1316
 	{
1244 1317
 		// Get PHP's default timezone, if set
1245 1318
 		$ini_tz = ini_get('date.timezone');
1246
-		if (!empty($ini_tz))
1247
-			$timezone_id = $ini_tz;
1248
-		else
1249
-			$timezone_id = '';
1319
+		if (!empty($ini_tz)) {
1320
+					$timezone_id = $ini_tz;
1321
+		} else {
1322
+					$timezone_id = '';
1323
+		}
1250 1324
 
1251 1325
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1252 1326
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1255,8 +1329,9 @@  discard block
 block discarded – undo
1255 1329
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1256 1330
 		}
1257 1331
 
1258
-		if (date_default_timezone_set($timezone_id))
1259
-			$newSettings[] = array('default_timezone', $timezone_id);
1332
+		if (date_default_timezone_set($timezone_id)) {
1333
+					$newSettings[] = array('default_timezone', $timezone_id);
1334
+		}
1260 1335
 	}
1261 1336
 
1262 1337
 	if (!empty($newSettings))
@@ -1287,16 +1362,18 @@  discard block
 block discarded – undo
1287 1362
 	}
1288 1363
 
1289 1364
 	// MySQL specific stuff
1290
-	if (substr($db_type, 0, 5) != 'mysql')
1291
-		return false;
1365
+	if (substr($db_type, 0, 5) != 'mysql') {
1366
+			return false;
1367
+	}
1292 1368
 
1293 1369
 	// Find database user privileges.
1294 1370
 	$privs = array();
1295 1371
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1296 1372
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1297 1373
 	{
1298
-		if ($row['Privilege'] == 'Alter')
1299
-			$privs[] = $row['Privilege'];
1374
+		if ($row['Privilege'] == 'Alter') {
1375
+					$privs[] = $row['Privilege'];
1376
+		}
1300 1377
 	}
1301 1378
 	$smcFunc['db_free_result']($get_privs);
1302 1379
 
@@ -1326,8 +1403,9 @@  discard block
 block discarded – undo
1326 1403
 	$incontext['continue'] = 1;
1327 1404
 
1328 1405
 	// Skipping?
1329
-	if (!empty($_POST['skip']))
1330
-		return true;
1406
+	if (!empty($_POST['skip'])) {
1407
+			return true;
1408
+	}
1331 1409
 
1332 1410
 	// Need this to check whether we need the database password.
1333 1411
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1340,18 +1418,22 @@  discard block
 block discarded – undo
1340 1418
 	// We need this to properly hash the password for Admin
1341 1419
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1342 1420
 			global $sourcedir;
1343
-			if (function_exists('mb_strtolower'))
1344
-				return mb_strtolower($string, 'UTF-8');
1421
+			if (function_exists('mb_strtolower')) {
1422
+							return mb_strtolower($string, 'UTF-8');
1423
+			}
1345 1424
 			require_once($sourcedir . '/Subs-Charset.php');
1346 1425
 			return utf8_strtolower($string);
1347 1426
 		};
1348 1427
 
1349
-	if (!isset($_POST['username']))
1350
-		$_POST['username'] = '';
1351
-	if (!isset($_POST['email']))
1352
-		$_POST['email'] = '';
1353
-	if (!isset($_POST['server_email']))
1354
-		$_POST['server_email'] = '';
1428
+	if (!isset($_POST['username'])) {
1429
+			$_POST['username'] = '';
1430
+	}
1431
+	if (!isset($_POST['email'])) {
1432
+			$_POST['email'] = '';
1433
+	}
1434
+	if (!isset($_POST['server_email'])) {
1435
+			$_POST['server_email'] = '';
1436
+	}
1355 1437
 
1356 1438
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1357 1439
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1370,8 +1452,9 @@  discard block
 block discarded – undo
1370 1452
 			'admin_group' => 1,
1371 1453
 		)
1372 1454
 	);
1373
-	if ($smcFunc['db_num_rows']($request) != 0)
1374
-		$incontext['skip'] = 1;
1455
+	if ($smcFunc['db_num_rows']($request) != 0) {
1456
+			$incontext['skip'] = 1;
1457
+	}
1375 1458
 	$smcFunc['db_free_result']($request);
1376 1459
 
1377 1460
 	// Trying to create an account?
@@ -1402,8 +1485,9 @@  discard block
 block discarded – undo
1402 1485
 		}
1403 1486
 
1404 1487
 		// Update the webmaster's email?
1405
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1406
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1488
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1489
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1490
+		}
1407 1491
 
1408 1492
 		// Work out whether we're going to have dodgy characters and remove them.
1409 1493
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1426,32 +1510,27 @@  discard block
 block discarded – undo
1426 1510
 			$smcFunc['db_free_result']($result);
1427 1511
 
1428 1512
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1429
-		}
1430
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1513
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1431 1514
 		{
1432 1515
 			// Try the previous step again.
1433 1516
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1434 1517
 			return false;
1435
-		}
1436
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1518
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1437 1519
 		{
1438 1520
 			// Try the previous step again.
1439 1521
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1440 1522
 			return false;
1441
-		}
1442
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1523
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1443 1524
 		{
1444 1525
 			// One step back, this time fill out a proper admin email address.
1445 1526
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1446 1527
 			return false;
1447
-		}
1448
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1528
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1449 1529
 		{
1450 1530
 			// One step back, this time fill out a proper admin email address.
1451 1531
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1452 1532
 			return false;
1453
-		}
1454
-		elseif ($_POST['username'] != '')
1533
+		} elseif ($_POST['username'] != '')
1455 1534
 		{
1456 1535
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1457 1536
 
@@ -1517,17 +1596,19 @@  discard block
 block discarded – undo
1517 1596
 	require_once($sourcedir . '/Subs-Auth.php');
1518 1597
 
1519 1598
 	// Bring a warning over.
1520
-	if (!empty($incontext['account_existed']))
1521
-		$incontext['warning'] = $incontext['account_existed'];
1599
+	if (!empty($incontext['account_existed'])) {
1600
+			$incontext['warning'] = $incontext['account_existed'];
1601
+	}
1522 1602
 
1523
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1524
-		$smcFunc['db_query']('', '
1603
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1604
+			$smcFunc['db_query']('', '
1525 1605
 			SET NAMES {string:db_character_set}',
1526 1606
 			array(
1527 1607
 				'db_character_set' => $db_character_set,
1528 1608
 				'db_error_skip' => true,
1529 1609
 			)
1530 1610
 		);
1611
+	}
1531 1612
 
1532 1613
 	// As track stats is by default enabled let's add some activity.
1533 1614
 	$smcFunc['db_insert']('ignore',
@@ -1548,14 +1629,16 @@  discard block
 block discarded – undo
1548 1629
 	// Only proceed if we can load the data.
1549 1630
 	if ($request)
1550 1631
 	{
1551
-		while ($row = $smcFunc['db_fetch_row']($request))
1552
-			$modSettings[$row[0]] = $row[1];
1632
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1633
+					$modSettings[$row[0]] = $row[1];
1634
+		}
1553 1635
 		$smcFunc['db_free_result']($request);
1554 1636
 	}
1555 1637
 
1556 1638
 	// Automatically log them in ;)
1557
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1558
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1639
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1640
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1641
+	}
1559 1642
 
1560 1643
 	$result = $smcFunc['db_query']('', '
1561 1644
 		SELECT value
@@ -1566,13 +1649,14 @@  discard block
 block discarded – undo
1566 1649
 			'db_error_skip' => true,
1567 1650
 		)
1568 1651
 	);
1569
-	if ($smcFunc['db_num_rows']($result) != 0)
1570
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1652
+	if ($smcFunc['db_num_rows']($result) != 0) {
1653
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1654
+	}
1571 1655
 	$smcFunc['db_free_result']($result);
1572 1656
 
1573
-	if (empty($db_sessions))
1574
-		$_SESSION['admin_time'] = time();
1575
-	else
1657
+	if (empty($db_sessions)) {
1658
+			$_SESSION['admin_time'] = time();
1659
+	} else
1576 1660
 	{
1577 1661
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1578 1662
 
@@ -1596,8 +1680,9 @@  discard block
 block discarded – undo
1596 1680
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1597 1681
 		function($string){
1598 1682
 			global $sourcedir;
1599
-			if (function_exists('mb_strtolower'))
1600
-				return mb_strtolower($string, 'UTF-8');
1683
+			if (function_exists('mb_strtolower')) {
1684
+							return mb_strtolower($string, 'UTF-8');
1685
+			}
1601 1686
 			require_once($sourcedir . '/Subs-Charset.php');
1602 1687
 			return utf8_strtolower($string);
1603 1688
 		};
@@ -1613,8 +1698,9 @@  discard block
 block discarded – undo
1613 1698
 		)
1614 1699
 	);
1615 1700
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1616
-	if ($smcFunc['db_num_rows']($request) > 0)
1617
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1701
+	if ($smcFunc['db_num_rows']($request) > 0) {
1702
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1703
+	}
1618 1704
 	$smcFunc['db_free_result']($request);
1619 1705
 
1620 1706
 	// Now is the perfect time to fetch the SM files.
@@ -1633,8 +1719,9 @@  discard block
 block discarded – undo
1633 1719
 
1634 1720
 	// Check if we need some stupid MySQL fix.
1635 1721
 	$server_version = $smcFunc['db_server_info']();
1636
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1637
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1722
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1723
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1724
+	}
1638 1725
 
1639 1726
 	// Some final context for the template.
1640 1727
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1654,8 +1741,9 @@  discard block
 block discarded – undo
1654 1741
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1655 1742
 
1656 1743
 	// @todo Do we just want to read the file in clean, and split it this way always?
1657
-	if (count($settingsArray) == 1)
1658
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1744
+	if (count($settingsArray) == 1) {
1745
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1746
+	}
1659 1747
 
1660 1748
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1661 1749
 	{
@@ -1670,19 +1758,22 @@  discard block
 block discarded – undo
1670 1758
 			continue;
1671 1759
 		}
1672 1760
 
1673
-		if (trim($settingsArray[$i]) == '?' . '>')
1674
-			$settingsArray[$i] = '';
1761
+		if (trim($settingsArray[$i]) == '?' . '>') {
1762
+					$settingsArray[$i] = '';
1763
+		}
1675 1764
 
1676 1765
 		// Don't trim or bother with it if it's not a variable.
1677
-		if (substr($settingsArray[$i], 0, 1) != '$')
1678
-			continue;
1766
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1767
+					continue;
1768
+		}
1679 1769
 
1680 1770
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1681 1771
 
1682
-		foreach ($vars as $var => $val)
1683
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1772
+		foreach ($vars as $var => $val) {
1773
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1684 1774
 			{
1685 1775
 				$comment = strstr($settingsArray[$i], '#');
1776
+		}
1686 1777
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1687 1778
 				unset($vars[$var]);
1688 1779
 			}
@@ -1692,36 +1783,41 @@  discard block
 block discarded – undo
1692 1783
 	if (!empty($vars))
1693 1784
 	{
1694 1785
 		$settingsArray[$i++] = '';
1695
-		foreach ($vars as $var => $val)
1696
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1786
+		foreach ($vars as $var => $val) {
1787
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1788
+		}
1697 1789
 	}
1698 1790
 
1699 1791
 	// Blank out the file - done to fix a oddity with some servers.
1700 1792
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1701
-	if (!$fp)
1702
-		return false;
1793
+	if (!$fp) {
1794
+			return false;
1795
+	}
1703 1796
 	fclose($fp);
1704 1797
 
1705 1798
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1706 1799
 
1707 1800
 	// Gotta have one of these ;)
1708
-	if (trim($settingsArray[0]) != '<?php')
1709
-		fwrite($fp, "<?php\n");
1801
+	if (trim($settingsArray[0]) != '<?php') {
1802
+			fwrite($fp, "<?php\n");
1803
+	}
1710 1804
 
1711 1805
 	$lines = count($settingsArray);
1712 1806
 	for ($i = 0; $i < $lines - 1; $i++)
1713 1807
 	{
1714 1808
 		// Don't just write a bunch of blank lines.
1715
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1716
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1809
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1810
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1811
+		}
1717 1812
 	}
1718 1813
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1719 1814
 	fclose($fp);
1720 1815
 
1721 1816
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1722 1817
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1723
-	if (function_exists('opcache_invalidate'))
1724
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1818
+	if (function_exists('opcache_invalidate')) {
1819
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1820
+	}
1725 1821
 
1726 1822
 	return true;
1727 1823
 }
@@ -1746,9 +1842,9 @@  discard block
 block discarded – undo
1746 1842
 	SecFilterScanPOST Off
1747 1843
 </IfModule>';
1748 1844
 
1749
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1750
-		return true;
1751
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1845
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1846
+			return true;
1847
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1752 1848
 	{
1753 1849
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1754 1850
 
@@ -1760,29 +1856,28 @@  discard block
 block discarded – undo
1760 1856
 				fwrite($ht_handle, $htaccess_addition);
1761 1857
 				fclose($ht_handle);
1762 1858
 				return true;
1859
+			} else {
1860
+							return false;
1763 1861
 			}
1764
-			else
1765
-				return false;
1862
+		} else {
1863
+					return true;
1766 1864
 		}
1767
-		else
1768
-			return true;
1769
-	}
1770
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1771
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1772
-	elseif (is_writable(dirname(__FILE__)))
1865
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1866
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1867
+	} elseif (is_writable(dirname(__FILE__)))
1773 1868
 	{
1774 1869
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1775 1870
 		{
1776 1871
 			fwrite($ht_handle, $htaccess_addition);
1777 1872
 			fclose($ht_handle);
1778 1873
 			return true;
1874
+		} else {
1875
+					return false;
1779 1876
 		}
1780
-		else
1877
+	} else {
1781 1878
 			return false;
1782 1879
 	}
1783
-	else
1784
-		return false;
1785
-}
1880
+	}
1786 1881
 
1787 1882
 function template_install_above()
1788 1883
 {
@@ -1820,9 +1915,10 @@  discard block
 block discarded – undo
1820 1915
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1821 1916
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1822 1917
 
1823
-		foreach ($incontext['detected_languages'] as $lang => $name)
1824
-			echo '
1918
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1919
+					echo '
1825 1920
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1921
+		}
1826 1922
 
1827 1923
 		echo '
1828 1924
 								</select>
@@ -1842,9 +1938,10 @@  discard block
 block discarded – undo
1842 1938
 						<h2>', $txt['upgrade_progress'], '</h2>
1843 1939
 						<ul>';
1844 1940
 
1845
-	foreach ($incontext['steps'] as $num => $step)
1846
-		echo '
1941
+	foreach ($incontext['steps'] as $num => $step) {
1942
+			echo '
1847 1943
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1944
+	}
1848 1945
 
1849 1946
 	echo '
1850 1947
 						</ul>
@@ -1869,20 +1966,23 @@  discard block
 block discarded – undo
1869 1966
 		echo '
1870 1967
 								<div>';
1871 1968
 
1872
-		if (!empty($incontext['continue']))
1873
-			echo '
1969
+		if (!empty($incontext['continue'])) {
1970
+					echo '
1874 1971
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1875
-		if (!empty($incontext['skip']))
1876
-			echo '
1972
+		}
1973
+		if (!empty($incontext['skip'])) {
1974
+					echo '
1877 1975
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1976
+		}
1878 1977
 		echo '
1879 1978
 								</div>';
1880 1979
 	}
1881 1980
 
1882 1981
 	// Show the closing form tag and other data only if not in the last step
1883
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1884
-		echo '
1982
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1983
+			echo '
1885 1984
 							</form>';
1985
+	}
1886 1986
 
1887 1987
 	echo '
1888 1988
 						</div>
@@ -1917,13 +2017,15 @@  discard block
 block discarded – undo
1917 2017
 		</div>';
1918 2018
 
1919 2019
 	// Show the warnings, or not.
1920
-	if (template_warning_divs())
1921
-		echo '
2020
+	if (template_warning_divs()) {
2021
+			echo '
1922 2022
 		<h3>', $txt['install_all_lovely'], '</h3>';
2023
+	}
1923 2024
 
1924 2025
 	// Say we want the continue button!
1925
-	if (empty($incontext['error']))
1926
-		$incontext['continue'] = 1;
2026
+	if (empty($incontext['error'])) {
2027
+			$incontext['continue'] = 1;
2028
+	}
1927 2029
 
1928 2030
 	// For the latest version stuff.
1929 2031
 	echo '
@@ -1957,8 +2059,8 @@  discard block
 block discarded – undo
1957 2059
 	global $txt, $incontext;
1958 2060
 
1959 2061
 	// Errors are very serious..
1960
-	if (!empty($incontext['error']))
1961
-		echo '
2062
+	if (!empty($incontext['error'])) {
2063
+			echo '
1962 2064
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1963 2065
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1964 2066
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1966,9 +2068,10 @@  discard block
 block discarded – undo
1966 2068
 				', $incontext['error'], '
1967 2069
 			</div>
1968 2070
 		</div>';
2071
+	}
1969 2072
 	// A warning message?
1970
-	elseif (!empty($incontext['warning']))
1971
-		echo '
2073
+	elseif (!empty($incontext['warning'])) {
2074
+			echo '
1972 2075
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1973 2076
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1974 2077
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1976,6 +2079,7 @@  discard block
 block discarded – undo
1976 2079
 				', $incontext['warning'], '
1977 2080
 			</div>
1978 2081
 		</div>';
2082
+	}
1979 2083
 
1980 2084
 	return empty($incontext['error']) && empty($incontext['warning']);
1981 2085
 }
@@ -1991,27 +2095,30 @@  discard block
 block discarded – undo
1991 2095
 			<li>', $incontext['failed_files']), '</li>
1992 2096
 		</ul>';
1993 2097
 
1994
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
1995
-		echo '
2098
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2099
+			echo '
1996 2100
 		<hr>
1997 2101
 		<p>', $txt['chmod_linux_info'], '</p>
1998 2102
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2103
+	}
1999 2104
 
2000 2105
 	// This is serious!
2001
-	if (!template_warning_divs())
2002
-		return;
2106
+	if (!template_warning_divs()) {
2107
+			return;
2108
+	}
2003 2109
 
2004 2110
 	echo '
2005 2111
 		<hr>
2006 2112
 		<p>', $txt['ftp_setup_info'], '</p>';
2007 2113
 
2008
-	if (!empty($incontext['ftp_errors']))
2009
-		echo '
2114
+	if (!empty($incontext['ftp_errors'])) {
2115
+			echo '
2010 2116
 		<div class="error_message">
2011 2117
 			', $txt['error_ftp_no_connect'], '<br><br>
2012 2118
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2013 2119
 		</div>
2014 2120
 		<br>';
2121
+	}
2015 2122
 
2016 2123
 	echo '
2017 2124
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2071,17 +2178,17 @@  discard block
 block discarded – undo
2071 2178
 				<td>
2072 2179
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2073 2180
 
2074
-	foreach ($incontext['supported_databases'] as $key => $db)
2075
-			echo '
2181
+	foreach ($incontext['supported_databases'] as $key => $db) {
2182
+				echo '
2076 2183
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2184
+	}
2077 2185
 
2078 2186
 	echo '
2079 2187
 					</select>
2080 2188
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2081 2189
 				</td>
2082 2190
 			</tr>';
2083
-	}
2084
-	else
2191
+	} else
2085 2192
 	{
2086 2193
 		echo '
2087 2194
 			<tr style="display: none;">
@@ -2273,9 +2380,10 @@  discard block
 block discarded – undo
2273 2380
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2274 2381
 				<ul>';
2275 2382
 
2276
-		foreach ($incontext['failures'] as $line => $fail)
2277
-			echo '
2383
+		foreach ($incontext['failures'] as $line => $fail) {
2384
+					echo '
2278 2385
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2386
+		}
2279 2387
 
2280 2388
 		echo '
2281 2389
 				</ul>';
@@ -2336,15 +2444,16 @@  discard block
 block discarded – undo
2336 2444
 			</tr>
2337 2445
 		</table>';
2338 2446
 
2339
-	if ($incontext['require_db_confirm'])
2340
-		echo '
2447
+	if ($incontext['require_db_confirm']) {
2448
+			echo '
2341 2449
 		<h2>', $txt['user_settings_database'], '</h2>
2342 2450
 		<p>', $txt['user_settings_database_info'], '</p>
2343 2451
 
2344 2452
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2345 2453
 			<input type="password" name="password3" size="30" class="input_password" />
2346 2454
 		</div>';
2347
-}
2455
+	}
2456
+	}
2348 2457
 
2349 2458
 // Tell them it's done, and to delete.
2350 2459
 function template_delete_install()
@@ -2357,14 +2466,15 @@  discard block
 block discarded – undo
2357 2466
 	template_warning_divs();
2358 2467
 
2359 2468
 	// Install directory still writable?
2360
-	if ($incontext['dir_still_writable'])
2361
-		echo '
2469
+	if ($incontext['dir_still_writable']) {
2470
+			echo '
2362 2471
 		<em>', $txt['still_writable'], '</em><br>
2363 2472
 		<br>';
2473
+	}
2364 2474
 
2365 2475
 	// Don't show the box if it's like 99% sure it won't work :P.
2366
-	if ($incontext['probably_delete_install'])
2367
-		echo '
2476
+	if ($incontext['probably_delete_install']) {
2477
+			echo '
2368 2478
 		<div style="margin: 1ex; font-weight: bold;">
2369 2479
 			<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>
2370 2480
 		</div>
@@ -2380,6 +2490,7 @@  discard block
 block discarded – undo
2380 2490
 			}
2381 2491
 		</script>
2382 2492
 		<br>';
2493
+	}
2383 2494
 
2384 2495
 	echo '
2385 2496
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +35 added lines, -24 removed lines patch added patch discarded remove patch
@@ -32,16 +32,18 @@  discard block
 block discarded – undo
32 32
 ob_start();
33 33
 
34 34
 // Do some cleaning, just in case.
35
-foreach (array('db_character_set', 'cachedir') as $variable)
35
+foreach (array('db_character_set', 'cachedir') as $variable) {
36 36
 	if (isset($GLOBALS[$variable]))
37 37
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
38
+}
38 39
 
39 40
 // Load the settings...
40 41
 require_once(dirname(__FILE__) . '/Settings.php');
41 42
 
42 43
 // Make absolutely sure the cache directory is defined.
43
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
44
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
44 45
 	$cachedir = $boarddir . '/cache';
46
+}
45 47
 
46 48
 // Without those we can't go anywhere
47 49
 require_once($sourcedir . '/QueryString.php');
@@ -51,8 +53,9 @@  discard block
 block discarded – undo
51 53
 require_once($sourcedir . '/Load.php');
52 54
 
53 55
 // If $maintenance is set specifically to 2, then we're upgrading or something.
54
-if (!empty($maintenance) && $maintenance == 2)
56
+if (!empty($maintenance) && $maintenance == 2) {
55 57
 	display_maintenance_message();
58
+}
56 59
 
57 60
 // Create a variable to store some SMF specific functions in.
58 61
 $smcFunc = array();
@@ -67,8 +70,9 @@  discard block
 block discarded – undo
67 70
 cleanRequest();
68 71
 
69 72
 // Seed the random generator.
70
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
73
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
71 74
 	smf_seed_generator();
75
+}
72 76
 
73 77
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
74 78
 if (isset($_GET['scheduled']))
@@ -88,9 +92,9 @@  discard block
 block discarded – undo
88 92
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
89 93
 {
90 94
 	// If zlib is being used, turn off output compression.
91
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
92
-		$modSettings['enableCompressedOutput'] = '0';
93
-	else
95
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
96
+			$modSettings['enableCompressedOutput'] = '0';
97
+	} else
94 98
 	{
95 99
 		ob_end_clean();
96 100
 		ob_start('ob_gzhandler');
@@ -182,18 +186,21 @@  discard block
 block discarded – undo
182 186
 	loadPermissions();
183 187
 
184 188
 	// Attachments don't require the entire theme to be loaded.
185
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
186
-		detectBrowser();
189
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
190
+			detectBrowser();
191
+	}
187 192
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
188
-	else
189
-		loadTheme();
193
+	else {
194
+			loadTheme();
195
+	}
190 196
 
191 197
 	// Check if the user should be disallowed access.
192 198
 	is_not_banned();
193 199
 
194 200
 	// If we are in a topic and don't have permission to approve it then duck out now.
195
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
196
-		fatal_lang_error('not_a_topic', false);
201
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
202
+			fatal_lang_error('not_a_topic', false);
203
+	}
197 204
 
198 205
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
199 206
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 		writeLog();
205 212
 
206 213
 		// Track forum statistics and hits...?
207
-		if (!empty($modSettings['hitStats']))
208
-			trackStats(array('hits' => '+'));
214
+		if (!empty($modSettings['hitStats'])) {
215
+					trackStats(array('hits' => '+'));
216
+		}
209 217
 	}
210 218
 	unset($no_stat_actions);
211 219
 
@@ -219,13 +227,14 @@  discard block
 block discarded – undo
219 227
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
220 228
 		}
221 229
 		// Don't even try it, sonny.
222
-		else
223
-			return 'InMaintenance';
230
+		else {
231
+					return 'InMaintenance';
232
+		}
224 233
 	}
225 234
 	// If guest access is off, a guest can only do one of the very few following actions.
226
-	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'))))
227
-		return 'KickGuest';
228
-	elseif (empty($_REQUEST['action']))
235
+	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')))) {
236
+			return 'KickGuest';
237
+	} elseif (empty($_REQUEST['action']))
229 238
 	{
230 239
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
231 240
 		if (empty($board) && empty($topic))
@@ -239,8 +248,9 @@  discard block
 block discarded – undo
239 248
 
240 249
 				$call = call_helper($defaultAction, true);
241 250
 
242
-				if (!empty($call))
243
-					return $call;
251
+				if (!empty($call)) {
252
+									return $call;
253
+				}
244 254
 			}
245 255
 
246 256
 			// No default action huh? then go to our good old BoardIndex.
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 
371 381
 			$call = call_helper($fallbackAction, true);
372 382
 
373
-			if (!empty($call))
374
-				return $call;
383
+			if (!empty($call)) {
384
+							return $call;
385
+			}
375 386
 		}
376 387
 
377 388
 		// No fallback action, huh?
Please login to merge, or discard this patch.
Sources/Drafts.php 1 patch
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
  *
174 174
  * @param string $post_errors A string of info about errors encountered trying to save this draft
175 175
  * @param array $recipientList An array of data about who this PM is being sent to
176
- * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise
176
+ * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise
177 177
  */
178 178
 function SavePMDraft(&$post_errors, $recipientList)
179 179
 {
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
  *
389 389
  * @param int $id_draft The ID of the draft to delete
390 390
  * @param boolean $check Whether or not to check that the draft belongs to the current user
391
- * @return boolean False if it couldn't be deleted (doesn't return anything otherwise)
391
+ * @return false|null False if it couldn't be deleted (doesn't return anything otherwise)
392 392
  */
393 393
 function DeleteDraft($id_draft, $check = true)
394 394
 {
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
  * @param int $member_id ID of the member to show drafts for
423 423
  * @param boolean|integer If $type is 1, this can be set to only load drafts for posts in the specific topic
424 424
  * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts
425
- * @return boolean False if the drafts couldn't be loaded, nothing otherwise
425
+ * @return false|null False if the drafts couldn't be loaded, nothing otherwise
426 426
  */
427 427
 function ShowDrafts($member_id, $topic = false, $draft_type = 0)
428 428
 {
Please login to merge, or discard this patch.