Completed
Push — release-2.1 ( b69d19...5b73e8 )
by Michael
08:16
created
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/RequestMethod/Curl.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -32,43 +32,43 @@
 block discarded – undo
32 32
 class Curl
33 33
 {
34 34
 
35
-    /**
36
-     * @see http://php.net/curl_init
37
-     * @param string $url
38
-     * @return resource cURL handle
39
-     */
40
-    public function init($url = null)
41
-    {
42
-        return curl_init($url);
43
-    }
35
+	/**
36
+	 * @see http://php.net/curl_init
37
+	 * @param string $url
38
+	 * @return resource cURL handle
39
+	 */
40
+	public function init($url = null)
41
+	{
42
+		return curl_init($url);
43
+	}
44 44
 
45
-    /**
46
-     * @see http://php.net/curl_setopt_array
47
-     * @param resource $ch
48
-     * @param array $options
49
-     * @return bool
50
-     */
51
-    public function setoptArray($ch, array $options)
52
-    {
53
-        return curl_setopt_array($ch, $options);
54
-    }
45
+	/**
46
+	 * @see http://php.net/curl_setopt_array
47
+	 * @param resource $ch
48
+	 * @param array $options
49
+	 * @return bool
50
+	 */
51
+	public function setoptArray($ch, array $options)
52
+	{
53
+		return curl_setopt_array($ch, $options);
54
+	}
55 55
 
56
-    /**
57
-     * @see http://php.net/curl_exec
58
-     * @param resource $ch
59
-     * @return mixed
60
-     */
61
-    public function exec($ch)
62
-    {
63
-        return curl_exec($ch);
64
-    }
56
+	/**
57
+	 * @see http://php.net/curl_exec
58
+	 * @param resource $ch
59
+	 * @return mixed
60
+	 */
61
+	public function exec($ch)
62
+	{
63
+		return curl_exec($ch);
64
+	}
65 65
 
66
-    /**
67
-     * @see http://php.net/curl_close
68
-     * @param resource $ch
69
-     */
70
-    public function close($ch)
71
-    {
72
-        curl_close($ch);
73
-    }
66
+	/**
67
+	 * @see http://php.net/curl_close
68
+	 * @param resource $ch
69
+	 */
70
+	public function close($ch)
71
+	{
72
+		curl_close($ch);
73
+	}
74 74
 }
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/ReCaptcha.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -31,67 +31,67 @@
 block discarded – undo
31 31
  */
32 32
 class ReCaptcha
33 33
 {
34
-    /**
35
-     * Version of this client library.
36
-     * @const string
37
-     */
38
-    const VERSION = 'php_1.1.2';
34
+	/**
35
+	 * Version of this client library.
36
+	 * @const string
37
+	 */
38
+	const VERSION = 'php_1.1.2';
39 39
 
40
-    /**
41
-     * Shared secret for the site.
42
-     * @var type string
43
-     */
44
-    private $secret;
40
+	/**
41
+	 * Shared secret for the site.
42
+	 * @var type string
43
+	 */
44
+	private $secret;
45 45
 
46
-    /**
47
-     * Method used to communicate  with service. Defaults to POST request.
48
-     * @var RequestMethod
49
-     */
50
-    private $requestMethod;
46
+	/**
47
+	 * Method used to communicate  with service. Defaults to POST request.
48
+	 * @var RequestMethod
49
+	 */
50
+	private $requestMethod;
51 51
 
52
-    /**
53
-     * Create a configured instance to use the reCAPTCHA service.
54
-     *
55
-     * @param string $secret shared secret between site and reCAPTCHA server.
56
-     * @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
57
-     */
58
-    public function __construct($secret, RequestMethod $requestMethod = null)
59
-    {
60
-        if (empty($secret)) {
61
-            throw new \RuntimeException('No secret provided');
62
-        }
52
+	/**
53
+	 * Create a configured instance to use the reCAPTCHA service.
54
+	 *
55
+	 * @param string $secret shared secret between site and reCAPTCHA server.
56
+	 * @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
57
+	 */
58
+	public function __construct($secret, RequestMethod $requestMethod = null)
59
+	{
60
+		if (empty($secret)) {
61
+			throw new \RuntimeException('No secret provided');
62
+		}
63 63
 
64
-        if (!is_string($secret)) {
65
-            throw new \RuntimeException('The provided secret must be a string');
66
-        }
64
+		if (!is_string($secret)) {
65
+			throw new \RuntimeException('The provided secret must be a string');
66
+		}
67 67
 
68
-        $this->secret = $secret;
68
+		$this->secret = $secret;
69 69
 
70
-        if (!is_null($requestMethod)) {
71
-            $this->requestMethod = $requestMethod;
72
-        } else {
73
-            $this->requestMethod = new RequestMethod\Post();
74
-        }
75
-    }
70
+		if (!is_null($requestMethod)) {
71
+			$this->requestMethod = $requestMethod;
72
+		} else {
73
+			$this->requestMethod = new RequestMethod\Post();
74
+		}
75
+	}
76 76
 
77
-    /**
78
-     * Calls the reCAPTCHA siteverify API to verify whether the user passes
79
-     * CAPTCHA test.
80
-     *
81
-     * @param string $response The value of 'g-recaptcha-response' in the submitted form.
82
-     * @param string $remoteIp The end user's IP address.
83
-     * @return Response Response from the service.
84
-     */
85
-    public function verify($response, $remoteIp = null)
86
-    {
87
-        // Discard empty solution submissions
88
-        if (empty($response)) {
89
-            $recaptchaResponse = new Response(false, array('missing-input-response'));
90
-            return $recaptchaResponse;
91
-        }
77
+	/**
78
+	 * Calls the reCAPTCHA siteverify API to verify whether the user passes
79
+	 * CAPTCHA test.
80
+	 *
81
+	 * @param string $response The value of 'g-recaptcha-response' in the submitted form.
82
+	 * @param string $remoteIp The end user's IP address.
83
+	 * @return Response Response from the service.
84
+	 */
85
+	public function verify($response, $remoteIp = null)
86
+	{
87
+		// Discard empty solution submissions
88
+		if (empty($response)) {
89
+			$recaptchaResponse = new Response(false, array('missing-input-response'));
90
+			return $recaptchaResponse;
91
+		}
92 92
 
93
-        $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
94
-        $rawResponse = $this->requestMethod->submit($params);
95
-        return Response::fromJson($rawResponse);
96
-    }
93
+		$params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
94
+		$rawResponse = $this->requestMethod->submit($params);
95
+		return Response::fromJson($rawResponse);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Sources/CacheAPI-sqlite.php 2 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * SQLite Cache API class
@@ -153,8 +154,7 @@  discard block
 block discarded – undo
153 154
 		if (is_null($dir) || !is_writable($dir))
154 155
 		{
155 156
 			$this->cachedir = $cachedir_sqlite;
156
-		}
157
-		else
157
+		} else
158 158
 		{
159 159
 			$this->cachedir = $dir;
160 160
 		}
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
 	 *
144 144
 	 * @param string $dir A valid path
145 145
 	 *
146
-	 * @return boolean If this was successful or not.
146
+	 * @return boolean|null If this was successful or not.
147 147
 	 */
148 148
 	public function setCachedir($dir = null)
149 149
 	{
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * Display a list of upcoming events, birthdays, and holidays.
69 69
  *
70 70
  * @param string $grid_name The grid name
71
- * @return void|bool Returns false if the grid doesn't exist.
71
+ * @return false|null Returns false if the grid doesn't exist.
72 72
  */
73 73
 function template_show_upcoming_list($grid_name)
74 74
 {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  *
239 239
  * @param string $grid_name The grid name
240 240
  * @param bool $is_mini Is this a mini grid?
241
- * @return void|bool Returns false if the grid doesn't exist.
241
+ * @return false|null Returns false if the grid doesn't exist.
242 242
  */
243 243
 function template_show_month_grid($grid_name, $is_mini = false)
244 244
 {
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
  * Shows a weekly grid
524 524
  *
525 525
  * @param string $grid_name The name of the grid
526
- * @return void|bool Returns false if the grid doesn't exist
526
+ * @return false|null Returns false if the grid doesn't exist
527 527
  */
528 528
 function template_show_week_grid($grid_name)
529 529
 {
Please login to merge, or discard this patch.
Braces   +152 added lines, -116 removed lines patch added patch discarded remove patch
@@ -40,16 +40,14 @@  discard block
 block discarded – undo
40 40
 				', template_show_upcoming_list('main'), '
41 41
 			</div>
42 42
 		';
43
-	}
44
-	elseif ($context['calendar_view'] == 'view_week')
43
+	} elseif ($context['calendar_view'] == 'view_week')
45 44
 	{
46 45
 		echo '
47 46
 			<div id="main_grid">
48 47
 				', template_show_week_grid('main'), '
49 48
 			</div>
50 49
 		';
51
-	}
52
-	else
50
+	} else
53 51
 	{
54 52
 		echo '
55 53
 			<div id="main_grid">
@@ -75,8 +73,9 @@  discard block
 block discarded – undo
75 73
 	global $context, $scripturl, $txt, $modSettings;
76 74
 
77 75
 	// Bail out if we have nothing to work with
78
-	if (!isset($context['calendar_grid_' . $grid_name]))
79
-		return false;
76
+	if (!isset($context['calendar_grid_' . $grid_name])) {
77
+			return false;
78
+	}
80 79
 
81 80
 	// Protect programmer sanity
82 81
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -113,11 +112,13 @@  discard block
 block discarded – undo
113 112
 					<li class="windowbg">
114 113
 						<b class="event_title">', $event['link'], '</b>';
115 114
 
116
-				if ($event['can_edit'])
117
-					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
115
+				if ($event['can_edit']) {
116
+									echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
117
+				}
118 118
 
119
-				if ($event['can_export'])
120
-					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
119
+				if ($event['can_export']) {
120
+									echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
121
+				}
121 122
 
122 123
 				echo '
123 124
 						<br>';
@@ -125,14 +126,14 @@  discard block
 block discarded – undo
125 126
 				if (!empty($event['allday']))
126 127
 				{
127 128
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
128
-				}
129
-				else
129
+				} else
130 130
 				{
131 131
 					// Display event info relative to user's local timezone
132 132
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
133 133
 
134
-					if ($event['start_date_local'] != $event['end_date_local'])
135
-						echo trim($event['end_date_local']) . ', ';
134
+					if ($event['start_date_local'] != $event['end_date_local']) {
135
+											echo trim($event['end_date_local']) . ', ';
136
+					}
136 137
 
137 138
 					echo trim($event['end_time_local']);
138 139
 
@@ -141,23 +142,27 @@  discard block
 block discarded – undo
141 142
 					{
142 143
 						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
143 144
 
144
-						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
145
-							echo trim($event['start_date_orig']), ', ';
145
+						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
146
+													echo trim($event['start_date_orig']), ', ';
147
+						}
146 148
 
147 149
 						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
148 150
 
149
-						if ($event['start_date_orig'] != $event['end_date_orig'])
150
-							echo trim($event['end_date_orig']) . ', ';
151
+						if ($event['start_date_orig'] != $event['end_date_orig']) {
152
+													echo trim($event['end_date_orig']) . ', ';
153
+						}
151 154
 
152 155
 						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
153 156
 					}
154 157
 					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
155
-					else
156
-						echo ' ', $event['tz_abbrev'], '</time>';
158
+					else {
159
+											echo ' ', $event['tz_abbrev'], '</time>';
160
+					}
157 161
 				}
158 162
 
159
-				if (!empty($event['location']))
160
-					echo '<br>', $event['location'];
163
+				if (!empty($event['location'])) {
164
+									echo '<br>', $event['location'];
165
+				}
161 166
 
162 167
 				echo '
163 168
 					</li>';
@@ -189,8 +194,9 @@  discard block
 block discarded – undo
189 194
 
190 195
 			$birthdays = array();
191 196
 
192
-			foreach ($date as $member)
193
-				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
197
+			foreach ($date as $member) {
198
+							$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
199
+			}
194 200
 
195 201
 			echo implode(', ', $birthdays);
196 202
 
@@ -221,8 +227,9 @@  discard block
 block discarded – undo
221 227
 			$date_local = $date['date_local'];
222 228
 			unset($date['date_local']);
223 229
 
224
-			foreach ($date as $holiday)
225
-				$holidays[] = $holiday . ' (' . $date_local . ')';
230
+			foreach ($date as $holiday) {
231
+							$holidays[] = $holiday . ' (' . $date_local . ')';
232
+			}
226 233
 		}
227 234
 
228 235
 		echo implode(', ', $holidays);
@@ -245,17 +252,19 @@  discard block
 block discarded – undo
245 252
 	global $context, $settings, $txt, $scripturl, $modSettings;
246 253
 
247 254
 	// If the grid doesn't exist, no point in proceeding.
248
-	if (!isset($context['calendar_grid_' . $grid_name]))
249
-		return false;
255
+	if (!isset($context['calendar_grid_' . $grid_name])) {
256
+			return false;
257
+	}
250 258
 
251 259
 	// A handy little pointer variable.
252 260
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
253 261
 
254 262
 	// Some conditions for whether or not we should show the week links *here*.
255
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
256
-		$show_week_links = true;
257
-	else
258
-		$show_week_links = false;
263
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
264
+			$show_week_links = true;
265
+	} else {
266
+			$show_week_links = false;
267
+	}
259 268
 
260 269
 	// Assuming that we've not disabled it, show the title block!
261 270
 	if (empty($calendar_data['disable_title']))
@@ -294,8 +303,9 @@  discard block
 block discarded – undo
294 303
 	}
295 304
 
296 305
 	// Show the controls on main grids
297
-	if ($is_mini === false)
298
-		template_calendar_top($calendar_data);
306
+	if ($is_mini === false) {
307
+			template_calendar_top($calendar_data);
308
+	}
299 309
 
300 310
 	// Finally, the main calendar table.
301 311
 	echo '<table class="calendar_table">';
@@ -306,8 +316,9 @@  discard block
 block discarded – undo
306 316
 		echo '<tr>';
307 317
 
308 318
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
309
-		if ($show_week_links === true)
310
-			echo '<th>&nbsp;</th>';
319
+		if ($show_week_links === true) {
320
+					echo '<th>&nbsp;</th>';
321
+		}
311 322
 
312 323
 		// Now, loop through each actual day of the week.
313 324
 		foreach ($calendar_data['week_days'] as $day)
@@ -354,27 +365,29 @@  discard block
 block discarded – undo
354 365
 				// Additional classes are given for events, holidays, and birthdays.
355 366
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
356 367
 				{
357
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
358
-						$classes[] = 'events';
359
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
360
-						$classes[] = 'events';
368
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) {
369
+											$classes[] = 'events';
370
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) {
371
+											$classes[] = 'events';
372
+					}
361 373
 				}
362 374
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
363 375
 				{
364
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
365
-						$classes[] = 'holidays';
366
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
367
-						$classes[] = 'holidays';
376
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) {
377
+											$classes[] = 'holidays';
378
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) {
379
+											$classes[] = 'holidays';
380
+					}
368 381
 				}
369 382
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
370 383
 				{
371
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
372
-						$classes[] = 'birthdays';
373
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
374
-						$classes[] = 'birthdays';
384
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) {
385
+											$classes[] = 'birthdays';
386
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) {
387
+											$classes[] = 'birthdays';
388
+					}
375 389
 				}
376
-			}
377
-			else
390
+			} else
378 391
 			{
379 392
 				// Default Classes (either compact or comfortable and disabled).
380 393
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
@@ -392,17 +405,19 @@  discard block
 block discarded – undo
392 405
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
393 406
 
394 407
 				// The actual day number - be it a link, or just plain old text!
395
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
396
-					echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
397
-				else
398
-					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
408
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
409
+									echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
410
+				} else {
411
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
412
+				}
399 413
 
400 414
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
401 415
 				if ($is_mini === false)
402 416
 				{
403 417
 					// Holidays are always fun, let's show them!
404
-					if (!empty($day['holidays']))
405
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
418
+					if (!empty($day['holidays'])) {
419
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
420
+					}
406 421
 
407 422
 					// Happy Birthday Dear, Member!
408 423
 					if (!empty($day['birthdays']))
@@ -420,14 +435,16 @@  discard block
 block discarded – undo
420 435
 							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
421 436
 
422 437
 							// 9...10! Let's stop there.
423
-							if ($birthday_count == 10 && $use_js_hide)
424
-								// !!TODO - Inline CSS and JavaScript should be moved.
438
+							if ($birthday_count == 10 && $use_js_hide) {
439
+															// !!TODO - Inline CSS and JavaScript should be moved.
425 440
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
441
+							}
426 442
 
427 443
 							++$birthday_count;
428 444
 						}
429
-						if ($use_js_hide)
430
-							echo '</span>';
445
+						if ($use_js_hide) {
446
+													echo '</span>';
447
+						}
431 448
 
432 449
 						echo '</div>';
433 450
 					}
@@ -437,8 +454,9 @@  discard block
 block discarded – undo
437 454
 					{
438 455
 						// Sort events by start time (all day events will be listed first)
439 456
 						uasort($day['events'], function($a, $b) {
440
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
441
-						        return 0;
457
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
458
+						    						        return 0;
459
+						    }
442 460
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
443 461
 						});
444 462
 
@@ -454,17 +472,19 @@  discard block
 block discarded – undo
454 472
 
455 473
 							echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
456 474
 
457
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
458
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
459
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
460
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
461
-							elseif (!empty($event['allday']))
462
-								echo $txt['calendar_allday'];
475
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
476
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
477
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
478
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
479
+							} elseif (!empty($event['allday'])) {
480
+															echo $txt['calendar_allday'];
481
+							}
463 482
 
464 483
 							echo '</span>';
465 484
 
466
-							if (!empty($event['location']))
467
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
485
+							if (!empty($event['location'])) {
486
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
487
+							}
468 488
 
469 489
 							if ($event['can_edit'] || $event['can_export'])
470 490
 							{
@@ -501,10 +521,11 @@  discard block
 block discarded – undo
501 521
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
502 522
 			elseif ($is_mini === false)
503 523
 			{
504
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
505
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
506
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
507
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
524
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
525
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
526
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
527
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
528
+				}
508 529
 			}
509 530
 
510 531
 			// Close this day and increase var count.
@@ -530,8 +551,9 @@  discard block
 block discarded – undo
530 551
 	global $context, $settings, $txt, $scripturl, $modSettings;
531 552
 
532 553
 	// We might have no reason to proceed, if the variable isn't there.
533
-	if (!isset($context['calendar_grid_' . $grid_name]))
534
-		return false;
554
+	if (!isset($context['calendar_grid_' . $grid_name])) {
555
+			return false;
556
+	}
535 557
 
536 558
 	// Handy pointer.
537 559
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -567,8 +589,9 @@  discard block
 block discarded – undo
567 589
 					}
568 590
 
569 591
 					// The Month Title + Week Number...
570
-					if (!empty($calendar_data['week_title']))
571
-							echo $calendar_data['week_title'];
592
+					if (!empty($calendar_data['week_title'])) {
593
+												echo $calendar_data['week_title'];
594
+					}
572 595
 
