Completed
Push — release-2.1 ( 8364ab...05f921 )
by Mathias
08:23
created
Sources/ReCaptcha/RequestParameters.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -31,73 +31,73 @@
 block discarded – undo
31 31
  */
32 32
 class RequestParameters
33 33
 {
34
-    /**
35
-     * Site secret.
36
-     * @var string
37
-     */
38
-    private $secret;
34
+	/**
35
+	 * Site secret.
36
+	 * @var string
37
+	 */
38
+	private $secret;
39 39
 
40
-    /**
41
-     * Form response.
42
-     * @var string
43
-     */
44
-    private $response;
40
+	/**
41
+	 * Form response.
42
+	 * @var string
43
+	 */
44
+	private $response;
45 45
 
46
-    /**
47
-     * Remote user's IP address.
48
-     * @var string
49
-     */
50
-    private $remoteIp;
46
+	/**
47
+	 * Remote user's IP address.
48
+	 * @var string
49
+	 */
50
+	private $remoteIp;
51 51
 
52
-    /**
53
-     * Client version.
54
-     * @var string
55
-     */
56
-    private $version;
52
+	/**
53
+	 * Client version.
54
+	 * @var string
55
+	 */
56
+	private $version;
57 57
 
58
-    /**
59
-     * Initialise parameters.
60
-     *
61
-     * @param string $secret Site secret.
62
-     * @param string $response Value from g-captcha-response form field.
63
-     * @param string $remoteIp User's IP address.
64
-     * @param string $version Version of this client library.
65
-     */
66
-    public function __construct($secret, $response, $remoteIp = null, $version = null)
67
-    {
68
-        $this->secret = $secret;
69
-        $this->response = $response;
70
-        $this->remoteIp = $remoteIp;
71
-        $this->version = $version;
72
-    }
58
+	/**
59
+	 * Initialise parameters.
60
+	 *
61
+	 * @param string $secret Site secret.
62
+	 * @param string $response Value from g-captcha-response form field.
63
+	 * @param string $remoteIp User's IP address.
64
+	 * @param string $version Version of this client library.
65
+	 */
66
+	public function __construct($secret, $response, $remoteIp = null, $version = null)
67
+	{
68
+		$this->secret = $secret;
69
+		$this->response = $response;
70
+		$this->remoteIp = $remoteIp;
71
+		$this->version = $version;
72
+	}
73 73
 
74
-    /**
75
-     * Array representation.
76
-     *
77
-     * @return array Array formatted parameters.
78
-     */
79
-    public function toArray()
80
-    {
81
-        $params = array('secret' => $this->secret, 'response' => $this->response);
74
+	/**
75
+	 * Array representation.
76
+	 *
77
+	 * @return array Array formatted parameters.
78
+	 */
79
+	public function toArray()
80
+	{
81
+		$params = array('secret' => $this->secret, 'response' => $this->response);
82 82
 
83
-        if (!is_null($this->remoteIp)) {
84
-            $params['remoteip'] = $this->remoteIp;
85
-        }
83
+		if (!is_null($this->remoteIp)) {
84
+			$params['remoteip'] = $this->remoteIp;
85
+		}
86 86
 
87
-        if (!is_null($this->version)) {
88
-            $params['version'] = $this->version;
89
-        }
87
+		if (!is_null($this->version)) {
88
+			$params['version'] = $this->version;
89
+		}
90 90
 
91
-        return $params;
92
-    }
91
+		return $params;
92
+	}
93 93
 
94
-    /**
95
-     * Query string representation for HTTP request.
96
-     *
97
-     * @return string Query string formatted parameters.
98
-     */
99
-    public function toQueryString()
100
-    {
101
-        return http_build_query($this->toArray(), '', '&');
102
-    }
94
+	/**
95
+	 * Query string representation for HTTP request.
96
+	 *
97
+	 * @return string Query string formatted parameters.
98
+	 */
99
+	public function toQueryString()
100
+	{
101
+		return http_build_query($this->toArray(), '', '&');
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Sources/ReCaptcha/RequestMethod/Post.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -34,37 +34,37 @@
 block discarded – undo
34 34
  */
35 35
 class Post implements RequestMethod
36 36
 {
37
-    /**
38
-     * URL to which requests are POSTed.
39
-     * @const string
40
-     */
41
-    const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
37
+	/**
38
+	 * URL to which requests are POSTed.
39
+	 * @const string
40
+	 */
41
+	const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
42 42
 
43
-    /**
44
-     * Submit the POST request with the specified parameters.
45
-     *
46
-     * @param RequestParameters $params Request parameters
47
-     * @return string Body of the reCAPTCHA response
48
-     */
49
-    public function submit(RequestParameters $params)
50
-    {
51
-        /**
52
-         * PHP 5.6.0 changed the way you specify the peer name for SSL context options.
53
-         * Using "CN_name" will still work, but it will raise deprecated errors.
54
-         */
55
-        $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
56
-        $options = array(
57
-            'http' => array(
58
-                'header' => "Content-type: application/x-www-form-urlencoded\r\n",
59
-                'method' => 'POST',
60
-                'content' => $params->toQueryString(),
61
-                // Force the peer to validate (not needed in 5.6.0+, but still works
62
-                'verify_peer' => true,
63
-                // Force the peer validation to use www.google.com
64
-                $peer_key => 'www.google.com',
65
-            ),
66
-        );
67
-        $context = stream_context_create($options);
68
-        return file_get_contents(self::SITE_VERIFY_URL, false, $context);
69
-    }
43
+	/**
44
+	 * Submit the POST request with the specified parameters.
45
+	 *
46
+	 * @param RequestParameters $params Request parameters
47
+	 * @return string Body of the reCAPTCHA response
48
+	 */
49
+	public function submit(RequestParameters $params)
50
+	{
51
+		/**
52
+		 * PHP 5.6.0 changed the way you specify the peer name for SSL context options.
53
+		 * Using "CN_name" will still work, but it will raise deprecated errors.
54
+		 */
55
+		$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
56
+		$options = array(
57
+			'http' => array(
58
+				'header' => "Content-type: application/x-www-form-urlencoded\r\n",
59
+				'method' => 'POST',
60
+				'content' => $params->toQueryString(),
61
+				// Force the peer to validate (not needed in 5.6.0+, but still works
62
+				'verify_peer' => true,
63
+				// Force the peer validation to use www.google.com
64
+				$peer_key => 'www.google.com',
65
+			),
66
+		);
67
+		$context = stream_context_create($options);
68
+		return file_get_contents(self::SITE_VERIFY_URL, false, $context);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Sources/ReCaptcha/RequestMethod/CurlPost.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -36,53 +36,53 @@
 block discarded – undo
36 36
  */
37 37
 class CurlPost implements RequestMethod
38 38
 {
39
-    /**
40
-     * URL to which requests are sent via cURL.
41
-     * @const string
42
-     */
43
-    const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
39
+	/**
40
+	 * URL to which requests are sent via cURL.
41
+	 * @const string
42
+	 */
43
+	const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
44 44
 
45
-    /**
46
-     * Curl connection to the reCAPTCHA service
47
-     * @var Curl
48
-     */
49
-    private $curl;
45
+	/**
46
+	 * Curl connection to the reCAPTCHA service
47
+	 * @var Curl
48
+	 */
49
+	private $curl;
50 50
 
51
-    public function __construct(Curl $curl = null)
52
-    {
53
-        if (!is_null($curl)) {
54
-            $this->curl = $curl;
55
-        } else {
56
-            $this->curl = new Curl();
57
-        }
58
-    }
51
+	public function __construct(Curl $curl = null)
52
+	{
53
+		if (!is_null($curl)) {
54
+			$this->curl = $curl;
55
+		} else {
56
+			$this->curl = new Curl();
57
+		}
58
+	}
59 59
 
60
-    /**
61
-     * Submit the cURL request with the specified parameters.
62
-     *
63
-     * @param RequestParameters $params Request parameters
64
-     * @return string Body of the reCAPTCHA response
65
-     */
66
-    public function submit(RequestParameters $params)
67
-    {
68
-        $handle = $this->curl->init(self::SITE_VERIFY_URL);
60
+	/**
61
+	 * Submit the cURL request with the specified parameters.
62
+	 *
63
+	 * @param RequestParameters $params Request parameters
64
+	 * @return string Body of the reCAPTCHA response
65
+	 */
66
+	public function submit(RequestParameters $params)
67
+	{
68
+		$handle = $this->curl->init(self::SITE_VERIFY_URL);
69 69
 
70
-        $options = array(
71
-            CURLOPT_POST => true,
72
-            CURLOPT_POSTFIELDS => $params->toQueryString(),
73
-            CURLOPT_HTTPHEADER => array(
74
-                'Content-Type: application/x-www-form-urlencoded'
75
-            ),
76
-            CURLINFO_HEADER_OUT => false,
77
-            CURLOPT_HEADER => false,
78
-            CURLOPT_RETURNTRANSFER => true,
79
-            CURLOPT_SSL_VERIFYPEER => true
80
-        );
81
-        $this->curl->setoptArray($handle, $options);
70
+		$options = array(
71
+			CURLOPT_POST => true,
72
+			CURLOPT_POSTFIELDS => $params->toQueryString(),
73
+			CURLOPT_HTTPHEADER => array(
74
+				'Content-Type: application/x-www-form-urlencoded'
75
+			),
76
+			CURLINFO_HEADER_OUT => false,
77
+			CURLOPT_HEADER => false,
78
+			CURLOPT_RETURNTRANSFER => true,
79
+			CURLOPT_SSL_VERIFYPEER => true
80
+		);
81
+		$this->curl->setoptArray($handle, $options);
82 82
 
83
-        $response = $this->curl->exec($handle);
84
-        $this->curl->close($handle);
83
+		$response = $this->curl->exec($handle);
84
+		$this->curl->close($handle);
85 85
 
86
-        return $response;
87
-    }
86
+		return $response;
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Sources/ReCaptcha/RequestMethod/SocketPost.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -36,86 +36,86 @@
 block discarded – undo
36 36
  */
37 37
 class SocketPost implements RequestMethod
38 38
 {
39
-    /**
40
-     * reCAPTCHA service host.
41
-     * @const string
42
-     */
43
-    const RECAPTCHA_HOST = 'www.google.com';
44
-
45
-    /**
46
-     * @const string reCAPTCHA service path
47
-     */
48
-    const SITE_VERIFY_PATH = '/recaptcha/api/siteverify';
49
-
50
-    /**
51
-     * @const string Bad request error
52
-     */
53
-    const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}';
54
-
55
-    /**
56
-     * @const string Bad response error
57
-     */
58
-    const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}';
59
-
60
-    /**
61
-     * Socket to the reCAPTCHA service
62
-     * @var Socket
63
-     */
64
-    private $socket;
65
-
66
-    /**
67
-     * Constructor
68
-     *
69
-     * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing
70
-     */
71
-    public function __construct(Socket $socket = null)
72
-    {
73
-        if (!is_null($socket)) {
74
-            $this->socket = $socket;
75
-        } else {
76
-            $this->socket = new Socket();
77
-        }
78
-    }
79
-
80
-    /**
81
-     * Submit the POST request with the specified parameters.
82
-     *
83
-     * @param RequestParameters $params Request parameters
84
-     * @return string Body of the reCAPTCHA response
85
-     */
86
-    public function submit(RequestParameters $params)
87
-    {
88
-        $errno = 0;
89
-        $errstr = '';
90
-
91
-        if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) {
92
-            return self::BAD_REQUEST;
93
-        }
94
-
95
-        $content = $params->toQueryString();
96
-
97
-        $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n";
98
-        $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n";
99
-        $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
100
-        $request .= "Content-length: " . strlen($content) . "\r\n";
101
-        $request .= "Connection: close\r\n\r\n";
102
-        $request .= $content . "\r\n\r\n";
103
-
104
-        $this->socket->fwrite($request);
105
-        $response = '';
106
-
107
-        while (!$this->socket->feof()) {
108
-            $response .= $this->socket->fgets(4096);
109
-        }
110
-
111
-        $this->socket->fclose();
112
-
113
-        if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
114
-            return self::BAD_RESPONSE;
115
-        }
116
-
117
-        $parts = preg_split("#\n\s*\n#Uis", $response);
118
-
119
-        return $parts[1];
120
-    }
39
+	/**
40
+	 * reCAPTCHA service host.
41
+	 * @const string
42
+	 */
43
+	const RECAPTCHA_HOST = 'www.google.com';
44
+
45
+	/**
46
+	 * @const string reCAPTCHA service path
47
+	 */
48
+	const SITE_VERIFY_PATH = '/recaptcha/api/siteverify';
49
+
50
+	/**
51
+	 * @const string Bad request error
52
+	 */
53
+	const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}';
54
+
55
+	/**
56
+	 * @const string Bad response error
57
+	 */
58
+	const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}';
59
+
60
+	/**
61
+	 * Socket to the reCAPTCHA service
62
+	 * @var Socket
63
+	 */
64
+	private $socket;
65
+
66
+	/**
67
+	 * Constructor
68
+	 *
69
+	 * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing
70
+	 */
71
+	public function __construct(Socket $socket = null)
72
+	{
73
+		if (!is_null($socket)) {
74
+			$this->socket = $socket;
75
+		} else {
76
+			$this->socket = new Socket();
77
+		}
78
+	}
79
+
80
+	/**
81
+	 * Submit the POST request with the specified parameters.
82
+	 *
83
+	 * @param RequestParameters $params Request parameters
84
+	 * @return string Body of the reCAPTCHA response
85
+	 */
86
+	public function submit(RequestParameters $params)
87
+	{
88
+		$errno = 0;
89
+		$errstr = '';
90
+
91
+		if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) {
92
+			return self::BAD_REQUEST;
93
+		}
94
+
95
+		$content = $params->toQueryString();
96
+
97
+		$request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n";
98
+		$request .= "Host: " . self::RECAPTCHA_HOST . "\r\n";
99
+		$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
100
+		$request .= "Content-length: " . strlen($content) . "\r\n";
101
+		$request .= "Connection: close\r\n\r\n";
102
+		$request .= $content . "\r\n\r\n";
103
+
104
+		$this->socket->fwrite($request);
105
+		$response = '';
106
+
107
+		while (!$this->socket->feof()) {
108
+			$response .= $this->socket->fgets(4096);
109
+		}
110
+
111
+		$this->socket->fclose();
112
+
113
+		if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
114
+			return self::BAD_RESPONSE;
115
+		}
116
+
117
+		$parts = preg_split("#\n\s*\n#Uis", $response);
118
+
119
+		return $parts[1];
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Sources/ReCaptcha/Response.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -31,72 +31,72 @@
 block discarded – undo
31 31
  */
32 32
 class Response
33 33
 {
34
-    /**
35
-     * Succes or failure.
36
-     * @var boolean
37
-     */
38
-    private $success = false;
34
+	/**
35
+	 * Succes or failure.
36
+	 * @var boolean
37
+	 */
38
+	private $success = false;
39 39
 
40
-    /**
41
-     * Error code strings.
42
-     * @var array
43
-     */
44
-    private $errorCodes = array();
40
+	/**
41
+	 * Error code strings.
42
+	 * @var array
43
+	 */
44
+	private $errorCodes = array();
45 45
 
46
-    /**
47
-     * Build the response from the expected JSON returned by the service.
48
-     *
49
-     * @param string $json
50
-     * @return \ReCaptcha\Response
51
-     */
52
-    public static function fromJson($json)
53
-    {
54
-        $responseData = json_decode($json, true);
46
+	/**
47
+	 * Build the response from the expected JSON returned by the service.
48
+	 *
49
+	 * @param string $json
50
+	 * @return \ReCaptcha\Response
51
+	 */
52
+	public static function fromJson($json)
53
+	{
54
+		$responseData = json_decode($json, true);
55 55
 
56
-        if (!$responseData) {
57
-            return new Response(false, array('invalid-json'));
58
-        }
56
+		if (!$responseData) {
57
+			return new Response(false, array('invalid-json'));
58
+		}
59 59
 
60
-        if (isset($responseData['success']) && $responseData['success'] == true) {
61
-            return new Response(true);
62
-        }
60
+		if (isset($responseData['success']) && $responseData['success'] == true) {
61
+			return new Response(true);
62
+		}
63 63
 
64
-        if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
65
-            return new Response(false, $responseData['error-codes']);
66
-        }
64
+		if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
65
+			return new Response(false, $responseData['error-codes']);
66
+		}
67 67
 
68
-        return new Response(false);
69
-    }
68
+		return new Response(false);
69
+	}
70 70
 
71
-    /**
72
-     * Constructor.
73
-     *
74
-     * @param boolean $success
75
-     * @param array $errorCodes
76
-     */
77
-    public function __construct($success, array $errorCodes = array())
78
-    {
79
-        $this->success = $success;
80
-        $this->errorCodes = $errorCodes;
81
-    }
71
+	/**
72
+	 * Constructor.
73
+	 *
74
+	 * @param boolean $success
75
+	 * @param array $errorCodes
76
+	 */
77
+	public function __construct($success, array $errorCodes = array())
78
+	{
79
+		$this->success = $success;
80
+		$this->errorCodes = $errorCodes;
81
+	}
82 82
 
83
-    /**
84
-     * Is success?
85
-     *
86
-     * @return boolean
87
-     */
88
-    public function isSuccess()
89
-    {
90
-        return $this->success;
91
-    }
83
+	/**
84
+	 * Is success?
85
+	 *
86
+	 * @return boolean
87
+	 */
88
+	public function isSuccess()
89
+	{
90
+		return $this->success;
91
+	}
92 92
 
93
-    /**
94
-     * Get error codes.
95
-     *
96
-     * @return array
97
-     */
98
-    public function getErrorCodes()
99
-    {
100
-        return $this->errorCodes;
101
-    }
93
+	/**
94
+	 * Get error codes.
95
+	 *
96
+	 * @return array
97
+	 */
98
+	public function getErrorCodes()
99
+	{
100
+		return $this->errorCodes;
101
+	}
102 102
 }
Please login to merge, or discard this patch.
Sources/ReCaptcha/RequestMethod.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@
 block discarded – undo
32 32
 interface RequestMethod
33 33
 {
34 34
 
35
-    /**
36
-     * Submit the request with the specified parameters.
37
-     *
38
-     * @param RequestParameters $params Request parameters
39
-     * @return string Body of the reCAPTCHA response
40
-     */
41
-    public function submit(RequestParameters $params);
35
+	/**
36
+	 * Submit the request with the specified parameters.
37
+	 *
38
+	 * @param RequestParameters $params Request parameters
39
+	 * @return string Body of the reCAPTCHA response
40
+	 */
41
+	public function submit(RequestParameters $params);
42 42
 }
Please login to merge, or discard this patch.
other/upgrade-helper.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 /**
82 82
  * Make files writable. First try to use regular chmod, but if that fails, try to use FTP.
83 83
  *
84
- * @param $files
84
+ * @param string[] $files
85 85
  * @return bool
86 86
  */
87 87
 function makeFilesWritable(&$files)
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 /**
323 323
  * Prints an error to stderr.
324 324
  *
325
- * @param $message
325
+ * @param string $message
326 326
  * @param bool $fatal
327 327
  */
328 328
 function print_error($message, $fatal = false)
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 /**
342 342
  * Throws a graphical error message.
343 343
  *
344
- * @param $message
344
+ * @param string $message
345 345
  * @return bool
346 346
  */
347 347
 function throw_error($message)
Please login to merge, or discard this patch.
Braces   +90 added lines, -64 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
 	die('No direct access!');
18
+}
18 19
 
