Completed
Push — release-2.1 ( 15f485...ae1be0 )
by Mathias
08:27
created
Sources/CacheAPI-apc.php 1 patch
Braces   +12 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	{
28 29
 		$supported = function_exists('apc_fetch') && function_exists('apc_store');
29 30
 
30
-		if ($test)
31
-			return $supported;
31
+		if ($test) {
32
+					return $supported;
33
+		}
32 34
 		return parent::isSupported() && $supported;
33 35
 	}
34 36
 
@@ -50,10 +52,11 @@  discard block
 block discarded – undo
50 52
 		$key = $this->prefix . strtr($key, ':/', '-_');
51 53
 
52 54
 		// An extended key is needed to counteract a bug in APC.
53
-		if ($value === null)
54
-			return apc_delete($key . 'smf');
55
-		else
56
-			return apc_store($key . 'smf', $value, $ttl);
55
+		if ($value === null) {
56
+					return apc_delete($key . 'smf');
57
+		} else {
58
+					return apc_store($key . 'smf', $value, $ttl);
59
+		}
57 60
 	}
58 61
 
59 62
 	/**
@@ -67,9 +70,9 @@  discard block
 block discarded – undo
67 70
 			// Always returns true.
68 71
 			apc_clear_cache('user');
69 72
 			apc_clear_cache('system');
73
+		} elseif ($type === 'user') {
74
+					apc_clear_cache('user');
70 75
 		}
71
-		elseif ($type === 'user')
72
-			apc_clear_cache('user');
73 76
 
74 77
 		$this->invalidateCache();
75 78
 		return true;
Please login to merge, or discard this patch.
Sources/ReCaptcha/ReCaptcha.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -31,67 +31,67 @@
 block discarded – undo
31 31
  */
32 32
 class ReCaptcha
33 33
 {
34
-    /**
35
-     * Version of this client library.
36
-     * @const string
37
-     */
38
-    const VERSION = 'php_1.1.2';
34
+	/**
35
+	 * Version of this client library.
36
+	 * @const string
37
+	 */
38
+	const VERSION = 'php_1.1.2';
39 39
 
40
-    /**
41
-     * Shared secret for the site.
42
-     * @var string
43
-     */
44
-    private $secret;
40
+	/**
41
+	 * Shared secret for the site.
42
+	 * @var string
43
+	 */
44
+	private $secret;
45 45
 
46
-    /**
47
-     * Method used to communicate  with service. Defaults to POST request.
48
-     * @var RequestMethod
49
-     */
50
-    private $requestMethod;
46
+	/**
47
+	 * Method used to communicate  with service. Defaults to POST request.
48
+	 * @var RequestMethod
49
+	 */
50
+	private $requestMethod;
51 51
 
52
-    /**
53
-     * Create a configured instance to use the reCAPTCHA service.
54
-     *
55
-     * @param string $secret shared secret between site and reCAPTCHA server.
56
-     * @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
57
-     */
58
-    public function __construct($secret, RequestMethod $requestMethod = null)
59
-    {
60
-        if (empty($secret)) {
61
-            throw new \RuntimeException('No secret provided');
62
-        }
52
+	/**
53
+	 * Create a configured instance to use the reCAPTCHA service.
54
+	 *
55
+	 * @param string $secret shared secret between site and reCAPTCHA server.
56
+	 * @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
57
+	 */
58
+	public function __construct($secret, RequestMethod $requestMethod = null)
59
+	{
60
+		if (empty($secret)) {
61
+			throw new \RuntimeException('No secret provided');
62
+		}
63 63
 
64
-        if (!is_string($secret)) {
65
-            throw new \RuntimeException('The provided secret must be a string');
66
-        }
64
+		if (!is_string($secret)) {
65
+			throw new \RuntimeException('The provided secret must be a string');
66
+		}
67 67
 
68
-        $this->secret = $secret;
68
+		$this->secret = $secret;
69 69
 
70
-        if (!is_null($requestMethod)) {
71
-            $this->requestMethod = $requestMethod;
72
-        } else {
73
-            $this->requestMethod = new RequestMethod\Post();
74
-        }
75
-    }
70
+		if (!is_null($requestMethod)) {
71
+			$this->requestMethod = $requestMethod;
72
+		} else {
73
+			$this->requestMethod = new RequestMethod\Post();
74
+		}
75
+	}
76 76
 
77
-    /**
78
-     * Calls the reCAPTCHA siteverify API to verify whether the user passes
79
-     * CAPTCHA test.
80
-     *
81
-     * @param string $response The value of 'g-recaptcha-response' in the submitted form.
82
-     * @param string $remoteIp The end user's IP address.
83
-     * @return Response Response from the service.
84
-     */
85
-    public function verify($response, $remoteIp = null)
86
-    {
87
-        // Discard empty solution submissions
88
-        if (empty($response)) {
89
-            $recaptchaResponse = new Response(false, array('missing-input-response'));
90
-            return $recaptchaResponse;
91
-        }
77
+	/**
78
+	 * Calls the reCAPTCHA siteverify API to verify whether the user passes
79
+	 * CAPTCHA test.
80
+	 *
81
+	 * @param string $response The value of 'g-recaptcha-response' in the submitted form.
82
+	 * @param string $remoteIp The end user's IP address.
83
+	 * @return Response Response from the service.
84
+	 */
85
+	public function verify($response, $remoteIp = null)
86
+	{
87
+		// Discard empty solution submissions
88
+		if (empty($response)) {
89
+			$recaptchaResponse = new Response(false, array('missing-input-response'));
90
+			return $recaptchaResponse;
91
+		}
92 92
 
93
-        $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
94
-        $rawResponse = $this->requestMethod->submit($params);
95
-        return Response::fromJson($rawResponse);
96
-    }
93
+		$params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
94
+		$rawResponse = $this->requestMethod->submit($params);
95
+		return Response::fromJson($rawResponse);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Sources/Profile.php 1 patch
Braces   +155 added lines, -118 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * The main designating function for modifying profiles. Loads up info, determins what to do, etc.
@@ -29,18 +30,21 @@  discard block
 block discarded – undo
29 30
 	global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc;
30 31
 
31 32
 	// Don't reload this as we may have processed error strings.
32
-	if (empty($post_errors))
33
-		loadLanguage('Profile+Drafts');
33
+	if (empty($post_errors)) {
34
+			loadLanguage('Profile+Drafts');
35
+	}
34 36
 	loadTemplate('Profile');
35 37
 
36 38
 	require_once($sourcedir . '/Subs-Menu.php');
37 39
 
38 40
 	// Did we get the user by name...
39
-	if (isset($_REQUEST['user']))
40
-		$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
41
+	if (isset($_REQUEST['user'])) {
42
+			$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
43
+	}
41 44
 	// ... or by id_member?
42
-	elseif (!empty($_REQUEST['u']))
43
-		$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
45
+	elseif (!empty($_REQUEST['u'])) {
46
+			$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
47
+	}
44 48
 	// If it was just ?action=profile, edit your own profile, but only if you're not a guest.
45 49
 	else
46 50
 	{
@@ -50,8 +54,9 @@  discard block
 block discarded – undo
50 54
 	}
51 55
 
52 56
 	// Check if loadMemberData() has returned a valid result.
53
-	if (!$memberResult)
54
-		fatal_lang_error('not_a_user', false, 404);
57
+	if (!$memberResult) {
58
+			fatal_lang_error('not_a_user', false, 404);
59
+	}
55 60
 
56 61
 	// If all went well, we have a valid member ID!
57 62
 	list ($memID) = $memberResult;
@@ -67,8 +72,9 @@  discard block
 block discarded – undo
67 72
 
68 73
 	// Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
69 74
 	// And we care about what the current user can do, not what the user whose profile it is.
70
-	if ($user_info['mod_cache']['gq'] != '0=1')
71
-		$user_info['permissions'][] = 'approve_group_requests';
75
+	if ($user_info['mod_cache']['gq'] != '0=1') {
76
+			$user_info['permissions'][] = 'approve_group_requests';
77
+	}
72 78
 
73 79
 	// If paid subscriptions are enabled, make sure we actually have at least one subscription available...
74 80
 	$context['subs_available'] = false;
@@ -436,21 +442,25 @@  discard block
 block discarded – undo
436 442
 		foreach ($section['areas'] as $area_id => $area)
437 443
 		{
438 444
 			// If it said no permissions that meant it wasn't valid!
439
-			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
440
-				$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
445
+			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) {
446
+							$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
447
+			}
441 448
 			// Otherwise pick the right set.
442
-			else
443
-				$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
449
+			else {
450
+							$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
451
+			}
444 452
 
445 453
 			// Password required in most cases
446
-			if (!empty($area['password']))
447
-				$context['password_areas'][] = $area_id;
454
+			if (!empty($area['password'])) {
455
+							$context['password_areas'][] = $area_id;
456
+			}
448 457
 		}
449 458
 	}
450 459
 
451 460
 	// Is there an updated message to show?
452
-	if (isset($_GET['updated']))
453
-		$context['profile_updated'] = $txt['profile_updated_own'];
461
+	if (isset($_GET['updated'])) {
462
+			$context['profile_updated'] = $txt['profile_updated_own'];
463
+	}
454 464
 
455 465
 	// Set a few options for the menu.
456 466
 	$menuOptions = array(
@@ -465,8 +475,9 @@  discard block
 block discarded – undo
465 475
 	$profile_include_data = createMenu($profile_areas, $menuOptions);
466 476
 
467 477
 	// No menu means no access.
468
-	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
469
-		fatal_lang_error('no_access', false);
478
+	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) {
479
+			fatal_lang_error('no_access', false);
480
+	}
470 481
 
471 482
 	// Make a note of the Unique ID for this menu.
472 483
 	$context['profile_menu_id'] = $context['max_menu_id'];
@@ -492,8 +503,9 @@  discard block
 block discarded – undo
492 503
 			if ($current_area == $area_id)
493 504
 			{
494 505
 				// This can't happen - but is a security check.
495
-				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
496
-					fatal_lang_error('no_access', false);
506
+				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) {
507
+									fatal_lang_error('no_access', false);
508
+				}
497 509
 
498 510
 				// Are we saving data in a valid area?
499 511
 				if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
@@ -512,12 +524,14 @@  discard block
 block discarded – undo
512 524
 				}
513 525
 
514 526
 				// Does this require session validating?
515
-				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
516
-					$security_checks['validate'] = true;
527
+				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) {
528
+									$security_checks['validate'] = true;
529
+				}
517 530
 
518 531
 				// Permissions for good measure.
519
-				if (!empty($profile_include_data['permission']))
520
-					$security_checks['permission'] = $profile_include_data['permission'];
532
+				if (!empty($profile_include_data['permission'])) {
533
+									$security_checks['permission'] = $profile_include_data['permission'];
534
+				}
521 535
 
522 536
 				// Either way got something.
523 537
 				$found_area = true;
@@ -526,21 +540,26 @@  discard block
 block discarded – undo
526 540
 	}
527 541
 
528 542
 	// Oh dear, some serious security lapse is going on here... we'll put a stop to that!
529
-	if (!$found_area)
530
-		fatal_lang_error('no_access', false);
543
+	if (!$found_area) {
544
+			fatal_lang_error('no_access', false);
545
+	}
531 546
 
532 547
 	// Release this now.
533 548
 	unset($profile_areas);
534 549
 
535 550
 	// Now the context is setup have we got any security checks to carry out additional to that above?
536
-	if (isset($security_checks['session']))
537
-		checkSession($security_checks['session']);
538
-	if (isset($security_checks['validate']))
539
-		validateSession();
540
-	if (isset($security_checks['validateToken']))
541
-		validateToken($token_name, $token_type);
542
-	if (isset($security_checks['permission']))
543
-		isAllowedTo($security_checks['permission']);
551
+	if (isset($security_checks['session'])) {
552
+			checkSession($security_checks['session']);
553
+	}
554
+	if (isset($security_checks['validate'])) {
555
+			validateSession();
556
+	}
557
+	if (isset($security_checks['validateToken'])) {
558
+			validateToken($token_name, $token_type);
559
+	}
560
+	if (isset($security_checks['permission'])) {
561
+			isAllowedTo($security_checks['permission']);
562
+	}
544 563
 
545 564
 	// Create a token if needed.
546 565
 	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
@@ -550,8 +569,9 @@  discard block
 block discarded – undo
550 569
 	}
551 570
 
552 571
 	// File to include?
553
-	if (isset($profile_include_data['file']))
554
-		require_once($sourcedir . '/' . $profile_include_data['file']);
572
+	if (isset($profile_include_data['file'])) {
573
+			require_once($sourcedir . '/' . $profile_include_data['file']);
574
+	}
555 575
 
556 576
 	// Build the link tree.
557 577
 	$context['linktree'][] = array(
@@ -559,17 +579,19 @@  discard block
 block discarded – undo
559 579
 		'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
560 580
 	);
561 581
 
562
-	if (!empty($profile_include_data['label']))
563
-		$context['linktree'][] = array(
582
+	if (!empty($profile_include_data['label'])) {
583
+			$context['linktree'][] = array(
564 584
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
565 585
 			'name' => $profile_include_data['label'],
566 586
 		);
587
+	}
567 588
 
568
-	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
569
-		$context['linktree'][] = array(
589
+	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) {
590
+			$context['linktree'][] = array(
570 591
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
571 592
 			'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
572 593
 		);
594
+	}
573 595
 
574 596
 	// Set the template for this area and add the profile layer.
575 597
 	$context['sub_template'] = $profile_include_data['function'];
@@ -595,12 +617,14 @@  discard block
 block discarded – undo
595 617
 		if ($check_password)
596 618
 		{
597 619
 			// Check to ensure we're forcing SSL for authentication
598
-			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
599
-				fatal_lang_error('login_ssl_required');
620
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
621
+							fatal_lang_error('login_ssl_required');
622
+			}
600 623
 
601 624
 			// You didn't even enter a password!
602
-			if (trim($_POST['oldpasswrd']) == '')
603
-				$post_errors[] = 'no_password';
625
+			if (trim($_POST['oldpasswrd']) == '') {
626
+							$post_errors[] = 'no_password';
627
+			}
604 628
 
605 629
 			// Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
606 630
 			$_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
@@ -609,33 +633,35 @@  discard block
 block discarded – undo
609 633
 			$good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
610 634
 
611 635
 			// Bad password!!!
612
-			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd']))
613
-				$post_errors[] = 'bad_password';
636
+			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) {
637
+							$post_errors[] = 'bad_password';
638
+			}
614 639
 
615 640
 			// Warn other elements not to jump the gun and do custom changes!
616
-			if (in_array('bad_password', $post_errors))
617
-				$context['password_auth_failed'] = true;
641
+			if (in_array('bad_password', $post_errors)) {
642
+							$context['password_auth_failed'] = true;
643
+			}
618 644
 		}
619 645
 
620 646
 		// Change the IP address in the database.
621
-		if ($context['user']['is_owner'])
622
-			$profile_vars['member_ip'] = $user_info['ip'];
647
+		if ($context['user']['is_owner']) {
648
+					$profile_vars['member_ip'] = $user_info['ip'];
649
+		}
623 650
 
624 651
 		// Now call the sub-action function...
625 652
 		if ($current_area == 'activateaccount')
626 653
 		{
627
-			if (empty($post_errors))
628
-				activateAccount($memID);
629
-		}
630
-		elseif ($current_area == 'deleteaccount')
654
+			if (empty($post_errors)) {
655
+							activateAccount($memID);
656
+			}
657
+		} elseif ($current_area == 'deleteaccount')
631 658
 		{
632 659
 			if (empty($post_errors))
633 660
 			{
634 661
 				deleteAccount2($memID);
635 662
 				redirectexit();
636 663
 			}
637
-		}
638
-		elseif ($current_area == 'groupmembership' && empty($post_errors))
664
+		} elseif ($current_area == 'groupmembership' && empty($post_errors))
639 665
 		{
640 666
 			$msg = groupMembership2($profile_vars, $post_errors, $memID);
641 667
 
@@ -646,10 +672,9 @@  discard block
 block discarded – undo
646 672
 		elseif ($current_area == 'authentication')
647 673
 		{
648 674
 			authentication($memID, true);
649
-		}
650
-		elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
651
-			saveProfileFields();
652
-		else
675
+		} elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) {
676
+					saveProfileFields();
677
+		} else
653 678
 		{
654 679
 			$force_redirect = true;
655 680
 			// Ensure we include this.
@@ -665,34 +690,36 @@  discard block
 block discarded – undo
665 690
 			// Load the language file so we can give a nice explanation of the errors.
666 691
 			loadLanguage('Errors');
667 692
 			$context['post_errors'] = $post_errors;
668
-		}
669
-		elseif (!empty($profile_vars))
693
+		} elseif (!empty($profile_vars))
670 694
 		{
671 695
 			// If we've changed the password, notify any integration that may be listening in.
672
-			if (isset($profile_vars['passwd']))
673
-				call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
696
+			if (isset($profile_vars['passwd'])) {
697
+							call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
698
+			}
674 699
 
675 700
 			updateMemberData($memID, $profile_vars);
676 701
 
677 702
 			// What if this is the newest member?
678
-			if ($modSettings['latestMember'] == $memID)
679
-				updateStats('member');
680
-			elseif (isset($profile_vars['real_name']))
681
-				updateSettings(array('memberlist_updated' => time()));
703
+			if ($modSettings['latestMember'] == $memID) {
704
+							updateStats('member');
705
+			} elseif (isset($profile_vars['real_name'])) {
706
+							updateSettings(array('memberlist_updated' => time()));
707
+			}
682 708
 
683 709
 			// If the member changed his/her birthdate, update calendar statistics.
684
-			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
685
-				updateSettings(array(
710
+			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) {
711
+							updateSettings(array(
686 712
 					'calendar_updated' => time(),
687 713
 				));
714
+			}
688 715
 
689 716
 			// Anything worth logging?
690 717
 			if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
691 718
 			{
692 719
 				$log_changes = array();
693 720
 				require_once($sourcedir . '/Logging.php');
694
-				foreach ($context['log_changes'] as $k => $v)
695
-					$log_changes[] = array(
721
+				foreach ($context['log_changes'] as $k => $v) {
722
+									$log_changes[] = array(
696 723
 						'action' => $k,
697 724
 						'log_type' => 'user',
698 725
 						'extra' => array_merge($v, array(
@@ -700,14 +727,16 @@  discard block
 block discarded – undo
700 727
 							'member_affected' => $memID,
701 728
 						)),
702 729
 					);
730
+				}
703 731
 
704 732
 				logActions($log_changes);
705 733
 			}
706 734
 
707 735
 			// Have we got any post save functions to execute?
708
-			if (!empty($context['profile_execute_on_save']))
709
-				foreach ($context['profile_execute_on_save'] as $saveFunc)
736
+			if (!empty($context['profile_execute_on_save'])) {
737
+							foreach ($context['profile_execute_on_save'] as $saveFunc)
710 738
 					$saveFunc();
739
+			}
711 740
 
712 741
 			// Let them know it worked!
713 742
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
@@ -721,27 +750,31 @@  discard block
 block discarded – undo
721 750
 	if (!empty($post_errors))
722 751
 	{
723 752
 		// Set all the errors so the template knows what went wrong.
724
-		foreach ($post_errors as $error_type)
725
-			$context['modify_error'][$error_type] = true;
753
+		foreach ($post_errors as $error_type) {
754
+					$context['modify_error'][$error_type] = true;
755
+		}
726 756
 	}
727 757
 	// If it's you then we should redirect upon save.
728
-	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
729
-		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
730
-	elseif (!empty($force_redirect))
731
-		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
758
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) {
759
+			redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
760
+	} elseif (!empty($force_redirect)) {
761
+			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
762
+	}
732 763
 
733 764
 
734 765
 	// Get the right callable.
735 766
 	$call = call_helper($profile_include_data['function'], true);
736 767
 
737 768
 	// Is it valid?
738
-	if (!empty($call))
739
-		call_user_func($call, $memID);
769
+	if (!empty($call)) {
770
+			call_user_func($call, $memID);
771
+	}
740 772
 
741 773
 	// Set the page title if it's not already set...
742
-	if (!isset($context['page_title']))
743
-		$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
744
-}
774
+	if (!isset($context['page_title'])) {
775
+			$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
776
+	}
777
+	}
745 778
 