573 596
 					echo '
574 597
 					</h3>
@@ -607,10 +630,11 @@  discard block
 block discarded – undo
607 630
 						<tr class="days_wrapper">
608 631
 							<td class="', implode(' ', $classes), ' act_day">';
609 632
 							// Should the day number be a link?
610
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
611
-								echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
612
-							else
613
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
633
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
634
+															echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
635
+							} else {
636
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
637
+							}
614 638
 
615 639
 							echo '</td>
616 640
 							<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
@@ -619,8 +643,9 @@  discard block
 block discarded – undo
619 643
 							{
620 644
 								// Sort events by start time (all day events will be listed first)
621 645
 								uasort($day['events'], function($a, $b) {
622
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
623
-								        return 0;
646
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
647
+								    								        return 0;
648
+								    }
624 649
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
625 650
 								});
626 651
 
@@ -632,15 +657,17 @@  discard block
 block discarded – undo
632 657
 
633 658
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
634 659
 
635
-									if (!empty($event['start_time_local']))
636
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
637
-									else
638
-										echo $txt['calendar_allday'];
660
+									if (!empty($event['start_time_local'])) {
661
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
662
+									} else {
663
+																			echo $txt['calendar_allday'];
664
+									}
639 665
 
640 666
 									echo '</span>';
641 667
 
642
-									if (!empty($event['location']))
643
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
668
+									if (!empty($event['location'])) {
669
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
670
+									}
644 671
 
645 672
 									if (!empty($event_icons_needed))
646 673
 									{
@@ -677,8 +704,7 @@  discard block
 block discarded – undo
677 704
 									</div>
678 705
 									<br class="clear">';
679 706
 								}
680
-							}
681
-							else
707
+							} else
682 708
 							{
683 709
 								if (!empty($context['can_post']))
684 710
 								{
@@ -691,8 +717,9 @@  discard block
 block discarded – undo
691 717
 							echo '</td>
692 718
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
693 719
 							// Show any holidays!
694
-							if (!empty($day['holidays']))
695
-								echo implode('<br>', $day['holidays']);
720
+							if (!empty($day['holidays'])) {
721
+															echo implode('<br>', $day['holidays']);
722
+							}
696 723
 
697 724
 							echo '</td>
698 725
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -750,8 +777,7 @@  discard block
 block discarded – undo
750 777
 				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date">
751 778
 				<input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '">
752 779
 			</form>';
753
-	}
754
-	else
780
+	} else
755 781
 	{
756 782
 		echo'
757 783
 			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
@@ -793,8 +819,9 @@  discard block
 block discarded – undo
793 819
 	echo '
794 820
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
795 821
 
796
-	if (!empty($context['event']['new']))
797
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
822
+	if (!empty($context['event']['new'])) {
823
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
824
+	}
798 825
 
799 826
 	// Start the main table.
800 827
 	echo '
@@ -844,9 +871,10 @@  discard block
 block discarded – undo
844 871
 		{
845 872
 			echo '
846 873
 								<optgroup label="', $category['name'], '">';
847
-			foreach ($category['boards'] as $board)
848
-				echo '
874
+			foreach ($category['boards'] as $board) {
875
+							echo '
849 876
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
877
+			}
850 878
 			echo '
851 879
 								</optgroup>';
852 880
 		}
@@ -882,9 +910,10 @@  discard block
 block discarded – undo
882 910
 							<span class="label">', $txt['calendar_timezone'], '</span>
883 911
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
884 912
 
885
-	foreach ($context['all_timezones'] as $tz => $tzname)
886
-		echo '
913
+	foreach ($context['all_timezones'] as $tz => $tzname) {
914
+			echo '
887 915
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
916
+	}
888 917
 
889 918
 	echo '
890 919
 							</select>
@@ -899,9 +928,10 @@  discard block
 block discarded – undo
899 928
 	echo '
900 929
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
901 930
 	// Delete button?
902
-	if (empty($context['event']['new']))
903
-		echo '
931
+	if (empty($context['event']['new'])) {
932
+			echo '
904 933
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
934
+	}
905 935
 
906 936
 	echo '
907 937
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -945,9 +975,10 @@  discard block
 block discarded – undo
945 975
 
946 976
 		foreach ($context['clockicons'] as $t => $v)
947 977
 		{
948
-			foreach ($v as $i)
949
-				echo '
978
+			foreach ($v as $i) {
979
+							echo '
950 980
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
981
+			}
951 982
 		}
952 983
 
953 984
 		echo '
@@ -972,13 +1003,14 @@  discard block
 block discarded – undo
972 1003
 
973 1004
 		foreach ($context['clockicons'] as $t => $v)
974 1005
 		{
975
-			foreach ($v as $i)
976
-				echo '
1006
+			foreach ($v as $i) {
1007
+							echo '
977 1008
 			if (', $t, ' >= ', $i, ')
978 1009
 			{
979 1010
 				turnon.push("', $t, '_', $i, '");
980 1011
 				', $t, ' -= ', $i, ';
981 1012
 			}';
1013
+			}
982 1014
 		}
983 1015
 
984 1016
 		echo '
@@ -1042,9 +1074,10 @@  discard block
 block discarded – undo
1042 1074
 
1043 1075
 	foreach ($context['clockicons'] as $t => $v)
1044 1076
 	{
1045
-		foreach ($v as $i)
1046
-			echo '
1077
+		foreach ($v as $i) {
1078
+					echo '
1047 1079
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1080
+		}
1048 1081
 	}
1049 1082
 
1050 1083
 	echo '
@@ -1061,13 +1094,14 @@  discard block
 block discarded – undo
1061 1094
 
1062 1095
 	foreach ($context['clockicons'] as $t => $v)
1063 1096
 	{
1064
-		foreach ($v as $i)
1065
-			echo '
1097
+		foreach ($v as $i) {
1098
+					echo '
1066 1099
 		if (', $t, ' >= ', $i, ')
1067 1100
 		{
1068 1101
 			turnon.push("', $t, '_', $i, '");
1069 1102
 			', $t, ' -= ', $i, ';
1070 1103
 		}';
1104
+		}
1071 1105
 	}
1072 1106
 
1073 1107
 	echo '
@@ -1126,9 +1160,10 @@  discard block
 block discarded – undo
1126 1160
 
1127 1161
 	foreach ($context['clockicons'] as $t => $v)
1128 1162
 	{
1129
-		foreach ($v as $i)
1130
-			echo '
1163
+		foreach ($v as $i) {
1164
+					echo '
1131 1165
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1166
+		}
1132 1167
 	}
1133 1168
 
1134 1169
 	echo '
@@ -1149,13 +1184,14 @@  discard block
 block discarded – undo
1149 1184
 
1150 1185
 	foreach ($context['clockicons'] as $t => $v)
1151 1186
 	{
1152
-		foreach ($v as $i)
1153
-		echo '
1187
+		foreach ($v as $i) {
1188
+				echo '
1154 1189
 		if (', $t, ' >= ', $i, ')
1155 1190
 		{
1156 1191
 			turnon.push("', $t, '_', $i, '");
1157 1192
 			', $t, ' -= ', $i, ';
1158 1193
 		}';
1194
+		}
1159 1195
 	}
1160 1196
 
1161 1197
 	echo '
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -437,9 +437,9 @@  discard block
 block discarded – undo
437 437
 					{
438 438
 						// Sort events by start time (all day events will be listed first)
439 439
 						uasort($day['events'], function($a, $b) {
440
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
441
-						        return 0;
442
-						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
440
+							if ($a['start_timestamp'] == $b['start_timestamp'])
441
+								return 0;
442
+							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
443 443
 						});
444 444
 
445 445
 						echo '
@@ -619,9 +619,9 @@  discard block
 block discarded – undo
619 619
 							{
620 620
 								// Sort events by start time (all day events will be listed first)
621 621
 								uasort($day['events'], function($a, $b) {
622
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
623
-								        return 0;
624
-								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
622
+									if ($a['start_timestamp'] == $b['start_timestamp'])
623
+										return 0;
624
+									return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
625 625
 								});
626 626
 
627 627
 								foreach ($day['events'] as $event)
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
@@ -388,6 +388,9 @@  discard block
 block discarded – undo
388 388
 }
389 389
 
390 390
 // Used to direct the user to another location.
391
+/**
392
+ * @param string $location
393
+ */
391 394
 function redirectLocation($location, $addForm = true)
392 395
 {
393 396
 	global $upgradeurl, $upcontext, $command_line;
@@ -1560,6 +1563,9 @@  discard block
 block discarded – undo
1560 1563
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1561 1564
 }
1562 1565
 
1566
+/**
1567
+ * @param string $filename
1568
+ */
1563 1569
 function parse_sql($filename)
1564 1570
 {
1565 1571
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -1594,6 +1600,10 @@  discard block
 block discarded – undo
1594 1600
 
1595 1601
 	// Our custom error handler - does nothing but does stop public errors from XML!
1596 1602
 	set_error_handler(
1603
+
1604
+		/**
1605
+		 * @param string $errno
1606
+		 */
1597 1607
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1598 1608
 		{
1599 1609
 			if ($support_js)
@@ -1840,6 +1850,9 @@  discard block
 block discarded – undo
1840 1850
 	return true;
1841 1851
 }
1842 1852
 
1853
+/**
1854
+ * @param string $string
1855
+ */
1843 1856
 function upgrade_query($string, $unbuffered = false)
1844 1857
 {
1845 1858
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4495,7 +4508,7 @@  discard block
 block discarded – undo
4495 4508
  * @param int $setSize The amount of entries after which to update the database.
4496 4509
  *
4497 4510
  * newCol needs to be a varbinary(16) null able field
4498
- * @return bool
4511
+ * @return boolean|null
4499 4512
  */
4500 4513
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4501 4514
 {
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
@@ -1626,7 +1626,7 @@  discard block
 block discarded – undo
1626 1626
 
1627 1627
 	// Our custom error handler - does nothing but does stop public errors from XML!
1628 1628
 	set_error_handler(
1629
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1629
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1630 1630
 		{
1631 1631
 			if ($support_js)
1632 1632
 				return true;
@@ -2643,94 +2643,94 @@  discard block
 block discarded – undo
2643 2643
 		// Translation table for the character sets not native for MySQL.
2644 2644
 		$translation_tables = array(
2645 2645
 			'windows-1255' => array(
2646
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2647
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2648
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2649
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2650
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2651
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2652
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2653
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2654
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2655
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2656
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2657
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2658
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2659
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2660
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2661
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2662
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2663
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2664
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2665
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2666
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2667
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2668
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2669
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2670
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2671
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2672
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2673
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2674
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2675
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2676
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2677
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2678
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2679
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2680
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2681
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2682
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2683
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2684
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2685
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2686
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2687
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2646
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2647
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2648
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2649
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2650
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2651
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2652
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2653
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2654
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2655
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2656
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2657
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2658
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2659
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2660
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2661
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2662
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2663
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2664
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2665
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2666
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2667
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2668
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2669
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2670
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2671
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2672
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2673
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2674
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2675
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2676
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2677
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2678
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2679
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2680
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2681
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2682
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2683
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2684
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2685
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2686
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2687
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2688 2688
 				'0xFA' => '0xD7AA',
2689 2689
 			),
2690 2690
 			'windows-1253' => array(
2691
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2692
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2693
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2694
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2695
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2696
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2697
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2698
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2699
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2700
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2701
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2702
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2703
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2704
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2705
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2706
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2707
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2708
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2709
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2710
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2711
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2712
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2713
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2714
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2715
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2716
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2717
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2718
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2719
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2720
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2721
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2722
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2723
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2724
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2725
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2726
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2727
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2728
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2729
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2730
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2731
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2732
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2733
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2691
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2692
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2693
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2694
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2695
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2696
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2697
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2698
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2699
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2700
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2701
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2702
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2703
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2704
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2705
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2706
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2707
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2708
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2709
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2710
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2711
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2712
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2713
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2714
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2715
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2716
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2717
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2718
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2719
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2720
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2721
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2722
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2723
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2724
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2725
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2726
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2727
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2728
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2729
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2730
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2731
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2732
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2733
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2734 2734
 			),
2735 2735
 		);
2736 2736
 
@@ -3829,7 +3829,7 @@  discard block
 block discarded – undo
3829 3829
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
3830 3830
 			<input type="hidden" name="backup_done" id="backup_done" value="0">
3831 3831
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
3832
-			<div id="debug_section" style="height: ', ($is_debug ? '195' : '12') , 'px; overflow: auto;">
3832
+			<div id="debug_section" style="height: ', ($is_debug ? '195' : '12'), 'px; overflow: auto;">
3833 3833
 			<span id="debuginfo"></span>
3834 3834
 			</div>';
3835 3835
 
@@ -4330,7 +4330,7 @@  discard block
 block discarded – undo
4330 4330
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4331 4331
 			<input type="hidden" name="utf8_done" id="utf8_done" value="0">
4332 4332
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4333
-			<div id="debug_section" style="height: ', ($is_debug ? '195' : '12') , 'px; overflow: auto;">
4333
+			<div id="debug_section" style="height: ', ($is_debug ? '195' : '12'), 'px; overflow: auto;">
4334 4334
 			<span id="debuginfo"></span>
4335 4335
 			</div>';
4336 4336
 
@@ -4427,7 +4427,7 @@  discard block
 block discarded – undo
4427 4427
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4428 4428
 			<input type="hidden" name="json_done" id="json_done" value="0">
4429 4429
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4430
-			<div id="debug_section" style="height: ', ($is_debug ? '195' : '12') , 'px; overflow: auto;">
4430
+			<div id="debug_section" style="height: ', ($is_debug ? '195' : '12'), 'px; overflow: auto;">
4431 4431
 			<span id="debuginfo"></span>
4432 4432
 			</div>';
4433 4433
 
Please login to merge, or discard this patch.
Braces   +887 added lines, -650 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
 $upcontext['inactive_timeout'] = 10;
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
84
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
85 85
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
86
+}
86 87
 
87 88
 require_once($upgrade_path . '/upgrade-helper.php');
88 89
 
@@ -106,11 +107,14 @@  discard block
 block discarded – undo
106 107
 	ini_set('default_socket_timeout', 900);
107 108
 }
108 109
 // Clean the upgrade path if this is from the client.
109
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
110
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
110
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
111
+	for ($i = 1;
112
+}
113
+$i < $_SERVER['argc']; $i++)
111 114
 	{
112
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
113
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
115
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
116
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
117
+		}
114 118
 	}
115 119
 
116 120
 // Are we from the client?
@@ -118,16 +122,17 @@  discard block
 block discarded – undo
118 122
 {
119 123
 	$command_line = true;
120 124
 	$disable_security = true;
121
-}
122
-else
125
+} else {
123 126
 	$command_line = false;
127
+}
124 128
 
125 129
 // Load this now just because we can.
126 130
 require_once($upgrade_path . '/Settings.php');
127 131
 
128 132
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
129
-if (isset($language))
133
+if (isset($language)) {
130 134
 	$language = str_ireplace('-utf8', '', $language);
135
+}
131 136
 
132 137
 // Are we logged in?
133 138
 if (isset($upgradeData))
@@ -135,10 +140,12 @@  discard block
 block discarded – undo
135 140
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
136 141
 
137 142
 	// Check for sensible values.
138
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
139
-		$upcontext['user']['started'] = time();
140
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
141
-		$upcontext['user']['updated'] = 0;
143
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
144
+			$upcontext['user']['started'] = time();
145
+	}
146
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
147
+			$upcontext['user']['updated'] = 0;
148
+	}
142 149
 
143 150
 	$upcontext['started'] = $upcontext['user']['started'];
144 151
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -196,8 +203,9 @@  discard block
 block discarded – undo
196 203
 			'db_error_skip' => true,
197 204
 		)
198 205
 	);
199
-	while ($row = $smcFunc['db_fetch_assoc']($request))
200
-		$modSettings[$row['variable']] = $row['value'];
206
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
207
+			$modSettings[$row['variable']] = $row['value'];
208
+	}
201 209
 	$smcFunc['db_free_result']($request);
202 210
 }
203 211
 
@@ -207,10 +215,12 @@  discard block
 block discarded – undo
207 215
 	$modSettings['theme_url'] = 'Themes/default';
208 216
 	$modSettings['images_url'] = 'Themes/default/images';
209 217
 }
210
-if (!isset($settings['default_theme_url']))
218
+if (!isset($settings['default_theme_url'])) {
211 219
 	$settings['default_theme_url'] = $modSettings['theme_url'];
212
-if (!isset($settings['default_theme_dir']))
220
+}
221
+if (!isset($settings['default_theme_dir'])) {
213 222
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
223
+}
214 224
 
215 225
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
216 226
 // Default title...
@@ -228,13 +238,15 @@  discard block
 block discarded – undo
228 238
 	$support_js = $upcontext['upgrade_status']['js'];
229 239
 
230 240
 	// Only set this if the upgrader status says so.
231
-	if (empty($is_debug))
232
-		$is_debug = $upcontext['upgrade_status']['debug'];
241
+	if (empty($is_debug)) {
242
+			$is_debug = $upcontext['upgrade_status']['debug'];
243
+	}
233 244
 
234 245
 	// Load the language.
235
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
236
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
237
-}
246
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
247
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
248
+	}
249
+	}
238 250
 // Set the defaults.
239 251
 else
240 252
 {
@@ -252,15 +264,18 @@  discard block
 block discarded – undo
252 264
 }
253 265
 
254 266
 // If this isn't the first stage see whether they are logging in and resuming.
255
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
267
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
256 268
 	checkLogin();
269
+}
257 270
 
258
-if ($command_line)
271
+if ($command_line) {
259 272
 	cmdStep0();
273
+}
260 274
 
261 275
 // Don't error if we're using xml.
262
-if (isset($_GET['xml']))
276
+if (isset($_GET['xml'])) {
263 277
 	$upcontext['return_error'] = true;
278
+}
264 279
 
265 280
 // Loop through all the steps doing each one as required.
266 281
 $upcontext['overall_percent'] = 0;
@@ -281,9 +296,9 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 
283 298
 		// Call the step and if it returns false that means pause!