19 20
 /**
20 21
  * Clean the cache using the SMF 2.1 CacheAPI.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	global $smcFunc;
46 47
 	static $member_groups = array();
47 48
 
48
-	if (!empty($member_groups))
49
-		return $member_groups;
49
+	if (!empty($member_groups)) {
50
+			return $member_groups;
51
+	}
50 52
 
51 53
 	$request = $smcFunc['db_query']('', '
52 54
 		SELECT group_name, id_group
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 			)
72 74
 		);
73 75
 	}
74
-	while ($row = $smcFunc['db_fetch_row']($request))
75
-		$member_groups[trim($row[0])] = $row[1];
76
+	while ($row = $smcFunc['db_fetch_row']($request)) {
77
+			$member_groups[trim($row[0])] = $row[1];
78
+	}
76 79
 	$smcFunc['db_free_result']($request);
77 80
 
78 81
 	return $member_groups;
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 {
89 92
 	global $upcontext, $boarddir, $sourcedir;
90 93
 
91
-	if (empty($files))
92
-		return true;
94
+	if (empty($files)) {
95
+			return true;
96
+	}
93 97
 
94 98
 	$failure = false;
95 99
 	// On linux, it's easy - just use is_writable!
@@ -104,14 +108,16 @@  discard block
 block discarded – undo
104 108
 				@chmod($file, 0755);
105 109
 
106 110
 				// Well, 755 hopefully worked... if not, try 777.
107
-				if (!is_writable($file) && !@chmod($file, 0777))
108
-					$failure = true;
111
+				if (!is_writable($file) && !@chmod($file, 0777)) {
112
+									$failure = true;
113
+				}
109 114
 				// Otherwise remove it as it's good!
110
-				else
111
-					unset($files[$k]);
115
+				else {
116
+									unset($files[$k]);
117
+				}
118
+			} else {
119
+							unset($files[$k]);
112 120
 			}
113
-			else
114
-				unset($files[$k]);
115 121
 		}
116 122
 	}
117 123
 	// Windows is trickier.  Let's try opening for r+...
@@ -122,30 +128,35 @@  discard block
 block discarded – undo
122 128
 		foreach ($files as $k => $file)
123 129
 		{
124 130
 			// Folders can't be opened for write... but the index.php in them can ;).
125
-			if (is_dir($file))
126
-				$file .= '/index.php';
131
+			if (is_dir($file)) {
132
+							$file .= '/index.php';
133
+			}
127 134
 
128 135
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
129 136
 			@chmod($file, 0777);
130 137
 			$fp = @fopen($file, 'r+');
131 138
 
132 139
 			// Hmm, okay, try just for write in that case...
133
-			if (!$fp)
134
-				$fp = @fopen($file, 'w');
140
+			if (!$fp) {
141
+							$fp = @fopen($file, 'w');
142
+			}
135 143
 
136
-			if (!$fp)
137
-				$failure = true;
138
-			else
139
-				unset($files[$k]);
144
+			if (!$fp) {
145
+							$failure = true;
146
+			} else {
147
+							unset($files[$k]);
148
+			}
140 149
 			@fclose($fp);
141 150
 		}
142 151
 	}
143 152
 
144
-	if (empty($files))
145
-		return true;
153
+	if (empty($files)) {
154
+			return true;
155
+	}
146 156
 
147
-	if (!isset($_SERVER))
148
-		return !$failure;
157
+	if (!isset($_SERVER)) {
158
+			return !$failure;
159
+	}
149 160
 
150 161
 	// What still needs to be done?
151 162
 	$upcontext['chmod']['files'] = $files;
@@ -197,36 +208,40 @@  discard block
 block discarded – undo
197 208
 
198 209
 		if (!isset($ftp) || $ftp->error !== false)
199 210
 		{
200
-			if (!isset($ftp))
201
-				$ftp = new ftp_connection(null);
211
+			if (!isset($ftp)) {
212
+							$ftp = new ftp_connection(null);
213
+			}
202 214
 			// Save the error so we can mess with listing...
203
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
204
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
215
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
216
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
217
+			}
205 218
 
206 219
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
207 220
 
208
-			if ($found_path || !isset($upcontext['chmod']['path']))
209
-				$upcontext['chmod']['path'] = $detect_path;
221
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
222
+							$upcontext['chmod']['path'] = $detect_path;
223
+			}
210 224
 
211
-			if (!isset($upcontext['chmod']['username']))
212
-				$upcontext['chmod']['username'] = $username;
225
+			if (!isset($upcontext['chmod']['username'])) {
226
+							$upcontext['chmod']['username'] = $username;
227
+			}
213 228
 
214 229
 			// Don't forget the login token.
215 230
 			$upcontext += createToken('login');
216 231
 
217 232
 			return false;
218
-		}
219
-		else
233
+		} else
220 234
 		{
221 235
 			// We want to do a relative path for FTP.
222 236
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
223 237
 			{
224 238
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
225
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
226
-					$ftp_root = substr($ftp_root, 0, -1);
239
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
240
+									$ftp_root = substr($ftp_root, 0, -1);
241
+				}
242
+			} else {
243
+							$ftp_root = $boarddir;
227 244
 			}
228
-			else
229
-				$ftp_root = $boarddir;
230 245
 
231 246
 			// Save the info for next time!
232 247
 			$_SESSION['installer_temp_ftp'] = array(
@@ -240,10 +255,12 @@  discard block
 block discarded – undo
240 255
 
241 256
 			foreach ($files as $k => $file)
242 257
 			{
243
-				if (!is_writable($file))
244
-					$ftp->chmod($file, 0755);
245
-				if (!is_writable($file))
246
-					$ftp->chmod($file, 0777);
258
+				if (!is_writable($file)) {
259
+									$ftp->chmod($file, 0755);
260
+				}
261
+				if (!is_writable($file)) {
262
+									$ftp->chmod($file, 0777);
263
+				}
247 264
 
248 265
 				// Assuming that didn't work calculate the path without the boarddir.
249 266
 				if (!is_writable($file))
@@ -252,19 +269,23 @@  discard block
 block discarded – undo
252 269
 					{
253 270
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
254 271
 						$ftp->chmod($ftp_file, 0755);
255
-						if (!is_writable($file))
256
-							$ftp->chmod($ftp_file, 0777);
272
+						if (!is_writable($file)) {
273
+													$ftp->chmod($ftp_file, 0777);
274
+						}
257 275
 						// Sometimes an extra slash can help...
258 276
 						$ftp_file = '/' . $ftp_file;
259
-						if (!is_writable($file))
260
-							$ftp->chmod($ftp_file, 0755);
261
-						if (!is_writable($file))
262
-							$ftp->chmod($ftp_file, 0777);
277
+						if (!is_writable($file)) {
278
+													$ftp->chmod($ftp_file, 0755);
279
+						}
280
+						if (!is_writable($file)) {
281
+													$ftp->chmod($ftp_file, 0777);
282
+						}
263 283
 					}
264 284
 				}
265 285
 
266
-				if (is_writable($file))
267
-					unset($files[$k]);
286
+				if (is_writable($file)) {
287
+									unset($files[$k]);
288
+				}
268 289
 			}
269 290
 
270 291
 			$ftp->close();
@@ -274,8 +295,9 @@  discard block
 block discarded – undo
274 295
 	// What remains?
275 296
 	$upcontext['chmod']['files'] = $files;
276 297
 
277
-	if (empty($files))
278
-		return true;
298
+	if (empty($files)) {
299
+			return true;
300
+	}
279 301
 
280 302
 	return false;
281 303
 }
@@ -288,8 +310,9 @@  discard block
 block discarded – undo
288 310
  */
289 311
 function quickFileWritable($file)
290 312
 {
291
-	if (is_writable($file))
292
-		return true;
313
+	if (is_writable($file)) {
314
+			return true;
315
+	}
293 316
 
294 317
 	@chmod($file, 0755);
295 318
 
@@ -299,10 +322,11 @@  discard block
 block discarded – undo
299 322
 	foreach ($chmod_values as $val)
300 323
 	{
301 324
 		// If it's writable, break out of the loop
302
-		if (is_writable($file))
303
-			break;
304
-		else
305
-			@chmod($file, $val);
325
+		if (is_writable($file)) {
326
+					break;
327
+		} else {
328
+					@chmod($file, $val);
329
+		}
306 330
 	}
307 331
 
308 332
 	return is_writable($file);
@@ -329,14 +353,16 @@  discard block
 block discarded – undo
329 353
 {
330 354
 	static $fp = null;
331 355
 
332
-	if ($fp === null)
333
-		$fp = fopen('php://stderr', 'wb');
356
+	if ($fp === null) {
357
+			$fp = fopen('php://stderr', 'wb');
358
+	}
334 359
 
335 360
 	fwrite($fp, $message . "\n");
336 361
 
337
-	if ($fatal)
338
-		exit;
339
-}
362
+	if ($fatal) {
363
+			exit;
364
+	}
365
+	}
340 366
 
341 367
 /**
342 368
  * Throws a graphical error message.
Please login to merge, or discard this patch.
other/upgrade.php 4 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -393,6 +393,9 @@  discard block
 block discarded – undo
393 393
 }
394 394
 
395 395
 // Used to direct the user to another location.
396
+/**
397
+ * @param string $location
398
+ */
396 399
 function redirectLocation($location, $addForm = true)
397 400
 {
398 401
 	global $upgradeurl, $upcontext, $command_line;
@@ -1573,6 +1576,9 @@  discard block
 block discarded – undo
1573 1576
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1574 1577
 }
1575 1578
 
1579
+/**
1580
+ * @param string $filename
1581
+ */
1576 1582
 function parse_sql($filename)
1577 1583
 {
1578 1584
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -1607,6 +1613,10 @@  discard block
 block discarded – undo
1607 1613
 
1608 1614
 	// Our custom error handler - does nothing but does stop public errors from XML!
1609 1615
 	set_error_handler(
1616
+
1617
+		/**
1618
+		 * @param string $errno
1619
+		 */
1610 1620
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1611 1621
 		{
1612 1622
 			if ($support_js)
@@ -1853,6 +1863,9 @@  discard block
 block discarded – undo
1853 1863
 	return true;
1854 1864
 }
1855 1865
 
1866
+/**
1867
+ * @param string $string
1868
+ */
1856 1869
 function upgrade_query($string, $unbuffered = false)
1857 1870
 {
1858 1871
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4512,7 +4525,7 @@  discard block
 block discarded – undo
4512 4525
  * @param int $setSize The amount of entries after which to update the database.
4513 4526
  *
4514 4527
  * newCol needs to be a varbinary(16) null able field
4515
- * @return bool
4528
+ * @return boolean|null
4516 4529
  */
4517 4530
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4518 4531
 {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84 84
 if (!file_exists($upgrade_path . '/upgrade-helper.php'))
85
-    die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
85
+	die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
86 86
 
87 87
 require_once($upgrade_path . '/upgrade-helper.php');
88 88
 
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
 
1626 1626
 	// Our custom error handler - does nothing but does stop public errors from XML!
1627 1627
 	set_error_handler(
1628
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1628
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1629 1629
 		{
1630 1630
 			if ($support_js)
1631 1631
 				return true;
@@ -2610,94 +2610,94 @@  discard block
 block discarded – undo
2610 2610
 		// Translation table for the character sets not native for MySQL.
2611 2611
 		$translation_tables = array(
2612 2612
 			'windows-1255' => array(
2613
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2614
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2615
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2616
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2617
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2618
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2619
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2620
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2621
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2622
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2623
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2624
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2625
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2626
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2627
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2628
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2629
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2630
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2631
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2632
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2633
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2634
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2635
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2636
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2637
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2638
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2639
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2640
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2641
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2642
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2643
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2644
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2645
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2646
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2647
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2648
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2649
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2650
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2651
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2652
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2653
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2654
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2613
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2614
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2615
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2616
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2617
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2618
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2619
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2620
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2621
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2622
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2623
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2624
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2625
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2626
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2627
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2628
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2629
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2630
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2631
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2632
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2633
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2634
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2635
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2636
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2637
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2638
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2639
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2640
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2641
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2642
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2643
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2644
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2645
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2646
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2647
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2648
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2649
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2650
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2651
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2652
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2653
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2654
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2655 2655
 				'0xFA' => '0xD7AA',
2656 2656
 			),
2657 2657
 			'windows-1253' => array(
2658
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2659
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2660
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2661
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2662
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2663
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2664
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2665
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2666
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2667
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2668
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2669
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2670
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2671
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2672
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2673
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2674
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2675
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2676
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2677
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2678
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2679
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2680
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2681
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2682
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2683
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2684
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2685
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2686
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2687
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2688
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2689
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2690
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2691
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2692
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2693
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2694
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2695
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2696
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2697
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2698
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2699
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2700
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2658
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2659
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2660
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2661
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2662
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2663
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2664
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2665
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2666
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2667
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2668
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2669
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2670
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2671
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2672
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2673
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2674
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2675
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2676
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2677
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2678
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2679
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2680
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2681
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2682
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2683
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2684
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2685
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2686
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2687
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2688
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2689
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2690
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2691
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2692
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2693
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2694
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2695
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2696
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2697
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2698
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2699
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2700
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2701 2701
 			),
2702 2702
 		);
2703 2703
 
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
3800 3800
 			<input type="hidden" name="backup_done" id="backup_done" value="0">
3801 3801
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
3802
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
3802
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
3803 3803
 			<span id="debuginfo"></span>
3804 3804
 			</div>';
3805 3805
 
@@ -4300,7 +4300,7 @@  discard block
 block discarded – undo
4300 4300
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4301 4301
 			<input type="hidden" name="utf8_done" id="utf8_done" value="0">
4302 4302
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4303
-			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12') , 'px; overflow: auto;">
4303
+			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12'), 'px; overflow: auto;">
4304 4304
 			<span id="debuginfo"></span>
4305 4305
 			</div>';
4306 4306
 
@@ -4401,7 +4401,7 @@  discard block
 block discarded – undo
4401 4401
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4402 4402
 			<input type="hidden" name="json_done" id="json_done" value="0">
4403 4403
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4404
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
4404
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
4405 4405
 			<span id="debuginfo"></span>
4406 4406
 			</div>';
4407 4407
 
Please login to merge, or discard this patch.
Braces   +878 added lines, -645 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,9 +290,9 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			//Clear out warnings at the start of each step
@@ -323,17 +338,18 @@  discard block
 block discarded – undo
323 338
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 339
 		if (!empty($command_line))
325 340
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
341
+			if (function_exists('debug_print_backtrace')) {
342
+							debug_print_backtrace();
343
+			}
328 344
 
329 345
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
330 346
 			flush();
331 347
 			die();
332 348
 		}
333 349
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
350
+		if (!isset($_GET['xml'])) {
351
+					template_upgrade_above();
352
+		} else
337 353
 		{
338 354
 			header('Content-Type: text/xml; charset=UTF-8');
339 355
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,25 +371,29 @@  discard block
 block discarded – undo
355 371
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 372
 
357 373
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
374
+			if (!empty($upcontext['query_string'])) {
375
+							$upcontext['form_url'] .= $upcontext['query_string'];
376
+			}
360 377
 
361 378
 			// Call the appropriate subtemplate
362
-			if (is_callable('template_' . $upcontext['sub_template']))
363
-				call_user_func('template_' . $upcontext['sub_template']);
364
-			else
365
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
379
+			if (is_callable('template_' . $upcontext['sub_template'])) {
380
+							call_user_func('template_' . $upcontext['sub_template']);
381
+			} else {
382
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
383
+			}
366 384
 		}
367 385
 
368 386
 		// Was there an error?
369
-		if (!empty($upcontext['forced_error_message']))
370
-			echo $upcontext['forced_error_message'];
387
+		if (!empty($upcontext['forced_error_message'])) {
388
+					echo $upcontext['forced_error_message'];
389
+		}
371 390
 
372 391
 		// Show the footer.
373
-		if (!isset($_GET['xml']))
374
-			template_upgrade_below();
375
-		else
376
-			template_xml_below();
392
+		if (!isset($_GET['xml'])) {
393
+					template_upgrade_below();
394
+		} else {
395
+					template_xml_below();
396
+		}
377 397
 	}
378 398
 
379 399
 
@@ -385,15 +405,19 @@  discard block
 block discarded – undo
385 405
 		$seconds = intval($active % 60);
386 406
 
387 407
 		$totalTime = '';
388
-		if ($hours > 0)
389
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
390
-		if ($minutes > 0)
391
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
392
-		if ($seconds > 0)
393
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
408
+		if ($hours > 0) {
409
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
410
+		}
411
+		if ($minutes > 0) {
412
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
413
+		}
414
+		if ($seconds > 0) {
415
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
416
+		}
394 417
 
395
-		if (!empty($totalTime))
396
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		if (!empty($totalTime)) {
419
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
420
+		}
397 421
 	}
398 422
 
399 423
 	// Bang - gone!
@@ -406,8 +430,9 @@  discard block
 block discarded – undo
406 430
 	global $upgradeurl, $upcontext, $command_line;
407 431
 
408 432
 	// Command line users can't be redirected.
409
-	if ($command_line)
410
-		upgradeExit(true);
433
+	if ($command_line) {
434
+			upgradeExit(true);
435
+	}
411 436
 
412 437
 	// Are we providing the core info?
413 438
 	if ($addForm)
@@ -433,12 +458,14 @@  discard block
 block discarded – undo
433 458
 	define('SMF', 1);
434 459
 
435 460
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
461
+	if (@ini_get('session.save_handler') == 'user') {
462
+			@ini_set('session.save_handler', 'files');
463
+	}
438 464
 	@session_start();
439 465
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
466
+	if (empty($smcFunc)) {
467
+			$smcFunc = array();
468
+	}
442 469
 
443 470
 	// We need this for authentication and some upgrade code
444 471
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -450,32 +477,36 @@  discard block
 block discarded – undo
450 477
 	initialize_inputs();
451 478
 
452 479
 	// Get the database going!
453
-	if (empty($db_type) || $db_type == 'mysqli')
454
-		$db_type = 'mysql';
480
+	if (empty($db_type) || $db_type == 'mysqli') {
481
+			$db_type = 'mysql';
482
+	}
455 483
 
456 484
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
457 485
 	{
458 486
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
459 487
 
460 488
 		// Make the connection...
461
-		if (empty($db_connection))
462
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
463
-		else
464
-			// If we've returned here, ping/reconnect to be safe
489
+		if (empty($db_connection)) {
490
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
491
+		} else {
492
+					// If we've returned here, ping/reconnect to be safe
465 493
 			$smcFunc['db_ping']($db_connection);
494
+		}
466 495
 
467 496
 		// Oh dear god!!
468
-		if ($db_connection === null)
469
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
497
+		if ($db_connection === null) {
498
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
499
+		}
470 500
 
471
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
472
-			$smcFunc['db_query']('', '
501
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
502
+					$smcFunc['db_query']('', '
473 503
 			SET NAMES {string:db_character_set}',
474 504
 			array(
475 505
 				'db_error_skip' => true,
476 506
 				'db_character_set' => $db_character_set,
477 507
 			)
478 508
 		);
509
+		}
479 510
 
480 511
 		// Load the modSettings data...
481 512
 		$request = $smcFunc['db_query']('', '
@@ -486,11 +517,11 @@  discard block
 block discarded – undo
486 517
 			)
487 518
 		);
488 519
 		$modSettings = array();
489
-		while ($row = $smcFunc['db_fetch_assoc']($request))
490
-			$modSettings[$row['variable']] = $row['value'];
520
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
521
+					$modSettings[$row['variable']] = $row['value'];
522
+		}
491 523
 		$smcFunc['db_free_result']($request);
492
-	}
493
-	else
524
+	} else
494 525
 	{
495 526
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
496 527
 	}
@@ -504,9 +535,10 @@  discard block
 block discarded – undo
504 535
 		cleanRequest();
505 536
 	}
506 537
 
507
-	if (!isset($_GET['substep']))
508
-		$_GET['substep'] = 0;
509
-}
538
+	if (!isset($_GET['substep'])) {
539
+			$_GET['substep'] = 0;
540
+	}
541
+	}
510 542
 
511 543
 function initialize_inputs()
512 544
 {
@@ -536,8 +568,9 @@  discard block
 block discarded – undo
536 568
 		$dh = opendir(dirname(__FILE__));
537 569
 		while ($file = readdir($dh))
538 570
 		{
539
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
540
-				@unlink(dirname(__FILE__) . '/' . $file);
571
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
572
+							@unlink(dirname(__FILE__) . '/' . $file);
573
+			}
541 574
 		}
542 575
 		closedir($dh);
543 576
 
@@ -566,8 +599,9 @@  discard block
 block discarded – undo
566 599
 	$temp = 'upgrade_php?step';
567 600
 	while (strlen($temp) > 4)
568 601
 	{
569
-		if (isset($_GET[$temp]))
570
-			unset($_GET[$temp]);
602
+		if (isset($_GET[$temp])) {
603
+					unset($_GET[$temp]);
604
+		}
571 605
 		$temp = substr($temp, 1);
572 606
 	}
573 607
 
@@ -594,32 +628,39 @@  discard block
 block discarded – undo
594 628
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
595 629
 
596 630
 	// Need legacy scripts?
597
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
598
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
599
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
600
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
601
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
602
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
631
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
632
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
633
+	}
634
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
635
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
636
+	}
637
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
638
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
639
+	}
603 640
 
604 641
 	// We don't need "-utf8" files anymore...
605 642
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
606 643
 
607 644
 	// This needs to exist!
608
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
609
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
610
-	else
611
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
645
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
646
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
647
+	} else {
648
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
649
+	}
612 650
 
613
-	if (!$check)
614
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
651
+	if (!$check) {
652
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
615 653
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
654
+	}
616 655
 