746 779
 /**
747 780
  * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
@@ -864,16 +897,18 @@  discard block
 block discarded – undo
864 897
 	if (!allowedTo('admin_forum') && $area != 'register')
865 898
 	{
866 899
 		// If it's the owner they can see two types of private fields, regardless.
867
-		if ($memID == $user_info['id'])
868
-			$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
869
-		else
870
-			$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
900
+		if ($memID == $user_info['id']) {
901
+					$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
902
+		} else {
903
+					$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
904
+		}
871 905
 	}
872 906
 
873
-	if ($area == 'register')
874
-		$where .= ' AND show_reg != 0';
875
-	elseif ($area != 'summary')
876
-		$where .= ' AND show_profile = {string:area}';
907
+	if ($area == 'register') {
908
+			$where .= ' AND show_reg != 0';
909
+	} elseif ($area != 'summary') {
910
+			$where .= ' AND show_profile = {string:area}';
911
+	}
877 912
 
878 913
 	// Load all the relevant fields - and data.
879 914
 	$request = $smcFunc['db_query']('', '
@@ -899,13 +934,15 @@  discard block
 block discarded – undo
899 934
 		if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
900 935
 		{
901 936
 			$value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
902
-			if (in_array($row['field_type'], array('select', 'radio')))
903
-					$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
937
+			if (in_array($row['field_type'], array('select', 'radio'))) {
938
+								$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
939
+			}
904 940
 		}
905 941
 
906 942
 		// Don't show the "disabled" option for the "gender" field if we are on the "summary" area.
907
-		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled')
908
-			continue;
943
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') {
944
+					continue;
945
+		}
909 946
 
910 947
 		// HTML for the input form.
911 948
 		$output_html = $value;
@@ -914,8 +951,7 @@  discard block
 block discarded – undo
914 951
 			$true = (!$exists && $row['default_value']) || $value;
915 952
 			$input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . ' class="input_check">';
916 953
 			$output_html = $true ? $txt['yes'] : $txt['no'];
917
-		}
918
-		elseif ($row['field_type'] == 'select')
954
+		} elseif ($row['field_type'] == 'select')
919 955
 		{
920 956
 			$input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
921 957
 			$options = explode(',', $row['field_options']);
@@ -923,13 +959,13 @@  discard block
 block discarded – undo
923 959
 			{
924 960
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
925 961
 				$input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
926
-				if ($true)
927
-					$output_html = $v;
962
+				if ($true) {
963
+									$output_html = $v;
964
+				}
928 965
 			}
929 966
 
930 967
 			$input_html .= '</select>';
931
-		}
932
-		elseif ($row['field_type'] == 'radio')
968
+		} elseif ($row['field_type'] == 'radio')
933 969
 		{
934 970
 			$input_html = '<fieldset>';
935 971
 			$options = explode(',', $row['field_options']);
@@ -937,36 +973,37 @@  discard block
 block discarded – undo
937 973
 			{
938 974
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
939 975
 				$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>';
940
-				if ($true)
941
-					$output_html = $v;
976
+				if ($true) {
977
+									$output_html = $v;
978
+				}
942 979
 			}
943 980
 			$input_html .= '</fieldset>';
944
-		}
945
-		elseif ($row['field_type'] == 'text')
981
+		} elseif ($row['field_type'] == 'text')
946 982
 		{
947 983
 			$input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '" class="input_text"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
948
-		}
949
-		else
984
+		} else
950 985
 		{
951 986
 			@list ($rows, $cols) = @explode(',', $row['default_value']);
952 987
 			$input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>';
953 988
 		}
954 989
 
955 990
 		// Parse BBCode
956
-		if ($row['bbc'])
957
-			$output_html = parse_bbc($output_html);
958
-		elseif ($row['field_type'] == 'textarea')
959
-			// Allow for newlines at least
991
+		if ($row['bbc']) {
992
+					$output_html = parse_bbc($output_html);
993
+		} elseif ($row['field_type'] == 'textarea') {
994
+					// Allow for newlines at least
960 995
 			$output_html = strtr($output_html, array("\n" => '<br>'));
996
+		}
961 997
 
962 998
 		// Enclosing the user input within some other text?
963
-		if (!empty($row['enclose']) && !empty($output_html))
964
-			$output_html = strtr($row['enclose'], array(
999
+		if (!empty($row['enclose']) && !empty($output_html)) {
1000
+					$output_html = strtr($row['enclose'], array(
965 1001
 				'{SCRIPTURL}' => $scripturl,
966 1002
 				'{IMAGES_URL}' => $settings['images_url'],
967 1003
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
968 1004
 				'{INPUT}' => un_htmlspecialchars($output_html),
969 1005
 			));
1006
+		}
970 1007
 
971 1008
 		$context['custom_fields'][] = array(
972 1009
 			'name' => $row['field_name'],
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +798 added lines, -602 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,27 +48,35 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
88 98
 	{
89
-		if (!$utf8 || $smcFunc['db_mb4'])
90
-			return $string;
99
+		if (!$utf8 || $smcFunc['db_mb4']) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i + 1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -214,23 +223,25 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
225
-		date_default_timezone_set($modSettings['default_timezone']);
226
-	else
234
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	} else
227 237
 	{
228 238
 		// Get PHP's default timezone, if set
229 239
 		$ini_tz = ini_get('date.timezone');
230
-		if (!empty($ini_tz))
231
-			$modSettings['default_timezone'] = $ini_tz;
232
-		else
233
-			$modSettings['default_timezone'] = '';
240
+		if (!empty($ini_tz)) {
241
+					$modSettings['default_timezone'] = $ini_tz;
242
+		} else {
243
+					$modSettings['default_timezone'] = '';
244
+		}
234 245
 
235 246
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
236 247
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -248,22 +259,26 @@  discard block
 block discarded – undo
248 259
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
249 260
 		{
250 261
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
251
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
252
-				$modSettings['load_average'] = (float) $matches[1];
253
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
254
-				$modSettings['load_average'] = (float) $matches[1];
255
-			else
256
-				unset($modSettings['load_average']);
262
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
263
+							$modSettings['load_average'] = (float) $matches[1];
264
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
265
+							$modSettings['load_average'] = (float) $matches[1];
266
+			} else {
267
+							unset($modSettings['load_average']);
268
+			}
257 269
 
258
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
259
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
270
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
271
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
272
+			}
260 273
 		}
261 274
 
262
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
263
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
275
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
276
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
277
+		}
264 278
 
265
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
266
-			display_loadavg_error();
279
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
280
+					display_loadavg_error();
281
+		}
267 282
 	}
268 283
 
269 284
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -284,8 +299,9 @@  discard block
 block discarded – undo
284 299
 	if (defined('SMF_INTEGRATION_SETTINGS'))
285 300
 	{
286 301
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
287
-		foreach ($integration_settings as $hook => $function)
288
-			add_integration_function($hook, $function, '', false);
302
+		foreach ($integration_settings as $hook => $function) {
303
+					add_integration_function($hook, $function, '', false);
304
+		}
289 305
 	}
290 306
 
291 307
 	// Any files to pre include?
@@ -295,8 +311,9 @@  discard block
 block discarded – undo
295 311
 		foreach ($pre_includes as $include)
296 312
 		{
297 313
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
298
-			if (file_exists($include))
299
-				require_once($include);
314
+			if (file_exists($include)) {
315
+							require_once($include);
316
+			}
300 317
 		}
301 318
 	}
302 319
 
@@ -400,27 +417,28 @@  discard block
 block discarded – undo
400 417
 				break;
401 418
 			}
402 419
 		}
420
+	} else {
421
+			$id_member = 0;
403 422
 	}
404
-	else
405
-		$id_member = 0;
406 423
 
407 424
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
408 425
 	{
409 426
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
410 427
 
411
-		if (empty($cookie_data))
412
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
428
+		if (empty($cookie_data)) {
429
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
430
+		}
413 431
 
414 432
 		list ($id_member, $password) = $cookie_data;
415 433
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
434
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 435
 	{
419 436
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 437
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
421 438
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
439
+		if (empty($cookie_data)) {
440
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
441
+		}
424 442
 
425 443
 		list ($id_member, $password, $login_span) = $cookie_data;
426 444
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +463,34 @@  discard block
 block discarded – undo
445 463
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 464
 			$smcFunc['db_free_result']($request);
447 465
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
466
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
467
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
468
+			}
450 469
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
470
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
471
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
472
+			}
453 473
 		}
454 474
 
455 475
 		// Did we find 'im?  If not, junk it.
456 476
 		if (!empty($user_settings))
457 477
 		{
458 478
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
479
+			if (!empty($already_verified) && $already_verified === true) {
480
+							$check = true;
481
+			}
461 482
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
483
+			elseif (strlen($password) == 128) {
484
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
485
+			} else {
486
+							$check = false;
487
+			}
466 488
 
467 489
 			// Wrong password or not activated - either way, you're going nowhere.
468 490
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
491
+		} else {
492
+					$id_member = 0;
469 493
 		}
470
-		else
471
-			$id_member = 0;
472 494
 
473 495
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 496
 		if (!$id_member)
@@ -490,13 +512,15 @@  discard block
 block discarded – undo
490 512
 				{
491 513
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
492 514
 
493
-					if (is_null($tfa_data))
494
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
515
+					if (is_null($tfa_data)) {
516
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
517
+					}
495 518
 
496 519
 					list ($tfamember, $tfasecret) = $tfa_data;
497 520
 
498
-					if ((int) $tfamember != $id_member)
499
-						$tfasecret = null;
521
+					if ((int) $tfamember != $id_member) {
522
+											$tfasecret = null;
523
+					}
500 524
 				}
501 525
 
502 526
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +540,12 @@  discard block
 block discarded – undo
516 540
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 541
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 542
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
543
+			if ($modSettings['tfa_mode'] == 2) {
544
+				//only do this if we are just forcing SOME membergroups
520 545
 			{
521 546
 				//Build an array of ALL user membergroups.
522 547
 				$full_groups = array($user_settings['id_group']);
548
+			}
523 549
 				if (!empty($user_settings['additional_groups']))
524 550
 				{
525 551
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +565,17 @@  discard block
 block discarded – undo
539 565
 				);
540 566
 				$row = $smcFunc['db_fetch_assoc']($request);
541 567
 				$smcFunc['db_free_result']($request);
568
+			} else {
569
+							$row['total'] = 1;
542 570
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
571
+			//simplifies logics in the next "if"
545 572
 
546 573
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 574
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 575
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
576
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
577
+							redirectexit('action=profile;area=tfasetup;forced');
578
+			}
551 579
 		}
552 580
 	}
553 581
 
@@ -584,33 +612,37 @@  discard block
 block discarded – undo
584 612
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
585 613
 				$user_settings['last_login'] = time();
586 614
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
615
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
616
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				}
589 618
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
619
+				if (!empty($modSettings['cache_enable'])) {
620
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				}
592 622
 			}
623
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
624
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 625
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 626
 
597 627
 		$username = $user_settings['member_name'];
598 628
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
629
+		if (empty($user_settings['additional_groups'])) {
630
+					$user_info = array(
601 631
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 632
 			);
603
-		else
604
-			$user_info = array(
633
+		} else {
634
+					$user_info = array(
605 635
 				'groups' => array_merge(
606 636
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 637
 					explode(',', $user_settings['additional_groups'])
608 638
 				)
609 639
 			);
640
+		}
610 641
 
611 642
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
643
+		foreach ($user_info['groups'] as $k => $v) {
644
+					$user_info['groups'][$k] = (int) $v;
645
+		}
614 646
 
615 647
 		// This is a logged in user, so definitely not a spider.
616 648
 		$user_info['possibly_robot'] = false;
@@ -624,8 +656,7 @@  discard block
 block discarded – undo
624 656
 			$time_system = new DateTime('now', $tz_system);
625 657
 			$time_user = new DateTime('now', $tz_user);
626 658
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
659
+		} else
629 660
 		{
630 661
 			// !!! Compatibility.
631 662
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -639,16 +670,18 @@  discard block
 block discarded – undo
639 670
 		$user_info = array('groups' => array(-1));
640 671
 		$user_settings = array();
641 672
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
673
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
674
+					$_COOKIE[$cookiename] = '';
675
+		}
644 676
 
645 677
 		// Expire the 2FA cookie
646 678
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
647 679
 		{
648 680
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
649 681
 
650
-			if (is_null($tfa_data))
651
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
682
+			if (is_null($tfa_data)) {
683
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
684
+			}
652 685
 
653 686
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
654 687
 
@@ -660,19 +693,20 @@  discard block
 block discarded – undo
660 693
 		}
661 694
 
662 695
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
667 701
 
668 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 704
 		{
671 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 709
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 710
 		// If we haven't turned on proper spider hunts then have a guess!
677 711
 		else
678 712
 		{
@@ -720,8 +754,9 @@  discard block
 block discarded – undo
720 754
 	$user_info['groups'] = array_unique($user_info['groups']);
721 755
 
722 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
725 760
 
726 761
 	// Allow the user to change their language.
727 762
 	if (!empty($modSettings['userLanguage']))
@@ -734,31 +769,36 @@  discard block
 block discarded – undo
734 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 770
 
736 771
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 779
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 780
 	}
745 781
 
746 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
747
-	if ($user_info['is_admin'])
748
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
749 786
 	// Otherwise just the groups in $user_info['groups'].
750
-	else
751
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
752 790
 
753 791
 	// Build the list of boards they WANT to see.
754 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
755 793
 
756 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
757
-	if (empty($user_info['ignoreboards']))
758
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
759 798
 	// Ok I guess they don't want to see all the boards
760
-	else
761
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
762 802
 
763 803
 	call_integration_hook('integrate_user_info');
764 804
 }
@@ -816,9 +856,9 @@  discard block
 block discarded – undo
816 856
 		}
817 857
 
818 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
822 862
 		{
823 863
 			loadPermissions();
824 864
 			loadTheme();
@@ -836,10 +876,11 @@  discard block
 block discarded – undo
836 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 877
 	{
838 878
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
843 884
 
844 885
 		if (!empty($temp))
845 886
 		{
@@ -877,8 +918,9 @@  discard block
 block discarded – undo
877 918
 			$row = $smcFunc['db_fetch_assoc']($request);
878 919
 
879 920
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
882 924
 
883 925
 			// Basic operating information. (globals... :/)
884 926
 			$board_info = array(
@@ -914,21 +956,23 @@  discard block
 block discarded – undo
914 956
 
915 957
 			do
916 958
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
919 961
 						'id' => $row['id_moderator'],
920 962
 						'name' => $row['real_name'],
921 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 965
 					);
966
+				}
924 967
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 970
 						'id' => $row['id_moderator_group'],
928 971
 						'name' => $row['group_name'],
929 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 974
 					);
975
+				}
932 976
 			}
933 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 978
 
@@ -960,12 +1004,12 @@  discard block
 block discarded – undo
960 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 1005
 			{
962 1006
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
965 1010
 				cache_put_data('board-' . $board, $board_info, 120);
966 1011
 			}
967
-		}
968
-		else
1012
+		} else
969 1013
 		{
970 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1015
 			$board_info = array(
@@ -979,8 +1023,9 @@  discard block
 block discarded – undo
979 1023
 		$smcFunc['db_free_result']($request);
980 1024
 	}
981 1025
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
984 1029
 
985 1030
 	if (!empty($board))
986 1031
 	{
@@ -990,10 +1035,12 @@  discard block
 block discarded – undo
990 1035
 		// Now check if the user is a moderator.
991 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1037
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
997 1044
 
998 1045
 		// Build up the linktree.
999 1046
 		$context['linktree'] = array_merge(
@@ -1016,8 +1063,9 @@  discard block
 block discarded – undo
1016 1063
 	$context['current_board'] = $board;
1017 1064
 
1018 1065
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1021 1069
 
1022 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1091,23 @@  discard block
 block discarded – undo
1043 1091
 			ob_end_clean();
1044 1092
 			header('HTTP/1.1 403 Forbidden');
1045 1093
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1095
 		{
1049 1096
 			// Slightly different error message here...
1050 1097
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1053 1099
 		{
1054 1100
 			loadLanguage('Errors');
1055 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1056 1104
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1105
 	}
1060 1106
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1064 1111
 
1065 1112
 /**
1066 1113
  * Load this user's permissions.
@@ -1081,8 +1128,9 @@  discard block
 block discarded – undo
1081 1128
 		asort($cache_groups);
1082 1129
 		$cache_groups = implode(',', $cache_groups);
1083 1130
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1086 1134
 
1087 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1136
 		{
@@ -1090,9 +1138,9 @@  discard block
 block discarded – undo
1090 1138
 			banPermissions();
1091 1139
 
1092 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1093 1143
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1144
 	}
1097 1145
 
1098 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1162,26 @@  discard block
 block discarded – undo
1114 1162
 		$removals = array();
1115 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1164
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1121 1170
 		}
1122 1171
 		$smcFunc['db_free_result']($request);
1123 1172
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1126 1176
 	}
1127 1177
 
1128 1178
 	// Get the board permissions.
1129 1179
 	if (!empty($board))
1130 1180
 	{
1131 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1134 1185
 
1135 1186
 		$request = $smcFunc['db_query']('', '
1136 1187
 			SELECT permission, add_deny
@@ -1146,20 +1197,23 @@  discard block
 block discarded – undo
1146 1197
 		);
1147 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1199
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1153 1205
 		}
1154 1206
 		$smcFunc['db_free_result']($request);
1155 1207
 	}
1156 1208
 
1157 1209
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1160 1213
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1163 1217
 
1164 1218
 	// Banned?  Watch, don't touch..
1165 1219
 	banPermissions();
@@ -1171,17 +1225,18 @@  discard block
 block discarded – undo
1171 1225
 		{
1172 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1230
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1231
 
1178 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1233
 		// For example this drastically simplifies certain changes to the profile area.
1180 1234
 		$user_info['permissions'][] = 'is_not_guest';
1181 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1236
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1185 1240
 	}
1186 1241
 }
1187 1242
 
@@ -1199,8 +1254,9 @@  discard block
 block discarded – undo
1199 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1200 1255
 
1201 1256
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1204 1260
 
1205 1261
 	// Pass the set value
1206 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1271,9 @@  discard block
 block discarded – undo
1215 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1272
 		{
1217 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1220 1277
 
1221 1278
 			$loaded_ids[] = $data['id_member'];
1222 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1283,13 +1340,16 @@  discard block
 block discarded – undo
1283 1340
 			$row['avatar_original'] = $row['avatar'];
1284 1341
 
1285 1342
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1287
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1343
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1344
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1345
+			}
1288 1346
 
1289
-			if (isset($row['member_ip']))
1290
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1291
-			if (isset($row['member_ip2']))
1292
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			if (isset($row['member_ip'])) {
1348
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1349
+			}
1350
+			if (isset($row['member_ip2'])) {
1351
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1352
+			}
1293 1353
 			$new_loaded_ids[] = $row['id_member'];
1294 1354
 			$loaded_ids[] = $row['id_member'];
1295 1355
 			$row['options'] = array();
@@ -1308,8 +1368,9 @@  discard block
 block discarded – undo
1308 1368
 				'loaded_ids' => $new_loaded_ids,
1309 1369
 			)
1310 1370
 		);
1311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1312
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1371
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1372
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1373
+		}
1313 1374
 		$smcFunc['db_free_result']($request);
1314 1375
 	}
1315 1376
 
@@ -1320,10 +1381,11 @@  discard block
 block discarded – undo
1320 1381
 	{
1321 1382
 		foreach ($loaded_ids as $a_member)
1322 1383
 		{
1323
-			if (!empty($user_profile[$a_member]['additional_groups']))
1324
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1325
-			else
1326
-				$groups = array($user_profile[$a_member]['id_group']);
1384
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1385
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1386
+			} else {
1387
+							$groups = array($user_profile[$a_member]['id_group']);
1388
+			}
1327 1389
 
1328 1390
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1329 1391
 
@@ -1336,8 +1398,9 @@  discard block
 block discarded – undo
1336 1398
 
1337 1399
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1338 1400
 	{
1339
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1340
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1401
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1402
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1403
+		}
1341 1404
 	}
1342 1405
 
1343 1406
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1363,14 +1426,17 @@  discard block
 block discarded – undo
1363 1426
 		foreach ($temp_mods as $id)
1364 1427
 		{
1365 1428
 			// By popular demand, don't show admins or global moderators as moderators.
1366
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1367
-				$user_profile[$id]['member_group'] = $row['member_group'];
1429
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1430
+							$user_profile[$id]['member_group'] = $row['member_group'];
1431
+			}
1368 1432
 
1369 1433
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1370
-			if (!empty($row['icons']))
1371
-				$user_profile[$id]['icons'] = $row['icons'];
1372
-			if (!empty($row['member_group_color']))
1373
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			if (!empty($row['icons'])) {
1435
+							$user_profile[$id]['icons'] = $row['icons'];
1436
+			}
1437
+			if (!empty($row['member_group_color'])) {
1438
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1439
+			}
1374 1440
 		}
1375 1441
 	}
1376 1442
 
@@ -1392,12 +1458,14 @@  discard block
 block discarded – undo
1392 1458
 	static $loadedLanguages = array();
1393 1459
 
1394 1460
 	// If this person's data is already loaded, skip it.
1395
-	if (isset($dataLoaded[$user]))
1396
-		return true;
1461
+	if (isset($dataLoaded[$user])) {
1462
+			return true;
1463
+	}
1397 1464
 
1398 1465
 	// We can't load guests or members not loaded by loadMemberData()!
1399
-	if ($user == 0)
1400
-		return false;
1466
+	if ($user == 0) {
1467
+			return false;
1468
+	}
1401 1469
 	if (!isset($user_profile[$user]))
1402 1470
 	{
1403 1471
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1423,12 +1491,16 @@  discard block
 block discarded – undo
1423 1491
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1424 1492
 
1425 1493
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1426
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1494
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1495
+		//icon is set and exists
1427 1496
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1428
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1497
+	} elseif (isset($profile['icons'][1])) {
1498
+		//icon is set and doesn't exist, fallback to default
1429 1499
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1430
-	else //not set, bye bye
1500
+	} else {
1501
+		//not set, bye bye
1431 1502
 		$group_icon_url = '';
1503
+	}
1432 1504
 
1433 1505
 	// These minimal values are always loaded
1434 1506
 	$memberContext[$user] = array(
@@ -1447,8 +1519,9 @@  discard block
 block discarded – undo
1447 1519
 	if ($context['loadMemberContext_set'] != 'minimal')
1448 1520
 	{
1449 1521
 		// Go the extra mile and load the user's native language name.
1450
-		if (empty($loadedLanguages))
1451
-			$loadedLanguages = getLanguages();
1522
+		if (empty($loadedLanguages)) {
1523
+					$loadedLanguages = getLanguages();
1524
+		}
1452 1525
 
1453 1526
 		$memberContext[$user] += array(
1454 1527
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1502,31 +1575,33 @@  discard block
 block discarded – undo
1502 1575
 	{
1503 1576
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1504 1577
 		{
1505
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1506
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1507
-			else
1508
-				$image = get_gravatar_url($profile['email_address']);
1509
-		}
1510
-		else
1578
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1579
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1580
+			} else {
1581
+							$image = get_gravatar_url($profile['email_address']);
1582
+			}
1583
+		} else
1511 1584
 		{
1512 1585
 			// So it's stored in the member table?
1513 1586
 			if (!empty($profile['avatar']))
1514 1587
 			{
1515 1588
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1589
+			} elseif (!empty($profile['filename'])) {
1590
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1591
 			}
1517
-			elseif (!empty($profile['filename']))
1518
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1519 1592
 			// Right... no avatar...use the default one
1520
-			else
1521
-				$image = $modSettings['avatar_url'] . '/default.png';
1593
+			else {
1594
+							$image = $modSettings['avatar_url'] . '/default.png';
1595
+			}
1522 1596
 		}
1523
-		if (!empty($image))
1524
-			$memberContext[$user]['avatar'] = array(
1597
+		if (!empty($image)) {
1598
+					$memberContext[$user]['avatar'] = array(
1525 1599
 				'name' => $profile['avatar'],
1526 1600
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1527 1601
 				'href' => $image,
1528 1602
 				'url' => $image,
1529 1603
 			);
1604
+		}
1530 1605
 	}
1531 1606
 
1532 1607
 	// Are we also loading the members custom fields into context?
@@ -1534,35 +1609,41 @@  discard block
 block discarded – undo
1534 1609
 	{
1535 1610
 		$memberContext[$user]['custom_fields'] = array();
1536 1611
 
1537
-		if (!isset($context['display_fields']))
1538
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1612
+		if (!isset($context['display_fields'])) {
1613
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1614
+		}
1539 1615
 
1540 1616
 		foreach ($context['display_fields'] as $custom)
1541 1617
 		{
1542
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1543
-				continue;
1618
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1619
+							continue;
1620
+			}
1544 1621
 
1545 1622
 			$value = $profile['options'][$custom['col_name']];
1546 1623
 
1547 1624
 			// Don't show the "disabled" option for the "gender" field.
1548
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1549
-				continue;
1625
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1626
+							continue;
1627
+			}
1550 1628
 
1551 1629
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1630
+			if ($custom['bbc']) {
1631
+							$value = parse_bbc($value);
1632
+			}
1554 1633
 			// ... or checkbox?
1555
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1556
-				$value = $value ? $txt['yes'] : $txt['no'];
1634
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1635
+							$value = $value ? $txt['yes'] : $txt['no'];
1636
+			}
1557 1637
 
1558 1638
 			// Enclosing the user input within some other text?
1559
-			if (!empty($custom['enclose']))
1560
-				$value = strtr($custom['enclose'], array(
1639
+			if (!empty($custom['enclose'])) {
1640
+							$value = strtr($custom['enclose'], array(
1561 1641
 					'{SCRIPTURL}' => $scripturl,
1562 1642
 					'{IMAGES_URL}' => $settings['images_url'],
1563 1643
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1564 1644
 					'{INPUT}' => $value,
1565 1645
 				));
1646
+			}
1566 1647
 
1567 1648
 			$memberContext[$user]['custom_fields'][] = array(
1568 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1670,9 @@  discard block
 block discarded – undo
1589 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1671
 
1591 1672
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1594 1676
 
1595 1677
 	// Make sure it's an array.
1596 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1614,31 +1696,36 @@  discard block
 block discarded – undo
1614 1696
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1615 1697
 	{
1616 1698
 		// BBC?
1617
-		if (!empty($row['bbc']))
1618
-			$row['value'] = parse_bbc($row['value']);
1699
+		if (!empty($row['bbc'])) {
1700
+					$row['value'] = parse_bbc($row['value']);
1701
+		}
1619 1702
 
1620 1703
 		// ... or checkbox?
1621
-		elseif (isset($row['type']) && $row['type'] == 'check')
1622
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1704
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1705
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1706
+		}
1623 1707
 
1624 1708
 		// Enclosing the user input within some other text?
1625
-		if (!empty($row['enclose']))
1626
-			$row['value'] = strtr($row['enclose'], array(
1709
+		if (!empty($row['enclose'])) {
1710
+					$row['value'] = strtr($row['enclose'], array(
1627 1711
 				'{SCRIPTURL}' => $scripturl,
1628 1712
 				'{IMAGES_URL}' => $settings['images_url'],
1629 1713
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1630 1714
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1631 1715
 			));
1716
+		}
1632 1717
 
1633 1718
 		// Send a simple array if there is just 1 param
1634
-		if (count($params) == 1)
1635
-			$return[$row['id_member']] = $row;
1719
+		if (count($params) == 1) {
1720
+					$return[$row['id_member']] = $row;
1721
+		}
1636 1722
 
1637 1723
 		// More than 1? knock yourself out...
1638 1724
 		else
1639 1725
 		{
1640
-			if (!isset($return[$row['id_member']]))
1641
-				$return[$row['id_member']] = array();
1726
+			if (!isset($return[$row['id_member']])) {
1727
+							$return[$row['id_member']] = array();
1728
+			}
1642 1729
 
1643 1730
 			$return[$row['id_member']][$row['variable']] = $row;
1644 1731
 		}
@@ -1672,8 +1759,9 @@  discard block
 block discarded – undo
1672 1759
 	global $context;
1673 1760
 
1674 1761
 	// Don't know any browser!
1675
-	if (empty($context['browser']))
1676
-		detectBrowser();
1762
+	if (empty($context['browser'])) {
1763
+			detectBrowser();
1764
+	}
1677 1765
 
1678 1766
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1679 1767
 }
@@ -1691,8 +1779,9 @@  discard block
 block discarded – undo
1691 1779
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1692 1780
 
1693 1781
 	// The theme was specified by parameter.
1694
-	if (!empty($id_theme))
1695
-		$id_theme = (int) $id_theme;
1782
+	if (!empty($id_theme)) {
1783
+			$id_theme = (int) $id_theme;
1784
+	}
1696 1785
 	// The theme was specified by REQUEST.
1697 1786
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1698 1787
 	{
@@ -1700,51 +1789,58 @@  discard block
 block discarded – undo
1700 1789
 		$_SESSION['id_theme'] = $id_theme;
1701 1790
 	}
1702 1791
 	// The theme was specified by REQUEST... previously.
1703
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1704
-		$id_theme = (int) $_SESSION['id_theme'];
1792
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1793
+			$id_theme = (int) $_SESSION['id_theme'];
1794
+	}
1705 1795
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1706
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1707
-		$id_theme = $user_info['theme'];
1796
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1797
+			$id_theme = $user_info['theme'];
1798
+	}
1708 1799
 	// The theme was specified by the board.
1709
-	elseif (!empty($board_info['theme']))
1710
-		$id_theme = $board_info['theme'];
1800
+	elseif (!empty($board_info['theme'])) {
1801
+			$id_theme = $board_info['theme'];
1802
+	}
1711 1803
 	// The theme is the forum's default.
1712
-	else
1713
-		$id_theme = $modSettings['theme_guests'];
1804
+	else {
1805
+			$id_theme = $modSettings['theme_guests'];
1806
+	}
1714 1807
 
1715 1808
 	// Verify the id_theme... no foul play.
1716 1809
 	// Always allow the board specific theme, if they are overriding.
1717
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1718
-		$id_theme = $board_info['theme'];
1810
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1811
+			$id_theme = $board_info['theme'];
1812
+	}
1719 1813
 	// If they have specified a particular theme to use with SSI allow it to be used.
1720
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1721
-		$id_theme = (int) $id_theme;
1722
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1814
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1815
+			$id_theme = (int) $id_theme;
1816
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1723 1817
 	{
1724 1818
 		$themes = explode(',', $modSettings['enableThemes']);
1725
-		if (!in_array($id_theme, $themes))
1726
-			$id_theme = $modSettings['theme_guests'];
1727
-		else
1819
+		if (!in_array($id_theme, $themes)) {
1820
+					$id_theme = $modSettings['theme_guests'];
1821
+		} else {
1822
+					$id_theme = (int) $id_theme;
1823
+		}
1824
+	} else {
1728 1825
 			$id_theme = (int) $id_theme;
1729 1826
 	}
1730
-	else
1731
-		$id_theme = (int) $id_theme;
1732 1827
 
1733 1828
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1734 1829
 
1735 1830
 	// Disable image proxy if we don't have SSL enabled
1736
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1737
-		$image_proxy_enabled = false;
1831
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1832
+			$image_proxy_enabled = false;
1833
+	}
1738 1834
 
1739 1835
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1740 1836
 	{
1741 1837
 		$themeData = $temp;
1742 1838
 		$flag = true;
1839
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1840
+			$themeData = $temp + array($member => array());
1841
+	} else {
1842
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1743 1843
 	}
1744
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1745
-		$themeData = $temp + array($member => array());
1746
-	else
1747
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1844
 
1749 1845
 	if (empty($flag))
1750 1846
 	{
@@ -1763,31 +1859,37 @@  discard block
 block discarded – undo
1763 1859
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1764 1860
 		{
1765 1861
 			// There are just things we shouldn't be able to change as members.
1766
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1767
-				continue;
1862
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1863
+							continue;
1864
+			}
1768 1865
 
1769 1866
 			// If this is the theme_dir of the default theme, store it.
1770
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1771
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1868
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1869
+			}
1772 1870
 
1773 1871
 			// If this isn't set yet, is a theme option, or is not the default theme..
1774
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1775
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1873
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1874
+			}
1776 1875
 		}
1777 1876
 		$smcFunc['db_free_result']($result);
1778 1877
 
1779
-		if (!empty($themeData[-1]))
1780
-			foreach ($themeData[-1] as $k => $v)
1878
+		if (!empty($themeData[-1])) {
1879
+					foreach ($themeData[-1] as $k => $v)
1781 1880
 			{
1782 1881
 				if (!isset($themeData[$member][$k]))
1783 1882
 					$themeData[$member][$k] = $v;
1883
+		}
1784 1884
 			}
1785 1885
 
1786
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1787
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1887
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1888
+		}
1788 1889
 		// Only if we didn't already load that part of the cache...
1789
-		elseif (!isset($temp))
1790
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+		elseif (!isset($temp)) {
1891
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1892
+		}
1791 1893
 	}
1792 1894
 
1793 1895
 	$settings = $themeData[0];
@@ -1804,20 +1906,24 @@  discard block
 block discarded – undo
1804 1906
 	$settings['template_dirs'][] = $settings['theme_dir'];
1805 1907
 
1806 1908
 	// Based on theme (if there is one).
1807
-	if (!empty($settings['base_theme_dir']))
1808
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+	if (!empty($settings['base_theme_dir'])) {
1910
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1911
+	}
1809 1912
 
1810 1913
 	// Lastly the default theme.
1811
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1812
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1915
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1916
+	}
1813 1917
 
1814
-	if (!$initialize)
1815
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1816 1921
 
1817 1922
 	// Check to see if we're forcing SSL
1818 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1819
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1820
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1821 1927
 
1822 1928
 	// Check to see if they're accessing it from the wrong place.
1823 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1825,8 +1931,9 @@  discard block
 block discarded – undo
1825 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1826 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1827 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1828
-		if ($temp != '/')
1829
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1830 1937
 	}
1831 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1832 1939
 	{
@@ -1838,8 +1945,9 @@  discard block
 block discarded – undo
1838 1945
 			foreach ($aliases as $alias)
1839 1946
 			{
1840 1947
 				// Rip off all the boring parts, spaces, etc.
1841
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1842
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1843 1951
 			}
1844 1952
 		}
1845 1953
 
@@ -1847,20 +1955,22 @@  discard block
 block discarded – undo
1847 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1848 1956
 		{
1849 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1850
-			if (empty($_GET))
1851
-				redirectexit('wwwRedirect');
1852
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1853 1961
 			{
1854 1962
 				list ($k, $v) = each($_GET);
1855 1963
 
1856
-				if ($k != 'wwwRedirect')
1857
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1858 1967
 			}
1859 1968
 		}
1860 1969
 
1861 1970
 		// #3 is just a check for SSL...
1862
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1863
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1864 1974
 
1865 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1866 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1894,8 +2004,9 @@  discard block
 block discarded – undo
1894 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1895 2005
 				}
1896 2006
 			}
1897
-			foreach ($context['linktree'] as $k => $dummy)
1898
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1899 2010
 		}
1900 2011
 	}
1901 2012
 	// Set up the contextual user array.
@@ -1914,16 +2025,16 @@  discard block
 block discarded – undo
1914 2025
 			'email' => $user_info['email'],
1915 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1916 2027
 		);
1917
-		if (!$context['user']['is_guest'])
1918
-			$context['user']['name'] = $user_info['name'];
1919
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1920
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1921 2033
 
1922 2034
 		// Determine the current smiley set.
1923 2035
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1924 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1925
-	}
1926
-	else
2037
+	} else
1927 2038
 	{
1928 2039
 		$context['user'] = array(
1929 2040
 			'id' => -1,
@@ -1939,18 +2050,24 @@  discard block
 block discarded – undo
1939 2050
 	}
1940 2051
 
1941 2052
 	// Some basic information...
1942
-	if (!isset($context['html_headers']))
1943
-		$context['html_headers'] = '';
1944
-	if (!isset($context['javascript_files']))
1945
-		$context['javascript_files'] = array();
1946
-	if (!isset($context['css_files']))
1947
-		$context['css_files'] = array();
1948
-	if (!isset($context['css_header']))
1949
-		$context['css_header'] = array();
1950
-	if (!isset($context['javascript_inline']))
1951
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1952
-	if (!isset($context['javascript_vars']))
1953
-		$context['javascript_vars'] = array();
2053
+	if (!isset($context['html_headers'])) {
2054
+			$context['html_headers'] = '';
2055
+	}
2056
+	if (!isset($context['javascript_files'])) {
2057
+			$context['javascript_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_files'])) {
2060
+			$context['css_files'] = array();
2061
+	}
2062
+	if (!isset($context['css_header'])) {
2063
+			$context['css_header'] = array();
2064
+	}
2065
+	if (!isset($context['javascript_inline'])) {
2066
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2067
+	}
2068
+	if (!isset($context['javascript_vars'])) {
2069
+			$context['javascript_vars'] = array();
2070
+	}
1954 2071
 
1955 2072
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1956 2073
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1962,8 +2079,9 @@  discard block
 block discarded – undo
1962 2079
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1963 2080
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1964 2081
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1965
-	if (isset($modSettings['load_average']))
1966
-		$context['load_average'] = $modSettings['load_average'];
2082
+	if (isset($modSettings['load_average'])) {
2083
+			$context['load_average'] = $modSettings['load_average'];
2084
+	}
1967 2085
 
1968 2086
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1969 2087
 	detectBrowser();
@@ -1977,8 +2095,9 @@  discard block
 block discarded – undo
1977 2095
 	// This allows sticking some HTML on the page output - useful for controls.
1978 2096
 	$context['insert_after_template'] = '';
1979 2097
 
1980
-	if (!isset($txt))
1981
-		$txt = array();
2098
+	if (!isset($txt)) {
2099
+			$txt = array();
2100
+	}
1982 2101
 
1983 2102
 	$simpleActions = array(
1984 2103
 		'findmember',
@@ -2024,9 +2143,10 @@  discard block
 block discarded – undo
2024 2143
 
2025 2144
 	// See if theres any extra param to check.
2026 2145
 	$requiresXML = false;
2027
-	foreach ($extraParams as $key => $extra)
2028
-		if (isset($_REQUEST[$extra]))
2146
+	foreach ($extraParams as $key => $extra) {
2147
+			if (isset($_REQUEST[$extra]))
2029 2148
 			$requiresXML = true;
2149
+	}
2030 2150
 
2031 2151
 	// Output is fully XML, so no need for the index template.
2032 2152
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2041,37 +2161,39 @@  discard block
 block discarded – undo
2041 2161
 	{
2042 2162
 		loadLanguage('index+Modifications');
2043 2163
 		$context['template_layers'] = array();
2044
-	}
2045
-
2046
-	else
2164
+	} else
2047 2165
 	{
2048 2166
 		// Custom templates to load, or just default?
2049
-		if (isset($settings['theme_templates']))
2050
-			$templates = explode(',', $settings['theme_templates']);
2051
-		else
2052
-			$templates = array('index');
2167
+		if (isset($settings['theme_templates'])) {
2168
+					$templates = explode(',', $settings['theme_templates']);
2169
+		} else {
2170
+					$templates = array('index');
2171
+		}
2053 2172
 
2054 2173
 		// Load each template...
2055
-		foreach ($templates as $template)
2056
-			loadTemplate($template);
2174
+		foreach ($templates as $template) {
2175
+					loadTemplate($template);
2176
+		}
2057 2177
 
2058 2178
 		// ...and attempt to load their associated language files.
2059 2179
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2060 2180
 		loadLanguage($required_files, '', false);
2061 2181
 
2062 2182
 		// Custom template layers?
2063
-		if (isset($settings['theme_layers']))
2064
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2065
-		else
2066
-			$context['template_layers'] = array('html', 'body');
2183
+		if (isset($settings['theme_layers'])) {
2184
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2185
+		} else {
2186
+					$context['template_layers'] = array('html', 'body');
2187
+		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Initialize the theme.
2070 2191
 	loadSubTemplate('init', 'ignore');
2071 2192
 
2072 2193
 	// Allow overriding the board wide time/number formats.
2073
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2074
-		$user_info['time_format'] = $txt['time_format'];
2194
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2195
+			$user_info['time_format'] = $txt['time_format'];
2196
+	}
2075 2197
 
2076 2198
 	// Set the character set from the template.
2077 2199
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2079,12 +2201,14 @@  discard block
 block discarded – undo
2079 2201
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2080 2202
 
2081 2203
 	// Guests may still need a name.
2082
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2083
-		$context['user']['name'] = $txt['guest_title'];
2204
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2205
+			$context['user']['name'] = $txt['guest_title'];
2206
+	}
2084 2207
 
2085 2208
 	// Any theme-related strings that need to be loaded?
2086
-	if (!empty($settings['require_theme_strings']))
2087
-		loadLanguage('ThemeStrings', '', false);
2209
+	if (!empty($settings['require_theme_strings'])) {
2210
+			loadLanguage('ThemeStrings', '', false);
2211
+	}
2088 2212
 
2089 2213
 	// Make a special URL for the language.
2090 2214
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2095,8 +2219,9 @@  discard block
 block discarded – undo
2095 2219
 	// Here is my luvly Responsive CSS
2096 2220
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2097 2221
 
2098
-	if ($context['right_to_left'])
2099
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2222
+	if ($context['right_to_left']) {
2223
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2224
+	}
2100 2225
 
2101 2226
 	// We allow theme variants, because we're cool.
2102 2227
 	$context['theme_variant'] = '';
@@ -2104,14 +2229,17 @@  discard block
 block discarded – undo
2104 2229
 	if (!empty($settings['theme_variants']))
2105 2230
 	{
2106 2231
 		// Overriding - for previews and that ilk.
2107
-		if (!empty($_REQUEST['variant']))
2108
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2232
+		if (!empty($_REQUEST['variant'])) {
2233
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2234
+		}
2109 2235
 		// User selection?
2110
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2111
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2236
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2237
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2238
+		}
2112 2239
 		// If not a user variant, select the default.
2113
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2114
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2240
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2241
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2242
+		}
2115 2243
 
2116 2244
 		// Do this to keep things easier in the templates.
2117 2245
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2120,20 +2248,23 @@  discard block
 block discarded – undo
2120 2248
 		if (!empty($context['theme_variant']))
2121 2249
 		{
2122 2250
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2123
-			if ($context['right_to_left'])
2124
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2251
+			if ($context['right_to_left']) {
2252
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2253
+			}
2125 2254
 		}
2126 2255
 	}
2127 2256
 
2128 2257
 	// Let's be compatible with old themes!
2129
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2130
-		$context['template_layers'] = array('main');
2258
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2259
+			$context['template_layers'] = array('main');
2260
+	}
2131 2261
 
2132 2262
 	$context['tabindex'] = 1;
2133 2263
 
2134 2264
 	// Compatibility.
2135
-	if (!isset($settings['theme_version']))
2136
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2265
+	if (!isset($settings['theme_version'])) {
2266
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2267
+	}
2137 2268
 
2138 2269
 	// Default JS variables for use in every theme
2139 2270
 	$context['javascript_vars'] = array(
@@ -2152,18 +2283,18 @@  discard block
 block discarded – undo
2152 2283
 	);
2153 2284
 
2154 2285
 	// Add the JQuery library to the list of files to load.
2155
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2156
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2159
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2160
-
2161
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2162
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2286
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2287
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2288
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2289
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2290
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2291
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2292
+	}
2163 2293
 
2164 2294
 	// Auto loading? template_javascript() will take care of the local half of this.
2165
-	else
2166
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2295
+	else {
2296
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2297
+	}
2167 2298
 
2168 2299
 	// Queue our JQuery plugins!
2169 2300
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2186,12 +2317,12 @@  discard block
 block discarded – undo
2186 2317
 			require_once($sourcedir . '/ScheduledTasks.php');
2187 2318
 
2188 2319
 			// What to do, what to do?!
2189
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2190
-				AutoTask();
2191
-			else
2192
-				ReduceMailQueue();
2193
-		}
2194
-		else
2320
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2321
+							AutoTask();
2322
+			} else {
2323
+							ReduceMailQueue();
2324
+			}
2325
+		} else
2195 2326
 		{
2196 2327
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2197 2328
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2242,8 +2373,9 @@  discard block
 block discarded – undo
2242 2373
 		foreach ($theme_includes as $include)
2243 2374
 		{
2244 2375
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2245
-			if (file_exists($include))
2246
-				require_once($include);
2376
+			if (file_exists($include)) {
2377
+							require_once($include);
2378
+			}
2247 2379
 		}
2248 2380
 	}
2249 2381
 
@@ -2273,16 +2405,19 @@  discard block
 block discarded – undo
2273 2405
 	// Do any style sheets first, cause we're easy with those.
2274 2406
 	if (!empty($style_sheets))
2275 2407
 	{
2276
-		if (!is_array($style_sheets))
2277
-			$style_sheets = array($style_sheets);
2408
+		if (!is_array($style_sheets)) {
2409
+					$style_sheets = array($style_sheets);
2410
+		}
2278 2411
 
2279
-		foreach ($style_sheets as $sheet)
2280
-			loadCSSFile($sheet . '.css', array(), $sheet);
2412
+		foreach ($style_sheets as $sheet) {
2413
+					loadCSSFile($sheet . '.css', array(), $sheet);
2414
+		}
2281 2415
 	}
2282 2416
 
2283 2417
 	// No template to load?
2284
-	if ($template_name === false)
2285
-		return true;
2418
+	if ($template_name === false) {
2419
+			return true;
2420
+	}
2286 2421
 
2287 2422
 	$loaded = false;
2288 2423
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2297,12 +2432,14 @@  discard block
 block discarded – undo
2297 2432
 
2298 2433
 	if ($loaded)
2299 2434
 	{
2300
-		if ($db_show_debug === true)
2301
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2435
+		if ($db_show_debug === true) {
2436
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2437
+		}
2302 2438
 
2303 2439
 		// If they have specified an initialization function for this template, go ahead and call it now.
2304
-		if (function_exists('template_' . $template_name . '_init'))
2305
-			call_user_func('template_' . $template_name . '_init');
2440
+		if (function_exists('template_' . $template_name . '_init')) {
2441
+					call_user_func('template_' . $template_name . '_init');
2442
+		}
2306 2443
 	}
2307 2444
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2308 2445
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2322,13 +2459,14 @@  discard block
 block discarded – undo
2322 2459
 		loadTemplate($template_name);
2323 2460
 	}
2324 2461
 	// Cause an error otherwise.
2325
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2326
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2327
-	elseif ($fatal)
2328
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2329
-	else
2330
-		return false;
2331
-}
2462
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2463
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2464
+	} elseif ($fatal) {
2465
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2466
+	} else {
2467
+			return false;
2468
+	}
2469
+	}
2332 2470
 
2333 2471
 /**
2334 2472
  * Load a sub-template.
@@ -2346,17 +2484,19 @@  discard block
 block discarded – undo
2346 2484
 {
2347 2485
 	global $context, $txt, $db_show_debug;
2348 2486
 
2349
-	if ($db_show_debug === true)
2350
-		$context['debug']['sub_templates'][] = $sub_template_name;
2487
+	if ($db_show_debug === true) {
2488
+			$context['debug']['sub_templates'][] = $sub_template_name;
2489
+	}
2351 2490
 
2352 2491
 	// Figure out what the template function is named.
2353 2492
 	$theme_function = 'template_' . $sub_template_name;
2354
-	if (function_exists($theme_function))
2355
-		$theme_function();
2356
-	elseif ($fatal === false)
2357
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2358
-	elseif ($fatal !== 'ignore')
2359
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2493
+	if (function_exists($theme_function)) {
2494
+			$theme_function();
2495
+	} elseif ($fatal === false) {
2496
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2497
+	} elseif ($fatal !== 'ignore') {
2498
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2499
+	}
2360 2500
 
2361 2501
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2362 2502
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2393,8 +2533,9 @@  discard block
 block discarded – undo
2393 2533
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2394 2534
 
2395 2535
 	// If this is an external file, automatically set this to false.
2396
-	if (!empty($params['external']))
2397
-		$params['minimize'] = false;
2536
+	if (!empty($params['external'])) {
2537
+			$params['minimize'] = false;
2538
+	}
2398 2539
 
2399 2540
 	// Account for shorthand like admin.css?alp21 filenames
2400 2541
 	$has_seed = strpos($fileName, '.css?');
@@ -2411,13 +2552,10 @@  discard block
 block discarded – undo
2411 2552
 			{
2412 2553
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2413 2554
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2555
+			} else {
2556
+							$fileUrl = false;
2414 2557
 			}
2415
-
2416
-			else
2417
-				$fileUrl = false;
2418
-		}
2419
-
2420
-		else
2558
+		} else
2421 2559
 		{
2422 2560
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2423 2561
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2432,12 +2570,14 @@  discard block
 block discarded – undo
2432 2570
 	}
2433 2571
 
2434 2572
 	// Add it to the array for use in the template
2435
-	if (!empty($fileName))
2436
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2573
+	if (!empty($fileName)) {
2574
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2575
+	}
2437 2576
 
2438
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2439
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2440
-}
2577
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2578
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2579
+	}
2580
+	}
2441 2581
 
2442 2582
 /**
2443 2583
  * Add a block of inline css code to be executed later
@@ -2454,8 +2594,9 @@  discard block
 block discarded – undo
2454 2594
 	global $context;
2455 2595
 
2456 2596
 	// Gotta add something...
2457
-	if (empty($css))
2458
-		return false;
2597
+	if (empty($css)) {
2598
+			return false;
2599
+	}
2459 2600
 
2460 2601
 	$context['css_header'][] = $css;
2461 2602
 }
@@ -2490,8 +2631,9 @@  discard block
 block discarded – undo
2490 2631
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2491 2632
 
2492 2633
 	// If this is an external file, automatically set this to false.
2493
-	if (!empty($params['external']))
2494
-		$params['minimize'] = false;
2634
+	if (!empty($params['external'])) {
2635
+			$params['minimize'] = false;
2636
+	}
2495 2637
 
2496 2638
 	// Account for shorthand like admin.js?alp21 filenames
2497 2639
 	$has_seed = strpos($fileName, '.js?');
@@ -2508,16 +2650,12 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2510 2652
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2511
-			}
2512
-
2513
-			else
2653
+			} else
2514 2654
 			{
2515 2655
 				$fileUrl = false;
2516 2656
 				$filePath = false;
2517 2657
 			}
2518
-		}
2519
-
2520
-		else
2658
+		} else
2521 2659
 		{
2522 2660
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2523 2661
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2532,9 +2670,10 @@  discard block
 block discarded – undo
2532 2670
 	}
2533 2671
 
2534 2672
 	// Add it to the array for use in the template
2535
-	if (!empty($fileName))
2536
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2537
-}
2673
+	if (!empty($fileName)) {
2674
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2675
+	}
2676
+	}
2538 2677
 
2539 2678
 /**
2540 2679
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2548,9 +2687,10 @@  discard block
 block discarded – undo
2548 2687
 {
2549 2688
 	global $context;
2550 2689
 
2551
-	if (!empty($key) && (!empty($value) || $value === '0'))
2552
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2553
-}
2690
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2691
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2692
+	}
2693
+	}
2554 2694
 
2555 2695
 /**
2556 2696
  * Add a block of inline Javascript code to be executed later
@@ -2567,8 +2707,9 @@  discard block
 block discarded – undo
2567 2707
 {
2568 2708
 	global $context;
2569 2709
 
2570
-	if (empty($javascript))
2571
-		return false;
2710
+	if (empty($javascript)) {
2711
+			return false;
2712
+	}
2572 2713
 
2573 2714
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2574 2715
 }
@@ -2589,15 +2730,18 @@  discard block
 block discarded – undo
2589 2730
 	static $already_loaded = array();
2590 2731
 
2591 2732
 	// Default to the user's language.
2592
-	if ($lang == '')
2593
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2733
+	if ($lang == '') {
2734
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2735
+	}
2594 2736
 
2595 2737
 	// Do we want the English version of language file as fallback?
2596
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2597
-		loadLanguage($template_name, 'english', false);
2738
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2739
+			loadLanguage($template_name, 'english', false);
2740
+	}
2598 2741
 
2599
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2600
-		return $lang;
2742
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2743
+			return $lang;
2744
+	}
2601 2745
 
2602 2746
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2603 2747
 	if (empty($settings['default_theme_dir']))
@@ -2608,8 +2752,9 @@  discard block
 block discarded – undo
2608 2752
 
2609 2753
 	// What theme are we in?
2610 2754
 	$theme_name = basename($settings['theme_url']);
2611
-	if (empty($theme_name))
2612
-		$theme_name = 'unknown';
2755
+	if (empty($theme_name)) {
2756
+			$theme_name = 'unknown';
2757
+	}
2613 2758
 
2614 2759
 	// For each file open it up and write it out!
2615 2760
 	foreach (explode('+', $template_name) as $template)
@@ -2651,8 +2796,9 @@  discard block
 block discarded – undo
2651 2796
 				$found = true;
2652 2797
 
2653 2798
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2654
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2655
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2799
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2800
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2801
+				}
2656 2802
 				
2657 2803
 				break;
2658 2804
 			}
@@ -2692,8 +2838,9 @@  discard block
 block discarded – undo
2692 2838
 	}
2693 2839
 
2694 2840
 	// Keep track of what we're up to soldier.
2695
-	if ($db_show_debug === true)
2696
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2841
+	if ($db_show_debug === true) {
2842
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2843
+	}
2697 2844
 
2698 2845
 	// Remember what we have loaded, and in which language.
2699 2846
 	$already_loaded[$template_name] = $lang;
@@ -2739,8 +2886,9 @@  discard block
 block discarded – undo
2739 2886
 				)
2740 2887
 			);
2741 2888
 			// In the EXTREMELY unlikely event this happens, give an error message.
2742
-			if ($smcFunc['db_num_rows']($result) == 0)
2743
-				fatal_lang_error('parent_not_found', 'critical');
2889
+			if ($smcFunc['db_num_rows']($result) == 0) {
2890
+							fatal_lang_error('parent_not_found', 'critical');
2891
+			}
2744 2892
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2745 2893
 			{
2746 2894
 				if (!isset($boards[$row['id_board']]))
@@ -2757,8 +2905,8 @@  discard block
 block discarded – undo
2757 2905
 					);
2758 2906
 				}
2759 2907
 				// If a moderator exists for this board, add that moderator for all children too.
2760
-				if (!empty($row['id_moderator']))
2761
-					foreach ($boards as $id => $dummy)
2908
+				if (!empty($row['id_moderator'])) {
2909
+									foreach ($boards as $id => $dummy)
2762 2910
 					{
2763 2911
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2764 2912
 							'id' => $row['id_moderator'],
@@ -2766,11 +2914,12 @@  discard block
 block discarded – undo
2766 2914
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2767 2915
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2768 2916
 						);
2917
+				}
2769 2918
 					}
2770 2919
 
2771 2920
 				// If a moderator group exists for this board, add that moderator group for all children too
2772
-				if (!empty($row['id_moderator_group']))
2773
-					foreach ($boards as $id => $dummy)
2921
+				if (!empty($row['id_moderator_group'])) {
2922
+									foreach ($boards as $id => $dummy)
2774 2923
 					{
2775 2924
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2776 2925
 							'id' => $row['id_moderator_group'],
@@ -2778,6 +2927,7 @@  discard block
 block discarded – undo
2778 2927
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2779 2928
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2780 2929
 						);
2930
+				}
2781 2931
 					}
2782 2932
 			}
2783 2933
 			$smcFunc['db_free_result']($result);
@@ -2804,23 +2954,27 @@  discard block
 block discarded – undo
2804 2954
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2805 2955
 	{
2806 2956
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2807
-		if (empty($smcFunc['ucwords']))
2808
-			reloadSettings();
2957
+		if (empty($smcFunc['ucwords'])) {
2958
+					reloadSettings();
2959
+		}
2809 2960
 
2810 2961
 		// If we don't have our theme information yet, let's get it.
2811
-		if (empty($settings['default_theme_dir']))
2812
-			loadTheme(0, false);
2962
+		if (empty($settings['default_theme_dir'])) {
2963
+					loadTheme(0, false);
2964
+		}
2813 2965
 
2814 2966
 		// Default language directories to try.
2815 2967
 		$language_directories = array(
2816 2968
 			$settings['default_theme_dir'] . '/languages',
2817 2969
 		);
2818
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2819
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2970
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2971
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2972
+		}
2820 2973
 
2821 2974
 		// We possibly have a base theme directory.
2822
-		if (!empty($settings['base_theme_dir']))
2823
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2975
+		if (!empty($settings['base_theme_dir'])) {
2976
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2977
+		}
2824 2978
 
2825 2979
 		// Remove any duplicates.
2826 2980
 		$language_directories = array_unique($language_directories);
@@ -2834,20 +2988,21 @@  discard block
 block discarded – undo
2834 2988
 		foreach ($language_directories as $language_dir)
2835 2989
 		{
2836 2990
 			// Can't look in here... doesn't exist!
2837
-			if (!file_exists($language_dir))
2838
-				continue;
2991
+			if (!file_exists($language_dir)) {
2992
+							continue;
2993
+			}
2839 2994
 
2840 2995
 			$dir = dir($language_dir);
2841 2996
 			while ($entry = $dir->read())
2842 2997
 			{
2843 2998
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2844
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2845
-					continue;
2846
-
2847
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2848
-					$langName = $langList[$matches[1]];
2999
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3000
+									continue;
3001
+				}
2849 3002
 
2850
-				else
3003
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3004
+									$langName = $langList[$matches[1]];
3005
+				} else
2851 3006
 				{
2852 3007
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2853 3008
 
@@ -2888,12 +3043,14 @@  discard block
 block discarded – undo
2888 3043
 		}
2889 3044
 
2890 3045
 		// Do we need to store the lang list?
2891
-		if (empty($langList))
2892
-			updateSettings(array('langList' => json_encode($catchLang)));
3046
+		if (empty($langList)) {
3047
+					updateSettings(array('langList' => json_encode($catchLang)));
3048
+		}
2893 3049
 
2894 3050
 		// Let's cash in on this deal.
2895
-		if (!empty($modSettings['cache_enable']))
2896
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3051
+		if (!empty($modSettings['cache_enable'])) {
3052
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3053
+		}
2897 3054
 	}
2898 3055
 
2899 3056
 	return $context['languages'];
@@ -2916,8 +3073,9 @@  discard block
 block discarded – undo
2916 3073
 	global $modSettings, $options, $txt;
2917 3074
 	static $censor_vulgar = null, $censor_proper;
2918 3075
 
2919
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2920
-		return $text;
3076
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3077
+			return $text;
3078
+	}
2921 3079
 
2922 3080
 	// If they haven't yet been loaded, load them.
2923 3081
 	if ($censor_vulgar == null)
@@ -2945,9 +3103,9 @@  discard block
 block discarded – undo
2945 3103
 	{
2946 3104
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2947 3105
 		$text = $func($censor_vulgar, $censor_proper, $text);
3106
+	} else {
3107
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2948 3108
 	}
2949
-	else
2950
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2951 3109
 
2952 3110
 	return $text;
2953 3111
 }
@@ -2973,38 +3131,42 @@  discard block
 block discarded – undo
2973 3131
 	@ini_set('track_errors', '1');
2974 3132
 
2975 3133
 	// Don't include the file more than once, if $once is true.
2976
-	if ($once && in_array($filename, $templates))
2977
-		return;
3134
+	if ($once && in_array($filename, $templates)) {
3135
+			return;
3136
+	}
2978 3137
 	// Add this file to the include list, whether $once is true or not.
2979
-	else
2980
-		$templates[] = $filename;
3138
+	else {
3139
+			$templates[] = $filename;
3140
+	}
2981 3141
 
2982 3142
 	// Are we going to use eval?
2983 3143
 	if (empty($modSettings['disableTemplateEval']))
2984 3144
 	{
2985 3145
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2986 3146
 		$settings['current_include_filename'] = $filename;
2987
-	}
2988
-	else
3147
+	} else
2989 3148
 	{
2990 3149
 		$file_found = file_exists($filename);
2991 3150
 
2992
-		if ($once && $file_found)
2993
-			require_once($filename);
2994
-		elseif ($file_found)
2995
-			require($filename);
3151
+		if ($once && $file_found) {
3152
+					require_once($filename);
3153
+		} elseif ($file_found) {
3154
+					require($filename);
3155
+		}
2996 3156
 	}
2997 3157
 
2998 3158
 	if ($file_found !== true)
2999 3159
 	{
3000 3160
 		ob_end_clean();
3001
-		if (!empty($modSettings['enableCompressedOutput']))
3002
-			@ob_start('ob_gzhandler');
3003
-		else
3004
-			ob_start();
3161
+		if (!empty($modSettings['enableCompressedOutput'])) {
3162
+					@ob_start('ob_gzhandler');
3163
+		} else {
3164
+					ob_start();
3165
+		}
3005 3166
 
3006
-		if (isset($_GET['debug']))
3007
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3167
+		if (isset($_GET['debug'])) {
3168
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3169
+		}
3008 3170
 
3009 3171
 		// Don't cache error pages!!
3010 3172
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3023,12 +3185,13 @@  discard block
 block discarded – undo
3023 3185
 		echo '<!DOCTYPE html>
3024 3186
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3025 3187
 	<head>';
3026
-		if (isset($context['character_set']))
3027
-			echo '
3188
+		if (isset($context['character_set'])) {
3189
+					echo '
3028 3190
 		<meta charset="', $context['character_set'], '">';
3191
+		}
3029 3192
 
3030
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3031
-			echo '
3193
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3194
+					echo '
3032 3195
 		<title>', $mtitle, '</title>
3033 3196
 	</head>
3034 3197
 	<body>
@@ -3036,8 +3199,8 @@  discard block
 block discarded – undo
3036 3199
 		', $mmessage, '
3037 3200
 	</body>
3038 3201
 </html>';
3039
-		elseif (!allowedTo('admin_forum'))
3040
-			echo '
3202
+		} elseif (!allowedTo('admin_forum')) {
3203
+					echo '
3041 3204
 		<title>', $txt['template_parse_error'], '</title>
3042 3205
 	</head>
3043 3206
 	<body>
@@ -3045,15 +3208,17 @@  discard block
 block discarded – undo
3045 3208
 		', $txt['template_parse_error_message'], '
3046 3209
 	</body>
3047 3210
 </html>';
3048
-		else
3211
+		} else
3049 3212
 		{
3050 3213
 			require_once($sourcedir . '/Subs-Package.php');
3051 3214
 
3052 3215
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3053
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3054
-				$error = $php_errormsg;
3055
-			if (empty($error))
3056
-				$error = $txt['template_parse_errmsg'];
3216
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3217
+							$error = $php_errormsg;
3218
+			}
3219
+			if (empty($error)) {
3220
+							$error = $txt['template_parse_errmsg'];
3221
+			}
3057 3222
 
3058 3223
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3059 3224
 
@@ -3064,11 +3229,12 @@  discard block
 block discarded – undo
3064 3229
 		<h3>', $txt['template_parse_error'], '</h3>
3065 3230
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3066 3231
 
3067
-			if (!empty($error))
3068
-				echo '
3232
+			if (!empty($error)) {
3233
+							echo '
3069 3234
 		<hr>
3070 3235
 
3071 3236
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3237
+			}
3072 3238
 
3073 3239
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3074 3240
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3078,10 +3244,11 @@  discard block
 block discarded – undo
3078 3244
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3079 3245
 
3080 3246
 				// Fix the PHP code stuff...
3081
-				if (!isBrowser('gecko'))
3082
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3083
-				else
3084
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3247
+				if (!isBrowser('gecko')) {
3248
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3249
+				} else {
3250
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3251
+				}
3085 3252
 
3086 3253
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3087 3254
 				$j = -1;
@@ -3089,8 +3256,9 @@  discard block
 block discarded – undo
3089 3256
 				{
3090 3257
 					$j++;
3091 3258
 
3092
-					if (substr_count($line, '<br>') == 0)
3093
-						continue;
3259
+					if (substr_count($line, '<br>') == 0) {
3260
+											continue;
3261
+					}
3094 3262
 
3095 3263
 					$n = substr_count($line, '<br>');
3096 3264
 					for ($i = 0; $i < $n; $i++)
@@ -3109,38 +3277,42 @@  discard block
 block discarded – undo
3109 3277
 				// Figure out what the color coding was before...
3110 3278
 				$line = max($match[1] - 9, 1);
3111 3279
 				$last_line = '';
3112
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3113
-					if (strpos($data2[$line2], '<') !== false)
3280
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3281
+									if (strpos($data2[$line2], '<') !== false)
3114 3282
 					{
3115 3283
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3116 3284
 							$last_line = $color_match[1];
3285
+				}
3117 3286
 						break;
3118 3287
 					}
3119 3288
 
3120 3289
 				// Show the relevant lines...
3121 3290
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3122 3291
 				{
3123
-					if ($line == $match[1])
3124
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3292
+					if ($line == $match[1]) {
3293
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3294
+					}
3125 3295
 
3126 3296
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3127
-					if (isset($data2[$line]) && $data2[$line] != '')
3128
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3297
+					if (isset($data2[$line]) && $data2[$line] != '') {
3298
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3299
+					}
3129 3300
 
3130 3301
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3131 3302
 					{
3132 3303
 						$last_line = $color_match[1];
3133 3304
 						echo '</', substr($last_line, 1, 4), '>';
3305
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3306
+											$last_line = '';
3307
+					} elseif ($last_line != '' && $data2[$line] != '') {
3308
+											echo '</', substr($last_line, 1, 4), '>';
3134 3309
 					}
3135
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3136
-						$last_line = '';
3137
-					elseif ($last_line != '' && $data2[$line] != '')
3138
-						echo '</', substr($last_line, 1, 4), '>';
3139 3310
 
3140
-					if ($line == $match[1])
3141
-						echo '</pre></div><pre style="margin: 0;">';
3142
-					else
3143
-						echo "\n";
3311
+					if ($line == $match[1]) {
3312
+											echo '</pre></div><pre style="margin: 0;">';
3313
+					} else {
3314
+											echo "\n";
3315
+					}
3144 3316
 				}
3145 3317
 
3146 3318
 				echo '</pre></div>';
@@ -3164,8 +3336,9 @@  discard block
 block discarded – undo
3164 3336
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3165 3337
 
3166 3338
 	// Figure out what type of database we are using.
3167
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3168
-		$db_type = 'mysql';
3339
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3340
+			$db_type = 'mysql';
3341
+	}
3169 3342
 
3170 3343
 	// Load the file for the database.
3171 3344
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3173,8 +3346,9 @@  discard block
 block discarded – undo
3173 3346
 	$db_options = array();
3174 3347
 
3175 3348
 	// Add in the port if needed
3176
-	if (!empty($db_port))
3177
-		$db_options['port'] = $db_port;
3349
+	if (!empty($db_port)) {
3350
+			$db_options['port'] = $db_port;
3351
+	}
3178 3352
 
3179 3353
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3180 3354
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3193,13 +3367,15 @@  discard block
 block discarded – undo
3193 3367
 	}
3194 3368
 
3195 3369
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3196
-	if (!$db_connection)
3197
-		display_db_error();
3370
+	if (!$db_connection) {
3371
+			display_db_error();
3372
+	}
3198 3373
 
3199 3374
 	// If in SSI mode fix up the prefix.
3200
-	if (SMF == 'SSI')
3201
-		db_fix_prefix($db_prefix, $db_name);
3202
-}
3375
+	if (SMF == 'SSI') {
3376
+			db_fix_prefix($db_prefix, $db_name);
3377
+	}
3378
+	}
3203 3379
 
3204 3380
 /**
3205 3381
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3213,10 +3389,11 @@  discard block
 block discarded – undo
3213 3389
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3214 3390
 
3215 3391
 	// Not overriding this and we have a cacheAPI, send it back.
3216
-	if (empty($overrideCache) && is_object($cacheAPI))
3217
-		return $cacheAPI;
3218
-	elseif (is_null($cacheAPI))
3219
-		$cacheAPI = false;
3392
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3393
+			return $cacheAPI;
3394
+	} elseif (is_null($cacheAPI)) {
3395
+			$cacheAPI = false;
3396
+	}
3220 3397
 
3221 3398
 	// Make sure our class is in session.
3222 3399
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3237,8 +3414,9 @@  discard block
 block discarded – undo
3237 3414
 		if (!$testAPI->isSupported())
3238 3415
 		{
3239 3416
 			// Can we save ourselves?
3240
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3241
-				return loadCacheAccelerator(null, false);
3417
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3418
+							return loadCacheAccelerator(null, false);
3419
+			}
3242 3420
 			return false;
3243 3421
 		}
3244 3422
 
@@ -3250,9 +3428,9 @@  discard block
 block discarded – undo
3250 3428
 		{
3251 3429
 			$cacheAPI = $testAPI;
3252 3430
 			return $cacheAPI;
3431
+		} else {
3432
+					return $testAPI;
3253 3433
 		}
3254
-		else
3255
-			return $testAPI;
3256 3434
 	}
3257 3435
 }
3258 3436
 
@@ -3272,8 +3450,9 @@  discard block
 block discarded – undo
3272 3450
 
3273 3451
 	// @todo Why are we doing this if caching is disabled?
3274 3452
 
3275
-	if (function_exists('call_integration_hook'))
3276
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3453
+	if (function_exists('call_integration_hook')) {
3454
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3455
+	}
3277 3456
 
3278 3457
 	/* Refresh the cache if either:
3279 3458
 		1. Caching is disabled.
@@ -3287,16 +3466,19 @@  discard block
 block discarded – undo
3287 3466
 		require_once($sourcedir . '/' . $file);
3288 3467
 		$cache_block = call_user_func_array($function, $params);
3289 3468
 
3290
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3291
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3469
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3470
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3471
+		}
3292 3472
 	}
3293 3473
 
3294 3474
 	// Some cached data may need a freshening up after retrieval.
3295
-	if (!empty($cache_block['post_retri_eval']))
3296
-		eval($cache_block['post_retri_eval']);
3475
+	if (!empty($cache_block['post_retri_eval'])) {
3476
+			eval($cache_block['post_retri_eval']);
3477
+	}
3297 3478
 
3298
-	if (function_exists('call_integration_hook'))
3299
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3479
+	if (function_exists('call_integration_hook')) {
3480
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3481
+	}
3300 3482
 
3301 3483
 	return $cache_block['data'];
3302 3484
 }
@@ -3323,8 +3505,9 @@  discard block
 block discarded – undo
3323 3505
 	global $cache_enable, $cacheAPI;
3324 3506
 	global $cache_hits, $cache_count, $db_show_debug;
3325 3507
 
3326
-	if (empty($cache_enable) || empty($cacheAPI))
3327
-		return;
3508
+	if (empty($cache_enable) || empty($cacheAPI)) {
3509
+			return;
3510
+	}
3328 3511
 
3329 3512
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3330 3513
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3337,12 +3520,14 @@  discard block
 block discarded – undo
3337 3520
 	$value = $value === null ? null : json_encode($value);
3338 3521
 	$cacheAPI->putData($key, $value, $ttl);
3339 3522
 
3340
-	if (function_exists('call_integration_hook'))
3341
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3523
+	if (function_exists('call_integration_hook')) {
3524
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3525
+	}
3342 3526
 
3343
-	if (isset($db_show_debug) && $db_show_debug === true)
3344
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3345
-}
3527
+	if (isset($db_show_debug) && $db_show_debug === true) {
3528
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3529
+	}
3530
+	}
3346 3531
 
3347 3532
 /**
3348 3533
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3358,8 +3543,9 @@  discard block
 block discarded – undo
3358 3543
 	global $cache_enable, $cacheAPI;
3359 3544
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3360 3545
 
3361
-	if (empty($cache_enable) || empty($cacheAPI))
3362
-		return;
3546
+	if (empty($cache_enable) || empty($cacheAPI)) {
3547
+			return;
3548
+	}
3363 3549
 
3364 3550
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3365 3551
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3379,16 +3565,18 @@  discard block
 block discarded – undo
3379 3565
 
3380 3566
 		if (empty($value))
3381 3567
 		{
3382
-			if (!is_array($cache_misses))
3383
-				$cache_misses = array();
3568
+			if (!is_array($cache_misses)) {
3569
+							$cache_misses = array();
3570
+			}
3384 3571
 
3385 3572
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3386 3573
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3387 3574
 		}
3388 3575
 	}
3389 3576
 
3390
-	if (function_exists('call_integration_hook') && isset($value))
3391
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3577
+	if (function_exists('call_integration_hook') && isset($value)) {
3578
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3579
+	}
3392 3580
 
3393 3581
 	return empty($value) ? null : smf_json_decode($value, true);
3394 3582
 }
@@ -3410,8 +3598,9 @@  discard block
 block discarded – undo
3410 3598
 	global $cacheAPI;
3411 3599
 
3412 3600
 	// If we can't get to the API, can't do this.
3413
-	if (empty($cacheAPI))
3414
-		return;
3601
+	if (empty($cacheAPI)) {
3602
+			return;
3603
+	}
3415 3604
 
3416 3605
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3417 3606
 	$cacheAPI->cleanCache($type);
@@ -3436,8 +3625,9 @@  discard block
 block discarded – undo
3436 3625
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3437 3626
 
3438 3627
 	// Come on!
3439
-	if (empty($data))
3440
-		return array();
3628
+	if (empty($data)) {
3629
+			return array();
3630
+	}
3441 3631
 
3442 3632
 	// Set a nice default var.
3443 3633
 	$image = '';
@@ -3445,11 +3635,11 @@  discard block
 block discarded – undo
3445 3635
 	// Gravatar has been set as mandatory!
3446 3636
 	if (!empty($modSettings['gravatarOverride']))
3447 3637
 	{
3448
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3449
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3450
-
3451
-		else if (!empty($data['email']))
3452
-			$image = get_gravatar_url($data['email']);
3638
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3639
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3640
+		} else if (!empty($data['email'])) {
3641
+					$image = get_gravatar_url($data['email']);
3642
+		}
3453 3643
 	}
3454 3644
 
3455 3645
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3461,54 +3651,60 @@  discard block
 block discarded – undo
3461 3651
 			// Gravatar.
3462 3652
 			if (stristr($data['avatar'], 'gravatar://'))
3463 3653
 			{
3464
-				if ($data['avatar'] == 'gravatar://')
3465
-					$image = get_gravatar_url($data['email']);
3466
-
3467
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3468
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3654
+				if ($data['avatar'] == 'gravatar://') {
3655
+									$image = get_gravatar_url($data['email']);
3656
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3657
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+				}
3469 3659
 			}
3470 3660
 
3471 3661
 			// External url.
3472 3662
 			else
3473 3663
 			{
3474 3664
 				// Using ssl?
3475
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3476
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3665
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3666
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3667
+				}
3477 3668
 
3478 3669
 				// Just a plain external url.
3479
-				else
3480
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3670
+				else {
3671
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3672
+				}
3481 3673
 			}
3482 3674
 		}
3483 3675
 
3484 3676
 		// Perhaps this user has an attachment as avatar...
3485
-		else if (!empty($data['filename']))
3486
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3677
+		else if (!empty($data['filename'])) {
3678
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3679
+		}
3487 3680
 
3488 3681
 		// Right... no avatar... use our default image.
3489
-		else
3490
-			$image = $modSettings['avatar_url'] . '/default.png';
3682
+		else {
3683
+					$image = $modSettings['avatar_url'] . '/default.png';
3684
+		}
3491 3685
 	}
3492 3686
 
3493 3687
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3494 3688
 
3495 3689
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3496
-	if (!empty($image))
3497
-		return array(
3690
+	if (!empty($image)) {
3691
+			return array(
3498 3692
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3499 3693
 			'image' => '<img class="avatar" src="' . $image . '" />',
3500 3694
 			'href' => $image,
3501 3695
 			'url' => $image,
3502 3696
 		);
3697
+	}
3503 3698
 
3504 3699
 	// Fallback to make life easier for everyone...
3505
-	else
3506
-		return array(
3700
+	else {
3701
+			return array(
3507 3702
 			'name' => '',
3508 3703
 			'image' => '',
3509 3704
 			'href' => '',
3510 3705
 			'url' => '',
3511 3706
 		);
3512
-}
3707
+	}
3708
+	}
3513 3709
 
3514 3710
 ?>
3515 3711
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +254 added lines, -187 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 
@@ -71,31 +74,35 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
94
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
95
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
100
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
101
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
96 102
 		array(),
97 103
 		false
98 104
 	);
105
+	}
99 106
 
100 107
 	return $connection;
101 108
 }
@@ -166,38 +173,46 @@  discard block
 block discarded – undo
166 173
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
167 174
 
168 175
 	list ($values, $connection) = $db_callback;
169
-	if (!is_object($connection))
170
-		display_db_error();
176
+	if (!is_object($connection)) {
177
+			display_db_error();
178
+	}
171 179
 
172
-	if ($matches[1] === 'db_prefix')
173
-		return $db_prefix;
180
+	if ($matches[1] === 'db_prefix') {
181
+			return $db_prefix;
182
+	}
174 183
 
175 184
 	if (!empty($user_info))
176 185
 	{
177
-		foreach (array_keys($user_info) as $key)
178
-			if (strpos($key, 'query_') !== false && $key === $matches[1])
186
+		foreach (array_keys($user_info) as $key) {
187
+					if (strpos($key, 'query_') !== false && $key === $matches[1])
179 188
 				return $user_info[$matches[1]];
189
+		}
180 190
 	}
181 191
 
182
-	if ($matches[1] === 'empty')
183
-		return '\'\'';
192
+	if ($matches[1] === 'empty') {
193
+			return '\'\'';
194
+	}
184 195
 
185
-	if (!isset($matches[2]))
186
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	if (!isset($matches[2])) {
197
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
198
+	}
187 199
 
188
-	if ($matches[1] === 'literal')
189
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	if ($matches[1] === 'literal') {
201
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
202
+	}
190 203
 
191
-	if (!isset($values[$matches[2]]))
192
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	if (!isset($values[$matches[2]])) {
205
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
206
+	}
193 207
 
194 208
 	$replacement = $values[$matches[2]];
195 209
 
196 210
 	switch ($matches[1])
197 211
 	{
198 212
 		case 'int':
199
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
200
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
214
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
215
+			}
201 216
 			return (string) (int) $replacement;
202 217
 		break;
203 218
 
@@ -209,65 +224,73 @@  discard block
 block discarded – undo
209 224
 		case 'array_int':
210 225
 			if (is_array($replacement))
211 226
 			{
212
-				if (empty($replacement))
213
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				if (empty($replacement)) {
228
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+				}
214 230
 
215 231
 				foreach ($replacement as $key => $value)
216 232
 				{
217
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
218
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
234
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
235
+					}
219 236
 
220 237
 					$replacement[$key] = (string) (int) $value;
221 238
 				}
222 239
 
223 240
 				return implode(', ', $replacement);
241
+			} else {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 243
 			}
225
-			else
226
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227 244
 
228 245
 		break;
229 246
 
230 247
 		case 'array_string':
231 248
 			if (is_array($replacement))
232 249
 			{
233
-				if (empty($replacement))
234
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				if (empty($replacement)) {
251
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+				}
235 253
 
236
-				foreach ($replacement as $key => $value)
237
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				foreach ($replacement as $key => $value) {
255
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
256
+				}
238 257
 
239 258
 				return implode(', ', $replacement);
259
+			} else {
260
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 261
 			}
241
-			else
242
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243 262
 		break;
244 263
 
245 264
 		case 'date':
246
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
247
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
248
-			else
249
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
266
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
267
+			} else {
268
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+			}
250 270
 		break;
251 271
 
252 272
 		case 'time':
253
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
254
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
255
-			else
256
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
274
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
275
+			} else {
276
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+			}
257 278
 		break;
258 279
 
259 280
 		case 'datetime':
260
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
261
-				return 'str_to_date('.
281
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
282
+							return 'str_to_date('.
262 283
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
263 284
 					',\'%Y-%m-%d %h:%i:%s\')';
264
-			else
265
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
285
+			} else {
286
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+			}
266 288
 		break;
267 289
 
268 290
 		case 'float':
269
-			if (!is_numeric($replacement))
270
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
291
+			if (!is_numeric($replacement)) {
292
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
293
+			}
271 294
 			return (string) (float) $replacement;
272 295
 		break;
273 296
 
@@ -281,32 +304,37 @@  discard block
 block discarded – undo
281 304
 		break;
282 305
 
283 306
 		case 'inet':
284
-			if ($replacement == 'null' || $replacement == '')
285
-				return 'null';
286
-			if (!isValidIP($replacement))
287
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+			if ($replacement == 'null' || $replacement == '') {
308
+							return 'null';
309
+			}
310
+			if (!isValidIP($replacement)) {
311
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
312
+			}
288 313
 			//we don't use the native support of mysql > 5.6.2
289 314
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
290 315
 
291 316
 		case 'array_inet':
292 317
 			if (is_array($replacement))
293 318
 			{
294
-				if (empty($replacement))
295
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
319
+				if (empty($replacement)) {
320
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
321
+				}
296 322
 
297 323
 				foreach ($replacement as $key => $value)
298 324
 				{
299
-					if ($replacement == 'null' || $replacement == '')
300
-						$replacement[$key] = 'null';
301
-					if (!isValidIP($value))
302
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+					if ($replacement == 'null' || $replacement == '') {
326
+											$replacement[$key] = 'null';
327
+					}
328
+					if (!isValidIP($value)) {
329
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
330
+					}
303 331
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
304 332
 				}
305 333
 
306 334
 				return implode(', ', $replacement);
335
+			} else {
336
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307 337
 			}
308
-			else
309
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
310 338
 		break;
311 339
 
312 340
 		default:
@@ -382,22 +410,25 @@  discard block
 block discarded – undo
382 410
 		// Are we in SSI mode?  If so try that username and password first
383 411
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
384 412
 		{
385
-			if (empty($db_persist))
386
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
387
-			else
388
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
413
+			if (empty($db_persist)) {
414
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
415
+			} else {
416
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
417
+			}
389 418
 		}
390 419
 		// Fall back to the regular username and password if need be
391 420
 		if (!$db_connection)
392 421
 		{
393
-			if (empty($db_persist))
394
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
395
-			else
396
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
422
+			if (empty($db_persist)) {
423
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
424
+			} else {
425
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
426
+			}
397 427
 		}
398 428
 
399
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
400
-			$db_connection = false;
429
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
430
+					$db_connection = false;
431
+		}
401 432
 
402 433
 		$connection = $db_connection;
403 434
 	}
@@ -405,18 +436,20 @@  discard block
 block discarded – undo
405 436
 	// One more query....
406 437
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
407 438
 
408
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
409
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
439
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
440
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
441
+	}
410 442
 
411 443
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
412 444
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
413 445
 	{
414 446
 		// Add before LIMIT
415
-		if ($pos = strpos($db_string, 'LIMIT '))
416
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
417
-		else
418
-			// Append it.
447
+		if ($pos = strpos($db_string, 'LIMIT ')) {
448
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
449
+		} else {
450
+					// Append it.
419 451
 			$db_string .= "\n\t\t\tORDER BY null";
452
+		}
420 453
 	}
421 454
 
422 455
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -438,8 +471,9 @@  discard block
 block discarded – undo
438 471
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
439 472
 
440 473
 		// Initialize $db_cache if not already initialized.
441
-		if (!isset($db_cache))
442
-			$db_cache = array();
474
+		if (!isset($db_cache)) {
475
+					$db_cache = array();
476
+		}
443 477
 
444 478
 		if (!empty($_SESSION['debug_redirect']))
445 479
 		{
@@ -465,17 +499,18 @@  discard block
 block discarded – undo
465 499
 		while (true)
466 500
 		{
467 501
 			$pos = strpos($db_string, '\'', $pos + 1);
468
-			if ($pos === false)
469
-				break;
502
+			if ($pos === false) {
503
+							break;
504
+			}
470 505
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
471 506
 
472 507
 			while (true)
473 508
 			{
474 509
 				$pos1 = strpos($db_string, '\'', $pos + 1);
475 510
 				$pos2 = strpos($db_string, '\\', $pos + 1);
476
-				if ($pos1 === false)
477
-					break;
478
-				elseif ($pos2 === false || $pos2 > $pos1)
511
+				if ($pos1 === false) {
512
+									break;
513
+				} elseif ($pos2 === false || $pos2 > $pos1)
479 514
 				{
480 515
 					$pos = $pos1;
481 516
 					break;
@@ -491,29 +526,35 @@  discard block
 block discarded – undo
491 526
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
492 527
 
493 528
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
494
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
495
-			$fail = true;
529
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
530
+					$fail = true;
531
+		}
496 532
 		// Trying to change passwords, slow us down, or something?
497
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
498
-			$fail = true;
499
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
500
-			$fail = true;
533
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
534
+					$fail = true;
535
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
536
+					$fail = true;
537
+		}
501 538
 
502
-		if (!empty($fail) && function_exists('log_error'))
503
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
539
+		if (!empty($fail) && function_exists('log_error')) {
540
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
541
+		}
504 542
 	}
505 543
 
506
-	if (empty($db_unbuffered))
507
-		$ret = @mysqli_query($connection, $db_string);
508
-	else
509
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
544
+	if (empty($db_unbuffered)) {
545
+			$ret = @mysqli_query($connection, $db_string);
546
+	} else {
547
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
548
+	}
510 549
 
511
-	if ($ret === false && empty($db_values['db_error_skip']))
512
-		$ret = smf_db_error($db_string, $connection);
550
+	if ($ret === false && empty($db_values['db_error_skip'])) {
551
+			$ret = smf_db_error($db_string, $connection);
552
+	}
513 553
 
514 554
 	// Debugging.
515
-	if (isset($db_show_debug) && $db_show_debug === true)
516
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
555
+	if (isset($db_show_debug) && $db_show_debug === true) {
556
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
557
+	}
517 558
 
518 559
 	return $ret;
519 560
 }
@@ -560,12 +601,13 @@  discard block
 block discarded – undo
560 601
 	// Decide which connection to use
561 602
 	$connection = $connection === null ? $db_connection : $connection;
562 603
 
563
-	if ($type == 'begin')
564
-		return @mysqli_query($connection, 'BEGIN');
565
-	elseif ($type == 'rollback')
566
-		return @mysqli_query($connection, 'ROLLBACK');
567
-	elseif ($type == 'commit')
568
-		return @mysqli_query($connection, 'COMMIT');
604
+	if ($type == 'begin') {
605
+			return @mysqli_query($connection, 'BEGIN');
606
+	} elseif ($type == 'rollback') {
607
+			return @mysqli_query($connection, 'ROLLBACK');
608
+	} elseif ($type == 'commit') {
609
+			return @mysqli_query($connection, 'COMMIT');
610
+	}
569 611
 
570 612
 	return false;
571 613
 }
@@ -605,8 +647,9 @@  discard block
 block discarded – undo
605 647
 	//    2013: Lost connection to server during query.
606 648
 
607 649
 	// Log the error.
608
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
609
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
650
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
651
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
652
+	}
610 653
 
611 654
 	// Database error auto fixing ;).
612 655
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -615,8 +658,9 @@  discard block
 block discarded – undo
615 658
 		$old_cache = @$modSettings['cache_enable'];
616 659
 		$modSettings['cache_enable'] = '1';
617 660
 
618
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
619
-			$db_last_error = max(@$db_last_error, $temp);
661
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
662
+					$db_last_error = max(@$db_last_error, $temp);
663
+		}
620 664
 
621 665
 		if (@$db_last_error < time() - 3600 * 24 * 3)
622 666
 		{
@@ -632,8 +676,9 @@  discard block
 block discarded – undo
632 676
 					foreach ($tables as $table)
633 677
 					{
634 678
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
635
-						if (trim($table) != '')
636
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
679
+						if (trim($table) != '') {
680
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
681
+						}
637 682
 					}
638 683
 				}
639 684
 
@@ -642,8 +687,9 @@  discard block
 block discarded – undo
642 687
 			// Table crashed.  Let's try to fix it.
643 688
 			elseif ($query_errno == 1016)
644 689
 			{
645
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
646
-					$fix_tables = array('`' . $match[1] . '`');
690
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
691
+									$fix_tables = array('`' . $match[1] . '`');
692
+				}
647 693
 			}
648 694
 			// Indexes crashed.  Should be easy to fix!
649 695
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -662,13 +708,15 @@  discard block
 block discarded – undo
662 708
 
663 709
 			// Make a note of the REPAIR...
664 710
 			cache_put_data('db_last_error', time(), 600);
665
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
666
-				updateSettingsFile(array('db_last_error' => time()));
711
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
712
+							updateSettingsFile(array('db_last_error' => time()));
713
+			}
667 714
 
668 715
 			// Attempt to find and repair the broken table.
669
-			foreach ($fix_tables as $table)
670
-				$smcFunc['db_query']('', "
716
+			foreach ($fix_tables as $table) {
717
+							$smcFunc['db_query']('', "
671 718
 					REPAIR TABLE $table", false, false);
719
+			}
672 720
 
673 721
 			// And send off an email!
674 722
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -677,11 +725,12 @@  discard block
 block discarded – undo
677 725
 
678 726
 			// Try the query again...?
679 727
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
680
-			if ($ret !== false)
681
-				return $ret;
728
+			if ($ret !== false) {
729
+							return $ret;
730
+			}
731
+		} else {
732
+					$modSettings['cache_enable'] = $old_cache;
682 733
 		}
683
-		else
684
-			$modSettings['cache_enable'] = $old_cache;
685 734
 
686 735
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
687 736
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -691,22 +740,25 @@  discard block
 block discarded – undo
691 740
 				// Are we in SSI mode?  If so try that username and password first
692 741
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
693 742
 				{
694
-					if (empty($db_persist))
695
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
696
-					else
697
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
743
+					if (empty($db_persist)) {
744
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
745
+					} else {
746
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
747
+					}
698 748
 				}
699 749
 				// Fall back to the regular username and password if need be
700 750
 				if (!$db_connection)
701 751
 				{
702
-					if (empty($db_persist))
703
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
704
-					else
705
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
752
+					if (empty($db_persist)) {
753
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
754
+					} else {
755
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
756
+					}
706 757
 				}
707 758
 
708
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
709
-					$db_connection = false;
759
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
760
+									$db_connection = false;
761
+				}
710 762
 			}
711 763
 
712 764
 			if ($db_connection)
@@ -717,24 +769,27 @@  discard block
 block discarded – undo
717 769
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
718 770
 
719 771
 					$new_errno = mysqli_errno($db_connection);
720
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
721
-						break;
772
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
773
+											break;
774
+					}
722 775
 				}
723 776
 
724 777
 				// If it failed again, shucks to be you... we're not trying it over and over.
725
-				if ($ret !== false)
726
-					return $ret;
778
+				if ($ret !== false) {
779
+									return $ret;
780
+				}
727 781
 			}
728 782
 		}
729 783
 		// Are they out of space, perhaps?
730 784
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
731 785
 		{
732
-			if (!isset($txt))
733
-				$query_error .= ' - check database storage space.';
734
-			else
786
+			if (!isset($txt)) {
787
+							$query_error .= ' - check database storage space.';
788
+			} else
735 789
 			{
736
-				if (!isset($txt['mysql_error_space']))
737
-					loadLanguage('Errors');
790
+				if (!isset($txt['mysql_error_space'])) {
791
+									loadLanguage('Errors');
792
+				}
738 793
 
739 794
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
740 795
 			}
@@ -742,15 +797,17 @@  discard block
 block discarded – undo
742 797
 	}
743 798
 
744 799
 	// Nothing's defined yet... just die with it.
745
-	if (empty($context) || empty($txt))
746
-		die($query_error);
800
+	if (empty($context) || empty($txt)) {
801
+			die($query_error);
802
+	}
747 803
 
748 804
 	// Show an error message, if possible.
749 805
 	$context['error_title'] = $txt['database_error'];
750
-	if (allowedTo('admin_forum'))
751
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
752
-	else
753
-		$context['error_message'] = $txt['try_again'];
806
+	if (allowedTo('admin_forum')) {
807
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
808
+	} else {
809
+			$context['error_message'] = $txt['try_again'];
810
+	}
754 811
 
755 812
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
756 813
 	{
@@ -780,25 +837,28 @@  discard block
 block discarded – undo
780 837
 	$connection = $connection === null ? $db_connection : $connection;
781 838
 
782 839
 	// With nothing to insert, simply return.
783
-	if (empty($data))
784
-		return;
840
+	if (empty($data)) {
841
+			return;
842
+	}
785 843
 
786 844
 	// Replace the prefix holder with the actual prefix.
787 845
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
788 846
 
789 847
 	// Inserting data as a single row can be done as a single array.
790
-	if (!is_array($data[array_rand($data)]))
791
-		$data = array($data);
848
+	if (!is_array($data[array_rand($data)])) {
849
+			$data = array($data);
850
+	}
792 851
 
793 852
 	// Create the mold for a single row insert.
794 853
 	$insertData = '(';
795 854
 	foreach ($columns as $columnName => $type)
796 855
 	{
797 856
 		// Are we restricting the length?
798
-		if (strpos($type, 'string-') !== false)
799
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
800
-		else
801
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
857
+		if (strpos($type, 'string-') !== false) {
858
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
859
+		} else {
860
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
861
+		}
802 862
 	}
803 863
 	$insertData = substr($insertData, 0, -2) . ')';
804 864
 
@@ -807,8 +867,9 @@  discard block
 block discarded – undo
807 867
 
808 868
 	// Here's where the variables are injected to the query.
809 869
 	$insertRows = array();
810
-	foreach ($data as $dataRow)
811
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
870
+	foreach ($data as $dataRow) {
871
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
872
+	}
812 873
 
813 874
 	// Determine the method of insertion.
814 875
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -828,15 +889,16 @@  discard block
 block discarded – undo
828 889
 
829 890
 	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
830 891
 	{
831
-		if ($returnmode == 1)
832
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
833
-		else if ($returnmode == 2)
892
+		if ($returnmode == 1) {
893
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
894
+		} else if ($returnmode == 2)
834 895
 		{
835 896
 			$return_var = array();
836 897
 			$count = count($insertRows);
837 898
 			$start = smf_db_insert_id($table, $keys[0]);
838
-			for ($i = 0; $i < $count; $i++ )
839
-				$return_var[] = $start + $i;
899
+			for ($i = 0; $i < $count; $i++ ) {
900
+							$return_var[] = $start + $i;
901
+			}
840 902
 		}
841 903
 		return $return_var;
842 904
 	}
@@ -854,8 +916,9 @@  discard block
 block discarded – undo
854 916
  */