284
-		if (function_exists($step[2]) && $step[2]() === false)
285
-			break;
286
-		elseif (function_exists($step[2])) {
299
+		if (function_exists($step[2]) && $step[2]() === false) {
300
+					break;
301
+		} elseif (function_exists($step[2])) {
287 302
 			//Start each new step with this unset, so the 'normal' template is called first
288 303
 			unset($_GET['xml']);
289 304
 			$_GET['substep'] = 0;
@@ -327,17 +342,18 @@  discard block
 block discarded – undo
327 342
 		// This should not happen my dear... HELP ME DEVELOPERS!!
328 343
 		if (!empty($command_line))
329 344
 		{
330
-			if (function_exists('debug_print_backtrace'))
331
-				debug_print_backtrace();
345
+			if (function_exists('debug_print_backtrace')) {
346
+							debug_print_backtrace();
347
+			}
332 348
 
333 349
 			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.';
334 350
 			flush();
335 351
 			die();
336 352
 		}
337 353
 
338
-		if (!isset($_GET['xml']))
339
-			template_upgrade_above();
340
-		else
354
+		if (!isset($_GET['xml'])) {
355
+					template_upgrade_above();
356
+		} else
341 357
 		{
342 358
 			header('Content-Type: text/xml; charset=UTF-8');
343 359
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -359,25 +375,29 @@  discard block
 block discarded – undo
359 375
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
360 376
 
361 377
 			// Custom stuff to pass back?
362
-			if (!empty($upcontext['query_string']))
363
-				$upcontext['form_url'] .= $upcontext['query_string'];
378
+			if (!empty($upcontext['query_string'])) {
379
+							$upcontext['form_url'] .= $upcontext['query_string'];
380
+			}
364 381
 
365 382
 			// Call the appropriate subtemplate
366
-			if (is_callable('template_' . $upcontext['sub_template']))
367
-				call_user_func('template_' . $upcontext['sub_template']);
368
-			else
369
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
383
+			if (is_callable('template_' . $upcontext['sub_template'])) {
384
+							call_user_func('template_' . $upcontext['sub_template']);
385
+			} else {
386
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
387
+			}
370 388
 		}
371 389
 
372 390
 		// Was there an error?
373
-		if (!empty($upcontext['forced_error_message']))
374
-			echo $upcontext['forced_error_message'];
391
+		if (!empty($upcontext['forced_error_message'])) {
392
+					echo $upcontext['forced_error_message'];
393
+		}
375 394
 
376 395
 		// Show the footer.
377
-		if (!isset($_GET['xml']))
378
-			template_upgrade_below();
379
-		else
380
-			template_xml_below();
396
+		if (!isset($_GET['xml'])) {
397
+					template_upgrade_below();
398
+		} else {
399
+					template_xml_below();
400
+		}
381 401
 	}
382 402
 
383 403
 
@@ -389,15 +409,19 @@  discard block
 block discarded – undo
389 409
 		$seconds = intval($active % 60);
390 410
 
391 411
 		$totalTime = '';
392
-		if ($hours > 0)
393
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
394
-		if ($minutes > 0)
395
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
396
-		if ($seconds > 0)
397
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
412
+		if ($hours > 0) {
413
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
414
+		}
415
+		if ($minutes > 0) {
416
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
417
+		}
418
+		if ($seconds > 0) {
419
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
420
+		}
398 421
 
399
-		if (!empty($totalTime))
400
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
422
+		if (!empty($totalTime)) {
423
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
424
+		}
401 425
 	}
402 426
 
403 427
 	// Bang - gone!
@@ -410,8 +434,9 @@  discard block
 block discarded – undo
410 434
 	global $upgradeurl, $upcontext, $command_line;
411 435
 
412 436
 	// Command line users can't be redirected.
413
-	if ($command_line)
414
-		upgradeExit(true);
437
+	if ($command_line) {
438
+			upgradeExit(true);
439
+	}
415 440
 
416 441
 	// Are we providing the core info?
417 442
 	if ($addForm)
@@ -434,19 +459,22 @@  discard block
 block discarded – undo
434 459
 	global $modSettings, $sourcedir, $smcFunc;
435 460
 
436 461
 	// Do the non-SSI stuff...
437
-	if (function_exists('set_magic_quotes_runtime'))
438
-		@set_magic_quotes_runtime(0);
462
+	if (function_exists('set_magic_quotes_runtime')) {
463
+			@set_magic_quotes_runtime(0);
464
+	}
439 465
 
440 466
 	error_reporting(E_ALL);
441 467
 	define('SMF', 1);
442 468
 
443 469
 	// Start the session.
444
-	if (@ini_get('session.save_handler') == 'user')
445
-		@ini_set('session.save_handler', 'files');
470
+	if (@ini_get('session.save_handler') == 'user') {
471
+			@ini_set('session.save_handler', 'files');
472
+	}
446 473
 	@session_start();
447 474
 
448
-	if (empty($smcFunc))
449
-		$smcFunc = array();
475
+	if (empty($smcFunc)) {
476
+			$smcFunc = array();
477
+	}
450 478
 
451 479
 	// We need this for authentication and some upgrade code
452 480
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -458,32 +486,36 @@  discard block
 block discarded – undo
458 486
 	initialize_inputs();
459 487
 
460 488
 	// Get the database going!
461
-	if (empty($db_type) || $db_type == 'mysqli')
462
-		$db_type = 'mysql';
489
+	if (empty($db_type) || $db_type == 'mysqli') {
490
+			$db_type = 'mysql';
491
+	}
463 492
 
464 493
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
465 494
 	{
466 495
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
467 496
 
468 497
 		// Make the connection...
469
-		if (empty($db_connection))
470
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
471
-		else
472
-			// If we've returned here, ping/reconnect to be safe
498
+		if (empty($db_connection)) {
499
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
500
+		} else {
501
+					// If we've returned here, ping/reconnect to be safe
473 502
 			$smcFunc['db_ping']($db_connection);
503
+		}
474 504
 
475 505
 		// Oh dear god!!
476
-		if ($db_connection === null)
477
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
506
+		if ($db_connection === null) {
507
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
508
+		}
478 509
 
479
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
480
-			$smcFunc['db_query']('', '
510
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
511
+					$smcFunc['db_query']('', '
481 512
 			SET NAMES {string:db_character_set}',
482 513
 			array(
483 514
 				'db_error_skip' => true,
484 515
 				'db_character_set' => $db_character_set,
485 516
 			)
486 517
 		);
518
+		}
487 519
 
488 520
 		// Load the modSettings data...
489 521
 		$request = $smcFunc['db_query']('', '
@@ -494,11 +526,11 @@  discard block
 block discarded – undo
494 526
 			)
495 527
 		);
496 528
 		$modSettings = array();
497
-		while ($row = $smcFunc['db_fetch_assoc']($request))
498
-			$modSettings[$row['variable']] = $row['value'];
529
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
530
+					$modSettings[$row['variable']] = $row['value'];
531
+		}
499 532
 		$smcFunc['db_free_result']($request);
500
-	}
501
-	else
533
+	} else
502 534
 	{
503 535
 		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.');
504 536
 	}
@@ -512,9 +544,10 @@  discard block
 block discarded – undo
512 544
 		cleanRequest();
513 545
 	}
514 546
 
515
-	if (!isset($_GET['substep']))
516
-		$_GET['substep'] = 0;
517
-}
547
+	if (!isset($_GET['substep'])) {
548
+			$_GET['substep'] = 0;
549
+	}
550
+	}
518 551
 
519 552
 function initialize_inputs()
520 553
 {
@@ -544,8 +577,9 @@  discard block
 block discarded – undo
544 577
 		$dh = opendir(dirname(__FILE__));
545 578
 		while ($file = readdir($dh))
546 579
 		{
547
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
548
-				@unlink(dirname(__FILE__) . '/' . $file);
580
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
581
+							@unlink(dirname(__FILE__) . '/' . $file);
582
+			}
549 583
 		}
550 584
 		closedir($dh);
551 585
 
@@ -575,8 +609,9 @@  discard block
 block discarded – undo
575 609
 	{
576 610
 		$upcontext['remote_files_available'] = false;
577 611
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
578
-		if ($test)
579
-			$upcontext['remote_files_available'] = true;
612
+		if ($test) {
613
+					$upcontext['remote_files_available'] = true;
614
+		}
580 615
 		@fclose($test);
581 616
 	}
582 617
 
@@ -584,8 +619,9 @@  discard block
 block discarded – undo
584 619
 	$temp = 'upgrade_php?step';
585 620
 	while (strlen($temp) > 4)
586 621
 	{
587
-		if (isset($_GET[$temp]))
588
-			unset($_GET[$temp]);
622
+		if (isset($_GET[$temp])) {
623
+					unset($_GET[$temp]);
624
+		}
589 625
 		$temp = substr($temp, 1);
590 626
 	}
591 627
 
@@ -612,32 +648,39 @@  discard block
 block discarded – undo
612 648
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
613 649
 
614 650
 	// Need legacy scripts?
615
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
616
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
617
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
618
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
619
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
620
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
651
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
652
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
653
+	}
654
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
655
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
656
+	}
657
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
658
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
659
+	}
621 660
 
622 661
 	// We don't need "-utf8" files anymore...
623 662
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
624 663
 
625 664
 	// This needs to exist!
626
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
627
-		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>]');
628
-	else
629
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
665
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
666
+			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>]');
667
+	} else {
668
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
669
+	}
630 670
 
631
-	if (!$check)
632
-		// 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.
671
+	if (!$check) {
672
+			// 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.
633 673
 		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.');
674
+	}
634 675
 
635 676
 	// Do they meet the install requirements?
636
-	if (!php_version_check())
637
-		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.');
677
+	if (!php_version_check()) {
678
+			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.');
679
+	}
638 680
 
639
-	if (!db_version_check())
640
-		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.');
681
+	if (!db_version_check()) {
682
+			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.');
683
+	}
641 684
 
642 685
 	// Do some checks to make sure they have proper privileges
643 686
 	db_extend('packages');
@@ -652,14 +695,16 @@  discard block
 block discarded – undo
652 695
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
653 696
 
654 697
 	// Sorry... we need CREATE, ALTER and DROP
655
-	if (!$create || !$alter || !$drop)
656
-		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.');
698
+	if (!$create || !$alter || !$drop) {
699
+			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.');
700
+	}
657 701
 
658 702
 	// Do a quick version spot check.
659 703
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
660 704
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
661
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
662
-		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.');
705
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
706
+			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.');
707
+	}
663 708
 
664 709
 	// What absolutely needs to be writable?
665 710
 	$writable_files = array(
@@ -681,12 +726,13 @@  discard block
 block discarded – undo
681 726
 	quickFileWritable($custom_av_dir);
682 727
 
683 728
 	// Are we good now?
684
-	if (!is_writable($custom_av_dir))
685
-		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));
686
-	elseif ($need_settings_update)
729
+	if (!is_writable($custom_av_dir)) {
730
+			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));
731
+	} elseif ($need_settings_update)
687 732
 	{
688
-		if (!function_exists('cache_put_data'))
689
-			require_once($sourcedir . '/Load.php');
733
+		if (!function_exists('cache_put_data')) {
734
+					require_once($sourcedir . '/Load.php');
735
+		}
690 736
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
691 737
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
692 738
 	}
@@ -695,28 +741,33 @@  discard block
 block discarded – undo
695 741
 
696 742
 	// Check the cache directory.
697 743
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
698
-	if (!file_exists($cachedir_temp))
699
-		@mkdir($cachedir_temp);
700
-	if (!file_exists($cachedir_temp))
701
-		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.');
702
-
703
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
704
-		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>.');
705
-	elseif (!isset($_GET['skiplang']))
744
+	if (!file_exists($cachedir_temp)) {
745
+			@mkdir($cachedir_temp);
746
+	}
747
+	if (!file_exists($cachedir_temp)) {
748
+			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.');
749
+	}
750
+
751
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
752
+			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>.');
753
+	} elseif (!isset($_GET['skiplang']))
706 754
 	{
707 755
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
708 756
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
709 757
 
710
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
711
-			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>]');
758
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
759
+					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>]');
760
+		}
712 761
 	}
713 762
 
714
-	if (!makeFilesWritable($writable_files))
715
-		return false;
763
+	if (!makeFilesWritable($writable_files)) {
764
+			return false;
765
+	}
716 766
 
717 767
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
718
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
719
-		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.');
768
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
769
+			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.');
770
+	}
720 771
 
721 772
 	// Upgrade the agreement.
722 773
 	elseif (isset($modSettings['agreement']))
@@ -727,8 +778,8 @@  discard block
 block discarded – undo
727 778
 	}
728 779
 
729 780
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
730
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
731
-		$upcontext['warning'] = '
781
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
782
+			$upcontext['warning'] = '
732 783
 			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>
733 784
 			<ul>
734 785
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -736,10 +787,12 @@  discard block
 block discarded – undo
736 787
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
737 788
 			</ul>
738 789
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
790
+	}
739 791
 
740 792
 	// Either we're logged in or we're going to present the login.
741
-	if (checkLogin())
742
-		return true;
793
+	if (checkLogin()) {
794
+			return true;
795
+	}
743 796
 
744 797
 	$upcontext += createToken('login');
745 798
 
@@ -753,15 +806,17 @@  discard block
 block discarded – undo
753 806
 	global $smcFunc, $db_type, $support_js;
754 807
 
755 808
 	// Don't bother if the security is disabled.
756
-	if ($disable_security)
757
-		return true;
809
+	if ($disable_security) {
810
+			return true;
811
+	}
758 812
 
759 813
 	// Are we trying to login?
760 814
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
761 815
 	{
762 816
 		// If we've disabled security pick a suitable name!
763
-		if (empty($_POST['user']))
764
-			$_POST['user'] = 'Administrator';
817
+		if (empty($_POST['user'])) {
818
+					$_POST['user'] = 'Administrator';
819
+		}
765 820
 
766 821
 		// Before 2.0 these column names were different!
767 822
 		$oldDB = false;
@@ -776,16 +831,17 @@  discard block
 block discarded – undo
776 831
 					'db_error_skip' => true,
777 832
 				)
778 833
 			);
779
-			if ($smcFunc['db_num_rows']($request) != 0)
780
-				$oldDB = true;
834
+			if ($smcFunc['db_num_rows']($request) != 0) {
835
+							$oldDB = true;
836
+			}
781 837
 			$smcFunc['db_free_result']($request);
782 838
 		}
783 839
 
784 840
 		// Get what we believe to be their details.
785 841
 		if (!$disable_security)
786 842
 		{
787
-			if ($oldDB)
788
-				$request = $smcFunc['db_query']('', '
843
+			if ($oldDB) {
844
+							$request = $smcFunc['db_query']('', '
789 845
 					SELECT id_member, memberName AS member_name, passwd, id_group,
790 846
 					additionalGroups AS additional_groups, lngfile
791 847
 					FROM {db_prefix}members
@@ -795,8 +851,8 @@  discard block
 block discarded – undo
795 851
 						'db_error_skip' => true,
796 852
 					)
797 853
 				);
798
-			else
799
-				$request = $smcFunc['db_query']('', '
854
+			} else {
855
+							$request = $smcFunc['db_query']('', '
800 856
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
801 857
 					FROM {db_prefix}members
802 858
 					WHERE member_name = {string:member_name}',
@@ -805,6 +861,7 @@  discard block
 block discarded – undo
805 861
 						'db_error_skip' => true,
806 862
 					)
807 863
 				);
864
+			}
808 865
 			if ($smcFunc['db_num_rows']($request) != 0)
809 866
 			{
810 867
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -812,16 +869,17 @@  discard block
 block discarded – undo
812 869
 				$groups = explode(',', $addGroups);
813 870
 				$groups[] = $id_group;
814 871
 
815
-				foreach ($groups as $k => $v)
816
-					$groups[$k] = (int) $v;
872
+				foreach ($groups as $k => $v) {
873
+									$groups[$k] = (int) $v;
874
+				}
817 875
 
818 876
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
819 877
 
820 878
 				// We don't use "-utf8" anymore...
821 879
 				$user_language = str_ireplace('-utf8', '', $user_language);
880
+			} else {
881
+							$upcontext['username_incorrect'] = true;
822 882
 			}
823
-			else
824
-				$upcontext['username_incorrect'] = true;
825 883
 			$smcFunc['db_free_result']($request);
826 884
 		}
827 885
 		$upcontext['username'] = $_POST['user'];
@@ -831,13 +889,14 @@  discard block
 block discarded – undo
831 889
 		{
832 890
 			$upcontext['upgrade_status']['js'] = 1;
833 891
 			$support_js = 1;
892
+		} else {
893
+					$support_js = 0;
834 894
 		}
835
-		else
836
-			$support_js = 0;
837 895
 
838 896
 		// Note down the version we are coming from.
839
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
840
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
897
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
898
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
899
+		}
841 900
 
842 901
 		// Didn't get anywhere?
843 902
 		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']))
@@ -871,15 +930,15 @@  discard block
 block discarded – undo
871 930
 							'db_error_skip' => true,
872 931
 						)
873 932
 					);
874
-					if ($smcFunc['db_num_rows']($request) == 0)
875
-						return throw_error('You need to be an admin to perform an upgrade!');
933
+					if ($smcFunc['db_num_rows']($request) == 0) {
934
+											return throw_error('You need to be an admin to perform an upgrade!');
935
+					}
876 936
 					$smcFunc['db_free_result']($request);
877 937
 				}
878 938
 
879 939
 				$upcontext['user']['id'] = $id_member;
880 940
 				$upcontext['user']['name'] = $name;
881
-			}
882
-			else
941
+			} else
883 942
 			{
884 943
 				$upcontext['user']['id'] = 1;
885 944
 				$upcontext['user']['name'] = 'Administrator';
@@ -895,11 +954,11 @@  discard block
 block discarded – undo
895 954
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
896 955
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
897 956
 
898
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
899
-					$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'] . '.';
900
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
901
-					$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'] . '.';
902
-				else
957
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
958
+									$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'] . '.';
959
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
960
+									$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'] . '.';
961
+				} else
903 962
 				{
904 963
 					// Set this as the new language.
905 964
 					$upcontext['language'] = $user_language;
@@ -943,8 +1002,9 @@  discard block
 block discarded – undo
943 1002
 	unset($member_columns);
944 1003
 
945 1004
 	// If we've not submitted then we're done.
946
-	if (empty($_POST['upcont']))
947
-		return false;
1005
+	if (empty($_POST['upcont'])) {
1006
+			return false;
1007
+	}
948 1008
 
949 1009
 	// Firstly, if they're enabling SM stat collection just do it.
950 1010
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -959,25 +1019,26 @@  discard block
 block discarded – undo
959 1019
 			fwrite($fp, $out);
960 1020
 
961 1021
 			$return_data = '';
962
-			while (!feof($fp))
963
-				$return_data .= fgets($fp, 128);
1022
+			while (!feof($fp)) {
1023
+							$return_data .= fgets($fp, 128);
1024
+			}
964 1025
 
965 1026
 			fclose($fp);
966 1027
 
967 1028
 			// Get the unique site ID.
968 1029
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
969 1030
 
970
-			if (!empty($ID[1]))
971
-				$smcFunc['db_insert']('replace',
1031
+			if (!empty($ID[1])) {
1032
+							$smcFunc['db_insert']('replace',
972 1033
 					$db_prefix . 'settings',
973 1034
 					array('variable' => 'string', 'value' => 'string'),
974 1035
 					array('allow_sm_stats', $ID[1]),
975 1036
 					array('variable')
976 1037
 				);
1038
+			}
977 1039
 		}
978
-	}
979
-	else
980
-		$smcFunc['db_query']('', '
1040
+	} else {
1041
+			$smcFunc['db_query']('', '
981 1042
 			DELETE FROM {db_prefix}settings
982 1043
 			WHERE variable = {string:allow_sm_stats}',
983 1044
 			array(
@@ -985,6 +1046,7 @@  discard block
 block discarded – undo
985 1046
 				'db_error_skip' => true,
986 1047
 			)
987 1048
 		);
1049
+	}
988 1050
 
989 1051
 	// Deleting old karma stuff?