617 656
 	// Do they meet the install requirements?
618
-	if (!php_version_check())
619
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
657
+	if (!php_version_check()) {
658
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
659
+	}
620 660
 
621
-	if (!db_version_check())
622
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
661
+	if (!db_version_check()) {
662
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
663
+	}
623 664
 
624 665
 	// Do some checks to make sure they have proper privileges
625 666
 	db_extend('packages');
@@ -634,14 +675,16 @@  discard block
 block discarded – undo
634 675
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
635 676
 
636 677
 	// Sorry... we need CREATE, ALTER and DROP
637
-	if (!$create || !$alter || !$drop)
638
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
678
+	if (!$create || !$alter || !$drop) {
679
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
680
+	}
639 681
 
640 682
 	// Do a quick version spot check.
641 683
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
642 684
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
643
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
644
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
685
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
686
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
687
+	}
645 688
 
646 689
 	// What absolutely needs to be writable?
647 690
 	$writable_files = array(
@@ -663,12 +706,13 @@  discard block
 block discarded – undo
663 706
 	quickFileWritable($custom_av_dir);
664 707
 
665 708
 	// Are we good now?
666
-	if (!is_writable($custom_av_dir))
667
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
668
-	elseif ($need_settings_update)
709
+	if (!is_writable($custom_av_dir)) {
710
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
711
+	} elseif ($need_settings_update)
669 712
 	{
670
-		if (!function_exists('cache_put_data'))
671
-			require_once($sourcedir . '/Load.php');
713
+		if (!function_exists('cache_put_data')) {
714
+					require_once($sourcedir . '/Load.php');
715
+		}
672 716
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
673 717
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
674 718
 	}
@@ -677,28 +721,33 @@  discard block
 block discarded – undo
677 721
 
678 722
 	// Check the cache directory.
679 723
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
680
-	if (!file_exists($cachedir_temp))
681
-		@mkdir($cachedir_temp);
682
-	if (!file_exists($cachedir_temp))
683
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
684
-
685
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
686
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
687
-	elseif (!isset($_GET['skiplang']))
724
+	if (!file_exists($cachedir_temp)) {
725
+			@mkdir($cachedir_temp);
726
+	}
727
+	if (!file_exists($cachedir_temp)) {
728
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
729
+	}
730
+
731
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
732
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
733
+	} elseif (!isset($_GET['skiplang']))
688 734
 	{
689 735
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
690 736
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
691 737
 
692
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
693
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
738
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
739
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
740
+		}
694 741
 	}
695 742
 
696
-	if (!makeFilesWritable($writable_files))
697
-		return false;
743
+	if (!makeFilesWritable($writable_files)) {
744
+			return false;
745
+	}
698 746
 
699 747
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
700
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
701
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
748
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
749
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
750
+	}
702 751
 
703 752
 	// Upgrade the agreement.
704 753
 	elseif (isset($modSettings['agreement']))
@@ -709,8 +758,8 @@  discard block
 block discarded – undo
709 758
 	}
710 759
 
711 760
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
712
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
713
-		$upcontext['warning'] = '
761
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
762
+			$upcontext['warning'] = '
714 763
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
715 764
 			<ul>
716 765
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -718,15 +767,18 @@  discard block
 block discarded – undo
718 767
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
719 768
 			</ul>
720 769
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
770
+	}
721 771
 
722 772
 	// Check for https stream support.
723 773
 	$supported_streams = stream_get_wrappers();
724
-	if (!in_array('https', $supported_streams))
725
-		$upcontext['custom_warning'] = $txt['install_no_https'];
774
+	if (!in_array('https', $supported_streams)) {
775
+			$upcontext['custom_warning'] = $txt['install_no_https'];
776
+	}
726 777
 
727 778
 	// Either we're logged in or we're going to present the login.
728
-	if (checkLogin())
729
-		return true;
779
+	if (checkLogin()) {
780
+			return true;
781
+	}
730 782
 
731 783
 	$upcontext += createToken('login');
732 784
 
@@ -740,15 +792,17 @@  discard block
 block discarded – undo
740 792
 	global $smcFunc, $db_type, $support_js;
741 793
 
742 794
 	// Don't bother if the security is disabled.
743
-	if ($disable_security)
744
-		return true;
795
+	if ($disable_security) {
796
+			return true;
797
+	}
745 798
 
746 799
 	// Are we trying to login?
747 800
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
748 801
 	{
749 802
 		// If we've disabled security pick a suitable name!
750
-		if (empty($_POST['user']))
751
-			$_POST['user'] = 'Administrator';
803
+		if (empty($_POST['user'])) {
804
+					$_POST['user'] = 'Administrator';
805
+		}
752 806
 
753 807
 		// Before 2.0 these column names were different!
754 808
 		$oldDB = false;
@@ -763,16 +817,17 @@  discard block
 block discarded – undo
763 817
 					'db_error_skip' => true,
764 818
 				)
765 819
 			);
766
-			if ($smcFunc['db_num_rows']($request) != 0)
767
-				$oldDB = true;
820
+			if ($smcFunc['db_num_rows']($request) != 0) {
821
+							$oldDB = true;
822
+			}
768 823
 			$smcFunc['db_free_result']($request);
769 824
 		}
770 825
 
771 826
 		// Get what we believe to be their details.
772 827
 		if (!$disable_security)
773 828
 		{
774
-			if ($oldDB)
775
-				$request = $smcFunc['db_query']('', '
829
+			if ($oldDB) {
830
+							$request = $smcFunc['db_query']('', '
776 831
 					SELECT id_member, memberName AS member_name, passwd, id_group,
777 832
 					additionalGroups AS additional_groups, lngfile
778 833
 					FROM {db_prefix}members
@@ -782,8 +837,8 @@  discard block
 block discarded – undo
782 837
 						'db_error_skip' => true,
783 838
 					)
784 839
 				);
785
-			else
786
-				$request = $smcFunc['db_query']('', '
840
+			} else {
841
+							$request = $smcFunc['db_query']('', '
787 842
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
788 843
 					FROM {db_prefix}members
789 844
 					WHERE member_name = {string:member_name}',
@@ -792,6 +847,7 @@  discard block
 block discarded – undo
792 847
 						'db_error_skip' => true,
793 848
 					)
794 849
 				);
850
+			}
795 851
 			if ($smcFunc['db_num_rows']($request) != 0)
796 852
 			{
797 853
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -799,16 +855,17 @@  discard block
 block discarded – undo
799 855
 				$groups = explode(',', $addGroups);
800 856
 				$groups[] = $id_group;
801 857
 
802
-				foreach ($groups as $k => $v)
803
-					$groups[$k] = (int) $v;
858
+				foreach ($groups as $k => $v) {
859
+									$groups[$k] = (int) $v;
860
+				}
804 861
 
805 862
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
806 863
 
807 864
 				// We don't use "-utf8" anymore...
808 865
 				$user_language = str_ireplace('-utf8', '', $user_language);
866
+			} else {
867
+							$upcontext['username_incorrect'] = true;
809 868
 			}
810
-			else
811
-				$upcontext['username_incorrect'] = true;
812 869
 			$smcFunc['db_free_result']($request);
813 870
 		}
814 871
 		$upcontext['username'] = $_POST['user'];
@@ -818,13 +875,14 @@  discard block
 block discarded – undo
818 875
 		{
819 876
 			$upcontext['upgrade_status']['js'] = 1;
820 877
 			$support_js = 1;
878
+		} else {
879
+					$support_js = 0;
821 880
 		}
822
-		else
823
-			$support_js = 0;
824 881
 
825 882
 		// Note down the version we are coming from.
826
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
827
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
883
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
884
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
885
+		}
828 886
 
829 887
 		// Didn't get anywhere?
830 888
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -858,15 +916,15 @@  discard block
 block discarded – undo
858 916
 							'db_error_skip' => true,
859 917
 						)
860 918
 					);
861
-					if ($smcFunc['db_num_rows']($request) == 0)
862
-						return throw_error('You need to be an admin to perform an upgrade!');
919
+					if ($smcFunc['db_num_rows']($request) == 0) {
920
+											return throw_error('You need to be an admin to perform an upgrade!');
921
+					}
863 922
 					$smcFunc['db_free_result']($request);
864 923
 				}
865 924
 
866 925
 				$upcontext['user']['id'] = $id_member;
867 926
 				$upcontext['user']['name'] = $name;
868
-			}
869
-			else
927
+			} else
870 928
 			{
871 929
 				$upcontext['user']['id'] = 1;
872 930
 				$upcontext['user']['name'] = 'Administrator';
@@ -882,11 +940,11 @@  discard block
 block discarded – undo
882 940
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
883 941
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
884 942
 
885
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
886
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
887
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
888
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
889
-				else
943
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
944
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
945
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
946
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
947
+				} else
890 948
 				{
891 949
 					// Set this as the new language.
892 950
 					$upcontext['language'] = $user_language;
@@ -930,8 +988,9 @@  discard block
 block discarded – undo
930 988
 	unset($member_columns);
931 989
 
932 990
 	// If we've not submitted then we're done.
933
-	if (empty($_POST['upcont']))
934
-		return false;
991
+	if (empty($_POST['upcont'])) {
992
+			return false;
993
+	}
935 994
 
936 995
 	// Firstly, if they're enabling SM stat collection just do it.
937 996
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -951,16 +1010,17 @@  discard block
 block discarded – undo
951 1010
 				fwrite($fp, $out);
952 1011
 
953 1012
 				$return_data = '';
954
-				while (!feof($fp))
955
-					$return_data .= fgets($fp, 128);
1013
+				while (!feof($fp)) {
1014
+									$return_data .= fgets($fp, 128);
1015
+				}
956 1016
 
957 1017
 				fclose($fp);
958 1018
 
959 1019
 				// Get the unique site ID.
960 1020
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
961 1021
 
962
-				if (!empty($ID[1]))
963
-					$smcFunc['db_insert']('replace',
1022
+				if (!empty($ID[1])) {
1023
+									$smcFunc['db_insert']('replace',
964 1024
 						$db_prefix . 'settings',
965 1025
 						array('variable' => 'string', 'value' => 'string'),
966 1026
 						array(
@@ -969,9 +1029,9 @@  discard block
 block discarded – undo
969 1029
 						),
970 1030
 						array('variable')
971 1031
 					);
1032
+				}
972 1033
 			}
973
-		}
974
-		else
1034
+		} else
975 1035
 		{
976 1036
 			$smcFunc['db_insert']('replace',
977 1037
 				$db_prefix . 'settings',
@@ -982,8 +1042,8 @@  discard block
 block discarded – undo
982 1042
 		}
983 1043
 	}
984 1044
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
985
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
986
-		$smcFunc['db_query']('', '
1045
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1046
+			$smcFunc['db_query']('', '
987 1047
 			DELETE FROM {db_prefix}settings
988 1048
 			WHERE variable = {string:enable_sm_stats}',
989 1049
 			array(
@@ -991,6 +1051,7 @@  discard block
 block discarded – undo
991 1051
 				'db_error_skip' => true,
992 1052
 			)
993 1053
 		);
1054
+	}
994 1055
 
995 1056
 	// Deleting old karma stuff?
996 1057
 	if (!empty($_POST['delete_karma']))
@@ -1005,20 +1066,22 @@  discard block
 block discarded – undo
1005 1066
 		);
1006 1067
 
1007 1068
 		// Cleaning up old karma member settings.
1008
-		if ($upcontext['karma_installed']['good'])
1009
-			$smcFunc['db_query']('', '
1069
+		if ($upcontext['karma_installed']['good']) {
1070
+					$smcFunc['db_query']('', '
1010 1071
 				ALTER TABLE {db_prefix}members
1011 1072
 				DROP karma_good',
1012 1073
 				array()
1013 1074
 			);
1075
+		}
1014 1076
 
1015 1077
 		// Does karma bad was enable?
1016
-		if ($upcontext['karma_installed']['bad'])
1017
-			$smcFunc['db_query']('', '
1078
+		if ($upcontext['karma_installed']['bad']) {
1079
+					$smcFunc['db_query']('', '
1018 1080
 				ALTER TABLE {db_prefix}members
1019 1081
 				DROP karma_bad',
1020 1082
 				array()
1021 1083
 			);
1084
+		}
1022 1085
 
1023 1086
 		// Cleaning up old karma permissions.
1024 1087
 		$smcFunc['db_query']('', '
@@ -1031,26 +1094,29 @@  discard block
 block discarded – undo
1031 1094
 	}
1032 1095
 
1033 1096
 	// Emptying the error log?
1034
-	if (!empty($_POST['empty_error']))
1035
-		$smcFunc['db_query']('truncate_table', '
1097
+	if (!empty($_POST['empty_error'])) {
1098
+			$smcFunc['db_query']('truncate_table', '
1036 1099
 			TRUNCATE {db_prefix}log_errors',
1037 1100
 			array(
1038 1101
 			)
1039 1102
 		);
1103
+	}
1040 1104
 
1041 1105
 	$changes = array();
1042 1106
 
1043 1107
 	// Add proxy settings.
1044
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1045
-		$changes += array(
1108
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1109
+			$changes += array(
1046 1110
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1047 1111
 			'image_proxy_maxsize' => 5190,
1048 1112
 			'image_proxy_enabled' => 0,
1049 1113
 		);
1114
+	}
1050 1115
 
1051 1116
 	// If we're overriding the language follow it through.
1052
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1053
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1117
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1118
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1119
+	}
1054 1120
 
1055 1121
 	if (!empty($_POST['maint']))
1056 1122
 	{
@@ -1062,30 +1128,34 @@  discard block
 block discarded – undo
1062 1128
 		{
1063 1129
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1064 1130
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1065
-		}
1066
-		else
1131
+		} else
1067 1132
 		{
1068 1133
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1069 1134
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1070 1135
 		}
1071 1136
 	}
1072 1137
 
1073
-	if ($command_line)
1074
-		echo ' * Updating Settings.php...';
1138
+	if ($command_line) {
1139
+			echo ' * Updating Settings.php...';
1140
+	}
1075 1141
 
1076 1142
 	// Fix some old paths.
1077
-	if (substr($boarddir, 0, 1) == '.')
1078
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1143
+	if (substr($boarddir, 0, 1) == '.') {
1144
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1145
+	}
1079 1146
 
1080
-	if (substr($sourcedir, 0, 1) == '.')
1081
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1147
+	if (substr($sourcedir, 0, 1) == '.') {
1148
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1149
+	}
1082 1150
 
1083
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1084
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1151
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1152
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1153
+	}
1085 1154
 
1086 1155
 	// Not had the database type added before?
1087
-	if (empty($db_type))
1088
-		$changes['db_type'] = 'mysql';
1156
+	if (empty($db_type)) {
1157
+			$changes['db_type'] = 'mysql';
1158
+	}
1089 1159
 
1090 1160
 	// If they have a "host:port" setup for the host, split that into separate values
1091 1161
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1096,32 +1166,36 @@  discard block
 block discarded – undo
1096 1166
 		$changes['db_server'] = '\'' . $db_server . '\'';
1097 1167
 
1098 1168
 		// Only set this if we're not using the default port
1099
-		if ($db_port != ini_get('mysqli.default_port'))
1100
-			$changes['db_port'] = (int) $db_port;
1101
-	}
1102
-	elseif (!empty($db_port))
1169
+		if ($db_port != ini_get('mysqli.default_port')) {
1170
+					$changes['db_port'] = (int) $db_port;
1171
+		}
1172
+	} elseif (!empty($db_port))
1103 1173
 	{
1104 1174
 		// If db_port is set and is the same as the default, set it to ''
1105 1175
 		if ($db_type == 'mysql')
1106 1176
 		{
1107
-			if ($db_port == ini_get('mysqli.default_port'))
1108
-				$changes['db_port'] = '\'\'';
1109
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1110
-				$changes['db_port'] = '\'\'';
1177
+			if ($db_port == ini_get('mysqli.default_port')) {
1178
+							$changes['db_port'] = '\'\'';
1179
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1180
+							$changes['db_port'] = '\'\'';
1181
+			}
1111 1182
 		}
1112 1183
 	}
1113 1184
 
1114 1185
 	// Maybe we haven't had this option yet?
1115
-	if (empty($packagesdir))
1116
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1186
+	if (empty($packagesdir)) {
1187
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1188
+	}
1117 1189
 
1118 1190
 	// Add support for $tasksdir var.
1119
-	if (empty($tasksdir))
1120
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1191
+	if (empty($tasksdir)) {
1192
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1193
+	}
1121 1194
 
1122 1195
 	// Make sure we fix the language as well.
1123
-	if (stristr($language, '-utf8'))
1124
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1196
+	if (stristr($language, '-utf8')) {
1197
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1198
+	}
1125 1199
 
1126 1200
 	// @todo Maybe change the cookie name if going to 1.1, too?
1127 1201
 
@@ -1129,8 +1203,9 @@  discard block
 block discarded – undo
1129 1203
 	require_once($sourcedir . '/Subs-Admin.php');
1130 1204
 	updateSettingsFile($changes);
1131 1205
 
1132
-	if ($command_line)
1133
-		echo ' Successful.' . "\n";
1206
+	if ($command_line) {
1207
+			echo ' Successful.' . "\n";
1208
+	}
1134 1209
 
1135 1210
 	// Are we doing debug?
1136 1211
 	if (isset($_POST['debug']))
@@ -1140,8 +1215,9 @@  discard block
 block discarded – undo
1140 1215
 	}
1141 1216
 
1142 1217
 	// If we're not backing up then jump one.
1143
-	if (empty($_POST['backup']))
1144
-		$upcontext['current_step']++;
1218
+	if (empty($_POST['backup'])) {
1219
+			$upcontext['current_step']++;
1220
+	}
1145 1221
 
1146 1222
 	// If we've got here then let's proceed to the next step!
1147 1223
 	return true;
@@ -1156,8 +1232,9 @@  discard block
 block discarded – undo
1156 1232
 	$upcontext['page_title'] = 'Backup Database';
1157 1233
 
1158 1234
 	// Done it already - js wise?
1159
-	if (!empty($_POST['backup_done']))
1160
-		return true;
1235
+	if (!empty($_POST['backup_done'])) {
1236
+			return true;
1237
+	}
1161 1238
 
1162 1239
 	// Some useful stuff here.
1163 1240
 	db_extend();
@@ -1171,9 +1248,10 @@  discard block
 block discarded – undo
1171 1248
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1172 1249
 
1173 1250
 	$table_names = array();
1174
-	foreach ($tables as $table)
1175
-		if (substr($table, 0, 7) !== 'backup_')
1251
+	foreach ($tables as $table) {
1252
+			if (substr($table, 0, 7) !== 'backup_')
1176 1253
 			$table_names[] = $table;
1254
+	}
1177 1255
 
1178 1256
 	$upcontext['table_count'] = count($table_names);
1179 1257
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1183,12 +1261,14 @@  discard block
 block discarded – undo
1183 1261
 	$file_steps = $upcontext['table_count'];
1184 1262
 
1185 1263
 	// What ones have we already done?
1186
-	foreach ($table_names as $id => $table)
1187
-		if ($id < $_GET['substep'])
1264
+	foreach ($table_names as $id => $table) {
1265
+			if ($id < $_GET['substep'])
1188 1266
 			$upcontext['previous_tables'][] = $table;
1267
+	}
1189 1268
 
1190
-	if ($command_line)
1191
-		echo 'Backing Up Tables.';
1269
+	if ($command_line) {
1270
+			echo 'Backing Up Tables.';
1271
+	}
1192 1272
 
1193 1273
 	// If we don't support javascript we backup here.
1194 1274
 	if (!$support_js || isset($_GET['xml']))
@@ -1207,8 +1287,9 @@  discard block
 block discarded – undo
1207 1287
 			backupTable($table_names[$substep]);
1208 1288
 
1209 1289
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1210
-			if (isset($_GET['xml']))
1211
-				return upgradeExit();
1290
+			if (isset($_GET['xml'])) {
1291
+							return upgradeExit();
1292
+			}
1212 1293
 		}
1213 1294
 
1214 1295
 		if ($command_line)
@@ -1241,9 +1322,10 @@  discard block
 block discarded – undo
1241 1322
 
1242 1323
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1243 1324
 
1244
-	if ($command_line)
1245
-		echo ' done.';
1246
-}
1325
+	if ($command_line) {
1326
+			echo ' done.';
1327
+	}
1328
+	}
1247 1329
 
1248 1330
 // Step 2: Everything.
1249 1331
 function DatabaseChanges()
@@ -1252,8 +1334,9 @@  discard block
 block discarded – undo
1252 1334
 	global $upcontext, $support_js, $db_type;
1253 1335
 
1254 1336
 	// Have we just completed this?