855 917
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
856 918
 {
857
-	if (empty($log_message))
858
-		$log_message = $error_message;
919
+	if (empty($log_message)) {
920
+			$log_message = $error_message;
921
+	}
859 922
 
860 923
 	foreach (debug_backtrace() as $step)
861 924
 	{
@@ -874,12 +937,14 @@  discard block
 block discarded – undo
874 937
 	}
875 938
 
876 939
 	// A special case - we want the file and line numbers for debugging.
877
-	if ($error_type == 'return')
878
-		return array($file, $line);
940
+	if ($error_type == 'return') {
941
+			return array($file, $line);
942
+	}
879 943
 
880 944
 	// Is always a critical error.
881
-	if (function_exists('log_error'))
882
-		log_error($log_message, 'critical', $file, $line);
945
+	if (function_exists('log_error')) {
946
+			log_error($log_message, 'critical', $file, $line);
947
+	}
883 948
 
884 949
 	if (function_exists('fatal_error'))
885 950
 	{
@@ -887,12 +952,12 @@  discard block
 block discarded – undo
887 952
 
888 953
 		// Cannot continue...
889 954
 		exit;
955
+	} elseif ($error_type) {
956
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
957
+	} else {
958
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
959
+	}
890 960
 	}
891
-	elseif ($error_type)
892
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
893
-	else
894
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
895
-}
896 961
 