990 1052
 	if (!empty($_POST['delete_karma']))
@@ -999,20 +1061,22 @@  discard block
 block discarded – undo
999 1061
 		);
1000 1062
 
1001 1063
 		// Cleaning up old karma member settings.
1002
-		if ($upcontext['karma_installed']['good'])
1003
-			$smcFunc['db_query']('', '
1064
+		if ($upcontext['karma_installed']['good']) {
1065
+					$smcFunc['db_query']('', '
1004 1066
 				ALTER TABLE {db_prefix}members
1005 1067
 				DROP karma_good',
1006 1068
 				array()
1007 1069
 			);
1070
+		}
1008 1071
 
1009 1072
 		// Does karma bad was enable?
1010
-		if ($upcontext['karma_installed']['bad'])
1011
-			$smcFunc['db_query']('', '
1073
+		if ($upcontext['karma_installed']['bad']) {
1074
+					$smcFunc['db_query']('', '
1012 1075
 				ALTER TABLE {db_prefix}members
1013 1076
 				DROP karma_bad',
1014 1077
 				array()
1015 1078
 			);
1079
+		}
1016 1080
 
1017 1081
 		// Cleaning up old karma permissions.
1018 1082
 		$smcFunc['db_query']('', '
@@ -1025,26 +1089,29 @@  discard block
 block discarded – undo
1025 1089
 	}
1026 1090
 
1027 1091
 	// Emptying the error log?
1028
-	if (!empty($_POST['empty_error']))
1029
-		$smcFunc['db_query']('truncate_table', '
1092
+	if (!empty($_POST['empty_error'])) {
1093
+			$smcFunc['db_query']('truncate_table', '
1030 1094
 			TRUNCATE {db_prefix}log_errors',
1031 1095
 			array(
1032 1096
 			)
1033 1097
 		);
1098
+	}
1034 1099
 
1035 1100
 	$changes = array();
1036 1101
 
1037 1102
 	// Add proxy settings.
1038
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1039
-		$changes += array(
1103
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1104
+			$changes += array(
1040 1105
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1041 1106
 			'image_proxy_maxsize' => 5190,
1042 1107
 			'image_proxy_enabled' => 0,
1043 1108
 		);
1109
+	}
1044 1110
 
1045 1111
 	// If we're overriding the language follow it through.
1046
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1047
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1112
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1113
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1114
+	}
1048 1115
 
1049 1116
 	if (!empty($_POST['maint']))
1050 1117
 	{
@@ -1056,30 +1123,34 @@  discard block
 block discarded – undo
1056 1123
 		{
1057 1124
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1058 1125
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1059
-		}
1060
-		else
1126
+		} else
1061 1127
 		{
1062 1128
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1063 1129
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1064 1130
 		}
1065 1131
 	}
1066 1132
 
1067
-	if ($command_line)
1068
-		echo ' * Updating Settings.php...';
1133
+	if ($command_line) {
1134
+			echo ' * Updating Settings.php...';
1135
+	}
1069 1136
 
1070 1137
 	// Fix some old paths.
1071
-	if (substr($boarddir, 0, 1) == '.')
1072
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1138
+	if (substr($boarddir, 0, 1) == '.') {
1139
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1140
+	}
1073 1141
 
1074
-	if (substr($sourcedir, 0, 1) == '.')
1075
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1142
+	if (substr($sourcedir, 0, 1) == '.') {
1143
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1144
+	}
1076 1145
 
1077
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1078
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1146
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1147
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1148
+	}
1079 1149
 
1080 1150
 	// Not had the database type added before?
1081
-	if (empty($db_type))
1082
-		$changes['db_type'] = 'mysql';
1151
+	if (empty($db_type)) {
1152
+			$changes['db_type'] = 'mysql';
1153
+	}
1083 1154
 
1084 1155
 	// If they have a "host:port" setup for the host, split that into separate values
1085 1156
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1090,32 +1161,36 @@  discard block
 block discarded – undo
1090 1161
 		$changes['db_server'] = '\'' . $db_server . '\'';
1091 1162
 
1092 1163
 		// Only set this if we're not using the default port
1093
-		if ($db_port != ini_get('mysqli.default_port'))
1094
-			$changes['db_port'] = (int) $db_port;
1095
-	}
1096
-	elseif (!empty($db_port))
1164
+		if ($db_port != ini_get('mysqli.default_port')) {
1165
+					$changes['db_port'] = (int) $db_port;
1166
+		}
1167
+	} elseif (!empty($db_port))
1097 1168
 	{
1098 1169
 		// If db_port is set and is the same as the default, set it to ''
1099 1170
 		if ($db_type == 'mysql')
1100 1171
 		{
1101
-			if ($db_port == ini_get('mysqli.default_port'))
1102
-				$changes['db_port'] = '\'\'';
1103
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1104
-				$changes['db_port'] = '\'\'';
1172
+			if ($db_port == ini_get('mysqli.default_port')) {
1173
+							$changes['db_port'] = '\'\'';
1174
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1175
+							$changes['db_port'] = '\'\'';
1176
+			}
1105 1177
 		}
1106 1178
 	}
1107 1179
 
1108 1180
 	// Maybe we haven't had this option yet?
1109
-	if (empty($packagesdir))
1110
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1181
+	if (empty($packagesdir)) {
1182
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1183
+	}
1111 1184
 
1112 1185
 	// Add support for $tasksdir var.
1113
-	if (empty($tasksdir))
1114
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1186
+	if (empty($tasksdir)) {
1187
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1188
+	}
1115 1189
 
1116 1190
 	// Make sure we fix the language as well.
1117
-	if (stristr($language, '-utf8'))
1118
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1191
+	if (stristr($language, '-utf8')) {
1192
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1193
+	}
1119 1194
 
1120 1195
 	// @todo Maybe change the cookie name if going to 1.1, too?
1121 1196
 
@@ -1123,8 +1198,9 @@  discard block
 block discarded – undo
1123 1198
 	require_once($sourcedir . '/Subs-Admin.php');
1124 1199
 	updateSettingsFile($changes);
1125 1200
 
1126
-	if ($command_line)
1127
-		echo ' Successful.' . "\n";
1201
+	if ($command_line) {
1202
+			echo ' Successful.' . "\n";
1203
+	}
1128 1204
 
1129 1205
 	// Are we doing debug?
1130 1206
 	if (isset($_POST['debug']))
@@ -1134,8 +1210,9 @@  discard block
 block discarded – undo
1134 1210
 	}
1135 1211
 
1136 1212
 	// If we're not backing up then jump one.
1137
-	if (empty($_POST['backup']))
1138
-		$upcontext['current_step']++;
1213
+	if (empty($_POST['backup'])) {
1214
+			$upcontext['current_step']++;
1215
+	}
1139 1216
 
1140 1217
 	// If we've got here then let's proceed to the next step!
1141 1218
 	return true;
@@ -1150,8 +1227,9 @@  discard block
 block discarded – undo
1150 1227
 	$upcontext['page_title'] = 'Backup Database';
1151 1228
 
1152 1229
 	// Done it already - js wise?
1153
-	if (!empty($_POST['backup_done']))
1154
-		return true;
1230
+	if (!empty($_POST['backup_done'])) {
1231
+			return true;
1232
+	}
1155 1233
 
1156 1234
 	// Some useful stuff here.
1157 1235
 	db_extend();
@@ -1165,9 +1243,10 @@  discard block
 block discarded – undo
1165 1243
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1166 1244
 
1167 1245
 	$table_names = array();
1168
-	foreach ($tables as $table)
1169
-		if (substr($table, 0, 7) !== 'backup_')
1246
+	foreach ($tables as $table) {
1247
+			if (substr($table, 0, 7) !== 'backup_')
1170 1248
 			$table_names[] = $table;
1249
+	}
1171 1250
 
1172 1251
 	$upcontext['table_count'] = count($table_names);
1173 1252
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1177,12 +1256,14 @@  discard block
 block discarded – undo
1177 1256
 	$file_steps = $upcontext['table_count'];
1178 1257
 
1179 1258
 	// What ones have we already done?
1180
-	foreach ($table_names as $id => $table)
1181
-		if ($id < $_GET['substep'])
1259
+	foreach ($table_names as $id => $table) {
1260
+			if ($id < $_GET['substep'])
1182 1261
 			$upcontext['previous_tables'][] = $table;
1262
+	}
1183 1263
 
1184
-	if ($command_line)
1185
-		echo 'Backing Up Tables.';
1264
+	if ($command_line) {
1265
+			echo 'Backing Up Tables.';
1266
+	}
1186 1267
 
1187 1268
 	// If we don't support javascript we backup here.
1188 1269
 	if (!$support_js || isset($_GET['xml']))
@@ -1201,8 +1282,9 @@  discard block
 block discarded – undo
1201 1282
 			backupTable($table_names[$substep]);
1202 1283
 
1203 1284
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1204
-			if (isset($_GET['xml']))
1205
-				return upgradeExit();
1285
+			if (isset($_GET['xml'])) {
1286
+							return upgradeExit();
1287
+			}
1206 1288
 		}
1207 1289
 
1208 1290
 		if ($command_line)
@@ -1235,9 +1317,10 @@  discard block
 block discarded – undo
1235 1317
 
1236 1318
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1237 1319
 
1238
-	if ($command_line)
1239
-		echo ' done.';
1240
-}
1320
+	if ($command_line) {
1321
+			echo ' done.';
1322
+	}
1323
+	}
1241 1324
 
1242 1325
 // Step 2: Everything.
1243 1326
 function DatabaseChanges()
@@ -1246,8 +1329,9 @@  discard block
 block discarded – undo
1246 1329
 	global $upcontext, $support_js, $db_type;
1247 1330
 
1248 1331
 	// Have we just completed this?
1249
-	if (!empty($_POST['database_done']))
1250
-		return true;
1332
+	if (!empty($_POST['database_done'])) {
1333
+			return true;
1334
+	}
1251 1335
 
1252 1336
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1253 1337
 	$upcontext['page_title'] = 'Database Changes';
@@ -1262,15 +1346,16 @@  discard block
 block discarded – undo
1262 1346
 	);
1263 1347
 
1264 1348
 	// How many files are there in total?
1265
-	if (isset($_GET['filecount']))
1266
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1267
-	else
1349
+	if (isset($_GET['filecount'])) {
1350
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1351
+	} else
1268 1352
 	{
1269 1353
 		$upcontext['file_count'] = 0;
1270 1354
 		foreach ($files as $file)
1271 1355
 		{
1272
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1273
-				$upcontext['file_count']++;
1356
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1357
+							$upcontext['file_count']++;
1358
+			}
1274 1359
 		}
1275 1360
 	}
1276 1361
 
@@ -1280,9 +1365,9 @@  discard block
 block discarded – undo
1280 1365
 	$upcontext['cur_file_num'] = 0;
1281 1366
 	foreach ($files as $file)
1282 1367
 	{
1283
-		if ($did_not_do)
1284
-			$did_not_do--;
1285
-		else
1368
+		if ($did_not_do) {
1369
+					$did_not_do--;
1370
+		} else
1286 1371
 		{
1287 1372
 			$upcontext['cur_file_num']++;
1288 1373
 			$upcontext['cur_file_name'] = $file[0];
@@ -1309,12 +1394,13 @@  discard block
 block discarded – undo
1309 1394
 					// Flag to move on to the next.
1310 1395
 					$upcontext['completed_step'] = true;
1311 1396
 					// Did we complete the whole file?
1312
-					if ($nextFile)
1313
-						$upcontext['current_debug_item_num'] = -1;
1397
+					if ($nextFile) {
1398
+											$upcontext['current_debug_item_num'] = -1;
1399
+					}
1314 1400
 					return upgradeExit();
1401
+				} elseif ($support_js) {
1402
+									break;
1315 1403
 				}
1316
-				elseif ($support_js)
1317
-					break;
1318 1404
 			}
1319 1405
 			// Set the progress bar to be right as if we had - even if we hadn't...
1320 1406
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1339,8 +1425,9 @@  discard block
 block discarded – undo
1339 1425
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1340 1426
 
1341 1427
 	// Now it's nice to have some of the basic SMF source files.
1342
-	if (!isset($_GET['ssi']) && !$command_line)
1343
-		redirectLocation('&ssi=1');
1428
+	if (!isset($_GET['ssi']) && !$command_line) {
1429
+			redirectLocation('&ssi=1');
1430
+	}
1344 1431
 
1345 1432
 	$upcontext['sub_template'] = 'upgrade_complete';
1346 1433
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1356,14 +1443,16 @@  discard block
 block discarded – undo
1356 1443
 	// Are we in maintenance mode?
1357 1444
 	if (isset($upcontext['user']['main']))
1358 1445
 	{
1359
-		if ($command_line)
1360
-			echo ' * ';
1446
+		if ($command_line) {
1447
+					echo ' * ';
1448
+		}
1361 1449
 		$upcontext['removed_maintenance'] = true;
1362 1450
 		$changes['maintenance'] = $upcontext['user']['main'];
1363 1451
 	}
1364 1452
 	// Otherwise if somehow we are in 2 let's go to 1.
1365
-	elseif (!empty($maintenance) && $maintenance == 2)
1366
-		$changes['maintenance'] = 1;
1453
+	elseif (!empty($maintenance) && $maintenance == 2) {
1454
+			$changes['maintenance'] = 1;
1455
+	}
1367 1456
 
1368 1457
 	// Wipe this out...
1369 1458
 	$upcontext['user'] = array();
@@ -1378,9 +1467,9 @@  discard block
 block discarded – undo
1378 1467
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1379 1468
 
1380 1469
 	// Now is the perfect time to fetch the SM files.
1381
-	if ($command_line)
1382
-		cli_scheduled_fetchSMfiles();
1383
-	else
1470
+	if ($command_line) {
1471
+			cli_scheduled_fetchSMfiles();
1472
+	} else
1384 1473
 	{
1385 1474
 		require_once($sourcedir . '/ScheduledTasks.php');
1386 1475
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1388,8 +1477,9 @@  discard block
 block discarded – undo
1388 1477
 	}
1389 1478
 
1390 1479
 	// Log what we've done.
1391
-	if (empty($user_info['id']))
1392
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1480
+	if (empty($user_info['id'])) {
1481
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1482
+	}
1393 1483
 
1394 1484
 	// Log the action manually, so CLI still works.
1395 1485
 	$smcFunc['db_insert']('',
@@ -1408,8 +1498,9 @@  discard block
 block discarded – undo
1408 1498
 
1409 1499
 	// Save the current database version.
1410 1500
 	$server_version = $smcFunc['db_server_info']();
1411
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1412
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1501
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1502
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1503
+	}
1413 1504
 
1414 1505
 	if ($command_line)
1415 1506
 	{
@@ -1421,8 +1512,9 @@  discard block
 block discarded – undo
1421 1512
 
1422 1513
 	// Make sure it says we're done.
1423 1514
 	$upcontext['overall_percent'] = 100;
1424
-	if (isset($upcontext['step_progress']))
1425
-		unset($upcontext['step_progress']);
1515
+	if (isset($upcontext['step_progress'])) {
1516
+			unset($upcontext['step_progress']);
1517
+	}
1426 1518
 
1427 1519
 	$_GET['substep'] = 0;
1428 1520
 	return false;
@@ -1433,8 +1525,9 @@  discard block
 block discarded – undo
1433 1525
 {
1434 1526
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1435 1527
 
1436
-	if (empty($modSettings['time_format']))
1437
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1528
+	if (empty($modSettings['time_format'])) {
1529
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1530
+	}
1438 1531
 
1439 1532
 	// What files do we want to get
1440 1533
 	$request = $smcFunc['db_query']('', '
@@ -1468,8 +1561,9 @@  discard block
 block discarded – undo
1468 1561
 		$file_data = fetch_web_data($url);
1469 1562
 
1470 1563
 		// If we got an error - give up - the site might be down.
1471
-		if ($file_data === false)
1472
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1564
+		if ($file_data === false) {
1565
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1566
+		}
1473 1567
 
1474 1568
 		// Save the file to the database.
1475 1569
 		$smcFunc['db_query']('substring', '
@@ -1511,8 +1605,9 @@  discard block
 block discarded – undo
1511 1605
 	$themeData = array();
1512 1606
 	foreach ($values as $variable => $value)
1513 1607
 	{
1514
-		if (!isset($value) || $value === null)
1515
-			$value = 0;
1608
+		if (!isset($value) || $value === null) {
1609
+					$value = 0;
1610
+		}
1516 1611
 
1517 1612
 		$themeData[] = array(0, 1, $variable, $value);
1518 1613
 	}
@@ -1541,8 +1636,9 @@  discard block
 block discarded – undo
1541 1636
 
1542 1637
 	foreach ($values as $variable => $value)
1543 1638
 	{
1544
-		if (empty($modSettings[$value[0]]))
1545
-			continue;
1639
+		if (empty($modSettings[$value[0]])) {
1640
+					continue;
1641
+		}
1546 1642
 
1547 1643
 		$smcFunc['db_query']('', '
1548 1644
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1628,10 +1724,11 @@  discard block
 block discarded – undo
1628 1724
 	set_error_handler(
1629 1725
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1630 1726
 		{
1631
-			if ($support_js)
1632
-				return true;
1633
-			else
1634
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1727
+			if ($support_js) {
1728
+							return true;
1729
+			} else {
1730
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1731
+			}
1635 1732
 		}
1636 1733
 	);
1637 1734
 
@@ -1646,8 +1743,9 @@  discard block
 block discarded – undo
1646 1743
 				'db_error_skip' => true,
1647 1744
 			)
1648 1745
 		);
1649
-		if ($smcFunc['db_num_rows']($request) === 0)
1650
-			die('Unable to find members table!');
1746
+		if ($smcFunc['db_num_rows']($request) === 0) {
1747
+					die('Unable to find members table!');
1748
+		}
1651 1749
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1652 1750
 		$smcFunc['db_free_result']($request);
1653 1751
 
@@ -1662,17 +1760,20 @@  discard block
 block discarded – undo
1662 1760
 				)
1663 1761
 			);
1664 1762
 			// Got something?
1665
-			if ($smcFunc['db_num_rows']($request) !== 0)
1666
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1763
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1764
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1765
+			}
1667 1766
 			$smcFunc['db_free_result']($request);
1668 1767
 
1669 1768
 			// Excellent!
1670
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1671
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1769
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1770
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1771
+			}
1672 1772
 		}
1673 1773
 	}
1674
-	if (empty($db_collation))
1675
-		$db_collation = '';
1774
+	if (empty($db_collation)) {
1775
+			$db_collation = '';
1776
+	}
1676 1777
 
1677 1778
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1678 1779
 
@@ -1684,8 +1785,9 @@  discard block
 block discarded – undo
1684 1785
 	$last_step = '';
1685 1786
 
1686 1787
 	// Make sure all newly created tables will have the proper characters set.
1687
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1688
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1788
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1789
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1790
+	}
1689 1791
 
1690 1792
 	// Count the total number of steps within this file - for progress.
1691 1793
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1705,15 +1807,18 @@  discard block
 block discarded – undo
1705 1807
 		$do_current = $substep >= $_GET['substep'];