1255
-	if (!empty($_POST['database_done']))
1256
-		return true;
1337
+	if (!empty($_POST['database_done'])) {
1338
+			return true;
1339
+	}
1257 1340
 
1258 1341
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1259 1342
 	$upcontext['page_title'] = 'Database Changes';
@@ -1268,15 +1351,16 @@  discard block
 block discarded – undo
1268 1351
 	);
1269 1352
 
1270 1353
 	// How many files are there in total?
1271
-	if (isset($_GET['filecount']))
1272
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1273
-	else
1354
+	if (isset($_GET['filecount'])) {
1355
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1356
+	} else
1274 1357
 	{
1275 1358
 		$upcontext['file_count'] = 0;
1276 1359
 		foreach ($files as $file)
1277 1360
 		{
1278
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1279
-				$upcontext['file_count']++;
1361
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1362
+							$upcontext['file_count']++;
1363
+			}
1280 1364
 		}
1281 1365
 	}
1282 1366
 
@@ -1286,9 +1370,9 @@  discard block
 block discarded – undo
1286 1370
 	$upcontext['cur_file_num'] = 0;
1287 1371
 	foreach ($files as $file)
1288 1372
 	{
1289
-		if ($did_not_do)
1290
-			$did_not_do--;
1291
-		else
1373
+		if ($did_not_do) {
1374
+					$did_not_do--;
1375
+		} else
1292 1376
 		{
1293 1377
 			$upcontext['cur_file_num']++;
1294 1378
 			$upcontext['cur_file_name'] = $file[0];
@@ -1315,12 +1399,13 @@  discard block
 block discarded – undo
1315 1399
 					// Flag to move on to the next.
1316 1400
 					$upcontext['completed_step'] = true;
1317 1401
 					// Did we complete the whole file?
1318
-					if ($nextFile)
1319
-						$upcontext['current_debug_item_num'] = -1;
1402
+					if ($nextFile) {
1403
+											$upcontext['current_debug_item_num'] = -1;
1404
+					}
1320 1405
 					return upgradeExit();
1406
+				} elseif ($support_js) {
1407
+									break;
1321 1408
 				}
1322
-				elseif ($support_js)
1323
-					break;
1324 1409
 			}
1325 1410
 			// Set the progress bar to be right as if we had - even if we hadn't...
1326 1411
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1345,8 +1430,9 @@  discard block
 block discarded – undo
1345 1430
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1346 1431
 
1347 1432
 	// Now it's nice to have some of the basic SMF source files.
1348
-	if (!isset($_GET['ssi']) && !$command_line)
1349
-		redirectLocation('&ssi=1');
1433
+	if (!isset($_GET['ssi']) && !$command_line) {
1434
+			redirectLocation('&ssi=1');
1435
+	}
1350 1436
 
1351 1437
 	$upcontext['sub_template'] = 'upgrade_complete';
1352 1438
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1362,14 +1448,16 @@  discard block
 block discarded – undo
1362 1448
 	// Are we in maintenance mode?
1363 1449
 	if (isset($upcontext['user']['main']))
1364 1450
 	{
1365
-		if ($command_line)
1366
-			echo ' * ';
1451
+		if ($command_line) {
1452
+					echo ' * ';
1453
+		}
1367 1454
 		$upcontext['removed_maintenance'] = true;
1368 1455
 		$changes['maintenance'] = $upcontext['user']['main'];
1369 1456
 	}
1370 1457
 	// Otherwise if somehow we are in 2 let's go to 1.
1371
-	elseif (!empty($maintenance) && $maintenance == 2)
1372
-		$changes['maintenance'] = 1;
1458
+	elseif (!empty($maintenance) && $maintenance == 2) {
1459
+			$changes['maintenance'] = 1;
1460
+	}
1373 1461
 
1374 1462
 	// Wipe this out...
1375 1463
 	$upcontext['user'] = array();
@@ -1384,9 +1472,9 @@  discard block
 block discarded – undo
1384 1472
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1385 1473
 
1386 1474
 	// Now is the perfect time to fetch the SM files.
1387
-	if ($command_line)
1388
-		cli_scheduled_fetchSMfiles();
1389
-	else
1475
+	if ($command_line) {
1476
+			cli_scheduled_fetchSMfiles();
1477
+	} else
1390 1478
 	{
1391 1479
 		require_once($sourcedir . '/ScheduledTasks.php');
1392 1480
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1394,8 +1482,9 @@  discard block
 block discarded – undo
1394 1482
 	}
1395 1483
 
1396 1484
 	// Log what we've done.
1397
-	if (empty($user_info['id']))
1398
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1485
+	if (empty($user_info['id'])) {
1486
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1487
+	}
1399 1488
 
1400 1489
 	// Log the action manually, so CLI still works.
1401 1490
 	$smcFunc['db_insert']('',
@@ -1414,8 +1503,9 @@  discard block
 block discarded – undo
1414 1503
 
1415 1504
 	// Save the current database version.
1416 1505
 	$server_version = $smcFunc['db_server_info']();
1417
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1418
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1506
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1507
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1508
+	}
1419 1509
 
1420 1510
 	if ($command_line)
1421 1511
 	{
@@ -1427,8 +1517,9 @@  discard block
 block discarded – undo
1427 1517
 
1428 1518
 	// Make sure it says we're done.
1429 1519
 	$upcontext['overall_percent'] = 100;
1430
-	if (isset($upcontext['step_progress']))
1431
-		unset($upcontext['step_progress']);
1520
+	if (isset($upcontext['step_progress'])) {
1521
+			unset($upcontext['step_progress']);
1522
+	}
1432 1523
 
1433 1524
 	$_GET['substep'] = 0;
1434 1525
 	return false;
@@ -1439,8 +1530,9 @@  discard block
 block discarded – undo
1439 1530
 {
1440 1531
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1441 1532
 
1442
-	if (empty($modSettings['time_format']))
1443
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1533
+	if (empty($modSettings['time_format'])) {
1534
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1535
+	}
1444 1536
 
1445 1537
 	// What files do we want to get
1446 1538
 	$request = $smcFunc['db_query']('', '
@@ -1474,8 +1566,9 @@  discard block
 block discarded – undo
1474 1566
 		$file_data = fetch_web_data($url);
1475 1567
 
1476 1568
 		// If we got an error - give up - the site might be down.
1477
-		if ($file_data === false)
1478
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1569
+		if ($file_data === false) {
1570
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1571
+		}
1479 1572
 
1480 1573
 		// Save the file to the database.
1481 1574
 		$smcFunc['db_query']('substring', '
@@ -1517,8 +1610,9 @@  discard block
 block discarded – undo
1517 1610
 	$themeData = array();
1518 1611
 	foreach ($values as $variable => $value)
1519 1612
 	{
1520
-		if (!isset($value) || $value === null)
1521
-			$value = 0;
1613
+		if (!isset($value) || $value === null) {
1614
+					$value = 0;
1615
+		}
1522 1616
 
1523 1617
 		$themeData[] = array(0, 1, $variable, $value);
1524 1618
 	}
@@ -1547,8 +1641,9 @@  discard block
 block discarded – undo
1547 1641
 
1548 1642
 	foreach ($values as $variable => $value)
1549 1643
 	{
1550
-		if (empty($modSettings[$value[0]]))
1551
-			continue;
1644
+		if (empty($modSettings[$value[0]])) {
1645
+					continue;
1646
+		}
1552 1647
 
1553 1648
 		$smcFunc['db_query']('', '
1554 1649
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1634,19 +1729,21 @@  discard block
 block discarded – undo
1634 1729
 	set_error_handler(
1635 1730
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1636 1731
 		{
1637
-			if ($support_js)
1638
-				return true;
1639
-			else
1640
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1732
+			if ($support_js) {
1733
+							return true;
1734
+			} else {
1735
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1736
+			}
1641 1737
 		}
1642 1738
 	);
1643 1739
 
1644 1740
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1645 1741
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1646
-	if ($db_type == 'mysql')
1647
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1648
-	else
1649
-		$db_collation = '';
1742
+	if ($db_type == 'mysql') {
1743
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1744
+	} else {
1745
+			$db_collation = '';
1746
+	}
1650 1747
 
1651 1748
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1652 1749
 
@@ -1658,8 +1755,9 @@  discard block
 block discarded – undo
1658 1755
 	$last_step = '';
1659 1756
 
1660 1757
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1661
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1662
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1758
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1759
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1760
+	}
1663 1761
 
1664 1762
 	// Count the total number of steps within this file - for progress.
1665 1763
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1679,15 +1777,18 @@  discard block
 block discarded – undo
1679 1777
 		$do_current = $substep >= $_GET['substep'];
1680 1778
 
1681 1779
 		// Get rid of any comments in the beginning of the line...
1682
-		if (substr(trim($line), 0, 2) === '/*')
1683
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1780
+		if (substr(trim($line), 0, 2) === '/*') {
1781
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1782
+		}
1684 1783
 
1685 1784
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1686
-		if ($is_debug && !$support_js && $command_line)
1687
-			flush();
1785
+		if ($is_debug && !$support_js && $command_line) {
1786
+					flush();
1787
+		}
1688 1788
 
1689
-		if (trim($line) === '')
1690
-			continue;
1789
+		if (trim($line) === '') {
1790
+					continue;
1791
+		}
1691 1792
 
1692 1793
 		if (trim(substr($line, 0, 3)) === '---')
1693 1794
 		{
@@ -1697,8 +1798,9 @@  discard block
 block discarded – undo
1697 1798
 			if (trim($current_data) != '' && $type !== '}')
1698 1799
 			{
1699 1800
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1700
-				if ($command_line)
1701
-					echo $upcontext['error_message'];
1801
+				if ($command_line) {
1802
+									echo $upcontext['error_message'];
1803
+				}
1702 1804
 			}
1703 1805
 
1704 1806
 			if ($type == ' ')
@@ -1716,17 +1818,18 @@  discard block
 block discarded – undo
1716 1818
 				if ($do_current)
1717 1819
 				{
1718 1820
 					$upcontext['actioned_items'][] = $last_step;
1719
-					if ($command_line)
1720
-						echo ' * ';
1821
+					if ($command_line) {
1822
+											echo ' * ';
1823
+					}
1721 1824
 				}
1722
-			}
1723
-			elseif ($type == '#')
1825
+			} elseif ($type == '#')
1724 1826
 			{
1725 1827
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1726 1828
 
1727 1829
 				$upcontext['current_debug_item_num']++;
1728
-				if (trim($line) != '---#')
1729
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1830
+				if (trim($line) != '---#') {
1831
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1832
+				}
1730 1833
 
1731 1834
 				// Have we already done something?
1732 1835
 				if (isset($_GET['xml']) && $done_something)
@@ -1737,34 +1840,36 @@  discard block
 block discarded – undo
1737 1840
 
1738 1841
 				if ($do_current)
1739 1842
 				{
1740
-					if (trim($line) == '---#' && $command_line)
1741
-						echo ' done.', $endl;
1742
-					elseif ($command_line)
1743
-						echo ' +++ ', rtrim(substr($line, 4));
1744
-					elseif (trim($line) != '---#')
1843
+					if (trim($line) == '---#' && $command_line) {
1844
+											echo ' done.', $endl;
1845
+					} elseif ($command_line) {
1846
+											echo ' +++ ', rtrim(substr($line, 4));
1847
+					} elseif (trim($line) != '---#')
1745 1848
 					{
1746
-						if ($is_debug)
1747
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1849
+						if ($is_debug) {
1850
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1851
+						}
1748 1852
 					}
1749 1853
 				}
1750 1854
 
1751 1855
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1752 1856
 				{
1753
-					if ($command_line)
1754
-						echo ' * ';
1755
-					else
1756
-						$upcontext['actioned_items'][] = $last_step;
1857
+					if ($command_line) {
1858
+											echo ' * ';
1859
+					} else {
1860
+											$upcontext['actioned_items'][] = $last_step;
1861
+					}
1757 1862
 				}
1758 1863
 
1759 1864
 				// Small step - only if we're actually doing stuff.
1760
-				if ($do_current)
1761
-					nextSubstep(++$substep);
1762
-				else
1763
-					$substep++;
1764
-			}
1765
-			elseif ($type == '{')
1766
-				$current_type = 'code';
1767
-			elseif ($type == '}')
1865
+				if ($do_current) {
1866
+									nextSubstep(++$substep);
1867
+				} else {
1868
+									$substep++;
1869
+				}
1870
+			} elseif ($type == '{') {
1871
+							$current_type = 'code';
1872
+			} elseif ($type == '}')
1768 1873
 			{
1769 1874
 				$current_type = 'sql';
1770 1875
 
@@ -1777,8 +1882,9 @@  discard block
 block discarded – undo
1777 1882
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1778 1883
 				{
1779 1884
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1780
-					if ($command_line)
1781
-						echo $upcontext['error_message'];
1885
+					if ($command_line) {
1886
+											echo $upcontext['error_message'];
1887
+					}
1782 1888
 				}
1783 1889
 
1784 1890
 				// Done with code!
@@ -1858,8 +1964,9 @@  discard block
 block discarded – undo
1858 1964
 	$db_unbuffered = false;
1859 1965
 
1860 1966
 	// Failure?!
1861
-	if ($result !== false)
1862
-		return $result;
1967
+	if ($result !== false) {
1968
+			return $result;
1969
+	}
1863 1970
 
1864 1971
 	$db_error_message = $smcFunc['db_error']($db_connection);
1865 1972
 	// If MySQL we do something more clever.
@@ -1887,54 +1994,61 @@  discard block
 block discarded – undo
1887 1994
 			{
1888 1995
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1889 1996
 				$result = mysqli_query($db_connection, $string);
1890
-				if ($result !== false)
1891
-					return $result;
1997
+				if ($result !== false) {
1998
+									return $result;
1999
+				}
1892 2000
 			}
1893
-		}
1894
-		elseif ($mysqli_errno == 2013)
2001
+		} elseif ($mysqli_errno == 2013)
1895 2002
 		{
1896 2003
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1897 2004
 			mysqli_select_db($db_connection, $db_name);
1898 2005
 			if ($db_connection)
1899 2006
 			{
1900 2007
 				$result = mysqli_query($db_connection, $string);
1901
-				if ($result !== false)
1902
-					return $result;
2008
+				if ($result !== false) {
2009
+									return $result;
2010
+				}
1903 2011
 			}
1904 2012
 		}
1905 2013
 		// Duplicate column name... should be okay ;).
1906
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1907
-			return false;
2014
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2015
+					return false;
2016
+		}
1908 2017
 		// Duplicate insert... make sure it's the proper type of query ;).
1909
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1910
-			return false;
2018
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2019
+					return false;
2020
+		}
1911 2021
 		// Creating an index on a non-existent column.
1912
-		elseif ($mysqli_errno == 1072)
1913
-			return false;
1914
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1915
-			return false;
2022
+		elseif ($mysqli_errno == 1072) {
2023
+					return false;
2024
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2025
+					return false;
2026
+		}
1916 2027
 	}
1917 2028
 	// If a table already exists don't go potty.
1918 2029
 	else
1919 2030
 	{
1920 2031
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1921 2032
 		{
1922
-			if (strpos($db_error_message, 'exist') !== false)
1923
-				return true;
1924
-		}
1925
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2033
+			if (strpos($db_error_message, 'exist') !== false) {
2034
+							return true;
2035
+			}
2036
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1926 2037
 		{
1927
-			if (strpos($db_error_message, 'duplicate') !== false)
1928
-				return true;
2038
+			if (strpos($db_error_message, 'duplicate') !== false) {
2039
+							return true;
2040
+			}
1929 2041
 		}
1930 2042
 	}
1931 2043
 
1932 2044
 	// Get the query string so we pass everything.
1933 2045
 	$query_string = '';
1934
-	foreach ($_GET as $k => $v)
1935
-		$query_string .= ';' . $k . '=' . $v;
1936
-	if (strlen($query_string) != 0)
1937
-		$query_string = '?' . substr($query_string, 1);
2046
+	foreach ($_GET as $k => $v) {
2047
+			$query_string .= ';' . $k . '=' . $v;
2048
+	}
2049
+	if (strlen($query_string) != 0) {
2050
+			$query_string = '?' . substr($query_string, 1);
2051
+	}
1938 2052
 
1939 2053
 	if ($command_line)
1940 2054
 	{
@@ -1989,16 +2103,18 @@  discard block
 block discarded – undo
1989 2103
 			{
1990 2104
 				$found |= 1;
1991 2105
 				// Do some checks on the data if we have it set.
1992
-				if (isset($change['col_type']))
1993
-					$found &= $change['col_type'] === $column['type'];
1994
-				if (isset($change['null_allowed']))
1995
-					$found &= $column['null'] == $change['null_allowed'];
1996
-				if (isset($change['default']))
1997
-					$found &= $change['default'] === $column['default'];
2106
+				if (isset($change['col_type'])) {
2107
+									$found &= $change['col_type'] === $column['type'];
2108
+				}
2109
+				if (isset($change['null_allowed'])) {
2110
+									$found &= $column['null'] == $change['null_allowed'];
2111
+				}
2112
+				if (isset($change['default'])) {
2113
+									$found &= $change['default'] === $column['default'];
2114
+				}
1998 2115
 			}
1999 2116
 		}
2000
-	}
2001
-	elseif ($change['type'] === 'index')
2117
+	} elseif ($change['type'] === 'index')
2002 2118
 	{
2003 2119
 		$request = upgrade_query('
2004 2120
 			SHOW INDEX
@@ -2007,9 +2123,10 @@  discard block
 block discarded – undo
2007 2123
 		{
2008 2124
 			$cur_index = array();
2009 2125
 
2010
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2011
-				if ($row['Key_name'] === $change['name'])
2126
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2127
+							if ($row['Key_name'] === $change['name'])
2012 2128
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2129
+			}
2013 2130
 
2014 2131
 			ksort($cur_index, SORT_NUMERIC);
2015 2132
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2019,14 +2136,17 @@  discard block
 block discarded – undo
2019 2136
 	}
2020 2137
 
2021 2138
 	// If we're trying to add and it's added, we're done.
2022
-	if ($found && in_array($change['method'], array('add', 'change')))
2023
-		return true;
2139
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2140
+			return true;
2141
+	}
2024 2142
 	// Otherwise if we're removing and it wasn't found we're also done.
2025
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2026
-		return true;
2143
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2144
+			return true;
2145
+	}
2027 2146
 	// Otherwise is it just a test?
2028
-	elseif ($is_test)
2029
-		return false;
2147
+	elseif ($is_test) {
2148
+			return false;
2149
+	}
2030 2150
 
2031 2151
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2032 2152
 	$running = false;
@@ -2037,8 +2157,9 @@  discard block
 block discarded – undo
2037 2157
 			SHOW FULL PROCESSLIST');
2038 2158
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2039 2159
 		{
2040
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2041
-				$found = true;
2160
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2161
+							$found = true;
2162
+			}
2042 2163
 		}
2043 2164
 
2044 2165
 		// Can't find it? Then we need to run it fools!
@@ -2050,8 +2171,9 @@  discard block
 block discarded – undo
2050 2171
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2051 2172
 				' . $change['text'], true) !== false;
2052 2173
 
2053
-			if (!$success)
2054
-				return false;
2174
+			if (!$success) {
2175
+							return false;
2176
+			}
2055 2177
 
2056 2178
 			// Return
2057 2179
 			$running = true;
@@ -2093,8 +2215,9 @@  discard block
 block discarded – undo
2093 2215
 			'db_error_skip' => true,
2094 2216
 		)
2095 2217
 	);
2096
-	if ($smcFunc['db_num_rows']($request) === 0)
2097
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2218
+	if ($smcFunc['db_num_rows']($request) === 0) {
2219
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2220
+	}
2098 2221
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2099 2222
 	$smcFunc['db_free_result']($request);
2100 2223
 
@@ -2116,18 +2239,19 @@  discard block
 block discarded – undo
2116 2239
 			)
2117 2240
 		);
2118 2241
 		// No results? Just forget it all together.
2119
-		if ($smcFunc['db_num_rows']($request) === 0)
2120
-			unset($table_row['Collation']);
2121
-		else
2122
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2242
+		if ($smcFunc['db_num_rows']($request) === 0) {
2243
+					unset($table_row['Collation']);
2244
+		} else {
2245
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2246
+		}
2123 2247
 		$smcFunc['db_free_result']($request);
2124 2248
 	}
2125 2249
 
2126 2250
 	if ($column_fix)