897 962
 /**
898 963
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -909,10 +974,11 @@  discard block
 block discarded – undo
909 974
 		'\\' => '\\\\',
910 975
 	);
911 976
 
912
-	if ($translate_human_wildcards)
913
-		$replacements += array(
977
+	if ($translate_human_wildcards) {
978
+			$replacements += array(
914 979
 			'*' => '%',
915 980
 		);
981
+	}
916 982
 
917 983
 	return strtr($string, $replacements);
918 984
 }
@@ -926,8 +992,9 @@  discard block
 block discarded – undo
926 992
  */
927 993
 function smf_is_resource($result)
928 994
 {
929
-	if ($result instanceof mysqli_result)
930
-		return true;
995
+	if ($result instanceof mysqli_result) {
996
+			return true;
997
+	}
931 998
 
932 999
 	return false;
933 1000
 }
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +333 added lines, -249 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct the page index, allowing for the .START method...
445 457
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -476,8 +488,9 @@  discard block
 block discarded – undo
476 488
 			$_REQUEST['start'] = 0;
477 489
 		}
478 490
 		// They aren't using it, but the *option* is there, at least.
479
-		else
480
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
491
+		else {
492
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
493
+		}
481 494
 	}
482 495
 
483 496
 	// Build the link tree.
@@ -493,14 +506,16 @@  discard block
 block discarded – undo
493 506
 	if (!empty($board_info['moderators']))
494 507
 	{
495 508
 		// Add a link for each moderator...
496
-		foreach ($board_info['moderators'] as $mod)
497
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
509
+		foreach ($board_info['moderators'] as $mod) {
510
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
511
+		}
498 512
 	}
499 513
 	if (!empty($board_info['moderator_groups']))
500 514
 	{
501 515
 		// Add a link for each moderator group as well...
502
-		foreach ($board_info['moderator_groups'] as $mod_group)
503
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
516
+		foreach ($board_info['moderator_groups'] as $mod_group) {
517
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
518
+		}
504 519
 	}
505 520
 
506 521
 	if (!empty($context['link_moderators']))
@@ -531,9 +546,9 @@  discard block
 block discarded – undo
531 546
 	// For quick reply we need a response prefix in the default forum language.
532 547
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
533 548
 	{
534
-		if ($language === $user_info['language'])
535
-			$context['response_prefix'] = $txt['response_prefix'];
536
-		else
549
+		if ($language === $user_info['language']) {
550
+					$context['response_prefix'] = $txt['response_prefix'];
551
+		} else
537 552
 		{
538 553
 			loadLanguage('index', $language, false);
539 554
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -565,8 +580,9 @@  discard block
 block discarded – undo
565 580
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
566 581
 
567 582
 			// Sanity check
568
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
569
-				continue;
583
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
584
+							continue;
585
+			}
570 586
 
571 587
 			$linked_calendar_event = array(
572 588
 				'id' => $row['id_event'],
@@ -615,8 +631,9 @@  discard block
 block discarded – undo
615 631
 		}
616 632
 		$smcFunc['db_free_result']($request);
617 633
 
618
-		if (!empty($context['linked_calendar_events']))
619
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
634
+		if (!empty($context['linked_calendar_events'])) {
635
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
636
+		}
620 637
 	}
621 638
 
622 639
 	// Create the poll info if it exists.
@@ -689,20 +706,21 @@  discard block
 block discarded – undo
689 706
 				foreach ($guestinfo as $i => $guestvoted)
690 707
 				{
691 708
 					$guestvoted = explode(',', $guestvoted);
692
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
693
-						break;
709
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
710
+											break;
711
+					}
694 712
 				}
695 713
 				// Has the poll been reset since guest voted?
696 714
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
697 715
 				{
698 716
 					// Remove the poll info from the cookie to allow guest to vote again
699 717
 					unset($guestinfo[$i]);
700
-					if (!empty($guestinfo))
701
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
702
-					else
703
-						unset($_COOKIE['guest_poll_vote']);
704
-				}
705
-				else
718
+					if (!empty($guestinfo)) {
719
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
720
+					} else {
721
+											unset($_COOKIE['guest_poll_vote']);
722
+					}
723
+				} else
706 724
 				{
707 725
 					// What did they vote for?
708 726
 					unset($guestvoted[0], $guestvoted[1]);
@@ -816,23 +834,29 @@  discard block
 block discarded – undo
816 834
 		// Build the poll moderation button array.
817 835
 		$context['poll_buttons'] = array();
818 836
 
819
-		if ($context['allow_return_vote'])
820
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
837
+		if ($context['allow_return_vote']) {
838
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
839
+		}
821 840
 
822
-		if ($context['show_view_results_button'])
823
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
841
+		if ($context['show_view_results_button']) {
842
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
843
+		}
824 844
 
825
-		if ($context['allow_change_vote'])
826
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
845
+		if ($context['allow_change_vote']) {
846
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
847
+		}
827 848
 
828
-		if ($context['allow_lock_poll'])
829
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
849
+		if ($context['allow_lock_poll']) {
850
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
851
+		}
830 852
 
831
-		if ($context['allow_edit_poll'])
832
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
853
+		if ($context['allow_edit_poll']) {
854
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
855
+		}
833 856
 
834
-		if ($context['can_remove_poll'])
835
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
857
+		if ($context['can_remove_poll']) {
858
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
859
+		}
836 860
 
837 861
 		// Allow mods to add additional buttons here
838 862
 		call_integration_hook('integrate_poll_buttons');
@@ -873,8 +897,9 @@  discard block
 block discarded – undo
873 897
 	$all_posters = array();
874 898
 	while ($row = $smcFunc['db_fetch_assoc']($request))
875 899
 	{
876
-		if (!empty($row['id_member']))
877
-			$all_posters[$row['id_msg']] = $row['id_member'];
900
+		if (!empty($row['id_member'])) {
901
+					$all_posters[$row['id_msg']] = $row['id_member'];
902
+		}
878 903
 		$messages[] = $row['id_msg'];
879 904
 	}
880 905
 	$smcFunc['db_free_result']($request);
@@ -886,8 +911,9 @@  discard block
 block discarded – undo
886 911
 	if (!$user_info['is_guest'] && !empty($messages))
887 912
 	{
888 913
 		$mark_at_msg = max($messages);
889
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
890
-			$mark_at_msg = $modSettings['maxMsgID'];
914
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
915
+					$mark_at_msg = $modSettings['maxMsgID'];
916
+		}
891 917
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
892 918
 		{
893 919
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -919,8 +945,9 @@  discard block
 block discarded – undo
919 945
 		while ($row = $smcFunc['db_fetch_assoc']($request))
920 946
 		{
921 947
 			// Find if this topic is marked for notification...
922
-			if (!empty($row['id_topic']))
923
-				$context['is_marked_notify'] = true;
948
+			if (!empty($row['id_topic'])) {
949
+							$context['is_marked_notify'] = true;
950
+			}
924 951
 
925 952
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
926 953
 			if (!empty($row['sent']) && $do_once)
@@ -942,8 +969,9 @@  discard block
 block discarded – undo
942 969
 		}
943 970
 
944 971
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
945
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
946
-			$_SESSION['topicseen_cache'][$board]--;
972
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
973
+					$_SESSION['topicseen_cache'][$board]--;
974
+		}
947 975
 		// Mark board as seen if this is the only new topic.
948 976
 		elseif (isset($_REQUEST['topicseen']))
949 977
 		{
@@ -967,14 +995,16 @@  discard block
 block discarded – undo
967 995
 			$smcFunc['db_free_result']($request);
968 996
 
969 997
 			// If there're no real new topics in this board, mark the board as seen.
970
-			if (empty($numNewTopics))
971
-				$_REQUEST['boardseen'] = true;
972
-			else
973
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
998
+			if (empty($numNewTopics)) {
999
+							$_REQUEST['boardseen'] = true;
1000
+			} else {
1001
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1002
+			}
974 1003
 		}
975 1004
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
976
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
977
-			$_SESSION['topicseen_cache'][$board]--;
1005
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1006
+					$_SESSION['topicseen_cache'][$board]--;
1007
+		}
978 1008
 
979 1009
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
980 1010
 		if (isset($_REQUEST['boardseen']))
@@ -1031,23 +1061,26 @@  discard block
 block discarded – undo
1031 1061
 			$temp = array();
1032 1062
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1033 1063
 			{
1034
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1035
-					continue;
1064
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1065
+									continue;
1066
+				}
1036 1067
 
1037 1068
 				$temp[$row['id_attach']] = $row;
1038 1069
 				$temp[$row['id_attach']]['topic'] = $topic;
1039 1070
 				$temp[$row['id_attach']]['board'] = $board;
1040 1071
 
1041
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1042
-					$context['loaded_attachments'][$row['id_msg']] = array();
1072
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1073
+									$context['loaded_attachments'][$row['id_msg']] = array();
1074
+				}
1043 1075
 			}
1044 1076
 			$smcFunc['db_free_result']($request);
1045 1077
 
1046 1078
 			// This is better than sorting it with the query...
1047 1079
 			ksort($temp);
1048 1080
 
1049
-			foreach ($temp as $row)
1050
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1081
+			foreach ($temp as $row) {
1082
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1083
+			}
1051 1084
 		}
1052 1085
 
1053 1086
 		$msg_parameters = array(
@@ -1074,21 +1107,23 @@  discard block
 block discarded – undo
1074 1107
 		);
1075 1108
 
1076 1109
 		// And the likes
1077
-		if (!empty($modSettings['enable_likes']))
1078
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1110
+		if (!empty($modSettings['enable_likes'])) {
1111
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1112
+		}
1079 1113
 
1080 1114
 		// Go to the last message if the given time is beyond the time of the last message.
1081
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1082
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1115
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1116
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1117
+		}
1083 1118
 
1084 1119
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1085 1120
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1086
-		if (empty($options['view_newest_first']))
1087
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1088
-		else
1089
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1090
-	}
1091
-	else
1121
+		if (empty($options['view_newest_first'])) {
1122
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1123
+		} else {
1124
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1125
+		}
1126
+	} else
1092 1127
 	{
1093 1128
 		$messages_request = false;
1094 1129
 		$context['first_message'] = 0;
@@ -1124,8 +1159,9 @@  discard block
 block discarded – undo
1124 1159
 		'can_see_likes' => 'likes_view',
1125 1160
 		'can_like' => 'likes_like',
1126 1161
 	);
1127
-	foreach ($common_permissions as $contextual => $perm)
1128
-		$context[$contextual] = allowedTo($perm);
1162
+	foreach ($common_permissions as $contextual => $perm) {
1163
+			$context[$contextual] = allowedTo($perm);
1164
+	}
1129 1165
 
1130 1166
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1131 1167
 	$anyown_permissions = array(
@@ -1138,8 +1174,9 @@  discard block
 block discarded – undo
1138 1174
 		'can_reply_unapproved' => 'post_unapproved_replies',
1139 1175
 		'can_view_warning' => 'profile_warning',
1140 1176
 	);
1141
-	foreach ($anyown_permissions as $contextual => $perm)
1142
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1177
+	foreach ($anyown_permissions as $contextual => $perm) {
1178
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1179
+	}
1143 1180
 
1144 1181
 	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
1145 1182
 	{
@@ -1185,8 +1222,9 @@  discard block
 block discarded – undo
1185 1222
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1186 1223
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1187 1224
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1188
-	if (!empty($context['drafts_save']))
1189
-		loadLanguage('Drafts');
1225
+	if (!empty($context['drafts_save'])) {
1226
+			loadLanguage('Drafts');
1227
+	}
1190 1228
 
1191 1229
 	// When was the last time this topic was replied to?  Should we warn them about it?
1192 1230
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1247,26 +1285,31 @@  discard block
 block discarded – undo
1247 1285
 	// Message icons - customized icons are off?
1248 1286
 	$context['icons'] = getMessageIcons($board);
1249 1287
 
1250
-	if (!empty($context['icons']))
1251
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1288
+	if (!empty($context['icons'])) {
1289
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1290
+	}
1252 1291
 
1253 1292
 	// Build the normal button array.
1254 1293
 	$context['normal_buttons'] = array();
1255 1294
 
1256
-	if ($context['can_reply'])
1257
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1295
+	if ($context['can_reply']) {
1296
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1297
+	}
1258 1298
 
1259
-	if ($context['can_add_poll'])
1260
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1299
+	if ($context['can_add_poll']) {
1300
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1301
+	}
1261 1302
 
1262
-	if ($context['can_mark_unread'])
1263
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1303
+	if ($context['can_mark_unread']) {
1304
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1305
+	}
1264 1306
 
1265
-	if ($context['can_print'])
1266
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1307
+	if ($context['can_print']) {
1308
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1309
+	}
1267 1310
 
1268
-	if ($context['can_set_notify'])
1269
-		$context['normal_buttons']['notify'] = array(
1311
+	if ($context['can_set_notify']) {
1312
+			$context['normal_buttons']['notify'] = array(
1270 1313
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1271 1314
 			'sub_buttons' => array(
1272 1315
 				array(
@@ -1288,38 +1331,47 @@  discard block
 block discarded – undo
1288 1331
 				),
1289 1332
 			),
1290 1333
 		);
1334
+	}
1291 1335
 
1292 1336
 	// Build the mod button array
1293 1337
 	$context['mod_buttons'] = array();
1294 1338
 
1295
-	if ($context['can_move'])
1296
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1339
+	if ($context['can_move']) {
1340
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1341
+	}
1297 1342
 
1298
-	if ($context['can_delete'])
1299
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1343
+	if ($context['can_delete']) {
1344
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1345
+	}
1300 1346
 
1301
-	if ($context['can_lock'])
1302
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1347
+	if ($context['can_lock']) {
1348
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1349
+	}
1303 1350
 
1304
-	if ($context['can_sticky'])
1305
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1351
+	if ($context['can_sticky']) {
1352
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1353
+	}
1306 1354
 
1307
-	if ($context['can_merge'])
1308
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1355
+	if ($context['can_merge']) {
1356
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1357
+	}
1309 1358
 
1310
-	if ($context['calendar_post'])
1311
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1359
+	if ($context['calendar_post']) {
1360
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1361
+	}
1312 1362
 
1313 1363
 	// Restore topic. eh?  No monkey business.
1314
-	if ($context['can_restore_topic'])
1315
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1364
+	if ($context['can_restore_topic']) {
1365
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1366
+	}
1316 1367
 
1317 1368
 	// Show a message in case a recently posted message became unapproved.
1318 1369
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1319 1370
 
1320 1371
 	// Don't want to show this forever...
1321
-	if ($context['becomesUnapproved'])
1322
-		unset($_SESSION['becomesUnapproved']);
1372
+	if ($context['becomesUnapproved']) {
1373
+			unset($_SESSION['becomesUnapproved']);
1374
+	}
1323 1375
 
1324 1376
 	// Allow adding new mod buttons easily.
1325 1377
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1328,12 +1380,14 @@  discard block
 block discarded – undo
1328 1380
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1329 1381
 
1330 1382
 	// Load the drafts js file
1331
-	if ($context['drafts_autosave'])
1332
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1383
+	if ($context['drafts_autosave']) {
1384
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1385
+	}
1333 1386
 
1334 1387
 	// Spellcheck
1335
-	if ($context['show_spellchecking'])
1336
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1388
+	if ($context['show_spellchecking']) {
1389
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1390
+	}
1337 1391
 
1338 1392
 	// topic.js
1339 1393
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1367,16 +1421,19 @@  discard block
 block discarded – undo
1367 1421
 	static $counter = null;
1368 1422
 
1369 1423
 	// If the query returned false, bail.
1370
-	if ($messages_request == false)
1371
-		return false;
1424
+	if ($messages_request == false) {
1425
+			return false;
1426
+	}
1372 1427
 
1373 1428
 	// Remember which message this is.  (ie. reply #83)
1374
-	if ($counter === null || $reset)
1375
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1429
+	if ($counter === null || $reset) {
1430
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1431
+	}
1376 1432
 
1377 1433
 	// Start from the beginning...
1378
-	if ($reset)
1379
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1434
+	if ($reset) {
1435
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1436
+	}
1380 1437
 
1381 1438
 	// Attempt to get the next message.
1382 1439
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1390,19 +1447,21 @@  discard block
 block discarded – undo
1390 1447
 	if (empty($context['icon_sources']))
1391 1448
 	{
1392 1449
 		$context['icon_sources'] = array();
1393
-		foreach ($context['stable_icons'] as $icon)
1394
-			$context['icon_sources'][$icon] = 'images_url';
1450
+		foreach ($context['stable_icons'] as $icon) {
1451
+					$context['icon_sources'][$icon] = 'images_url';
1452
+		}
1395 1453
 	}
1396 1454
 
1397 1455
 	// Message Icon Management... check the images exist.
1398 1456
 	if (empty($modSettings['messageIconChecks_disable']))
1399 1457
 	{
1400 1458
 		// If the current icon isn't known, then we need to do something...
1401
-		if (!isset($context['icon_sources'][$message['icon']]))
1402
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1459
+		if (!isset($context['icon_sources'][$message['icon']])) {
1460
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1461
+		}
1462
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1463
+			$context['icon_sources'][$message['icon']] = 'images_url';
1403 1464
 	}
1404
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1405
-		$context['icon_sources'][$message['icon']] = 'images_url';
1406 1465
 
1407 1466
 	// If you're a lazy bum, you probably didn't give a subject...
1408 1467
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1427,8 +1486,7 @@  discard block
 block discarded – undo
1427 1486
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1428 1487
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1429 1488
 		$memberContext[$message['id_member']]['is_guest'] = true;
1430
-	}
1431
-	else
1489
+	} else
1432 1490
 	{
1433 1491
 		// Define this here to make things a bit more readable
1434 1492
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1451,8 +1509,9 @@  discard block
 block discarded – undo
1451 1509
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1452 1510
 
1453 1511
 	// If it's in the recycle bin we need to override whatever icon we did have.
1454
-	if (!empty($board_info['recycle']))
1455
-		$message['icon'] = 'recycled';
1512
+	if (!empty($board_info['recycle'])) {
1513
+			$message['icon'] = 'recycled';
1514
+	}
1456 1515
 
1457 1516
 	require_once($sourcedir . '/Subs-Attachments.php');
1458 1517
 
@@ -1496,32 +1555,36 @@  discard block
 block discarded – undo
1496 1555
 	}
1497 1556
 
1498 1557
 	// Are likes enable?
1499
-	if (!empty($modSettings['enable_likes']))
1500
-		$output['likes'] = array(
1558
+	if (!empty($modSettings['enable_likes'])) {
1559
+			$output['likes'] = array(
1501 1560
 			'count' => $message['likes'],
1502 1561
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1503 1562
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1504 1563
 		);
1564
+	}
1505 1565
 
1506 1566
 	// Is this user the message author?
1507 1567
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1508
-	if (!empty($output['modified']['name']))
1509
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1568
+	if (!empty($output['modified']['name'])) {
1569
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1570
+	}
1510 1571
 
1511 1572
 	// Did they give a reason for editing?
1512
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1513
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1573
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1574
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1575
+	}
1514 1576
 
1515 1577
 	// Any custom profile fields?
1516
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1517
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1578
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1579
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1518 1580
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1581
+	}
1519 1582
 
1520
-	if (empty($options['view_newest_first']))
1521
-		$counter++;
1522
-
1523
-	else
1524
-		$counter--;
1583
+	if (empty($options['view_newest_first'])) {
1584
+			$counter++;
1585
+	} else {
1586
+			$counter--;
1587
+	}
1525 1588
 
1526 1589
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1527 1590
 
@@ -1547,21 +1610,23 @@  discard block
 block discarded – undo
1547 1610
 	$context['no_last_modified'] = true;
1548 1611
 
1549 1612
 	// Prevent a preview image from being displayed twice.
1550
-	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview'))
1551
-		return;
1613
+	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) {
1614
+			return;
1615
+	}
1552 1616
 
1553 1617
 	// Make sure some attachment was requested!
1554
-	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
1555
-		fatal_lang_error('no_access', false);
1618
+	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) {
1619
+			fatal_lang_error('no_access', false);
1620
+	}
1556 1621
 
1557 1622
 	$_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
1558 1623
 
1559 1624
 	// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
1560 1625
 	$attachRequest = null;
1561 1626
 	call_integration_hook('integrate_download_request', array(&$attachRequest));
1562
-	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
1563
-		$request = $attachRequest;
1564
-	else
1627
+	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
1628
+			$request = $attachRequest;
1629
+	} else
1565 1630
 	{
1566 1631
 		// This checks only the current board for $board/$topic's permissions.
1567 1632
 		isAllowedTo('view_attachments');
@@ -1582,19 +1647,21 @@  discard block
 block discarded – undo
1582 1647
 		);
1583 1648
 	}
1584 1649
 
1585
-	if ($smcFunc['db_num_rows']($request) == 0)
1586
-		fatal_lang_error('no_access', false);
1650
+	if ($smcFunc['db_num_rows']($request) == 0) {
1651
+			fatal_lang_error('no_access', false);
1652
+	}
1587 1653
 
1588 1654
 	list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
1589 1655
 	$smcFunc['db_free_result']($request);
1590 1656
 
1591 1657
 	// If it isn't yet approved, do they have permission to view it?
1592
-	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
1593
-		isAllowedTo('approve_posts');
1658
+	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) {
1659
+			isAllowedTo('approve_posts');
1660
+	}
1594 1661
 
1595 1662
 	// Update the download counter (unless it's a thumbnail).
1596
-	if ($attachment_type != 3)
1597
-		$smcFunc['db_query']('attach_download_increase', '
1663
+	if ($attachment_type != 3) {
1664
+			$smcFunc['db_query']('attach_download_increase', '
1598 1665
 			UPDATE LOW_PRIORITY {db_prefix}attachments
1599 1666
 			SET downloads = downloads + 1
1600 1667
 			WHERE id_attach = {int:id_attach}',
@@ -1602,15 +1669,15 @@  discard block
 block discarded – undo
1602 1669
 				'id_attach' => $id_attach,
1603 1670
 			)
1604 1671
 		);
1672
+	}
1605 1673
 
1606 1674
 	$filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
1607 1675
 
1608 1676
 	// This is done to clear any output that was made before now.
1609 1677
 	ob_end_clean();
1610
-	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
1611
-		@ob_start('ob_gzhandler');
1612
-
1613
-	else
1678
+	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) {
1679
+			@ob_start('ob_gzhandler');
1680
+	} else
1614 1681
 	{
1615 1682
 		ob_start();
1616 1683
 		header('Content-Encoding: none');
@@ -1653,8 +1720,9 @@  discard block
 block discarded – undo
1653 1720
 	// Send the attachment headers.
1654 1721
 	header('Pragma: ');
1655 1722
 
1656
-	if (!isBrowser('gecko'))
1657
-		header('Content-Transfer-Encoding: binary');
1723
+	if (!isBrowser('gecko')) {
1724
+			header('Content-Transfer-Encoding: binary');
1725
+	}
1658 1726
 
1659 1727
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
1660 1728
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
@@ -1663,18 +1731,19 @@  discard block
 block discarded – undo
1663 1731
 	header('ETag: ' . $eTag);
1664 1732
 
1665 1733
 	// Make sure the mime type warrants an inline display.
1666
-	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
1667
-		unset($_REQUEST['image']);
1734
+	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) {
1735
+			unset($_REQUEST['image']);
1736
+	}
1668 1737
 
1669 1738
 	// Does this have a mime type?
1670
-	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
1671
-		header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1672
-
1673
-	else
1739
+	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
1740
+			header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1741
+	} else
1674 1742
 	{
1675 1743
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
1676
-		if (isset($_REQUEST['image']))
1677
-			unset($_REQUEST['image']);
1744
+		if (isset($_REQUEST['image'])) {
1745
+					unset($_REQUEST['image']);
1746
+		}
1678 1747
 	}
1679 1748
 
1680 1749
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -1682,23 +1751,22 @@  discard block
 block discarded – undo
1682 1751
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
1683 1752
 
1684 1753
 	// Different browsers like different standards...
1685
-	if (isBrowser('firefox'))
1686
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1687
-
1688
-	elseif (isBrowser('opera'))
1689
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1690
-
1691
-	elseif (isBrowser('ie'))
1692
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1693
-
1694
-	else
1695
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1754
+	if (isBrowser('firefox')) {
1755
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1756
+	} elseif (isBrowser('opera')) {
1757
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1758
+	} elseif (isBrowser('ie')) {
1759
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1760
+	} else {
1761
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1762
+	}
1696 1763
 
1697 1764
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
1698
-	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
1699
-		header('Cache-Control: no-cache');
1700
-	else
1701
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1765
+	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
1766
+			header('Cache-Control: no-cache');
1767
+	} else {
1768
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1769
+	}
1702 1770
 
1703 1771
 	header('Content-Length: ' . filesize($filename));
1704 1772
 
@@ -1708,20 +1776,23 @@  discard block
 block discarded – undo
1708 1776
 	// Recode line endings for text files, if enabled.
1709 1777
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
1710 1778
 	{
1711
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
1712
-			$callback = function($buffer)
1779
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
1780
+					$callback = function($buffer)
1713 1781
 			{
1714 1782
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
1783
+		}
1715 1784
 			};
1716
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
1717
-			$callback = function($buffer)
1785
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
1786
+					$callback = function($buffer)
1718 1787
 			{
1719 1788
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
1789
+		}
1720 1790
 			};