1706 1808
 
1707 1809
 		// Get rid of any comments in the beginning of the line...
1708
-		if (substr(trim($line), 0, 2) === '/*')
1709
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1810
+		if (substr(trim($line), 0, 2) === '/*') {
1811
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1812
+		}
1710 1813
 
1711 1814
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1712
-		if ($is_debug && !$support_js && $command_line)
1713
-			flush();
1815
+		if ($is_debug && !$support_js && $command_line) {
1816
+					flush();
1817
+		}
1714 1818
 
1715
-		if (trim($line) === '')
1716
-			continue;
1819
+		if (trim($line) === '') {
1820
+					continue;
1821
+		}
1717 1822
 
1718 1823
 		if (trim(substr($line, 0, 3)) === '---')
1719 1824
 		{
@@ -1723,8 +1828,9 @@  discard block
 block discarded – undo
1723 1828
 			if (trim($current_data) != '' && $type !== '}')
1724 1829
 			{
1725 1830
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1726
-				if ($command_line)
1727
-					echo $upcontext['error_message'];
1831
+				if ($command_line) {
1832
+									echo $upcontext['error_message'];
1833
+				}
1728 1834
 			}
1729 1835
 
1730 1836
 			if ($type == ' ')
@@ -1742,17 +1848,18 @@  discard block
 block discarded – undo
1742 1848
 				if ($do_current)
1743 1849
 				{
1744 1850
 					$upcontext['actioned_items'][] = $last_step;
1745
-					if ($command_line)
1746
-						echo ' * ';
1851
+					if ($command_line) {
1852
+											echo ' * ';
1853
+					}
1747 1854
 				}
1748
-			}
1749
-			elseif ($type == '#')
1855
+			} elseif ($type == '#')
1750 1856
 			{
1751 1857
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1752 1858
 
1753 1859
 				$upcontext['current_debug_item_num']++;
1754
-				if (trim($line) != '---#')
1755
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1860
+				if (trim($line) != '---#') {
1861
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1862
+				}
1756 1863
 
1757 1864
 				// Have we already done something?
1758 1865
 				if (isset($_GET['xml']) && $done_something)
@@ -1763,34 +1870,36 @@  discard block
 block discarded – undo
1763 1870
 
1764 1871
 				if ($do_current)
1765 1872
 				{
1766
-					if (trim($line) == '---#' && $command_line)
1767
-						echo ' done.', $endl;
1768
-					elseif ($command_line)
1769
-						echo ' +++ ', rtrim(substr($line, 4));
1770
-					elseif (trim($line) != '---#')
1873
+					if (trim($line) == '---#' && $command_line) {
1874
+											echo ' done.', $endl;
1875
+					} elseif ($command_line) {
1876
+											echo ' +++ ', rtrim(substr($line, 4));
1877
+					} elseif (trim($line) != '---#')
1771 1878
 					{
1772
-						if ($is_debug)
1773
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1879
+						if ($is_debug) {
1880
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1881
+						}
1774 1882
 					}
1775 1883
 				}
1776 1884
 
1777 1885
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1778 1886
 				{
1779
-					if ($command_line)
1780
-						echo ' * ';
1781
-					else
1782
-						$upcontext['actioned_items'][] = $last_step;
1887
+					if ($command_line) {
1888
+											echo ' * ';
1889
+					} else {
1890
+											$upcontext['actioned_items'][] = $last_step;
1891
+					}
1783 1892
 				}
1784 1893
 
1785 1894
 				// Small step - only if we're actually doing stuff.
1786
-				if ($do_current)
1787
-					nextSubstep(++$substep);
1788
-				else
1789
-					$substep++;
1790
-			}
1791
-			elseif ($type == '{')
1792
-				$current_type = 'code';
1793
-			elseif ($type == '}')
1895
+				if ($do_current) {
1896
+									nextSubstep(++$substep);
1897
+				} else {
1898
+									$substep++;
1899
+				}
1900
+			} elseif ($type == '{') {
1901
+							$current_type = 'code';
1902
+			} elseif ($type == '}')
1794 1903
 			{
1795 1904
 				$current_type = 'sql';
1796 1905
 
@@ -1803,8 +1912,9 @@  discard block
 block discarded – undo
1803 1912
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1804 1913
 				{
1805 1914
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1806
-					if ($command_line)
1807
-						echo $upcontext['error_message'];
1915
+					if ($command_line) {
1916
+											echo $upcontext['error_message'];
1917
+					}
1808 1918
 				}
1809 1919
 
1810 1920
 				// Done with code!
@@ -1884,8 +1994,9 @@  discard block
 block discarded – undo
1884 1994
 	$db_unbuffered = false;
1885 1995
 
1886 1996
 	// Failure?!
1887
-	if ($result !== false)
1888
-		return $result;
1997
+	if ($result !== false) {
1998
+			return $result;
1999
+	}
1889 2000
 
1890 2001
 	$db_error_message = $smcFunc['db_error']($db_connection);
1891 2002
 	// If MySQL we do something more clever.
@@ -1913,54 +2024,61 @@  discard block
 block discarded – undo
1913 2024
 			{
1914 2025
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1915 2026
 				$result = mysqli_query($db_connection, $string);
1916
-				if ($result !== false)
1917
-					return $result;
2027
+				if ($result !== false) {
2028
+									return $result;
2029
+				}
1918 2030
 			}
1919
-		}
1920
-		elseif ($mysqli_errno == 2013)
2031
+		} elseif ($mysqli_errno == 2013)
1921 2032
 		{
1922 2033
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1923 2034
 			mysqli_select_db($db_connection, $db_name);
1924 2035
 			if ($db_connection)
1925 2036
 			{
1926 2037
 				$result = mysqli_query($db_connection, $string);
1927
-				if ($result !== false)
1928
-					return $result;
2038
+				if ($result !== false) {
2039
+									return $result;
2040
+				}
1929 2041
 			}
1930 2042
 		}
1931 2043
 		// Duplicate column name... should be okay ;).
1932
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1933
-			return false;
2044
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2045
+					return false;
2046
+		}
1934 2047
 		// Duplicate insert... make sure it's the proper type of query ;).
1935
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1936
-			return false;
2048
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2049
+					return false;
2050
+		}
1937 2051
 		// Creating an index on a non-existent column.
1938
-		elseif ($mysqli_errno == 1072)
1939
-			return false;
1940
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1941
-			return false;
2052
+		elseif ($mysqli_errno == 1072) {
2053
+					return false;
2054
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2055
+					return false;
2056
+		}
1942 2057
 	}
1943 2058
 	// If a table already exists don't go potty.
1944 2059
 	else
1945 2060
 	{
1946 2061
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1947 2062
 		{
1948
-			if (strpos($db_error_message, 'exist') !== false)
1949
-				return true;
1950
-		}
1951
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2063
+			if (strpos($db_error_message, 'exist') !== false) {
2064
+							return true;
2065
+			}
2066
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1952 2067
 		{
1953
-			if (strpos($db_error_message, 'duplicate') !== false)
1954
-				return true;
2068
+			if (strpos($db_error_message, 'duplicate') !== false) {
2069
+							return true;
2070
+			}
1955 2071
 		}
1956 2072
 	}
1957 2073
 
1958 2074
 	// Get the query string so we pass everything.
1959 2075
 	$query_string = '';
1960
-	foreach ($_GET as $k => $v)
1961
-		$query_string .= ';' . $k . '=' . $v;
1962
-	if (strlen($query_string) != 0)
1963
-		$query_string = '?' . substr($query_string, 1);
2076
+	foreach ($_GET as $k => $v) {
2077
+			$query_string .= ';' . $k . '=' . $v;
2078
+	}
2079
+	if (strlen($query_string) != 0) {
2080
+			$query_string = '?' . substr($query_string, 1);
2081
+	}
1964 2082
 
1965 2083
 	if ($command_line)
1966 2084
 	{
@@ -2015,16 +2133,18 @@  discard block
 block discarded – undo
2015 2133
 			{
2016 2134
 				$found |= 1;
2017 2135
 				// Do some checks on the data if we have it set.
2018
-				if (isset($change['col_type']))
2019
-					$found &= $change['col_type'] === $column['type'];
2020
-				if (isset($change['null_allowed']))
2021
-					$found &= $column['null'] == $change['null_allowed'];
2022
-				if (isset($change['default']))
2023
-					$found &= $change['default'] === $column['default'];
2136
+				if (isset($change['col_type'])) {
2137
+									$found &= $change['col_type'] === $column['type'];
2138
+				}
2139
+				if (isset($change['null_allowed'])) {
2140
+									$found &= $column['null'] == $change['null_allowed'];
2141
+				}
2142
+				if (isset($change['default'])) {
2143
+									$found &= $change['default'] === $column['default'];
2144
+				}
2024 2145
 			}
2025 2146
 		}
2026
-	}
2027
-	elseif ($change['type'] === 'index')
2147
+	} elseif ($change['type'] === 'index')
2028 2148
 	{
2029 2149
 		$request = upgrade_query('
2030 2150
 			SHOW INDEX
@@ -2033,9 +2153,10 @@  discard block
 block discarded – undo
2033 2153
 		{
2034 2154
 			$cur_index = array();
2035 2155
 
2036
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2037
-				if ($row['Key_name'] === $change['name'])
2156
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2157
+							if ($row['Key_name'] === $change['name'])
2038 2158
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2159
+			}
2039 2160
 
2040 2161
 			ksort($cur_index, SORT_NUMERIC);
2041 2162
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2045,14 +2166,17 @@  discard block
 block discarded – undo
2045 2166
 	}
2046 2167
 
2047 2168
 	// If we're trying to add and it's added, we're done.
2048
-	if ($found && in_array($change['method'], array('add', 'change')))
2049
-		return true;
2169
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2170
+			return true;
2171
+	}
2050 2172
 	// Otherwise if we're removing and it wasn't found we're also done.
2051
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2052
-		return true;
2173
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2174
+			return true;
2175
+	}
2053 2176
 	// Otherwise is it just a test?
2054
-	elseif ($is_test)
2055
-		return false;
2177
+	elseif ($is_test) {
2178
+			return false;
2179
+	}
2056 2180
 
2057 2181
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2058 2182
 	$running = false;
@@ -2063,8 +2187,9 @@  discard block
 block discarded – undo
2063 2187
 			SHOW FULL PROCESSLIST');
2064 2188
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2065 2189
 		{
2066
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2067
-				$found = true;
2190
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2191
+							$found = true;
2192
+			}
2068 2193
 		}
2069 2194
 
2070 2195
 		// Can't find it? Then we need to run it fools!
@@ -2076,8 +2201,9 @@  discard block
 block discarded – undo
2076 2201
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2077 2202
 				' . $change['text'], true) !== false;
2078 2203
 
2079
-			if (!$success)
2080
-				return false;
2204
+			if (!$success) {
2205
+							return false;
2206
+			}
2081 2207
 
2082 2208
 			// Return
2083 2209
 			$running = true;
@@ -2119,8 +2245,9 @@  discard block
 block discarded – undo
2119 2245
 			'db_error_skip' => true,
2120 2246
 		)
2121 2247
 	);
2122
-	if ($smcFunc['db_num_rows']($request) === 0)
2123
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2248
+	if ($smcFunc['db_num_rows']($request) === 0) {
2249
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2250
+	}
2124 2251
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2125 2252
 	$smcFunc['db_free_result']($request);
2126 2253
 
@@ -2142,18 +2269,19 @@  discard block
 block discarded – undo
2142 2269
 			)
2143 2270
 		);
2144 2271
 		// No results? Just forget it all together.
2145
-		if ($smcFunc['db_num_rows']($request) === 0)
2146
-			unset($table_row['Collation']);
2147
-		else
2148
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2272
+		if ($smcFunc['db_num_rows']($request) === 0) {
2273
+					unset($table_row['Collation']);
2274
+		} else {
2275
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2276
+		}
2149 2277
 		$smcFunc['db_free_result']($request);
2150 2278
 	}
2151 2279
 
2152 2280
 	if ($column_fix)
2153 2281
 	{
2154 2282
 		// Make sure there are no NULL's left.
2155
-		if ($null_fix)
2156
-			$smcFunc['db_query']('', '
2283
+		if ($null_fix) {
2284
+					$smcFunc['db_query']('', '
2157 2285
 				UPDATE {db_prefix}' . $change['table'] . '
2158 2286
 				SET ' . $change['column'] . ' = {string:default}
2159 2287
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2162,6 +2290,7 @@  discard block
 block discarded – undo
2162 2290
 					'db_error_skip' => true,
2163 2291
 				)
2164 2292
 			);
2293
+		}
2165 2294
 
2166 2295
 		// Do the actual alteration.
2167 2296
 		$smcFunc['db_query']('', '
@@ -2190,8 +2319,9 @@  discard block
 block discarded – undo
2190 2319
 	}
2191 2320
 
2192 2321
 	// Not a column we need to check on?
2193
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2194
-		return;
2322
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2323
+			return;
2324
+	}
2195 2325
 
2196 2326
 	// Break it up you (six|seven).
2197 2327
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2210,13 +2340,13 @@  discard block
 block discarded – undo
2210 2340
 				'new_name' => $temp[2],
2211 2341
 		));
2212 2342
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2213
-		if ($smcFunc['db_num_rows'] != 1)
2214
-			return;
2343
+		if ($smcFunc['db_num_rows'] != 1) {
2344
+					return;
2345
+		}
2215 2346
 
2216 2347
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2217 2348
 		$smcFunc['db_free_result']($request);
2218
-	}
2219
-	else
2349
+	} else
2220 2350
 	{
2221 2351
 		// Do this the old fashion, sure method way.
2222 2352
 		$request = $smcFunc['db_query']('', '
@@ -2227,21 +2357,24 @@  discard block
 block discarded – undo
2227 2357
 		));
2228 2358
 		// Mayday!
2229 2359
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2230
-		if ($smcFunc['db_num_rows'] == 0)
2231
-			return;
2360
+		if ($smcFunc['db_num_rows'] == 0) {
2361
+					return;
2362
+		}
2232 2363
 
2233 2364
 		// Oh where, oh where has my little field gone. Oh where can it be...
2234
-		while ($row = $smcFunc['db_query']($request))
2235
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2365
+		while ($row = $smcFunc['db_query']($request)) {
2366
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2236 2367
 			{
2237 2368
 				$current_type = $row['Type'];
2369
+		}
2238 2370
 				break;
2239 2371
 			}
2240 2372
 	}
2241 2373
 
2242 2374
 	// If this doesn't match, the column may of been altered for a reason.
2243
-	if (trim($current_type) != trim($temp[3]))
2244
-		$temp[3] = $current_type;
2375
+	if (trim($current_type) != trim($temp[3])) {
2376
+			$temp[3] = $current_type;
2377
+	}
2245 2378
 
2246 2379
 	// Piece this back together.
2247 2380
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2253,8 +2386,9 @@  discard block
 block discarded – undo
2253 2386
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2254 2387
 	global $step_progress, $is_debug, $upcontext;
2255 2388
 
2256
-	if ($_GET['substep'] < $substep)
2257
-		$_GET['substep'] = $substep;
2389
+	if ($_GET['substep'] < $substep) {
2390
+			$_GET['substep'] = $substep;
2391
+	}
2258 2392
 
2259 2393
 	if ($command_line)
2260 2394
 	{
@@ -2267,29 +2401,33 @@  discard block
 block discarded – undo
2267 2401
 	}
2268 2402
 
2269 2403
 	@set_time_limit(300);
2270
-	if (function_exists('apache_reset_timeout'))
2271
-		@apache_reset_timeout();
2404
+	if (function_exists('apache_reset_timeout')) {
2405
+			@apache_reset_timeout();
2406
+	}
2272 2407
 
2273
-	if (time() - $start_time <= $timeLimitThreshold)
2274
-		return;
2408
+	if (time() - $start_time <= $timeLimitThreshold) {
2409
+			return;
2410
+	}
2275 2411
 
2276 2412
 	// Do we have some custom step progress stuff?
2277 2413
 	if (!empty($step_progress))
2278 2414
 	{
2279 2415
 		$upcontext['substep_progress'] = 0;
2280 2416
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2281
-		if ($step_progress['current'] > $step_progress['total'])
2282
-			$upcontext['substep_progress'] = 99.9;
2283
-		else
2284
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2417
+		if ($step_progress['current'] > $step_progress['total']) {
2418
+					$upcontext['substep_progress'] = 99.9;
2419
+		} else {
2420
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2421
+		}
2285 2422
 
2286 2423
 		// Make it nicely rounded.
2287 2424
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2288 2425
 	}
2289 2426
 
2290 2427
 	// If this is XML we just exit right away!
2291
-	if (isset($_GET['xml']))
2292
-		return upgradeExit();
2428
+	if (isset($_GET['xml'])) {
2429
+			return upgradeExit();
2430
+	}
2293 2431
 
2294 2432
 	// We're going to pause after this!
2295 2433
 	$upcontext['pause'] = true;
@@ -2297,13 +2435,15 @@  discard block
 block discarded – undo
2297 2435
 	$upcontext['query_string'] = '';
2298 2436
 	foreach ($_GET as $k => $v)
2299 2437
 	{
2300
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2301
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2438
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2439
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2440
+		}
2302 2441
 	}
2303 2442
 
2304 2443
 	// Custom warning?
2305
-	if (!empty($custom_warning))
2306
-		$upcontext['custom_warning'] = $custom_warning;
2444
+	if (!empty($custom_warning)) {
2445
+			$upcontext['custom_warning'] = $custom_warning;
2446
+	}
2307 2447
 
2308 2448
 	upgradeExit();
2309 2449
 }
@@ -2318,25 +2458,26 @@  discard block
 block discarded – undo
2318 2458
 	ob_implicit_flush(true);
2319 2459
 	@set_time_limit(600);
2320 2460
 
2321
-	if (!isset($_SERVER['argv']))
2322
-		$_SERVER['argv'] = array();
2461
+	if (!isset($_SERVER['argv'])) {
2462
+			$_SERVER['argv'] = array();
2463
+	}
2323 2464
 	$_GET['maint'] = 1;
2324 2465
 
2325 2466
 	foreach ($_SERVER['argv'] as $i => $arg)
2326 2467
 	{
2327
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2328
-			$_GET['lang'] = $match[1];
2329
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2330
-			continue;
2331
-		elseif ($arg == '--no-maintenance')
2332
-			$_GET['maint'] = 0;
2333
-		elseif ($arg == '--debug')
2334
-			$is_debug = true;
2335
-		elseif ($arg == '--backup')
2336
-			$_POST['backup'] = 1;
2337
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2338
-			$_GET['conv'] = 1;
2339
-		elseif ($i != 0)
2468
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2469
+					$_GET['lang'] = $match[1];
2470
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2471
+					continue;
2472
+		} elseif ($arg == '--no-maintenance') {
2473
+					$_GET['maint'] = 0;
2474
+		} elseif ($arg == '--debug') {
2475
+					$is_debug = true;
2476
+		} elseif ($arg == '--backup') {
2477
+					$_POST['backup'] = 1;
2478
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2479
+					$_GET['conv'] = 1;
2480
+		} elseif ($i != 0)
2340 2481
 		{
2341 2482
 			echo 'SMF Command-line Upgrader
2342 2483
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2350,10 +2491,12 @@  discard block
 block discarded – undo
2350 2491
 		}