2127 2251
 	{
2128 2252
 		// Make sure there are no NULL's left.
2129
-		if ($null_fix)
2130
-			$smcFunc['db_query']('', '
2253
+		if ($null_fix) {
2254
+					$smcFunc['db_query']('', '
2131 2255
 				UPDATE {db_prefix}' . $change['table'] . '
2132 2256
 				SET ' . $change['column'] . ' = {string:default}
2133 2257
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2136,6 +2260,7 @@  discard block
 block discarded – undo
2136 2260
 					'db_error_skip' => true,
2137 2261
 				)
2138 2262
 			);
2263
+		}
2139 2264
 
2140 2265
 		// Do the actual alteration.
2141 2266
 		$smcFunc['db_query']('', '
@@ -2164,8 +2289,9 @@  discard block
 block discarded – undo
2164 2289
 	}
2165 2290
 
2166 2291
 	// Not a column we need to check on?
2167
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2168
-		return;
2292
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2293
+			return;
2294
+	}
2169 2295
 
2170 2296
 	// Break it up you (six|seven).
2171 2297
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2184,13 +2310,13 @@  discard block
 block discarded – undo
2184 2310
 				'new_name' => $temp[2],
2185 2311
 		));
2186 2312
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2187
-		if ($smcFunc['db_num_rows'] != 1)
2188
-			return;
2313
+		if ($smcFunc['db_num_rows'] != 1) {
2314
+					return;
2315
+		}
2189 2316
 
2190 2317
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2191 2318
 		$smcFunc['db_free_result']($request);
2192
-	}
2193
-	else
2319
+	} else
2194 2320
 	{
2195 2321
 		// Do this the old fashion, sure method way.
2196 2322
 		$request = $smcFunc['db_query']('', '
@@ -2201,21 +2327,24 @@  discard block
 block discarded – undo
2201 2327
 		));
2202 2328
 		// Mayday!
2203 2329
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2204
-		if ($smcFunc['db_num_rows'] == 0)
2205
-			return;
2330
+		if ($smcFunc['db_num_rows'] == 0) {
2331
+					return;
2332
+		}
2206 2333
 
2207 2334
 		// Oh where, oh where has my little field gone. Oh where can it be...
2208
-		while ($row = $smcFunc['db_query']($request))
2209
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2335
+		while ($row = $smcFunc['db_query']($request)) {
2336
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2210 2337
 			{
2211 2338
 				$current_type = $row['Type'];
2339
+		}
2212 2340
 				break;
2213 2341
 			}
2214 2342
 	}
2215 2343
 
2216 2344
 	// If this doesn't match, the column may of been altered for a reason.
2217
-	if (trim($current_type) != trim($temp[3]))
2218
-		$temp[3] = $current_type;
2345
+	if (trim($current_type) != trim($temp[3])) {
2346
+			$temp[3] = $current_type;
2347
+	}
2219 2348
 
2220 2349
 	// Piece this back together.
2221 2350
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2227,8 +2356,9 @@  discard block
 block discarded – undo
2227 2356
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2228 2357
 	global $step_progress, $is_debug, $upcontext;
2229 2358
 
2230
-	if ($_GET['substep'] < $substep)
2231
-		$_GET['substep'] = $substep;
2359
+	if ($_GET['substep'] < $substep) {
2360
+			$_GET['substep'] = $substep;
2361
+	}
2232 2362
 
2233 2363
 	if ($command_line)
2234 2364
 	{
@@ -2241,29 +2371,33 @@  discard block
 block discarded – undo
2241 2371
 	}
2242 2372
 
2243 2373
 	@set_time_limit(300);
2244
-	if (function_exists('apache_reset_timeout'))
2245
-		@apache_reset_timeout();
2374
+	if (function_exists('apache_reset_timeout')) {
2375
+			@apache_reset_timeout();
2376
+	}
2246 2377
 
2247
-	if (time() - $start_time <= $timeLimitThreshold)
2248
-		return;
2378
+	if (time() - $start_time <= $timeLimitThreshold) {
2379
+			return;
2380
+	}
2249 2381
 
2250 2382
 	// Do we have some custom step progress stuff?
2251 2383
 	if (!empty($step_progress))
2252 2384
 	{
2253 2385
 		$upcontext['substep_progress'] = 0;
2254 2386
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2255
-		if ($step_progress['current'] > $step_progress['total'])
2256
-			$upcontext['substep_progress'] = 99.9;
2257
-		else
2258
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2387
+		if ($step_progress['current'] > $step_progress['total']) {
2388
+					$upcontext['substep_progress'] = 99.9;
2389
+		} else {
2390
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2391
+		}
2259 2392
 
2260 2393
 		// Make it nicely rounded.
2261 2394
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2262 2395
 	}
2263 2396
 
2264 2397
 	// If this is XML we just exit right away!
2265
-	if (isset($_GET['xml']))
2266
-		return upgradeExit();
2398
+	if (isset($_GET['xml'])) {
2399
+			return upgradeExit();
2400
+	}
2267 2401
 
2268 2402
 	// We're going to pause after this!
2269 2403
 	$upcontext['pause'] = true;
@@ -2271,13 +2405,15 @@  discard block
 block discarded – undo
2271 2405
 	$upcontext['query_string'] = '';
2272 2406
 	foreach ($_GET as $k => $v)
2273 2407
 	{
2274
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2275
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2408
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2409
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2410
+		}
2276 2411
 	}
2277 2412
 
2278 2413
 	// Custom warning?
2279
-	if (!empty($custom_warning))
2280
-		$upcontext['custom_warning'] = $custom_warning;
2414
+	if (!empty($custom_warning)) {
2415
+			$upcontext['custom_warning'] = $custom_warning;
2416
+	}
2281 2417
 
2282 2418
 	upgradeExit();
2283 2419
 }
@@ -2292,25 +2428,26 @@  discard block
 block discarded – undo
2292 2428
 	ob_implicit_flush(true);
2293 2429
 	@set_time_limit(600);
2294 2430
 
2295
-	if (!isset($_SERVER['argv']))
2296
-		$_SERVER['argv'] = array();
2431
+	if (!isset($_SERVER['argv'])) {
2432
+			$_SERVER['argv'] = array();
2433
+	}
2297 2434
 	$_GET['maint'] = 1;
2298 2435
 
2299 2436
 	foreach ($_SERVER['argv'] as $i => $arg)
2300 2437
 	{
2301
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2302
-			$_GET['lang'] = $match[1];
2303
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2304
-			continue;
2305
-		elseif ($arg == '--no-maintenance')
2306
-			$_GET['maint'] = 0;
2307
-		elseif ($arg == '--debug')
2308
-			$is_debug = true;
2309
-		elseif ($arg == '--backup')
2310
-			$_POST['backup'] = 1;
2311
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2312
-			$_GET['conv'] = 1;
2313
-		elseif ($i != 0)
2438
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2439
+					$_GET['lang'] = $match[1];
2440
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2441
+					continue;
2442
+		} elseif ($arg == '--no-maintenance') {
2443
+					$_GET['maint'] = 0;
2444
+		} elseif ($arg == '--debug') {
2445
+					$is_debug = true;
2446
+		} elseif ($arg == '--backup') {
2447
+					$_POST['backup'] = 1;
2448
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2449
+					$_GET['conv'] = 1;
2450
+		} elseif ($i != 0)
2314 2451
 		{
2315 2452
 			echo 'SMF Command-line Upgrader
2316 2453
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2324,10 +2461,12 @@  discard block
 block discarded – undo
2324 2461
 		}
2325 2462
 	}
2326 2463
 
2327
-	if (!php_version_check())
2328
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2329
-	if (!db_version_check())
2330
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2464
+	if (!php_version_check()) {
2465
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2466
+	}
2467
+	if (!db_version_check()) {
2468
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2469
+	}
2331 2470
 
2332 2471
 	// Do some checks to make sure they have proper privileges
2333 2472
 	db_extend('packages');
@@ -2342,34 +2481,39 @@  discard block
 block discarded – undo
2342 2481
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2343 2482
 
2344 2483
 	// Sorry... we need CREATE, ALTER and DROP
2345
-	if (!$create || !$alter || !$drop)
2346
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2484
+	if (!$create || !$alter || !$drop) {
2485
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2486
+	}
2347 2487
 
2348 2488
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2349 2489
 		&& @file_exists($sourcedir . '/QueryString.php')
2350 2490
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2351
-	if (!$check && !isset($modSettings['smfVersion']))
2352
-		print_error('Error: Some files are missing or out-of-date.', true);
2491
+	if (!$check && !isset($modSettings['smfVersion'])) {
2492
+			print_error('Error: Some files are missing or out-of-date.', true);
2493
+	}
2353 2494
 
2354 2495
 	// Do a quick version spot check.
2355 2496
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2356 2497
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2357
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2358
-		print_error('Error: Some files have not yet been updated properly.');
2498
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2499
+			print_error('Error: Some files have not yet been updated properly.');
2500
+	}
2359 2501
 
2360 2502
 	// Make sure Settings.php is writable.
2361 2503
 		quickFileWritable($boarddir . '/Settings.php');
2362
-	if (!is_writable($boarddir . '/Settings.php'))
2363
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2504
+	if (!is_writable($boarddir . '/Settings.php')) {
2505
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2506
+	}
2364 2507
 
2365 2508
 	// Make sure Settings_bak.php is writable.
2366 2509
 		quickFileWritable($boarddir . '/Settings_bak.php');
2367
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2368
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2510
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2511
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2512
+	}
2369 2513
 
2370
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2371
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2372
-	elseif (isset($modSettings['agreement']))
2514
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2515
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2516
+	} elseif (isset($modSettings['agreement']))
2373 2517
 	{
2374 2518
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2375 2519
 		fwrite($fp, $modSettings['agreement']);
@@ -2379,31 +2523,36 @@  discard block
 block discarded – undo
2379 2523
 	// Make sure Themes is writable.
2380 2524
 	quickFileWritable($modSettings['theme_dir']);
2381 2525
 
2382
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2383
-		print_error('Error: Unable to obtain write access to "Themes".');
2526
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2527
+			print_error('Error: Unable to obtain write access to "Themes".');
2528
+	}
2384 2529
 
2385 2530
 	// Make sure cache directory exists and is writable!
2386 2531
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2387
-	if (!file_exists($cachedir_temp))
2388
-		@mkdir($cachedir_temp);
2532
+	if (!file_exists($cachedir_temp)) {
2533
+			@mkdir($cachedir_temp);
2534
+	}
2389 2535
 
2390 2536
 	// Make sure the cache temp dir is writable.
2391 2537
 	quickFileWritable($cachedir_temp);
2392 2538
 
2393
-	if (!is_writable($cachedir_temp))
2394
-		print_error('Error: Unable to obtain write access to "cache".', true);
2539
+	if (!is_writable($cachedir_temp)) {
2540
+			print_error('Error: Unable to obtain write access to "cache".', true);
2541
+	}
2395 2542
 
2396
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2397
-		print_error('Error: Unable to find language files!', true);
2398
-	else
2543
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2544
+			print_error('Error: Unable to find language files!', true);
2545
+	} else
2399 2546
 	{
2400 2547
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2401 2548
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2402 2549
 
2403
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2404
-			print_error('Error: Language files out of date.', true);
2405
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2406
-			print_error('Error: Install language is missing for selected language.', true);
2550
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2551
+					print_error('Error: Language files out of date.', true);
2552
+		}
2553
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2554
+					print_error('Error: Install language is missing for selected language.', true);
2555
+		}
2407 2556
 
2408 2557
 		// Otherwise include it!
2409 2558
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2422,8 +2571,9 @@  discard block
 block discarded – undo
2422 2571
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2423 2572
 
2424 2573
 	// Done it already?
2425
-	if (!empty($_POST['utf8_done']))
2426
-		return true;
2574
+	if (!empty($_POST['utf8_done'])) {
2575
+			return true;
2576
+	}
2427 2577
 
2428 2578
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2429 2579
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2436,8 +2586,7 @@  discard block
 block discarded – undo
2436 2586
 		);
2437 2587
 
2438 2588
 		return true;
2439
-	}
2440
-	else
2589
+	} else
2441 2590
 	{
2442 2591
 		$upcontext['page_title'] = 'Converting to UTF8';
2443 2592
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2481,8 +2630,9 @@  discard block
 block discarded – undo
2481 2630
 			)
2482 2631
 		);
2483 2632
 		$db_charsets = array();
2484
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2485
-			$db_charsets[] = $row['Charset'];
2633
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2634
+					$db_charsets[] = $row['Charset'];
2635
+		}
2486 2636
 
2487 2637
 		$smcFunc['db_free_result']($request);
2488 2638
 
@@ -2518,13 +2668,15 @@  discard block
 block discarded – undo
2518 2668
 		// If there's a fulltext index, we need to drop it first...
2519 2669
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2520 2670
 		{
2521
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2522
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2671
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2672
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2523 2673
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2674
+			}
2524 2675
 			$smcFunc['db_free_result']($request);
2525 2676
 
2526
-			if (isset($upcontext['fulltext_index']))
2527
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2677
+			if (isset($upcontext['fulltext_index'])) {
2678
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2679
+			}
2528 2680
 		}
2529 2681
 
2530 2682
 		// Drop it and make a note...
@@ -2714,8 +2866,9 @@  discard block
 block discarded – undo
2714 2866
 			$replace = '%field%';
2715 2867
 
2716 2868
 			// Build a huge REPLACE statement...
2717
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2718
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2869
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2870
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2871
+			}
2719 2872
 		}
2720 2873
 
2721 2874
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2725,9 +2878,10 @@  discard block
 block discarded – undo
2725 2878
 		$upcontext['table_count'] = count($queryTables);
2726 2879
 
2727 2880
 		// What ones have we already done?
2728
-		foreach ($queryTables as $id => $table)
2729
-			if ($id < $_GET['substep'])
2881
+		foreach ($queryTables as $id => $table) {
2882
+					if ($id < $_GET['substep'])
2730 2883
 				$upcontext['previous_tables'][] = $table;
2884
+		}
2731 2885
 
2732 2886
 		$upcontext['cur_table_num'] = $_GET['substep'];
2733 2887
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2764,8 +2918,9 @@  discard block
 block discarded – undo
2764 2918
 			nextSubstep($substep);
2765 2919
 
2766 2920
 			// Just to make sure it doesn't time out.
2767
-			if (function_exists('apache_reset_timeout'))
2768
-				@apache_reset_timeout();
2921
+			if (function_exists('apache_reset_timeout')) {
2922
+							@apache_reset_timeout();
2923
+			}
2769 2924
 
2770 2925
 			$table_charsets = array();
2771 2926
 
@@ -2788,8 +2943,9 @@  discard block
 block discarded – undo
2788 2943
 
2789 2944
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2790 2945
 						if ($charset != 'utf8') {
2791
-							if (!isset($table_charsets[$charset]))
2792
-								$table_charsets[$charset] = array();
2946
+							if (!isset($table_charsets[$charset])) {
2947
+															$table_charsets[$charset] = array();
2948
+							}
2793 2949
 
2794 2950
 							$table_charsets[$charset][] = $column_info;
2795 2951
 						}
@@ -2830,10 +2986,11 @@  discard block
 block discarded – undo
2830 2986
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2831 2987
 				{
2832 2988
 					$update = '';
2833
-					foreach ($table_charsets as $charset => $columns)
2834
-						foreach ($columns as $column)
2989
+					foreach ($table_charsets as $charset => $columns) {
2990
+											foreach ($columns as $column)
2835 2991
 							$update .= '
2836 2992
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2993
+					}
2837 2994
 
2838 2995
 					$smcFunc['db_query']('', '
2839 2996
 						UPDATE {raw:table_name}
@@ -2858,8 +3015,9 @@  discard block
 block discarded – undo
2858 3015
 			// Now do the actual conversion (if still needed).
2859 3016
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2860 3017
 			{
2861
-				if ($command_line)
2862
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3018
+				if ($command_line) {
3019
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3020
+				}
2863 3021
 
2864 3022
 				$smcFunc['db_query']('', '
2865 3023
 					ALTER TABLE {raw:table_name}
@@ -2869,12 +3027,14 @@  discard block
 block discarded – undo
2869 3027
 					)
2870 3028
 				);
2871 3029
 
2872
-				if ($command_line)
2873
-					echo " done.\n";
3030
+				if ($command_line) {
3031
+									echo " done.\n";
3032
+				}
2874 3033
 			}
2875 3034
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2876
-			if (isset($_GET['xml']))
2877
-				return upgradeExit();
3035
+			if (isset($_GET['xml'])) {
3036
+							return upgradeExit();
3037
+			}
2878 3038
 		}
2879 3039
 
2880 3040
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2903,8 +3063,8 @@  discard block
 block discarded – undo
2903 3063
 		);
2904 3064
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2905 3065
 		{
2906
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
2907
-				$smcFunc['db_query']('', '
3066
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3067
+							$smcFunc['db_query']('', '
2908 3068
 					UPDATE {db_prefix}log_actions
2909 3069
 					SET extra = {string:extra}
2910 3070
 					WHERE id_action = {int:current_action}',
@@ -2913,6 +3073,7 @@  discard block
 block discarded – undo
2913 3073
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2914 3074
 					)
2915 3075
 				);
3076
+			}
2916 3077
 		}
2917 3078
 		$smcFunc['db_free_result']($request);
2918 3079
 
@@ -2934,15 +3095,17 @@  discard block
 block discarded – undo
2934 3095
 	// First thing's first - did we already do this?
2935 3096
 	if (!empty($modSettings['json_done']))
2936 3097
 	{
2937
-		if ($command_line)
2938
-			return DeleteUpgrade();
2939
-		else
2940
-			return true;
3098
+		if ($command_line) {
3099
+					return DeleteUpgrade();
3100
+		} else {
3101
+					return true;
3102
+		}
2941 3103
 	}
2942 3104
 
2943 3105
 	// Done it already - js wise?
2944
-	if (!empty($_POST['json_done']))
2945
-		return true;
3106
+	if (!empty($_POST['json_done'])) {
3107
+			return true;
3108
+	}
2946 3109
 
2947 3110
 	// List of tables affected by this function
2948 3111
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2974,12 +3137,14 @@  discard block
 block discarded – undo
2974 3137
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2975 3138
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2976 3139
 
2977
-	foreach ($keys as $id => $table)
2978
-		if ($id < $_GET['substep'])
3140
+	foreach ($keys as $id => $table) {
3141
+			if ($id < $_GET['substep'])
2979 3142
 			$upcontext['previous_tables'][] = $table;
3143
+	}
2980 3144
 
2981
-	if ($command_line)
2982
-		echo 'Converting data from serialize() to json_encode().';
3145
+	if ($command_line) {
3146
+			echo 'Converting data from serialize() to json_encode().';
3147
+	}
2983 3148
 
2984 3149
 	if (!$support_js || isset($_GET['xml']))
2985 3150
 	{
@@ -3019,8 +3184,9 @@  discard block
 block discarded – undo
3019 3184
 
3020 3185
 				// Loop through and fix these...
3021 3186
 				$new_settings = array();
3022
-				if ($command_line)
3023
-					echo "\n" . 'Fixing some settings...';
3187
+				if ($command_line) {
3188
+									echo "\n" . 'Fixing some settings...';
3189
+				}
3024 3190
 
3025 3191
 				foreach ($serialized_settings as $var)
3026 3192
 				{
@@ -3028,22 +3194,24 @@  discard block
 block discarded – undo
3028 3194
 					{
3029 3195
 						// Attempt to unserialize the setting
3030 3196
 						$temp = @safe_unserialize($modSettings[$var]);
3031
-						if (!$temp && $command_line)
3032
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3033
-						elseif ($temp !== false)
3034
-							$new_settings[$var] = json_encode($temp);
3197
+						if (!$temp && $command_line) {
3198
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3199
+						} elseif ($temp !== false) {
3200
+													$new_settings[$var] = json_encode($temp);
3201
+						}
3035 3202
 					}
3036 3203
 				}
3037 3204
 
3038 3205
 				// Update everything at once
3039
-				if (!function_exists('cache_put_data'))
3040
-					require_once($sourcedir . '/Load.php');
3206
+				if (!function_exists('cache_put_data')) {
3207
+									require_once($sourcedir . '/Load.php');
3208
+				}
3041 3209
 				updateSettings($new_settings, true);
3042 3210
 
3043
-				if ($command_line)
3044
-					echo ' done.';
3045
-			}
3046
-			elseif ($table == 'themes')
3211
+				if ($command_line) {
3212
+									echo ' done.';
3213
+				}
3214
+			} elseif ($table == 'themes')
3047 3215
 			{
3048 3216
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3049 3217
 				$query = $smcFunc['db_query']('', '
@@ -3062,10 +3230,11 @@  discard block
 block discarded – undo
3062 3230
 
3063 3231
 						if ($command_line)
3064 3232
 						{
3065
-							if ($temp === false)
3066
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3067
-							else
3068
-								echo "\n" . 'Fixing admin preferences...';
3233
+							if ($temp === false) {
3234
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3235
+							} else {
3236
+															echo "\n" . 'Fixing admin preferences...';
3237
+							}
3069 3238
 						}
3070 3239
 
3071 3240
 						if ($temp !== false)
@@ -3087,15 +3256,15 @@  discard block
 block discarded – undo
3087 3256
 								)
3088 3257
 							);