1721
-		else
1722
-			$callback = function($buffer)
1791
+		else {
1792
+					$callback = function($buffer)
1723 1793
 			{
1724 1794
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
1795
+		}
1725 1796
 			};
1726 1797
 	}
1727 1798
 
@@ -1729,23 +1800,26 @@  discard block
 block discarded – undo
1729 1800
 	if (filesize($filename) > 4194304)
1730 1801
 	{
1731 1802
 		// Forcibly end any output buffering going on.
1732
-		while (@ob_get_level() > 0)
1733
-			@ob_end_clean();
1803
+		while (@ob_get_level() > 0) {
1804
+					@ob_end_clean();
1805
+		}
1734 1806
 
1735 1807
 		$fp = fopen($filename, 'rb');
1736 1808
 		while (!feof($fp))
1737 1809
 		{
1738
-			if (isset($callback))
1739
-				echo $callback(fread($fp, 8192));
1740
-			else
1741
-				echo fread($fp, 8192);
1810
+			if (isset($callback)) {
1811
+							echo $callback(fread($fp, 8192));
1812
+			} else {
1813
+							echo fread($fp, 8192);
1814
+			}
1742 1815
 			flush();
1743 1816
 		}
1744 1817
 		fclose($fp);
1745 1818
 	}
1746 1819
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
1747
-	elseif (isset($callback) || @readfile($filename) === null)
1748
-		echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1820
+	elseif (isset($callback) || @readfile($filename) === null) {
1821
+			echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1822
+	}
1749 1823
 
1750 1824
 	obExit(false);
1751 1825
 }
@@ -1758,8 +1832,9 @@  discard block
 block discarded – undo
1758 1832
  */
1759 1833
 function approved_attach_sort($a, $b)
1760 1834
 {
1761
-	if ($a['is_approved'] == $b['is_approved'])
1762
-		return 0;
1835
+	if ($a['is_approved'] == $b['is_approved']) {
1836
+			return 0;
1837
+	}
1763 1838
 
1764 1839
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1765 1840
 }
@@ -1776,16 +1851,19 @@  discard block
 block discarded – undo
1776 1851
 
1777 1852
 	require_once($sourcedir . '/RemoveTopic.php');
1778 1853
 
1779
-	if (empty($_REQUEST['msgs']))
1780
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1854
+	if (empty($_REQUEST['msgs'])) {
1855
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1856
+	}
1781 1857
 
1782 1858
 	$messages = array();
1783
-	foreach ($_REQUEST['msgs'] as $dummy)
1784
-		$messages[] = (int) $dummy;
1859
+	foreach ($_REQUEST['msgs'] as $dummy) {
1860
+			$messages[] = (int) $dummy;
1861
+	}
1785 1862
 
1786 1863
 	// We are restoring messages. We handle this in another place.
1787
-	if (isset($_REQUEST['restore_selected']))
1788
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1864
+	if (isset($_REQUEST['restore_selected'])) {
1865
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1866
+	}
1789 1867
 	if (isset($_REQUEST['split_selection']))
1790 1868
 	{
1791 1869
 		$request = $smcFunc['db_query']('', '
@@ -1804,8 +1882,9 @@  discard block
 block discarded – undo
1804 1882
 	}
1805 1883
 
1806 1884
 	// Allowed to delete any message?
1807
-	if (allowedTo('delete_any'))
1808
-		$allowed_all = true;
1885
+	if (allowedTo('delete_any')) {
1886
+			$allowed_all = true;
1887
+	}
1809 1888
 	// Allowed to delete replies to their messages?
1810 1889
 	elseif (allowedTo('delete_replies'))
1811 1890
 	{
@@ -1822,13 +1901,14 @@  discard block
 block discarded – undo
1822 1901
 		$smcFunc['db_free_result']($request);
1823 1902
 
1824 1903
 		$allowed_all = $starter == $user_info['id'];
1904
+	} else {
1905
+			$allowed_all = false;
1825 1906
 	}
1826
-	else
1827
-		$allowed_all = false;
1828 1907
 
1829 1908
 	// Make sure they're allowed to delete their own messages, if not any.
1830
-	if (!$allowed_all)
1831
-		isAllowedTo('delete_own');
1909
+	if (!$allowed_all) {
1910
+			isAllowedTo('delete_own');
1911
+	}
1832 1912
 
1833 1913
 	// Allowed to remove which messages?
1834 1914
 	$request = $smcFunc['db_query']('', '
@@ -1848,8 +1928,9 @@  discard block
 block discarded – undo
1848 1928
 	$messages = array();
1849 1929
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1850 1930
 	{
1851
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1852
-			continue;
1931
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1932
+					continue;
1933
+		}
1853 1934
 
1854 1935
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1855 1936
 	}
@@ -1872,17 +1953,20 @@  discard block
 block discarded – undo
1872 1953
 	foreach ($messages as $message => $info)
1873 1954
 	{
1874 1955
 		// Just skip the first message - if it's not the last.
1875
-		if ($message == $first_message && $message != $last_message)
1876
-			continue;
1956
+		if ($message == $first_message && $message != $last_message) {
1957
+					continue;
1958
+		}
1877 1959
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1878
-		elseif ($message == $first_message)
1879
-			$topicGone = true;
1960
+		elseif ($message == $first_message) {
1961
+					$topicGone = true;
1962
+		}
1880 1963
 
1881 1964
 		removeMessage($message);
1882 1965
 
1883 1966
 		// Log this moderation action ;).
1884
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1885
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1967
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1968
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1969
+		}
1886 1970
 	}
1887 1971
 
1888 1972
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/tasks/Birthday-Notify.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@
 block discarded – undo
18 18
  */
19 19
 class Birthday_Notify_Background extends SMF_BackgroundTask
20 20
 {
21
-    /**
22
-     * This executes the task. It loads up the birthdays, figures out the greeting, etc.
23
-     * @return bool Always returns true
24
-     */
21
+	/**
22
+	 * This executes the task. It loads up the birthdays, figures out the greeting, etc.
23
+	 * @return bool Always returns true
24
+	 */
25 25
 	public function execute()
26 26
  	{
27 27
 		global $txt, $smcFunc, $txtBirthdayEmails, $modSettings, $sourcedir;
Please login to merge, or discard this patch.
Sources/Subs-Boards.php 1 patch
Braces   +247 added lines, -175 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Mark a board or multiple boards read.
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 	global $user_info, $modSettings, $smcFunc;
29 30
 
30 31
 	// Force $boards to be an array.
31
-	if (!is_array($boards))
32
-		$boards = array($boards);
33
-	else
34
-		$boards = array_unique($boards);
32
+	if (!is_array($boards)) {
33
+			$boards = array($boards);
34
+	} else {
35
+			$boards = array_unique($boards);
36
+	}
35 37
 
36 38
 	// No boards, nothing to mark as read.
37
-	if (empty($boards))
38
-		return;
39
+	if (empty($boards)) {
40
+			return;
41
+	}
39 42
 
40 43
 	// Allow the user to mark a board as unread.
41 44
 	if ($unread)
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	else
66 69
 	{
67 70
 		$markRead = array();
68
-		foreach ($boards as $board)
69
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
71
+		foreach ($boards as $board) {
72
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board);
73
+		}
70 74
 
71 75
 		// Update log_mark_read and log_boards.
72 76
 		$smcFunc['db_insert']('replace',
@@ -99,8 +103,9 @@  discard block
 block discarded – undo
99 103
 	list ($lowest_topic) = $smcFunc['db_fetch_row']($result);
100 104
 	$smcFunc['db_free_result']($result);
101 105
 
102
-	if (empty($lowest_topic))
103
-		return;
106
+	if (empty($lowest_topic)) {
107
+			return;
108
+	}
104 109
 
105 110
 	// @todo SLOW This query seems to eat it sometimes.
106 111
 	$result = $smcFunc['db_query']('', '
@@ -118,12 +123,13 @@  discard block
 block discarded – undo
118 123
 		)
119 124
 	);
120 125
 	$topics = array();
121
-	while ($row = $smcFunc['db_fetch_assoc']($result))
122
-		$topics[] = $row['id_topic'];
126
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
127
+			$topics[] = $row['id_topic'];
128
+	}
123 129
 	$smcFunc['db_free_result']($result);
124 130
 
125
-	if (!empty($topics))
126
-		$smcFunc['db_query']('', '
131
+	if (!empty($topics)) {
132
+			$smcFunc['db_query']('', '
127 133
 			DELETE FROM {db_prefix}log_topics
128 134
 			WHERE id_member = {int:current_member}
129 135
 				AND id_topic IN ({array_int:topic_list})',
@@ -132,7 +138,8 @@  discard block
 block discarded – undo
132 138
 				'topic_list' => $topics,
133 139
 			)
134 140
 		);
135
-}
141
+	}
142
+	}
136 143
 
137 144
 /**
138 145
  * Mark one or more boards as read.
@@ -157,23 +164,26 @@  discard block
 block discarded – undo
157 164
 			)
158 165
 		);
159 166
 		$boards = array();
160
-		while ($row = $smcFunc['db_fetch_assoc']($result))
161
-			$boards[] = $row['id_board'];
167
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
168
+					$boards[] = $row['id_board'];
169
+		}
162 170
 		$smcFunc['db_free_result']($result);
163 171
 
164
-		if (!empty($boards))
165
-			markBoardsRead($boards, isset($_REQUEST['unread']));
172
+		if (!empty($boards)) {
173
+					markBoardsRead($boards, isset($_REQUEST['unread']));
174
+		}
166 175
 
167 176
 		$_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID'];
168
-		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false)
169
-			redirectexit('action=unread');
177
+		if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) {
178
+					redirectexit('action=unread');
179
+		}
170 180
 
171
-		if (isset($_SESSION['topicseen_cache']))
172
-			$_SESSION['topicseen_cache'] = array();
181
+		if (isset($_SESSION['topicseen_cache'])) {
182
+					$_SESSION['topicseen_cache'] = array();
183
+		}
173 184
 
174 185
 		redirectexit();
175
-	}
176
-	elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
186
+	} elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies')
177 187
 	{
178 188
 		// Make sure all the topics are integers!
179 189
 		$topics = array_map('intval', explode('-', $_REQUEST['topics']));
@@ -189,13 +199,15 @@  discard block
 block discarded – undo
189 199
 			)
190 200
 		);
191 201
 		$logged_topics = array();
192
-		while ($row = $smcFunc['db_fetch_assoc']($request))
193
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
203
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
204
+		}
194 205
 		$smcFunc['db_free_result']($request);
195 206
 
196 207
 		$markRead = array();
197
-		foreach ($topics as $id_topic)
198
-			$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
208
+		foreach ($topics as $id_topic) {
209
+					$markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
210
+		}
199 211
 
200 212
 		$smcFunc['db_insert']('replace',
201 213
 			'{db_prefix}log_topics',
@@ -204,8 +216,9 @@  discard block
 block discarded – undo
204 216
 			array('id_member', 'id_topic')
205 217
 		);
206 218
 
207
-		if (isset($_SESSION['topicseen_cache']))
208
-			$_SESSION['topicseen_cache'] = array();
219
+		if (isset($_SESSION['topicseen_cache'])) {
220
+					$_SESSION['topicseen_cache'] = array();
221
+		}
209 222
 
210 223
 		redirectexit('action=unreadreplies');
211 224
 	}
@@ -230,11 +243,13 @@  discard block
 block discarded – undo
230 243
 		if (!empty($_GET['t']))
231 244
 		{
232 245
 			// If they read the whole topic, go back to the beginning.
233
-			if ($_GET['t'] >= $topicinfo['id_last_msg'])
234
-				$earlyMsg = 0;
246
+			if ($_GET['t'] >= $topicinfo['id_last_msg']) {
247
+							$earlyMsg = 0;
248
+			}
235 249
 			// If they want to mark the whole thing read, same.
236
-			elseif ($_GET['t'] <= $topicinfo['id_first_msg'])
237
-				$earlyMsg = 0;
250
+			elseif ($_GET['t'] <= $topicinfo['id_first_msg']) {
251
+							$earlyMsg = 0;
252
+			}
238 253
 			// Otherwise, get the latest message before the named one.
239 254
 			else
240 255
 			{
@@ -255,9 +270,9 @@  discard block
 block discarded – undo
255 270
 			}
256 271
 		}
257 272
 		// Marking read from first page?  That's the whole topic.
258
-		elseif ($_REQUEST['start'] == 0)
259
-			$earlyMsg = 0;
260
-		else
273
+		elseif ($_REQUEST['start'] == 0) {
274
+					$earlyMsg = 0;
275
+		} else
261 276
 		{
262 277
 			$result = $smcFunc['db_query']('', '
263 278
 				SELECT id_msg
@@ -285,8 +300,7 @@  discard block
 block discarded – undo
285 300
 		);
286 301
 
287 302
 		redirectexit('board=' . $board . '.0');
288
-	}
289
-	else
303
+	} else
290 304
 	{
291 305
 		$categories = array();
292 306
 		$boards = array();
@@ -294,17 +308,20 @@  discard block
 block discarded – undo
294 308
 		if (isset($_REQUEST['c']))
295 309
 		{
296 310
 			$_REQUEST['c'] = explode(',', $_REQUEST['c']);
297
-			foreach ($_REQUEST['c'] as $c)
298
-				$categories[] = (int) $c;
311
+			foreach ($_REQUEST['c'] as $c) {
312
+							$categories[] = (int) $c;
313
+			}
299 314
 		}
300 315
 		if (isset($_REQUEST['boards']))
301 316
 		{
302 317
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
303
-			foreach ($_REQUEST['boards'] as $b)
304
-				$boards[] = (int) $b;
318
+			foreach ($_REQUEST['boards'] as $b) {
319
+							$boards[] = (int) $b;
320
+			}
321
+		}
322
+		if (!empty($board)) {
323
+					$boards[] = (int) $board;
305 324
 		}
306
-		if (!empty($board))
307
-			$boards[] = (int) $board;
308 325
 
309 326
 		if (isset($_REQUEST['children']) && !empty($boards))
310 327
 		{
@@ -324,9 +341,10 @@  discard block
 block discarded – undo
324 341
 					'board_list' => $boards,
325 342
 				)
326 343
 			);
327
-			while ($row = $smcFunc['db_fetch_assoc']($request))
328
-				if (in_array($row['id_parent'], $boards))
344
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
345
+							if (in_array($row['id_parent'], $boards))
329 346
 					$boards[] = $row['id_board'];
347
+			}
330 348
 			$smcFunc['db_free_result']($request);
331 349
 		}
332 350
 
@@ -343,8 +361,9 @@  discard block
 block discarded – undo
343 361
 			$clauseParameters['board_list'] = $boards;
344 362
 		}
345 363
 
346
-		if (empty($clauses))
347
-			redirectexit();
364
+		if (empty($clauses)) {
365
+					redirectexit();
366
+		}
348 367
 
349 368
 		$request = $smcFunc['db_query']('', '
350 369
 			SELECT b.id_board
@@ -355,19 +374,22 @@  discard block
 block discarded – undo
355 374
 			))
356 375
 		);
357 376
 		$boards = array();
358
-		while ($row = $smcFunc['db_fetch_assoc']($request))
359
-			$boards[] = $row['id_board'];
377
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
378
+					$boards[] = $row['id_board'];
379
+		}
360 380
 		$smcFunc['db_free_result']($request);
361 381
 
362
-		if (empty($boards))
363
-			redirectexit();
382
+		if (empty($boards)) {
383
+					redirectexit();
384
+		}
364 385
 
365 386
 		markBoardsRead($boards, isset($_REQUEST['unread']));
366 387
 
367 388
 		foreach ($boards as $b)
368 389
 		{
369
-			if (isset($_SESSION['topicseen_cache'][$b]))
370
-				$_SESSION['topicseen_cache'][$b] = array();
390
+			if (isset($_SESSION['topicseen_cache'][$b])) {
391
+							$_SESSION['topicseen_cache'][$b] = array();
392
+			}
371 393
 		}
372 394
 
373 395
 		if (!isset($_REQUEST['unread']))
@@ -385,8 +407,9 @@  discard block
 block discarded – undo
385 407
 			if ($smcFunc['db_num_rows']($result) > 0)
386 408
 			{
387 409
 				$logBoardInserts = array();
388
-				while ($row = $smcFunc['db_fetch_assoc']($result))
389
-					$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
410
+				while ($row = $smcFunc['db_fetch_assoc']($result)) {
411
+									$logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']);
412
+				}
390 413
 
391 414
 				$smcFunc['db_insert']('replace',
392 415
 					'{db_prefix}log_boards',
@@ -397,17 +420,18 @@  discard block
 block discarded – undo
397 420
 			}
398 421
 			$smcFunc['db_free_result']($result);
399 422
 
400
-			if (empty($board))
401
-				redirectexit();
402
-			else
403
-				redirectexit('board=' . $board . '.0');
404
-		}
405
-		else
423
+			if (empty($board)) {
424
+							redirectexit();
425
+			} else {
426
+							redirectexit('board=' . $board . '.0');
427
+			}
428
+		} else
406 429
 		{
407
-			if (empty($board_info['parent']))
408
-				redirectexit();
409
-			else
410
-				redirectexit('board=' . $board_info['parent'] . '.0');
430
+			if (empty($board_info['parent'])) {
431
+							redirectexit();
432
+			} else {
433
+							redirectexit('board=' . $board_info['parent'] . '.0');
434
+			}
411 435
 		}
412 436
 	}
413 437
 }
@@ -432,11 +456,13 @@  discard block
 block discarded – undo
432 456
 			'selected_message' => (int) $messageID,
433 457
 		)
434 458
 	);
435
-	if ($smcFunc['db_num_rows']($result) > 0)
436
-		list ($memberID) = $smcFunc['db_fetch_row']($result);
459
+	if ($smcFunc['db_num_rows']($result) > 0) {
460
+			list ($memberID) = $smcFunc['db_fetch_row']($result);
461
+	}
437 462
 	// The message doesn't even exist.
438
-	else
439
-		$memberID = 0;
463
+	else {
464
+			$memberID = 0;
465
+	}
440 466
 	$smcFunc['db_free_result']($result);
441 467
 
442 468
 	return (int) $memberID;
@@ -457,8 +483,9 @@  discard block
 block discarded – undo
457 483
 	getBoardTree();
458 484
 
459 485
 	// Make sure given boards and categories exist.
460
-	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']])))
461
-		fatal_lang_error('no_board');
486
+	if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) {
487
+			fatal_lang_error('no_board');
488
+	}
462 489
 
463 490
 	$id = $board_id;
464 491
 	call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions));
@@ -486,8 +513,9 @@  discard block
 block discarded – undo
486 513
 			$child_level = 0;
487 514
 			$id_parent = 0;
488 515
 			$after = 0;
489
-			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy)
490
-				$after = max($after, $boards[$id_board]['order']);
516
+			foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) {
517
+							$after = max($after, $boards[$id_board]['order']);
518
+			}
491 519
 		}
492 520
 
493 521
 		// Make the board a child of a given board.
@@ -498,17 +526,19 @@  discard block
 block discarded – undo
498 526
 			$id_parent = $boardOptions['target_board'];
499 527
 
500 528
 			// People can be creative, in many ways...
501
-			if (isChildOf($id_parent, $board_id))
502
-				fatal_lang_error('mboards_parent_own_child_error', false);
503
-			elseif ($id_parent == $board_id)
504
-				fatal_lang_error('mboards_board_own_child_error', false);
529
+			if (isChildOf($id_parent, $board_id)) {
530
+							fatal_lang_error('mboards_parent_own_child_error', false);
531
+			} elseif ($id_parent == $board_id) {
532
+							fatal_lang_error('mboards_board_own_child_error', false);
533
+			}
505 534
 
506 535
 			$after = $boards[$boardOptions['target_board']]['order'];
507 536
 
508 537
 			// Check if there are already children and (if so) get the max board order.
509
-			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child']))
510
-				foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
538
+			if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) {
539
+							foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy)
511 540
 					$after = max($after, $boards[$childBoard_id]['order']);
541
+			}
512 542
 		}
513 543
 
514 544
 		// Place a board before or after another board, on the same child level.
@@ -521,8 +551,9 @@  discard block
 block discarded – undo
521 551
 		}
522 552
 
523 553
 		// Oops...?
524
-		else
525
-			trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
554
+		else {
555
+					trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR);
556
+		}
526 557
 
527 558
 		// Get a list of children of this board.
528 559
 		$childList = array();
@@ -531,14 +562,16 @@  discard block
 block discarded – undo
531 562
 		// See if there are changes that affect children.
532 563
 		$childUpdates = array();
533 564
 		$levelDiff = $child_level - $boards[$board_id]['level'];
534
-		if ($levelDiff != 0)
535
-			$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
536
-		if ($id_cat != $boards[$board_id]['category'])
537
-			$childUpdates[] = 'id_cat = {int:category}';
565
+		if ($levelDiff != 0) {
566
+					$childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}';
567
+		}
568
+		if ($id_cat != $boards[$board_id]['category']) {
569
+					$childUpdates[] = 'id_cat = {int:category}';
570
+		}
538 571
 
539 572
 		// Fix the children of this board.
540
-		if (!empty($childList) && !empty($childUpdates))
541
-			$smcFunc['db_query']('', '
573
+		if (!empty($childList) && !empty($childUpdates)) {
574
+					$smcFunc['db_query']('', '
542 575
 				UPDATE {db_prefix}boards
543 576
 				SET ' . implode(',
544 577
 					', $childUpdates) . '
@@ -549,6 +582,7 @@  discard block
 block discarded – undo
549 582
 					'level_diff' => $levelDiff,
550 583
 				)
551 584
 			);
585
+		}
552 586
 
553 587
 		// Make some room for this spot.
554 588
 		$smcFunc['db_query']('', '
@@ -644,8 +678,8 @@  discard block
 block discarded – undo
644 678
 	call_integration_hook('integrate_modify_board', array($id, &$boardUpdates, &$boardUpdateParameters));
645 679
 
646 680
 	// Do the updates (if any).
647
-	if (!empty($boardUpdates))
648
-		$smcFunc['db_query']('', '
681
+	if (!empty($boardUpdates)) {
682
+			$smcFunc['db_query']('', '
649 683
 			UPDATE {db_prefix}boards
650 684
 			SET
651 685
 				' . implode(',
@@ -655,6 +689,7 @@  discard block
 block discarded – undo
655 689
 				'selected_board' => $board_id,
656 690
 			))
657 691
 		);
692
+	}
658 693
 
659 694
 	// Set moderators of this board.
660 695
 	if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string']))
@@ -679,13 +714,15 @@  discard block
 block discarded – undo
679 714
 			{
680 715
 				$moderators[$k] = trim($moderators[$k]);
681 716
 
682
-				if (strlen($moderators[$k]) == 0)
683
-					unset($moderators[$k]);
717
+				if (strlen($moderators[$k]) == 0) {
718
+									unset($moderators[$k]);
719
+				}
684 720
 			}
685 721
 
686 722
 			// Find all the id_member's for the member_name's in the list.
687
-			if (empty($boardOptions['moderators']))
688
-				$boardOptions['moderators'] = array();
723
+			if (empty($boardOptions['moderators'])) {
724
+							$boardOptions['moderators'] = array();
725
+			}
689 726
 			if (!empty($moderators))
690 727
 			{
691 728
 				$request = $smcFunc['db_query']('', '
@@ -698,8 +735,9 @@  discard block
 block discarded – undo
698 735
 						'limit' => count($moderators),
699 736
 					)
700 737
 				);
701
-				while ($row = $smcFunc['db_fetch_assoc']($request))
702
-					$boardOptions['moderators'][] = $row['id_member'];
738
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
739
+									$boardOptions['moderators'][] = $row['id_member'];
740
+				}
703 741
 				$smcFunc['db_free_result']($request);
704 742
 			}
705 743
 		}
@@ -708,8 +746,9 @@  discard block
 block discarded – undo
708 746
 		if (!empty($boardOptions['moderators']))
709 747
 		{
710 748
 			$inserts = array();
711
-			foreach ($boardOptions['moderators'] as $moderator)
712
-				$inserts[] = array($board_id, $moderator);
749
+			foreach ($boardOptions['moderators'] as $moderator) {
750
+							$inserts[] = array($board_id, $moderator);
751
+			}
713 752
 
714 753
 			$smcFunc['db_insert']('insert',
715 754
 				'{db_prefix}moderators',
@@ -739,14 +778,16 @@  discard block
 block discarded – undo
739 778
 			{
740 779
 				$moderator_groups[$k] = trim($moderator_groups[$k]);
741 780
 
742
-				if (strlen($moderator_groups[$k]) == 0)
743
-					unset($moderator_groups[$k]);
781
+				if (strlen($moderator_groups[$k]) == 0) {
782
+									unset($moderator_groups[$k]);
783
+				}
744 784
 			}
745 785
 
746 786
 			/* 	Find all the id_group's for all the group names in the list
747 787
 				But skip any invalid ones (invisible/post groups/Administrator/Moderator) */
748
-			if (empty($boardOptions['moderator_groups']))
749
-				$boardOptions['moderator_groups'] = array();
788
+			if (empty($boardOptions['moderator_groups'])) {
789
+							$boardOptions['moderator_groups'] = array();
790
+			}
750 791
 			if (!empty($moderator_groups))