2351 2492
 	}
2352 2493
 
2353
-	if (!php_version_check())
2354
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2355
-	if (!db_version_check())
2356
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2494
+	if (!php_version_check()) {
2495
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2496
+	}
2497
+	if (!db_version_check()) {
2498
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2499
+	}
2357 2500
 
2358 2501
 	// Do some checks to make sure they have proper privileges
2359 2502
 	db_extend('packages');
@@ -2368,34 +2511,39 @@  discard block
 block discarded – undo
2368 2511
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2369 2512
 
2370 2513
 	// Sorry... we need CREATE, ALTER and DROP
2371
-	if (!$create || !$alter || !$drop)
2372
-		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);
2514
+	if (!$create || !$alter || !$drop) {
2515
+			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);
2516
+	}
2373 2517
 
2374 2518
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2375 2519
 		&& @file_exists($sourcedir . '/QueryString.php')
2376 2520
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2377
-	if (!$check && !isset($modSettings['smfVersion']))
2378
-		print_error('Error: Some files are missing or out-of-date.', true);
2521
+	if (!$check && !isset($modSettings['smfVersion'])) {
2522
+			print_error('Error: Some files are missing or out-of-date.', true);
2523
+	}
2379 2524
 
2380 2525
 	// Do a quick version spot check.
2381 2526
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2382 2527
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2383
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2384
-		print_error('Error: Some files have not yet been updated properly.');
2528
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2529
+			print_error('Error: Some files have not yet been updated properly.');
2530
+	}
2385 2531
 
2386 2532
 	// Make sure Settings.php is writable.
2387 2533
 		quickFileWritable($boarddir . '/Settings.php');
2388
-	if (!is_writable($boarddir . '/Settings.php'))
2389
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2534
+	if (!is_writable($boarddir . '/Settings.php')) {
2535
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2536
+	}
2390 2537
 
2391 2538
 	// Make sure Settings_bak.php is writable.
2392 2539
 		quickFileWritable($boarddir . '/Settings_bak.php');
2393
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2394
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2540
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2541
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2542
+	}
2395 2543
 
2396
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2397
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2398
-	elseif (isset($modSettings['agreement']))
2544
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2545
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2546
+	} elseif (isset($modSettings['agreement']))
2399 2547
 	{
2400 2548
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2401 2549
 		fwrite($fp, $modSettings['agreement']);
@@ -2405,31 +2553,36 @@  discard block
 block discarded – undo
2405 2553
 	// Make sure Themes is writable.
2406 2554
 	quickFileWritable($modSettings['theme_dir']);
2407 2555
 
2408
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2409
-		print_error('Error: Unable to obtain write access to "Themes".');
2556
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2557
+			print_error('Error: Unable to obtain write access to "Themes".');
2558
+	}
2410 2559
 
2411 2560
 	// Make sure cache directory exists and is writable!
2412 2561
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2413
-	if (!file_exists($cachedir_temp))
2414
-		@mkdir($cachedir_temp);
2562
+	if (!file_exists($cachedir_temp)) {
2563
+			@mkdir($cachedir_temp);
2564
+	}
2415 2565
 
2416 2566
 	// Make sure the cache temp dir is writable.
2417 2567
 	quickFileWritable($cachedir_temp);
2418 2568
 
2419
-	if (!is_writable($cachedir_temp))
2420
-		print_error('Error: Unable to obtain write access to "cache".', true);
2569
+	if (!is_writable($cachedir_temp)) {
2570
+			print_error('Error: Unable to obtain write access to "cache".', true);
2571
+	}
2421 2572
 
2422
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2423
-		print_error('Error: Unable to find language files!', true);
2424
-	else
2573
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2574
+			print_error('Error: Unable to find language files!', true);
2575
+	} else
2425 2576
 	{
2426 2577
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2427 2578
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2428 2579
 
2429
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2430
-			print_error('Error: Language files out of date.', true);
2431
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2432
-			print_error('Error: Install language is missing for selected language.', true);
2580
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2581
+					print_error('Error: Language files out of date.', true);
2582
+		}
2583
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2584
+					print_error('Error: Install language is missing for selected language.', true);
2585
+		}
2433 2586
 
2434 2587
 		// Otherwise include it!
2435 2588
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2448,8 +2601,9 @@  discard block
 block discarded – undo
2448 2601
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2449 2602
 
2450 2603
 	// Done it already?
2451
-	if (!empty($_POST['utf8_done']))
2452
-		return true;
2604
+	if (!empty($_POST['utf8_done'])) {
2605
+			return true;
2606
+	}
2453 2607
 
2454 2608
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2455 2609
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2462,8 +2616,7 @@  discard block
 block discarded – undo
2462 2616
 		);
2463 2617
 
2464 2618
 		return true;
2465
-	}
2466
-	else
2619
+	} else
2467 2620
 	{
2468 2621
 		$upcontext['page_title'] = 'Converting to UTF8';
2469 2622
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2507,8 +2660,9 @@  discard block
 block discarded – undo
2507 2660
 			)
2508 2661
 		);
2509 2662
 		$db_charsets = array();
2510
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2511
-			$db_charsets[] = $row['Charset'];
2663
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2664
+					$db_charsets[] = $row['Charset'];
2665
+		}
2512 2666
 
2513 2667
 		$smcFunc['db_free_result']($request);
2514 2668
 
@@ -2544,13 +2698,15 @@  discard block
 block discarded – undo
2544 2698
 		// If there's a fulltext index, we need to drop it first...
2545 2699
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2546 2700
 		{
2547
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2548
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2701
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2702
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2549 2703
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2704
+			}
2550 2705
 			$smcFunc['db_free_result']($request);
2551 2706
 
2552
-			if (isset($upcontext['fulltext_index']))
2553
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2707
+			if (isset($upcontext['fulltext_index'])) {
2708
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2709
+			}
2554 2710
 		}
2555 2711
 
2556 2712
 		// Drop it and make a note...
@@ -2740,8 +2896,9 @@  discard block
 block discarded – undo
2740 2896
 			$replace = '%field%';
2741 2897
 
2742 2898
 			// Build a huge REPLACE statement...
2743
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2744
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2899
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2900
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2901
+			}
2745 2902
 		}
2746 2903
 
2747 2904
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2751,9 +2908,10 @@  discard block
 block discarded – undo
2751 2908
 		$upcontext['table_count'] = count($queryTables);
2752 2909
 	
2753 2910
 		// What ones have we already done?
2754
-		foreach ($queryTables as $id => $table)
2755
-			if ($id < $_GET['substep'])
2911
+		foreach ($queryTables as $id => $table) {
2912
+					if ($id < $_GET['substep'])
2756 2913
 				$upcontext['previous_tables'][] = $table;
2914
+		}
2757 2915
 
2758 2916
 		$upcontext['cur_table_num'] = $_GET['substep'];
2759 2917
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2790,8 +2948,9 @@  discard block
 block discarded – undo
2790 2948
 			nextSubstep($substep);
2791 2949
 
2792 2950
 			// Just to make sure it doesn't time out.
2793
-			if (function_exists('apache_reset_timeout'))
2794
-				@apache_reset_timeout();
2951
+			if (function_exists('apache_reset_timeout')) {
2952
+							@apache_reset_timeout();
2953
+			}
2795 2954
 
2796 2955
 			$table_charsets = array();
2797 2956
 
@@ -2812,8 +2971,9 @@  discard block
 block discarded – undo
2812 2971
 					{
2813 2972
 						list($charset) = explode('_', $collation);
2814 2973
 
2815
-						if (!isset($table_charsets[$charset]))
2816
-							$table_charsets[$charset] = array();
2974
+						if (!isset($table_charsets[$charset])) {
2975
+													$table_charsets[$charset] = array();
2976
+						}
2817 2977
 
2818 2978
 						$table_charsets[$charset][] = $column_info;
2819 2979
 					}
@@ -2853,10 +3013,11 @@  discard block
 block discarded – undo
2853 3013
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2854 3014
 				{
2855 3015
 					$update = '';
2856
-					foreach ($table_charsets as $charset => $columns)
2857
-						foreach ($columns as $column)
3016
+					foreach ($table_charsets as $charset => $columns) {
3017
+											foreach ($columns as $column)
2858 3018
 							$update .= '
2859 3019
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3020
+					}
2860 3021
 
2861 3022
 					$smcFunc['db_query']('', '
2862 3023
 						UPDATE {raw:table_name}
@@ -2881,8 +3042,9 @@  discard block
 block discarded – undo
2881 3042
 			// Now do the actual conversion (if still needed).
2882 3043
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2883 3044
 			{
2884
-				if ($command_line)
2885
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3045
+				if ($command_line) {
3046
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3047
+				}
2886 3048
 
2887 3049
 				$smcFunc['db_query']('', '
2888 3050
 					ALTER TABLE {raw:table_name}
@@ -2892,12 +3054,14 @@  discard block
 block discarded – undo
2892 3054
 					)
2893 3055
 				);
2894 3056
 
2895
-				if ($command_line)
2896
-					echo " done.\n";
3057
+				if ($command_line) {
3058
+									echo " done.\n";
3059
+				}
2897 3060
 			}
2898 3061
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2899
-			if (isset($_GET['xml']))
2900
-				return upgradeExit();
3062
+			if (isset($_GET['xml'])) {
3063
+							return upgradeExit();
3064
+			}
2901 3065
 		}
2902 3066
 
2903 3067
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2926,8 +3090,8 @@  discard block
 block discarded – undo
2926 3090
 		);
2927 3091
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2928 3092
 		{
2929
-			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)
2930
-				$smcFunc['db_query']('', '
3093
+			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) {
3094
+							$smcFunc['db_query']('', '
2931 3095
 					UPDATE {db_prefix}log_actions
2932 3096
 					SET extra = {string:extra}
2933 3097
 					WHERE id_action = {int:current_action}',
@@ -2936,6 +3100,7 @@  discard block
 block discarded – undo
2936 3100
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2937 3101
 					)
2938 3102
 				);
3103
+			}
2939 3104
 		}
2940 3105
 		$smcFunc['db_free_result']($request);
2941 3106
 
@@ -2957,15 +3122,17 @@  discard block
 block discarded – undo
2957 3122
 	// First thing's first - did we already do this?
2958 3123
 	if (!empty($modSettings['json_done']))
2959 3124
 	{
2960
-		if ($command_line)
2961
-			return DeleteUpgrade();
2962
-		else
2963
-			return true;
3125
+		if ($command_line) {
3126
+					return DeleteUpgrade();
3127
+		} else {
3128
+					return true;
3129
+		}
2964 3130
 	}
2965 3131
 
2966 3132
 	// Done it already - js wise?
2967
-	if (!empty($_POST['json_done']))
2968
-		return true;
3133
+	if (!empty($_POST['json_done'])) {
3134
+			return true;
3135
+	}
2969 3136
 
2970 3137
 	// List of tables affected by this function
2971 3138
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2997,12 +3164,14 @@  discard block
 block discarded – undo
2997 3164
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2998 3165
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2999 3166
 
3000
-	foreach ($keys as $id => $table)
3001
-		if ($id < $_GET['substep'])
3167
+	foreach ($keys as $id => $table) {
3168
+			if ($id < $_GET['substep'])
3002 3169
 			$upcontext['previous_tables'][] = $table;
3170
+	}
3003 3171
 
3004
-	if ($command_line)
3005
-		echo 'Converting data from serialize() to json_encode().';
3172
+	if ($command_line) {
3173
+			echo 'Converting data from serialize() to json_encode().';
3174
+	}
3006 3175
 
3007 3176
 	if (!$support_js || isset($_GET['xml']))
3008 3177
 	{
@@ -3042,8 +3211,9 @@  discard block
 block discarded – undo
3042 3211
 
3043 3212
 				// Loop through and fix these...
3044 3213
 				$new_settings = array();
3045
-				if ($command_line)
3046
-					echo "\n" . 'Fixing some settings...';
3214
+				if ($command_line) {
3215
+									echo "\n" . 'Fixing some settings...';
3216
+				}
3047 3217
 
3048 3218
 				foreach ($serialized_settings as $var)
3049 3219
 				{
@@ -3051,22 +3221,24 @@  discard block
 block discarded – undo
3051 3221
 					{
3052 3222
 						// Attempt to unserialize the setting
3053 3223
 						$temp = @safe_unserialize($modSettings[$var]);
3054
-						if (!$temp && $command_line)
3055
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3056
-						elseif ($temp !== false)
3057
-							$new_settings[$var] = json_encode($temp);
3224
+						if (!$temp && $command_line) {
3225
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3226
+						} elseif ($temp !== false) {
3227
+													$new_settings[$var] = json_encode($temp);
3228
+						}
3058 3229
 					}
3059 3230
 				}
3060 3231
 
3061 3232
 				// Update everything at once
3062
-				if (!function_exists('cache_put_data'))
3063
-					require_once($sourcedir . '/Load.php');
3233
+				if (!function_exists('cache_put_data')) {
3234
+									require_once($sourcedir . '/Load.php');
3235
+				}
3064 3236
 				updateSettings($new_settings, true);
3065 3237
 
3066
-				if ($command_line)
3067
-					echo ' done.';
3068
-			}
3069
-			elseif ($table == 'themes')
3238
+				if ($command_line) {
3239
+									echo ' done.';
3240
+				}
3241
+			} elseif ($table == 'themes')
3070 3242
 			{
3071 3243
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3072 3244
 				$query = $smcFunc['db_query']('', '
@@ -3085,10 +3257,11 @@  discard block
 block discarded – undo
3085 3257
 
3086 3258
 						if ($command_line)
3087 3259
 						{
3088
-							if ($temp === false)
3089
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3090
-							else
3091
-								echo "\n" . 'Fixing admin preferences...';
3260
+							if ($temp === false) {
3261
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3262
+							} else {
3263
+															echo "\n" . 'Fixing admin preferences...';
3264
+							}
3092 3265
 						}
3093 3266
 
3094 3267
 						if ($temp !== false)
@@ -3110,15 +3283,15 @@  discard block
 block discarded – undo
3110 3283
 								)
3111 3284
 							);
3112 3285
 
3113
-							if ($command_line)
3114
-								echo ' done.';
3286
+							if ($command_line) {
3287
+															echo ' done.';
3288
+							}
3115 3289
 						}
3116 3290
 					}
3117 3291
 
3118 3292
 					$smcFunc['db_free_result']($query);
3119 3293
 				}
3120
-			}
3121
-			else
3294
+			} else
3122 3295
 			{
3123 3296
 				// First item is always the key...
3124 3297
 				$key = $info[0];
@@ -3129,8 +3302,7 @@  discard block
 block discarded – undo
3129 3302
 				{
3130 3303
 					$col_select = $info[1];
3131 3304
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3132
-				}
3133
-				else
3305
+				} else
3134 3306
 				{
3135 3307
 					$col_select = implode(', ', $info);
3136 3308
 				}
@@ -3163,8 +3335,7 @@  discard block
 block discarded – undo
3163 3335
 								if ($temp === false && $command_line)
3164 3336
 								{
3165 3337
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3166
-								}
3167
-								else
3338
+								} else
3168 3339
 								{
3169 3340
 									$row[$col] = json_encode($temp);
3170 3341
 
@@ -3189,16 +3360,18 @@  discard block
 block discarded – undo
3189 3360
 						}
3190 3361
 					}
3191 3362
 
3192
-					if ($command_line)
3193
-						echo ' done.';
3363
+					if ($command_line) {
3364
+											echo ' done.';
3365
+					}
3194 3366
 
3195 3367
 					// Free up some memory...
3196 3368
 					$smcFunc['db_free_result']($query);
3197 3369
 				}
3198 3370
 			}
3199 3371
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3200
-			if (isset($_GET['xml']))
3201
-				return upgradeExit();
3372
+			if (isset($_GET['xml'])) {
3373
+							return upgradeExit();
3374
+			}
3202 3375
 		}
3203 3376
 
3204 3377
 		if ($command_line)
@@ -3213,8 +3386,9 @@  discard block
 block discarded – undo
3213 3386
 
3214 3387
 		$_GET['substep'] = 0;
3215 3388
 		// Make sure we move on!
3216
-		if ($command_line)
3217
-			return DeleteUpgrade();
3389
+		if ($command_line) {
3390
+					return DeleteUpgrade();
3391
+		}
3218 3392
 
3219 3393
 		return true;
3220 3394
 	}
@@ -3234,14 +3408,16 @@  discard block
 block discarded – undo
3234 3408
 	global $upcontext, $txt, $settings;
3235 3409
 
3236 3410
 	// Don't call me twice!
3237
-	if (!empty($upcontext['chmod_called']))
3238
-		return;
3411
+	if (!empty($upcontext['chmod_called'])) {
3412
+			return;
3413
+	}
3239 3414
 
3240 3415
 	$upcontext['chmod_called'] = true;
3241 3416
 
3242 3417
 	// Nothing?
3243
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3244
-		return;
3418
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3419
+			return;
3420
+	}
3245 3421
 
3246 3422
 	// Was it a problem with Windows?
3247 3423
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3273,11 +3449,12 @@  discard block
 block discarded – undo
3273 3449
 					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\');
3274 3450
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3275 3451
 
3276
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3277
-		echo '
3452
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3453
+			echo '
3278 3454
 					content.write(\'<hr>\n\t\t\t\');
3279 3455
 					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\');
3280 3456
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3457
+	}
3281 3458
 
3282 3459
 	echo '
3283 3460
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3285,17 +3462,19 @@  discard block
 block discarded – undo
3285 3462
 				}
3286 3463
 			</script>';
3287 3464
 
3288
-	if (!empty($upcontext['chmod']['ftp_error']))
3289
-		echo '
3465
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3466
+			echo '
3290 3467
 			<div class="error_message red">
3291 3468
 				The following error was encountered when trying to connect:<br><br>
3292 3469
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3293 3470
 			</div>
3294 3471
 			<br>';
3472
+	}
3295 3473
 
3296
-	if (empty($upcontext['chmod_in_form']))
3297
-		echo '
3474
+	if (empty($upcontext['chmod_in_form'])) {
3475
+			echo '
3298 3476
 	<form action="', $upcontext['form_url'], '" method="post">';
3477
+	}
3299 3478
 
3300 3479
 	echo '
3301 3480
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3330,10 +3509,11 @@  discard block
 block discarded – undo
3330 3509
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3331 3510
 	</div>';
3332 3511
 
3333
-	if (empty($upcontext['chmod_in_form']))
3334
-		echo '
3512
+	if (empty($upcontext['chmod_in_form'])) {
3513
+			echo '
3335 3514
 	</form>';
3336
-}
3515
+	}
3516
+	}
3337 3517
 
3338 3518
 function template_upgrade_above()