3089 3258
 
3090
-							if ($command_line)
3091
-								echo ' done.';
3259
+							if ($command_line) {
3260
+															echo ' done.';
3261
+							}
3092 3262
 						}
3093 3263
 					}
3094 3264
 
3095 3265
 					$smcFunc['db_free_result']($query);
3096 3266
 				}
3097
-			}
3098
-			else
3267
+			} else
3099 3268
 			{
3100 3269
 				// First item is always the key...
3101 3270
 				$key = $info[0];
@@ -3106,8 +3275,7 @@  discard block
 block discarded – undo
3106 3275
 				{
3107 3276
 					$col_select = $info[1];
3108 3277
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3109
-				}
3110
-				else
3278
+				} else
3111 3279
 				{
3112 3280
 					$col_select = implode(', ', $info);
3113 3281
 				}
@@ -3140,8 +3308,7 @@  discard block
 block discarded – undo
3140 3308
 								if ($temp === false && $command_line)
3141 3309
 								{
3142 3310
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3143
-								}
3144
-								else
3311
+								} else
3145 3312
 								{
3146 3313
 									$row[$col] = json_encode($temp);
3147 3314
 
@@ -3166,16 +3333,18 @@  discard block
 block discarded – undo
3166 3333
 						}
3167 3334
 					}
3168 3335
 
3169
-					if ($command_line)
3170
-						echo ' done.';
3336
+					if ($command_line) {
3337
+											echo ' done.';
3338
+					}
3171 3339
 
3172 3340
 					// Free up some memory...
3173 3341
 					$smcFunc['db_free_result']($query);
3174 3342
 				}
3175 3343
 			}
3176 3344
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3177
-			if (isset($_GET['xml']))
3178
-				return upgradeExit();
3345
+			if (isset($_GET['xml'])) {
3346
+							return upgradeExit();
3347
+			}
3179 3348
 		}
3180 3349
 
3181 3350
 		if ($command_line)
@@ -3190,8 +3359,9 @@  discard block
 block discarded – undo
3190 3359
 
3191 3360
 		$_GET['substep'] = 0;
3192 3361
 		// Make sure we move on!
3193
-		if ($command_line)
3194
-			return DeleteUpgrade();
3362
+		if ($command_line) {
3363
+					return DeleteUpgrade();
3364
+		}
3195 3365
 
3196 3366
 		return true;
3197 3367
 	}
@@ -3211,14 +3381,16 @@  discard block
 block discarded – undo
3211 3381
 	global $upcontext, $txt, $settings;
3212 3382
 
3213 3383
 	// Don't call me twice!
3214
-	if (!empty($upcontext['chmod_called']))
3215
-		return;
3384
+	if (!empty($upcontext['chmod_called'])) {
3385
+			return;
3386
+	}
3216 3387
 
3217 3388
 	$upcontext['chmod_called'] = true;
3218 3389
 
3219 3390
 	// Nothing?
3220
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3221
-		return;
3391
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3392
+			return;
3393
+	}
3222 3394
 
3223 3395
 	// Was it a problem with Windows?
3224 3396
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3250,11 +3422,12 @@  discard block
 block discarded – undo
3250 3422
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3251 3423
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3252 3424
 
3253
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3254
-		echo '
3425
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3426
+			echo '
3255 3427
 					content.write(\'<hr>\n\t\t\t\');
3256 3428
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3257 3429
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3430
+	}
3258 3431
 
3259 3432
 	echo '
3260 3433
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3262,17 +3435,19 @@  discard block
 block discarded – undo
3262 3435
 				}
3263 3436
 			</script>';
3264 3437
 
3265
-	if (!empty($upcontext['chmod']['ftp_error']))
3266
-		echo '
3438
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3439
+			echo '
3267 3440
 			<div class="error_message red">
3268 3441
 				The following error was encountered when trying to connect:<br><br>
3269 3442
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3270 3443
 			</div>
3271 3444
 			<br>';
3445
+	}
3272 3446
 
3273
-	if (empty($upcontext['chmod_in_form']))
3274
-		echo '
3447
+	if (empty($upcontext['chmod_in_form'])) {
3448
+			echo '
3275 3449
 	<form action="', $upcontext['form_url'], '" method="post">';
3450
+	}
3276 3451
 
3277 3452
 	echo '
3278 3453
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3307,10 +3482,11 @@  discard block
 block discarded – undo
3307 3482
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3308 3483
 	</div>';
3309 3484
 
3310
-	if (empty($upcontext['chmod_in_form']))
3311
-		echo '
3485
+	if (empty($upcontext['chmod_in_form'])) {
3486
+			echo '
3312 3487
 	</form>';
3313
-}
3488
+	}
3489
+	}
3314 3490
 
3315 3491
 function template_upgrade_above()
3316 3492
 {
@@ -3370,9 +3546,10 @@  discard block
 block discarded – undo
3370 3546
 				<h2>', $txt['upgrade_progress'], '</h2>
3371 3547
 				<ul>';
3372 3548
 
3373
-	foreach ($upcontext['steps'] as $num => $step)
3374
-		echo '
3549
+	foreach ($upcontext['steps'] as $num => $step) {
3550
+			echo '
3375 3551
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3552
+	}
3376 3553
 
3377 3554
 	echo '
3378 3555
 					</ul>
@@ -3385,8 +3562,8 @@  discard block
 block discarded – undo
3385 3562
 				</div>
3386 3563
 			</div>';
3387 3564
 
3388
-	if (isset($upcontext['step_progress']))
3389
-		echo '
3565
+	if (isset($upcontext['step_progress'])) {
3566
+			echo '
3390 3567
 				<br>
3391 3568
 				<br>
3392 3569
 				<div id="progress_bar_step">
@@ -3395,6 +3572,7 @@  discard block
 block discarded – undo
3395 3572
 						<span>', $txt['upgrade_step_progress'], '</span>
3396 3573
 					</div>
3397 3574
 				</div>';
3575
+	}
3398 3576
 
3399 3577
 	echo '
3400 3578
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3425,32 +3603,36 @@  discard block
 block discarded – undo
3425 3603
 {
3426 3604
 	global $upcontext, $txt;
3427 3605
 
3428
-	if (!empty($upcontext['pause']))
3429
-		echo '
3606
+	if (!empty($upcontext['pause'])) {
3607
+			echo '
3430 3608
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3431 3609
 
3432 3610
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3433 3611
 								<h3>
3434 3612
 									', $txt['upgrade_paused_overload'], '
3435 3613
 								</h3>';
3614
+	}
3436 3615
 
3437
-	if (!empty($upcontext['custom_warning']))
3438
-		echo '
3616
+	if (!empty($upcontext['custom_warning'])) {
3617
+			echo '
3439 3618
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3440 3619
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3441 3620
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3442 3621
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3443 3622
 								</div>';
3623
+	}
3444 3624
 
3445 3625
 	echo '
3446 3626
 								<div class="righttext" style="margin: 1ex;">';
3447 3627
 
3448
-	if (!empty($upcontext['continue']))
3449
-		echo '
3628
+	if (!empty($upcontext['continue'])) {
3629
+			echo '
3450 3630
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3451
-	if (!empty($upcontext['skip']))
3452
-		echo '
3631
+	}
3632
+	if (!empty($upcontext['skip'])) {
3633
+			echo '
3453 3634
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3635
+	}
3454 3636
 
3455 3637
 	echo '
3456 3638
 								</div>
@@ -3500,11 +3682,12 @@  discard block
 block discarded – undo
3500 3682
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3501 3683
 	<smf>';
3502 3684
 
3503
-	if (!empty($upcontext['get_data']))
3504
-		foreach ($upcontext['get_data'] as $k => $v)
3685
+	if (!empty($upcontext['get_data'])) {
3686
+			foreach ($upcontext['get_data'] as $k => $v)
3505 3687
 			echo '
3506 3688
 		<get key="', $k, '">', $v, '</get>';
3507
-}
3689
+	}
3690
+	}
3508 3691
 
3509 3692
 function template_xml_below()
3510 3693
 {
@@ -3545,8 +3728,8 @@  discard block
 block discarded – undo
3545 3728
 	template_chmod();
3546 3729
 
3547 3730
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3548
-	if ($upcontext['is_large_forum'])
3549
-		echo '
3731
+	if ($upcontext['is_large_forum']) {
3732
+			echo '
3550 3733
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3551 3734
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3552 3735
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3554,10 +3737,11 @@  discard block
 block discarded – undo
3554 3737
 				', $txt['upgrade_warning_lots_data'], '
3555 3738
 			</div>
3556 3739
 		</div>';
3740
+	}
3557 3741
 
3558 3742
 	// A warning message?
3559
-	if (!empty($upcontext['warning']))
3560
-		echo '
3743
+	if (!empty($upcontext['warning'])) {
3744
+			echo '
3561 3745
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3562 3746
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3563 3747
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3565,6 +3749,7 @@  discard block
 block discarded – undo
3565 3749
 				', $upcontext['warning'], '
3566 3750
 			</div>
3567 3751
 		</div>';
3752
+	}
3568 3753
 
3569 3754
 	// Paths are incorrect?
3570 3755
 	echo '
@@ -3580,20 +3765,22 @@  discard block
 block discarded – undo
3580 3765
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3581 3766
 	{
3582 3767
 		$ago = time() - $upcontext['started'];
3583
-		if ($ago < 60)
3584
-			$ago = $ago . ' seconds';
3585
-		elseif ($ago < 3600)
3586
-			$ago = (int) ($ago / 60) . ' minutes';
3587
-		else
3588
-			$ago = (int) ($ago / 3600) . ' hours';
3768
+		if ($ago < 60) {
3769
+					$ago = $ago . ' seconds';
3770
+		} elseif ($ago < 3600) {
3771
+					$ago = (int) ($ago / 60) . ' minutes';
3772
+		} else {
3773
+					$ago = (int) ($ago / 3600) . ' hours';
3774
+		}
3589 3775
 
3590 3776
 		$active = time() - $upcontext['updated'];
3591
-		if ($active < 60)
3592
-			$updated = $active . ' seconds';
3593
-		elseif ($active < 3600)
3594
-			$updated = (int) ($active / 60) . ' minutes';
3595
-		else
3596
-			$updated = (int) ($active / 3600) . ' hours';
3777
+		if ($active < 60) {
3778
+					$updated = $active . ' seconds';
3779
+		} elseif ($active < 3600) {
3780
+					$updated = (int) ($active / 60) . ' minutes';
3781
+		} else {
3782
+					$updated = (int) ($active / 3600) . ' hours';
3783
+		}
3597 3784
 
3598 3785
 		echo '
3599 3786
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3602,16 +3789,18 @@  discard block
 block discarded – undo
3602 3789
 			<div style="padding-left: 6ex;">
3603 3790
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3604 3791
 
3605
-		if ($active < 600)
3606
-			echo '
3792
+		if ($active < 600) {
3793
+					echo '
3607 3794
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3795
+		}
3608 3796
 
3609
-		if ($active > $upcontext['inactive_timeout'])
3610
-			echo '
3797
+		if ($active > $upcontext['inactive_timeout']) {
3798
+					echo '
3611 3799
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3612
-		else
3613
-			echo '
3800
+		} else {
3801
+					echo '
3614 3802
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3803
+		}
3615 3804
 
3616 3805
 		echo '
3617 3806
 			</div>
@@ -3627,9 +3816,10 @@  discard block
 block discarded – undo
3627 3816
 					<td>
3628 3817
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3629 3818
 
3630
-	if (!empty($upcontext['username_incorrect']))
3631
-		echo '
3819
+	if (!empty($upcontext['username_incorrect'])) {
3820
+			echo '
3632 3821
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3822
+	}
3633 3823
 
3634 3824
 	echo '
3635 3825
 					</td>
@@ -3640,9 +3830,10 @@  discard block
 block discarded – undo
3640 3830
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3641 3831
 						<input type="hidden" name="hash_passwrd" value="">';
3642 3832
 
3643
-	if (!empty($upcontext['password_failed']))
3644
-		echo '
3833
+	if (!empty($upcontext['password_failed'])) {
3834
+			echo '
3645 3835
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3836
+	}
3646 3837
 
3647 3838
 	echo '
3648 3839
 					</td>
@@ -3713,8 +3904,8 @@  discard block
 block discarded – undo
3713 3904
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3714 3905
 
3715 3906
 	// Warning message?
3716
-	if (!empty($upcontext['upgrade_options_warning']))
3717
-		echo '
3907
+	if (!empty($upcontext['upgrade_options_warning'])) {
3908
+			echo '
3718 3909
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3719 3910
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3720 3911
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3722,6 +3913,7 @@  discard block
 block discarded – undo
3722 3913
 				', $upcontext['upgrade_options_warning'], '
3723 3914
 			</div>
3724 3915
 		</div>';
3916
+	}
3725 3917
 
3726 3918
 	echo '
3727 3919
 				<table>
@@ -3764,8 +3956,8 @@  discard block
 block discarded – undo
3764 3956
 						</td>
3765 3957
 					</tr>';
3766 3958
 
3767
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3768
-		echo '
3959
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3960
+			echo '
3769 3961
 					<tr valign="top">
3770 3962
 						<td width="2%">
3771 3963
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3774,6 +3966,7 @@  discard block
 block discarded – undo
3774 3966
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3775 3967
 						</td>
3776 3968
 					</tr>';
3969
+	}
3777 3970
 
3778 3971
 	echo '
3779 3972
 					<tr valign="top">
@@ -3811,10 +4004,11 @@  discard block
 block discarded – undo
3811 4004
 			</div>';
3812 4005
 
3813 4006
 	// Dont any tables so far?
3814
-	if (!empty($upcontext['previous_tables']))
3815
-		foreach ($upcontext['previous_tables'] as $table)
4007
+	if (!empty($upcontext['previous_tables'])) {
4008
+			foreach ($upcontext['previous_tables'] as $table)
3816 4009
 			echo '
3817 4010
 			<br>Completed Table: &quot;', $table, '&quot;.';
4011
+	}
3818 4012
 
3819 4013
 	echo '
3820 4014
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3851,12 +4045,13 @@  discard block
 block discarded – undo
3851 4045
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3852 4046
 
3853 4047
 		// If debug flood the screen.
3854
-		if ($is_debug)
3855
-			echo '
4048
+		if ($is_debug) {
4049
+					echo '
3856 4050
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3857 4051
 
3858 4052
 				if (document.getElementById(\'debug_section\').scrollHeight)
3859 4053
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4054
+		}
3860 4055
 
3861 4056
 		echo '
3862 4057
 				// Get the next update...
@@ -3889,8 +4084,9 @@  discard block
 block discarded – undo
3889 4084
 {
3890 4085
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3891 4086
 
3892
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3893
-		$is_debug = true;
4087
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4088
+			$is_debug = true;
4089
+	}
3894 4090
 
3895 4091
 	echo '
3896 4092
 		<h3>Executing database changes</h3>
@@ -3905,8 +4101,9 @@  discard block
 block discarded – undo
3905 4101
 	{
3906 4102
 		foreach ($upcontext['actioned_items'] as $num => $item)
3907 4103
 		{
3908
-			if ($num != 0)
3909
-				echo ' Successful!';
4104
+			if ($num != 0) {
4105
+							echo ' Successful!';
4106
+			}
3910 4107
 			echo '<br>' . $item;
3911 4108
 		}
3912 4109
 		if (!empty($upcontext['changes_complete']))
@@ -3919,28 +4116,32 @@  discard block
 block discarded – undo
3919 4116
 				$seconds = intval($active % 60);
3920 4117
 
3921 4118
 				$totalTime = '';
3922
-				if ($hours > 0)
3923
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3924
-				if ($minutes > 0)
3925
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3926
-				if ($seconds > 0)
3927
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4119
+				if ($hours > 0) {
4120
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4121
+				}
4122
+				if ($minutes > 0) {
4123
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4124
+				}
4125
+				if ($seconds > 0) {
4126
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4127
+				}
3928 4128
 			}
3929 4129
 
3930
-			if ($is_debug && !empty($totalTime))
3931
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3932
-			else
3933
-				echo ' Successful!<br><br>';
4130
+			if ($is_debug && !empty($totalTime)) {
4131
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4132
+			} else {
4133
+							echo ' Successful!<br><br>';
4134
+			}
3934 4135
 
3935 4136
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3936 4137
 		}
3937
-	}
3938
-	else
4138
+	} else
3939 4139
 	{
3940 4140
 		// Tell them how many files we have in total.
3941
-		if ($upcontext['file_count'] > 1)
3942
-			echo '
4141
+		if ($upcontext['file_count'] > 1) {
4142
+					echo '
3943 4143
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4144
+		}
3944 4145
 
3945 4146
 		echo '
3946 4147
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3956,19 +4157,23 @@  discard block
 block discarded – undo
3956 4157
 				$seconds = intval($active % 60);
3957 4158
 
3958 4159
 				$totalTime = '';
3959
-				if ($hours > 0)
3960
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3961
-				if ($minutes > 0)
3962
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3963
-				if ($seconds > 0)
3964
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4160
+				if ($hours > 0) {
4161
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4162
+				}
4163
+				if ($minutes > 0) {
4164
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4165
+				}
4166
+				if ($seconds > 0) {
4167
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4168
+				}
3965 4169
 			}
3966 4170
 
3967 4171
 			echo '
3968 4172
 			<br><span id="upgradeCompleted">';
3969 4173
 
3970
-			if (!empty($totalTime))
3971
-				echo 'Completed in ', $totalTime, '<br>';
4174
+			if (!empty($totalTime)) {
4175
+							echo 'Completed in ', $totalTime, '<br>';
4176
+			}
3972 4177
 
3973 4178
 			echo '</span>
3974 4179
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4005,9 +4210,10 @@  discard block
 block discarded – undo
4005 4210
 			var getData = "";
4006 4211
 			var debugItems = ', $upcontext['debug_items'], ';';
4007 4212
 
4008
-		if ($is_debug)
4009
-			echo '
4213
+		if ($is_debug) {
4214
+					echo '
4010 4215
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4216
+		}
4011 4217
 
4012 4218
 		echo '
4013 4219
 			function getNextItem()
@@ -4047,9 +4253,10 @@  discard block
 block discarded – undo
4047 4253
 						document.getElementById("error_block").style.display = "";
4048 4254
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4049 4255
 
4050
-	if ($is_debug)
4051
-		echo '
4256
+	if ($is_debug) {
4257
+			echo '
4052 4258
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4259
+	}
4053 4260
 
4054 4261
 	echo '
4055 4262
 					}
@@ -4070,9 +4277,10 @@  discard block
 block discarded – undo
4070 4277
 						document.getElementById("error_block").style.display = "";
4071 4278
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4072 4279
 
4073
-	if ($is_debug)
4074
-		echo '
4280
+	if ($is_debug) {
4281
+			echo '
4075 4282
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4283
+	}
4076 4284
 
4077 4285
 	echo '
4078 4286
 					}
@@ -4131,8 +4339,8 @@  discard block
 block discarded – undo