751 792
 			{
752 793
 				$request = $smcFunc['db_query']('', '
@@ -777,8 +818,9 @@  discard block
 block discarded – undo
777 818
 		if (!empty($boardOptions['moderator_groups']))
778 819
 		{
779 820
 			$inserts = array();
780
-			foreach ($boardOptions['moderator_groups'] as $moderator_group)
781
-				$inserts[] = array($board_id, $moderator_group);
821
+			foreach ($boardOptions['moderator_groups'] as $moderator_group) {
822
+							$inserts[] = array($board_id, $moderator_group);
823
+			}
782 824
 
783 825
 			$smcFunc['db_insert']('insert',
784 826
 				'{db_prefix}moderator_groups',
@@ -792,14 +834,16 @@  discard block
 block discarded – undo
792 834
 		updateSettings(array('settings_updated' => time()));
793 835
 	}
794 836
 
795
-	if (isset($boardOptions['move_to']))
796
-		reorderBoards();
837
+	if (isset($boardOptions['move_to'])) {
838
+			reorderBoards();
839
+	}
797 840
 
798 841
 	clean_cache('data');
799 842
 
800
-	if (empty($boardOptions['dont_log']))
801
-		logAction('edit_board', array('board' => $board_id), 'admin');
802
-}
843
+	if (empty($boardOptions['dont_log'])) {
844
+			logAction('edit_board', array('board' => $board_id), 'admin');
845
+	}
846
+	}
803 847
 
804 848
 /**
805 849
  * Create a new board and set its properties and position.
@@ -815,11 +859,13 @@  discard block
 block discarded – undo
815 859
 	global $boards, $smcFunc;
816 860
 
817 861
 	// Trigger an error if one of the required values is not set.
818
-	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category']))
819
-		trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
862
+	if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) {
863
+			trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR);
864
+	}
820 865
 
821
-	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board']))
822
-		trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
866
+	if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) {
867
+			trigger_error('createBoard(): Target board is not set', E_USER_ERROR);
868
+	}
823 869
 
824 870
 	// Set every optional value to its default value.
825 871
 	$boardOptions += array(
@@ -853,8 +899,9 @@  discard block
 block discarded – undo
853 899
 		1
854 900
 	);
855 901
 
856
-	if (empty($board_id))
857
-		return 0;
902
+	if (empty($board_id)) {
903
+			return 0;
904
+	}
858 905
 
859 906
 	// Change the board according to the given specifications.
860 907
 	modifyBoard($board_id, $boardOptions);
@@ -917,8 +964,9 @@  discard block
 block discarded – undo
917 964
 	global $sourcedir, $boards, $smcFunc;
918 965
 
919 966
 	// No boards to delete? Return!
920
-	if (empty($boards_to_remove))
921
-		return;
967
+	if (empty($boards_to_remove)) {
968
+			return;
969
+	}
922 970
 
923 971
 	getBoardTree();
924 972
 
@@ -929,12 +977,14 @@  discard block
 block discarded – undo
929 977
 	{
930 978
 		// Get a list of the child boards that will also be removed.
931 979
 		$child_boards_to_remove = array();
932
-		foreach ($boards_to_remove as $board_to_remove)
933
-			recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
980
+		foreach ($boards_to_remove as $board_to_remove) {
981
+					recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
982
+		}
934 983
 
935 984
 		// Merge the children with their parents.
936
-		if (!empty($child_boards_to_remove))
937
-			$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
985
+		if (!empty($child_boards_to_remove)) {
986
+					$boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
987
+		}
938 988
 	}
939 989
 	// Move the children to a safe home.
940 990
 	else
@@ -942,10 +992,11 @@  discard block
 block discarded – undo
942 992
 		foreach ($boards_to_remove as $id_board)
943 993
 		{
944 994
 			// @todo Separate category?
945
-			if ($moveChildrenTo === 0)
946
-				fixChildren($id_board, 0, 0);
947
-			else
948
-				fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
995
+			if ($moveChildrenTo === 0) {
996
+							fixChildren($id_board, 0, 0);
997
+			} else {
998
+							fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
999
+			}
949 1000
 		}
950 1001
 	}
951 1002
 
@@ -959,8 +1010,9 @@  discard block
 block discarded – undo
959 1010
 		)
960 1011
 	);
961 1012
 	$topics = array();
962
-	while ($row = $smcFunc['db_fetch_assoc']($request))
963
-		$topics[] = $row['id_topic'];
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$topics[] = $row['id_topic'];
1015
+	}
964 1016
 	$smcFunc['db_free_result']($request);
965 1017
 
966 1018
 	require_once($sourcedir . '/RemoveTopic.php');
@@ -1048,8 +1100,9 @@  discard block
 block discarded – undo
1048 1100
 	clean_cache('data');
1049 1101
 
1050 1102
 	// Let's do some serious logging.
1051
-	foreach ($boards_to_remove as $id_board)
1052
-		logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1103
+	foreach ($boards_to_remove as $id_board) {
1104
+			logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
1105
+	}
1053 1106
 
1054 1107
 	reorderBoards();
1055 1108
 }
@@ -1068,8 +1121,8 @@  discard block
 block discarded – undo
1068 1121
 	$board_order = 0;
1069 1122
 	foreach ($cat_tree as $catID => $dummy)
1070 1123
 	{
1071
-		foreach ($boardList[$catID] as $boardID)
1072
-			if ($boards[$boardID]['order'] != ++$board_order)
1124
+		foreach ($boardList[$catID] as $boardID) {
1125
+					if ($boards[$boardID]['order'] != ++$board_order)
1073 1126
 				$smcFunc['db_query']('', '
1074 1127
 					UPDATE {db_prefix}boards
1075 1128
 					SET board_order = {int:new_order}
@@ -1079,6 +1132,7 @@  discard block
 block discarded – undo
1079 1132
 						'selected_board' => $boardID,
1080 1133
 					)
1081 1134
 				);
1135
+		}
1082 1136
 	}
1083 1137
 
1084 1138
 	// Empty the board order cache
@@ -1107,8 +1161,9 @@  discard block
 block discarded – undo
1107 1161
 		)
1108 1162
 	);
1109 1163
 	$children = array();
1110
-	while ($row = $smcFunc['db_fetch_assoc']($result))
1111
-		$children[] = $row['id_board'];
1164
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
1165
+			$children[] = $row['id_board'];
1166
+	}
1112 1167
 	$smcFunc['db_free_result']($result);
1113 1168
 
1114 1169
 	// ...and set it to a new parent and child_level.
@@ -1124,9 +1179,10 @@  discard block
 block discarded – undo
1124 1179
 	);
1125 1180
 
1126 1181
 	// Recursively fix the children of the children.
1127
-	foreach ($children as $child)
1128
-		fixChildren($child, $newLevel + 1, $child);
1129
-}
1182
+	foreach ($children as $child) {
1183
+			fixChildren($child, $newLevel + 1, $child);
1184
+	}
1185
+	}
1130 1186
 
1131 1187
 /**
1132 1188
  * Tries to load up the entire board order and category very very quickly
@@ -1143,8 +1199,9 @@  discard block
 block discarded – undo
1143 1199
 		'boards' => array(),
1144 1200
 	);
1145 1201
 
1146
-	if (!empty($tree_order['boards']))
1147
-		return $tree_order;
1202
+	if (!empty($tree_order['boards'])) {
1203
+			return $tree_order;
1204
+	}
1148 1205
 
1149 1206
 	if (($cached = cache_get_data('board_order', 86400)) !== null)
1150 1207
 	{
@@ -1160,8 +1217,9 @@  discard block
 block discarded – undo
1160 1217
 	);
1161 1218
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1219
 	{
1163
-		if (!in_array($row['id_cat'], $tree_order['cats']))
1164
-			$tree_order['cats'][] = $row['id_cat'];
1220
+		if (!in_array($row['id_cat'], $tree_order['cats'])) {
1221
+					$tree_order['cats'][] = $row['id_cat'];
1222
+		}
1165 1223
 		$tree_order['boards'][] = $row['id_board'];
1166 1224
 	}
1167 1225
 	$smcFunc['db_free_result']($request);
@@ -1181,16 +1239,19 @@  discard block
 block discarded – undo
1181 1239
 	$tree = getTreeOrder();
1182 1240
 
1183 1241
 	$ordered = array();
1184
-	foreach ($tree['boards'] as $board)
1185
-		if (!empty($boards[$board]))
1242
+	foreach ($tree['boards'] as $board) {
1243
+			if (!empty($boards[$board]))
1186 1244
 		{
1187 1245
 			$ordered[$board] = $boards[$board];
1246
+	}
1188 1247
 
1189
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards']))
1190
-				sortBoards($ordered[$board]['boards']);
1248
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) {
1249
+							sortBoards($ordered[$board]['boards']);
1250
+			}
1191 1251
 
1192
-			if (is_array($ordered[$board]) && !empty($ordered[$board]['children']))
1193
-				sortBoards($ordered[$board]['children']);
1252
+			if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) {
1253
+							sortBoards($ordered[$board]['children']);
1254
+			}
1194 1255
 		}
1195 1256
 
1196 1257
 	$boards = $ordered;
@@ -1206,12 +1267,14 @@  discard block
 block discarded – undo
1206 1267
 	$tree = getTreeOrder();
1207 1268
 
1208 1269
 	$ordered = array();
1209
-	foreach ($tree['cats'] as $cat)
1210
-		if (!empty($categories[$cat]))
1270
+	foreach ($tree['cats'] as $cat) {
1271
+			if (!empty($categories[$cat]))
1211 1272
 		{
1212 1273
 			$ordered[$cat] = $categories[$cat];
1213
-			if (!empty($ordered[$cat]['boards']))
1214
-				sortBoards($ordered[$cat]['boards']);
1274
+	}
1275
+			if (!empty($ordered[$cat]['boards'])) {
1276
+							sortBoards($ordered[$cat]['boards']);
1277
+			}
1215 1278
 		}
1216 1279
 
1217 1280
 	$categories = $ordered;
@@ -1227,8 +1290,9 @@  discard block
 block discarded – undo
1227 1290
 {
1228 1291
 	global $smcFunc, $scripturl, $txt;
1229 1292
 
1230
-	if (empty($boards))
1231
-		return array();
1293
+	if (empty($boards)) {
1294
+			return array();
1295
+	}
1232 1296
 
1233 1297
 	$request = $smcFunc['db_query']('', '
1234 1298
 		SELECT mem.id_member, mem.real_name, mo.id_board
@@ -1242,8 +1306,9 @@  discard block
 block discarded – undo
1242 1306
 	$moderators = array();
1243 1307
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1244 1308
 	{
1245
-		if (empty($moderators[$row['id_board']]))
1246
-			$moderators[$row['id_board']] = array();
1309
+		if (empty($moderators[$row['id_board']])) {
1310
+					$moderators[$row['id_board']] = array();
1311
+		}
1247 1312
 
1248 1313
 		$moderators[$row['id_board']][] = array(
1249 1314
 			'id' => $row['id_member'],
@@ -1267,8 +1332,9 @@  discard block
 block discarded – undo
1267 1332
 {
1268 1333
 	global $smcFunc, $scripturl, $txt;
1269 1334
 
1270
-	if (empty($boards))
1271
-		return array();
1335
+	if (empty($boards)) {
1336
+			return array();
1337
+	}
1272 1338
 
1273 1339
 	$request = $smcFunc['db_query']('', '
1274 1340
 		SELECT mg.id_group, mg.group_name, bg.id_board
@@ -1282,8 +1348,9 @@  discard block
 block discarded – undo
1282 1348
 	$groups = array();
1283 1349
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1284 1350
 	{
1285
-		if (empty($groups[$row['id_board']]))
1286
-			$groups[$row['id_board']] = array();
1351
+		if (empty($groups[$row['id_board']])) {
1352
+					$groups[$row['id_board']] = array();
1353
+		}
1287 1354
 
1288 1355
 		$groups[$row['id_board']][] = array(
1289 1356
 			'id' => $row['id_group'],
@@ -1358,8 +1425,9 @@  discard block
 block discarded – undo
1358 1425
 
1359 1426
 		if (!empty($row['id_board']))
1360 1427
 		{
1361
-			if ($row['child_level'] != $curLevel)
1362
-				$prevBoard = 0;
1428
+			if ($row['child_level'] != $curLevel) {
1429
+							$prevBoard = 0;
1430
+			}
1363 1431
 
1364 1432
 			$boards[$row['id_board']] = array(
1365 1433
 				'id' => $row['id_board'],
@@ -1391,16 +1459,16 @@  discard block
 block discarded – undo
1391 1459
 					'children' => array()
1392 1460
 				);
1393 1461
 				$boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']];
1394
-			}
1395
-			else
1462
+			} else
1396 1463
 			{
1397 1464
 				// Parent doesn't exist!
1398
-				if (!isset($boards[$row['id_parent']]['tree']))
1399
-					fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1465
+				if (!isset($boards[$row['id_parent']]['tree'])) {
1466
+									fatal_lang_error('no_valid_parent', false, array($row['board_name']));
1467
+				}
1400 1468
 
1401 1469
 				// Wrong childlevel...we can silently fix this...
1402
-				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1)
1403
-					$smcFunc['db_query']('', '
1470
+				if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) {
1471
+									$smcFunc['db_query']('', '
1404 1472
 						UPDATE {db_prefix}boards
1405 1473
 						SET child_level = {int:new_child_level}
1406 1474
 						WHERE id_board = {int:selected_board}',
@@ -1409,6 +1477,7 @@  discard block
 block discarded – undo
1409 1477
 							'selected_board' => $row['id_board'],
1410 1478
 						)
1411 1479
 					);
1480
+				}
1412 1481
 
1413 1482
 				$boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array(
1414 1483
 					'node' => &$boards[$row['id_board']],
@@ -1442,8 +1511,9 @@  discard block
 block discarded – undo
1442 1511
  */
1443 1512
 function recursiveBoards(&$_boardList, &$_tree)
1444 1513
 {
1445
-	if (empty($_tree['children']))
1446
-		return;
1514
+	if (empty($_tree['children'])) {
1515
+			return;
1516
+	}
1447 1517
 
1448 1518
 	foreach ($_tree['children'] as $id => $node)
1449 1519
 	{
@@ -1462,11 +1532,13 @@  discard block
 block discarded – undo
1462 1532
 {
1463 1533
 	global $boards;
1464 1534
 
1465
-	if (empty($boards[$child]['parent']))
1466
-		return false;
1535
+	if (empty($boards[$child]['parent'])) {
1536
+			return false;
1537
+	}
1467 1538
 
1468
-	if ($boards[$child]['parent'] == $parent)
1469
-		return true;
1539
+	if ($boards[$child]['parent'] == $parent) {
1540
+			return true;
1541
+	}
1470 1542
 
1471 1543
 	return isChildOf($boards[$child]['parent'], $parent);
1472 1544
 }
Please login to merge, or discard this patch.
Sources/Subs-Package.php 1 patch
Braces   +853 added lines, -669 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 3
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 /**
23 24
  * Reads a .tar.gz file, filename, in and extracts file(s) from it.
@@ -67,47 +68,53 @@  discard block
 block discarded – undo
67 68
 	loadLanguage('Packages');
68 69
 
69 70
 	// This function sorta needs gzinflate!
70
-	if (!function_exists('gzinflate'))
71
-		fatal_lang_error('package_no_zlib', 'critical');
71
+	if (!function_exists('gzinflate')) {
72
+			fatal_lang_error('package_no_zlib', 'critical');
73
+	}
72 74
 
73 75
 	if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://')
74 76
 	{
75 77
 		$data = fetch_web_data($gzfilename);
76 78
 
77
-		if ($data === false)
78
-			return false;
79
-	}
80
-	else
79
+		if ($data === false) {
80
+					return false;
81
+		}
82
+	} else
81 83
 	{
82 84
 		$data = @file_get_contents($gzfilename);
83 85
 
84
-		if ($data === false)
85
-			return false;
86
+		if ($data === false) {
87
+					return false;
88
+		}
86 89
 	}
87 90
 
88 91
 	umask(0);
89
-	if (!$single_file && $destination !== null && !file_exists($destination))
90
-		mktree($destination, 0777);
92
+	if (!$single_file && $destination !== null && !file_exists($destination)) {
93
+			mktree($destination, 0777);
94
+	}
91 95
 
92 96
 	// No signature?
93
-	if (strlen($data) < 2)
94
-		return false;
97
+	if (strlen($data) < 2) {
98
+			return false;
99
+	}
95 100
 
96 101
 	$id = unpack('H2a/H2b', substr($data, 0, 2));
97 102
 	if (strtolower($id['a'] . $id['b']) != '1f8b')
98 103
 	{
99 104
 		// Okay, this ain't no tar.gz, but maybe it's a zip file.
100
-		if (substr($data, 0, 2) == 'PK')
101
-			return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
102
-		else
103
-			return false;
105
+		if (substr($data, 0, 2) == 'PK') {
106
+					return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
107
+		} else {
108
+					return false;
109
+		}
104 110
 	}
105 111
 
106 112
 	$flags = unpack('Ct/Cf', substr($data, 2, 2));
107 113
 
108 114
 	// Not deflate!
109
-	if ($flags['t'] != 8)
110
-		return false;
115
+	if ($flags['t'] != 8) {
116
+			return false;
117
+	}
111 118
 	$flags = $flags['f'];
112 119
 
113 120
 	$offset = 10;
@@ -117,18 +124,21 @@  discard block
 block discarded – undo
117 124
 	// @todo Might be mussed.
118 125
 	if ($flags & 12)
119 126
 	{
120
-		while ($flags & 8 && $data{$offset++} != "\0")
121
-			continue;
122
-		while ($flags & 4 && $data{$offset++} != "\0")
123
-			continue;
127
+		while ($flags & 8 && $data{$offset++} != "\0") {
128
+					continue;
129
+		}
130
+		while ($flags & 4 && $data{$offset++} != "\0") {
131
+					continue;
132
+		}
124 133
 	}
125 134
 
126 135
 	$crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8));
127 136
 	$data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset));
128 137
 
129 138
 	// smf_crc32 and crc32 may not return the same results, so we accept either.
130
-	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data))
131
-		return false;
139
+	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) {
140
+			return false;
141
+	}
132 142
 
133 143
 	$blocks = strlen($data) / 512 - 1;
134 144
 	$offset = 0;
@@ -149,83 +159,98 @@  discard block
 block discarded – undo
149 159
 
150 160
 		foreach ($current as $k => $v)
151 161
 		{
152
-			if (in_array($k, $octdec))
153
-				$current[$k] = octdec(trim($v));
154
-			else
155
-				$current[$k] = trim($v);
162
+			if (in_array($k, $octdec)) {
163
+							$current[$k] = octdec(trim($v));
164
+			} else {
165
+							$current[$k] = trim($v);
166
+			}
156 167
 		}
157 168
 
158
-		if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
159
-			$current['filename'] .= '/';
169
+		if ($current['type'] == 5 && substr($current['filename'], -1) != '/') {
170
+					$current['filename'] .= '/';
171
+		}
160 172
 
161 173
 		$checksum = 256;
162
-		for ($i = 0; $i < 148; $i++)
163
-			$checksum += ord($header{$i});
164
-		for ($i = 156; $i < 512; $i++)
165
-			$checksum += ord($header{$i});
174
+		for ($i = 0; $i < 148; $i++) {
175
+					$checksum += ord($header{$i});
176
+		}
177
+		for ($i = 156; $i < 512; $i++) {
178
+					$checksum += ord($header{$i});
179
+		}
166 180
 
167
-		if ($current['checksum'] != $checksum)
168
-			break;
181
+		if ($current['checksum'] != $checksum) {
182
+					break;
183
+		}
169 184
 
170 185
 		$size = ceil($current['size'] / 512);
171 186
 		$current['data'] = substr($data, ++$offset << 9, $current['size']);
172 187
 		$offset += $size;
173 188
 
174 189
 		// Not a directory and doesn't exist already...
175
-		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename']))
176
-			$write_this = true;
190
+		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) {
191
+					$write_this = true;
192
+		}
177 193
 		// File exists... check if it is newer.
178
-		elseif (substr($current['filename'], -1, 1) != '/')
179
-			$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
194
+		elseif (substr($current['filename'], -1, 1) != '/') {
195
+					$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
196
+		}
180 197
 		// Folder... create.
181 198
 		elseif ($destination !== null && !$single_file)
182 199
 		{
183 200
 			// Protect from accidental parent directory writing...
184 201
 			$current['filename'] = strtr($current['filename'], array('../' => '', '/..' => ''));
185 202
 
186
-			if (!file_exists($destination . '/' . $current['filename']))
187
-				mktree($destination . '/' . $current['filename'], 0777);
203
+			if (!file_exists($destination . '/' . $current['filename'])) {
204
+							mktree($destination . '/' . $current['filename'], 0777);
205
+			}
188 206
 			$write_this = false;
207
+		} else {
208
+					$write_this = false;
189 209
 		}
190
-		else
191
-			$write_this = false;
192 210
 
193 211
 		if ($write_this && $destination !== null)
194 212
 		{
195
-			if (strpos($current['filename'], '/') !== false && !$single_file)
196
-				mktree($destination . '/' . dirname($current['filename']), 0777);
213
+			if (strpos($current['filename'], '/') !== false && !$single_file) {
214
+							mktree($destination . '/' . dirname($current['filename']), 0777);
215
+			}
197 216
 
198 217
 			// Is this the file we're looking for?
199
-			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename'])))
200
-				return $current['data'];
218
+			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) {
219
+							return $current['data'];
220
+			}
201 221
 			// If we're looking for another file, keep going.
202
-			elseif ($single_file)
203
-				continue;
222
+			elseif ($single_file) {
223
+							continue;
224
+			}
204 225
 			// Looking for restricted files?
205
-			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract))
206
-				continue;
226
+			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) {
227
+							continue;
228
+			}
207 229
 
208 230
 			package_put_contents($destination . '/' . $current['filename'], $current['data']);
209 231
 		}
210 232
 
211
-		if (substr($current['filename'], -1, 1) != '/')
212
-			$return[] = array(
233
+		if (substr($current['filename'], -1, 1) != '/') {
234
+					$return[] = array(
213 235
 				'filename' => $current['filename'],
214 236
 				'md5' => md5($current['data']),
215 237
 				'preview' => substr($current['data'], 0, 100),
216 238
 				'size' => $current['size'],
217 239
 				'skipped' => false
218 240
 			);
241
+		}
219 242
 	}
220 243
 
221
-	if ($destination !== null && !$single_file)
222
-		package_flush_cache();
244
+	if ($destination !== null && !$single_file) {
245
+			package_flush_cache();
246
+	}
223 247
 
224
-	if ($single_file)
225
-		return false;
226
-	else
227
-		return $return;
228
-}
248
+	if ($single_file) {
249
+			return false;
250
+	} else {
251
+			return $return;
252
+	}
253
+	}
229 254
 
230 255
 /**
231 256
  * Extract zip data. A functional copy of {@list read_zip_data()}.
@@ -254,65 +279,74 @@  discard block
 block discarded – undo
254 279
 			{
255 280
 				$i = $iterator->getSubPathname();
256 281
 				// If this is a file, and it doesn't exist.... happy days!
257
-				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i))
258
-					$write_this = true;
282
+				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) {
283
+									$write_this = true;
284
+				}
259 285
 				// If the file exists, we may not want to overwrite it.
260
-				elseif (substr($i, -1) != '/')
261
-					$write_this = $overwrite;
262
-				else
263
-					$write_this = false;
286
+				elseif (substr($i, -1) != '/') {
287
+									$write_this = $overwrite;
288
+				} else {
289
+									$write_this = false;
290
+				}
264 291
 
265 292
 				// Get the actual compressed data.
266
-				if (!$file_info->isDir())
267
-					$file_data = file_get_contents($file_info);
268
-				elseif ($destination !== null && !$single_file)
293
+				if (!$file_info->isDir()) {
294
+									$file_data = file_get_contents($file_info);
295
+				} elseif ($destination !== null && !$single_file)
269 296
 				{
270 297
 					// Folder... create.
271
-					if (!file_exists($destination . '/' . $i))
272
-						mktree($destination . '/' . $i, 0777);
298
+					if (!file_exists($destination . '/' . $i)) {
299
+											mktree($destination . '/' . $i, 0777);
300
+					}
273 301
 					$file_data = null;
302
+				} else {
303
+									$file_data = null;
274 304
 				}
275
-				else
276
-					$file_data = null;
277 305
 
278 306
 				// Okay!  We can write this file, looks good from here...
279 307
 				if ($write_this && $destination !== null)
280 308
 				{
281
-					if (!$single_file && !is_dir($destination . '/' . dirname($i)))
282
-						mktree($destination . '/' . dirname($i), 0777);
309
+					if (!$single_file && !is_dir($destination . '/' . dirname($i))) {
310
+											mktree($destination . '/' . dirname($i), 0777);
311
+					}
283 312
 
284 313
 					// If we're looking for a specific file, and this is it... ka-bam, baby.
285
-					if ($single_file && ($destination == $i || $destination == '*/' . basename($i)))
286
-						return $file_data;
314
+					if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) {
315
+											return $file_data;
316
+					}
287 317
 					// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
288
-					elseif ($single_file)
289
-						continue;
318
+					elseif ($single_file) {
319
+											continue;
320
+					}
290 321
 					// Don't really want this?
291
-					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract))
292
-						continue;
322
+					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) {
323
+											continue;
324
+					}
293 325
 
294 326
 					package_put_contents($destination . '/' . $i, $file_data);
295 327
 				}
296 328
 
297
-				if (substr($i, -1, 1) != '/')
298
-					$return[] = array(
329
+				if (substr($i, -1, 1) != '/') {
330
+									$return[] = array(
299 331
 						'filename' => $i,
300 332
 						'md5' => md5($file_data),
301 333
 						'preview' => substr($file_data, 0, 100),
302 334
 						'size' => strlen($file_data),
303 335
 						'skipped' => false
304 336
 					);
337
+				}
305 338
 			}
306 339
 
307
-		if ($destination !== null && !$single_file)
308
-			package_flush_cache();
340
+		if ($destination !== null && !$single_file) {
341
+					package_flush_cache();
342
+		}
309 343
 
310
-		if ($single_file)
311
-			return false;
312
-		else
313
-			return $return;
314
-	}
315
-	catch (Exception $e)
344
+		if ($single_file) {
345
+					return false;
346
+		} else {
347
+					return $return;
348
+		}
349
+	} catch (Exception $e)
316 350
 	{
317 351
 		return false;
318 352
 	}
@@ -334,13 +368,15 @@  discard block
 block discarded – undo
334 368
 function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
335 369
 {
336 370
 	umask(0);
337
-	if ($destination !== null && !file_exists($destination) && !$single_file)
338
-		mktree($destination, 0777);
371
+	if ($destination !== null && !file_exists($destination) && !$single_file) {
372
+			mktree($destination, 0777);
373
+	}
339 374
 
340 375
 	// Look for the end of directory signature 0x06054b50
341 376
 	$data_ecr = explode("\x50\x4b\x05\x06", $data);
342
-	if (!isset($data_ecr[1]))
343
-		return false;
377
+	if (!isset($data_ecr[1])) {
378
+			return false;
379
+	}
344 380
 
345 381
 	$return = array();
346 382
 
@@ -355,8 +391,9 @@  discard block
 block discarded – undo
355 391
 	array_shift($file_sections);
356 392
 
357 393
 	// sections and count from the signature must match or the zip file is bad
358
-	if (count($file_sections) != $zip_info['files'])
359
-		return false;
394
+	if (count($file_sections) != $zip_info['files']) {
395
+			return false;
396
+	}
360 397
 
361 398
 	// go though each file in the archive
362 399
 	foreach ($file_sections as $data)
@@ -378,68 +415,79 @@  discard block
 block discarded – undo
378 415
 		}
379 416
 
380 417
 		// If this is a file, and it doesn't exist.... happy days!
381
-		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename']))
382
-			$write_this = true;
418
+		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) {
419
+					$write_this = true;
420
+		}
383 421
 		// If the file exists, we may not want to overwrite it.
384
-		elseif (substr($file_info['filename'], -1) != '/')
385
-			$write_this = $overwrite;
422
+		elseif (substr($file_info['filename'], -1) != '/') {
423
+					$write_this = $overwrite;
424
+		}
386 425
 		// This is a directory, so we're gonna want to create it. (probably...)
387 426
 		elseif ($destination !== null && !$single_file)
388 427
 		{
389 428
 			// Just a little accident prevention, don't mind me.
390 429
 			$file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => ''));
391 430
 
392
-			if (!file_exists($destination . '/' . $file_info['filename']))
393
-				mktree($destination . '/' . $file_info['filename'], 0777);
431
+			if (!file_exists($destination . '/' . $file_info['filename'])) {
432
+							mktree($destination . '/' . $file_info['filename'], 0777);
433
+			}
394 434
 			$write_this = false;
435
+		} else {
436
+					$write_this = false;
395 437
 		}
396
-		else
397
-			$write_this = false;
398 438
 
399 439
 		// Get the actual compressed data.
400 440
 		$file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']);
401 441
 
402 442
 		// Only inflate it if we need to ;)
403
-		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size']))
404
-			$file_info['data'] = gzinflate($file_info['data']);
443
+		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) {
444
+					$file_info['data'] = gzinflate($file_info['data']);
445
+		}
405 446
 
406 447
 		// Okay!  We can write this file, looks good from here...
407 448
 		if ($write_this && $destination !== null)
408 449
 		{
409
-			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir'])))
410
-				mktree($file_info['dir'], 0777);
450
+			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) {
451
+							mktree($file_info['dir'], 0777);
452
+			}
411 453
 
412 454
 			// If we're looking for a specific file, and this is it... ka-bam, baby.
413
-			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename'])))
414
-				return $file_info['data'];
455
+			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) {
456
+							return $file_info['data'];
457
+			}
415 458
 			// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
416
-			elseif ($single_file)
417
-				continue;
459
+			elseif ($single_file) {
460
+							continue;
461
+			}
418 462
 			// Don't really want this?
419
-			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract))
420
-				continue;
463
+			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) {
464
+							continue;
465
+			}
421 466
 
422 467
 			package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']);
423 468
 		}
424 469
 
425
-		if (substr($file_info['filename'], -1, 1) != '/')
426
-			$return[] = array(
470
+		if (substr($file_info['filename'], -1, 1) != '/') {
471
+					$return[] = array(
427 472
 				'filename' => $file_info['filename'],
428 473
 				'md5' => md5($file_info['data']),
429 474
 				'preview' => substr($file_info['data'], 0, 100),
430 475
 				'size' => $file_info['size'],
431 476
 				'skipped' => false
432 477
 			);
478
+		}
433 479
 	}
434 480
 
435
-	if ($destination !== null && !$single_file)
436
-		package_flush_cache();
481
+	if ($destination !== null && !$single_file) {
482
+			package_flush_cache();
483
+	}
437 484
 
438
-	if ($single_file)
439
-		return false;
440
-	else
441
-		return $return;
442
-}
485
+	if ($single_file) {
486
+			return false;
487
+	} else {
488
+			return $return;
489
+	}
490
+	}
443 491
 