3339 3519
 {
@@ -3393,9 +3573,10 @@  discard block
 block discarded – undo
3393 3573
 				<h2>', $txt['upgrade_progress'], '</h2>
3394 3574
 				<ul>';
3395 3575
 
3396
-	foreach ($upcontext['steps'] as $num => $step)
3397
-		echo '
3576
+	foreach ($upcontext['steps'] as $num => $step) {
3577
+			echo '
3398 3578
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3579
+	}
3399 3580
 
3400 3581
 	echo '
3401 3582
 					</ul>
@@ -3408,8 +3589,8 @@  discard block
 block discarded – undo
3408 3589
 				</div>
3409 3590
 			</div>';
3410 3591
 
3411
-	if (isset($upcontext['step_progress']))
3412
-		echo '
3592
+	if (isset($upcontext['step_progress'])) {
3593
+			echo '
3413 3594
 				<br>
3414 3595
 				<br>
3415 3596
 				<div id="progress_bar_step">
@@ -3418,6 +3599,7 @@  discard block
 block discarded – undo
3418 3599
 						<span>', $txt['upgrade_step_progress'], '</span>
3419 3600
 					</div>
3420 3601
 				</div>';
3602
+	}
3421 3603
 
3422 3604
 	echo '
3423 3605
 				<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>
@@ -3448,32 +3630,36 @@  discard block
 block discarded – undo
3448 3630
 {
3449 3631
 	global $upcontext, $txt;
3450 3632
 
3451
-	if (!empty($upcontext['pause']))
3452
-		echo '
3633
+	if (!empty($upcontext['pause'])) {
3634
+			echo '
3453 3635
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3454 3636
 
3455 3637
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3456 3638
 								<h3>
3457 3639
 									', $txt['upgrade_paused_overload'], '
3458 3640
 								</h3>';
3641
+	}
3459 3642
 
3460
-	if (!empty($upcontext['custom_warning']))
3461
-		echo '
3643
+	if (!empty($upcontext['custom_warning'])) {
3644
+			echo '
3462 3645
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3463 3646
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3464 3647
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3465 3648
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3466 3649
 								</div>';
3650
+	}
3467 3651
 
3468 3652
 	echo '
3469 3653
 								<div class="righttext" style="margin: 1ex;">';
3470 3654
 
3471
-	if (!empty($upcontext['continue']))
3472
-		echo '
3655
+	if (!empty($upcontext['continue'])) {
3656
+			echo '
3473 3657
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3474
-	if (!empty($upcontext['skip']))
3475
-		echo '
3658
+	}
3659
+	if (!empty($upcontext['skip'])) {
3660
+			echo '
3476 3661
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3662
+	}
3477 3663
 
3478 3664
 	echo '
3479 3665
 								</div>
@@ -3523,11 +3709,12 @@  discard block
 block discarded – undo
3523 3709
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3524 3710
 	<smf>';
3525 3711
 
3526
-	if (!empty($upcontext['get_data']))
3527
-		foreach ($upcontext['get_data'] as $k => $v)
3712
+	if (!empty($upcontext['get_data'])) {
3713
+			foreach ($upcontext['get_data'] as $k => $v)
3528 3714
 			echo '
3529 3715
 		<get key="', $k, '">', $v, '</get>';
3530
-}
3716
+	}
3717
+	}
3531 3718
 
3532 3719
 function template_xml_below()
3533 3720
 {
@@ -3568,8 +3755,8 @@  discard block
 block discarded – undo
3568 3755
 	template_chmod();
3569 3756
 
3570 3757
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3571
-	if ($upcontext['is_large_forum'])
3572
-		echo '
3758
+	if ($upcontext['is_large_forum']) {
3759
+			echo '
3573 3760
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3574 3761
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3575 3762
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3577,10 +3764,11 @@  discard block
 block discarded – undo
3577 3764
 				', $txt['upgrade_warning_lots_data'], '
3578 3765
 			</div>
3579 3766
 		</div>';
3767
+	}
3580 3768
 
3581 3769
 	// A warning message?
3582
-	if (!empty($upcontext['warning']))
3583
-		echo '
3770
+	if (!empty($upcontext['warning'])) {
3771
+			echo '
3584 3772
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3585 3773
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3586 3774
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3588,6 +3776,7 @@  discard block
 block discarded – undo
3588 3776
 				', $upcontext['warning'], '
3589 3777
 			</div>
3590 3778
 		</div>';
3779
+	}
3591 3780
 
3592 3781
 	// Paths are incorrect?
3593 3782
 	echo '
@@ -3603,20 +3792,22 @@  discard block
 block discarded – undo
3603 3792
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3604 3793
 	{
3605 3794
 		$ago = time() - $upcontext['started'];
3606
-		if ($ago < 60)
3607
-			$ago = $ago . ' seconds';
3608
-		elseif ($ago < 3600)
3609
-			$ago = (int) ($ago / 60) . ' minutes';
3610
-		else
3611
-			$ago = (int) ($ago / 3600) . ' hours';
3795
+		if ($ago < 60) {
3796
+					$ago = $ago . ' seconds';
3797
+		} elseif ($ago < 3600) {
3798
+					$ago = (int) ($ago / 60) . ' minutes';
3799
+		} else {
3800
+					$ago = (int) ($ago / 3600) . ' hours';
3801
+		}
3612 3802
 
3613 3803
 		$active = time() - $upcontext['updated'];
3614
-		if ($active < 60)
3615
-			$updated = $active . ' seconds';
3616
-		elseif ($active < 3600)
3617
-			$updated = (int) ($active / 60) . ' minutes';
3618
-		else
3619
-			$updated = (int) ($active / 3600) . ' hours';
3804
+		if ($active < 60) {
3805
+					$updated = $active . ' seconds';
3806
+		} elseif ($active < 3600) {
3807
+					$updated = (int) ($active / 60) . ' minutes';
3808
+		} else {
3809
+					$updated = (int) ($active / 3600) . ' hours';
3810
+		}
3620 3811
 
3621 3812
 		echo '
3622 3813
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3625,16 +3816,18 @@  discard block
 block discarded – undo
3625 3816
 			<div style="padding-left: 6ex;">
3626 3817
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3627 3818
 
3628
-		if ($active < 600)
3629
-			echo '
3819
+		if ($active < 600) {
3820
+					echo '
3630 3821
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3822
+		}
3631 3823
 
3632
-		if ($active > $upcontext['inactive_timeout'])
3633
-			echo '
3824
+		if ($active > $upcontext['inactive_timeout']) {
3825
+					echo '
3634 3826
 				<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.';
3635
-		else
3636
-			echo '
3827
+		} else {
3828
+					echo '
3637 3829
 				<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!');
3830
+		}
3638 3831
 
3639 3832
 		echo '
3640 3833
 			</div>
@@ -3650,9 +3843,10 @@  discard block
 block discarded – undo
3650 3843
 					<td>
3651 3844
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3652 3845
 
3653
-	if (!empty($upcontext['username_incorrect']))
3654
-		echo '
3846
+	if (!empty($upcontext['username_incorrect'])) {
3847
+			echo '
3655 3848
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3849
+	}
3656 3850
 
3657 3851
 	echo '
3658 3852
 					</td>
@@ -3663,9 +3857,10 @@  discard block
 block discarded – undo
3663 3857
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3664 3858
 						<input type="hidden" name="hash_passwrd" value="">';
3665 3859
 
3666
-	if (!empty($upcontext['password_failed']))
3667
-		echo '
3860
+	if (!empty($upcontext['password_failed'])) {
3861
+			echo '
3668 3862
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3863
+	}
3669 3864
 
3670 3865
 	echo '
3671 3866
 					</td>
@@ -3736,8 +3931,8 @@  discard block
 block discarded – undo
3736 3931
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3737 3932
 
3738 3933
 	// Warning message?
3739
-	if (!empty($upcontext['upgrade_options_warning']))
3740
-		echo '
3934
+	if (!empty($upcontext['upgrade_options_warning'])) {
3935
+			echo '
3741 3936
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3742 3937
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3743 3938
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3745,6 +3940,7 @@  discard block
 block discarded – undo
3745 3940
 				', $upcontext['upgrade_options_warning'], '
3746 3941
 			</div>
3747 3942
 		</div>';
3943
+	}
3748 3944
 
3749 3945
 	echo '
3750 3946
 				<table>
@@ -3787,8 +3983,8 @@  discard block
 block discarded – undo
3787 3983
 						</td>
3788 3984
 					</tr>';
3789 3985
 
3790
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3791
-		echo '
3986
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3987
+			echo '
3792 3988
 					<tr valign="top">
3793 3989
 						<td width="2%">
3794 3990
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3797,6 +3993,7 @@  discard block
 block discarded – undo
3797 3993
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3798 3994
 						</td>
3799 3995
 					</tr>';
3996
+	}
3800 3997
 
3801 3998
 	echo '
3802 3999
 					<tr valign="top">
@@ -3834,10 +4031,11 @@  discard block
 block discarded – undo
3834 4031
 			</div>';
3835 4032
 
3836 4033
 	// Dont any tables so far?
3837
-	if (!empty($upcontext['previous_tables']))
3838
-		foreach ($upcontext['previous_tables'] as $table)
4034
+	if (!empty($upcontext['previous_tables'])) {
4035
+			foreach ($upcontext['previous_tables'] as $table)
3839 4036
 			echo '
3840 4037
 			<br>Completed Table: &quot;', $table, '&quot;.';
4038
+	}
3841 4039
 
3842 4040
 	echo '
3843 4041
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3874,12 +4072,13 @@  discard block
 block discarded – undo
3874 4072
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3875 4073
 
3876 4074
 		// If debug flood the screen.
3877
-		if ($is_debug)
3878
-			echo '
4075
+		if ($is_debug) {
4076
+					echo '
3879 4077
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3880 4078
 
3881 4079
 				if (document.getElementById(\'debug_section\').scrollHeight)
3882 4080
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4081
+		}
3883 4082
 
3884 4083
 		echo '
3885 4084
 				// Get the next update...
@@ -3912,8 +4111,9 @@  discard block
 block discarded – undo
3912 4111
 {
3913 4112
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3914 4113
 
3915
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3916
-		$is_debug = true;
4114
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4115
+			$is_debug = true;
4116
+	}
3917 4117
 
3918 4118
 	echo '
3919 4119
 		<h3>Executing database changes</h3>
@@ -3928,8 +4128,9 @@  discard block
 block discarded – undo
3928 4128
 	{
3929 4129
 		foreach ($upcontext['actioned_items'] as $num => $item)
3930 4130
 		{
3931
-			if ($num != 0)
3932
-				echo ' Successful!';
4131
+			if ($num != 0) {
4132
+							echo ' Successful!';
4133
+			}
3933 4134
 			echo '<br>' . $item;
3934 4135
 		}
3935 4136
 		if (!empty($upcontext['changes_complete']))
@@ -3942,28 +4143,32 @@  discard block
 block discarded – undo
3942 4143
 				$seconds = intval($active % 60);
3943 4144
 
3944 4145
 				$totalTime = '';
3945
-				if ($hours > 0)
3946
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3947
-				if ($minutes > 0)
3948
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3949
-				if ($seconds > 0)
3950
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4146
+				if ($hours > 0) {
4147
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4148
+				}
4149
+				if ($minutes > 0) {
4150
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4151
+				}
4152
+				if ($seconds > 0) {
4153
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4154
+				}
3951 4155
 			}
3952 4156
 
3953
-			if ($is_debug && !empty($totalTime))
3954
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3955
-			else
3956
-				echo ' Successful!<br><br>';
4157
+			if ($is_debug && !empty($totalTime)) {
4158
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4159
+			} else {
4160
+							echo ' Successful!<br><br>';
4161
+			}
3957 4162
 
3958 4163
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3959 4164
 		}
3960
-	}
3961
-	else
4165
+	} else
3962 4166
 	{
3963 4167
 		// Tell them how many files we have in total.
3964
-		if ($upcontext['file_count'] > 1)
3965
-			echo '
4168
+		if ($upcontext['file_count'] > 1) {
4169
+					echo '
3966 4170
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4171
+		}
3967 4172
 
3968 4173
 		echo '
3969 4174
 		<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>
@@ -3979,19 +4184,23 @@  discard block
 block discarded – undo
3979 4184
 				$seconds = intval($active % 60);
3980 4185
 
3981 4186
 				$totalTime = '';
3982
-				if ($hours > 0)
3983
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3984
-				if ($minutes > 0)
3985
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3986
-				if ($seconds > 0)
3987
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4187
+				if ($hours > 0) {
4188
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4189
+				}
4190
+				if ($minutes > 0) {
4191
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4192
+				}
4193
+				if ($seconds > 0) {
4194
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4195
+				}
3988 4196
 			}
3989 4197
 
3990 4198
 			echo '
3991 4199
 			<br><span id="upgradeCompleted">';
3992 4200
 
3993
-			if (!empty($totalTime))
3994
-				echo 'Completed in ', $totalTime, '<br>';
4201
+			if (!empty($totalTime)) {
4202
+							echo 'Completed in ', $totalTime, '<br>';
4203
+			}
3995 4204
 
3996 4205
 			echo '</span>
3997 4206
 			<div id="debug_section" style="height: 117px; overflow: auto;">
@@ -4028,9 +4237,10 @@  discard block
 block discarded – undo
4028 4237
 			var getData = "";
4029 4238
 			var debugItems = ', $upcontext['debug_items'], ';';
4030 4239
 
4031
-		if ($is_debug)
4032
-			echo '
4240
+		if ($is_debug) {
4241
+					echo '
4033 4242
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4243
+		}
4034 4244
 
4035 4245
 		echo '
4036 4246
 			function getNextItem()
@@ -4070,9 +4280,10 @@  discard block
 block discarded – undo
4070 4280
 						document.getElementById("error_block").style.display = "";
4071 4281
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4072 4282
 
4073
-	if ($is_debug)
4074
-		echo '
4283
+	if ($is_debug) {
4284
+			echo '
4075 4285
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4286
+	}
4076 4287
 
4077 4288
 	echo '
4078 4289
 					}
@@ -4093,9 +4304,10 @@  discard block
 block discarded – undo
4093 4304
 						document.getElementById("error_block").style.display = "";
4094 4305
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4095 4306
 
4096
-	if ($is_debug)
4097
-		echo '
4307
+	if ($is_debug) {
4308
+			echo '
4098 4309
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4310
+	}
4099 4311
 
4100 4312
 	echo '
4101 4313
 					}
@@ -4154,8 +4366,8 @@  discard block
 block discarded – undo