4131 4339
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4132 4340
 				{';
4133 4341
 
4134
-		if ($is_debug)
4135
-			echo '
4342
+		if ($is_debug) {
4343
+					echo '
4136 4344
 					document.getElementById(\'debug_section\').style.display = "none";
4137 4345
 
4138 4346
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4150,6 +4358,7 @@  discard block
 block discarded – undo
4150 4358
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4151 4359
 
4152 4360
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4361
+		}
4153 4362
 
4154 4363
 		echo '
4155 4364
 
@@ -4157,9 +4366,10 @@  discard block
 block discarded – undo
4157 4366
 					document.getElementById(\'contbutt\').disabled = 0;
4158 4367
 					document.getElementById(\'database_done\').value = 1;';
4159 4368
 
4160
-		if ($upcontext['file_count'] > 1)
4161
-			echo '
4369
+		if ($upcontext['file_count'] > 1) {
4370
+					echo '
4162 4371
 					document.getElementById(\'info1\').style.display = "none";';
4372
+		}
4163 4373
 
4164 4374
 		echo '
4165 4375
 					document.getElementById(\'info2\').style.display = "none";
@@ -4172,9 +4382,10 @@  discard block
 block discarded – undo
4172 4382
 					lastItem = 0;
4173 4383
 					prevFile = curFile;';
4174 4384
 
4175
-		if ($is_debug)
4176
-			echo '
4385
+		if ($is_debug) {
4386
+					echo '
4177 4387
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4388
+		}
4178 4389
 
4179 4390
 		echo '
4180 4391
 					getNextItem();
@@ -4182,8 +4393,8 @@  discard block
 block discarded – undo
4182 4393
 				}';
4183 4394
 
4184 4395
 		// If debug scroll the screen.
4185
-		if ($is_debug)
4186
-			echo '
4396
+		if ($is_debug) {
4397
+					echo '
4187 4398
 				if (iLastSubStepProgress == -1)
4188 4399
 				{
4189 4400
 					// Give it consistent dots.
@@ -4202,6 +4413,7 @@  discard block
 block discarded – undo
4202 4413
 
4203 4414
 				if (document.getElementById(\'debug_section\').scrollHeight)
4204 4415
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4416
+		}
4205 4417
 
4206 4418
 		echo '
4207 4419
 				// Update the page.
@@ -4262,9 +4474,10 @@  discard block
 block discarded – undo
4262 4474
 			}';
4263 4475
 
4264 4476
 		// Start things off assuming we've not errored.
4265
-		if (empty($upcontext['error_message']))
4266
-			echo '
4477
+		if (empty($upcontext['error_message'])) {
4478
+					echo '
4267 4479
 			getNextItem();';
4480
+		}
4268 4481
 
4269 4482
 		echo '
4270 4483
 		//# sourceURL=dynamicScript-dbch.js
@@ -4282,18 +4495,21 @@  discard block
 block discarded – undo
4282 4495
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4283 4496
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4284 4497
 
4285
-	if (!empty($upcontext['error_message']))
4286
-		echo '
4498
+	if (!empty($upcontext['error_message'])) {
4499
+			echo '
4287 4500
 	<error>', $upcontext['error_message'], '</error>';
4501
+	}
4288 4502
 
4289
-	if (!empty($upcontext['error_string']))
4290
-		echo '
4503
+	if (!empty($upcontext['error_string'])) {
4504
+			echo '
4291 4505
 	<sql>', $upcontext['error_string'], '</sql>';
4506
+	}
4292 4507
 
4293
-	if ($is_debug)
4294
-		echo '
4508
+	if ($is_debug) {
4509
+			echo '
4295 4510
 	<curtime>', time(), '</curtime>';
4296
-}
4511
+	}
4512
+	}
4297 4513
 
4298 4514
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4299 4515
 function template_convert_utf8()
@@ -4312,18 +4528,20 @@  discard block
 block discarded – undo
4312 4528
 			</div>';
4313 4529
 
4314 4530
 	// Done any tables so far?
4315
-	if (!empty($upcontext['previous_tables']))
4316
-		foreach ($upcontext['previous_tables'] as $table)
4531
+	if (!empty($upcontext['previous_tables'])) {
4532
+			foreach ($upcontext['previous_tables'] as $table)
4317 4533
 			echo '
4318 4534
 			<br>Completed Table: &quot;', $table, '&quot;.';
4535
+	}
4319 4536
 
4320 4537
 	echo '
4321 4538
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4322 4539
 
4323 4540
 	// If we dropped their index, let's let them know
4324
-	if ($upcontext['dropping_index'])
4325
-		echo '
4541
+	if ($upcontext['dropping_index']) {
4542
+			echo '
4326 4543
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4544
+	}
4327 4545
 
4328 4546
 	// Completion notification
4329 4547
 	echo '
@@ -4360,12 +4578,13 @@  discard block
 block discarded – undo
4360 4578
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4361 4579
 
4362 4580
 		// If debug flood the screen.
4363
-		if ($is_debug)
4364
-			echo '
4581
+		if ($is_debug) {
4582
+					echo '
4365 4583
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4366 4584
 
4367 4585
 				if (document.getElementById(\'debug_section\').scrollHeight)
4368 4586
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4587
+		}
4369 4588
 
4370 4589
 		echo '
4371 4590
 				// Get the next update...
@@ -4413,19 +4632,21 @@  discard block
 block discarded – undo
4413 4632
 			</div>';
4414 4633
 
4415 4634
 	// Dont any tables so far?
4416
-	if (!empty($upcontext['previous_tables']))
4417
-		foreach ($upcontext['previous_tables'] as $table)
4635
+	if (!empty($upcontext['previous_tables'])) {
4636
+			foreach ($upcontext['previous_tables'] as $table)
4418 4637
 			echo '
4419 4638
 			<br>Completed Table: &quot;', $table, '&quot;.';
4639
+	}
4420 4640
 
4421 4641
 	echo '
4422 4642
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4423 4643
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4424 4644
 
4425 4645
 	// Try to make sure substep was reset.
4426
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4427
-		echo '
4646
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4647
+			echo '
4428 4648
 			<input type="hidden" name="substep" id="substep" value="0">';
4649
+	}
4429 4650
 
4430 4651
 	// Continue please!
4431 4652
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4458,12 +4679,13 @@  discard block
 block discarded – undo
4458 4679
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4459 4680
 
4460 4681
 		// If debug flood the screen.
4461
-		if ($is_debug)
4462
-			echo '
4682
+		if ($is_debug) {
4683
+					echo '
4463 4684
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4464 4685
 
4465 4686
 				if (document.getElementById(\'debug_section\').scrollHeight)
4466 4687
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4688
+		}
4467 4689
 
4468 4690
 		echo '
4469 4691
 				// Get the next update...
@@ -4499,8 +4721,8 @@  discard block
 block discarded – undo
4499 4721
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4500 4722
 	<form action="', $boardurl, '/index.php">';
4501 4723
 
4502
-	if (!empty($upcontext['can_delete_script']))
4503
-		echo '
4724
+	if (!empty($upcontext['can_delete_script'])) {
4725
+			echo '
4504 4726
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4505 4727
 			<script>
4506 4728
 				function doTheDelete(theCheck)
@@ -4512,6 +4734,7 @@  discard block
 block discarded – undo
4512 4734
 				}
4513 4735
 			</script>
4514 4736
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4737
+	}
4515 4738
 
4516 4739
 	$active = time() - $upcontext['started'];
4517 4740
 	$hours = floor($active / 3600);
@@ -4521,16 +4744,20 @@  discard block
 block discarded – undo
4521 4744
 	if ($is_debug)
4522 4745
 	{
4523 4746
 		$totalTime = '';
4524
-		if ($hours > 0)
4525
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4526
-		if ($minutes > 0)
4527
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4528
-		if ($seconds > 0)
4529
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4747
+		if ($hours > 0) {
4748
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4749
+		}
4750
+		if ($minutes > 0) {
4751
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4752
+		}
4753
+		if ($seconds > 0) {
4754
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4755
+		}
4530 4756
 	}
4531 4757
 
4532
-	if ($is_debug && !empty($totalTime))
4533
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4758
+	if ($is_debug && !empty($totalTime)) {
4759
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4760
+	}
4534 4761
 
4535 4762
 	echo '<br>
4536 4763
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4557,8 +4784,9 @@  discard block
 block discarded – undo
4557 4784
 
4558 4785
 	$current_substep = $_GET['substep'];
4559 4786
 
4560
-	if (empty($_GET['a']))
4561
-		$_GET['a'] = 0;
4787
+	if (empty($_GET['a'])) {
4788
+			$_GET['a'] = 0;
4789
+	}
4562 4790
 	$step_progress['name'] = 'Converting ips';
4563 4791
 	$step_progress['current'] = $_GET['a'];
4564 4792
 
@@ -4601,16 +4829,19 @@  discard block
 block discarded – undo
4601 4829
 				'empty' => '',
4602 4830
 				'limit' => $limit,
4603 4831
 		));
4604
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4605
-			$arIp[] = $row[$oldCol];
4832
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4833
+					$arIp[] = $row[$oldCol];
4834
+		}
4606 4835
 		$smcFunc['db_free_result']($request);
4607 4836
 
4608 4837
 		// Special case, null ip could keep us in a loop.
4609
-		if (is_null($arIp[0]))
4610
-			unset($arIp[0]);
4838
+		if (is_null($arIp[0])) {
4839
+					unset($arIp[0]);
4840
+		}
4611 4841
 
4612
-		if (empty($arIp))
4613
-			$is_done = true;
4842
+		if (empty($arIp)) {
4843
+					$is_done = true;
4844
+		}
4614 4845
 
4615 4846
 		$updates = array();
4616 4847
 		$cases = array();
@@ -4619,16 +4850,18 @@  discard block
 block discarded – undo
4619 4850
 		{
4620 4851
 			$arIp[$i] = trim($arIp[$i]);
4621 4852
 
4622
-			if (empty($arIp[$i]))
4623
-				continue;
4853
+			if (empty($arIp[$i])) {
4854
+							continue;
4855
+			}
4624 4856
 
4625 4857
 			$updates['ip' . $i] = $arIp[$i];
4626 4858
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4627 4859
 
4628 4860
 			if ($setSize > 0 && $i % $setSize === 0)
4629 4861
 			{
4630
-				if (count($updates) == 1)
4631
-					continue;
4862
+				if (count($updates) == 1) {
4863
+									continue;
4864
+				}
4632 4865
 
4633 4866
 				$updates['whereSet'] = array_values($updates);
4634 4867
 				$smcFunc['db_query']('', '
@@ -4662,8 +4895,7 @@  discard block
 block discarded – undo
4662 4895
 							'ip' => $ip
4663 4896
 					));
4664 4897
 				}
4665
-			}
4666
-			else
4898
+			} else
4667 4899
 			{
4668 4900
 				$updates['whereSet'] = array_values($updates);
4669 4901
 				$smcFunc['db_query']('', '
@@ -4677,9 +4909,9 @@  discard block
 block discarded – undo
4677 4909
 					$updates
4678 4910
 				);
4679 4911
 			}
4912
+		} else {
4913
+					$is_done = true;
4680 4914
 		}
4681
-		else
4682
-			$is_done = true;
4683 4915
 
4684 4916
 		$_GET['a'] += $limit;
4685 4917
 		$step_progress['current'] = $_GET['a'];
@@ -4705,10 +4937,11 @@  discard block
 block discarded – undo
4705 4937
 
4706 4938
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4707 4939
 
4708
-	if (isset($columns[$column]))
4709
-		return $columns[$column];
4710
-	else
4711
-		return null;
4712
-}
4940
+	if (isset($columns[$column])) {
4941
+			return $columns[$column];
4942
+	} else {
4943
+			return null;
4944
+	}
4945
+	}
4713 4946
 
4714 4947
 ?>
4715 4948
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/News.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -540,6 +540,7 @@
 block discarded – undo
540 540
  * @param string $xml_format The format to use ('atom', 'rss', 'rss2' or empty for plain XML)
541 541
  * @param array $forceCdataKeys A list of keys on which to force cdata wrapping (used by mods, maybe)
542 542
  * @param array $nsKeys Key-value pairs of namespace prefixes to pass to cdata_parse() (used by mods, maybe)
543
+ * @param string $tag
543 544
  */
544 545
 function dumpTags($data, $i, $tag = null, $xml_format = '', $forceCdataKeys = array(), $nsKeys = array())
545 546
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
 			{
863 863
 				uasort($loaded_attachments, function($a, $b) {
864 864
 					if ($a['filesize'] == $b['filesize'])
865
-					        return 0;
865
+							return 0;
866 866
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
867 867
 				});
868 868
 			}
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
 			{
1273 1273
 				uasort($loaded_attachments, function($a, $b) {
1274 1274
 					if ($a['filesize'] == $b['filesize'])
1275
-					        return 0;
1275
+							return 0;
1276 1276
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1277 1277
 				});
1278 1278
 			}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		$smcFunc['db_free_result']($request);
166 166
 
167 167
 		$feed_meta['title'] = ' - ' . strip_tags($board_info['name']);
168
-		$feed_meta['source'] .= '?board=' . $board . '.0' ;
168
+		$feed_meta['source'] .= '?board=' . $board . '.0';
169 169
 
170 170
 		$query_this_board = 'b.id_board = ' . $board;
171 171
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 
390 390
 		foreach ($xml_data as $item)
391 391
 		{
392
-			$link = array_filter($item['content'], function ($e) { return ($e['tag'] == 'link'); });
392
+			$link = array_filter($item['content'], function($e) { return ($e['tag'] == 'link'); });
393 393
 			$link = array_pop($link);
394 394
 
395 395
 			echo '
Please login to merge, or discard this patch.
Braces   +226 added lines, -185 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
  * Outputs xml data representing recent information or a profile.
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	global $query_this_board, $smcFunc, $forum_version, $settings;
38 39
 
39 40
 	// If it's not enabled, die.
40
-	if (empty($modSettings['xmlnews_enable']))
41
-		obExit(false);
41
+	if (empty($modSettings['xmlnews_enable'])) {
42
+			obExit(false);
43
+	}
42 44
 
43 45
 	loadLanguage('Stats');
44 46
 
@@ -64,8 +66,9 @@  discard block
 block discarded – undo
64 66
 	if (!empty($_REQUEST['c']) && empty($board))
65 67
 	{
66 68
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
67
-		foreach ($_REQUEST['c'] as $i => $c)
68
-			$_REQUEST['c'][$i] = (int) $c;
69
+		foreach ($_REQUEST['c'] as $i => $c) {
70
+					$_REQUEST['c'][$i] = (int) $c;
71
+		}
69 72
 
70 73
 		if (count($_REQUEST['c']) == 1)
71 74
 		{
@@ -101,18 +104,20 @@  discard block
 block discarded – undo
101 104
 		}
102 105
 		$smcFunc['db_free_result']($request);
103 106
 
104
-		if (!empty($boards))
105
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
107
+		if (!empty($boards)) {
108
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
109
+		}
106 110
 
107 111
 		// Try to limit the number of messages we look through.
108
-		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
109
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
110
-	}
111
-	elseif (!empty($_REQUEST['boards']))
112
+		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
113
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
114
+		}
115
+	} elseif (!empty($_REQUEST['boards']))
112 116
 	{
113 117
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
114
-		foreach ($_REQUEST['boards'] as $i => $b)
115
-			$_REQUEST['boards'][$i] = (int) $b;
118
+		foreach ($_REQUEST['boards'] as $i => $b) {
119
+					$_REQUEST['boards'][$i] = (int) $b;
120
+		}
116 121
 
117 122
 		$request = $smcFunc['db_query']('', '
118 123
 			SELECT b.id_board, b.num_posts, b.name
@@ -128,29 +133,32 @@  discard block
 block discarded – undo
128 133
 
129 134
 		// Either the board specified doesn't exist or you have no access.
130 135
 		$num_boards = $smcFunc['db_num_rows']($request);
131
-		if ($num_boards == 0)
132
-			fatal_lang_error('no_board');
136
+		if ($num_boards == 0) {
137
+					fatal_lang_error('no_board');
138
+		}
133 139
 
134 140
 		$total_posts = 0;
135 141
 		$boards = array();
136 142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
137 143
 		{
138
-			if ($num_boards == 1)
139
-				$feed_meta['title'] = ' - ' . strip_tags($row['name']);
144
+			if ($num_boards == 1) {
145
+							$feed_meta['title'] = ' - ' . strip_tags($row['name']);
146
+			}
140 147
 
141 148
 			$boards[] = $row['id_board'];
142 149
 			$total_posts += $row['num_posts'];
143 150
 		}
144 151
 		$smcFunc['db_free_result']($request);
145 152
 
146
-		if (!empty($boards))
147
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
153
+		if (!empty($boards)) {
154
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
155
+		}
148 156
 
149 157
 		// The more boards, the more we're going to look through...
150
-		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
151
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
152
-	}
153
-	elseif (!empty($board))
158
+		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
159
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
160
+		}
161
+	} elseif (!empty($board))
154 162
 	{
155 163
 		$request = $smcFunc['db_query']('', '
156 164
 			SELECT num_posts
@@ -170,10 +178,10 @@  discard block
 block discarded – undo
170 178
 		$query_this_board = 'b.id_board = ' . $board;
171 179
 
172 180
 		// Try to look through just a few messages, if at all possible.
173
-		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
174
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
175
-	}
176
-	else
181
+		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
182
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
183
+		}
184
+	} else
177 185
 	{
178 186
 		$query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
179 187
 			AND b.id_board != ' . $modSettings['recycle_board'] : '');
@@ -196,30 +204,35 @@  discard block
 block discarded – undo
196 204
 	// Easy adding of sub actions
197 205
  	call_integration_hook('integrate_xmlfeeds', array(&$subActions));
198 206
 
199
-	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
200
-		$_GET['sa'] = 'recent';
207
+	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
208
+			$_GET['sa'] = 'recent';
209
+	}
201 210
 
202 211
 	// We only want some information, not all of it.
203 212
 	$cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
204
-	foreach (array('board', 'boards', 'c') as $var)
205
-		if (isset($_REQUEST[$var]))
213
+	foreach (array('board', 'boards', 'c') as $var) {
214
+			if (isset($_REQUEST[$var]))
206 215
 			$cachekey[] = $_REQUEST[$var];
216
+	}
207 217
 	$cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
208 218
 	$cache_t = microtime();
209 219
 
210 220
 	// Get the associative array representing the xml.
211
-	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
212
-		$xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
221
+	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) {
222
+			$xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
223
+	}
213 224
 	if (empty($xml_data))
214 225
 	{
215 226
 		$call = call_helper($subActions[$_GET['sa']][0], true);
216 227
 
217
-		if (!empty($call))
218
-			$xml_data = call_user_func($call, $xml_format);
228
+		if (!empty($call)) {
229
+					$xml_data = call_user_func($call, $xml_format);
230
+		}
219 231
 
220 232
 		if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
221
-		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
222
-			cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240);
233
+		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) {
234
+					cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240);
235
+		}
223 236
 	}
224 237
 
225 238
 	$feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : '');
@@ -259,43 +272,49 @@  discard block
 block discarded – undo
259 272
 	call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa']));
260 273
 
261 274
 	// These can't be empty
262
-	foreach (array('title', 'desc', 'source') as $mkey)
263
-		$feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey];
275
+	foreach (array('title', 'desc', 'source') as $mkey) {
276
+			$feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey];
277
+	}
264 278
 
265 279
 	// Sanitize basic feed metadata values
266
-	foreach ($feed_meta as $mkey => $mvalue)
267
-		$feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey])));
280
+	foreach ($feed_meta as $mkey => $mvalue) {
281
+			$feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey])));
282
+	}
268 283
 
269 284
 	$ns_string = '';
270 285
 	if (!empty($namespaces[$xml_format]))
271 286
 	{
272
-		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl)
273
-			$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
287
+		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) {
288
+					$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
289
+		}
274 290
 	}
275 291
 
276 292
 	$extraFeedTags_string = '';
277 293
 	if (!empty($extraFeedTags[$xml_format]))
278 294
 	{
279 295
 		$indent = "\t" . ($xml_format !== 'atom' ? "\t" : '');
280
-		foreach ($extraFeedTags[$xml_format] as $extraTag)
281
-			$extraFeedTags_string .= "\n" . $indent . $extraTag;
296
+		foreach ($extraFeedTags[$xml_format] as $extraTag) {
297
+					$extraFeedTags_string .= "\n" . $indent . $extraTag;
298
+		}
282 299
 	}
283 300
 
284 301
 	// This is an xml file....
285 302
 	ob_end_clean();
286
-	if (!empty($modSettings['enableCompressedOutput']))
287
-		@ob_start('ob_gzhandler');
288
-	else
289
-		ob_start();
303
+	if (!empty($modSettings['enableCompressedOutput'])) {
304
+			@ob_start('ob_gzhandler');
305
+	} else {
306
+			ob_start();
307
+	}
290 308
 
291
-	if ($xml_format == 'smf' || isset($_REQUEST['debug']))
292
-		header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
293
-	elseif ($xml_format == 'rss' || $xml_format == 'rss2')
294
-		header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
295
-	elseif ($xml_format == 'atom')
296
-		header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
297
-	elseif ($xml_format == 'rdf')
298
-		header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
309
+	if ($xml_format == 'smf' || isset($_REQUEST['debug'])) {
310
+			header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
311
+	} elseif ($xml_format == 'rss' || $xml_format == 'rss2') {
312
+			header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
313
+	} elseif ($xml_format == 'atom') {
314
+			header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
315
+	} elseif ($xml_format == 'rdf') {
316
+			header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
317
+	}
299 318
 
300 319
 	// First, output the xml header.
301 320
 	echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
@@ -303,10 +322,11 @@  discard block
 block discarded – undo
303 322
 	// Are we outputting an rss feed or one with more information?