444 492
 /**
445 493
  * Checks the existence of a remote file since file_exists() does not do remote.
@@ -451,14 +499,16 @@  discard block
 block discarded – undo
451 499
 {
452 500
 	$a_url = parse_url($url);
453 501
 
454
-	if (!isset($a_url['scheme']))
455
-		return false;
502
+	if (!isset($a_url['scheme'])) {
503
+			return false;
504
+	}
456 505
 
457 506
 	// Attempt to connect...
458 507
 	$temp = '';
459 508
 	$fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8);
460
-	if (!$fid)
461
-		return false;
509
+	if (!$fid) {
510
+			return false;
511
+	}
462 512
 
463 513
 	fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n");
464 514
 	$head = fread($fid, 1024);
@@ -493,8 +543,9 @@  discard block
 block discarded – undo
493 543
 	while ($row = $smcFunc['db_fetch_assoc']($request))
494 544
 	{
495 545
 		// Already found this? If so don't add it twice!
496
-		if (in_array($row['package_id'], $found))
497
-			continue;
546
+		if (in_array($row['package_id'], $found)) {
547
+					continue;
548
+		}
498 549
 
499 550
 		$found[] = $row['package_id'];
500 551
 
@@ -529,19 +580,21 @@  discard block
 block discarded – undo
529 580
 	global $sourcedir, $packagesdir;
530 581
 
531 582
 	// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
532
-	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false)
533
-		$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
534
-	else
583
+	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) {
584
+			$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
585
+	} else
535 586
 	{
536
-		if (!file_exists($packagesdir . '/' . $gzfilename))
537
-			return 'package_get_error_not_found';
587
+		if (!file_exists($packagesdir . '/' . $gzfilename)) {
588
+					return 'package_get_error_not_found';
589
+		}
538 590
 
539
-		if (is_file($packagesdir . '/' . $gzfilename))
540
-			$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
541
-		elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml'))
542
-			$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
543
-		else
544
-			return 'package_get_error_missing_xml';
591
+		if (is_file($packagesdir . '/' . $gzfilename)) {
592
+					$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
593
+		} elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) {
594
+					$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
595
+		} else {
596
+					return 'package_get_error_missing_xml';
597
+		}
545 598
 	}
546 599
 
547 600
 	// Nothing?
@@ -549,10 +602,11 @@  discard block
 block discarded – undo
549 602
 	{
550 603
 		// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
551 604
 		$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true);
552
-		if (!empty($packageInfo))
553
-			return 'package_get_error_is_theme';
554
-		else
555
-			return 'package_get_error_is_zero';
605
+		if (!empty($packageInfo)) {
606
+					return 'package_get_error_is_theme';
607
+		} else {
608
+					return 'package_get_error_is_zero';
609
+		}
556 610
 	}
557 611
 
558 612
 	// Parse package-info.xml into an xmlArray.
@@ -560,8 +614,9 @@  discard block
 block discarded – undo
560 614
 	$packageInfo = new xmlArray($packageInfo);
561 615
 
562 616
 	// @todo Error message of some sort?
563
-	if (!$packageInfo->exists('package-info[0]'))
564
-		return 'package_get_error_packageinfo_corrupt';
617
+	if (!$packageInfo->exists('package-info[0]')) {
618
+			return 'package_get_error_packageinfo_corrupt';
619
+	}
565 620
 
566 621
 	$packageInfo = $packageInfo->path('package-info[0]');
567 622
 
@@ -580,8 +635,9 @@  discard block
 block discarded – undo
580 635
 		}
581 636
 	}
582 637
 
583
-	if (!isset($package['type']))
584
-		$package['type'] = 'modification';
638
+	if (!isset($package['type'])) {
639
+			$package['type'] = 'modification';
640
+	}
585 641
 
586 642
 	return $package;
587 643
 }
@@ -634,15 +690,14 @@  discard block
 block discarded – undo
634 690
 					{
635 691
 						$ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => ''));
636 692
 						$package_ftp->chmod($ftp_file, $perms);
693
+					} else {
694
+											smf_chmod($file, $perms);
637 695
 					}
638
-					else
639
-						smf_chmod($file, $perms);
640 696
 
641 697
 					$new_permissions = @fileperms($file);
642 698
 					$result = $new_permissions == $perms ? 'success' : 'failure';
643 699
 					unset($_SESSION['pack_ftp']['original_perms'][$file]);
644
-				}
645
-				elseif ($do_change)
700
+				} elseif ($do_change)
646 701
 				{
647 702
 					$new_permissions = '';
648 703
 					$result = 'skipped';
@@ -758,8 +813,7 @@  discard block
 block discarded – undo
758 813
 
759 814
 			$context['sub_template'] = 'show_list';
760 815
 			$context['default_list'] = 'restore_file_permissions';
761
-		}
762
-		else
816
+		} else
763 817
 		{
764 818
 			unset($listOptions['columns']['result']);
765 819
 		}
@@ -769,12 +823,14 @@  discard block
 block discarded – undo
769 823
 		createList($listOptions);
770 824
 
771 825
 		// If we just restored permissions then whereever we are, we are now done and dusted.
772
-		if (!empty($_POST['restore_perms']))
773
-			obExit();
826
+		if (!empty($_POST['restore_perms'])) {
827
+					obExit();
828
+		}
774 829
 	}
775 830
 	// Otherwise, it's entirely irrelevant?
776
-	elseif ($restore_write_status)
777
-		return true;
831
+	elseif ($restore_write_status) {
832
+			return true;
833
+	}
778 834
 
779 835
 	// This is where we report what we got up to.
780 836
 	$return_data = array(
@@ -812,11 +868,12 @@  discard block
 block discarded – undo
812 868
 			if (!in_array($_POST['ftp_path'], array('', '/')))
813 869
 			{
814 870
 				$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
815
-				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/'))
816
-					$ftp_root = substr($ftp_root, 0, -1);
871
+				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) {
872
+									$ftp_root = substr($ftp_root, 0, -1);
873
+				}
874
+			} else {
875
+							$ftp_root = $boarddir;
817 876
 			}
818
-			else
819
-				$ftp_root = $boarddir;
820 877
 
821 878
 			$_SESSION['pack_ftp'] = array(
822 879
 				'server' => $_POST['ftp_server'],
@@ -828,8 +885,9 @@  discard block
 block discarded – undo
828 885
 				'connected' => true,
829 886
 			);
830 887
 
831
-			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
832
-				updateSettings(array('package_path' => $_POST['ftp_path']));
888
+			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
889
+							updateSettings(array('package_path' => $_POST['ftp_path']));
890
+			}
833 891
 
834 892
 			// This is now the primary connection.
835 893
 			$package_ftp = $ftp;
@@ -842,12 +900,13 @@  discard block
 block discarded – undo
842 900
 		foreach ($chmodFiles as $k => $file)
843 901
 		{
844 902
 			// Sometimes this can somehow happen maybe?
845
-			if (empty($file))
846
-				unset($chmodFiles[$k]);
903
+			if (empty($file)) {
904
+							unset($chmodFiles[$k]);
905
+			}
847 906
 			// Already writable?
848
-			elseif (@is_writable($file))
849
-				$return_data['files']['writable'][] = $file;
850
-			else
907
+			elseif (@is_writable($file)) {
908
+							$return_data['files']['writable'][] = $file;
909
+			} else
851 910
 			{
852 911
 				// Now try to change that.
853 912
 				$return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file;
@@ -864,19 +923,21 @@  discard block
 block discarded – undo
864 923
 			{
865 924
 				require_once($sourcedir . '/Class-Package.php');
866 925
 				$ftp = new ftp_connection(null);
926
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
927
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
867 928
 			}
868
-			elseif ($ftp->error !== false && !isset($ftp_error))
869
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
870 929
 
871 930
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
872 931
 
873
-			if ($found_path)
874
-				$_POST['ftp_path'] = $detect_path;
875
-			elseif (!isset($_POST['ftp_path']))
876
-				$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
932
+			if ($found_path) {
933
+							$_POST['ftp_path'] = $detect_path;
934
+			} elseif (!isset($_POST['ftp_path'])) {
935
+							$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
936
+			}
877 937
 
878
-			if (!isset($_POST['ftp_username']))
879
-				$_POST['ftp_username'] = $username;
938
+			if (!isset($_POST['ftp_username'])) {
939
+							$_POST['ftp_username'] = $username;
940
+			}
880 941
 		}
881 942
 
882 943
 		$context['package_ftp'] = array(
@@ -889,8 +950,9 @@  discard block
 block discarded – undo
889 950
 		);
890 951
 
891 952
 		// Which files failed?
892
-		if (!isset($context['notwritable_files']))
893
-			$context['notwritable_files'] = array();
953
+		if (!isset($context['notwritable_files'])) {
954
+					$context['notwritable_files'] = array();
955
+		}
894 956
 		$context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']);
895 957
 
896 958
 		// Sent here to die?
@@ -923,40 +985,48 @@  discard block
 block discarded – undo
923 985
 		foreach ($files as $k => $file)
924 986
 		{
925 987
 			// If this file doesn't exist, then we actually want to look at the directory, no?
926
-			if (!file_exists($file))
927
-				$file = dirname($file);
988
+			if (!file_exists($file)) {
989
+							$file = dirname($file);
990
+			}
928 991
 
929 992
 			// This looks odd, but it's an attempt to work around PHP suExec.
930
-			if (!@is_writable($file))
931
-				smf_chmod($file, 0755);
932
-			if (!@is_writable($file))
933
-				smf_chmod($file, 0777);
934
-			if (!@is_writable(dirname($file)))
935
-				smf_chmod($file, 0755);
936
-			if (!@is_writable(dirname($file)))
937
-				smf_chmod($file, 0777);
993
+			if (!@is_writable($file)) {
994
+							smf_chmod($file, 0755);
995
+			}
996
+			if (!@is_writable($file)) {
997
+							smf_chmod($file, 0777);
998
+			}
999
+			if (!@is_writable(dirname($file))) {
1000
+							smf_chmod($file, 0755);
1001
+			}
1002
+			if (!@is_writable(dirname($file))) {
1003
+							smf_chmod($file, 0777);
1004
+			}
938 1005
 
939 1006
 			$fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb');
940 1007
 			if (@is_writable($file) && $fp)
941 1008
 			{
942 1009
 				unset($files[$k]);
943
-				if (!is_dir($file))
944
-					fclose($fp);
945
-				else
946
-					closedir($fp);
1010
+				if (!is_dir($file)) {
1011
+									fclose($fp);
1012
+				} else {
1013
+									closedir($fp);
1014
+				}
947 1015
 			}
948 1016
 		}
949 1017
 
950 1018
 		// No FTP required!
951
-		if (empty($files))
952
-			return array();
1019
+		if (empty($files)) {
1020
+					return array();
1021
+		}
953 1022
 	}
954 1023
 
955 1024
 	// They've opted to not use FTP, and try anyway.
956 1025
 	if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false)
957 1026
 	{
958
-		if ($files === null)
959
-			return array();
1027
+		if ($files === null) {
1028
+					return array();
1029
+		}
960 1030
 
961 1031
 		foreach ($files as $k => $file)
962 1032
 		{
@@ -968,26 +1038,29 @@  discard block
 block discarded – undo
968 1038
 				smf_chmod($file, 0755);
969 1039
 			}
970 1040
 
971
-			if (!@is_writable($file))
972
-				smf_chmod($file, 0777);
973
-			if (!@is_writable(dirname($file)))
974
-				smf_chmod(dirname($file), 0777);
1041
+			if (!@is_writable($file)) {
1042
+							smf_chmod($file, 0777);
1043
+			}
1044
+			if (!@is_writable(dirname($file))) {
1045
+							smf_chmod(dirname($file), 0777);
1046
+			}
975 1047
 
976
-			if (@is_writable($file))
977
-				unset($files[$k]);
1048
+			if (@is_writable($file)) {
1049
+							unset($files[$k]);
1050
+			}
978 1051
 		}
979 1052
 
980 1053
 		return $files;
981
-	}
982
-	elseif (isset($_SESSION['pack_ftp']))
1054
+	} elseif (isset($_SESSION['pack_ftp']))
983 1055
 	{
984 1056
 		// Load the file containing the ftp_connection class.
985 1057
 		require_once($sourcedir . '/Class-Package.php');
986 1058
 
987 1059
 		$package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password']));
988 1060
 
989
-		if ($files === null)
990
-			return array();
1061
+		if ($files === null) {
1062
+					return array();
1063
+		}
991 1064
 
992 1065
 		foreach ($files as $k => $file)
993 1066
 		{
@@ -1001,13 +1074,16 @@  discard block
 block discarded – undo
1001 1074
 				$package_ftp->chmod($ftp_file, 0755);
1002 1075
 			}
1003 1076
 
1004
-			if (!@is_writable($file))
1005
-				$package_ftp->chmod($ftp_file, 0777);
1006
-			if (!@is_writable(dirname($file)))
1007
-				$package_ftp->chmod(dirname($ftp_file), 0777);
1077
+			if (!@is_writable($file)) {
1078
+							$package_ftp->chmod($ftp_file, 0777);
1079
+			}
1080
+			if (!@is_writable(dirname($file))) {
1081
+							$package_ftp->chmod(dirname($ftp_file), 0777);
1082
+			}
1008 1083
 
1009
-			if (@is_writable($file))
1010
-				unset($files[$k]);
1084
+			if (@is_writable($file)) {
1085
+							unset($files[$k]);
1086
+			}
1011 1087
 		}
1012 1088
 
1013 1089
 		return $files;
@@ -1019,8 +1095,7 @@  discard block
 block discarded – undo
1019 1095
 
1020 1096
 		$files = packageRequireFTP($destination_url, $files, $return);
1021 1097
 		return $files;
1022
-	}
1023
-	elseif (isset($_POST['ftp_username']))
1098
+	} elseif (isset($_POST['ftp_username']))
1024 1099
 	{
1025 1100
 		require_once($sourcedir . '/Class-Package.php');
1026 1101
 		$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
@@ -1042,19 +1117,21 @@  discard block
 block discarded – undo
1042 1117
 		{
1043 1118
 			require_once($sourcedir . '/Class-Package.php');
1044 1119
 			$ftp = new ftp_connection(null);
1120
+		} elseif ($ftp->error !== false && !isset($ftp_error)) {
1121
+					$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1045 1122
 		}
1046
-		elseif ($ftp->error !== false && !isset($ftp_error))
1047
-			$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1048 1123
 
1049 1124
 		list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
1050 1125
 
1051
-		if ($found_path)
1052
-			$_POST['ftp_path'] = $detect_path;
1053
-		elseif (!isset($_POST['ftp_path']))
1054
-			$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1126
+		if ($found_path) {
1127
+					$_POST['ftp_path'] = $detect_path;
1128
+		} elseif (!isset($_POST['ftp_path'])) {
1129
+					$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1130
+		}
1055 1131
 
1056
-		if (!isset($_POST['ftp_username']))
1057
-			$_POST['ftp_username'] = $username;
1132
+		if (!isset($_POST['ftp_username'])) {
1133
+					$_POST['ftp_username'] = $username;
1134
+		}
1058 1135
 
1059 1136
 		$context['package_ftp'] = array(
1060 1137
 			'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -1066,23 +1143,24 @@  discard block
 block discarded – undo
1066 1143
 		);
1067 1144
 
1068 1145
 		// If we're returning dump out here.
1069
-		if ($return)
1070
-			return $files;
1146
+		if ($return) {
1147
+					return $files;
1148
+		}
1071 1149
 
1072 1150
 		$context['page_title'] = $txt['package_ftp_necessary'];
1073 1151
 		$context['sub_template'] = 'ftp_required';
1074 1152
 		obExit();
1075
-	}
1076
-	else
1153
+	} else
1077 1154
 	{
1078 1155
 		if (!in_array($_POST['ftp_path'], array('', '/')))
1079 1156
 		{
1080 1157
 			$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
1081
-			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/'))
1082
-				$ftp_root = substr($ftp_root, 0, -1);
1158
+			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) {
1159
+							$ftp_root = substr($ftp_root, 0, -1);
1160
+			}
1161
+		} else {
1162
+					$ftp_root = $boarddir;
1083 1163
 		}
1084
-		else
1085
-			$ftp_root = $boarddir;
1086 1164
 
1087 1165
 		$_SESSION['pack_ftp'] = array(
1088 1166
 			'server' => $_POST['ftp_server'],
@@ -1093,8 +1171,9 @@  discard block
 block discarded – undo
1093 1171
 			'root' => $ftp_root,
1094 1172
 		);
1095 1173
 
1096
-		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
1097
-			updateSettings(array('package_path' => $_POST['ftp_path']));
1174
+		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
1175
+					updateSettings(array('package_path' => $_POST['ftp_path']));
1176
+		}
1098 1177
 
1099 1178
 		$files = packageRequireFTP($destination_url, $files, $return);
1100 1179
 	}
@@ -1122,16 +1201,18 @@  discard block
 block discarded – undo
1122 1201
 	global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc;
1123 1202
 
1124 1203
 	// Mayday!  That action doesn't exist!!
1125
-	if (empty($packageXML) || !$packageXML->exists($method))
1126
-		return array();
1204
+	if (empty($packageXML) || !$packageXML->exists($method)) {
1205
+			return array();
1206
+	}
1127 1207
 
1128 1208
 	// We haven't found the package script yet...
1129 1209
 	$script = false;
1130 1210
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1131 1211
 
1132 1212
 	// Emulation support...
1133
-	if (!empty($_SESSION['version_emulate']))
1134
-		$the_version = $_SESSION['version_emulate'];
1213
+	if (!empty($_SESSION['version_emulate'])) {
1214
+			$the_version = $_SESSION['version_emulate'];
1215
+	}
1135 1216
 
1136 1217
 	// Single package emulation
1137 1218
 	if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package']))
@@ -1139,8 +1220,9 @@  discard block
 block discarded – undo
1139 1220
 		$the_version = $_REQUEST['ve'];
1140 1221
 		$_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version;
1141 1222
 	}
1142
-	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']])))
1143
-		$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1223
+	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) {
1224
+			$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1225
+	}
1144 1226
 
1145 1227
 	// Get all the versions of this method and find the right one.
1146 1228
 	$these_methods = $packageXML->set($method);
@@ -1150,16 +1232,18 @@  discard block
 block discarded – undo
1150 1232
 		if ($this_method->exists('@for'))
1151 1233
 		{
1152 1234
 			// Don't keep going if this won't work for this version of SMF.
1153
-			if (!matchPackageVersion($the_version, $this_method->fetch('@for')))
1154
-				continue;
1235
+			if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) {
1236
+							continue;
1237
+			}
1155 1238
 		}
1156 1239
 
1157 1240
 		// Upgrades may go from a certain old version of the mod.
1158 1241
 		if ($method == 'upgrade' && $this_method->exists('@from'))
1159 1242
 		{
1160 1243
 			// Well, this is for the wrong old version...
1161
-			if (!matchPackageVersion($previous_version, $this_method->fetch('@from')))
1162
-				continue;
1244
+			if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) {
1245
+							continue;
1246
+			}
1163 1247
 		}
1164 1248
 
1165 1249
 		// We've found it!
@@ -1168,8 +1252,9 @@  discard block
 block discarded – undo
1168 1252
 	}
1169 1253
 
1170 1254
 	// Bad news, a matching script wasn't found!
1171
-	if (!($script instanceof xmlArray))
1172
-		return array();
1255
+	if (!($script instanceof xmlArray)) {
1256
+			return array();
1257
+	}
1173 1258
 
1174 1259
 	// Find all the actions in this method - in theory, these should only be allowed actions. (* means all.)
1175 1260
 	$actions = $script->set('*');
@@ -1198,12 +1283,12 @@  discard block
 block discarded – undo
1198 1283
 					if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language))
1199 1284
 					{
1200 1285
 						// In case the user put the blocks in the wrong order.
1201
-						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default')
1202
-							$context[$type][] = 'default';
1286
+						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') {
1287
+													$context[$type][] = 'default';
1288
+						}
1203 1289
 
1204 1290
 						$context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
1205
-					}
1206
-					else
1291
+					} else
1207 1292
 					{
1208 1293
 						// We don't want this now, but we'll allow the user to select to read it.
1209 1294
 						$context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
@@ -1218,9 +1303,9 @@  discard block
 block discarded – undo
1218 1303
 					{
1219 1304
 						$context[$type][] = 'default';
1220 1305
 						continue;
1306
+					} else {
1307
+											$context[$type]['selected'] = 'default';
1221 1308
 					}
1222
-					else
1223
-						$context[$type]['selected'] = 'default';
1224 1309
 				}
1225 1310
 			}
1226 1311
 
@@ -1230,9 +1315,9 @@  discard block
 block discarded – undo
1230 1315
 				$filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod'));
1231 1316
 				package_put_contents($filename, $action->fetch('.'));
1232 1317
 				$filename = strtr($filename, array($temp_path => ''));
1318
+			} else {
1319
+							$filename = $action->fetch('.');
1233 1320
 			}
1234
-			else
1235
-				$filename = $action->fetch('.');
1236 1321
 
1237 1322
 			$return[] = array(
1238 1323
 				'type' => $actionType,
@@ -1247,8 +1332,7 @@  discard block
 block discarded – undo
1247 1332
 			);
1248 1333
 
1249 1334
 			continue;
1250
-		}
1251
-		elseif ($actionType == 'hook')
1335
+		} elseif ($actionType == 'hook')
1252 1336
 		{
1253 1337
 			$return[] = array(
1254 1338
 				'type' => $actionType,
@@ -1260,16 +1344,16 @@  discard block
 block discarded – undo
1260 1344
 				'description' => '',
1261 1345
 			);
1262 1346
 			continue;
1263
-		}
1264
-		elseif ($actionType == 'credits')
1347
+		} elseif ($actionType == 'credits')
1265 1348
 		{
1266 1349
 			// quick check of any supplied url
1267 1350
 			$url = $action->exists('@url') ? $action->fetch('@url') : '';
1268 1351
 			if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')
1269 1352
 			{
1270 1353
 				$url = 'http://' . $url;
1271
-				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://'))
1272
-					$url = '';
1354
+				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) {
1355
+									$url = '';
1356
+				}
1273 1357
 			}
1274 1358
 
1275 1359
 			$return[] = array(
@@ -1281,8 +1365,7 @@  discard block
 block discarded – undo
1281 1365
 				'title' => $action->fetch('.'),
1282 1366
 			);
1283 1367
 			continue;
1284
-		}
1285
-		elseif ($actionType == 'requires')
1368
+		} elseif ($actionType == 'requires')
1286 1369
 		{
1287 1370
 			$return[] = array(
1288 1371
 				'type' => $actionType,
@@ -1291,14 +1374,12 @@  discard block
 block discarded – undo
1291 1374
 				'description' => '',
1292 1375
 			);
1293 1376
 			continue;
1294
-		}
1295
-		elseif ($actionType == 'error')
1377
+		} elseif ($actionType == 'error')
1296 1378
 		{
1297 1379
 			$return[] = array(
1298 1380
 				'type' => 'error',
1299 1381
 			);
1300
-		}
1301
-		elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1382
+		} elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1302 1383
 		{
1303 1384
 			$this_action = &$return[];
1304 1385
 			$this_action = array(
@@ -1312,8 +1393,7 @@  discard block
 block discarded – undo
1312 1393
 			{
1313 1394
 				$this_action['unparsed_destination'] = $action->fetch('@destination');
1314 1395
 				$this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']);
1315
-			}
1316
-			else
1396
+			} else
1317 1397
 			{
1318 1398
 				$this_action['unparsed_filename'] = $this_action['filename'];
1319 1399
 				$this_action['filename'] = parse_path($this_action['filename']);
@@ -1322,10 +1402,11 @@  discard block
 block discarded – undo
1322 1402
 			// If we're moving or requiring (copying) a file.
1323 1403
 			if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require')
1324 1404
 			{
1325
-				if ($action->exists('@from'))
1326
-					$this_action['source'] = parse_path($action->fetch('@from'));
1327
-				else
1328
-					$this_action['source'] = $temp_path . $this_action['filename'];
1405
+				if ($action->exists('@from')) {
1406
+									$this_action['source'] = parse_path($action->fetch('@from'));
1407
+				} else {
1408
+									$this_action['source'] = $temp_path . $this_action['filename'];
1409
+				}
1329 1410
 			}
1330 1411
 
1331 1412
 			// Check if these things can be done. (chmod's etc.)
@@ -1334,22 +1415,23 @@  discard block
 block discarded – undo
1334 1415
 				if (!mktree($this_action['destination'], false))
1335 1416
 				{
1336 1417
 					$temp = $this_action['destination'];
1337
-					while (!file_exists($temp) && strlen($temp) > 1)
1338
-						$temp = dirname($temp);
1418
+					while (!file_exists($temp) && strlen($temp) > 1) {
1419
+											$temp = dirname($temp);
1420
+					}
1339 1421
 
1340 1422
 					$return[] = array(
1341 1423
 						'type' => 'chmod',
1342 1424
 						'filename' => $temp
1343 1425
 					);
1344 1426
 				}
1345
-			}
1346
-			elseif ($actionType == 'create-file')
1427
+			} elseif ($actionType == 'create-file')
1347 1428
 			{
1348 1429
 				if (!mktree(dirname($this_action['destination']), false))
1349 1430
 				{
1350 1431
 					$temp = dirname($this_action['destination']);
1351
-					while (!file_exists($temp) && strlen($temp) > 1)
1352
-						$temp = dirname($temp);
1432
+					while (!file_exists($temp) && strlen($temp) > 1) {
1433
+											$temp = dirname($temp);
1434
+					}
1353 1435
 
1354 1436
 					$return[] = array(
1355 1437
 						'type' => 'chmod',
@@ -1357,36 +1439,38 @@  discard block
 block discarded – undo
1357 1439
 					);
1358 1440
 				}
1359 1441
 
1360
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1361
-					$return[] = array(
1442
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1443
+									$return[] = array(
1362 1444
 						'type' => 'chmod',
1363 1445
 						'filename' => $this_action['destination']
1364 1446
 					);
1365
-			}
1366
-			elseif ($actionType == 'require-dir')
1447
+				}
1448
+			} elseif ($actionType == 'require-dir')
1367 1449
 			{
1368 1450
 				if (!mktree($this_action['destination'], false))
1369 1451
 				{
1370 1452
 					$temp = $this_action['destination'];
1371
-					while (!file_exists($temp) && strlen($temp) > 1)
1372
-						$temp = dirname($temp);
1453
+					while (!file_exists($temp) && strlen($temp) > 1) {
1454
+											$temp = dirname($temp);
1455
+					}
1373 1456
 
1374 1457
 					$return[] = array(
1375 1458
 						'type' => 'chmod',
1376 1459
 						'filename' => $temp
1377 1460
 					);
1378 1461
 				}
1379
-			}
1380
-			elseif ($actionType == 'require-file')
1462
+			} elseif ($actionType == 'require-file')
1381 1463
 			{
1382
-				if ($action->exists('@theme'))
1383
-					$this_action['theme_action'] = $action->fetch('@theme');
1464
+				if ($action->exists('@theme')) {
1465
+									$this_action['theme_action'] = $action->fetch('@theme');
1466
+				}
1384 1467
 
1385 1468
 				if (!mktree(dirname($this_action['destination']), false))
1386 1469
 				{
1387 1470
 					$temp = dirname($this_action['destination']);
1388
-					while (!file_exists($temp) && strlen($temp) > 1)
1389
-						$temp = dirname($temp);
1471
+					while (!file_exists($temp) && strlen($temp) > 1) {
1472
+											$temp = dirname($temp);
1473
+					}
1390 1474
 
1391 1475
 					$return[] = array(
1392 1476
 						'type' => 'chmod',
@@ -1394,19 +1478,20 @@  discard block
 block discarded – undo
1394 1478
 					);
1395 1479
 				}
1396 1480
 
1397
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1398
-					$return[] = array(
1481
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1482
+									$return[] = array(
1399 1483
 						'type' => 'chmod',
1400 1484
 						'filename' => $this_action['destination']
1401 1485
 					);
1402
-			}
1403
-			elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1486
+				}
1487
+			} elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1404 1488
 			{
1405 1489
 				if (!mktree(dirname($this_action['destination']), false))
1406 1490
 				{
1407 1491
 					$temp = dirname($this_action['destination']);
1408
-					while (!file_exists($temp) && strlen($temp) > 1)
1409
-						$temp = dirname($temp);
1492
+					while (!file_exists($temp) && strlen($temp) > 1) {
1493
+											$temp = dirname($temp);
1494
+					}
1410 1495
 
1411 1496
 					$return[] = array(
1412 1497
 						'type' => 'chmod',
@@ -1414,30 +1499,30 @@  discard block
 block discarded – undo
1414 1499
 					);
1415 1500
 				}
1416 1501
 
1417
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1418
-					$return[] = array(
1502
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1503
+									$return[] = array(
1419 1504
 						'type' => 'chmod',
1420 1505
 						'filename' => $this_action['destination']
1421 1506
 					);
1422
-			}
1423
-			elseif ($actionType == 'remove-dir')
1507
+				}
1508
+			} elseif ($actionType == 'remove-dir')
1424 1509
 			{
1425
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1426
-					$return[] = array(
1510
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1511
+									$return[] = array(
1427 1512
 						'type' => 'chmod',
1428 1513
 						'filename' => $this_action['filename']
1429 1514
 					);
1430
-			}
1431
-			elseif ($actionType == 'remove-file')
1515
+				}
1516
+			} elseif ($actionType == 'remove-file')
1432 1517
 			{
1433
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1434
-					$return[] = array(
1518
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1519
+									$return[] = array(
1435 1520
 						'type' => 'chmod',
1436 1521
 						'filename' => $this_action['filename']
1437 1522
 					);
1523
+				}
1438 1524
 			}
1439
-		}
1440
-		else
1525
+		} else
1441 1526
 		{
1442 1527
 			$return[] = array(
1443 1528
 				'type' => 'error',
@@ -1448,8 +1533,9 @@  discard block
 block discarded – undo
1448 1533
 	}
1449 1534
 
1450 1535
 	// Only testing - just return a list of things to be done.
1451
-	if ($testing_only)
1452
-		return $return;
1536
+	if ($testing_only) {
1537
+			return $return;
1538
+	}
1453 1539
 
1454 1540
 	umask(0);
1455 1541
 
@@ -1457,78 +1543,81 @@  discard block
 block discarded – undo
1457 1543
 	$not_done = array(array('type' => '!'));
1458 1544
 	foreach ($return as $action)
1459 1545
 	{
1460
-		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits')))
1461
-			$not_done[] = $action;
1546
+		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) {
1547
+					$not_done[] = $action;
1548
+		}
1462 1549
 
1463 1550
 		if ($action['type'] == 'create-dir')
1464 1551
 		{
1465
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1466
-				$failure |= !mktree($action['destination'], 0777);
1467
-		}
1468
-		elseif ($action['type'] == 'create-file')
1552
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1553
+							$failure |= !mktree($action['destination'], 0777);
1554
+			}
1555
+		} elseif ($action['type'] == 'create-file')
1469 1556
 		{
1470
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1471
-				$failure |= !mktree(dirname($action['destination']), 0777);
1557
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1558
+							$failure |= !mktree(dirname($action['destination']), 0777);
1559
+			}
1472 1560
 
1473 1561
 			// Create an empty file.
1474 1562
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1475 1563
 
1476
-			if (!file_exists($action['destination']))
1477
-				$failure = true;
1478
-		}
1479
-		elseif ($action['type'] == 'require-dir')
1564
+			if (!file_exists($action['destination'])) {
1565
+							$failure = true;
1566
+			}
1567
+		} elseif ($action['type'] == 'require-dir')
1480 1568
 		{
1481 1569
 			copytree($action['source'], $action['destination']);
1482 1570
 			// Any other theme folders?
1483
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1484
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1571
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1572
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1485 1573
 					copytree($action['source'], $theme_destination);
1486
-		}
1487
-		elseif ($action['type'] == 'require-file')
1574
+			}
1575
+		} elseif ($action['type'] == 'require-file')
1488 1576
 		{
1489
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1490
-				$failure |= !mktree(dirname($action['destination']), 0777);
1577
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1578
+							$failure |= !mktree(dirname($action['destination']), 0777);
1579
+			}
1491 1580
 
1492 1581
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1493 1582
 
1494 1583
 			$failure |= !copy($action['source'], $action['destination']);
1495 1584
 
1496 1585
 			// Any other theme files?
1497
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1498
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1586
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1587
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1499 1588
 				{
1500 1589
 					if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination)))
1501 1590
 						$failure |= !mktree(dirname($theme_destination), 0777);
1591
+			}
1502 1592
 
1503 1593
 					package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only);
1504 1594
 
1505 1595
 					$failure |= !copy($action['source'], $theme_destination);
1506 1596
 				}
1507
-		}
1508
-		elseif ($action['type'] == 'move-file')
1597
+		} elseif ($action['type'] == 'move-file')
1509 1598
 		{
1510
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1511
-				$failure |= !mktree(dirname($action['destination']), 0777);
1599
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1600
+							$failure |= !mktree(dirname($action['destination']), 0777);
1601
+			}
1512 1602
 
1513 1603
 			$failure |= !rename($action['source'], $action['destination']);
1514
-		}
1515
-		elseif ($action['type'] == 'move-dir')
1604
+		} elseif ($action['type'] == 'move-dir')
1516 1605
 		{
1517
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1518
-				$failure |= !mktree($action['destination'], 0777);
1606
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1607
+							$failure |= !mktree($action['destination'], 0777);
1608
+			}
1519 1609
 
1520 1610
 			$failure |= !rename($action['source'], $action['destination']);
1521
-		}
1522
-		elseif ($action['type'] == 'remove-dir')
1611
+		} elseif ($action['type'] == 'remove-dir')
1523 1612
 		{
1524 1613
 			deltree($action['filename']);
1525 1614
 
1526 1615
 			// Any other theme folders?
1527
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1528
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1616
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1617
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1529 1618
 					deltree($theme_destination);
1530
-		}
1531
-		elseif ($action['type'] == 'remove-file')
1619
+			}
1620
+		} elseif ($action['type'] == 'remove-file')
1532 1621
 		{
1533 1622
 			// Make sure the file exists before deleting it.
1534 1623
 			if (file_exists($action['filename']))
@@ -1537,16 +1626,18 @@  discard block
 block discarded – undo
1537 1626
 				$failure |= !unlink($action['filename']);
1538 1627
 			}
1539 1628
 			// The file that was supposed to be deleted couldn't be found.
1540
-			else
1541
-				$failure = true;
1629
+			else {
1630
+							$failure = true;
1631
+			}
1542 1632
 
1543 1633
 			// Any other theme folders?
1544
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1545
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1634
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1635
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1546 1636
 					if (file_exists($theme_destination))
1547 1637
 						$failure |= !unlink($theme_destination);
1548
-					else
1549
-						$failure = true;
1638
+			} else {
1639
+											$failure = true;
1640
+					}
1550 1641
 		}
1551 1642
 	}
1552 1643
 
@@ -1568,8 +1659,9 @@  discard block
 block discarded – undo
1568 1659
 {
1569 1660
 	static $near_version = 0;
1570 1661
 
1571
-	if ($reset)
1572
-		$near_version = 0;
1662
+	if ($reset) {
1663
+			$near_version = 0;
1664
+	}
1573 1665
 
1574 1666
 	// Normalize the $versions while we remove our previous Doh!
1575 1667
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
@@ -1578,16 +1670,19 @@  discard block
 block discarded – undo
1578 1670
 	foreach ($versions as $for)
1579 1671
 	{
1580 1672
 		// Adjust for those wild cards
1581
-		if (strpos($for, '*') !== false)
1582
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1673
+		if (strpos($for, '*') !== false) {
1674
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1675
+		}
1583 1676
 
1584 1677
 		// If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99
1585
-		if (strpos($for, '-') !== false)
1586
-			list ($for, $higher) = explode('-', $for);
1678
+		if (strpos($for, '-') !== false) {
1679
+					list ($for, $higher) = explode('-', $for);
1680
+		}
1587 1681
 
1588 1682
 		// Do the compare, if the for is greater, than what we have but not greater than what we are running .....
1589
-		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1)
1590
-			$near_version = $for;
1683
+		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) {
1684
+					$near_version = $for;
1685
+		}
1591 1686
 	}
1592 1687
 
1593 1688
 	return !empty($near_version) ? $near_version : false;
@@ -1610,15 +1705,17 @@  discard block
 block discarded – undo
1610 1705
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
1611 1706
 
1612 1707
 	// Perhaps we do accept anything?
1613
-	if (in_array('all', $versions))
1614
-		return true;
1708
+	if (in_array('all', $versions)) {
1709
+			return true;
1710
+	}
1615 1711
 
1616 1712
 	// Loop through each version.
1617 1713
 	foreach ($versions as $for)
1618 1714
 	{
1619 1715
 		// Wild card spotted?
1620
-		if (strpos($for, '*') !== false)
1621
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1716
+		if (strpos($for, '*') !== false) {
1717
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1718
+		}
1622 1719
 
1623 1720
 		// Do we have a range?
1624 1721
 		if (strpos($for, '-') !== false)
@@ -1626,12 +1723,14 @@  discard block
 block discarded – undo
1626 1723
 			list ($lower, $upper) = explode('-', $for);
1627 1724
 
1628 1725
 			// Compare the version against lower and upper bounds.
1629
-			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1)
1630
-				return true;
1726
+			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) {
1727
+							return true;
1728
+			}
1631 1729
 		}
1632 1730
 		// Otherwise check if they are equal...
1633
-		elseif (compareVersions($version, $for) === 0)
1634
-			return true;
1731
+		elseif (compareVersions($version, $for) === 0) {
1732
+					return true;
1733
+		}
1635 1734
 	}
1636 1735
 
1637 1736
 	return false;
@@ -1671,12 +1770,14 @@  discard block
 block discarded – undo
1671 1770
 	}
1672 1771
 
1673 1772
 	// Are they the same, perhaps?
1674
-	if ($versions[1] === $versions[2])
1675
-		return 0;
1773
+	if ($versions[1] === $versions[2]) {
1774
+			return 0;
1775
+	}
1676 1776
 
1677 1777
 	// Get version numbering categories...
1678
-	if (!isset($categories))
1679
-		$categories = array_keys($versions[1]);
1778
+	if (!isset($categories)) {
1779
+			$categories = array_keys($versions[1]);
1780
+	}
1680 1781
 
1681 1782
 	// Loop through each category.
1682 1783
 	foreach ($categories as $category)
@@ -1686,13 +1787,15 @@  discard block
 block discarded – undo
1686 1787
 		{
1687 1788
 			// Dev builds are a problematic exception.
1688 1789
 			// (stable) dev < (stable) but (unstable) dev = (unstable)
1689
-			if ($category == 'type')
1690
-				return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1691
-			elseif ($category == 'dev')
1692
-				return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1790
+			if ($category == 'type') {
1791
+							return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1792
+			} elseif ($category == 'dev') {
1793
+							return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1794
+			}
1693 1795
 			// Otherwise a simple comparison.
1694
-			else
1695
-				return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1796
+			else {
1797
+							return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1798
+			}
1696 1799
 		}
1697 1800
 	}
1698 1801
 
@@ -1726,11 +1829,13 @@  discard block
 block discarded – undo
1726 1829
 	);
1727 1830
 
1728 1831
 	// do we parse in a package directory?
1729
-	if (!empty($temp_path))
1730
-		$dirs['$package'] = $temp_path;
1832
+	if (!empty($temp_path)) {
1833
+			$dirs['$package'] = $temp_path;
1834
+	}
1731 1835
 
1732
-	if (strlen($path) == 0)
1733
-		trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1836
+	if (strlen($path) == 0) {
1837
+			trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1838
+	}
1734 1839
 
1735 1840
 	return strtr($path, $dirs);
1736 1841
 }
@@ -1747,8 +1852,9 @@  discard block
 block discarded – undo
1747 1852
 	/** @var ftp_connection $package_ftp */
1748 1853
 	global $package_ftp;
1749 1854
 
1750
-	if (!file_exists($dir))
1751
-		return;
1855
+	if (!file_exists($dir)) {
1856
+			return;
1857
+	}
1752 1858
 
1753 1859
 	$current_dir = @opendir($dir);
1754 1860
 	if ($current_dir == false)
@@ -1756,8 +1862,9 @@  discard block
 block discarded – undo
1756 1862
 		if ($delete_dir && isset($package_ftp))
1757 1863
 		{
1758 1864
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1759
-			if (!is_dir($dir))
1760
-				$package_ftp->chmod($ftp_file, 0777);
1865
+			if (!is_dir($dir)) {
1866
+							$package_ftp->chmod($ftp_file, 0777);
1867
+			}
1761 1868
 			$package_ftp->unlink($ftp_file);
1762 1869
 		}
1763 1870
 
@@ -1766,26 +1873,28 @@  discard block
 block discarded – undo
1766 1873
 
1767 1874
 	while ($entryname = readdir($current_dir))
1768 1875
 	{
1769
-		if (in_array($entryname, array('.', '..')))
1770
-			continue;
1876
+		if (in_array($entryname, array('.', '..'))) {
1877
+					continue;
1878
+		}
1771 1879
 
1772
-		if (is_dir($dir . '/' . $entryname))
1773
-			deltree($dir . '/' . $entryname);
1774
-		else
1880
+		if (is_dir($dir . '/' . $entryname)) {
1881
+					deltree($dir . '/' . $entryname);
1882
+		} else
1775 1883
 		{
1776 1884
 			// Here, 755 doesn't really matter since we're deleting it anyway.
1777 1885
 			if (isset($package_ftp))
1778 1886
 			{
1779 1887
 				$ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
1780 1888
 
1781
-				if (!is_writable($dir . '/' . $entryname))
1782
-					$package_ftp->chmod($ftp_file, 0777);
1889
+				if (!is_writable($dir . '/' . $entryname)) {
1890
+									$package_ftp->chmod($ftp_file, 0777);
1891
+				}
1783 1892
 				$package_ftp->unlink($ftp_file);
1784
-			}
1785
-			else
1893
+			} else
1786 1894
 			{
1787
-				if (!is_writable($dir . '/' . $entryname))
1788
-					smf_chmod($dir . '/' . $entryname, 0777);
1895
+				if (!is_writable($dir . '/' . $entryname)) {
1896
+									smf_chmod($dir . '/' . $entryname, 0777);
1897
+				}
1789 1898
 				unlink($dir . '/' . $entryname);
1790 1899
 			}
1791 1900
 		}
@@ -1798,14 +1907,15 @@  discard block
 block discarded – undo
1798 1907
 		if (isset($package_ftp))
1799 1908
 		{
1800 1909
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1801
-			if (!is_writable($dir . '/' . $entryname))
1802
-				$package_ftp->chmod($ftp_file, 0777);
1910
+			if (!is_writable($dir . '/' . $entryname)) {
1911
+							$package_ftp->chmod($ftp_file, 0777);
1912
+			}
1803 1913
 			$package_ftp->unlink($ftp_file);
1804
-		}
1805
-		else
1914
+		} else
1806 1915
 		{
1807
-			if (!is_writable($dir))
1808
-				smf_chmod($dir, 0777);
1916
+			if (!is_writable($dir)) {
1917
+							smf_chmod($dir, 0777);
1918
+			}
1809 1919
 			@rmdir($dir);
1810 1920
 		}
1811 1921
 	}
@@ -1828,10 +1938,11 @@  discard block
 block discarded – undo
1828 1938
 	{
1829 1939
 		if (!is_writable($strPath) && $mode !== false)
1830 1940
 		{
1831
-			if (isset($package_ftp))
1832
-				$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1833
-			else
1834
-				smf_chmod($strPath, $mode);
1941
+			if (isset($package_ftp)) {
1942
+							$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1943
+			} else {
1944
+							smf_chmod($strPath, $mode);
1945
+			}
1835 1946
 		}
1836 1947
 
1837 1948
 		$test = @opendir($strPath);
@@ -1839,36 +1950,37 @@  discard block
 block discarded – undo
1839 1950
 		{
1840 1951
 			closedir($test);
1841 1952
 			return is_writable($strPath);
1953
+		} else {
1954
+					return false;
1842 1955
 		}
1843
-		else
1844
-			return false;
1845 1956
 	}
1846 1957
 	// Is this an invalid path and/or we can't make the directory?
1847
-	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode))
1848
-		return false;
1958
+	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) {
1959
+			return false;
1960
+	}
1849 1961
 
1850 1962
 	if (!is_writable(dirname($strPath)) && $mode !== false)
1851 1963
 	{
1852
-		if (isset($package_ftp))
1853
-			$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1854
-		else
1855
-			smf_chmod(dirname($strPath), $mode);
1964
+		if (isset($package_ftp)) {
1965
+					$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1966
+		} else {
1967
+					smf_chmod(dirname($strPath), $mode);
1968
+		}
1856 1969
 	}
1857 1970
 
1858
-	if ($mode !== false && isset($package_ftp))
1859
-		return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1860
-	elseif ($mode === false)
1971
+	if ($mode !== false && isset($package_ftp)) {
1972
+			return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1973
+	} elseif ($mode === false)
1861 1974
 	{
1862 1975
 		$test = @opendir(dirname($strPath));
1863 1976
 		if ($test)
1864 1977
 		{
1865 1978
 			closedir($test);
1866 1979
 			return true;
1980
+		} else {
1981
+					return false;
1867 1982
 		}
1868
-		else
1869
-			return false;
1870
-	}
1871
-	else
1983
+	} else
1872 1984
 	{
1873 1985
 		@mkdir($strPath, $mode);
1874 1986
 		$test = @opendir($strPath);
@@ -1876,9 +1988,9 @@  discard block
 block discarded – undo
1876 1988
 		{
1877 1989
 			closedir($test);
1878 1990
 			return true;
1991
+		} else {
1992
+					return false;
1879 1993
 		}
1880
-		else
1881
-			return false;
1882 1994
 	}
1883 1995
 }
1884 1996
 
@@ -1894,39 +2006,46 @@  discard block
 block discarded – undo
1894 2006
 	/** @var ftp_connection $package_ftp */
1895 2007
 	global $package_ftp;
1896 2008
 
1897
-	if (!file_exists($destination) || !is_writable($destination))
1898
-		mktree($destination, 0755);
1899
-	if (!is_writable($destination))
1900
-		mktree($destination, 0777);
2009
+	if (!file_exists($destination) || !is_writable($destination)) {
2010
+			mktree($destination, 0755);
2011
+	}
2012
+	if (!is_writable($destination)) {
2013
+			mktree($destination, 0777);
2014
+	}
1901 2015
 
1902 2016
 	$current_dir = opendir($source);
1903
-	if ($current_dir == false)
1904
-		return;
2017
+	if ($current_dir == false) {
2018
+			return;
2019
+	}
1905 2020
 
1906 2021
 	while ($entryname = readdir($current_dir))
1907 2022
 	{
1908
-		if (in_array($entryname, array('.', '..')))
1909
-			continue;
2023
+		if (in_array($entryname, array('.', '..'))) {
2024
+					continue;
2025
+		}
1910 2026
 
1911
-		if (isset($package_ftp))
1912
-			$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2027
+		if (isset($package_ftp)) {
2028
+					$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2029
+		}
1913 2030
 
1914 2031
 		if (is_file($source . '/' . $entryname))
1915 2032
 		{
1916
-			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname))
1917
-				$package_ftp->create_file($ftp_file);
1918
-			elseif (!file_exists($destination . '/' . $entryname))
1919
-				@touch($destination . '/' . $entryname);
2033
+			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) {
2034
+							$package_ftp->create_file($ftp_file);
2035
+			} elseif (!file_exists($destination . '/' . $entryname)) {
2036
+							@touch($destination . '/' . $entryname);
2037
+			}
1920 2038
 		}
1921 2039
 
1922 2040
 		package_chmod($destination . '/' . $entryname);
1923 2041
 
1924
-		if (is_dir($source . '/' . $entryname))
1925
-			copytree($source . '/' . $entryname, $destination . '/' . $entryname);
1926
-		elseif (file_exists($destination . '/' . $entryname))
1927
-			package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
1928
-		else
1929
-			copy($source . '/' . $entryname, $destination . '/' . $entryname);
2042
+		if (is_dir($source . '/' . $entryname)) {
2043
+					copytree($source . '/' . $entryname, $destination . '/' . $entryname);
2044
+		} elseif (file_exists($destination . '/' . $entryname)) {
2045
+					package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
2046
+		} else {
2047
+					copy($source . '/' . $entryname, $destination . '/' . $entryname);
2048
+		}
1930 2049
 	}
1931 2050
 
1932 2051
 	closedir($current_dir);
@@ -1944,21 +2063,24 @@  discard block
 block discarded – undo
1944 2063
 	$data = array();
1945 2064
 
1946 2065
 	$dir = @dir($path . $sub_path);
1947
-	if (!$dir)
1948
-		return array();
2066
+	if (!$dir) {
2067
+			return array();
2068
+	}
1949 2069
 	while ($entry = $dir->read())