4154 4366
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4155 4367
 				{';
4156 4368
 
4157
-		if ($is_debug)
4158
-			echo '
4369
+		if ($is_debug) {
4370
+					echo '
4159 4371
 					document.getElementById(\'debug_section\').style.display = "none";
4160 4372
 
4161 4373
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4173,6 +4385,7 @@  discard block
 block discarded – undo
4173 4385
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4174 4386
 
4175 4387
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4388
+		}
4176 4389
 
4177 4390
 		echo '
4178 4391
 
@@ -4180,9 +4393,10 @@  discard block
 block discarded – undo
4180 4393
 					document.getElementById(\'contbutt\').disabled = 0;
4181 4394
 					document.getElementById(\'database_done\').value = 1;';
4182 4395
 
4183
-		if ($upcontext['file_count'] > 1)
4184
-			echo '
4396
+		if ($upcontext['file_count'] > 1) {
4397
+					echo '
4185 4398
 					document.getElementById(\'info1\').style.display = "none";';
4399
+		}
4186 4400
 
4187 4401
 		echo '
4188 4402
 					document.getElementById(\'info2\').style.display = "none";
@@ -4195,9 +4409,10 @@  discard block
 block discarded – undo
4195 4409
 					lastItem = 0;
4196 4410
 					prevFile = curFile;';
4197 4411
 
4198
-		if ($is_debug)
4199
-			echo '
4412
+		if ($is_debug) {
4413
+					echo '
4200 4414
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4415
+		}
4201 4416
 
4202 4417
 		echo '
4203 4418
 					getNextItem();
@@ -4205,8 +4420,8 @@  discard block
 block discarded – undo
4205 4420
 				}';
4206 4421
 
4207 4422
 		// If debug scroll the screen.
4208
-		if ($is_debug)
4209
-			echo '
4423
+		if ($is_debug) {
4424
+					echo '
4210 4425
 				if (iLastSubStepProgress == -1)
4211 4426
 				{
4212 4427
 					// Give it consistent dots.
@@ -4225,6 +4440,7 @@  discard block
 block discarded – undo
4225 4440
 
4226 4441
 				if (document.getElementById(\'debug_section\').scrollHeight)
4227 4442
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4443
+		}
4228 4444
 
4229 4445
 		echo '
4230 4446
 				// Update the page.
@@ -4285,9 +4501,10 @@  discard block
 block discarded – undo
4285 4501
 			}';
4286 4502
 
4287 4503
 		// Start things off assuming we've not errored.
4288
-		if (empty($upcontext['error_message']))
4289
-			echo '
4504
+		if (empty($upcontext['error_message'])) {
4505
+					echo '
4290 4506
 			getNextItem();';
4507
+		}
4291 4508
 
4292 4509
 		echo '
4293 4510
 		//# sourceURL=dynamicScript-dbch.js 
@@ -4305,18 +4522,21 @@  discard block
 block discarded – undo
4305 4522
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4306 4523
 	<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>';
4307 4524
 
4308
-	if (!empty($upcontext['error_message']))
4309
-		echo '
4525
+	if (!empty($upcontext['error_message'])) {
4526
+			echo '
4310 4527
 	<error>', $upcontext['error_message'], '</error>';
4528
+	}
4311 4529
 
4312
-	if (!empty($upcontext['error_string']))
4313
-		echo '
4530
+	if (!empty($upcontext['error_string'])) {
4531
+			echo '
4314 4532
 	<sql>', $upcontext['error_string'], '</sql>';
4533
+	}
4315 4534
 
4316
-	if ($is_debug)
4317
-		echo '
4535
+	if ($is_debug) {
4536
+			echo '
4318 4537
 	<curtime>', time(), '</curtime>';
4319
-}
4538
+	}
4539
+	}
4320 4540
 
4321 4541
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4322 4542
 function template_convert_utf8()
@@ -4335,18 +4555,20 @@  discard block
 block discarded – undo
4335 4555
 			</div>';
4336 4556
 
4337 4557
 	// Done any tables so far?
4338
-	if (!empty($upcontext['previous_tables']))
4339
-		foreach ($upcontext['previous_tables'] as $table)
4558
+	if (!empty($upcontext['previous_tables'])) {
4559
+			foreach ($upcontext['previous_tables'] as $table)
4340 4560
 			echo '
4341 4561
 			<br>Completed Table: &quot;', $table, '&quot;.';
4562
+	}
4342 4563
 
4343 4564
 	echo '
4344 4565
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4345 4566
 
4346 4567
 	// If we dropped their index, let's let them know
4347
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4348
-		echo '
4568
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4569
+			echo '
4349 4570
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4571
+	}
4350 4572
 
4351 4573
 	echo '
4352 4574
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4382,12 +4604,13 @@  discard block
 block discarded – undo
4382 4604
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4383 4605
 
4384 4606
 		// If debug flood the screen.
4385
-		if ($is_debug)
4386
-			echo '
4607
+		if ($is_debug) {
4608
+					echo '
4387 4609
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4388 4610
 
4389 4611
 				if (document.getElementById(\'debug_section\').scrollHeight)
4390 4612
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4613
+		}
4391 4614
 
4392 4615
 		echo '
4393 4616
 				// Get the next update...
@@ -4432,19 +4655,21 @@  discard block
 block discarded – undo
4432 4655
 			</div>';
4433 4656
 
4434 4657
 	// Dont any tables so far?
4435
-	if (!empty($upcontext['previous_tables']))
4436
-		foreach ($upcontext['previous_tables'] as $table)
4658
+	if (!empty($upcontext['previous_tables'])) {
4659
+			foreach ($upcontext['previous_tables'] as $table)
4437 4660
 			echo '
4438 4661
 			<br>Completed Table: &quot;', $table, '&quot;.';
4662
+	}
4439 4663
 
4440 4664
 	echo '
4441 4665
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4442 4666
 			<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>';
4443 4667
 
4444 4668
 	// Try to make sure substep was reset.
4445
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4446
-		echo '
4669
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4670
+			echo '
4447 4671
 			<input type="hidden" name="substep" id="substep" value="0">';
4672
+	}
4448 4673
 
4449 4674
 	// Continue please!
4450 4675
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4477,12 +4702,13 @@  discard block
 block discarded – undo
4477 4702
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4478 4703
 
4479 4704
 		// If debug flood the screen.
4480
-		if ($is_debug)
4481
-			echo '
4705
+		if ($is_debug) {
4706
+					echo '
4482 4707
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4483 4708
 
4484 4709
 				if (document.getElementById(\'debug_section\').scrollHeight)
4485 4710
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4711
+		}
4486 4712
 
4487 4713
 		echo '
4488 4714
 				// Get the next update...
@@ -4518,8 +4744,8 @@  discard block
 block discarded – undo
4518 4744
 	<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>
4519 4745
 	<form action="', $boardurl, '/index.php">';
4520 4746
 
4521
-	if (!empty($upcontext['can_delete_script']))
4522
-		echo '
4747
+	if (!empty($upcontext['can_delete_script'])) {
4748
+			echo '
4523 4749
 			<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>
4524 4750
 			<script>
4525 4751
 				function doTheDelete(theCheck)
@@ -4531,6 +4757,7 @@  discard block
 block discarded – undo
4531 4757
 				}
4532 4758
 			</script>
4533 4759
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4760
+	}
4534 4761
 
4535 4762
 	$active = time() - $upcontext['started'];
4536 4763
 	$hours = floor($active / 3600);
@@ -4540,16 +4767,20 @@  discard block
 block discarded – undo
4540 4767
 	if ($is_debug)
4541 4768
 	{
4542 4769
 		$totalTime = '';
4543
-		if ($hours > 0)
4544
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4545
-		if ($minutes > 0)
4546
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4547
-		if ($seconds > 0)
4548
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4770
+		if ($hours > 0) {
4771
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4772
+		}
4773
+		if ($minutes > 0) {
4774
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4775
+		}
4776
+		if ($seconds > 0) {
4777
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4778
+		}
4549 4779
 	}
4550 4780
 
4551
-	if ($is_debug && !empty($totalTime))
4552
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4781
+	if ($is_debug && !empty($totalTime)) {
4782
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4783
+	}
4553 4784
 
4554 4785
 	echo '<br>
4555 4786
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4576,8 +4807,9 @@  discard block
 block discarded – undo
4576 4807
 
4577 4808
 	$current_substep = $_GET['substep'];
4578 4809
 
4579
-	if (empty($_GET['a']))
4580
-		$_GET['a'] = 0;
4810
+	if (empty($_GET['a'])) {
4811
+			$_GET['a'] = 0;
4812
+	}
4581 4813
 	$step_progress['name'] = 'Converting ips';
4582 4814
 	$step_progress['current'] = $_GET['a'];
4583 4815
 
@@ -4620,16 +4852,19 @@  discard block
 block discarded – undo
4620 4852
 				'empty' => '',
4621 4853
 				'limit' => $limit,
4622 4854
 		));
4623
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4624
-			$arIp[] = $row[$oldCol];
4855
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4856
+					$arIp[] = $row[$oldCol];
4857
+		}
4625 4858
 		$smcFunc['db_free_result']($request);
4626 4859
 
4627 4860
 		// Special case, null ip could keep us in a loop.
4628
-		if (is_null($arIp[0]))
4629
-			unset($arIp[0]);
4861
+		if (is_null($arIp[0])) {
4862
+					unset($arIp[0]);
4863
+		}
4630 4864
 
4631
-		if (empty($arIp))
4632
-			$is_done = true;
4865
+		if (empty($arIp)) {
4866
+					$is_done = true;
4867
+		}
4633 4868
 
4634 4869
 		$updates = array();
4635 4870
 		$cases = array();
@@ -4638,16 +4873,18 @@  discard block
 block discarded – undo
4638 4873
 		{
4639 4874
 			$arIp[$i] = trim($arIp[$i]);
4640 4875
 
4641
-			if (empty($arIp[$i]))
4642
-				continue;
4876
+			if (empty($arIp[$i])) {
4877
+							continue;
4878
+			}
4643 4879
 
4644 4880
 			$updates['ip' . $i] = $arIp[$i];
4645 4881
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4646 4882
 
4647 4883
 			if ($setSize > 0 && $i % $setSize === 0)
4648 4884
 			{
4649
-				if (count($updates) == 1)
4650
-					continue;
4885
+				if (count($updates) == 1) {
4886
+									continue;
4887
+				}
4651 4888
 
4652 4889
 				$updates['whereSet'] = array_values($updates);
4653 4890
 				$smcFunc['db_query']('', '
@@ -4681,8 +4918,7 @@  discard block
 block discarded – undo
4681 4918
 							'ip' => $ip
4682 4919
 					));
4683 4920
 				}
4684
-			}
4685
-			else
4921
+			} else
4686 4922
 			{
4687 4923
 				$updates['whereSet'] = array_values($updates);
4688 4924
 				$smcFunc['db_query']('', '
@@ -4696,9 +4932,9 @@  discard block
 block discarded – undo
4696 4932
 					$updates
4697 4933
 				);
4698 4934
 			}
4935
+		} else {
4936
+					$is_done = true;
4699 4937
 		}
4700
-		else
4701
-			$is_done = true;
4702 4938
 
4703 4939
 		$_GET['a'] += $limit;
4704 4940
 		$step_progress['current'] = $_GET['a'];
@@ -4724,10 +4960,11 @@  discard block
 block discarded – undo
4724 4960
  
4725 4961
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4726 4962
 
4727
-	if (isset($columns[$column]))
4728
-		return $columns[$column];
4729
-	else
4730
-		return null;
4731
-}
4963
+	if (isset($columns[$column])) {
4964
+			return $columns[$column];
4965
+	} else {
4966
+			return null;
4967
+	}
4968
+	}
4732 4969
 
4733 4970
 ?>
4734 4971
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['validImageTypes'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
562
+				if (isset($context['validImageTypes'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['validImageTypes'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
713
+		elseif (isset($context['validImageTypes'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['validImageTypes'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -882,8 +930,9 @@  discard block
 block discarded – undo
882 930
 	$externalParse = false;
883 931
 
884 932
 	// Meh...
885
-	if (empty($attachID))
886
-		return 'attachments_no_data_loaded';
933
+	if (empty($attachID)) {
934
+			return 'attachments_no_data_loaded';
935
+	}
887 936
 
888 937
 	// Make it easy.
889 938
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -892,20 +941,23 @@  discard block
 block discarded – undo
892 941
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
893 942
 
894 943
 	// "I am innocent of the blood of this just person: see ye to it."
895
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
896
-		return $externalParse;
944
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
945
+			return $externalParse;
946
+	}
897 947
 
898 948
 	//Are attachments enable?
899
-	if (empty($modSettings['attachmentEnable']))
900
-		return 'attachments_not_enable';
949
+	if (empty($modSettings['attachmentEnable'])) {
950
+			return 'attachments_not_enable';
951
+	}
901 952
 
902 953
 	// Previewing much? no msg ID has been set yet.
903 954
 	if (!empty($context['preview_message']))
904 955
 	{
905 956
 		$allAttachments = getAttachsByMsg(0);
906 957
 
907
-		if (empty($allAttachments[0][$attachID]))
908
-			return 'attachments_no_data_loaded';
958
+		if (empty($allAttachments[0][$attachID])) {
959
+					return 'attachments_no_data_loaded';
960
+		}
909 961
 
910 962
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
911 963
 
@@ -917,57 +969,66 @@  discard block
 block discarded – undo
917 969
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
918 970
 
919 971
 		// Fix the thumbnail too, if the image has one.
920
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
921
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
973
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
974
+		}
922 975
 
923 976
 		return $attachContext;
924 977
 	}
925 978
 
926 979
 	// There is always the chance someone else has already done our dirty work...
927 980
 	// If so, all pertinent checks were already done. Hopefully...
928
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
929
-		return $context['current_attachments'][$attachID];
981
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
982
+			return $context['current_attachments'][$attachID];
983
+	}
930 984
 
931 985
 	// If we are lucky enough to be in $board's scope then check it!
932
-	if (!empty($board) && !allowedTo('view_attachments', $board))
933
-		return 'attachments_not_allowed_to_see';
986
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
987
+			return 'attachments_not_allowed_to_see';
988
+	}
934 989
 
935 990
 	// Get the message info associated with this particular attach ID.
936 991
 	$attachInfo = getAttachMsgInfo($attachID);
937 992
 
938 993
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
939
-	if (empty($attachInfo) || empty($attachInfo['msg']))
940
-		return 'attachments_no_msg_associated';
994
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
995
+			return 'attachments_no_msg_associated';
996
+	}
941 997
 
942 998
 	// Hold it! got the info now check if you can see this attachment.
943
-	if (!allowedTo('view_attachments', $attachInfo['board']))
944
-		return 'attachments_not_allowed_to_see';
999
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
1000
+			return 'attachments_not_allowed_to_see';
1001
+	}
945 1002
 
946 1003
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
947 1004
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
948 1005
 
949 1006
 	// No point in keep going further.
950
-	if (!allowedTo('view_attachments', $attachContext['board']))
951
-		return 'attachments_not_allowed_to_see';
1007
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1008
+			return 'attachments_not_allowed_to_see';
1009
+	}
952 1010
 
953 1011
 	// Load this particular attach's context.
954
-	if (!empty($attachContext))
955
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	if (!empty($attachContext)) {
1013
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1014
+	}
956 1015
 
957 1016
 	// One last check, you know, gotta be paranoid...
958
-	else
959
-		return 'attachments_no_data_loaded';
1017
+	else {
1018
+			return 'attachments_no_data_loaded';
1019
+	}
960 1020
 
961 1021
 	// This is the last "if" I promise!
962
-	if (empty($attachLoaded))
963
-		return 'attachments_no_data_loaded';
964
-
965
-	else
966
-		$attachContext = $attachLoaded[$attachID];
1022
+	if (empty($attachLoaded)) {
1023
+			return 'attachments_no_data_loaded';
1024
+	} else {
1025
+			$attachContext = $attachLoaded[$attachID];
1026
+	}
967 1027
 
968 1028
 	// You may or may not want to show this under the post.
969
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
970
-		$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1030
+			$context['show_attach_under_post'][$attachID] = $attachID;
1031
+	}
971 1032
 
972 1033
 	// Last minute changes?
973 1034
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -987,8 +1048,9 @@  discard block
 block discarded – undo
987 1048
 {
988 1049
 	global $smcFunc, $modSettings;
989 1050
 
990
-	if (empty($attachIDs))
991
-		return array();
1051
+	if (empty($attachIDs)) {
1052
+			return array();
1053
+	}
992 1054
 
993 1055
 	$return = array();
994 1056
 
@@ -1004,11 +1066,12 @@  discard block
 block discarded – undo
1004 1066
 		)
1005 1067
 	);
1006 1068
 
1007
-	if ($smcFunc['db_num_rows']($request) != 1)
1008
-		return array();
1069
+	if ($smcFunc['db_num_rows']($request) != 1) {
1070
+			return array();
1071
+	}
1009 1072
 
1010
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1011
-		$return[$row['id_attach']] = array(
1073
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1074
+			$return[$row['id_attach']] = array(
1012 1075
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1013 1076
 			'size' => $row['size'],
1014 1077
 			'attachID' => $row['id_attach'],
@@ -1017,6 +1080,7 @@  discard block
 block discarded – undo
1017 1080
 			'mime_type' => $row['mime_type'],
1018 1081
 			'thumb' => $row['id_thumb'],
1019 1082
 		);
1083
+	}
1020 1084
 	$smcFunc['db_free_result']($request);
1021 1085
 
1022 1086
 	return $return;
@@ -1033,8 +1097,9 @@  discard block
 block discarded – undo
1033 1097
 {
1034 1098
 	global $smcFunc;
1035 1099
 
1036
-	if (empty($attachID))
1037
-		return array();
1100
+	if (empty($attachID)) {
1101
+			return array();
1102
+	}
1038 1103
 
1039 1104
 	$request = $smcFunc['db_query']('', '
1040 1105
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1047,8 +1112,9 @@  discard block
 block discarded – undo
1047 1112
 		)
1048 1113
 	);
1049 1114
 
1050
-	if ($smcFunc['db_num_rows']($request) != 1)
1051
-		return array();
1115
+	if ($smcFunc['db_num_rows']($request) != 1) {
1116
+			return array();
1117
+	}
1052 1118
 
1053 1119
 	$row = $smcFunc['db_fetch_assoc']($request);
1054 1120
 	$smcFunc['db_free_result']($request);
@@ -1089,8 +1155,9 @@  discard block
 block discarded – undo
1089 1155
 		$temp = array();
1090 1156
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1091 1157
 		{
1092
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1093
-				continue;
1158
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1159
+							continue;
1160
+			}
1094 1161
 
1095 1162
 			$temp[$row['id_attach']] = $row;
1096 1163
 		}
@@ -1119,8 +1186,9 @@  discard block
 block discarded – undo
1119 1186
 {
1120 1187
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1121 1188
 
1122
-	if (empty($attachments) || empty($attachments[$id_msg]))
1123
-		return array();
1189
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1190
+			return array();
1191
+	}
1124 1192
 
1125 1193
 	// Set up the attachment info - based on code by Meriadoc.
1126 1194
 	$attachmentData = array();
@@ -1144,11 +1212,13 @@  discard block
 block discarded – undo
1144 1212
 			);
1145 1213
 
1146 1214
 			// If something is unapproved we'll note it so we can sort them.
1147
-			if (!$attachment['approved'])
1148
-				$have_unapproved = true;
1215
+			if (!$attachment['approved']) {
1216
+							$have_unapproved = true;
1217
+			}
1149 1218
 
1150
-			if (!$attachmentData[$i]['is_image'])
1151
-				continue;
1219
+			if (!$attachmentData[$i]['is_image']) {
1220
+							continue;
1221
+			}
1152 1222
 
1153 1223
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1154 1224
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1169,12 +1239,12 @@  discard block
 block discarded – undo
1169 1239
 						// So what folder are we putting this image in?
1170 1240
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1171 1241
 						{
1172
-							if (!is_array($modSettings['attachmentUploadDir']))
1173
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1243
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1244
+							}
1174 1245
 							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
1175 1246
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1176
-						}
1177
-						else
1247
+						} else
1178 1248
 						{
1179 1249
 							$path = $modSettings['attachmentUploadDir'];
1180 1250
 							$id_folder_thumb = 1;
@@ -1189,10 +1259,11 @@  discard block
 block discarded – undo
1189 1259
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1190 1260
 
1191 1261
 						// Figure out the mime type.
1192
-						if (!empty($size['mime']))
1193
-							$thumb_mime = $size['mime'];
1194
-						else
1195
-							$thumb_mime = 'image/' . $thumb_ext;
1262
+						if (!empty($size['mime'])) {
1263
+													$thumb_mime = $size['mime'];
1264
+						} else {
1265
+													$thumb_mime = 'image/' . $thumb_ext;
1266
+						}
1196 1267
 
1197 1268
 						$thumb_filename = $attachment['filename'] . '_thumb';
1198 1269
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1239,11 +1310,12 @@  discard block
 block discarded – undo
1239 1310
 				}
1240 1311
 			}
1241 1312
 
1242
-			if (!empty($attachment['id_thumb']))
1243
-				$attachmentData[$i]['thumbnail'] = array(
1313
+			if (!empty($attachment['id_thumb'])) {
1314
+							$attachmentData[$i]['thumbnail'] = array(
1244 1315
 					'id' => $attachment['id_thumb'],
1245 1316
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1246 1317
 				);
1318
+			}
1247 1319
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1248 1320
 
1249 1321
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1253,30 +1325,31 @@  discard block
 block discarded – undo
1253 1325
 				{
1254 1326
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1255 1327
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1256
-				}
1257
-				elseif (!empty($modSettings['max_image_width']))
1328
+				} elseif (!empty($modSettings['max_image_width']))
1258 1329
 				{
1259 1330
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1260 1331
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1261 1332
 				}
1262
-			}
1263
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1333
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1264 1334
 			{
1265 1335
 				// If the image is too large to show inline, make it a popup.
1266
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1267
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1268
-				else
1269
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1336
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1337
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1338
+				} else {
1339
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1340
+				}
1270 1341
 			}
1271 1342
 
1272
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1273
-				$attachmentData[$i]['downloads']++;
1343
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1344
+							$attachmentData[$i]['downloads']++;
1345
+			}
1274 1346
 		}
1275 1347
 	}
1276 1348
 
1277 1349
 	// Do we need to instigate a sort?
1278
-	if ($have_unapproved)
1279
-		usort($attachmentData, 'approved_attach_sort');
1350
+	if ($have_unapproved) {
1351
+			usort($attachmentData, 'approved_attach_sort');
1352
+	}
1280 1353
 
1281 1354
 	return $attachmentData;
1282 1355
 }
Please login to merge, or discard this patch.
Sources/News.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -497,6 +497,7 @@
 block discarded – undo
497 497
  * @param string $xml_format The format to use ('atom', 'rss', 'rss2' or empty for plain XML)
498 498
  * @param array $forceCdataKeys A list of keys on which to force cdata wrapping (used by mods, maybe)
499 499
  * @param array $nsKeys Key-value pairs of namespace prefixes to pass to cdata_parse() (used by mods, maybe)
500
+ * @param string $tag
500 501
  */
501 502
 function dumpTags($data, $i, $tag = null, $xml_format = '', $forceCdataKeys = array(), $nsKeys = array())
502 503
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 			{
838 838
 				uasort($loaded_attachments, function($a, $b) {
839 839
 					if ($a['filesize'] == $b['filesize'])
840
-					        return 0;
840
+							return 0;
841 841
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
842 842
 				});
843 843
 			}
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 			{
1243 1243
 				uasort($loaded_attachments, function($a, $b) {
1244 1244
 					if ($a['filesize'] == $b['filesize'])
1245
-					        return 0;
1245
+							return 0;
1246 1246
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1247 1247
 				});
1248 1248
 			}
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.
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.