304 323
 	if ($xml_format == 'rss' || $xml_format == 'rss2')
305 324
 	{
306
-		if ($xml_format == 'rss2')
307
-			foreach ($_REQUEST as $var => $val)
325
+		if ($xml_format == 'rss2') {
326
+					foreach ($_REQUEST as $var => $val)
308 327
 				if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
309 328
 					$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
329
+		}
310 330
 
311 331
 		// Start with an RSS 2.0 header.
312 332
 		echo '
@@ -327,9 +347,10 @@  discard block
 block discarded – undo
327 347
 		<language>' . $feed_meta['language'] . '</language>' : '';
328 348
 
329 349
 		// RSS2 calls for this.
330
-		if ($xml_format == 'rss2')
331
-			echo '
350
+		if ($xml_format == 'rss2') {
351
+					echo '
332 352
 		<atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />';
353
+		}
333 354
 
334 355
 		echo $extraFeedTags_string;
335 356
 
@@ -340,12 +361,12 @@  discard block
 block discarded – undo
340 361
 		echo '
341 362
 	</channel>
342 363
 </rss>';
343
-	}
344
-	elseif ($xml_format == 'atom')
364
+	} elseif ($xml_format == 'atom')
345 365
 	{
346
-		foreach ($_REQUEST as $var => $val)
347
-			if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
366
+		foreach ($_REQUEST as $var => $val) {
367
+					if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
348 368
 				$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
369
+		}
349 370
 
350 371
 		echo '
351 372
 <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '>
@@ -371,8 +392,7 @@  discard block
 block discarded – undo
371 392
 
372 393
 		echo '
373 394
 </feed>';
374
-	}
375
-	elseif ($xml_format == 'rdf')
395
+	} elseif ($xml_format == 'rdf')
376 396
 	{
377 397
 		echo '
378 398
 <rdf:RDF', $ns_string, '>
@@ -437,13 +457,15 @@  discard block
 block discarded – undo
437 457
 {
438 458
 	global $modSettings, $context, $scripturl;
439 459
 
440
-	if (substr($val, 0, strlen($scripturl)) != $scripturl)
441
-		return $val;
460
+	if (substr($val, 0, strlen($scripturl)) != $scripturl) {
461
+			return $val;
462
+	}
442 463
 
443 464
 	call_integration_hook('integrate_fix_url', array(&$val));
444 465
 
445
-	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
446
-		return $val;
466
+	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) {
467
+			return $val;
468
+	}
447 469
 
448 470
 	$val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl)
449 471
 		{
@@ -466,8 +488,9 @@  discard block
 block discarded – undo
466 488
 	global $smcFunc;
467 489
 
468 490
 	// Do we even need to do this?
469
-	if (strpbrk($data, '<>&') == false && $force !== true)
470
-		return $data;
491
+	if (strpbrk($data, '<>&') == false && $force !== true) {
492
+			return $data;
493
+	}
471 494
 
472 495
 	$cdata = '<![CDATA[';
473 496
 
@@ -477,49 +500,55 @@  discard block
 block discarded – undo
477 500
 			$smcFunc['strpos']($data, '&', $pos),
478 501
 			$smcFunc['strpos']($data, ']', $pos),
479 502
 		);
480
-		if ($ns != '')
481
-			$positions[] = $smcFunc['strpos']($data, '<', $pos);
503
+		if ($ns != '') {
504
+					$positions[] = $smcFunc['strpos']($data, '<', $pos);
505
+		}
482 506
 		foreach ($positions as $k => $dummy)
483 507
 		{
484
-			if ($dummy === false)
485
-				unset($positions[$k]);
508
+			if ($dummy === false) {
509
+							unset($positions[$k]);
510
+			}
486 511
 		}
487 512
 
488 513
 		$old = $pos;
489 514
 		$pos = empty($positions) ? $n : min($positions);
490 515
 
491
-		if ($pos - $old > 0)
492
-			$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
493
-		if ($pos >= $n)
494
-			break;
516
+		if ($pos - $old > 0) {
517
+					$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
518
+		}
519
+		if ($pos >= $n) {
520
+					break;
521
+		}
495 522
 
496 523
 		if ($smcFunc['substr']($data, $pos, 1) == '<')
497 524
 		{
498 525
 			$pos2 = $smcFunc['strpos']($data, '>', $pos);
499
-			if ($pos2 === false)
500
-				$pos2 = $n;
501
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
502
-				$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
503
-			else
504
-				$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
526
+			if ($pos2 === false) {
527
+							$pos2 = $n;
528
+			}
529
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '/') {
530
+							$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
531
+			} else {
532
+							$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
533
+			}
505 534
 			$pos = $pos2 + 1;
506
-		}
507
-		elseif ($smcFunc['substr']($data, $pos, 1) == ']')
535
+		} elseif ($smcFunc['substr']($data, $pos, 1) == ']')
508 536
 		{
509 537
 			$cdata .= ']]>&#093;<![CDATA[';
510 538
 			$pos++;
511
-		}
512
-		elseif ($smcFunc['substr']($data, $pos, 1) == '&')
539
+		} elseif ($smcFunc['substr']($data, $pos, 1) == '&')
513 540
 		{
514 541
 			$pos2 = $smcFunc['strpos']($data, ';', $pos);
515
-			if ($pos2 === false)
516
-				$pos2 = $n;
542
+			if ($pos2 === false) {
543
+							$pos2 = $n;
544
+			}
517 545
 			$ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
518 546
 
519
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
520
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
521
-			elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
522
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
547
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '#') {
548
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
549
+			} elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) {
550
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
551
+			}
523 552
 
524 553
 			$pos = $pos2 + 1;
525 554
 		}
@@ -558,8 +587,9 @@  discard block
 block discarded – undo
558 587
 		'gender',
559 588
 		'blurb',
560 589
 	);
561
-	if ($xml_format != 'atom')
562
-		$keysToCdata[] = 'category';
590
+	if ($xml_format != 'atom') {
591
+			$keysToCdata[] = 'category';
592
+	}
563 593
 
564 594
 	if (!empty($forceCdataKeys))
565 595
 	{
@@ -576,8 +606,9 @@  discard block
 block discarded – undo
576 606
 		$attrs = isset($element['attributes']) ? $element['attributes'] : null;
577 607
 
578 608
 		// Skip it, it's been set to null.
579
-		if ($key === null || ($val === null && $attrs === null))
580
-			continue;
609
+		if ($key === null || ($val === null && $attrs === null)) {
610
+					continue;
611
+		}
581 612
 
582 613
 		$forceCdata = in_array($key, $forceCdataKeys);
583 614
 		$ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : '';
@@ -590,16 +621,16 @@  discard block
 block discarded – undo
590 621
 
591 622
 		if (!empty($attrs))
592 623
 		{
593
-			foreach ($attrs as $attr_key => $attr_value)
594
-				echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
624
+			foreach ($attrs as $attr_key => $attr_value) {
625
+							echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
626
+			}
595 627
 		}
596 628
 
597 629
 		// If it's empty, simply output an empty element.
598 630
 		if (empty($val))
599 631
 		{
600 632
 			echo ' />';
601
-		}
602
-		else
633
+		} else
603 634
 		{
604 635
 			echo '>';
605 636
 
@@ -611,11 +642,13 @@  discard block
 block discarded – undo
611 642
 				echo "\n", str_repeat("\t", $i);
612 643
 			}
613 644
 			// A string with returns in it.... show this as a multiline element.
614
-			elseif (strpos($val, "\n") !== false)
615
-				echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
645
+			elseif (strpos($val, "\n") !== false) {
646
+							echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
647
+			}
616 648
 			// A simple string.
617
-			else
618
-				echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
649
+			else {
650
+							echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
651
+			}
619 652
 
620 653
 			// Ending tag.
621 654
 			echo '</', $key, '>';
@@ -635,8 +668,9 @@  discard block
 block discarded – undo
635 668
 {
636 669
 	global $scripturl, $smcFunc;
637 670
 
638
-	if (!allowedTo('view_mlist'))
639
-		return array();
671
+	if (!allowedTo('view_mlist')) {
672
+			return array();
673
+	}
640 674
 
641 675
 	// Find the most recent members.
642 676
 	$request = $smcFunc['db_query']('', '
@@ -655,8 +689,8 @@  discard block
 block discarded – undo
655 689
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member'];
656 690
 
657 691
 		// Make the data look rss-ish.
658
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
659
-			$data[] = array(
692
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
693
+					$data[] = array(
660 694
 				'tag' => 'item',
661 695
 				'content' => array(
662 696
 					array(
@@ -684,8 +718,8 @@  discard block
 block discarded – undo
684 718
 					),
685 719
 				),
686 720
 			);
687
-		elseif ($xml_format == 'rdf')
688
-			$data[] = array(
721
+		} elseif ($xml_format == 'rdf') {
722
+					$data[] = array(
689 723
 				'tag' => 'item',
690 724
 				'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']),
691 725
 				'content' => array(
@@ -703,8 +737,8 @@  discard block
 block discarded – undo
703 737
 					),
704 738
 				),
705 739
 			);
706
-		elseif ($xml_format == 'atom')
707
-			$data[] = array(
740
+		} elseif ($xml_format == 'atom') {
741
+					$data[] = array(
708 742
 				'tag' => 'entry',
709 743
 				'content' => array(
710 744
 					array(
@@ -733,9 +767,10 @@  discard block
 block discarded – undo
733 767
 					),
734 768
 				),
735 769
 			);
770
+		}
736 771
 		// More logical format for the data, but harder to apply.
737
-		else
738
-			$data[] = array(
772
+		else {
773
+					$data[] = array(
739 774
 				'tag' => 'member',
740 775
 				'content' => array(
741 776
 					array(
@@ -756,6 +791,7 @@  discard block
 block discarded – undo
756 791
 					),
757 792
 				),
758 793
 			);
794
+		}
759 795
 	}
760 796
 	$smcFunc['db_free_result']($request);
761 797
 
@@ -816,22 +852,24 @@  discard block
 block discarded – undo
816 852
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
817 853
 		{
818 854
 			$smcFunc['db_free_result']($request);
819
-			if (empty($_REQUEST['boards']) && empty($board))
820
-				unset($context['optimize_msg']['lowest']);
821
-			else
822
-				$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
855
+			if (empty($_REQUEST['boards']) && empty($board)) {
856
+							unset($context['optimize_msg']['lowest']);
857
+			} else {
858
+							$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
859
+			}
823 860
 			$context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
824 861
 			$loops++;
862
+		} else {
863
+					$done = true;
825 864
 		}
826
-		else
827
-			$done = true;
828 865
 	}
829 866
 	$data = array();
830 867
 	while ($row = $smcFunc['db_fetch_assoc']($request))
831 868
 	{
832 869
 		// Limit the length of the message, if the option is set.
833
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
834
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
870
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
871
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
872
+		}
835 873
 
836 874
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
837 875
 
@@ -858,8 +896,9 @@  discard block
 block discarded – undo
858 896
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
859 897
 			{
860 898
 				// Include approved attachments only
861
-				if ($attach['approved'])
862
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
899
+				if ($attach['approved']) {
900
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
901
+				}
863 902
 			}
864 903
 			$smcFunc['db_free_result']($attach_request);
865 904
 
@@ -867,16 +906,17 @@  discard block
 block discarded – undo
867 906
 			if (!empty($loaded_attachments))
868 907
 			{
869 908
 				uasort($loaded_attachments, function($a, $b) {
870
-					if ($a['filesize'] == $b['filesize'])
871
-					        return 0;
909
+					if ($a['filesize'] == $b['filesize']) {
910
+										        return 0;
911
+					}
872 912
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
873 913
 				});
914
+			} else {
915
+							$loaded_attachments = null;
874 916
 			}
875
-			else
876
-				$loaded_attachments = null;
917
+		} else {
918
+					$loaded_attachments = null;
877 919
 		}
878
-		else
879
-			$loaded_attachments = null;
880 920
 
881 921
 		// Create a GUID for this topic using the tag URI scheme
882 922
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic'];
@@ -893,9 +933,9 @@  discard block
 block discarded – undo
893 933
 					'length' => $attachment['filesize'],
894 934
 					'type' => $attachment['mime_type'],
895 935
 				);
936
+			} else {
937
+							$enclosure = null;
896 938
 			}
897
-			else
898
-				$enclosure = null;
899 939
 
900 940
 			$data[] = array(
901 941
 				'tag' => 'item',
@@ -941,8 +981,7 @@  discard block
 block discarded – undo
941 981
 					),
942 982
 				),
943 983
 			);
944
-		}
945
-		elseif ($xml_format == 'rdf')
984
+		} elseif ($xml_format == 'rdf')
946 985
 		{
947 986
 			$data[] = array(
948 987
 				'tag' => 'item',
@@ -966,8 +1005,7 @@  discard block
 block discarded – undo
966 1005
 					),
967 1006
 				),
968 1007
 			);
969
-		}
970
-		elseif ($xml_format == 'atom')
1008
+		} elseif ($xml_format == 'atom')
971 1009
 		{
972 1010
 			// Only one attachment allowed
973 1011
 			if (!empty($loaded_attachments))
@@ -979,9 +1017,9 @@  discard block
 block discarded – undo
979 1017
 					'length' => $attachment['filesize'],
980 1018
 					'type' => $attachment['mime_type'],
981 1019
 				);
1020
+			} else {
1021
+							$enclosure = null;
982 1022
 			}
983
-			else
984
-				$enclosure = null;
985 1023
 
986 1024
 			$data[] = array(
987 1025
 				'tag' => 'entry',
@@ -1081,9 +1119,9 @@  discard block
 block discarded – undo
1081 1119
 						)
1082 1120
 					);
1083 1121
 				}
1122
+			} else {
1123
+							$attachments = null;
1084 1124
 			}
1085
-			else
1086
-				$attachments = null;
1087 1125
 
1088 1126
 			$data[] = array(
1089 1127
 				'tag' => 'article',
@@ -1201,22 +1239,25 @@  discard block
 block discarded – undo
1201 1239
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
1202 1240
 		{
1203 1241
 			$smcFunc['db_free_result']($request);
1204
-			if (empty($_REQUEST['boards']) && empty($board))
1205
-				unset($context['optimize_msg']['lowest']);
1206
-			else
1207
-				$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1242
+			if (empty($_REQUEST['boards']) && empty($board)) {
1243
+							unset($context['optimize_msg']['lowest']);
1244
+			} else {
1245
+							$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1246
+			}
1208 1247
 			$loops++;
1248
+		} else {
1249
+					$done = true;
1209 1250
 		}
1210
-		else
1211
-			$done = true;
1212 1251
 	}
1213 1252
 	$messages = array();
1214
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1215
-		$messages[] = $row['id_msg'];
1253
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1254
+			$messages[] = $row['id_msg'];
1255
+	}
1216 1256
 	$smcFunc['db_free_result']($request);
1217 1257
 
1218
-	if (empty($messages))
1219
-		return array();
1258
+	if (empty($messages)) {
1259
+			return array();
1260
+	}
1220 1261
 
1221 1262
 	// Find the most recent posts this user can see.
1222 1263
 	$request = $smcFunc['db_query']('', '
@@ -1246,8 +1287,9 @@  discard block
 block discarded – undo
1246 1287
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1247 1288
 	{
1248 1289
 		// Limit the length of the message, if the option is set.
1249
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
1250
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1290
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
1291
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1292
+		}
1251 1293
 
1252 1294
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1253 1295
 
@@ -1274,8 +1316,9 @@  discard block
 block discarded – undo
1274 1316
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
1275 1317
 			{
1276 1318
 				// Include approved attachments only
1277
-				if ($attach['approved'])
1278
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1319
+				if ($attach['approved']) {
1320
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1321
+				}
1279 1322
 			}
1280 1323
 			$smcFunc['db_free_result']($attach_request);
1281 1324
 
@@ -1283,16 +1326,17 @@  discard block
 block discarded – undo
1283 1326
 			if (!empty($loaded_attachments))
1284 1327
 			{
1285 1328
 				uasort($loaded_attachments, function($a, $b) {
1286
-					if ($a['filesize'] == $b['filesize'])
1287
-					        return 0;
1329
+					if ($a['filesize'] == $b['filesize']) {
1330
+										        return 0;
1331
+					}
1288 1332
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1289 1333
 				});
1334
+			} else {
1335
+							$loaded_attachments = null;
1290 1336
 			}
1291
-			else
1292
-				$loaded_attachments = null;
1337
+		} else {
1338
+					$loaded_attachments = null;
1293 1339
 		}
1294
-		else
1295
-			$loaded_attachments = null;
1296 1340
 
1297 1341
 		// Create a GUID for this post using the tag URI scheme
1298 1342
 		$guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg'];
@@ -1309,9 +1353,9 @@  discard block
 block discarded – undo
1309 1353
 					'length' => $attachment['filesize'],
1310 1354
 					'type' => $attachment['mime_type'],
1311 1355
 				);
1356
+			} else {
1357
+							$enclosure = null;
1312 1358
 			}
1313
-			else
1314
-				$enclosure = null;
1315 1359
 
1316 1360
 			$data[] = array(
1317 1361
 				'tag' => 'item',
@@ -1357,8 +1401,7 @@  discard block
 block discarded – undo
1357 1401
 					),
1358 1402
 				),
1359 1403
 			);
1360
-		}
1361
-		elseif ($xml_format == 'rdf')
1404
+		} elseif ($xml_format == 'rdf')
1362 1405
 		{
1363 1406
 			$data[] = array(
1364 1407
 				'tag' => 'item',
@@ -1382,8 +1425,7 @@  discard block
 block discarded – undo
1382 1425
 					),
1383 1426
 				),
1384 1427
 			);
1385
-		}
1386
-		elseif ($xml_format == 'atom')
1428
+		} elseif ($xml_format == 'atom')
1387 1429
 		{
1388 1430
 			// Only one attachment allowed
1389 1431
 			if (!empty($loaded_attachments))
@@ -1395,9 +1437,9 @@  discard block
 block discarded – undo
1395 1437
 					'length' => $attachment['filesize'],
1396 1438
 					'type' => $attachment['mime_type'],
1397 1439
 				);
1440
+			} else {
1441
+							$enclosure = null;
1398 1442
 			}
1399
-			else
1400
-				$enclosure = null;
1401 1443
 
1402 1444
 			$data[] = array(
1403 1445
 				'tag' => 'entry',
@@ -1497,9 +1539,9 @@  discard block
 block discarded – undo
1497 1539
 						)
1498 1540
 					);
1499 1541
 				}
1542
+			} else {
1543
+							$attachments = null;
1500 1544
 			}
1501
-			else
1502
-				$attachments = null;
1503 1545
 
1504 1546
 			$data[] = array(
1505 1547
 				'tag' => 'recent-post',
@@ -1618,14 +1660,16 @@  discard block
 block discarded – undo
1618 1660
 	global $scripturl, $memberContext, $user_profile, $user_info;
1619 1661
 
1620 1662
 	// You must input a valid user....
1621
-	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u']))
1622
-		return array();
1663
+	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) {
1664
+			return array();
1665
+	}
1623 1666
 
1624 1667
 	// Make sure the id is a number and not "I like trying to hack the database".
1625 1668
 	$_GET['u'] = (int) $_GET['u'];
1626 1669
 	// Load the member's contextual information!
1627
-	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view'))
1628
-		return array();
1670
+	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) {
1671
+			return array();
1672
+	}
1629 1673
 
1630 1674
 	// Okay, I admit it, I'm lazy.  Stupid $_GET['u'] is long and hard to type.
1631 1675
 	$profile = &$memberContext[$_GET['u']];
@@ -1667,8 +1711,7 @@  discard block
 block discarded – undo
1667 1711
 				),
1668 1712
 			)
1669 1713
 		);
1670
-	}
1671
-	elseif ($xml_format == 'rdf')
1714
+	} elseif ($xml_format == 'rdf')
1672 1715
 	{
1673 1716
 		$data[] = array(
1674 1717
 			'tag' => 'item',
@@ -1692,8 +1735,7 @@  discard block
 block discarded – undo
1692 1735
 				),
1693 1736
 			)
1694 1737
 		);
1695
-	}
1696
-	elseif ($xml_format == 'atom')
1738
+	} elseif ($xml_format == 'atom')
1697 1739
 	{
1698 1740
 		$data[] = array(
1699 1741
 			'tag' => 'entry',
@@ -1746,8 +1788,7 @@  discard block
 block discarded – undo
1746 1788
 				),
1747 1789
 			)
1748 1790
 		);
1749
-	}
1750
-	else
1791
+	} else
1751 1792
 	{
1752 1793
 		$data = array(
1753 1794
 			array(
Please login to merge, or discard this patch.