1950 2070
 	{
1951
-		if ($entry == '.' || $entry == '..')
1952
-			continue;
2071
+		if ($entry == '.' || $entry == '..') {
2072
+					continue;
2073
+		}
1953 2074
 
1954
-		if (is_dir($path . $sub_path . '/' . $entry))
1955
-			$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
1956
-		else
1957
-			$data[] = array(
2075
+		if (is_dir($path . $sub_path . '/' . $entry)) {
2076
+					$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
2077
+		} else {
2078
+					$data[] = array(
1958 2079
 				'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry,
1959 2080
 				'size' => filesize($path . $sub_path . '/' . $entry),
1960 2081
 				'skipped' => false,
1961 2082
 			);
2083
+		}
1962 2084
 	}
1963 2085
 	$dir->close();
1964 2086
 
@@ -2013,8 +2135,9 @@  discard block
 block discarded – undo
2013 2135
 		{
2014 2136
 			// If this filename is relative, if so take a guess at what it should be.
2015 2137
 			$real_filename = $filename;
2016
-			if (strpos($filename, 'Themes') === 0)
2017
-				$real_filename = $boarddir . '/' . $filename;
2138
+			if (strpos($filename, 'Themes') === 0) {
2139
+							$real_filename = $boarddir . '/' . $filename;
2140
+			}
2018 2141
 
2019 2142
 			if (strpos($real_filename, $theme['theme_dir']) === 0)
2020 2143
 			{
@@ -2033,8 +2156,9 @@  discard block
 block discarded – undo
2033 2156
 		foreach ($theme_paths as $id => $theme)
2034 2157
 		{
2035 2158
 			// Default is getting done anyway, so no need for involvement here.
2036
-			if ($id == 1)
2037
-				continue;
2159
+			if ($id == 1) {
2160
+							continue;
2161
+			}
2038 2162
 
2039 2163
 			// For every template, do we want it? Yea, no, maybe?
2040 2164
 			foreach ($template_changes[1] as $index => $template_file)
@@ -2057,8 +2181,9 @@  discard block
 block discarded – undo
2057 2181
 		);
2058 2182
 
2059 2183
 		// Sometimes though, we have some additional files for other themes, if we have add them to the mix.
2060
-		if (isset($custom_themes_add[$files_to_change[1]]))
2061
-			$files_to_change += $custom_themes_add[$files_to_change[1]];
2184
+		if (isset($custom_themes_add[$files_to_change[1]])) {
2185
+					$files_to_change += $custom_themes_add[$files_to_change[1]];
2186
+		}
2062 2187
 
2063 2188
 		// Now, loop through all the files we're changing, and, well, change them ;)
2064 2189
 		foreach ($files_to_change as $theme => $working_file)
@@ -2092,11 +2217,13 @@  discard block
 block discarded – undo
2092 2217
 				continue;
2093 2218
 			}
2094 2219
 			// Okay, we're creating this file then...?
2095
-			elseif (!file_exists($working_file))
2096
-				$working_data = '';
2220
+			elseif (!file_exists($working_file)) {
2221
+							$working_data = '';
2222
+			}
2097 2223
 			// Phew, it exists!  Load 'er up!
2098
-			else
2099
-				$working_data = str_replace("\r", '', package_get_contents($working_file));
2224
+			else {
2225
+							$working_data = str_replace("\r", '', package_get_contents($working_file));
2226
+			}
2100 2227
 
2101 2228
 			$actions[] = array(
2102 2229
 				'type' => 'opened',
@@ -2117,8 +2244,8 @@  discard block
 block discarded – undo
2117 2244
 
2118 2245
 				// Grab all search items of this operation (in most cases just 1).
2119 2246
 				$searches = $operation->set('search');
2120
-				foreach ($searches as $i => $search)
2121
-					$actual_operation['searches'][] = array(
2247
+				foreach ($searches as $i => $search) {
2248
+									$actual_operation['searches'][] = array(
2122 2249
 						'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace',
2123 2250
 						'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true',
2124 2251
 						'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose',
@@ -2127,6 +2254,7 @@  discard block
 block discarded – undo
2127 2254
 						'preg_search' => '',
2128 2255
 						'preg_replace' => '',
2129 2256
 					);
2257
+				}
2130 2258
 
2131 2259
 				// At least one search should be defined.
2132 2260
 				if (empty($actual_operation['searches']))
@@ -2151,30 +2279,32 @@  discard block
 block discarded – undo
2151 2279
 						// Reverse modification of regular expressions are not allowed.
2152 2280
 						if ($search['is_reg_exp'])
2153 2281
 						{
2154
-							if ($actual_operation['error'] === 'fatal')
2155
-								$actions[] = array(
2282
+							if ($actual_operation['error'] === 'fatal') {
2283
+															$actions[] = array(
2156 2284
 									'type' => 'failure',
2157 2285
 									'filename' => $working_file,
2158 2286
 									'search' => $search['search'],
2159 2287
 									'is_custom' => $theme > 1 ? $theme : 0,
2160 2288
 								);
2289
+							}
2161 2290
 
2162 2291
 							// Continue to the next operation.
2163 2292
 							continue 2;
2164 2293
 						}
2165 2294
 
2166 2295
 						// The replacement is now the search subject...
2167
-						if ($search['position'] === 'replace' || $search['position'] === 'end')
2168
-							$actual_operation['searches'][$i]['search'] = $search['add'];
2169
-						else
2296
+						if ($search['position'] === 'replace' || $search['position'] === 'end') {
2297
+													$actual_operation['searches'][$i]['search'] = $search['add'];
2298
+						} else
2170 2299
 						{
2171 2300
 							// Reversing a before/after modification becomes a replacement.
2172 2301
 							$actual_operation['searches'][$i]['position'] = 'replace';
2173 2302
 
2174
-							if ($search['position'] === 'before')
2175
-								$actual_operation['searches'][$i]['search'] .= $search['add'];
2176
-							elseif ($search['position'] === 'after')
2177
-								$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2303
+							if ($search['position'] === 'before') {
2304
+															$actual_operation['searches'][$i]['search'] .= $search['add'];
2305
+							} elseif ($search['position'] === 'after') {
2306
+															$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2307
+							}
2178 2308
 						}
2179 2309
 
2180 2310
 						// ...and the search subject is now the replacement.
@@ -2202,16 +2332,17 @@  discard block
 block discarded – undo
2202 2332
 				foreach ($actual_operation['searches'] as $i => $search)
2203 2333
 				{
2204 2334
 					// Not much needed if the search subject is already a regexp.
2205
-					if ($search['is_reg_exp'])
2206
-						$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2207
-					else
2335
+					if ($search['is_reg_exp']) {
2336
+											$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2337
+					} else
2208 2338
 					{
2209 2339
 						// Make the search subject fit into a regular expression.
2210 2340
 						$actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~');
2211 2341
 
2212 2342
 						// Using 'loose', a random amount of tabs and spaces may be used.
2213
-						if ($search['loose_whitespace'])
2214
-							$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2343
+						if ($search['loose_whitespace']) {
2344
+													$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2345
+						}
2215 2346
 					}
2216 2347
 
2217 2348
 					// Shuzzup.  This is done so we can safely use a regular expression. ($0 is bad!!)
@@ -2237,8 +2368,7 @@  discard block
 block discarded – undo
2237 2368
 						if ($undo)
2238 2369
 						{
2239 2370
 							$actual_operation['searches'][$i]['preg_replace'] = '';
2240
-						}
2241
-						else
2371
+						} else
2242 2372
 						{
2243 2373
 							$actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$';
2244 2374
 							$actual_operation['searches'][$i]['preg_replace'] .= '$1';
@@ -2285,8 +2415,9 @@  discard block
 block discarded – undo
2285 2415
 					}
2286 2416
 
2287 2417
 					// Replace it into nothing? That's not an option...unless it's an undoing end.
2288
-					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo))
2289
-						continue;
2418
+					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) {
2419
+											continue;
2420
+					}
2290 2421
 
2291 2422
 					// Finally, we're doing some replacements.
2292 2423
 					$working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1);
@@ -2311,22 +2442,25 @@  discard block
 block discarded – undo
2311 2442
 
2312 2443
 			package_chmod($working_file);
2313 2444
 
2314
-			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file))))
2315
-				$actions[] = array(
2445
+			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) {
2446
+							$actions[] = array(
2316 2447
 					'type' => 'chmod',
2317 2448
 					'filename' => $working_file
2318 2449
 				);
2450
+			}
2319 2451
 
2320
-			if (basename($working_file) == 'Settings_bak.php')
2321
-				continue;
2452
+			if (basename($working_file) == 'Settings_bak.php') {
2453
+							continue;
2454
+			}
2322 2455
 
2323 2456
 			if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2324 2457
 			{
2325 2458
 				// No, no, not Settings.php!
2326
-				if (basename($working_file) == 'Settings.php')
2327
-					@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2328
-				else
2329
-					@copy($working_file, $working_file . '~');
2459
+				if (basename($working_file) == 'Settings.php') {
2460
+									@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2461
+				} else {
2462
+									@copy($working_file, $working_file . '~');
2463
+				}
2330 2464
 			}
2331 2465
 
2332 2466
 			// Always call this, even if in testing, because it won't really be written in testing mode.
@@ -2393,8 +2527,9 @@  discard block
 block discarded – undo
2393 2527
 		if ($code_match[1] != 'edit file' && $code_match[1] != 'file')
2394 2528
 		{
2395 2529
 			// It's a step, let's add that to the current steps.
2396
-			if (isset($temp_changes[$step_counter]))
2397
-				$temp_changes[$step_counter]['changes'][] = $code_match[0];
2530
+			if (isset($temp_changes[$step_counter])) {
2531
+							$temp_changes[$step_counter]['changes'][] = $code_match[0];
2532
+			}
2398 2533
 			continue;
2399 2534
 		}
2400 2535
 
@@ -2411,11 +2546,13 @@  discard block
 block discarded – undo
2411 2546
 		foreach ($theme_paths as $id => $theme)
2412 2547
 		{
2413 2548
 			// If this filename is relative, if so take a guess at what it should be.
2414
-			if (strpos($filename, 'Themes') === 0)
2415
-				$filename = $boarddir . '/' . $filename;
2549
+			if (strpos($filename, 'Themes') === 0) {
2550
+							$filename = $boarddir . '/' . $filename;
2551
+			}
2416 2552
 
2417
-			if (strpos($filename, $theme['theme_dir']) === 0)
2418
-				$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2553
+			if (strpos($filename, $theme['theme_dir']) === 0) {
2554
+							$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2555
+			}
2419 2556
 		}
2420 2557
 	}
2421 2558
 
@@ -2428,8 +2565,9 @@  discard block
 block discarded – undo
2428 2565
 		foreach ($theme_paths as $id => $theme)
2429 2566
 		{
2430 2567
 			// Don't do default, it means nothing to me.
2431
-			if ($id == 1)
2432
-				continue;
2568
+			if ($id == 1) {
2569
+							continue;
2570
+			}
2433 2571
 
2434 2572
 			// Now, for each file do we need to edit it?
2435 2573
 			foreach ($template_changes[1] as $pos => $template_file)
@@ -2465,32 +2603,36 @@  discard block
 block discarded – undo
2465 2603
 				package_chmod($working_file);
2466 2604
 
2467 2605
 				// Don't even dare.
2468
-				if (basename($working_file) == 'Settings_bak.php')
2469
-					continue;
2606
+				if (basename($working_file) == 'Settings_bak.php') {
2607
+									continue;
2608
+				}
2470 2609
 
2471
-				if (!is_writable($working_file))
2472
-					$actions[] = array(
2610
+				if (!is_writable($working_file)) {
2611
+									$actions[] = array(
2473 2612
 						'type' => 'chmod',
2474 2613
 						'filename' => $working_file
2475 2614
 					);
2615
+				}
2476 2616
 
2477 2617
 				if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2478 2618
 				{
2479
-					if (basename($working_file) == 'Settings.php')
2480
-						@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2481
-					else
2482
-						@copy($working_file, $working_file . '~');
2619
+					if (basename($working_file) == 'Settings.php') {
2620
+											@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2621
+					} else {
2622
+											@copy($working_file, $working_file . '~');
2623
+					}
2483 2624
 				}
2484 2625
 
2485 2626
 				package_put_contents($working_file, $working_data, $testing);
2486 2627
 			}
2487 2628
 
2488
-			if ($working_file !== null)
2489
-				$actions[] = array(
2629
+			if ($working_file !== null) {
2630
+							$actions[] = array(
2490 2631
 					'type' => 'saved',
2491 2632
 					'filename' => $working_file,
2492 2633
 					'is_custom' => $is_custom,
2493 2634
 				);
2635
+			}
2494 2636
 
2495 2637
 			// Is this "now working on" file a theme specific one?
2496 2638
 			$is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0;
@@ -2509,10 +2651,11 @@  discard block
 block discarded – undo
2509 2651
 			{
2510 2652
 				$places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
2511 2653
 
2512
-				foreach ($places_to_check as $place)
2513
-					if (file_exists($place . '/' . $working_file))
2654
+				foreach ($places_to_check as $place) {
2655
+									if (file_exists($place . '/' . $working_file))
2514 2656
 					{
2515 2657
 						$working_file = $place . '/' . $working_file;
2658
+				}
2516 2659
 						break;
2517 2660
 					}
2518 2661
 			}
@@ -2526,8 +2669,7 @@  discard block
 block discarded – undo
2526 2669
 					'type' => 'opened',
2527 2670
 					'filename' => $working_file
2528 2671
 				);
2529
-			}
2530
-			else
2672
+			} else
2531 2673
 			{
2532 2674
 				$actions[] = array(
2533 2675
 					'type' => 'missing',
@@ -2563,11 +2705,13 @@  discard block
 block discarded – undo
2563 2705
 			$replace_with = $code_match[2];
2564 2706
 
2565 2707
 			// Add this afterward...
2566
-			if ($code_match[1] == 'add' || $code_match[1] == 'add after')
2567
-				$replace_with = $working_search . "\n" . $replace_with;
2708
+			if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
2709
+							$replace_with = $working_search . "\n" . $replace_with;
2710
+			}
2568 2711
 			// Add this beforehand.
2569
-			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above')
2570
-				$replace_with .= "\n" . $working_search;
2712
+			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
2713
+							$replace_with .= "\n" . $working_search;
2714
+			}
2571 2715
 			// Otherwise.. replace with $replace_with ;).
2572 2716
 		}
2573 2717
 
@@ -2630,29 +2774,32 @@  discard block
 block discarded – undo
2630 2774
 	{
2631 2775
 		package_chmod($working_file);
2632 2776
 
2633
-		if (!is_writable($working_file))
2634
-			$actions[] = array(
2777
+		if (!is_writable($working_file)) {
2778
+					$actions[] = array(
2635 2779
 				'type' => 'chmod',
2636 2780
 				'filename' => $working_file
2637 2781
 			);
2782
+		}
2638 2783
 
2639 2784
 		if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2640 2785
 		{
2641
-			if (basename($working_file) == 'Settings.php')
2642
-				@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2643
-			else
2644
-				@copy($working_file, $working_file . '~');
2786
+			if (basename($working_file) == 'Settings.php') {
2787
+							@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2788
+			} else {
2789
+							@copy($working_file, $working_file . '~');
2790
+			}
2645 2791
 		}
2646 2792
 
2647 2793
 		package_put_contents($working_file, $working_data, $testing);
2648 2794
 	}
2649 2795
 
2650
-	if ($working_file !== null)
2651
-		$actions[] = array(
2796
+	if ($working_file !== null) {
2797
+			$actions[] = array(
2652 2798
 			'type' => 'saved',
2653 2799
 			'filename' => $working_file,
2654 2800
 			'is_custom' => $is_custom,
2655 2801
 		);
2802
+	}
2656 2803
 
2657 2804
 	$actions[] = array(
2658 2805
 		'type' => 'result',
@@ -2678,17 +2825,19 @@  discard block
 block discarded – undo
2678 2825
 		$mem_check = setMemoryLimit('128M');
2679 2826
 
2680 2827
 		// Windows doesn't seem to care about the memory_limit.
2681
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2682
-			$package_cache = array();
2683
-		else
2684
-			$package_cache = false;
2828
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2829
+					$package_cache = array();
2830
+		} else {
2831
+					$package_cache = false;
2832
+		}
2685 2833
 	}
2686 2834
 
2687
-	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename]))
2688
-		return file_get_contents($filename);
2689
-	else
2690
-		return $package_cache[$filename];
2691
-}
2835
+	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) {
2836
+			return file_get_contents($filename);
2837
+	} else {
2838
+			return $package_cache[$filename];
2839
+	}
2840
+	}
2692 2841
 
2693 2842
 /**
2694 2843
  * Writes data to a file, almost exactly like the file_put_contents() function.
@@ -2712,19 +2861,22 @@  discard block
 block discarded – undo
2712 2861
 		// Try to increase the memory limit - we don't want to run out of ram!
2713 2862
 		$mem_check = setMemoryLimit('128M');
2714 2863
 
2715
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2716
-			$package_cache = array();
2717
-		else
2718
-			$package_cache = false;
2864
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2865
+					$package_cache = array();
2866
+		} else {
2867
+					$package_cache = false;
2868
+		}
2719 2869
 	}
2720 2870
 
2721
-	if (isset($package_ftp))
2722
-		$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2871
+	if (isset($package_ftp)) {
2872
+			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2873
+	}
2723 2874
 
2724
-	if (!file_exists($filename) && isset($package_ftp))
2725
-		$package_ftp->create_file($ftp_file);
2726
-	elseif (!file_exists($filename))
2727
-		@touch($filename);
2875
+	if (!file_exists($filename) && isset($package_ftp)) {
2876
+			$package_ftp->create_file($ftp_file);
2877
+	} elseif (!file_exists($filename)) {
2878
+			@touch($filename);
2879
+	}
2728 2880
 
2729 2881
 	package_chmod($filename);
2730 2882
 
@@ -2733,22 +2885,23 @@  discard block
 block discarded – undo
2733 2885
 		$fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb');
2734 2886
 
2735 2887
 		// We should show an error message or attempt a rollback, no?
2736
-		if (!$fp)
2737
-			return false;
2888
+		if (!$fp) {
2889
+					return false;
2890
+		}
2738 2891
 
2739 2892
 		fwrite($fp, $data);
2740 2893
 		fclose($fp);
2741
-	}
2742
-	elseif (strpos($filename, 'Packages/') !== false || $package_cache === false)
2743
-		return strlen($data);
2744
-	else
2894
+	} elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) {
2895
+			return strlen($data);
2896
+	} else
2745 2897
 	{
2746 2898
 		$package_cache[$filename] = $data;
2747 2899
 
2748 2900
 		// Permission denied, eh?
2749 2901
 		$fp = @fopen($filename, 'r+');
2750
-		if (!$fp)
2751
-			return false;
2902
+		if (!$fp) {
2903
+					return false;
2904
+		}
2752 2905
 		fclose($fp);
2753 2906
 	}
2754 2907
 
@@ -2766,19 +2919,22 @@  discard block
 block discarded – undo
2766 2919
 	global $package_ftp, $package_cache;
2767 2920
 	static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm');
2768 2921
 
2769
-	if (empty($package_cache))
2770
-		return;
2922
+	if (empty($package_cache)) {
2923
+			return;
2924
+	}
2771 2925
 
2772 2926
 	// First, let's check permissions!
2773 2927
 	foreach ($package_cache as $filename => $data)
2774 2928
 	{
2775
-		if (isset($package_ftp))
2776
-			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2929
+		if (isset($package_ftp)) {
2930
+					$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2931
+		}
2777 2932
 
2778
-		if (!file_exists($filename) && isset($package_ftp))
2779
-			$package_ftp->create_file($ftp_file);
2780
-		elseif (!file_exists($filename))
2781
-			@touch($filename);
2933
+		if (!file_exists($filename) && isset($package_ftp)) {
2934
+					$package_ftp->create_file($ftp_file);
2935
+		} elseif (!file_exists($filename)) {
2936
+					@touch($filename);
2937
+		}
2782 2938
 
2783 2939
 		$result = package_chmod($filename);
2784 2940
 
@@ -2832,8 +2988,9 @@  discard block
 block discarded – undo
2832 2988
 	/** @var ftp_connection $package_ftp */
2833 2989
 	global $package_ftp;
2834 2990
 
2835
-	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable')
2836
-		return true;
2991
+	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') {
2992
+			return true;
2993
+	}
2837 2994
 
2838 2995
 	// Start off checking without FTP.
2839 2996
 	if (!isset($package_ftp) || $package_ftp === false)
@@ -2855,8 +3012,7 @@  discard block
 block discarded – undo
2855 3012
 
2856 3013
 				// Keep track of the writable status here.
2857 3014
 				$file_permissions = @fileperms($chmod_file);
2858
-			}
2859
-			else
3015
+			} else
2860 3016
 			{
2861 3017
 				// This looks odd, but it's an attempt to work around PHP suExec.
2862 3018
 				if (!file_exists($chmod_file) && $perm_state == 'writable')
@@ -2866,24 +3022,28 @@  discard block
 block discarded – undo
2866 3022
 					mktree(dirname($chmod_file), 0755);
2867 3023
 					@touch($chmod_file);
2868 3024
 					smf_chmod($chmod_file, 0755);
3025
+				} else {
3026
+									$file_permissions = @fileperms($chmod_file);
2869 3027
 				}
2870
-				else
2871
-					$file_permissions = @fileperms($chmod_file);
2872 3028
 			}
2873 3029
 
2874 3030
 			// This looks odd, but it's another attempt to work around PHP suExec.
2875
-			if ($perm_state != 'writable')
2876
-				smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
2877
-			else
3031
+			if ($perm_state != 'writable') {
3032
+							smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
3033
+			} else
2878 3034
 			{
2879
-				if (!@is_writable($chmod_file))
2880
-					smf_chmod($chmod_file, 0755);
2881
-				if (!@is_writable($chmod_file))
2882
-					smf_chmod($chmod_file, 0777);
2883
-				if (!@is_writable(dirname($chmod_file)))
2884
-					smf_chmod($chmod_file, 0755);
2885
-				if (!@is_writable(dirname($chmod_file)))
2886
-					smf_chmod($chmod_file, 0777);
3035
+				if (!@is_writable($chmod_file)) {
3036
+									smf_chmod($chmod_file, 0755);
3037
+				}
3038
+				if (!@is_writable($chmod_file)) {
3039
+									smf_chmod($chmod_file, 0777);
3040
+				}
3041
+				if (!@is_writable(dirname($chmod_file))) {
3042
+									smf_chmod($chmod_file, 0755);
3043
+				}
3044
+				if (!@is_writable(dirname($chmod_file))) {
3045
+									smf_chmod($chmod_file, 0777);
3046
+				}
2887 3047
 			}
2888 3048
 
2889 3049
 			// The ultimate writable test.
@@ -2892,20 +3052,22 @@  discard block
 block discarded – undo
2892 3052
 				$fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb');
2893 3053
 				if (@is_writable($chmod_file) && $fp)
2894 3054
 				{
2895
-					if (!is_dir($chmod_file))
2896
-						fclose($fp);
2897
-					else
2898
-						closedir($fp);
3055
+					if (!is_dir($chmod_file)) {
3056
+											fclose($fp);
3057
+					} else {
3058
+											closedir($fp);
3059
+					}
2899 3060
 
2900 3061
 					// It worked!
2901
-					if ($track_change)
2902
-						$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3062
+					if ($track_change) {
3063
+											$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3064
+					}
2903 3065
 
2904 3066
 					return true;
2905 3067
 				}
3068
+			} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) {
3069
+							unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2906 3070
 			}
2907
-			elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file]))
2908
-				unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2909 3071
 		}
2910 3072
 
2911 3073
 		// If we're here we're a failure.
@@ -2924,31 +3086,33 @@  discard block
 block discarded – undo
2924 3086
 			mktree(dirname($filename), 0755);
2925 3087
 			$package_ftp->create_file($ftp_file);
2926 3088
 			$package_ftp->chmod($ftp_file, 0755);
3089
+		} else {
3090
+					$file_permissions = @fileperms($filename);
2927 3091
 		}
2928
-		else
2929
-			$file_permissions = @fileperms($filename);
2930 3092
 
2931 3093
 		if ($perm_state != 'writable')
2932 3094
 		{
2933 3095
 			$package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644);
2934
-		}
2935
-		else
3096
+		} else
2936 3097
 		{
2937
-			if (!@is_writable($filename))
2938
-				$package_ftp->chmod($ftp_file, 0777);
2939
-			if (!@is_writable(dirname($filename)))
2940
-				$package_ftp->chmod(dirname($ftp_file), 0777);
3098
+			if (!@is_writable($filename)) {
3099
+							$package_ftp->chmod($ftp_file, 0777);
3100
+			}
3101
+			if (!@is_writable(dirname($filename))) {
3102
+							$package_ftp->chmod(dirname($ftp_file), 0777);
3103
+			}
2941 3104
 		}
2942 3105
 
2943 3106
 		if (@is_writable($filename))
2944 3107
 		{
2945
-			if ($track_change)
2946
-				$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3108
+			if ($track_change) {
3109
+							$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3110
+			}
2947 3111
 
2948 3112
 			return true;
3113
+		} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) {
3114
+					unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2949 3115
 		}
2950
-		elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename]))
2951
-			unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2952 3116
 	}
2953 3117
 
2954 3118
 	// Oh dear, we failed if we get here.
@@ -2966,11 +3130,13 @@  discard block
 block discarded – undo
2966 3130
 	$n = strlen($pass);
2967 3131
 
2968 3132
 	$salt = session_id();
2969
-	while (strlen($salt) < $n)
2970
-		$salt .= session_id();
3133
+	while (strlen($salt) < $n) {
3134
+			$salt .= session_id();
3135
+	}
2971 3136
 
2972
-	for ($i = 0; $i < $n; $i++)
2973
-		$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3137
+	for ($i = 0; $i < $n; $i++) {
3138
+			$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3139
+	}
2974 3140
 
2975 3141
 	return $pass;
2976 3142
 }
@@ -2989,8 +3155,9 @@  discard block
 block discarded – undo
2989 3155
 	$base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php');
2990 3156
 	foreach ($base_files as $file)
2991 3157
 	{
2992
-		if (file_exists($boarddir . '/' . $file))
2993
-			$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3158
+		if (file_exists($boarddir . '/' . $file)) {
3159
+					$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3160
+		}
2994 3161
 	}
2995 3162
 
2996 3163
 	$dirs = array(
@@ -3007,8 +3174,9 @@  discard block
 block discarded – undo
3007 3174
 			'theme_dir' => 'theme_dir',
3008 3175
 		)
3009 3176
 	);
3010
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3011
-		$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3177
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3178
+			$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3179
+	}
3012 3180
 	$smcFunc['db_free_result']($request);
3013 3181
 
3014 3182
 	try
@@ -3023,11 +3191,13 @@  discard block
 block discarded – undo
3023 3191
 
3024 3192
 			foreach ($iter as $entry => $dir)
3025 3193
 			{
3026
-				if ($dir->isDir())
3027
-					continue;
3194
+				if ($dir->isDir()) {
3195
+									continue;
3196
+				}
3028 3197
 
3029
-				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0)
3030
-					continue;
3198
+				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) {
3199
+									continue;
3200
+				}
3031 3201
 
3032 3202
 				$files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry;
3033 3203
 			}
@@ -3035,10 +3205,12 @@  discard block
 block discarded – undo
3035 3205
 		$obj = new ArrayObject($files);
3036 3206
 		$iterator = $obj->getIterator();
3037 3207
 
3038
-		if (!file_exists($packagesdir . '/backups'))
3039
-			mktree($packagesdir . '/backups', 0777);
3040
-		if (!is_writable($packagesdir . '/backups'))
3041
-			package_chmod($packagesdir . '/backups');
3208
+		if (!file_exists($packagesdir . '/backups')) {
3209
+					mktree($packagesdir . '/backups', 0777);
3210
+		}
3211
+		if (!is_writable($packagesdir . '/backups')) {
3212
+					package_chmod($packagesdir . '/backups');
3213
+		}
3042 3214
 		$output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id);
3043 3215
 		$output_ext = '.tar';
3044 3216
 		$output_ext_target = '.tar.gz';
@@ -3046,16 +3218,18 @@  discard block
 block discarded – undo
3046 3218
 		if (file_exists($output_file . $output_ext_target))
3047 3219
 		{
3048 3220
 			$i = 2;
3049
-			while (file_exists($output_file . '_' . $i . $output_ext_target))
3050
-				$i++;
3221
+			while (file_exists($output_file . '_' . $i . $output_ext_target)) {
3222
+							$i++;
3223
+			}
3051 3224
 			$output_file = $output_file . '_' . $i . $output_ext;
3225
+		} else {
3226
+					$output_file .= $output_ext;
3052 3227
 		}
3053
-		else
3054
-			$output_file .= $output_ext;
3055 3228
 
3056 3229
 		@set_time_limit(300);
3057
-		if (function_exists('apache_reset_timeout'))
3058
-			@apache_reset_timeout();
3230
+		if (function_exists('apache_reset_timeout')) {
3231
+					@apache_reset_timeout();
3232
+		}
3059 3233
 
3060 3234
 		$a = new PharData($output_file);
3061 3235
 		$a->buildFromIterator($iterator);
@@ -3067,8 +3241,7 @@  discard block
 block discarded – undo
3067 3241
 		 */
3068 3242
 		unset($a);
3069 3243
 		unlink($output_file);
3070
-	}
3071
-	catch (Exception $e)
3244
+	} catch (Exception $e)
3072 3245
 	{
3073 3246
 		log_error($e->getMessage(), 'backup');
3074 3247
 
@@ -3100,32 +3273,35 @@  discard block
 block discarded – undo
3100 3273
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
3101 3274
 
3102 3275
 	// An FTP url. We should try connecting and RETRieving it...
3103
-	if (empty($match[1]))
3104
-		return false;
3105
-	elseif ($match[1] == 'ftp')
3276
+	if (empty($match[1])) {
3277
+			return false;
3278
+	} elseif ($match[1] == 'ftp')
3106 3279
 	{
3107 3280
 		// Include the file containing the ftp_connection class.
3108 3281
 		require_once($sourcedir . '/Class-Package.php');
3109 3282
 
3110 3283
 		// Establish a connection and attempt to enable passive mode.
3111 3284
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
3112
-		if ($ftp->error !== false || !$ftp->passive())
3113
-			return false;
3285
+		if ($ftp->error !== false || !$ftp->passive()) {
3286
+					return false;
3287
+		}
3114 3288
 
3115 3289
 		// I want that one *points*!
3116 3290
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
3117 3291
 
3118 3292
 		// Since passive mode worked (or we would have returned already!) open the connection.
3119 3293
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
3120
-		if (!$fp)
3121
-			return false;
3294
+		if (!$fp) {
3295
+					return false;
3296
+		}
3122 3297
 
3123 3298
 		// The server should now say something in acknowledgement.
3124 3299
 		$ftp->check_response(150);
3125 3300
 
3126 3301
 		$data = '';
3127
-		while (!feof($fp))
3128
-			$data .= fread($fp, 4096);
3302
+		while (!feof($fp)) {
3303
+					$data .= fread($fp, 4096);
3304
+		}
3129 3305
 		fclose($fp);
3130 3306
 
3131 3307
 		// All done, right?  Good.
@@ -3142,22 +3318,25 @@  discard block
 block discarded – undo
3142 3318
 		$fetch_data->get_url_data($url, $post_data);
3143 3319
 
3144 3320
 		// no errors and a 200 result, then we have a good dataset, well we at least have data ;)
3145
-		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
3146
-			$data = $fetch_data->result('body');
3147
-		else
3148
-			return false;
3321
+		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
3322
+					$data = $fetch_data->result('body');
3323
+		} else {
3324
+					return false;
3325
+		}
3149 3326
 	}
3150 3327
 	// This is more likely; a standard HTTP URL.
3151 3328
 	elseif (isset($match[1]) && $match[1] == 'http')
3152 3329
 	{
3153
-		if ($keep_alive && $match[3] == $keep_alive_dom)
3154
-			$fp = $keep_alive_fp;
3330
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
3331
+					$fp = $keep_alive_fp;
3332
+		}
3155 3333
 		if (empty($fp))
3156 3334
 		{
3157 3335
 			// Open the socket on the port we want...
3158 3336
 			$fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5);
3159
-			if (!$fp)
3160
-				return false;
3337
+			if (!$fp) {
3338
+							return false;
3339
+			}
3161 3340
 		}
3162 3341
 
3163 3342
 		if ($keep_alive)
@@ -3172,20 +3351,21 @@  discard block
 block discarded – undo
3172 3351
 			fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
3173 3352
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3174 3353
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3175
-			if ($keep_alive)
3176
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3177
-			else
3178
-				fwrite($fp, 'Connection: close' . "\r\n\r\n");
3179
-		}
3180
-		else
3354
+			if ($keep_alive) {
3355
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3356
+			} else {
3357
+							fwrite($fp, 'Connection: close' . "\r\n\r\n");
3358
+			}
3359
+		} else
3181 3360
 		{
3182 3361
 			fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
3183 3362
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3184 3363
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3185
-			if ($keep_alive)
3186
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3187
-			else
3188
-				fwrite($fp, 'Connection: close' . "\r\n");
3364
+			if ($keep_alive) {
3365
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3366
+			} else {
3367
+							fwrite($fp, 'Connection: close' . "\r\n");
3368
+			}
3189 3369
 			fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n");
3190 3370
 			fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n");
3191 3371
 			fwrite($fp, $post_data);
@@ -3198,30 +3378,33 @@  discard block
 block discarded – undo
3198 3378
 		{
3199 3379
 			$header = '';
3200 3380
 			$location = '';
3201
-			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3202
-				if (strpos($header, 'Location:') !== false)
3381
+			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
3382
+							if (strpos($header, 'Location:') !== false)
3203 3383
 					$location = trim(substr($header, strpos($header, ':') + 1));
3384
+			}
3204 3385
 
3205
-			if (empty($location))
3206
-				return false;
3207
-			else
3386
+			if (empty($location)) {
3387
+							return false;
3388
+			} else
3208 3389
 			{
3209
-				if (!$keep_alive)
3210
-					fclose($fp);
3390
+				if (!$keep_alive) {
3391
+									fclose($fp);
3392
+				}
3211 3393
 				return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
3212 3394
 			}
3213 3395
 		}
3214 3396
 
3215 3397
 		// Make sure we get a 200 OK.
3216
-		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
3217
-			return false;
3398
+		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
3399
+					return false;
3400
+		}
3218 3401
 
3219 3402
 		// Skip the headers...
3220 3403
 		while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3221 3404
 		{
3222
-			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
3223
-				$content_length = $match[1];
3224
-			elseif (preg_match('~connection:\s*close~i', $header) != 0)
3405
+			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
3406
+							$content_length = $match[1];
3407
+			} elseif (preg_match('~connection:\s*close~i', $header) != 0)
3225 3408
 			{
3226 3409
 				$keep_alive_dom = null;
3227 3410
 				$keep_alive = false;
@@ -3233,19 +3416,20 @@  discard block
 block discarded – undo
3233 3416
 		$data = '';
3234 3417
 		if (isset($content_length))
3235 3418
 		{
3236
-			while (!feof($fp) && strlen($data) < $content_length)
3237
-				$data .= fread($fp, $content_length - strlen($data));
3238
-		}
3239
-		else
3419
+			while (!feof($fp) && strlen($data) < $content_length) {
3420
+							$data .= fread($fp, $content_length - strlen($data));
3421
+			}
3422
+		} else
3240 3423
 		{
3241
-			while (!feof($fp))
3242
-				$data .= fread($fp, 4096);
3424
+			while (!feof($fp)) {
3425
+							$data .= fread($fp, 4096);
3426
+			}
3243 3427
 		}
3244 3428
 
3245
-		if (!$keep_alive)
3246
-			fclose($fp);
3247
-	}
3248
-	else
3429
+		if (!$keep_alive) {
3430
+					fclose($fp);
3431
+		}
3432
+	} else
3249 3433
 	{
3250 3434
 		// Umm, this shouldn't happen?
3251 3435
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
Please login to merge, or discard this patch.