Completed
Push — release-2.1 ( 15f485...ae1be0 )
by Mathias
08:27
created
Sources/Class-Package.php 1 patch
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * of elements, an array of xmlArray's is returned for use with foreach.
258 258
 	 * Example use:
259 259
 	 *  foreach ($xml->set('html/body/p') as $p)
260
-	 * @param $path string The path to search for.
260
+	 * @param string $path string The path to search for.
261 261
 	 * @return xmlArray[] An array of xmlArray objects
262 262
 	 */
263 263
 	public function set($path)
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 	 * Changes a files atrributes (chmod)
856 856
 	 *
857 857
 	 * @param string $ftp_file The file to CHMOD
858
-	 * @param int|string $chmod The value for the CHMOD operation
858
+	 * @param integer $chmod The value for the CHMOD operation
859 859
 	 * @return boolean Whether or not the operation was successful
860 860
 	 */
861 861
 	public function chmod($ftp_file, $chmod)
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 	 *
1026 1026
 	 * @param string $ftp_path The path to the directory
1027 1027
 	 * @param bool $search Whether or not to get a recursive directory listing
1028
-	 * @return string|boolean The results of the command or false if unsuccessful
1028
+	 * @return false|string The results of the command or false if unsuccessful
1029 1029
 	 */
1030 1030
 	public function list_dir($ftp_path = '', $search = false)
1031 1031
 	{
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 	 *
1071 1071
 	 * @param string $file The name of a file
1072 1072
 	 * @param string $listing A directory listing or null to generate one
1073
-	 * @return string|boolean The name of the file or false if it wasn't found
1073
+	 * @return string|false The name of the file or false if it wasn't found
1074 1074
 	 */
1075 1075
 	public function locate($file, $listing = null)
1076 1076
 	{
Please login to merge, or discard this patch.
Sources/Drafts.php 1 patch
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
  *
174 174
  * @param string $post_errors A string of info about errors encountered trying to save this draft
175 175
  * @param array $recipientList An array of data about who this PM is being sent to
176
- * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise
176
+ * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise
177 177
  */
178 178
 function SavePMDraft(&$post_errors, $recipientList)
179 179
 {
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
  *
389 389
  * @param int $id_draft The ID of the draft to delete
390 390
  * @param boolean $check Whether or not to check that the draft belongs to the current user
391
- * @return boolean False if it couldn't be deleted (doesn't return anything otherwise)
391
+ * @return false|null False if it couldn't be deleted (doesn't return anything otherwise)
392 392
  */
393 393
 function DeleteDraft($id_draft, $check = true)
394 394
 {
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
  * @param int $member_id ID of the member to show drafts for
423 423
  * @param boolean|integer If $type is 1, this can be set to only load drafts for posts in the specific topic
424 424
  * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts
425
- * @return boolean False if the drafts couldn't be loaded, nothing otherwise
425
+ * @return false|null False if the drafts couldn't be loaded, nothing otherwise
426 426
  */
427 427
 function ShowDrafts($member_id, $topic = false, $draft_type = 0)
428 428
 {
Please login to merge, or discard this patch.
Sources/Logging.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 /**
20 20
  * Truncate the GET array to a specified length
21 21
  * @param array $arr The array to truncate
22
- * @param max_length $max_length The upperbound on the length
22
+ * @param integer $max_length The upperbound on the length
23 23
  *
24 24
  * @return array The truncated array
25 25
  */
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return array The truncated array
25 25
  */
26
-function truncateArray($arr, $max_length=1900)
26
+function truncateArray($arr, $max_length = 1900)
27 27
 {
28 28
 	$curr_length = array_sum(array_map("strlen", $arr));
29 29
 	if ($curr_length <= $max_length)
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	else
32 32
 	{
33 33
 		// Truncate each element's value to a reasonable length
34
-		$param_max = floor($max_length/count($arr));
34
+		$param_max = floor($max_length / count($arr));
35 35
 		foreach ($arr as $key => &$value)
36 36
 			$value = substr($value, 0, $param_max - strlen($key) - 5);
37 37
 		return $arr;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	if (filemtime($boarddir . '/db_last_error.php') === $last_db_error_change)
198 198
 	{
199 199
 		// Write the change
200
-		$write_db_change =  '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>';
200
+		$write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>';
201 201
 		$written_bytes = file_put_contents($boarddir . '/db_last_error.php', $write_db_change, LOCK_EX);
202 202
 
203 203
 		// survey says ...
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br>
271 271
 	', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br>
272 272
 	', $txt['debug_hooks'], empty($context['debug']['hooks']) ? 0 : count($context['debug']['hooks']) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_hooks\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_hooks" style="display: none;"><em>' . implode('</em>, <em>', $context['debug']['hooks']), '</em></span>)', '<br>
273
-	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
273
+	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">' . $txt['debug_show'] . '</a><span id="debug_instances" style="display: none;"><em>' . implode('</em>, <em>', array_keys($context['debug']['instances'])) . '</em></span>)' . '<br>') : ''), '
274 274
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
275 275
 
276 276
 	if (function_exists('memory_get_peak_usage'))
Please login to merge, or discard this patch.
Braces   +140 added lines, -101 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
  * Truncate the GET array to a specified length
@@ -26,14 +27,15 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = array_sum(array_map("strlen", $arr));
29
-	if ($curr_length <= $max_length)
30
-		return $arr;
31
-	else
30
+	if ($curr_length <= $max_length) {
31
+			return $arr;
32
+	} else
32 33
 	{
33 34
 		// Truncate each element's value to a reasonable length
34 35
 		$param_max = floor($max_length/count($arr));
35
-		foreach ($arr as $key => &$value)
36
-			$value = substr($value, 0, $param_max - strlen($key) - 5);
36
+		foreach ($arr as $key => &$value) {
37
+					$value = substr($value, 0, $param_max - strlen($key) - 5);
38
+		}
37 39
 		return $arr;
38 40
 	}
39 41
 }
@@ -55,8 +57,9 @@  discard block
 block discarded – undo
55 57
 		// Don't update for every page - this isn't wholly accurate but who cares.
56 58
 		if ($topic)
57 59
 		{
58
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
59
-				$force = false;
60
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
61
+							$force = false;
62
+			}
60 63
 			$_SESSION['last_topic_id'] = $topic;
61 64
 		}
62 65
 	}
@@ -69,22 +72,24 @@  discard block
 block discarded – undo
69 72
 	}
70 73
 
71 74
 	// Don't mark them as online more than every so often.
72
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
73
-		return;
75
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
76
+			return;
77
+	}
74 78
 
75 79
 	if (!empty($modSettings['who_enabled']))
76 80
 	{
77 81
 		$serialized = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
78 82
 
79 83
 		// In the case of a dlattach action, session_var may not be set.
80
-		if (!isset($context['session_var']))
81
-			$context['session_var'] = $_SESSION['session_var'];
84
+		if (!isset($context['session_var'])) {
85
+					$context['session_var'] = $_SESSION['session_var'];
86
+		}
82 87
 
83 88
 		unset($serialized['sesc'], $serialized[$context['session_var']]);
84 89
 		$serialized = json_encode($serialized);
90
+	} else {
91
+			$serialized = '';
85 92
 	}
86
-	else
87
-		$serialized = '';
88 93
 
89 94
 	// Guests use 0, members use their session ID.
90 95
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -124,17 +129,18 @@  discard block
 block discarded – undo
124 129
 		);
125 130
 
126 131
 		// Guess it got deleted.
127
-		if ($smcFunc['db_affected_rows']() == 0)
132
+		if ($smcFunc['db_affected_rows']() == 0) {
133
+					$_SESSION['log_time'] = 0;
134
+		}
135
+	} else {
128 136
 			$_SESSION['log_time'] = 0;
129 137
 	}
130
-	else
131
-		$_SESSION['log_time'] = 0;
132 138
 
133 139
 	// Otherwise, we have to delete and insert.
134 140
 	if (empty($_SESSION['log_time']))
135 141
 	{
136
-		if ($do_delete || !empty($user_info['id']))
137
-			$smcFunc['db_query']('', '
142
+		if ($do_delete || !empty($user_info['id'])) {
143
+					$smcFunc['db_query']('', '
138 144
 				DELETE FROM {db_prefix}log_online
139 145
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
140 146
 				array(
@@ -142,6 +148,7 @@  discard block
 block discarded – undo
142 148
 					'log_time' => time() - $modSettings['lastActive'] * 60,
143 149
 				)
144 150
 			);
151
+		}
145 152
 
146 153
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
147 154
 			'{db_prefix}log_online',
@@ -155,21 +162,24 @@  discard block
 block discarded – undo
155 162
 	$_SESSION['log_time'] = time();
156 163
 
157 164
 	// Well, they are online now.
158
-	if (empty($_SESSION['timeOnlineUpdated']))
159
-		$_SESSION['timeOnlineUpdated'] = time();
165
+	if (empty($_SESSION['timeOnlineUpdated'])) {
166
+			$_SESSION['timeOnlineUpdated'] = time();
167
+	}
160 168
 
161 169
 	// Set their login time, if not already done within the last minute.
162 170
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
163 171
 	{
164 172
 		// Don't count longer than 15 minutes.
165
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
166
-			$_SESSION['timeOnlineUpdated'] = time();
173
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
174
+					$_SESSION['timeOnlineUpdated'] = time();
175
+		}
167 176
 
168 177
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
169 178
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
170 179
 
171
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
172
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
180
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
181
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
182
+		}
173 183
 
174 184
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
175 185
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -206,8 +216,7 @@  discard block
 block discarded – undo
206 216
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
207 217
 			// Copy the file back and run for your life!
208 218
 			@copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php');
209
-		}
210
-		else
219
+		} else
211 220
 		{
212 221
 			@touch($boarddir . '/' . 'Settings.php');
213 222
 			return true;
@@ -227,22 +236,27 @@  discard block
 block discarded – undo
227 236
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
228 237
 
229 238
 	// Add to Settings.php if you want to show the debugging information.
230
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
231
-		return;
239
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
240
+			return;
241
+	}
232 242
 
233
-	if (empty($_SESSION['view_queries']))
234
-		$_SESSION['view_queries'] = 0;
235
-	if (empty($context['debug']['language_files']))
236
-		$context['debug']['language_files'] = array();
237
-	if (empty($context['debug']['sheets']))
238
-		$context['debug']['sheets'] = array();
243
+	if (empty($_SESSION['view_queries'])) {
244
+			$_SESSION['view_queries'] = 0;
245
+	}
246
+	if (empty($context['debug']['language_files'])) {
247
+			$context['debug']['language_files'] = array();
248
+	}
249
+	if (empty($context['debug']['sheets'])) {
250
+			$context['debug']['sheets'] = array();
251
+	}
239 252
 
240 253
 	$files = get_included_files();
241 254
 	$total_size = 0;
242 255
 	for ($i = 0, $n = count($files); $i < $n; $i++)
243 256
 	{
244
-		if (file_exists($files[$i]))
245
-			$total_size += filesize($files[$i]);
257
+		if (file_exists($files[$i])) {
258
+					$total_size += filesize($files[$i]);
259
+		}
246 260
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
247 261
 	}
248 262
 
@@ -251,8 +265,9 @@  discard block
 block discarded – undo
251 265
 	{
252 266
 		foreach ($db_cache as $q => $qq)
253 267
 		{
254
-			if (!empty($qq['w']))
255
-				$warnings += count($qq['w']);
268
+			if (!empty($qq['w'])) {
269
+							$warnings += count($qq['w']);
270
+			}
256 271
 		}
257 272
 
258 273
 		$_SESSION['debug'] = &$db_cache;
@@ -273,12 +288,14 @@  discard block
 block discarded – undo
273 288
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
274 289
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
275 290
 
276
-	if (function_exists('memory_get_peak_usage'))
277
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
291
+	if (function_exists('memory_get_peak_usage')) {
292
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
293
+	}
278 294
 
279 295
 	// What tokens are active?
280
-	if (isset($_SESSION['token']))
281
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
296
+	if (isset($_SESSION['token'])) {
297
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
298
+	}
282 299
 
283 300
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
284 301
 	{
@@ -292,10 +309,12 @@  discard block
 block discarded – undo
292 309
 			$total_t += $cache_hit['t'];
293 310
 			$total_s += $cache_hit['s'];
294 311
 		}
295
-		if (!isset($cache_misses))
296
-			$cache_misses = array();
297
-		foreach ($cache_misses as $missed)
298
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
312
+		if (!isset($cache_misses)) {
313
+					$cache_misses = array();
314
+		}
315
+		foreach ($cache_misses as $missed) {
316
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
317
+		}
299 318
 
300 319
 		echo '
301 320
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -306,38 +325,44 @@  discard block
 block discarded – undo
306 325
 	<a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
307 326
 	<br>';
308 327
 
309
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
310
-		foreach ($db_cache as $q => $qq)
328
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
329
+			foreach ($db_cache as $q => $qq)
311 330
 		{
312 331
 			$is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0;
332
+	}
313 333
 			// Temporary tables created in earlier queries are not explainable.
314 334
 			if ($is_select)
315 335
 			{
316
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
317
-					if (strpos(trim($qq['q']), $tmp) !== false)
336
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
337
+									if (strpos(trim($qq['q']), $tmp) !== false)
318 338
 					{
319 339
 						$is_select = false;
340
+				}
320 341
 						break;
321 342
 					}
322 343
 			}
323 344
 			// But actual creation of the temporary tables are.
324
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0)
325
-				$is_select = true;
345
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) {
346
+							$is_select = true;
347
+			}
326 348
 
327 349
 			// Make the filenames look a bit better.
328
-			if (isset($qq['f']))
329
-				$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
350
+			if (isset($qq['f'])) {
351
+							$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
352
+			}
330 353
 
331 354
 			echo '
332 355
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
333 356
 	&nbsp;&nbsp;&nbsp;';
334
-			if (!empty($qq['f']) && !empty($qq['l']))
335
-				echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
357
+			if (!empty($qq['f']) && !empty($qq['l'])) {
358
+							echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
359
+			}
336 360
 
337
-			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at']))
338
-				echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
339
-			elseif (isset($qq['t']))
340
-				echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
361
+			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) {
362
+							echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
363
+			} elseif (isset($qq['t'])) {
364
+							echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
365
+			}
341 366
 			echo '
342 367
 	<br>';
343 368
 		}
@@ -362,12 +387,14 @@  discard block
 block discarded – undo
362 387
 	global $modSettings, $smcFunc;
363 388
 	static $cache_stats = array();
364 389
 
365
-	if (empty($modSettings['trackStats']))
366
-		return false;
367
-	if (!empty($stats))
368
-		return $cache_stats = array_merge($cache_stats, $stats);
369
-	elseif (empty($cache_stats))
370
-		return false;
390
+	if (empty($modSettings['trackStats'])) {
391
+			return false;
392
+	}
393
+	if (!empty($stats)) {
394
+			return $cache_stats = array_merge($cache_stats, $stats);
395
+	} elseif (empty($cache_stats)) {
396
+			return false;
397
+	}
371 398
 
372 399
 	$setStringUpdate = '';
373 400
 	$insert_keys = array();
@@ -380,10 +407,11 @@  discard block
 block discarded – undo
380 407
 		$setStringUpdate .= '
381 408
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
382 409
 
383
-		if ($change === '+')
384
-			$cache_stats[$field] = 1;
385
-		else
386
-			$update_parameters[$field] = $change;
410
+		if ($change === '+') {
411
+					$cache_stats[$field] = 1;
412
+		} else {
413
+					$update_parameters[$field] = $change;
414
+		}
387 415
 		$insert_keys[$field] = 'int';
388 416
 	}
389 417
 
@@ -447,43 +475,50 @@  discard block
 block discarded – undo
447 475
 	);
448 476
 
449 477
 	// Make sure this particular log is enabled first...
450
-	if (empty($modSettings['modlog_enabled']))
451
-		unset ($log_types['moderate']);
452
-	if (empty($modSettings['userlog_enabled']))
453
-		unset ($log_types['user']);
454
-	if (empty($modSettings['adminlog_enabled']))
455
-		unset ($log_types['admin']);
478
+	if (empty($modSettings['modlog_enabled'])) {
479
+			unset ($log_types['moderate']);
480
+	}
481
+	if (empty($modSettings['userlog_enabled'])) {
482
+			unset ($log_types['user']);
483
+	}
484
+	if (empty($modSettings['adminlog_enabled'])) {
485
+			unset ($log_types['admin']);
486
+	}
456 487
 
457 488
 	call_integration_hook('integrate_log_types', array(&$log_types));
458 489
 
459 490
 	foreach ($logs as $log)
460 491
 	{
461
-		if (!isset($log_types[$log['log_type']]))
462
-			return false;
492
+		if (!isset($log_types[$log['log_type']])) {
493
+					return false;
494
+		}
463 495
 
464
-		if (!is_array($log['extra']))
465
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
496
+		if (!is_array($log['extra'])) {
497
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
498
+		}
466 499
 
467 500
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
468 501
 		if (isset($log['extra']['topic']))
469 502
 		{
470
-			if (!is_numeric($log['extra']['topic']))
471
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
503
+			if (!is_numeric($log['extra']['topic'])) {
504
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
505
+			}
472 506
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
473 507
 			unset($log['extra']['topic']);
508
+		} else {
509
+					$topic_id = 0;
474 510
 		}
475
-		else
476
-			$topic_id = 0;
477 511
 
478 512
 		if (isset($log['extra']['message']))
479 513
 		{
480
-			if (!is_numeric($log['extra']['message']))
481
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
514
+			if (!is_numeric($log['extra']['message'])) {
515
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
516
+			}
482 517
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
483 518
 			unset($log['extra']['message']);
519
+		} else {
520
+					$msg_id = 0;
484 521
 		}
485
-		else
486
-			$msg_id = 0;
487 522
 
488 523
 		// @todo cache this?
489 524
 		// Is there an associated report on this?
@@ -510,23 +545,26 @@  discard block
 block discarded – undo
510 545
 			$smcFunc['db_free_result']($request);
511 546
 		}
512 547
 
513
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
514
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
548
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
549
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
550
+		}
515 551
 
516 552
 		if (isset($log['extra']['board']))
517 553
 		{
518
-			if (!is_numeric($log['extra']['board']))
519
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
554
+			if (!is_numeric($log['extra']['board'])) {
555
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
556
+			}
520 557
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
521 558
 			unset($log['extra']['board']);
559
+		} else {
560
+					$board_id = 0;
522 561
 		}
523
-		else
524
-			$board_id = 0;
525 562
 
526 563
 		if (isset($log['extra']['board_to']))
527 564
 		{
528
-			if (!is_numeric($log['extra']['board_to']))
529
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
565
+			if (!is_numeric($log['extra']['board_to'])) {
566
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
567
+			}
530 568
 			if (empty($board_id))
531 569
 			{
532 570
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -534,10 +572,11 @@  discard block
 block discarded – undo
534 572
 			}
535 573
 		}
536 574
 
537
-		if (isset($log['extra']['member_affected']))
538
-			$memID = $log['extra']['member_affected'];
539
-		else
540
-			$memID = $user_info['id'];
575
+		if (isset($log['extra']['member_affected'])) {
576
+					$memID = $log['extra']['member_affected'];
577
+		} else {
578
+					$memID = $user_info['id'];
579
+		}
541 580
 
542 581
 		$inserts[] = array(
543 582
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.
Sources/Subs.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  * - caches the formatting data from the setting for optimization.
677 677
  *
678 678
  * @param float $number A number
679
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
679
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
680 680
  * @return string A formatted number
681 681
  */
682 682
 function comma_format($number, $override_decimal_count = false)
@@ -5527,7 +5527,7 @@  discard block
 block discarded – undo
5527 5527
  * It assumes the data is already a string.
5528 5528
  * @param string $data The data to print
5529 5529
  * @param string $type The content type. Defaults to Json.
5530
- * @return void
5530
+ * @return false|null
5531 5531
  */
5532 5532
 function smf_serverResponse($data = '', $type = 'Content-Type: application/json')
5533 5533
 {
Please login to merge, or discard this patch.
Braces   +1287 added lines, -957 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
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
760
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1281,10 +1345,11 @@  discard block
 block discarded – undo
1281 1345
 				{
1282 1346
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1347
 
1284
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1285
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1286
-					else
1287
-						$css = '';
1348
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1349
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1350
+					} else {
1351
+											$css = '';
1352
+					}
1288 1353
 
1289 1354
 					$data = $class . $css;
1290 1355
 				},
@@ -1334,14 +1399,16 @@  discard block
 block discarded – undo
1334 1399
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1335 1400
 					if ($image_proxy_enabled)
1336 1401
 					{
1337
-						if (empty($scheme))
1338
-							$data = 'http://' . ltrim($data, ':/');
1402
+						if (empty($scheme)) {
1403
+													$data = 'http://' . ltrim($data, ':/');
1404
+						}
1339 1405
 
1340
-						if ($scheme != 'https')
1341
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1406
+						if ($scheme != 'https') {
1407
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1408
+						}
1409
+					} elseif (empty($scheme)) {
1410
+											$data = '//' . ltrim($data, ':/');
1342 1411
 					}
1343
-					elseif (empty($scheme))
1344
-						$data = '//' . ltrim($data, ':/');
1345 1412
 				},
1346 1413
 				'disabled_content' => '($1)',
1347 1414
 			),
@@ -1357,14 +1424,16 @@  discard block
 block discarded – undo
1357 1424
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1358 1425
 					if ($image_proxy_enabled)
1359 1426
 					{
1360
-						if (empty($scheme))
1361
-							$data = 'http://' . ltrim($data, ':/');
1427
+						if (empty($scheme)) {
1428
+													$data = 'http://' . ltrim($data, ':/');
1429
+						}
1362 1430
 
1363
-						if ($scheme != 'https')
1364
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1431
+						if ($scheme != 'https') {
1432
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1433
+						}
1434
+					} elseif (empty($scheme)) {
1435
+											$data = '//' . ltrim($data, ':/');
1365 1436
 					}
1366
-					elseif (empty($scheme))
1367
-						$data = '//' . ltrim($data, ':/');
1368 1437
 				},
1369 1438
 				'disabled_content' => '($1)',
1370 1439
 			),
@@ -1376,8 +1445,9 @@  discard block
 block discarded – undo
1376 1445
 				{
1377 1446
 					$data = strtr($data, array('<br>' => ''));
1378 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1379
-					if (empty($scheme))
1380
-						$data = '//' . ltrim($data, ':/');
1448
+					if (empty($scheme)) {
1449
+											$data = '//' . ltrim($data, ':/');
1450
+					}
1381 1451
 				},
1382 1452
 			),
1383 1453
 			array(
@@ -1388,13 +1458,14 @@  discard block
 block discarded – undo
1388 1458
 				'after' => '</a>',
1389 1459
 				'validate' => function (&$tag, &$data, $disabled)
1390 1460
 				{
1391
-					if (substr($data, 0, 1) == '#')
1392
-						$data = '#post_' . substr($data, 1);
1393
-					else
1461
+					if (substr($data, 0, 1) == '#') {
1462
+											$data = '#post_' . substr($data, 1);
1463
+					} else
1394 1464
 					{
1395 1465
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1396
-						if (empty($scheme))
1397
-							$data = '//' . ltrim($data, ':/');
1466
+						if (empty($scheme)) {
1467
+													$data = '//' . ltrim($data, ':/');
1468
+						}
1398 1469
 					}
1399 1470
 				},
1400 1471
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1472,8 +1543,9 @@  discard block
 block discarded – undo
1472 1543
 					{
1473 1544
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1474 1545
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1475
-						if ($add_begin)
1476
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1546
+						if ($add_begin) {
1547
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1548
+						}
1477 1549
 					}
1478 1550
 				},
1479 1551
 				'block_level' => false,
@@ -1604,10 +1676,11 @@  discard block
 block discarded – undo
1604 1676
 				'content' => '$1',
1605 1677
 				'validate' => function (&$tag, &$data, $disabled)
1606 1678
 				{
1607
-					if (is_numeric($data))
1608
-						$data = timeformat($data);
1609
-					else
1610
-						$tag['content'] = '[time]$1[/time]';
1679
+					if (is_numeric($data)) {
1680
+											$data = timeformat($data);
1681
+					} else {
1682
+											$tag['content'] = '[time]$1[/time]';
1683
+					}
1611 1684
 				},
1612 1685
 			),
1613 1686
 			array(
@@ -1634,8 +1707,9 @@  discard block
 block discarded – undo
1634 1707
 				{
1635 1708
 					$data = strtr($data, array('<br>' => ''));
1636 1709
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1637
-					if (empty($scheme))
1638
-						$data = '//' . ltrim($data, ':/');
1710
+					if (empty($scheme)) {
1711
+											$data = '//' . ltrim($data, ':/');
1712
+					}
1639 1713
 				},
1640 1714
 			),
1641 1715
 			array(
@@ -1647,8 +1721,9 @@  discard block
 block discarded – undo
1647 1721
 				'validate' => function (&$tag, &$data, $disabled)
1648 1722
 				{
1649 1723
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650
-					if (empty($scheme))
1651
-						$data = '//' . ltrim($data, ':/');
1724
+					if (empty($scheme)) {
1725
+											$data = '//' . ltrim($data, ':/');
1726
+					}
1652 1727
 				},
1653 1728
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1654 1729
 				'disabled_after' => ' ($1)',
@@ -1668,8 +1743,9 @@  discard block
 block discarded – undo
1668 1743
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1669 1744
 		if ($message === false)
1670 1745
 		{
1671
-			if (isset($temp_bbc))
1672
-				$bbc_codes = $temp_bbc;
1746
+			if (isset($temp_bbc)) {
1747
+							$bbc_codes = $temp_bbc;
1748
+			}
1673 1749
 			usort($codes, function ($a, $b) {
1674 1750
 				return strcmp($a['tag'], $b['tag']);
1675 1751
 			});
@@ -1689,8 +1765,9 @@  discard block
 block discarded – undo
1689 1765
 		);
1690 1766
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1691 1767
 		{
1692
-			foreach ($itemcodes as $c => $dummy)
1693
-				$bbc_codes[$c] = array();
1768
+			foreach ($itemcodes as $c => $dummy) {
1769
+							$bbc_codes[$c] = array();
1770
+			}
1694 1771
 		}
1695 1772
 
1696 1773
 		// Shhhh!
@@ -1711,12 +1788,14 @@  discard block
 block discarded – undo
1711 1788
 		foreach ($codes as $code)
1712 1789
 		{
1713 1790
 			// Make it easier to process parameters later
1714
-			if (!empty($code['parameters']))
1715
-				ksort($code['parameters'], SORT_STRING);
1791
+			if (!empty($code['parameters'])) {
1792
+							ksort($code['parameters'], SORT_STRING);
1793
+			}
1716 1794
 
1717 1795
 			// If we are not doing every tag only do ones we are interested in.
1718
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1719
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1796
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1797
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1798
+			}
1720 1799
 		}
1721 1800
 		$codes = null;
1722 1801
 	}
@@ -1727,8 +1806,9 @@  discard block
 block discarded – undo
1727 1806
 		// It's likely this will change if the message is modified.
1728 1807
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1729 1808
 
1730
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1731
-			return $temp;
1809
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1810
+					return $temp;
1811
+		}
1732 1812
 
1733 1813
 		$cache_t = microtime();
1734 1814
 	}
@@ -1760,8 +1840,9 @@  discard block
 block discarded – undo
1760 1840
 		$disabled['flash'] = true;
1761 1841
 
1762 1842
 		// @todo Change maybe?
1763
-		if (!isset($_GET['images']))
1764
-			$disabled['img'] = true;
1843
+		if (!isset($_GET['images'])) {
1844
+					$disabled['img'] = true;
1845
+		}
1765 1846
 
1766 1847
 		// @todo Interface/setting to add more?
1767 1848
 	}
@@ -1785,8 +1866,9 @@  discard block
 block discarded – undo
1785 1866
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1786 1867
 
1787 1868
 		// Failsafe.
1788
-		if ($pos === false || $last_pos > $pos)
1789
-			$pos = strlen($message) + 1;
1869
+		if ($pos === false || $last_pos > $pos) {
1870
+					$pos = strlen($message) + 1;
1871
+		}
1790 1872
 
1791 1873
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1792 1874
 		if ($last_pos < $pos - 1)
@@ -1805,8 +1887,9 @@  discard block
 block discarded – undo
1805 1887
 
1806 1888
 				// <br> should be empty.
1807 1889
 				$empty_tags = array('br', 'hr');
1808
-				foreach ($empty_tags as $tag)
1809
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1890
+				foreach ($empty_tags as $tag) {
1891
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1892
+				}
1810 1893
 
1811 1894
 				// b, u, i, s, pre... basic tags.
1812 1895
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1815,8 +1898,9 @@  discard block
 block discarded – undo
1815 1898
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1816 1899
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1817 1900
 
1818
-					if ($diff > 0)
1819
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1901
+					if ($diff > 0) {
1902
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1903
+					}
1820 1904
 				}
1821 1905
 
1822 1906
 				// Do <img ...> - with security... action= -> action-.
@@ -1829,8 +1913,9 @@  discard block
 block discarded – undo
1829 1913
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1830 1914
 
1831 1915
 						// Remove action= from the URL - no funny business, now.
1832
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1833
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1916
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1917
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1918
+						}
1834 1919
 
1835 1920
 						// Check if the image is larger than allowed.
1836 1921
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1851,9 +1936,9 @@  discard block
 block discarded – undo
1851 1936
 
1852 1937
 							// Set the new image tag.
1853 1938
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1939
+						} else {
1940
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1854 1941
 						}
1855
-						else
1856
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1857 1942
 					}
1858 1943
 
1859 1944
 					$data = strtr($data, $replaces);
@@ -1866,16 +1951,18 @@  discard block
 block discarded – undo
1866 1951
 				$no_autolink_area = false;
1867 1952
 				if (!empty($open_tags))
1868 1953
 				{
1869
-					foreach ($open_tags as $open_tag)
1870
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1954
+					foreach ($open_tags as $open_tag) {
1955
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1871 1956
 							$no_autolink_area = true;
1957
+					}
1872 1958
 				}
1873 1959
 
1874 1960
 				// Don't go backwards.
1875 1961
 				// @todo Don't think is the real solution....
1876 1962
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1877
-				if ($pos < $lastAutoPos)
1878
-					$no_autolink_area = true;
1963
+				if ($pos < $lastAutoPos) {
1964
+									$no_autolink_area = true;
1965
+				}
1879 1966
 				$lastAutoPos = $pos;
1880 1967
 
1881 1968
 				if (!$no_autolink_area)
@@ -1984,17 +2071,19 @@  discard block
 block discarded – undo
1984 2071
 							if ($scheme == 'mailto')
1985 2072
 							{
1986 2073
 								$email_address = str_replace('mailto:', '', $url);
1987
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1988
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1989
-								else
1990
-									return $url;
2074
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2075
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2076
+								} else {
2077
+																	return $url;
2078
+								}
1991 2079
 							}
1992 2080
 
1993 2081
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1994
-							if (empty($scheme))
1995
-								$fullUrl = '//' . ltrim($url, ':/');
1996
-							else
1997
-								$fullUrl = $url;
2082
+							if (empty($scheme)) {
2083
+															$fullUrl = '//' . ltrim($url, ':/');
2084
+							} else {
2085
+															$fullUrl = $url;
2086
+							}
1998 2087
 
1999 2088
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2000 2089
 						}, $data);
@@ -2043,16 +2132,18 @@  discard block
 block discarded – undo
2043 2132
 		}
2044 2133
 
2045 2134
 		// Are we there yet?  Are we there yet?
2046
-		if ($pos >= strlen($message) - 1)
2047
-			break;
2135
+		if ($pos >= strlen($message) - 1) {
2136
+					break;
2137
+		}
2048 2138
 
2049 2139
 		$tags = strtolower($message[$pos + 1]);
2050 2140
 
2051 2141
 		if ($tags == '/' && !empty($open_tags))
2052 2142
 		{
2053 2143
 			$pos2 = strpos($message, ']', $pos + 1);
2054
-			if ($pos2 == $pos + 2)
2055
-				continue;
2144
+			if ($pos2 == $pos + 2) {
2145
+							continue;
2146
+			}
2056 2147
 
2057 2148
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2058 2149
 
@@ -2062,8 +2153,9 @@  discard block
 block discarded – undo
2062 2153
 			do
2063 2154
 			{
2064 2155
 				$tag = array_pop($open_tags);
2065
-				if (!$tag)
2066
-					break;
2156
+				if (!$tag) {
2157
+									break;
2158
+				}
2067 2159
 
2068 2160
 				if (!empty($tag['block_level']))
2069 2161
 				{
@@ -2077,10 +2169,11 @@  discard block
 block discarded – undo
2077 2169
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2078 2170
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2079 2171
 					{
2080
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2081
-							if ($temp['tag'] == $look_for)
2172
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2173
+													if ($temp['tag'] == $look_for)
2082 2174
 							{
2083 2175
 								$block_level = !empty($temp['block_level']);
2176
+						}
2084 2177
 								break;
2085 2178
 							}
2086 2179
 					}
@@ -2102,15 +2195,15 @@  discard block
 block discarded – undo
2102 2195
 			{
2103 2196
 				$open_tags = $to_close;
2104 2197
 				continue;
2105
-			}
2106
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2198
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2107 2199
 			{
2108 2200
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2109 2201
 				{
2110
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2111
-						if ($temp['tag'] == $look_for)
2202
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2203
+											if ($temp['tag'] == $look_for)
2112 2204
 						{
2113 2205
 							$block_level = !empty($temp['block_level']);
2206
+					}
2114 2207
 							break;
2115 2208
 						}
2116 2209
 				}
@@ -2118,8 +2211,9 @@  discard block
 block discarded – undo
2118 2211
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2119 2212
 				if (!$block_level)
2120 2213
 				{
2121
-					foreach ($to_close as $tag)
2122
-						array_push($open_tags, $tag);
2214
+					foreach ($to_close as $tag) {
2215
+											array_push($open_tags, $tag);
2216
+					}
2123 2217
 					continue;
2124 2218
 				}
2125 2219
 			}
@@ -2132,14 +2226,17 @@  discard block
 block discarded – undo
2132 2226
 
2133 2227
 				// See the comment at the end of the big loop - just eating whitespace ;).
2134 2228
 				$whitespace_regex = '';
2135
-				if (!empty($tag['block_level']))
2136
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2229
+				if (!empty($tag['block_level'])) {
2230
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2231
+				}
2137 2232
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2138
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2139
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2233
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2234
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2235
+				}
2140 2236
 
2141
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2142
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2237
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2238
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2239
+				}
2143 2240
 			}
2144 2241
 
2145 2242
 			if (!empty($to_close))
@@ -2152,8 +2249,9 @@  discard block
 block discarded – undo
2152 2249
 		}
2153 2250
 
2154 2251
 		// No tags for this character, so just keep going (fastest possible course.)
2155
-		if (!isset($bbc_codes[$tags]))
2156
-			continue;
2252
+		if (!isset($bbc_codes[$tags])) {
2253
+					continue;
2254
+		}
2157 2255
 
2158 2256
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2159 2257
 		$tag = null;
@@ -2162,44 +2260,52 @@  discard block
 block discarded – undo
2162 2260
 			$pt_strlen = strlen($possible['tag']);
2163 2261
 
2164 2262
 			// Not a match?
2165
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2166
-				continue;
2263
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2264
+							continue;
2265
+			}
2167 2266
 
2168 2267
 			$next_c = $message[$pos + 1 + $pt_strlen];
2169 2268
 
2170 2269
 			// A test validation?
2171
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2172
-				continue;
2270
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2271
+							continue;
2272
+			}
2173 2273
 			// Do we want parameters?
2174 2274
 			elseif (!empty($possible['parameters']))
2175 2275
 			{
2176
-				if ($next_c != ' ')
2177
-					continue;
2178
-			}
2179
-			elseif (isset($possible['type']))
2276
+				if ($next_c != ' ') {
2277
+									continue;
2278
+				}
2279
+			} elseif (isset($possible['type']))
2180 2280
 			{
2181 2281
 				// Do we need an equal sign?
2182
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2183
-					continue;
2282
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2283
+									continue;
2284
+				}
2184 2285
 				// Maybe we just want a /...
2185
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2186
-					continue;
2286
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2287
+									continue;
2288
+				}
2187 2289
 				// An immediate ]?
2188
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2189
-					continue;
2290
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2291
+									continue;
2292
+				}
2190 2293
 			}
2191 2294
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2192
-			elseif ($next_c != ']')
2193
-				continue;
2295
+			elseif ($next_c != ']') {
2296
+							continue;
2297
+			}
2194 2298
 
2195 2299
 			// Check allowed tree?
2196
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2197
-				continue;
2198
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2199
-				continue;
2300
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2301
+							continue;
2302
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2303
+							continue;
2304
+			}
2200 2305
 			// If this is in the list of disallowed child tags, don't parse it.
2201
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2202
-				continue;
2306
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2307
+							continue;
2308
+			}
2203 2309
 
2204 2310
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2205 2311
 
@@ -2211,8 +2317,9 @@  discard block
 block discarded – undo
2211 2317
 				foreach ($open_tags as $open_quote)
2212 2318
 				{
2213 2319
 					// Every parent quote this quote has flips the styling
2214
-					if ($open_quote['tag'] == 'quote')
2215
-						$quote_alt = !$quote_alt;
2320
+					if ($open_quote['tag'] == 'quote') {
2321
+											$quote_alt = !$quote_alt;
2322
+					}
2216 2323
 				}
2217 2324
 				// Add a class to the quote to style alternating blockquotes
2218 2325
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2223,8 +2330,9 @@  discard block
 block discarded – undo
2223 2330
 			{
2224 2331
 				// Build a regular expression for each parameter for the current tag.
2225 2332
 				$preg = array();
2226
-				foreach ($possible['parameters'] as $p => $info)
2227
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2333
+				foreach ($possible['parameters'] as $p => $info) {
2334
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2335
+				}
2228 2336
 
2229 2337
 				// Extract the string that potentially holds our parameters.
2230 2338
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2244,24 +2352,27 @@  discard block
 block discarded – undo
2244 2352
 
2245 2353
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2246 2354
 
2247
-					if ($match)
2248
-						$blob_counter = count($blobs) + 1;
2355
+					if ($match) {
2356
+											$blob_counter = count($blobs) + 1;
2357
+					}
2249 2358
 				}
2250 2359
 
2251 2360
 				// Didn't match our parameter list, try the next possible.
2252
-				if (!$match)
2253
-					continue;
2361
+				if (!$match) {
2362
+									continue;
2363
+				}
2254 2364
 
2255 2365
 				$params = array();
2256 2366
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2257 2367
 				{
2258 2368
 					$key = strtok(ltrim($matches[$i]), '=');
2259
-					if (isset($possible['parameters'][$key]['value']))
2260
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2261
-					elseif (isset($possible['parameters'][$key]['validate']))
2262
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2263
-					else
2264
-						$params['{' . $key . '}'] = $matches[$i + 1];
2369
+					if (isset($possible['parameters'][$key]['value'])) {
2370
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2371
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2372
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2373
+					} else {
2374
+											$params['{' . $key . '}'] = $matches[$i + 1];
2375
+					}
2265 2376
 
2266 2377
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2267 2378
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2269,23 +2380,26 @@  discard block
 block discarded – undo
2269 2380
 
2270 2381
 				foreach ($possible['parameters'] as $p => $info)
2271 2382
 				{
2272
-					if (!isset($params['{' . $p . '}']))
2273
-						$params['{' . $p . '}'] = '';
2383
+					if (!isset($params['{' . $p . '}'])) {
2384
+											$params['{' . $p . '}'] = '';
2385
+					}
2274 2386
 				}
2275 2387
 
2276 2388
 				$tag = $possible;
2277 2389
 
2278 2390
 				// Put the parameters into the string.
2279
-				if (isset($tag['before']))
2280
-					$tag['before'] = strtr($tag['before'], $params);
2281
-				if (isset($tag['after']))
2282
-					$tag['after'] = strtr($tag['after'], $params);
2283
-				if (isset($tag['content']))
2284
-					$tag['content'] = strtr($tag['content'], $params);
2391
+				if (isset($tag['before'])) {
2392
+									$tag['before'] = strtr($tag['before'], $params);
2393
+				}
2394
+				if (isset($tag['after'])) {
2395
+									$tag['after'] = strtr($tag['after'], $params);
2396
+				}
2397
+				if (isset($tag['content'])) {
2398
+									$tag['content'] = strtr($tag['content'], $params);
2399
+				}
2285 2400
 
2286 2401
 				$pos1 += strlen($given_param_string);
2287
-			}
2288
-			else
2402
+			} else
2289 2403
 			{
2290 2404
 				$tag = $possible;
2291 2405
 				$params = array();
@@ -2296,8 +2410,9 @@  discard block
 block discarded – undo
2296 2410
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2297 2411
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2298 2412
 		{
2299
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2300
-				continue;
2413
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2414
+							continue;
2415
+			}
2301 2416
 
2302 2417
 			$tag = $itemcodes[$message[$pos + 1]];
2303 2418
 
@@ -2318,9 +2433,9 @@  discard block
 block discarded – undo
2318 2433
 			{
2319 2434
 				array_pop($open_tags);
2320 2435
 				$code = '</li>';
2436
+			} else {
2437
+							$code = '';
2321 2438
 			}
2322
-			else
2323
-				$code = '';
2324 2439
 
2325 2440
 			// Now we open a new tag.
2326 2441
 			$open_tags[] = array(
@@ -2367,12 +2482,14 @@  discard block
 block discarded – undo
2367 2482
 		}
2368 2483
 
2369 2484
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2370
-		if ($tag === null)
2371
-			continue;
2485
+		if ($tag === null) {
2486
+					continue;
2487
+		}
2372 2488
 
2373 2489
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2374
-		if (isset($inside['disallow_children']))
2375
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2490
+		if (isset($inside['disallow_children'])) {
2491
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2492
+		}
2376 2493
 
2377 2494
 		// Is this tag disabled?
2378 2495
 		if (isset($disabled[$tag['tag']]))
@@ -2382,14 +2499,13 @@  discard block
 block discarded – undo
2382 2499
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2383 2500
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2384 2501
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2385
-			}
2386
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2502
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2387 2503
 			{
2388 2504
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2389 2505
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2506
+			} else {
2507
+							$tag['content'] = $tag['disabled_content'];
2390 2508
 			}
2391
-			else
2392
-				$tag['content'] = $tag['disabled_content'];
2393 2509
 		}
2394 2510
 
2395 2511
 		// we use this a lot
@@ -2399,8 +2515,9 @@  discard block
 block discarded – undo
2399 2515
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2400 2516
 		{
2401 2517
 			$n = count($open_tags) - 1;
2402
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2403
-				$n--;
2518
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2519
+							$n--;
2520
+			}
2404 2521
 
2405 2522
 			// Close all the non block level tags so this tag isn't surrounded by them.
2406 2523
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2412,12 +2529,15 @@  discard block
 block discarded – undo
2412 2529
 
2413 2530
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2414 2531
 				$whitespace_regex = '';
2415
-				if (!empty($tag['block_level']))
2416
-					$whitespace_regex .= '(&nbsp;|\s)*<br>';
2417
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2418
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2419
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2420
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2532
+				if (!empty($tag['block_level'])) {
2533
+									$whitespace_regex .= '(&nbsp;|\s)*<br>';
2534
+				}
2535
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2536
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2537
+				}
2538
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2539
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2540
+				}
2421 2541
 
2422 2542
 				array_pop($open_tags);
2423 2543
 			}
@@ -2435,16 +2555,19 @@  discard block
 block discarded – undo
2435 2555
 		elseif ($tag['type'] == 'unparsed_content')
2436 2556
 		{
2437 2557
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2438
-			if ($pos2 === false)
2439
-				continue;
2558
+			if ($pos2 === false) {
2559
+							continue;
2560
+			}
2440 2561
 
2441 2562
 			$data = substr($message, $pos1, $pos2 - $pos1);
2442 2563
 
2443
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2444
-				$data = substr($data, 4);
2564
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2565
+							$data = substr($data, 4);
2566
+			}
2445 2567
 
2446
-			if (isset($tag['validate']))
2447
-				$tag['validate']($tag, $data, $disabled, $params);
2568
+			if (isset($tag['validate'])) {
2569
+							$tag['validate']($tag, $data, $disabled, $params);
2570
+			}
2448 2571
 
2449 2572
 			$code = strtr($tag['content'], array('$1' => $data));
2450 2573
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2460,34 +2583,40 @@  discard block
 block discarded – undo
2460 2583
 			if (isset($tag['quoted']))
2461 2584
 			{
2462 2585
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2463
-				if ($tag['quoted'] != 'optional' && !$quoted)
2464
-					continue;
2586
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2587
+									continue;
2588
+				}
2465 2589
 
2466
-				if ($quoted)
2467
-					$pos1 += 6;
2590
+				if ($quoted) {
2591
+									$pos1 += 6;
2592
+				}
2593
+			} else {
2594
+							$quoted = false;
2468 2595
 			}
2469
-			else
2470
-				$quoted = false;
2471 2596
 
2472 2597
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2473
-			if ($pos2 === false)
2474
-				continue;
2598
+			if ($pos2 === false) {
2599
+							continue;
2600
+			}
2475 2601
 
2476 2602
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2477
-			if ($pos3 === false)
2478
-				continue;
2603
+			if ($pos3 === false) {
2604
+							continue;
2605
+			}
2479 2606
 
2480 2607
 			$data = array(
2481 2608
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2482 2609
 				substr($message, $pos1, $pos2 - $pos1)
2483 2610
 			);
2484 2611
 
2485
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2486
-				$data[0] = substr($data[0], 4);
2612
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2613
+							$data[0] = substr($data[0], 4);
2614
+			}
2487 2615
 
2488 2616
 			// Validation for my parking, please!
2489
-			if (isset($tag['validate']))
2490
-				$tag['validate']($tag, $data, $disabled, $params);
2617
+			if (isset($tag['validate'])) {
2618
+							$tag['validate']($tag, $data, $disabled, $params);
2619
+			}
2491 2620
 
2492 2621
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2493 2622
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2504,23 +2633,27 @@  discard block
 block discarded – undo
2504 2633
 		elseif ($tag['type'] == 'unparsed_commas_content')
2505 2634
 		{
2506 2635
 			$pos2 = strpos($message, ']', $pos1);
2507
-			if ($pos2 === false)
2508
-				continue;
2636
+			if ($pos2 === false) {
2637
+							continue;
2638
+			}
2509 2639
 
2510 2640
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2511
-			if ($pos3 === false)
2512
-				continue;
2641
+			if ($pos3 === false) {
2642
+							continue;
2643
+			}
2513 2644
 
2514 2645
 			// We want $1 to be the content, and the rest to be csv.
2515 2646
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2516 2647
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2517 2648
 
2518
-			if (isset($tag['validate']))
2519
-				$tag['validate']($tag, $data, $disabled, $params);
2649
+			if (isset($tag['validate'])) {
2650
+							$tag['validate']($tag, $data, $disabled, $params);
2651
+			}
2520 2652
 
2521 2653
 			$code = $tag['content'];
2522
-			foreach ($data as $k => $d)
2523
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2524 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2525 2658
 			$pos += strlen($code) - 1 + 2;
2526 2659
 		}
@@ -2528,24 +2661,28 @@  discard block
 block discarded – undo
2528 2661
 		elseif ($tag['type'] == 'unparsed_commas')
2529 2662
 		{
2530 2663
 			$pos2 = strpos($message, ']', $pos1);
2531
-			if ($pos2 === false)
2532
-				continue;
2664
+			if ($pos2 === false) {
2665
+							continue;
2666
+			}
2533 2667
 
2534 2668
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2535 2669
 
2536
-			if (isset($tag['validate']))
2537
-				$tag['validate']($tag, $data, $disabled, $params);
2670
+			if (isset($tag['validate'])) {
2671
+							$tag['validate']($tag, $data, $disabled, $params);
2672
+			}
2538 2673
 
2539 2674
 			// Fix after, for disabled code mainly.
2540
-			foreach ($data as $k => $d)
2541
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2675
+			foreach ($data as $k => $d) {
2676
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2677
+			}
2542 2678
 
2543 2679
 			$open_tags[] = $tag;
2544 2680
 
2545 2681
 			// Replace them out, $1, $2, $3, $4, etc.
2546 2682
 			$code = $tag['before'];
2547
-			foreach ($data as $k => $d)
2548
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2683
+			foreach ($data as $k => $d) {
2684
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2685
+			}
2549 2686
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2550 2687
 			$pos += strlen($code) - 1 + 2;
2551 2688
 		}
@@ -2556,28 +2693,33 @@  discard block
 block discarded – undo
2556 2693
 			if (isset($tag['quoted']))
2557 2694
 			{
2558 2695
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2559
-				if ($tag['quoted'] != 'optional' && !$quoted)
2560
-					continue;
2696
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2697
+									continue;
2698
+				}
2561 2699
 
2562
-				if ($quoted)
2563
-					$pos1 += 6;
2700
+				if ($quoted) {
2701
+									$pos1 += 6;
2702
+				}
2703
+			} else {
2704
+							$quoted = false;
2564 2705
 			}
2565
-			else
2566
-				$quoted = false;
2567 2706
 
2568 2707
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2569
-			if ($pos2 === false)
2570
-				continue;
2708
+			if ($pos2 === false) {
2709
+							continue;
2710
+			}
2571 2711
 
2572 2712
 			$data = substr($message, $pos1, $pos2 - $pos1);
2573 2713
 
2574 2714
 			// Validation for my parking, please!
2575
-			if (isset($tag['validate']))
2576
-				$tag['validate']($tag, $data, $disabled, $params);
2715
+			if (isset($tag['validate'])) {
2716
+							$tag['validate']($tag, $data, $disabled, $params);
2717
+			}
2577 2718
 
2578 2719
 			// For parsed content, we must recurse to avoid security problems.
2579
-			if ($tag['type'] != 'unparsed_equals')
2580
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2720
+			if ($tag['type'] != 'unparsed_equals') {
2721
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2722
+			}
2581 2723
 
2582 2724
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2583 2725
 
@@ -2589,34 +2731,40 @@  discard block
 block discarded – undo
2589 2731
 		}
2590 2732
 
2591 2733
 		// If this is block level, eat any breaks after it.
2592
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2593
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2734
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2735
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2736
+		}
2594 2737
 
2595 2738
 		// Are we trimming outside this tag?
2596
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2597
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2739
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2740
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2741
+		}
2598 2742
 	}
2599 2743
 
2600 2744
 	// Close any remaining tags.
2601
-	while ($tag = array_pop($open_tags))
2602
-		$message .= "\n" . $tag['after'] . "\n";
2745
+	while ($tag = array_pop($open_tags)) {
2746
+			$message .= "\n" . $tag['after'] . "\n";
2747
+	}
2603 2748
 
2604 2749
 	// Parse the smileys within the parts where it can be done safely.
2605 2750
 	if ($smileys === true)
2606 2751
 	{
2607 2752
 		$message_parts = explode("\n", $message);
2608
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2609
-			parsesmileys($message_parts[$i]);
2753
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2754
+					parsesmileys($message_parts[$i]);
2755
+		}
2610 2756
 
2611 2757
 		$message = implode('', $message_parts);
2612 2758
 	}
2613 2759
 
2614 2760
 	// No smileys, just get rid of the markers.
2615
-	else
2616
-		$message = strtr($message, array("\n" => ''));
2761
+	else {
2762
+			$message = strtr($message, array("\n" => ''));
2763
+	}
2617 2764
 
2618
-	if ($message !== '' && $message[0] === ' ')
2619
-		$message = '&nbsp;' . substr($message, 1);
2765
+	if ($message !== '' && $message[0] === ' ') {
2766
+			$message = '&nbsp;' . substr($message, 1);
2767
+	}
2620 2768
 
2621 2769
 	// Cleanup whitespace.
2622 2770
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2625,15 +2773,16 @@  discard block
 block discarded – undo
2625 2773
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2626 2774
 
2627 2775
 	// Cache the output if it took some time...
2628
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2629
-		cache_put_data($cache_key, $message, 240);
2776
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2777
+			cache_put_data($cache_key, $message, 240);
2778
+	}
2630 2779
 
2631 2780
 	// If this was a force parse revert if needed.
2632 2781
 	if (!empty($parse_tags))
2633 2782
 	{
2634
-		if (empty($temp_bbc))
2635
-			$bbc_codes = array();
2636
-		else
2783
+		if (empty($temp_bbc)) {
2784
+					$bbc_codes = array();
2785
+		} else
2637 2786
 		{
2638 2787
 			$bbc_codes = $temp_bbc;
2639 2788
 			unset($temp_bbc);
@@ -2660,8 +2809,9 @@  discard block
 block discarded – undo
2660 2809
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2661 2810
 
2662 2811
 	// No smiley set at all?!
2663
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2664
-		return;
2812
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2813
+			return;
2814
+	}
2665 2815
 
2666 2816
 	// If smileyPregSearch hasn't been set, do it now.
2667 2817
 	if (empty($smileyPregSearch))
@@ -2672,8 +2822,7 @@  discard block
 block discarded – undo
2672 2822
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2673 2823
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2674 2824
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2675
-		}
2676
-		else
2825
+		} else
2677 2826
 		{
2678 2827
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2679 2828
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2697,9 +2846,9 @@  discard block
 block discarded – undo
2697 2846
 				$smcFunc['db_free_result']($result);
2698 2847
 
2699 2848
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2849
+			} else {
2850
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2700 2851
 			}
2701
-			else
2702
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2703 2852
 		}
2704 2853
 
2705 2854
 		// The non-breaking-space is a complex thing...
@@ -2776,35 +2925,41 @@  discard block
 block discarded – undo
2776 2925
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2777 2926
 
2778 2927
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2779
-	if (!empty($context['flush_mail']))
2780
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2928
+	if (!empty($context['flush_mail'])) {
2929
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2781 2930
 		AddMailQueue(true);
2931
+	}
2782 2932
 
2783 2933
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2784 2934
 
2785
-	if ($add)
2786
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2935
+	if ($add) {
2936
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2937
+	}
2787 2938
 
2788 2939
 	// Put the session ID in.
2789
-	if (defined('SID') && SID != '')
2790
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2940
+	if (defined('SID') && SID != '') {
2941
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2942
+	}
2791 2943
 	// Keep that debug in their for template debugging!
2792
-	elseif (isset($_GET['debug']))
2793
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2944
+	elseif (isset($_GET['debug'])) {
2945
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2946
+	}
2794 2947
 
2795 2948
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2796 2949
 	{
2797
-		if (defined('SID') && SID != '')
2798
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2950
+		if (defined('SID') && SID != '') {
2951
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2799 2952
 				function ($m) use ($scripturl)
2800 2953
 				{
2801 2954
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2955
+		}
2802 2956
 				}, $setLocation);
2803
-		else
2804
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2957
+		else {
2958
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2805 2959
 				function ($m) use ($scripturl)
2806 2960
 				{
2807 2961
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2962
+		}
2808 2963
 				}, $setLocation);
2809 2964
 	}
2810 2965
 
@@ -2815,8 +2970,9 @@  discard block
 block discarded – undo
2815 2970
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2816 2971
 
2817 2972
 	// Debugging.
2818
-	if (isset($db_show_debug) && $db_show_debug === true)
2819
-		$_SESSION['debug_redirect'] = $db_cache;
2973
+	if (isset($db_show_debug) && $db_show_debug === true) {
2974
+			$_SESSION['debug_redirect'] = $db_cache;
2975
+	}
2820 2976
 
2821 2977
 	obExit(false);
2822 2978
 }
@@ -2835,51 +2991,60 @@  discard block
 block discarded – undo
2835 2991
 
2836 2992
 	// Attempt to prevent a recursive loop.
2837 2993
 	++$level;
2838
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2839
-		exit;
2840
-	if ($from_fatal_error)
2841
-		$has_fatal_error = true;
2994
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2995
+			exit;
2996
+	}
2997
+	if ($from_fatal_error) {
2998
+			$has_fatal_error = true;
2999
+	}
2842 3000
 
2843 3001
 	// Clear out the stat cache.
2844 3002
 	trackStats();
2845 3003
 
2846 3004
 	// If we have mail to send, send it.
2847
-	if (!empty($context['flush_mail']))
2848
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3005
+	if (!empty($context['flush_mail'])) {
3006
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2849 3007
 		AddMailQueue(true);
3008
+	}
2850 3009
 
2851 3010
 	$do_header = $header === null ? !$header_done : $header;
2852
-	if ($do_footer === null)
2853
-		$do_footer = $do_header;
3011
+	if ($do_footer === null) {
3012
+			$do_footer = $do_header;
3013
+	}
2854 3014
 
2855 3015
 	// Has the template/header been done yet?
2856 3016
 	if ($do_header)
2857 3017
 	{
2858 3018
 		// Was the page title set last minute? Also update the HTML safe one.
2859
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2860
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3019
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3020
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3021
+		}
2861 3022
 
2862 3023
 		// Start up the session URL fixer.
2863 3024
 		ob_start('ob_sessrewrite');
2864 3025
 
2865
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2866
-			$buffers = explode(',', $settings['output_buffers']);
2867
-		elseif (!empty($settings['output_buffers']))
2868
-			$buffers = $settings['output_buffers'];
2869
-		else
2870
-			$buffers = array();
3026
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3027
+					$buffers = explode(',', $settings['output_buffers']);
3028
+		} elseif (!empty($settings['output_buffers'])) {
3029
+					$buffers = $settings['output_buffers'];
3030
+		} else {
3031
+					$buffers = array();
3032
+		}
2871 3033
 
2872
-		if (isset($modSettings['integrate_buffer']))
2873
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3034
+		if (isset($modSettings['integrate_buffer'])) {
3035
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3036
+		}
2874 3037
 
2875
-		if (!empty($buffers))
2876
-			foreach ($buffers as $function)
3038
+		if (!empty($buffers)) {
3039
+					foreach ($buffers as $function)
2877 3040
 			{
2878 3041
 				$call = call_helper($function, true);
3042
+		}
2879 3043
 
2880 3044
 				// Is it valid?
2881
-				if (!empty($call))
2882
-					ob_start($call);
3045
+				if (!empty($call)) {
3046
+									ob_start($call);
3047
+				}
2883 3048
 			}
2884 3049
 
2885 3050
 		// Display the screen in the logical order.
@@ -2891,8 +3056,9 @@  discard block
 block discarded – undo
2891 3056
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2892 3057
 
2893 3058
 		// Anything special to put out?
2894
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2895
-			echo $context['insert_after_template'];
3059
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3060
+					echo $context['insert_after_template'];
3061
+		}
2896 3062
 
2897 3063
 		// Just so we don't get caught in an endless loop of errors from the footer...
2898 3064
 		if (!$footer_done)
@@ -2901,14 +3067,16 @@  discard block
 block discarded – undo
2901 3067
 			template_footer();
2902 3068
 
2903 3069
 			// (since this is just debugging... it's okay that it's after </html>.)
2904
-			if (!isset($_REQUEST['xml']))
2905
-				displayDebug();
3070
+			if (!isset($_REQUEST['xml'])) {
3071
+							displayDebug();
3072
+			}
2906 3073
 		}
2907 3074
 	}
2908 3075
 
2909 3076
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2910
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2911
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3077
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3078
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3079
+	}
2912 3080
 
2913 3081
 	// For session check verification.... don't switch browsers...
2914 3082
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2917,9 +3085,10 @@  discard block
 block discarded – undo
2917 3085
 	call_integration_hook('integrate_exit', array($do_footer));
2918 3086
 
2919 3087
 	// Don't exit if we're coming from index.php; that will pass through normally.
2920
-	if (!$from_index)
2921
-		exit;
2922
-}
3088
+	if (!$from_index) {
3089
+			exit;
3090
+	}
3091
+	}
2923 3092
 
2924 3093
 /**
2925 3094
  * Get the size of a specified image with better error handling.
@@ -2938,8 +3107,9 @@  discard block
 block discarded – undo
2938 3107
 	$url = str_replace(' ', '%20', $url);
2939 3108
 
2940 3109
 	// Can we pull this from the cache... please please?
2941
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2942
-		return $temp;
3110
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3111
+			return $temp;
3112
+	}
2943 3113
 	$t = microtime();
2944 3114
 
2945 3115
 	// Get the host to pester...
@@ -2949,12 +3119,10 @@  discard block
 block discarded – undo
2949 3119
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2950 3120
 	{
2951 3121
 		return false;
2952
-	}
2953
-	elseif (!isset($match[1]))
3122
+	} elseif (!isset($match[1]))
2954 3123
 	{
2955 3124
 		$size = @getimagesize($url);
2956
-	}
2957
-	else
3125
+	} else
2958 3126
 	{
2959 3127
 		// Try to connect to the server... give it half a second.
2960 3128
 		$temp = 0;
@@ -2993,12 +3161,14 @@  discard block
 block discarded – undo
2993 3161
 	}
2994 3162
 
2995 3163
 	// If we didn't get it, we failed.
2996
-	if (!isset($size))
2997
-		$size = false;
3164
+	if (!isset($size)) {
3165
+			$size = false;
3166
+	}
2998 3167
 
2999 3168
 	// If this took a long time, we may never have to do it again, but then again we might...
3000
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3001
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3169
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3170
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3171
+	}
3002 3172
 
3003 3173
 	// Didn't work.
3004 3174
 	return $size;
@@ -3016,8 +3186,9 @@  discard block
 block discarded – undo
3016 3186
 
3017 3187
 	// Under SSI this function can be called more then once.  That can cause some problems.
3018 3188
 	//   So only run the function once unless we are forced to run it again.
3019
-	if ($loaded && !$forceload)
3020
-		return;
3189
+	if ($loaded && !$forceload) {
3190
+			return;
3191
+	}
3021 3192
 
3022 3193
 	$loaded = true;
3023 3194
 
@@ -3029,14 +3200,16 @@  discard block
 block discarded – undo
3029 3200
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3030 3201
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3031 3202
 	{
3032
-		if (trim($context['news_lines'][$i]) == '')
3033
-			continue;
3203
+		if (trim($context['news_lines'][$i]) == '') {
3204
+					continue;
3205
+		}
3034 3206
 
3035 3207
 		// Clean it up for presentation ;).
3036 3208
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3037 3209
 	}
3038
-	if (!empty($context['news_lines']))
3039
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3210
+	if (!empty($context['news_lines'])) {
3211
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3212
+	}
3040 3213
 
3041 3214
 	if (!$user_info['is_guest'])
3042 3215
 	{
@@ -3045,40 +3218,48 @@  discard block
 block discarded – undo
3045 3218
 		$context['user']['alerts'] = &$user_info['alerts'];
3046 3219
 
3047 3220
 		// Personal message popup...
3048
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3049
-			$context['user']['popup_messages'] = true;
3050
-		else
3051
-			$context['user']['popup_messages'] = false;
3221
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3222
+					$context['user']['popup_messages'] = true;
3223
+		} else {
3224
+					$context['user']['popup_messages'] = false;
3225
+		}
3052 3226
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3053 3227
 
3054
-		if (allowedTo('moderate_forum'))
3055
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3228
+		if (allowedTo('moderate_forum')) {
3229
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3230
+		}
3056 3231
 
3057 3232
 		$context['user']['avatar'] = array();
3058 3233
 
3059 3234
 		// Check for gravatar first since we might be forcing them...
3060 3235
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3061 3236
 		{
3062
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3063
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3064
-			else
3065
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3237
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3238
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3239
+			} else {
3240
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3241
+			}
3066 3242
 		}
3067 3243
 		// Uploaded?
3068
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3069
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3244
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3245
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3246
+		}
3070 3247
 		// Full URL?
3071
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3072
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3248
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3249
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3250
+		}
3073 3251
 		// Otherwise we assume it's server stored.
3074
-		elseif ($user_info['avatar']['url'] != '')
3075
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3252
+		elseif ($user_info['avatar']['url'] != '') {
3253
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3254
+		}
3076 3255
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3077
-		else
3078
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3256
+		else {
3257
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3258
+		}
3079 3259
 
3080
-		if (!empty($context['user']['avatar']))
3081
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3260
+		if (!empty($context['user']['avatar'])) {
3261
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3262
+		}
3082 3263
 
3083 3264
 		// Figure out how long they've been logged in.
3084 3265
 		$context['user']['total_time_logged_in'] = array(
@@ -3086,8 +3267,7 @@  discard block
 block discarded – undo
3086 3267
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3087 3268
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3088 3269
 		);
3089
-	}
3090
-	else
3270
+	} else
3091 3271
 	{
3092 3272
 		$context['user']['messages'] = 0;
3093 3273
 		$context['user']['unread_messages'] = 0;
@@ -3095,12 +3275,14 @@  discard block
 block discarded – undo
3095 3275
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3096 3276
 		$context['user']['popup_messages'] = false;
3097 3277
 
3098
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3099
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3278
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3279
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3280
+		}
3100 3281
 
3101 3282
 		// If we've upgraded recently, go easy on the passwords.
3102
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3103
-			$context['disable_login_hashing'] = true;
3283
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3284
+					$context['disable_login_hashing'] = true;
3285
+		}
3104 3286
 	}
3105 3287
 
3106 3288
 	// Setup the main menu items.
@@ -3113,8 +3295,8 @@  discard block
 block discarded – undo
3113 3295
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3114 3296
 
3115 3297
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3116
-	if ($context['show_pm_popup'])
3117
-		addInlineJavaScript('
3298
+	if ($context['show_pm_popup']) {
3299
+			addInlineJavaScript('
3118 3300
 		jQuery(document).ready(function($) {
3119 3301
 			new smc_Popup({
3120 3302
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3122,15 +3304,17 @@  discard block
 block discarded – undo
3122 3304
 				icon_class: \'generic_icons mail_new\'
3123 3305
 			});
3124 3306
 		});');
3307
+	}
3125 3308
 
3126 3309
 	// Add a generic "Are you sure?" confirmation message.
3127 3310
 	addInlineJavaScript('
3128 3311
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3129 3312
 
3130 3313
 	// Now add the capping code for avatars.
3131
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3132
-		addInlineCss('
3314
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3315
+			addInlineCss('
3133 3316
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3317
+	}
3134 3318
 
3135 3319
 	// This looks weird, but it's because BoardIndex.php references the variable.
3136 3320
 	$context['common_stats']['latest_member'] = array(
@@ -3147,11 +3331,13 @@  discard block
 block discarded – undo
3147 3331
 	);
3148 3332
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3149 3333
 
3150
-	if (empty($settings['theme_version']))
3151
-		addJavaScriptVar('smf_scripturl', $scripturl);
3334
+	if (empty($settings['theme_version'])) {
3335
+			addJavaScriptVar('smf_scripturl', $scripturl);
3336
+	}
3152 3337
 
3153
-	if (!isset($context['page_title']))
3154
-		$context['page_title'] = '';
3338
+	if (!isset($context['page_title'])) {
3339
+			$context['page_title'] = '';
3340
+	}
3155 3341
 
3156 3342
 	// Set some specific vars.
3157 3343
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3161,21 +3347,23 @@  discard block
 block discarded – undo
3161 3347
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3162 3348
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3163 3349
 
3164
-	if (!empty($context['meta_keywords']))
3165
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3350
+	if (!empty($context['meta_keywords'])) {
3351
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3352
+	}
3166 3353
 
3167
-	if (!empty($context['canonical_url']))
3168
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3354
+	if (!empty($context['canonical_url'])) {
3355
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3356
+	}
3169 3357
 
3170
-	if (!empty($settings['og_image']))
3171
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3358
+	if (!empty($settings['og_image'])) {
3359
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3360
+	}
3172 3361
 
3173 3362
 	if (!empty($context['meta_description']))
3174 3363
 	{
3175 3364
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3176 3365
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3177
-	}
3178
-	else
3366
+	} else
3179 3367
 	{
3180 3368
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3181 3369
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3200,8 +3388,9 @@  discard block
 block discarded – undo
3200 3388
 	$memory_needed = memoryReturnBytes($needed);
3201 3389
 
3202 3390
 	// should we account for how much is currently being used?
3203
-	if ($in_use)
3204
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3391
+	if ($in_use) {
3392
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3393
+	}
3205 3394
 
3206 3395
 	// if more is needed, request it
3207 3396
 	if ($memory_current < $memory_needed)
@@ -3224,8 +3413,9 @@  discard block
 block discarded – undo
3224 3413
  */
3225 3414
 function memoryReturnBytes($val)
3226 3415
 {
3227
-	if (is_integer($val))
3228
-		return $val;
3416
+	if (is_integer($val)) {
3417
+			return $val;
3418
+	}
3229 3419
 
3230 3420
 	// Separate the number from the designator
3231 3421
 	$val = trim($val);
@@ -3261,10 +3451,11 @@  discard block
 block discarded – undo
3261 3451
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3262 3452
 
3263 3453
 		// Are we debugging the template/html content?
3264
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3265
-			header('Content-Type: application/xhtml+xml');
3266
-		elseif (!isset($_REQUEST['xml']))
3267
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3454
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3455
+					header('Content-Type: application/xhtml+xml');
3456
+		} elseif (!isset($_REQUEST['xml'])) {
3457
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3458
+		}
3268 3459
 	}
3269 3460
 
3270 3461
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3273,8 +3464,9 @@  discard block
 block discarded – undo
3273 3464
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3274 3465
 	{
3275 3466
 		$position = array_search('body', $context['template_layers']);
3276
-		if ($position === false)
3277
-			$position = array_search('main', $context['template_layers']);
3467
+		if ($position === false) {
3468
+					$position = array_search('main', $context['template_layers']);
3469
+		}
3278 3470
 
3279 3471
 		if ($position !== false)
3280 3472
 		{
@@ -3302,23 +3494,25 @@  discard block
 block discarded – undo
3302 3494
 
3303 3495
 			foreach ($securityFiles as $i => $securityFile)
3304 3496
 			{
3305
-				if (!file_exists($boarddir . '/' . $securityFile))
3306
-					unset($securityFiles[$i]);
3497
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3498
+									unset($securityFiles[$i]);
3499
+				}
3307 3500
 			}
3308 3501
 
3309 3502
 			// We are already checking so many files...just few more doesn't make any difference! :P
3310
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3311
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3312
-
3313
-			else
3314
-				$path = $modSettings['attachmentUploadDir'];
3503
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3504
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3505
+			} else {
3506
+							$path = $modSettings['attachmentUploadDir'];
3507
+			}
3315 3508
 
3316 3509
 			secureDirectory($path, true);
3317 3510
 			secureDirectory($cachedir);
3318 3511
 
3319 3512
 			// If agreement is enabled, at least the english version shall exists
3320
-			if ($modSettings['requireAgreement'])
3321
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3513
+			if ($modSettings['requireAgreement']) {
3514
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3515
+			}
3322 3516
 
3323 3517
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3324 3518
 			{
@@ -3333,18 +3527,21 @@  discard block
 block discarded – undo
3333 3527
 					echo '
3334 3528
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3335 3529
 
3336
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3337
-						echo '
3530
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3531
+											echo '
3338 3532
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3533
+					}
3339 3534
 				}
3340 3535
 
3341
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3342
-					echo '
3536
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3537
+									echo '
3343 3538
 				<strong>', $txt['cache_writable'], '</strong><br>';
3539
+				}
3344 3540
 
3345
-				if (!empty($agreement))
3346
-					echo '
3541
+				if (!empty($agreement)) {
3542
+									echo '
3347 3543
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3544
+				}
3348 3545
 
3349 3546
 				echo '
3350 3547
 			</p>
@@ -3359,16 +3556,18 @@  discard block
 block discarded – undo
3359 3556
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3360 3557
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3361 3558
 
3362
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3363
-				echo '
3559
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3560
+							echo '
3364 3561
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3562
+			}
3365 3563
 
3366
-			if (!empty($_SESSION['ban']['expire_time']))
3367
-				echo '
3564
+			if (!empty($_SESSION['ban']['expire_time'])) {
3565
+							echo '
3368 3566
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3369
-			else
3370
-				echo '
3567
+			} else {
3568
+							echo '
3371 3569
 					<div>', $txt['your_ban_expires_never'], '</div>';
3570
+			}
3372 3571
 
3373 3572
 			echo '
3374 3573
 				</div>';
@@ -3384,8 +3583,9 @@  discard block
 block discarded – undo
3384 3583
 	global $forum_copyright, $software_year, $forum_version;
3385 3584
 
3386 3585
 	// Don't display copyright for things like SSI.
3387
-	if (!isset($forum_version) || !isset($software_year))
3388
-		return;
3586
+	if (!isset($forum_version) || !isset($software_year)) {
3587
+			return;
3588
+	}
3389 3589
 
3390 3590
 	// Put in the version...
3391 3591
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3403,9 +3603,10 @@  discard block
 block discarded – undo
3403 3603
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3404 3604
 	$context['load_queries'] = $db_count;
3405 3605
 
3406
-	foreach (array_reverse($context['template_layers']) as $layer)
3407
-		loadSubTemplate($layer . '_below', true);
3408
-}
3606
+	foreach (array_reverse($context['template_layers']) as $layer) {
3607
+			loadSubTemplate($layer . '_below', true);
3608
+	}
3609
+	}
3409 3610
 
3410 3611
 /**
3411 3612
  * Output the Javascript files
@@ -3436,8 +3637,7 @@  discard block
 block discarded – undo
3436 3637
 			{
3437 3638
 				echo '
3438 3639
 		var ', $key, ';';
3439
-			}
3440
-			else
3640
+			} else
3441 3641
 			{
3442 3642
 				echo '
3443 3643
 		var ', $key, ' = ', $value, ';';
@@ -3452,26 +3652,27 @@  discard block
 block discarded – undo
3452 3652
 	foreach ($context['javascript_files'] as $id => $js_file)
3453 3653
 	{
3454 3654
 		// Last minute call! allow theme authors to disable single files.
3455
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3456
-			continue;
3655
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3656
+					continue;
3657
+		}
3457 3658
 
3458 3659
 		// By default all files don't get minimized unless the file explicitly says so!
3459 3660
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3460 3661
 		{
3461
-			if ($do_deferred && !empty($js_file['options']['defer']))
3462
-				$toMinifyDefer[] = $js_file;
3463
-
3464
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3465
-				$toMinify[] = $js_file;
3662
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3663
+							$toMinifyDefer[] = $js_file;
3664
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3665
+							$toMinify[] = $js_file;
3666
+			}
3466 3667
 
3467 3668
 			// Grab a random seed.
3468
-			if (!isset($minSeed))
3469
-				$minSeed = $js_file['options']['seed'];
3470
-		}
3471
-
3472
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3473
-			echo '
3669
+			if (!isset($minSeed)) {
3670
+							$minSeed = $js_file['options']['seed'];
3671
+			}
3672
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3673
+					echo '
3474 3674
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3675
+		}
3475 3676
 	}
3476 3677
 
3477 3678
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3479,14 +3680,14 @@  discard block
 block discarded – undo
3479 3680
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3480 3681
 
3481 3682
 		// Minify process couldn't work, print each individual files.
3482
-		if (!empty($result) && is_array($result))
3483
-			foreach ($result as $minFailedFile)
3683
+		if (!empty($result) && is_array($result)) {
3684
+					foreach ($result as $minFailedFile)
3484 3685
 				echo '
3485 3686
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3486
-
3487
-		else
3488
-			echo '
3687
+		} else {
3688
+					echo '
3489 3689
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3690
+		}
3490 3691
 	}
3491 3692
 
3492 3693
 	// Inline JavaScript - Actually useful some times!
@@ -3497,8 +3698,9 @@  discard block
 block discarded – undo
3497 3698
 			echo '
3498 3699
 <script>';
3499 3700
 
3500
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3501
-				echo $js_code;
3701
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3702
+							echo $js_code;
3703
+			}
3502 3704
 
3503 3705
 			echo '
3504 3706
 </script>';
@@ -3509,8 +3711,9 @@  discard block
 block discarded – undo
3509 3711
 			echo '
3510 3712
 	<script>';
3511 3713
 
3512
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3513
-				echo $js_code;
3714
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3715
+							echo $js_code;
3716
+			}
3514 3717
 
3515 3718
 			echo '
3516 3719
 	</script>';
@@ -3535,8 +3738,9 @@  discard block
 block discarded – undo
3535 3738
 	foreach ($context['css_files'] as $id => $file)
3536 3739
 	{
3537 3740
 		// Last minute call! allow theme authors to disable single files.
3538
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3539
-			continue;
3741
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3742
+					continue;
3743
+		}
3540 3744
 
3541 3745
 		// By default all files don't get minimized unless the file explicitly says so!
3542 3746
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3544,12 +3748,12 @@  discard block
 block discarded – undo
3544 3748
 			$toMinify[] = $file;
3545 3749
 
3546 3750
 			// Grab a random seed.
3547
-			if (!isset($minSeed))
3548
-				$minSeed = $file['options']['seed'];
3751
+			if (!isset($minSeed)) {
3752
+							$minSeed = $file['options']['seed'];
3753
+			}
3754
+		} else {
3755
+					$normal[] = $file['fileUrl'];
3549 3756
 		}
3550
-
3551
-		else
3552
-			$normal[] = $file['fileUrl'];
3553 3757
 	}
3554 3758
 
3555 3759
 	if (!empty($toMinify))
@@ -3557,28 +3761,30 @@  discard block
 block discarded – undo
3557 3761
 		$result = custMinify($toMinify, 'css');
3558 3762
 
3559 3763
 		// Minify process couldn't work, print each individual files.
3560
-		if (!empty($result) && is_array($result))
3561
-			foreach ($result as $minFailedFile)
3764
+		if (!empty($result) && is_array($result)) {
3765
+					foreach ($result as $minFailedFile)
3562 3766
 				echo '
3563 3767
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3564
-
3565
-		else
3566
-			echo '
3768
+		} else {
3769
+					echo '
3567 3770
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3771
+		}
3568 3772
 	}
3569 3773
 
3570 3774
 	// Print the rest after the minified files.
3571
-	if (!empty($normal))
3572
-		foreach ($normal as $nf)
3775
+	if (!empty($normal)) {
3776
+			foreach ($normal as $nf)
3573 3777
 			echo '
3574 3778
 	<link rel="stylesheet" href="', $nf ,'">';
3779
+	}
3575 3780
 
3576 3781
 	if ($db_show_debug === true)
3577 3782
 	{
3578 3783
 		// Try to keep only what's useful.
3579 3784
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3580
-		foreach ($context['css_files'] as $file)
3581
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3785
+		foreach ($context['css_files'] as $file) {
3786
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3787
+		}
3582 3788
 	}
3583 3789
 
3584 3790
 	if (!empty($context['css_header']))
@@ -3586,9 +3792,10 @@  discard block
 block discarded – undo
3586 3792
 		echo '
3587 3793
 	<style>';
3588 3794
 
3589
-		foreach ($context['css_header'] as $css)
3590
-			echo $css .'
3795
+		foreach ($context['css_header'] as $css) {
3796
+					echo $css .'
3591 3797
 	';
3798
+		}
3592 3799
 
3593 3800
 		echo'
3594 3801
 	</style>';
@@ -3612,15 +3819,17 @@  discard block
 block discarded – undo
3612 3819
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3613 3820
 	$data = !empty($data) ? $data : false;
3614 3821
 
3615
-	if (empty($type) || empty($data))
3616
-		return false;
3822
+	if (empty($type) || empty($data)) {
3823
+			return false;
3824
+	}
3617 3825
 
3618 3826
 	// Did we already did this?
3619 3827
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3620 3828
 
3621 3829
 	// Already done?
3622
-	if (!empty($toCache))
3623
-		return true;
3830
+	if (!empty($toCache)) {
3831
+			return true;
3832
+	}
3624 3833
 
3625 3834
 	// No namespaces, sorry!
3626 3835
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3702,8 +3911,9 @@  discard block
 block discarded – undo
3702 3911
 	global $modSettings, $smcFunc;
3703 3912
 
3704 3913
 	// Just make up a nice hash...
3705
-	if ($new)
3706
-		return sha1(md5($filename . time()) . mt_rand());
3914
+	if ($new) {
3915
+			return sha1(md5($filename . time()) . mt_rand());
3916
+	}
3707 3917
 
3708 3918
 	// Just make sure that attachment id is only a int
3709 3919
 	$attachment_id = (int) $attachment_id;
@@ -3720,23 +3930,25 @@  discard block
 block discarded – undo
3720 3930
 				'id_attach' => $attachment_id,
3721 3931
 			));
3722 3932
 
3723
-		if ($smcFunc['db_num_rows']($request) === 0)
3724
-			return false;
3933
+		if ($smcFunc['db_num_rows']($request) === 0) {
3934
+					return false;
3935
+		}
3725 3936
 
3726 3937
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3727 3938
 		$smcFunc['db_free_result']($request);
3728 3939
 	}
3729 3940
 
3730 3941
 	// Still no hash? mmm...
3731
-	if (empty($file_hash))
3732
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3942
+	if (empty($file_hash)) {
3943
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3944
+	}
3733 3945
 
3734 3946
 	// Are we using multiple directories?
3735
-	if (is_array($modSettings['attachmentUploadDir']))
3736
-		$path = $modSettings['attachmentUploadDir'][$dir];
3737
-
3738
-	else
3739
-		$path = $modSettings['attachmentUploadDir'];
3947
+	if (is_array($modSettings['attachmentUploadDir'])) {
3948
+			$path = $modSettings['attachmentUploadDir'][$dir];
3949
+	} else {
3950
+			$path = $modSettings['attachmentUploadDir'];
3951
+	}
3740 3952
 
3741 3953
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3742 3954
 }
@@ -3751,8 +3963,9 @@  discard block
 block discarded – undo
3751 3963
 function ip2range($fullip)
3752 3964
 {
3753 3965
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3754
-	if ($fullip == 'unknown')
3755
-		$fullip = '255.255.255.255';
3966
+	if ($fullip == 'unknown') {
3967
+			$fullip = '255.255.255.255';
3968
+	}
3756 3969
 
3757 3970
 	$ip_parts = explode('-', $fullip);
3758 3971
 	$ip_array = array();
@@ -3776,10 +3989,11 @@  discard block
 block discarded – undo
3776 3989
 		$ip_array['low'] = $ip_parts[0];
3777 3990
 		$ip_array['high'] = $ip_parts[1];
3778 3991
 		return $ip_array;
3779
-	}
3780
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3992
+	} elseif (count($ip_parts) == 2) {
3993
+		// if ip 22.22.*-22.22.*
3781 3994
 	{
3782 3995
 		$valid_low = isValidIP($ip_parts[0]);
3996
+	}
3783 3997
 		$valid_high = isValidIP($ip_parts[1]);
3784 3998
 		$count = 0;
3785 3999
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3794,7 +4008,9 @@  discard block
 block discarded – undo
3794 4008
 				$ip_parts[0] .= $mode . $min;
3795 4009
 				$valid_low = isValidIP($ip_parts[0]);
3796 4010
 				$count++;
3797
-				if ($count > 9) break;
4011
+				if ($count > 9) {
4012
+					break;
4013
+				}
3798 4014
 			}
3799 4015
 		}
3800 4016
 
@@ -3808,7 +4024,9 @@  discard block
 block discarded – undo
3808 4024
 				$ip_parts[1] .= $mode . $max;
3809 4025
 				$valid_high = isValidIP($ip_parts[1]);
3810 4026
 				$count++;
3811
-				if ($count > 9) break;
4027
+				if ($count > 9) {
4028
+					break;
4029
+				}
3812 4030
 			}
3813 4031
 		}
3814 4032
 
@@ -3833,46 +4051,54 @@  discard block
 block discarded – undo
3833 4051
 {
3834 4052
 	global $modSettings;
3835 4053
 
3836
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3837
-		return $host;
4054
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4055
+			return $host;
4056
+	}
3838 4057
 	$t = microtime();
3839 4058
 
3840 4059
 	// Try the Linux host command, perhaps?
3841 4060
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3842 4061
 	{
3843
-		if (!isset($modSettings['host_to_dis']))
3844
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3845
-		else
3846
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4062
+		if (!isset($modSettings['host_to_dis'])) {
4063
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4064
+		} else {
4065
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4066
+		}
3847 4067
 
3848 4068
 		// Did host say it didn't find anything?
3849
-		if (strpos($test, 'not found') !== false)
3850
-			$host = '';
4069
+		if (strpos($test, 'not found') !== false) {
4070
+					$host = '';
4071
+		}
3851 4072
 		// Invalid server option?
3852
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3853
-			updateSettings(array('host_to_dis' => 1));
4073
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4074
+					updateSettings(array('host_to_dis' => 1));
4075
+		}
3854 4076
 		// Maybe it found something, after all?
3855
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3856
-			$host = $match[1];
4077
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4078
+					$host = $match[1];
4079
+		}
3857 4080
 	}
3858 4081
 
3859 4082
 	// This is nslookup; usually only Windows, but possibly some Unix?
3860 4083
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3861 4084
 	{
3862 4085
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3863
-		if (strpos($test, 'Non-existent domain') !== false)
3864
-			$host = '';
3865
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3866
-			$host = $match[1];
4086
+		if (strpos($test, 'Non-existent domain') !== false) {
4087
+					$host = '';
4088
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4089
+					$host = $match[1];
4090
+		}
3867 4091
 	}
3868 4092
 
3869 4093
 	// This is the last try :/.
3870
-	if (!isset($host) || $host === false)
3871
-		$host = @gethostbyaddr($ip);
4094
+	if (!isset($host) || $host === false) {
4095
+			$host = @gethostbyaddr($ip);
4096
+	}
3872 4097
 
3873 4098
 	// It took a long time, so let's cache it!
3874
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3875
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4099
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4100
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4101
+	}
3876 4102
 
3877 4103
 	return $host;
3878 4104
 }
@@ -3908,20 +4134,21 @@  discard block
 block discarded – undo
3908 4134
 			{
3909 4135
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3910 4136
 				$total = 0;
3911
-				for ($i = 0; $i < $max_chars; $i++)
3912
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4137
+				for ($i = 0; $i < $max_chars; $i++) {
4138
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4139
+				}
3913 4140
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3914 4141
 			}
3915 4142
 		}
3916 4143
 		return array_unique($returned_ints);
3917
-	}
3918
-	else
4144
+	} else
3919 4145
 	{
3920 4146
 		// Trim characters before and after and add slashes for database insertion.
3921 4147
 		$returned_words = array();
3922
-		foreach ($words as $word)
3923
-			if (($word = trim($word, '-_\'')) !== '')
4148
+		foreach ($words as $word) {
4149
+					if (($word = trim($word, '-_\'')) !== '')
3924 4150
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4151
+		}
3925 4152
 
3926 4153
 		// Filter out all words that occur more than once.
3927 4154
 		return array_unique($returned_words);
@@ -3943,16 +4170,18 @@  discard block
 block discarded – undo
3943 4170
 	global $settings, $txt;
3944 4171
 
3945 4172
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3946
-	if (function_exists('template_create_button') && !$force_use)
3947
-		return template_create_button($name, $alt, $label = '', $custom = '');
4173
+	if (function_exists('template_create_button') && !$force_use) {
4174
+			return template_create_button($name, $alt, $label = '', $custom = '');
4175
+	}
3948 4176
 
3949
-	if (!$settings['use_image_buttons'])
3950
-		return $txt[$alt];
3951
-	elseif (!empty($settings['use_buttons']))
3952
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3953
-	else
3954
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3955
-}
4177
+	if (!$settings['use_image_buttons']) {
4178
+			return $txt[$alt];
4179
+	} elseif (!empty($settings['use_buttons'])) {
4180
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4181
+	} else {
4182
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4183
+	}
4184
+	}
3956 4185
 
3957 4186
 /**
3958 4187
  * Sets up all of the top menu buttons
@@ -3995,9 +4224,10 @@  discard block
 block discarded – undo
3995 4224
 	var user_menus = new smc_PopupMenu();
3996 4225
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3997 4226
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3998
-		if ($context['allow_pm'])
3999
-			addInlineJavaScript('
4227
+		if ($context['allow_pm']) {
4228
+					addInlineJavaScript('
4000 4229
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4230
+		}
4001 4231
 
4002 4232
 		if (!empty($modSettings['enable_ajax_alerts']))
4003 4233
 		{
@@ -4157,88 +4387,96 @@  discard block
 block discarded – undo
4157 4387
 
4158 4388
 		// Now we put the buttons in the context so the theme can use them.
4159 4389
 		$menu_buttons = array();
4160
-		foreach ($buttons as $act => $button)
4161
-			if (!empty($button['show']))
4390
+		foreach ($buttons as $act => $button) {
4391
+					if (!empty($button['show']))
4162 4392
 			{
4163 4393
 				$button['active_button'] = false;
4394
+		}
4164 4395
 
4165 4396
 				// This button needs some action.
4166
-				if (isset($button['action_hook']))
4167
-					$needs_action_hook = true;
4397
+				if (isset($button['action_hook'])) {
4398
+									$needs_action_hook = true;
4399
+				}
4168 4400
 
4169 4401
 				// Make sure the last button truly is the last button.
4170 4402
 				if (!empty($button['is_last']))
4171 4403
 				{
4172
-					if (isset($last_button))
4173
-						unset($menu_buttons[$last_button]['is_last']);
4404
+					if (isset($last_button)) {
4405
+											unset($menu_buttons[$last_button]['is_last']);
4406
+					}
4174 4407
 					$last_button = $act;
4175 4408
 				}
4176 4409
 
4177 4410
 				// Go through the sub buttons if there are any.
4178
-				if (!empty($button['sub_buttons']))
4179
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4411
+				if (!empty($button['sub_buttons'])) {
4412
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4180 4413
 					{
4181 4414
 						if (empty($subbutton['show']))
4182 4415
 							unset($button['sub_buttons'][$key]);
4416
+				}
4183 4417
 
4184 4418
 						// 2nd level sub buttons next...
4185 4419
 						if (!empty($subbutton['sub_buttons']))
4186 4420
 						{
4187 4421
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4188 4422
 							{
4189
-								if (empty($sub_button2['show']))
4190
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4423
+								if (empty($sub_button2['show'])) {
4424
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4425
+								}
4191 4426
 							}
4192 4427
 						}
4193 4428
 					}
4194 4429
 
4195 4430
 				// Does this button have its own icon?
4196
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4197
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4198
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4199
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4200
-				elseif (isset($button['icon']))
4201
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4202
-				else
4203
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4431
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4432
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4433
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4434
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4435
+				} elseif (isset($button['icon'])) {
4436
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4437
+				} else {
4438
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4439
+				}
4204 4440
 
4205 4441
 				$menu_buttons[$act] = $button;
4206 4442
 			}
4207 4443
 
4208
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4209
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4444
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4445
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4446
+		}
4210 4447
 	}
4211 4448
 
4212 4449
 	$context['menu_buttons'] = $menu_buttons;
4213 4450
 
4214 4451
 	// Logging out requires the session id in the url.
4215
-	if (isset($context['menu_buttons']['logout']))
4216
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4452
+	if (isset($context['menu_buttons']['logout'])) {
4453
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4454
+	}
4217 4455
 
4218 4456
 	// Figure out which action we are doing so we can set the active tab.
4219 4457
 	// Default to home.
4220 4458
 	$current_action = 'home';
4221 4459
 
4222
-	if (isset($context['menu_buttons'][$context['current_action']]))
4223
-		$current_action = $context['current_action'];
4224
-	elseif ($context['current_action'] == 'search2')
4225
-		$current_action = 'search';
4226
-	elseif ($context['current_action'] == 'theme')
4227
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4228
-	elseif ($context['current_action'] == 'register2')
4229
-		$current_action = 'register';
4230
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4231
-		$current_action = 'login';
4232
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4233
-		$current_action = 'moderate';
4460
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4461
+			$current_action = $context['current_action'];
4462
+	} elseif ($context['current_action'] == 'search2') {
4463
+			$current_action = 'search';
4464
+	} elseif ($context['current_action'] == 'theme') {
4465
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4466
+	} elseif ($context['current_action'] == 'register2') {
4467
+			$current_action = 'register';
4468
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4469
+			$current_action = 'login';
4470
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4471
+			$current_action = 'moderate';
4472
+	}
4234 4473
 
4235 4474
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4236 4475
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4237 4476
 	{
4238 4477
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4239 4478
 		$context[$current_action] = true;
4240
-	}
4241
-	elseif ($context['current_action'] == 'pm')
4479
+	} elseif ($context['current_action'] == 'pm')
4242 4480
 	{
4243 4481
 		$current_action = 'self_pm';
4244 4482
 		$context['self_pm'] = true;
@@ -4281,12 +4519,14 @@  discard block
 block discarded – undo
4281 4519
 	}
4282 4520
 
4283 4521
 	// Not all actions are simple.
4284
-	if (!empty($needs_action_hook))
4285
-		call_integration_hook('integrate_current_action', array(&$current_action));
4522
+	if (!empty($needs_action_hook)) {
4523
+			call_integration_hook('integrate_current_action', array(&$current_action));
4524
+	}
4286 4525
 
4287
-	if (isset($context['menu_buttons'][$current_action]))
4288
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4289
-}
4526
+	if (isset($context['menu_buttons'][$current_action])) {
4527
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4528
+	}
4529
+	}
4290 4530
 
4291 4531
 /**
4292 4532
  * Generate a random seed and ensure it's stored in settings.
@@ -4310,30 +4550,35 @@  discard block
 block discarded – undo
4310 4550
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4311 4551
 	global $context, $txt;
4312 4552
 
4313
-	if ($db_show_debug === true)
4314
-		$context['debug']['hooks'][] = $hook;
4553
+	if ($db_show_debug === true) {
4554
+			$context['debug']['hooks'][] = $hook;
4555
+	}
4315 4556
 
4316 4557
 	// Need to have some control.
4317
-	if (!isset($context['instances']))
4318
-		$context['instances'] = array();
4558
+	if (!isset($context['instances'])) {
4559
+			$context['instances'] = array();
4560
+	}
4319 4561
 
4320 4562
 	$results = array();
4321
-	if (empty($modSettings[$hook]))
4322
-		return $results;
4563
+	if (empty($modSettings[$hook])) {
4564
+			return $results;
4565
+	}
4323 4566
 
4324 4567
 	$functions = explode(',', $modSettings[$hook]);
4325 4568
 	// Loop through each function.
4326 4569
 	foreach ($functions as $function)
4327 4570
 	{
4328 4571
 		// Hook has been marked as "disabled". Skip it!
4329
-		if (strpos($function, '!') !== false)
4330
-			continue;
4572
+		if (strpos($function, '!') !== false) {
4573
+					continue;
4574
+		}
4331 4575
 
4332 4576
 		$call = call_helper($function, true);
4333 4577
 
4334 4578
 		// Is it valid?
4335
-		if (!empty($call))
4336
-			$results[$function] = call_user_func_array($call, $parameters);
4579
+		if (!empty($call)) {
4580
+					$results[$function] = call_user_func_array($call, $parameters);
4581
+		}
4337 4582
 
4338 4583
 		// Whatever it was suppose to call, it failed :(
4339 4584
 		elseif (!empty($function))
@@ -4349,8 +4594,9 @@  discard block
 block discarded – undo
4349 4594
 			}
4350 4595
 
4351 4596
 			// "Assume" the file resides on $boarddir somewhere...
4352
-			else
4353
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4597
+			else {
4598
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4599
+			}
4354 4600
 		}
4355 4601
 	}
4356 4602
 
@@ -4372,12 +4618,14 @@  discard block
 block discarded – undo
4372 4618
 	global $smcFunc, $modSettings;
4373 4619
 
4374 4620
 	// Any objects?
4375
-	if ($object)
4376
-		$function = $function . '#';
4621
+	if ($object) {
4622
+			$function = $function . '#';
4623
+	}
4377 4624
 
4378 4625
 	// Any files  to load?
4379
-	if (!empty($file) && is_string($file))
4380
-		$function = $file . (!empty($function) ? '|' . $function : '');
4626
+	if (!empty($file) && is_string($file)) {
4627
+			$function = $file . (!empty($function) ? '|' . $function : '');
4628
+	}
4381 4629
 
4382 4630
 	// Get the correct string.
4383 4631
 	$integration_call = $function;
@@ -4399,13 +4647,14 @@  discard block
 block discarded – undo
4399 4647
 		if (!empty($current_functions))
4400 4648
 		{
4401 4649
 			$current_functions = explode(',', $current_functions);
4402
-			if (in_array($integration_call, $current_functions))
4403
-				return;
4650
+			if (in_array($integration_call, $current_functions)) {
4651
+							return;
4652
+			}
4404 4653
 
4405 4654
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4655
+		} else {
4656
+					$permanent_functions = array($integration_call);
4406 4657
 		}
4407
-		else
4408
-			$permanent_functions = array($integration_call);
4409 4658
 
4410 4659
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4411 4660
 	}
@@ -4414,8 +4663,9 @@  discard block
 block discarded – undo
4414 4663
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4415 4664
 
4416 4665
 	// Do nothing, if it's already there.
4417
-	if (in_array($integration_call, $functions))
4418
-		return;
4666
+	if (in_array($integration_call, $functions)) {
4667
+			return;
4668
+	}
4419 4669
 
4420 4670
 	$functions[] = $integration_call;
4421 4671
 	$modSettings[$hook] = implode(',', $functions);
@@ -4438,12 +4688,14 @@  discard block
 block discarded – undo
4438 4688
 	global $smcFunc, $modSettings;
4439 4689
 
4440 4690
 	// Any objects?
4441
-	if ($object)
4442
-		$function = $function . '#';
4691
+	if ($object) {
4692
+			$function = $function . '#';
4693
+	}
4443 4694
 
4444 4695
 	// Any files  to load?
4445
-	if (!empty($file) && is_string($file))
4446
-		$function = $file . '|' . $function;
4696
+	if (!empty($file) && is_string($file)) {
4697
+			$function = $file . '|' . $function;
4698
+	}
4447 4699
 
4448 4700
 	// Get the correct string.
4449 4701
 	$integration_call = $function;
@@ -4464,16 +4716,18 @@  discard block
 block discarded – undo
4464 4716
 	{
4465 4717
 		$current_functions = explode(',', $current_functions);
4466 4718
 
4467
-		if (in_array($integration_call, $current_functions))
4468
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4719
+		if (in_array($integration_call, $current_functions)) {
4720
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4721
+		}
4469 4722
 	}
4470 4723
 
4471 4724
 	// Turn the function list into something usable.
4472 4725
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4473 4726
 
4474 4727
 	// You can only remove it if it's available.
4475
-	if (!in_array($integration_call, $functions))
4476
-		return;
4728
+	if (!in_array($integration_call, $functions)) {
4729
+			return;
4730
+	}
4477 4731
 
4478 4732
 	$functions = array_diff($functions, array($integration_call));
4479 4733
 	$modSettings[$hook] = implode(',', $functions);
@@ -4494,17 +4748,20 @@  discard block
 block discarded – undo
4494 4748
 	global $context, $smcFunc, $txt, $db_show_debug;
4495 4749
 
4496 4750
 	// Really?
4497
-	if (empty($string))
4498
-		return false;
4751
+	if (empty($string)) {
4752
+			return false;
4753
+	}
4499 4754
 
4500 4755
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4501 4756
 	// A closure? should be a callable one.
4502
-	if (is_array($string) || $string instanceof Closure)
4503
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4757
+	if (is_array($string) || $string instanceof Closure) {
4758
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4759
+	}
4504 4760
 
4505 4761
 	// No full objects, sorry! pass a method or a property instead!
4506
-	if (is_object($string))
4507
-		return false;
4762
+	if (is_object($string)) {
4763
+			return false;
4764
+	}
4508 4765
 
4509 4766
 	// Stay vitaminized my friends...
4510 4767
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4513,8 +4770,9 @@  discard block
 block discarded – undo
4513 4770
 	$string = load_file($string);
4514 4771
 
4515 4772
 	// Loaded file failed
4516
-	if (empty($string))
4517
-		return false;
4773
+	if (empty($string)) {
4774
+			return false;
4775
+	}
4518 4776
 
4519 4777
 	// Found a method.
4520 4778
 	if (strpos($string, '::') !== false)
@@ -4535,8 +4793,9 @@  discard block
 block discarded – undo
4535 4793
 				// Add another one to the list.
4536 4794
 				if ($db_show_debug === true)
4537 4795
 				{
4538
-					if (!isset($context['debug']['instances']))
4539
-						$context['debug']['instances'] = array();
4796
+					if (!isset($context['debug']['instances'])) {
4797
+											$context['debug']['instances'] = array();
4798
+					}
4540 4799
 
4541 4800
 					$context['debug']['instances'][$class] = $class;
4542 4801
 				}
@@ -4546,13 +4805,15 @@  discard block
 block discarded – undo
4546 4805
 		}
4547 4806
 
4548 4807
 		// Right then. This is a call to a static method.
4549
-		else
4550
-			$func = array($class, $method);
4808
+		else {
4809
+					$func = array($class, $method);
4810
+		}
4551 4811
 	}
4552 4812
 
4553 4813
 	// Nope! just a plain regular function.
4554
-	else
4555
-		$func = $string;
4814
+	else {
4815
+			$func = $string;
4816
+	}
4556 4817
 
4557 4818
 	// Right, we got what we need, time to do some checks.
4558 4819
 	if (!is_callable($func, false, $callable_name))
@@ -4568,17 +4829,18 @@  discard block
 block discarded – undo
4568 4829
 	else
4569 4830
 	{
4570 4831
 		// What are we gonna do about it?
4571
-		if ($return)
4572
-			return $func;
4832
+		if ($return) {
4833
+					return $func;
4834
+		}
4573 4835
 
4574 4836
 		// If this is a plain function, avoid the heat of calling call_user_func().
4575 4837
 		else
4576 4838
 		{
4577
-			if (is_array($func))
4578
-				call_user_func($func);
4579
-
4580
-			else
4581
-				$func();
4839
+			if (is_array($func)) {
4840
+							call_user_func($func);
4841
+			} else {
4842
+							$func();
4843
+			}
4582 4844
 		}
4583 4845
 	}
4584 4846
 }
@@ -4595,31 +4857,34 @@  discard block
 block discarded – undo
4595 4857
 {
4596 4858
 	global $sourcedir, $txt, $boarddir, $settings;
4597 4859
 
4598
-	if (empty($string))
4599
-		return false;
4860
+	if (empty($string)) {
4861
+			return false;
4862
+	}
4600 4863
 
4601 4864
 	if (strpos($string, '|') !== false)
4602 4865
 	{
4603 4866
 		list ($file, $string) = explode('|', $string);
4604 4867
 
4605 4868
 		// Match the wildcards to their regular vars.
4606
-		if (empty($settings['theme_dir']))
4607
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4608
-
4609
-		else
4610
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4869
+		if (empty($settings['theme_dir'])) {
4870
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4871
+		} else {
4872
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4873
+		}
4611 4874
 
4612 4875
 		// Load the file if it can be loaded.
4613
-		if (file_exists($absPath))
4614
-			require_once($absPath);
4876
+		if (file_exists($absPath)) {
4877
+					require_once($absPath);
4878
+		}
4615 4879
 
4616 4880
 		// No? try a fallback to $sourcedir
4617 4881
 		else
4618 4882
 		{
4619 4883
 			$absPath = $sourcedir .'/'. $file;
4620 4884
 
4621
-			if (file_exists($absPath))
4622
-				require_once($absPath);
4885
+			if (file_exists($absPath)) {
4886
+							require_once($absPath);
4887
+			}
4623 4888
 
4624 4889
 			// Sorry, can't do much for you at this point.
4625 4890
 			else
@@ -4646,8 +4911,9 @@  discard block
 block discarded – undo
4646 4911
 	global $user_info, $smcFunc;
4647 4912
 
4648 4913
 	// Make sure we have something to work with.
4649
-	if (empty($topic))
4650
-		return array();
4914
+	if (empty($topic)) {
4915
+			return array();
4916
+	}
4651 4917
 
4652 4918
 
4653 4919
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4670,8 +4936,9 @@  discard block
 block discarded – undo
4670 4936
 				'topic' => $topic,
4671 4937
 			)
4672 4938
 		);
4673
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4674
-			$temp[] = (int) $row['content_id'];
4939
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4940
+					$temp[] = (int) $row['content_id'];
4941
+		}
4675 4942
 
4676 4943
 		cache_put_data($cache_key, $temp, $ttl);
4677 4944
 	}
@@ -4692,8 +4959,9 @@  discard block
 block discarded – undo
4692 4959
 {
4693 4960
 	global $context;
4694 4961
 
4695
-	if (empty($string))
4696
-		return $string;
4962
+	if (empty($string)) {
4963
+			return $string;
4964
+	}
4697 4965
 
4698 4966
 	// UTF-8 occurences of MS special characters
4699 4967
 	$findchars_utf8 = array(
@@ -4734,10 +5002,11 @@  discard block
 block discarded – undo
4734 5002
 		'--',	// &mdash;
4735 5003
 	);
4736 5004
 
4737
-	if ($context['utf8'])
4738
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4739
-	else
4740
-		$string = str_replace($findchars_iso, $replacechars, $string);
5005
+	if ($context['utf8']) {
5006
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5007
+	} else {
5008
+			$string = str_replace($findchars_iso, $replacechars, $string);
5009
+	}
4741 5010
 
4742 5011
 	return $string;
4743 5012
 }
@@ -4756,49 +5025,59 @@  discard block
 block discarded – undo
4756 5025
 {
4757 5026
 	global $context;
4758 5027
 
4759
-	if (!isset($matches[2]))
4760
-		return '';
5028
+	if (!isset($matches[2])) {
5029
+			return '';
5030
+	}
4761 5031
 
4762 5032
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4763 5033
 
4764 5034
 	// remove left to right / right to left overrides
4765
-	if ($num === 0x202D || $num === 0x202E)
4766
-		return '';
5035
+	if ($num === 0x202D || $num === 0x202E) {
5036
+			return '';
5037
+	}
4767 5038
 
4768 5039
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4769
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4770
-		return '&#' . $num . ';';
5040
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5041
+			return '&#' . $num . ';';
5042
+	}
4771 5043
 
4772 5044
 	if (empty($context['utf8']))
4773 5045
 	{
4774 5046
 		// no control characters
4775
-		if ($num < 0x20)
4776
-			return '';
5047
+		if ($num < 0x20) {
5048
+					return '';
5049
+		}
4777 5050
 		// text is text
4778
-		elseif ($num < 0x80)
4779
-			return chr($num);
5051
+		elseif ($num < 0x80) {
5052
+					return chr($num);
5053
+		}
4780 5054
 		// all others get html-ised
4781
-		else
4782
-			return '&#' . $matches[2] . ';';
4783
-	}
4784
-	else
5055
+		else {
5056
+					return '&#' . $matches[2] . ';';
5057
+		}
5058
+	} else
4785 5059
 	{
4786 5060
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4787 5061
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4788
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4789
-			return '';
5062
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5063
+					return '';
5064
+		}
4790 5065
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4791
-		elseif ($num < 0x80)
4792
-			return chr($num);
5066
+		elseif ($num < 0x80) {
5067
+					return chr($num);
5068
+		}
4793 5069
 		// <0x800 (2048)
4794
-		elseif ($num < 0x800)
4795
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5070
+		elseif ($num < 0x800) {
5071
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5072
+		}
4796 5073
 		// < 0x10000 (65536)
4797
-		elseif ($num < 0x10000)
4798
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5074
+		elseif ($num < 0x10000) {
5075
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5076
+		}
4799 5077
 		// <= 0x10FFFF (1114111)
4800
-		else
4801
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5078
+		else {
5079
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5080
+		}
4802 5081
 	}
4803 5082
 }
4804 5083
 
@@ -4814,28 +5093,34 @@  discard block
 block discarded – undo
4814 5093
  */
4815 5094
 function fixchar__callback($matches)
4816 5095
 {
4817
-	if (!isset($matches[1]))
4818
-		return '';
5096
+	if (!isset($matches[1])) {
5097
+			return '';
5098
+	}
4819 5099
 
4820 5100
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4821 5101
 
4822 5102
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4823 5103
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4824
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4825
-		return '';
5104
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5105
+			return '';
5106
+	}
4826 5107
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4827
-	elseif ($num < 0x80)
4828
-		return chr($num);
5108
+	elseif ($num < 0x80) {
5109
+			return chr($num);
5110
+	}
4829 5111
 	// <0x800 (2048)
4830
-	elseif ($num < 0x800)
4831
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5112
+	elseif ($num < 0x800) {
5113
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5114
+	}
4832 5115
 	// < 0x10000 (65536)
4833
-	elseif ($num < 0x10000)
4834
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5116
+	elseif ($num < 0x10000) {
5117
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5118
+	}
4835 5119
 	// <= 0x10FFFF (1114111)
4836
-	else
4837
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4838
-}
5120
+	else {
5121
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5122
+	}
5123
+	}
4839 5124
 
4840 5125
 /**
4841 5126
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4848,17 +5133,19 @@  discard block
 block discarded – undo
4848 5133
  */
4849 5134
 function entity_fix__callback($matches)
4850 5135
 {
4851
-	if (!isset($matches[2]))
4852
-		return '';
5136
+	if (!isset($matches[2])) {
5137
+			return '';
5138
+	}
4853 5139
 
4854 5140
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4855 5141
 
4856 5142
 	// we don't allow control characters, characters out of range, byte markers, etc
4857
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4858
-		return '';
4859
-	else
4860
-		return '&#' . $num . ';';
4861
-}
5143
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5144
+			return '';
5145
+	} else {
5146
+			return '&#' . $num . ';';
5147
+	}
5148
+	}
4862 5149
 
4863 5150
 /**
4864 5151
  * Return a Gravatar URL based on
@@ -4882,18 +5169,23 @@  discard block
 block discarded – undo
4882 5169
 		$ratings = array('G', 'PG', 'R', 'X');
4883 5170
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4884 5171
 		$url_params = array();
4885
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4886
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4887
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4888
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4889
-		if (!empty($modSettings['avatar_max_width_external']))
4890
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4891
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4892
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5172
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5173
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5174
+		}
5175
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5176
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5177
+		}
5178
+		if (!empty($modSettings['avatar_max_width_external'])) {
5179
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5180
+		}
5181
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5182
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4893 5183
 				$size_string = $modSettings['avatar_max_height_external'];
5184
+		}
4894 5185
 
4895
-		if (!empty($size_string))
4896
-			$url_params[] = 's=' . $size_string;
5186
+		if (!empty($size_string)) {
5187
+					$url_params[] = 's=' . $size_string;
5188
+		}
4897 5189
 	}
4898 5190
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4899 5191
 
@@ -4912,22 +5204,26 @@  discard block
 block discarded – undo
4912 5204
 	static $timezones = null, $lastwhen = null;
4913 5205
 
4914 5206
 	// No point doing this over if we already did it once
4915
-	if (!empty($timezones) && $when == $lastwhen)
4916
-		return $timezones;
4917
-	else
4918
-		$lastwhen = $when;
5207
+	if (!empty($timezones) && $when == $lastwhen) {
5208
+			return $timezones;
5209
+	} else {
5210
+			$lastwhen = $when;
5211
+	}
4919 5212
 
4920 5213
 	// Parseable datetime string?
4921
-	if (is_int($timestamp = strtotime($when)))
4922
-		$when = $timestamp;
5214
+	if (is_int($timestamp = strtotime($when))) {
5215
+			$when = $timestamp;
5216
+	}
4923 5217
 
4924 5218
 	// A Unix timestamp?
4925
-	elseif (is_numeric($when))
4926
-		$when = intval($when);
5219
+	elseif (is_numeric($when)) {
5220
+			$when = intval($when);
5221
+	}
4927 5222
 
4928 5223
 	// Invalid value? Just get current Unix timestamp.
4929
-	else
4930
-		$when = time();
5224
+	else {
5225
+			$when = time();
5226
+	}
4931 5227
 
4932 5228
 	// We'll need these too
4933 5229
 	$date_when = date_create('@' . $when);
@@ -4991,8 +5287,9 @@  discard block
 block discarded – undo
4991 5287
 	foreach ($priority_countries as $country)
4992 5288
 	{
4993 5289
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4994
-		if (!empty($country_tzids))
4995
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5290
+		if (!empty($country_tzids)) {
5291
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5292
+		}
4996 5293
 	}
4997 5294
 
4998 5295
 	// Process the preferred timezones first, then the rest.
@@ -5002,8 +5299,9 @@  discard block
 block discarded – undo
5002 5299
 	foreach ($tzids as $tzid)
5003 5300
 	{
5004 5301
 		// We don't want UTC right now
5005
-		if ($tzid == 'UTC')
5006
-			continue;
5302
+		if ($tzid == 'UTC') {
5303
+					continue;
5304
+		}
5007 5305
 
5008 5306
 		$tz = timezone_open($tzid);
5009 5307
 
@@ -5018,12 +5316,14 @@  discard block
 block discarded – undo
5018 5316
 		$tzgeo = timezone_location_get($tz);
5019 5317
 
5020 5318
 		// Don't overwrite our preferred tzids
5021
-		if (empty($zones[$tzkey]['tzid']))
5022
-			$zones[$tzkey]['tzid'] = $tzid;
5319
+		if (empty($zones[$tzkey]['tzid'])) {
5320
+					$zones[$tzkey]['tzid'] = $tzid;
5321
+		}
5023 5322
 
5024 5323
 		// A time zone from a prioritized country?
5025
-		if (in_array($tzid, $priority_tzids))
5026
-			$priority_zones[$tzkey] = true;
5324
+		if (in_array($tzid, $priority_tzids)) {
5325
+					$priority_zones[$tzkey] = true;
5326
+		}
5027 5327
 
5028 5328
 		// Keep track of the location and offset for this tzid
5029 5329
 		$tzid_parts = explode('/', $tzid);
@@ -5044,15 +5344,17 @@  discard block
 block discarded – undo
5044 5344
 
5045 5345
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5046 5346
 
5047
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5048
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5049
-		else
5050
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5347
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5348
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5349
+		} else {
5350
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5351
+		}
5051 5352
 
5052
-		if (isset($priority_zones[$tzkey]))
5053
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5054
-		else
5055
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5353
+		if (isset($priority_zones[$tzkey])) {
5354
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5355
+		} else {
5356
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5357
+		}
5056 5358
 	}
5057 5359
 
5058 5360
 	$timezones = array_merge(
@@ -5106,9 +5408,9 @@  discard block
 block discarded – undo
5106 5408
 			'Indian/Kerguelen' => 'TFT',
5107 5409
 		);
5108 5410
 
5109
-		if (!empty($missing_tz_abbrs[$tzid]))
5110
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5111
-		else
5411
+		if (!empty($missing_tz_abbrs[$tzid])) {
5412
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5413
+		} else
5112 5414
 		{
5113 5415
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5114 5416
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5136,8 +5438,9 @@  discard block
 block discarded – undo
5136 5438
  */
5137 5439
 function inet_ptod($ip_address)
5138 5440
 {
5139
-	if (!isValidIP($ip_address))
5140
-		return $ip_address;
5441
+	if (!isValidIP($ip_address)) {
5442
+			return $ip_address;
5443
+	}
5141 5444
 
5142 5445
 	$bin = inet_pton($ip_address);
5143 5446
 	return $bin;
@@ -5149,13 +5452,15 @@  discard block
 block discarded – undo
5149 5452
  */
5150 5453
 function inet_dtop($bin)
5151 5454
 {
5152
-	if(empty($bin))
5153
-		return '';
5455
+	if(empty($bin)) {
5456
+			return '';
5457
+	}
5154 5458
 
5155 5459
 	global $db_type;
5156 5460
 
5157
-	if ($db_type == 'postgresql')
5158
-		return $bin;
5461
+	if ($db_type == 'postgresql') {
5462
+			return $bin;
5463
+	}
5159 5464
 
5160 5465
 	$ip_address = inet_ntop($bin);
5161 5466
 
@@ -5180,26 +5485,32 @@  discard block
 block discarded – undo
5180 5485
  */
5181 5486
 function _safe_serialize($value)
5182 5487
 {
5183
-	if(is_null($value))
5184
-		return 'N;';
5488
+	if(is_null($value)) {
5489
+			return 'N;';
5490
+	}
5185 5491
 
5186
-	if(is_bool($value))
5187
-		return 'b:'. (int) $value .';';
5492
+	if(is_bool($value)) {
5493
+			return 'b:'. (int) $value .';';
5494
+	}
5188 5495
 
5189
-	if(is_int($value))
5190
-		return 'i:'. $value .';';
5496
+	if(is_int($value)) {
5497
+			return 'i:'. $value .';';
5498
+	}
5191 5499
 
5192
-	if(is_float($value))
5193
-		return 'd:'. str_replace(',', '.', $value) .';';
5500
+	if(is_float($value)) {
5501
+			return 'd:'. str_replace(',', '.', $value) .';';
5502
+	}
5194 5503
 
5195
-	if(is_string($value))
5196
-		return 's:'. strlen($value) .':"'. $value .'";';
5504
+	if(is_string($value)) {
5505
+			return 's:'. strlen($value) .':"'. $value .'";';
5506
+	}
5197 5507
 
5198 5508
 	if(is_array($value))
5199 5509
 	{
5200 5510
 		$out = '';
5201
-		foreach($value as $k => $v)
5202
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5511
+		foreach($value as $k => $v) {
5512
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5513
+		}
5203 5514
 
5204 5515
 		return 'a:'. count($value) .':{'. $out .'}';
5205 5516
 	}
@@ -5225,8 +5536,9 @@  discard block
 block discarded – undo
5225 5536
 
5226 5537
 	$out = _safe_serialize($value);
5227 5538
 
5228
-	if (isset($mbIntEnc))
5229
-		mb_internal_encoding($mbIntEnc);
5539
+	if (isset($mbIntEnc)) {
5540
+			mb_internal_encoding($mbIntEnc);
5541
+	}
5230 5542
 
5231 5543
 	return $out;
5232 5544
 }
@@ -5243,8 +5555,9 @@  discard block
 block discarded – undo
5243 5555
 function _safe_unserialize($str)
5244 5556
 {
5245 5557
 	// Input  is not a string.
5246
-	if(empty($str) || !is_string($str))
5247
-		return false;
5558
+	if(empty($str) || !is_string($str)) {
5559
+			return false;
5560
+	}
5248 5561
 
5249 5562
 	$stack = array();
5250 5563
 	$expected = array();
@@ -5260,43 +5573,38 @@  discard block
 block discarded – undo
5260 5573
 	while($state != 1)
5261 5574
 	{
5262 5575
 		$type = isset($str[0]) ? $str[0] : '';
5263
-		if($type == '}')
5264
-			$str = substr($str, 1);
5265
-
5266
-		else if($type == 'N' && $str[1] == ';')
5576
+		if($type == '}') {
5577
+					$str = substr($str, 1);
5578
+		} else if($type == 'N' && $str[1] == ';')
5267 5579
 		{
5268 5580
 			$value = null;
5269 5581
 			$str = substr($str, 2);
5270
-		}
5271
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5582
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5272 5583
 		{
5273 5584
 			$value = $matches[1] == '1' ? true : false;
5274 5585
 			$str = substr($str, 4);
5275
-		}
5276
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5586
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5277 5587
 		{
5278 5588
 			$value = (int)$matches[1];
5279 5589
 			$str = $matches[2];
5280
-		}
5281
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5590
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5282 5591
 		{
5283 5592
 			$value = (float)$matches[1];
5284 5593
 			$str = $matches[3];
5285
-		}
5286
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5594
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5287 5595
 		{
5288 5596
 			$value = substr($matches[2], 0, (int)$matches[1]);
5289 5597
 			$str = substr($matches[2], (int)$matches[1] + 2);
5290
-		}
5291
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5598
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5292 5599
 		{
5293 5600
 			$expectedLength = (int)$matches[1];
5294 5601
 			$str = $matches[2];
5295 5602
 		}
5296 5603
 
5297 5604
 		// Object or unknown/malformed type.
5298
-		else
5299
-			return false;
5605
+		else {
5606
+					return false;
5607
+		}
5300 5608
 
5301 5609
 		switch($state)
5302 5610
 		{
@@ -5324,8 +5632,9 @@  discard block
 block discarded – undo
5324 5632
 				if($type == '}')
5325 5633
 				{
5326 5634
 					// Array size is less than expected.
5327
-					if(count($list) < end($expected))
5328
-						return false;
5635
+					if(count($list) < end($expected)) {
5636
+											return false;
5637
+					}
5329 5638
 
5330 5639
 					unset($list);
5331 5640
 					$list = &$stack[count($stack)-1];
@@ -5334,8 +5643,9 @@  discard block
 block discarded – undo
5334 5643
 					// Go to terminal state if we're at the end of the root array.
5335 5644
 					array_pop($expected);
5336 5645
 
5337
-					if(count($expected) == 0)
5338
-						$state = 1;
5646
+					if(count($expected) == 0) {
5647
+											$state = 1;
5648
+					}
5339 5649
 
5340 5650
 					break;
5341 5651
 				}
@@ -5343,8 +5653,9 @@  discard block
 block discarded – undo
5343 5653
 				if($type == 'i' || $type == 's')
5344 5654
 				{
5345 5655
 					// Array size exceeds expected length.
5346
-					if(count($list) >= end($expected))
5347
-						return false;
5656
+					if(count($list) >= end($expected)) {
5657
+											return false;
5658
+					}
5348 5659
 
5349 5660
 					$key = $value;
5350 5661
 					$state = 3;
@@ -5378,8 +5689,9 @@  discard block
 block discarded – undo
5378 5689
 	}
5379 5690
 
5380 5691
 	// Trailing data in input.
5381
-	if(!empty($str))
5382
-		return false;
5692
+	if(!empty($str)) {
5693
+			return false;
5694
+	}
5383 5695
 
5384 5696
 	return $data;
5385 5697
 }
@@ -5402,8 +5714,9 @@  discard block
 block discarded – undo
5402 5714
 
5403 5715
 	$out = _safe_unserialize($str);
5404 5716
 
5405
-	if (isset($mbIntEnc))
5406
-		mb_internal_encoding($mbIntEnc);
5717
+	if (isset($mbIntEnc)) {
5718
+			mb_internal_encoding($mbIntEnc);
5719
+	}
5407 5720
 
5408 5721
 	return $out;
5409 5722
 }
@@ -5418,12 +5731,14 @@  discard block
 block discarded – undo
5418 5731
 function smf_chmod($file, $value = 0)
5419 5732
 {
5420 5733
 	// No file? no checks!
5421
-	if (empty($file))
5422
-		return false;
5734
+	if (empty($file)) {
5735
+			return false;
5736
+	}
5423 5737
 
5424 5738
 	// Already writable?
5425
-	if (is_writable($file))
5426
-		return true;
5739
+	if (is_writable($file)) {
5740
+			return true;
5741
+	}
5427 5742
 
5428 5743
 	// Do we have a file or a dir?
5429 5744
 	$isDir = is_dir($file);
@@ -5439,10 +5754,9 @@  discard block
 block discarded – undo
5439 5754
 		{
5440 5755
 			$isWritable = true;
5441 5756
 			break;
5757
+		} else {
5758
+					@chmod($file, $val);
5442 5759
 		}
5443
-
5444
-		else
5445
-			@chmod($file, $val);
5446 5760
 	}
5447 5761
 
5448 5762
 	return $isWritable;
@@ -5461,8 +5775,9 @@  discard block
 block discarded – undo
5461 5775
 	global $txt;
5462 5776
 
5463 5777
 	// Come on...
5464
-	if (empty($json) || !is_string($json))
5465
-		return array();
5778
+	if (empty($json) || !is_string($json)) {
5779
+			return array();
5780
+	}
5466 5781
 
5467 5782
 	$returnArray = @json_decode($json, $returnAsArray);
5468 5783
 
@@ -5500,11 +5815,11 @@  discard block
 block discarded – undo
5500 5815
 		$jsonDebug = $jsonDebug[0];
5501 5816
 		loadLanguage('Errors');
5502 5817
 
5503
-		if (!empty($jsonDebug))
5504
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5505
-
5506
-		else
5507
-			log_error($txt['json_'. $jsonError], 'critical');
5818
+		if (!empty($jsonDebug)) {
5819
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5820
+		} else {
5821
+					log_error($txt['json_'. $jsonError], 'critical');
5822
+		}
5508 5823
 
5509 5824
 		// Everyone expects an array.
5510 5825
 		return array();
@@ -5534,8 +5849,9 @@  discard block
 block discarded – undo
5534 5849
 	global $db_show_debug, $modSettings;
5535 5850
 
5536 5851
 	// Defensive programming anyone?
5537
-	if (empty($data))
5538
-		return false;
5852
+	if (empty($data)) {
5853
+			return false;
5854
+	}
5539 5855
 
5540 5856
 	// Don't need extra stuff...
5541 5857
 	$db_show_debug = false;
@@ -5543,11 +5859,11 @@  discard block
 block discarded – undo
5543 5859
 	// Kill anything else.
5544 5860
 	ob_end_clean();
5545 5861
 
5546
-	if (!empty($modSettings['CompressedOutput']))
5547
-		@ob_start('ob_gzhandler');
5548
-
5549
-	else
5550
-		ob_start();
5862
+	if (!empty($modSettings['CompressedOutput'])) {
5863
+			@ob_start('ob_gzhandler');
5864
+	} else {
5865
+			ob_start();
5866
+	}
5551 5867
 
5552 5868
 	// Set the header.
5553 5869
 	header($type);
@@ -5579,8 +5895,9 @@  discard block
 block discarded – undo
5579 5895
 	static $done = false;
5580 5896
 
5581 5897
 	// If we don't need to do anything, don't
5582
-	if (!$update && $done)
5583
-		return;
5898
+	if (!$update && $done) {
5899
+			return;
5900
+	}
5584 5901
 
5585 5902
 	// Should we get a new copy of the official list of TLDs?
5586 5903
 	if ($update)
@@ -5601,10 +5918,11 @@  discard block
 block discarded – undo
5601 5918
 		// Clean $tlds and convert it to an array
5602 5919
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5603 5920
 			$line = trim($line);
5604
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5605
-				return false;
5606
-			else
5607
-				return true;
5921
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5922
+							return false;
5923
+			} else {
5924
+							return true;
5925
+			}
5608 5926
 		});
5609 5927
 
5610 5928
 		// Convert Punycode to Unicode
@@ -5658,8 +5976,9 @@  discard block
 block discarded – undo
5658 5976
 						$idx += $digit * $w;
5659 5977
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5660 5978
 
5661
-						if ($digit < $t)
5662
-							break;
5979
+						if ($digit < $t) {
5980
+													break;
5981
+						}
5663 5982
 
5664 5983
 						$w = (int) ($w * ($base - $t));
5665 5984
 					}
@@ -5668,8 +5987,9 @@  discard block
 block discarded – undo
5668 5987
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5669 5988
 					$delta += intval($delta / ($deco_len + 1));
5670 5989
 
5671
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5672
-						$delta = intval($delta / ($base - $tmin));
5990
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5991
+											$delta = intval($delta / ($base - $tmin));
5992
+					}
5673 5993
 
5674 5994
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5675 5995
 					$is_first = false;
@@ -5678,8 +5998,9 @@  discard block
 block discarded – undo
5678 5998
 
5679 5999
 					if ($deco_len > 0)
5680 6000
 					{
5681
-						for ($i = $deco_len; $i > $idx; $i--)
5682
-							$decoded[$i] = $decoded[($i - 1)];
6001
+						for ($i = $deco_len; $i > $idx; $i--) {
6002
+													$decoded[$i] = $decoded[($i - 1)];
6003
+						}
5683 6004
 					}
5684 6005
 					$decoded[$idx++] = $char;
5685 6006
 				}
@@ -5687,24 +6008,29 @@  discard block
 block discarded – undo
5687 6008
 				foreach ($decoded as $k => $v)
5688 6009
 				{
5689 6010
 					// 7bit are transferred literally
5690
-					if ($v < 128)
5691
-						$output .= chr($v);
6011
+					if ($v < 128) {
6012
+											$output .= chr($v);
6013
+					}
5692 6014
 
5693 6015
 					// 2 bytes
5694
-					elseif ($v < (1 << 11))
5695
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6016
+					elseif ($v < (1 << 11)) {
6017
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6018
+					}
5696 6019
 
5697 6020
 					// 3 bytes
5698
-					elseif ($v < (1 << 16))
5699
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6021
+					elseif ($v < (1 << 16)) {
6022
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6023
+					}
5700 6024
 
5701 6025
 					// 4 bytes
5702
-					elseif ($v < (1 << 21))
5703
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6026
+					elseif ($v < (1 << 21)) {
6027
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6028
+					}
5704 6029
 
5705 6030
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5706
-					else
5707
-						$output .= $safe_char;
6031
+					else {
6032
+											$output .= $safe_char;
6033
+					}
5708 6034
 				}
5709 6035
 
5710 6036
 				$output_parts[] = $output;
@@ -5799,8 +6125,7 @@  discard block
 block discarded – undo
5799 6125
 
5800 6126
 		$strlen = 'mb_strlen';
5801 6127
 		$substr = 'mb_substr';
5802
-	}
5803
-	else
6128
+	} else
5804 6129
 	{
5805 6130
 		$strlen = $smcFunc['strlen'];
5806 6131
 		$substr = $smcFunc['substr'];
@@ -5814,20 +6139,21 @@  discard block
 block discarded – undo
5814 6139
 
5815 6140
 		$first = $substr($string, 0, 1);
5816 6141
 
5817
-		if (empty($index[$first]))
5818
-			$index[$first] = array();
6142
+		if (empty($index[$first])) {
6143
+					$index[$first] = array();
6144
+		}
5819 6145
 
5820 6146
 		if ($strlen($string) > 1)
5821 6147
 		{
5822 6148
 			// Sanity check on recursion
5823
-			if ($depth > 99)
5824
-				$index[$first][$substr($string, 1)] = '';
5825
-
5826
-			else
5827
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6149
+			if ($depth > 99) {
6150
+							$index[$first][$substr($string, 1)] = '';
6151
+			} else {
6152
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6153
+			}
6154
+		} else {
6155
+					$index[$first][''] = '';
5828 6156
 		}
5829
-		else
5830
-			$index[$first][''] = '';
5831 6157
 
5832 6158
 		$depth--;
5833 6159
 		return $index;
@@ -5850,9 +6176,9 @@  discard block
 block discarded – undo
5850 6176
 			$key_regex = preg_quote($key, $delim);
5851 6177
 			$new_key = $key;
5852 6178
 
5853
-			if (empty($value))
5854
-				$sub_regex = '';
5855
-			else
6179
+			if (empty($value)) {
6180
+							$sub_regex = '';
6181
+			} else
5856 6182
 			{
5857 6183
 				$sub_regex = $index_to_regex($value, $delim);
5858 6184
 
@@ -5860,22 +6186,22 @@  discard block
 block discarded – undo
5860 6186
 				{
5861 6187
 					$new_key_array = explode('(?'.'>', $sub_regex);
5862 6188
 					$new_key .= $new_key_array[0];
6189
+				} else {
6190
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5863 6191
 				}
5864
-				else
5865
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5866 6192
 			}
5867 6193
 
5868
-			if ($depth > 1)
5869
-				$regex[$new_key] = $key_regex . $sub_regex;
5870
-			else
6194
+			if ($depth > 1) {
6195
+							$regex[$new_key] = $key_regex . $sub_regex;
6196
+			} else
5871 6197
 			{
5872 6198
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5873 6199
 				{
5874 6200
 					$regex[$new_key] = $key_regex . $sub_regex;
5875 6201
 					unset($index[$key]);
6202
+				} else {
6203
+									break;
5876 6204
 				}
5877
-				else
5878
-					break;
5879 6205
 			}
5880 6206
 		}
5881 6207
 
@@ -5884,10 +6210,11 @@  discard block
 block discarded – undo
5884 6210
 			$l1 = $strlen($k1);
5885 6211
 			$l2 = $strlen($k2);
5886 6212
 
5887
-			if ($l1 == $l2)
5888
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5889
-			else
5890
-				return $l1 > $l2 ? -1 : 1;
6213
+			if ($l1 == $l2) {
6214
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6215
+			} else {
6216
+							return $l1 > $l2 ? -1 : 1;
6217
+			}
5891 6218
 		});
5892 6219
 
5893 6220
 		$depth--;
@@ -5898,15 +6225,18 @@  discard block
 block discarded – undo
5898 6225
 	$index = array();
5899 6226
 	$regexes = array();
5900 6227
 
5901
-	foreach ($strings as $string)
5902
-		$index = $add_string_to_index($string, $index);
6228
+	foreach ($strings as $string) {
6229
+			$index = $add_string_to_index($string, $index);
6230
+	}
5903 6231
 
5904
-	while (!empty($index))
5905
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6232
+	while (!empty($index)) {
6233
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6234
+	}
5906 6235
 
5907 6236
 	// Restore PHP's internal character encoding to whatever it was originally
5908
-	if (!empty($current_encoding))
5909
-		mb_internal_encoding($current_encoding);
6237
+	if (!empty($current_encoding)) {
6238
+			mb_internal_encoding($current_encoding);
6239
+	}
5910 6240
 
5911 6241
 	return $regexes;
5912 6242
 }
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 1 patch
Braces   +154 added lines, -118 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'] == 'viewweek')
43
+	} elseif ($context['calendar_view'] == 'viewweek')
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;
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, $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,19 +405,21 @@  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
-				elseif ($is_mini)
398
-					echo '<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
399
-				else
400
-					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
+				} elseif ($is_mini) {
411
+									echo '<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
412
+				} else {
413
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
414
+				}
401 415
 
402 416
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
403 417
 				if ($is_mini === false)
404 418
 				{
405 419
 					// Holidays are always fun, let's show them!
406
-					if (!empty($day['holidays']))
407
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
420
+					if (!empty($day['holidays'])) {
421
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
422
+					}
408 423
 
409 424
 					// Happy Birthday Dear, Member!
410 425
 					if (!empty($day['birthdays']))
@@ -422,14 +437,16 @@  discard block
 block discarded – undo
422 437
 							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) ? '' : ', ';
423 438
 
424 439
 							// 9...10! Let's stop there.
425
-							if ($birthday_count == 10 && $use_js_hide)
426
-								// !!TODO - Inline CSS and JavaScript should be moved.
440
+							if ($birthday_count == 10 && $use_js_hide) {
441
+															// !!TODO - Inline CSS and JavaScript should be moved.
427 442
 								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;">, ';
443
+							}
428 444
 
429 445
 							++$birthday_count;
430 446
 						}
431
-						if ($use_js_hide)
432
-							echo '</span>';
447
+						if ($use_js_hide) {
448
+													echo '</span>';
449
+						}
433 450
 
434 451
 						echo '</div>';
435 452
 					}
@@ -439,8 +456,9 @@  discard block
 block discarded – undo
439 456
 					{
440 457
 						// Sort events by start time (all day events will be listed first)
441 458
 						uasort($day['events'], function($a, $b) {
442
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
443
-						        return 0;
459
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
460
+						    						        return 0;
461
+						    }
444 462
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
445 463
 						});
446 464
 
@@ -456,17 +474,19 @@  discard block
 block discarded – undo
456 474
 
457 475
 							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' : '', '">';
458 476
 
459
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
460
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
461
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
462
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
463
-							elseif (!empty($event['allday']))
464
-								echo $txt['calendar_allday'];
477
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
478
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
479
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
480
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
481
+							} elseif (!empty($event['allday'])) {
482
+															echo $txt['calendar_allday'];
483
+							}
465 484
 
466 485
 							echo '</span>';
467 486
 
468
-							if (!empty($event['location']))
469
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
487
+							if (!empty($event['location'])) {
488
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
489
+							}
470 490
 
471 491
 							if ($event['can_edit'] || $event['can_export'])
472 492
 							{
@@ -503,10 +523,11 @@  discard block
 block discarded – undo
503 523
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
504 524
 			elseif ($is_mini === false)
505 525
 			{
506
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
507
-					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>';
508
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
509
-					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>';
526
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
527
+									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>';
528
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
529
+									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>';
530
+				}
510 531
 			}
511 532
 
512 533
 			// Close this day and increase var count.
@@ -532,8 +553,9 @@  discard block
 block discarded – undo
532 553
 	global $context, $txt, $scripturl, $modSettings;
533 554
 
534 555
 	// We might have no reason to proceed, if the variable isn't there.
535
-	if (!isset($context['calendar_grid_' . $grid_name]))
536
-		return false;
556
+	if (!isset($context['calendar_grid_' . $grid_name])) {
557
+			return false;
558
+	}
537 559
 
538 560
 	// Handy pointer.
539 561
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -568,8 +590,9 @@  discard block
 block discarded – undo
568 590
 					}
569 591
 
570 592
 					// The Month Title + Week Number...
571
-					if (!empty($calendar_data['week_title']))
572
-							echo $calendar_data['week_title'];
593
+					if (!empty($calendar_data['week_title'])) {
594
+												echo $calendar_data['week_title'];
595
+					}
573 596
 
574 597
 					echo '
575 598
 					</h3>
@@ -608,10 +631,11 @@  discard block
 block discarded – undo
608 631
 						<tr class="days_wrapper">
609 632
 							<td class="', implode(' ', $classes), ' act_day">';
610 633
 							// Should the day number be a link?
611
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
612
-								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>';
613
-							else
614
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
634
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
635
+															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>';
636
+							} else {
637
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
638
+							}
615 639
 
616 640
 							echo '</td>
617 641
 							<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'] : '', '">';
@@ -620,8 +644,9 @@  discard block
 block discarded – undo
620 644
 							{
621 645
 								// Sort events by start time (all day events will be listed first)
622 646
 								uasort($day['events'], function($a, $b) {
623
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
624
-								        return 0;
647
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
648
+								    								        return 0;
649
+								    }
625 650
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
626 651
 								});
627 652
 
@@ -633,15 +658,17 @@  discard block
 block discarded – undo
633 658
 
634 659
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
635 660
 
636
-									if (!empty($event['start_time_local']))
637
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
638
-									else
639
-										echo $txt['calendar_allday'];
661
+									if (!empty($event['start_time_local'])) {
662
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
663
+									} else {
664
+																			echo $txt['calendar_allday'];
665
+									}
640 666
 
641 667
 									echo '</span>';
642 668
 
643
-									if (!empty($event['location']))
644
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
669
+									if (!empty($event['location'])) {
670
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
671
+									}
645 672
 
646 673
 									if (!empty($event_icons_needed))
647 674
 									{
@@ -678,8 +705,7 @@  discard block
 block discarded – undo
678 705
 									</div>
679 706
 									<br class="clear">';
680 707
 								}
681
-							}
682
-							else
708
+							} else
683 709
 							{
684 710
 								if (!empty($context['can_post']))
685 711
 								{
@@ -692,8 +718,9 @@  discard block
 block discarded – undo
692 718
 							echo '</td>
693 719
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
694 720
 							// Show any holidays!
695
-							if (!empty($day['holidays']))
696
-								echo implode('<br>', $day['holidays']);
721
+							if (!empty($day['holidays'])) {
722
+															echo implode('<br>', $day['holidays']);
723
+							}
697 724
 
698 725
 							echo '</td>
699 726
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -751,8 +778,7 @@  discard block
 block discarded – undo
751 778
 				<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">
752 779
 				<input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '">
753 780
 			</form>';
754
-	}
755
-	else
781
+	} else
756 782
 	{
757 783
 		echo'
758 784
 			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
@@ -794,8 +820,9 @@  discard block
 block discarded – undo
794 820
 	echo '
795 821
 		<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;">';
796 822
 
797
-	if (!empty($context['event']['new']))
798
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
823
+	if (!empty($context['event']['new'])) {
824
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
825
+	}
799 826
 
800 827
 	// Start the main table.
801 828
 	echo '
@@ -845,9 +872,10 @@  discard block
 block discarded – undo
845 872
 		{
846 873
 			echo '
847 874
 								<optgroup label="', $category['name'], '">';
848
-			foreach ($category['boards'] as $board)
849
-				echo '
875
+			foreach ($category['boards'] as $board) {
876
+							echo '
850 877
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
878
+			}
851 879
 			echo '
852 880
 								</optgroup>';
853 881
 		}
@@ -883,9 +911,10 @@  discard block
 block discarded – undo
883 911
 							<span class="label">', $txt['calendar_timezone'], '</span>
884 912
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
885 913
 
886
-	foreach ($context['all_timezones'] as $tz => $tzname)
887
-		echo '
914
+	foreach ($context['all_timezones'] as $tz => $tzname) {
915
+			echo '
888 916
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
917
+	}
889 918
 
890 919
 	echo '
891 920
 							</select>
@@ -900,9 +929,10 @@  discard block
 block discarded – undo
900 929
 	echo '
901 930
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
902 931
 	// Delete button?
903
-	if (empty($context['event']['new']))
904
-		echo '
932
+	if (empty($context['event']['new'])) {
933
+			echo '
905 934
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
935
+	}
906 936
 
907 937
 	echo '
908 938
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -946,9 +976,10 @@  discard block
 block discarded – undo
946 976
 
947 977
 		foreach ($context['clockicons'] as $t => $v)
948 978
 		{
949
-			foreach ($v as $i)
950
-				echo '
979
+			foreach ($v as $i) {
980
+							echo '
951 981
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
982
+			}
952 983
 		}
953 984
 
954 985
 		echo '
@@ -973,13 +1004,14 @@  discard block
 block discarded – undo
973 1004
 
974 1005
 		foreach ($context['clockicons'] as $t => $v)
975 1006
 		{
976
-			foreach ($v as $i)
977
-				echo '
1007
+			foreach ($v as $i) {
1008
+							echo '
978 1009
 			if (', $t, ' >= ', $i, ')
979 1010
 			{
980 1011
 				turnon.push("', $t, '_', $i, '");
981 1012
 				', $t, ' -= ', $i, ';
982 1013
 			}';
1014
+			}
983 1015
 		}
984 1016
 
985 1017
 		echo '
@@ -1043,9 +1075,10 @@  discard block
 block discarded – undo
1043 1075
 
1044 1076
 	foreach ($context['clockicons'] as $t => $v)
1045 1077
 	{
1046
-		foreach ($v as $i)
1047
-			echo '
1078
+		foreach ($v as $i) {
1079
+					echo '
1048 1080
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1081
+		}
1049 1082
 	}
1050 1083
 
1051 1084
 	echo '
@@ -1062,13 +1095,14 @@  discard block
 block discarded – undo
1062 1095
 
1063 1096
 	foreach ($context['clockicons'] as $t => $v)
1064 1097
 	{
1065
-		foreach ($v as $i)
1066
-			echo '
1098
+		foreach ($v as $i) {
1099
+					echo '
1067 1100
 		if (', $t, ' >= ', $i, ')
1068 1101
 		{
1069 1102
 			turnon.push("', $t, '_', $i, '");
1070 1103
 			', $t, ' -= ', $i, ';
1071 1104
 		}';
1105
+		}
1072 1106
 	}
1073 1107
 
1074 1108
 	echo '
@@ -1127,9 +1161,10 @@  discard block
 block discarded – undo
1127 1161
 
1128 1162
 	foreach ($context['clockicons'] as $t => $v)
1129 1163
 	{
1130
-		foreach ($v as $i)
1131
-			echo '
1164
+		foreach ($v as $i) {
1165
+					echo '
1132 1166
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1167
+		}
1133 1168
 	}
1134 1169
 
1135 1170
 	echo '
@@ -1150,13 +1185,14 @@  discard block
 block discarded – undo
1150 1185
 
1151 1186
 	foreach ($context['clockicons'] as $t => $v)
1152 1187
 	{
1153
-		foreach ($v as $i)
1154
-		echo '
1188
+		foreach ($v as $i) {
1189
+				echo '
1155 1190
 		if (', $t, ' >= ', $i, ')
1156 1191
 		{
1157 1192
 			turnon.push("', $t, '_', $i, '");
1158 1193
 			', $t, ' -= ', $i, ';
1159 1194
 		}';
1195
+		}
1160 1196
 	}
1161 1197
 
1162 1198
 	echo '
Please login to merge, or discard this patch.
Themes/default/Admin.template.php 1 patch
Braces   +173 added lines, -125 removed lines patch added patch discarded remove patch
@@ -64,9 +64,10 @@  discard block
 block discarded – undo
64 64
 										<strong>', $txt['administrators'], ':</strong>
65 65
 										', implode(', ', $context['administrators']);
66 66
 	// If we have lots of admins... don't show them all.
67
-	if (!empty($context['more_admins_link']))
68
-		echo '
67
+	if (!empty($context['more_admins_link'])) {
68
+			echo '
69 69
 							(', $context['more_admins_link'], ')';
70
+	}
70 71
 
71 72
 	echo '
72 73
 									</div>
@@ -83,16 +84,18 @@  discard block
 block discarded – undo
83 84
 		foreach ($area['areas'] as $item_id => $item)
84 85
 		{
85 86
 			// No point showing the 'home' page here, we're already on it!
86
-			if ($area_id == 'forum' && $item_id == 'index')
87
-				continue;
87
+			if ($area_id == 'forum' && $item_id == 'index') {
88
+							continue;
89
+			}
88 90
 
89 91
 			$url = isset($item['url']) ? $item['url'] : $scripturl . '?action=admin;area=' . $item_id . (!empty($context[$context['admin_menu_name']]['extra_parameters']) ? $context[$context['admin_menu_name']]['extra_parameters'] : '');
90
-			if (!empty($item['icon_file']))
91
-				echo '
92
+			if (!empty($item['icon_file'])) {
93
+							echo '
92 94
 							<a href="', $url, '" class="admin_group', !empty($item['inactive']) ? ' inactive' : '', '"><img class="large_admin_menu_icon_file" src="', $item['icon_file'], '" alt="">', $item['label'], '</a>';
93
-			else
94
-				echo '
95
+			} else {
96
+							echo '
95 97
 							<a href="', $url, '"><span class="large_', $item['icon_class'], !empty($item['inactive']) ? ' inactive' : '', '"></span>', $item['label'], '</a>';
98
+			}
96 99
 		}
97 100
 
98 101
 		echo '
@@ -103,10 +106,11 @@  discard block
 block discarded – undo
103 106
 					</div>';
104 107
 
105 108
 	// The below functions include all the scripts needed from the simplemachines.org site. The language and format are passed for internationalization.
106
-	if (empty($modSettings['disable_smf_js']))
107
-		echo '
109
+	if (empty($modSettings['disable_smf_js'])) {
110
+			echo '
108 111
 					<script src="', $scripturl, '?action=viewsmfile;filename=current-version.js"></script>
109 112
 					<script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>';
113
+	}
110 114
 
111 115
 	// This sets the announcements and current versions themselves ;).
112 116
 	echo '
@@ -185,9 +189,10 @@  discard block
 block discarded – undo
185 189
 								<em>', $version['version'], '</em>';
186 190
 
187 191
 		// more details for this item, show them a link
188
-		if ($context['can_admin'] && isset($version['more']))
189
-			echo
192
+		if ($context['can_admin'] && isset($version['more'])) {
193
+					echo
190 194
 								' <a href="', $scripturl, $version['more'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['version_check_more'], '</a>';
195
+		}
191 196
 		echo '
192 197
 								<br>';
193 198
 	}
@@ -218,20 +223,22 @@  discard block
 block discarded – undo
218 223
 
219 224
 	foreach ($context['credits'] as $section)
220 225
 	{
221
-		if (isset($section['pretext']))
222
-			echo '
226
+		if (isset($section['pretext'])) {
227
+					echo '
223 228
 								<p>', $section['pretext'], '</p><hr>';
229
+		}
224 230
 
225 231
 		echo '
226 232
 								<dl>';
227 233
 
228 234
 		foreach ($section['groups'] as $group)
229 235
 		{
230
-			if (isset($group['title']))
231
-				echo '
236
+			if (isset($group['title'])) {
237
+							echo '
232 238
 									<dt>
233 239
 										<strong>', $group['title'], ':</strong>
234 240
 									</dt>';
241
+			}
235 242
 
236 243
 			echo '
237 244
 									<dd>', implode(', ', $group['members']), '</dd>';
@@ -240,10 +247,11 @@  discard block
 block discarded – undo
240 247
 		echo '
241 248
 								</dl>';
242 249
 
243
-		if (isset($section['posttext']))
244
-			echo '
250
+		if (isset($section['posttext'])) {
251
+					echo '
245 252
 								<hr>
246 253
 								<p>', $section['posttext'], '</p>';
254
+		}
247 255
 	}
248 256
 
249 257
 	echo '
@@ -259,9 +267,10 @@  discard block
 block discarded – undo
259 267
 							smfSupportVersions.forum = "', $context['forum_version'], '";';
260 268
 
261 269
 	// Don't worry, none of this is logged, it's just used to give information that might be of use.
262
-	foreach ($context['current_versions'] as $variable => $version)
263
-		echo '
270
+	foreach ($context['current_versions'] as $variable => $version) {
271
+			echo '
264 272
 							smfSupportVersions.', $variable, ' = "', $version['version'], '";';
273
+	}
265 274
 
266 275
 	// Now we just have to include the script and wait ;).
267 276
 	echo '
@@ -358,8 +367,8 @@  discard block
 block discarded – undo
358 367
 							<tbody>';
359 368
 
360 369
 	// Loop through every source file displaying its version - using javascript.
361
-	foreach ($context['file_versions'] as $filename => $version)
362
-		echo '
370
+	foreach ($context['file_versions'] as $filename => $version) {
371
+			echo '
363 372
 								<tr class="windowbg">
364 373
 									<td class="half_table">
365 374
 										', $filename, '
@@ -371,6 +380,7 @@  discard block
 block discarded – undo
371 380
 										<em id="currentSources', $filename, '">??</em>
372 381
 									</td>
373 382
 								</tr>';
383
+	}
374 384
 
375 385
 	// Default template files.
376 386
 	echo '
@@ -396,8 +406,8 @@  discard block
 block discarded – undo
396 406
 							<table id="Default" class="table_grid">
397 407
 								<tbody>';
398 408
 
399
-	foreach ($context['default_template_versions'] as $filename => $version)
400
-		echo '
409
+	foreach ($context['default_template_versions'] as $filename => $version) {
410
+			echo '
401 411
 									<tr class="windowbg">
402 412
 										<td class="half_table">
403 413
 											', $filename, '
@@ -409,6 +419,7 @@  discard block
 block discarded – undo
409 419
 											<em id="currentDefault', $filename, '">??</em>
410 420
 										</td>
411 421
 									</tr>';
422
+	}
412 423
 
413 424
 	// Now the language files...
414 425
 	echo '
@@ -436,8 +447,8 @@  discard block
 block discarded – undo
436 447
 
437 448
 	foreach ($context['default_language_versions'] as $language => $files)
438 449
 	{
439
-		foreach ($files as $filename => $version)
440
-			echo '
450
+		foreach ($files as $filename => $version) {
451
+					echo '
441 452
 									<tr class="windowbg">
442 453
 										<td class="half_table">
443 454
 											', $filename, '.<em>', $language, '</em>.php
@@ -449,6 +460,7 @@  discard block
 block discarded – undo
449 460
 											<em id="current', $filename, '.', $language, '">??</em>
450 461
 										</td>
451 462
 									</tr>';
463
+		}
452 464
 	}
453 465
 
454 466
 	echo '
@@ -478,8 +490,8 @@  discard block
 block discarded – undo
478 490
 							<table id="Templates" class="table_grid">
479 491
 								<tbody>';
480 492
 
481
-		foreach ($context['template_versions'] as $filename => $version)
482
-			echo '
493
+		foreach ($context['template_versions'] as $filename => $version) {
494
+					echo '
483 495
 									<tr class="windowbg">
484 496
 										<td class="half_table">
485 497
 											', $filename, '
@@ -491,6 +503,7 @@  discard block
 block discarded – undo
491 503
 											<em id="currentTemplates', $filename, '">??</em>
492 504
 										</td>
493 505
 									</tr>';
506
+		}
494 507
 
495 508
 		echo '
496 509
 								</tbody>
@@ -520,8 +533,8 @@  discard block
 block discarded – undo
520 533
 							<table id="Tasks" class="table_grid">
521 534
 								<tbody>';
522 535
 
523
-		foreach ($context['tasks_versions'] as $filename => $version)
524
-			echo '
536
+		foreach ($context['tasks_versions'] as $filename => $version) {
537
+					echo '
525 538
 									<tr class="windowbg">
526 539
 										<td class="half_table">
527 540
 											', $filename, '
@@ -533,6 +546,7 @@  discard block
 block discarded – undo
533 546
 											<em id="currentTasks', $filename, '">??</em>
534 547
 										</td>
535 548
 									</tr>';
549
+		}
536 550
 
537 551
 		echo '
538 552
 								</tbody>
@@ -574,9 +588,10 @@  discard block
 block discarded – undo
574 588
 {
575 589
 	global $context, $scripturl, $txt, $modSettings;
576 590
 
577
-	if (!empty($context['saved_successful']))
578
-		echo '
591
+	if (!empty($context['saved_successful'])) {
592
+			echo '
579 593
 					<div class="infobox">', $txt['settings_saved'], '</div>';
594
+	}
580 595
 
581 596
 	// First section is for adding/removing words from the censored list.
582 597
 	echo '
@@ -591,11 +606,12 @@  discard block
 block discarded – undo
591 606
 								<p>', $txt['admin_censored_where'], '</p>';
592 607
 
593 608
 	// Show text boxes for censoring [bad   ] => [good  ].
594
-	foreach ($context['censored_words'] as $vulgar => $proper)
595
-		echo '
609
+	foreach ($context['censored_words'] as $vulgar => $proper) {
610
+			echo '
596 611
 								<div class="block">
597 612
 									<input type="text" name="censor_vulgar[]" value="', $vulgar, '" size="30"> =&gt; <input type="text" name="censor_proper[]" value="', $proper, '" size="30">
598 613
 								</div>';
614
+	}
599 615
 
600 616
 	// Now provide a way to censor more words.
601 617
 	echo '
@@ -669,19 +685,21 @@  discard block
 block discarded – undo
669 685
 						<div class="windowbg2 noup">
670 686
 							', $txt['not_done_reason'];
671 687
 
672
-	if (!empty($context['continue_percent']))
673
-		echo '
688
+	if (!empty($context['continue_percent'])) {
689
+			echo '
674 690
 							<div class="progress_bar">
675 691
 								<div class="full_bar">', $context['continue_percent'], '%</div>
676 692
 								<div class="green_percent" style="width: ', $context['continue_percent'], '%;">&nbsp;</div>
677 693
 							</div>';
694
+	}
678 695
 
679
-	if (!empty($context['substep_enabled']))
680
-		echo '
696
+	if (!empty($context['substep_enabled'])) {
697
+			echo '
681 698
 							<div class="progress_bar">
682 699
 								<div class="full_bar">', $context['substep_title'], ' (', $context['substep_continue_percent'], '%)</div>
683 700
 								<div class="blue_percent" style="width: ', $context['substep_continue_percent'], '%;">&nbsp;</div>
684 701
 							</div>';
702
+	}
685 703
 
686 704
 	echo '
687 705
 							<form action="', $scripturl, $context['continue_get_data'], '" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
@@ -716,35 +734,40 @@  discard block
 block discarded – undo
716 734
 {
717 735
 	global $context, $txt, $scripturl;
718 736
 
719
-	if (!empty($context['saved_successful']))
720
-		echo '
737
+	if (!empty($context['saved_successful'])) {
738
+			echo '
721 739
 					<div class="infobox">', $txt['settings_saved'], '</div>';
722
-	elseif (!empty($context['saved_failed']))
723
-		echo '
740
+	} elseif (!empty($context['saved_failed'])) {
741
+			echo '
724 742
 					<div class="errorbox">', sprintf($txt['settings_not_saved'], $context['saved_failed']), '</div>';
743
+	}
725 744
 
726
-	if (!empty($context['settings_pre_javascript']))
727
-		echo '
745
+	if (!empty($context['settings_pre_javascript'])) {
746
+			echo '
728 747
 					<script>', $context['settings_pre_javascript'], '</script>';
748
+	}
729 749
 
730
-	if (!empty($context['settings_insert_above']))
731
-		echo $context['settings_insert_above'];
750
+	if (!empty($context['settings_insert_above'])) {
751
+			echo $context['settings_insert_above'];
752
+	}
732 753
 
733 754
 	echo '
734 755
 					<div id="admincenter">
735 756
 						<form id="admin_form_wrapper" action="', $context['post_url'], '" method="post" accept-charset="', $context['character_set'], '"', !empty($context['force_form_onsubmit']) ? ' onsubmit="' . $context['force_form_onsubmit'] . '"' : '', '>';
736 757
 
737 758
 	// Is there a custom title?
738
-	if (isset($context['settings_title']))
739
-		echo '
759
+	if (isset($context['settings_title'])) {
760
+			echo '
740 761
 							<div class="cat_bar">
741 762
 								<h3 class="catbg">', $context['settings_title'], '</h3>
742 763
 							</div>';
764
+	}
743 765
 
744 766
 	// Have we got a message to display?
745
-	if (!empty($context['settings_message']))
746
-		echo '
767
+	if (!empty($context['settings_message'])) {
768
+			echo '
747 769
 							<div class="information">', $context['settings_message'], '</div>';
770
+	}
748 771
 
749 772
 	// Now actually loop through all the variables.
750 773
 	$is_open = false;
@@ -797,8 +820,9 @@  discard block
 block discarded – undo
797 820
 		// Hang about? Are you pulling my leg - a callback?!
798 821
 		if (is_array($config_var) && $config_var['type'] == 'callback')
799 822
 		{
800
-			if (function_exists('template_callback_' . $config_var['name']))
801
-				call_user_func('template_callback_' . $config_var['name']);
823
+			if (function_exists('template_callback_' . $config_var['name'])) {
824
+							call_user_func('template_callback_' . $config_var['name']);
825
+			}
802 826
 
803 827
 			continue;
804 828
 		}
@@ -828,9 +852,10 @@  discard block
 block discarded – undo
828 852
 				$text_types = array('color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time');
829 853
 
830 854
 				// Show the [?] button.
831
-				if ($config_var['help'])
832
-					echo '
855
+				if ($config_var['help']) {
856
+									echo '
833 857
 							<a id="setting_', $config_var['name'], '_help" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help" title="', $txt['help'], '"></span></a> ';
858
+				}
834 859
 
835 860
 				echo '
836 861
 										<a id="setting_', $config_var['name'], '"></a> <span', ($config_var['disabled'] ? ' style="color: #777777;"' : ($config_var['invalid'] ? ' class="error"' : '')), '><label for="', $config_var['name'], '">', $config_var['label'], '</label>', $subtext, ($config_var['type'] == 'password' ? '<br><em>' . $txt['admin_confirm_password'] . '</em>' : ''), '</span>
@@ -839,22 +864,25 @@  discard block
 block discarded – undo
839 864
 										$config_var['preinput'];
840 865
 
841 866
 				// Show a check box.
842
-				if ($config_var['type'] == 'check')
843
-					echo '
867
+				if ($config_var['type'] == 'check') {
868
+									echo '
844 869
 										<input type="checkbox"', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '"', ($config_var['value'] ? ' checked' : ''), ' value="1" class="input_check">';
870
+				}
845 871
 				// Escape (via htmlspecialchars.) the text box.
846
-				elseif ($config_var['type'] == 'password')
847
-					echo '
872
+				elseif ($config_var['type'] == 'password') {
873
+									echo '
848 874
 										<input type="password"', $disabled, $javascript, ' name="', $config_var['name'], '[0]"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' value="*#fakepass#*" onfocus="this.value = \'\'; this.form.', $config_var['name'], '.disabled = false;" class="input_password"><br>
849 875
 										<input type="password" disabled id="', $config_var['name'], '" name="', $config_var['name'], '[1]"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' class="input_password">';
876
+				}
850 877
 				// Show a selection box.
851 878
 				elseif ($config_var['type'] == 'select')
852 879
 				{
853 880
 					echo '
854 881
 										<select name="', $config_var['name'], '" id="', $config_var['name'], '" ', $javascript, $disabled, (!empty($config_var['multiple']) ? ' multiple="multiple"' : ''), (!empty($config_var['multiple']) && !empty($config_var['size']) ? ' size="' . $config_var['size'] . '"' : ''), '>';
855
-					foreach ($config_var['data'] as $option)
856
-						echo '
882
+					foreach ($config_var['data'] as $option) {
883
+											echo '
857 884
 											<option value="', $option[0], '"', (!empty($config_var['value']) && ($option[0] == $config_var['value'] || (!empty($config_var['multiple']) && in_array($option[0], $config_var['value']))) ? ' selected' : ''), '>', $option[1], '</option>';
885
+					}
858 886
 					echo '
859 887
 										</select>';
860 888
 				}
@@ -868,15 +896,17 @@  discard block
 block discarded – undo
868 896
 												<legend class="board_selector"><a href="#">', $txt['select_boards_from_list'], '</a></legend>';
869 897
 					foreach ($context['board_list'] as $id_cat => $cat)
870 898
 					{
871
-						if (!$first)
872
-							echo '
899
+						if (!$first) {
900
+													echo '
873 901
 											<hr>';
902
+						}
874 903
 						echo '
875 904
 											<strong>', $cat['name'], '</strong>
876 905
 											<ul>';
877
-						foreach ($cat['boards'] as $id_board => $brd)
878
-							echo '
906
+						foreach ($cat['boards'] as $id_board => $brd) {
907
+													echo '
879 908
 												<li><label><input type="checkbox" name="', $config_var['name'], '[', $brd['id'], ']" value="1" class="input_check"', in_array($brd['id'], $config_var['value']) ? ' checked' : '', '> ', $brd['child_level'] > 0 ? str_repeat('&nbsp; &nbsp;', $brd['child_level']) : '', $brd['name'], '</label></li>';
909
+						}
880 910
 
881 911
 						echo '
882 912
 											</ul>';
@@ -886,12 +916,14 @@  discard block
 block discarded – undo
886 916
 											</fieldset>';
887 917
 				}
888 918
 				// Text area?
889
-				elseif ($config_var['type'] == 'large_text')
890
-					echo '
919
+				elseif ($config_var['type'] == 'large_text') {
920
+									echo '
891 921
 											<textarea rows="', (!empty($config_var['size']) ? $config_var['size'] : (!empty($config_var['rows']) ? $config_var['rows'] : 4)), '" cols="', (!empty($config_var['cols']) ? $config_var['cols'] : 30), '" ', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>';
922
+				}
892 923
 				// Permission group?
893
-				elseif ($config_var['type'] == 'permissions')
894
-					theme_inline_permissions($config_var['name']);
924
+				elseif ($config_var['type'] == 'permissions') {
925
+									theme_inline_permissions($config_var['name']);
926
+				}
895 927
 				// BBC selection?
896 928
 				elseif ($config_var['type'] == 'bbc')
897 929
 				{
@@ -902,20 +934,22 @@  discard block
 block discarded – undo
902 934
 
903 935
 					foreach ($context['bbc_columns'] as $bbcColumn)
904 936
 					{
905
-						foreach ($bbcColumn as $bbcTag)
906
-							echo '
937
+						foreach ($bbcColumn as $bbcTag) {
938
+													echo '
907 939
 														<li class="list_bbc floatleft">
908 940
 															<input type="checkbox" name="', $config_var['name'], '_enabledTags[]" id="tag_', $config_var['name'], '_', $bbcTag['tag'], '" value="', $bbcTag['tag'], '"', !in_array($bbcTag['tag'], $context['bbc_sections'][$config_var['name']]['disabled']) ? ' checked' : '', ' class="input_check"> <label for="tag_', $config_var['name'], '_', $bbcTag['tag'], '">', $bbcTag['tag'], '</label>', $bbcTag['show_help'] ? ' (<a href="' . $scripturl . '?action=helpadmin;help=tag_' . $bbcTag['tag'] . '" onclick="return reqOverlayDiv(this.href);">?</a>)' : '', '
909 941
 														</li>';
942
+						}
910 943
 					}
911 944
 					echo '							</ul>
912 945
 												<input type="checkbox" id="bbc_', $config_var['name'], '_select_all" onclick="invertAll(this, this.form, \'', $config_var['name'], '_enabledTags\');"', $context['bbc_sections'][$config_var['name']]['all_selected'] ? ' checked' : '', ' class="input_check"> <label for="bbc_', $config_var['name'], '_select_all"><em>', $txt['bbcTagsToUse_select_all'], '</em></label>
913 946
 											</fieldset>';
914 947
 				}
915 948
 				// A simple message?
916
-				elseif ($config_var['type'] == 'var_message')
917
-					echo '
949
+				elseif ($config_var['type'] == 'var_message') {
950
+									echo '
918 951
 											<div', !empty($config_var['name']) ? ' id="' . $config_var['name'] . '"' : '', '>', $config_var['var_message'], '</div>';
952
+				}
919 953
 				// Assume it must be a text box
920 954
 				else
921 955
 				{
@@ -940,63 +974,70 @@  discard block
 block discarded – undo
940 974
 											' . $config_var['postinput'] : '',
941 975
 										'</dd>';
942 976
 			}
943
-		}
944
-
945
-		else
977
+		} else
946 978
 		{
947 979
 			// Just show a separator.
948
-			if ($config_var == '')
949
-				echo '
980
+			if ($config_var == '') {
981
+							echo '
950 982
 								</dl>
951 983
 								<hr>
952 984
 								<dl class="settings">';
953
-			else
954
-				echo '
985
+			} else {
986
+							echo '
955 987
 									<dd>
956 988
 										<strong>' . $config_var . '</strong>
957 989
 									</dd>';
990
+			}
958 991
 		}
959 992
 	}
960 993
 
961
-	if ($is_open)
962
-		echo '
994
+	if ($is_open) {
995
+			echo '
963 996
 								</dl>';
997
+	}
964 998
 
965
-	if (empty($context['settings_save_dont_show']))
966
-		echo '
999
+	if (empty($context['settings_save_dont_show'])) {
1000
+			echo '
967 1001
 								<input type="submit" value="', $txt['save'], '"', (!empty($context['save_disabled']) ? ' disabled' : ''), (!empty($context['settings_save_onclick']) ? ' onclick="' . $context['settings_save_onclick'] . '"' : ''), ' class="button_submit">';
1002
+	}
968 1003
 
969
-	if ($is_open)
970
-		echo '
1004
+	if ($is_open) {
1005
+			echo '
971 1006
 							</div>';
1007
+	}
972 1008
 
973 1009
 
974 1010
 	// At least one token has to be used!
975
-	if (isset($context['admin-ssc_token']))
976
-		echo '
1011
+	if (isset($context['admin-ssc_token'])) {
1012
+			echo '
977 1013
 							<input type="hidden" name="', $context['admin-ssc_token_var'], '" value="', $context['admin-ssc_token'], '">';
1014
+	}
978 1015
 
979
-	if (isset($context['admin-dbsc_token']))
980
-		echo '
1016
+	if (isset($context['admin-dbsc_token'])) {
1017
+			echo '
981 1018
 							<input type="hidden" name="', $context['admin-dbsc_token_var'], '" value="', $context['admin-dbsc_token'], '">';
1019
+	}
982 1020
 
983
-	if (isset($context['admin-mp_token']))
984
-		echo '
1021
+	if (isset($context['admin-mp_token'])) {
1022
+			echo '
985 1023
 							<input type="hidden" name="', $context['admin-mp_token_var'], '" value="', $context['admin-mp_token'], '">';
1024
+	}
986 1025
 
987 1026
 	echo '
988 1027
 							<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
989 1028
 						</form>
990 1029
 					</div>';
991 1030
 
992
-	if (!empty($context['settings_post_javascript']))
993
-		echo '
1031
+	if (!empty($context['settings_post_javascript'])) {
1032
+			echo '
994 1033
 					<script>
995 1034
 					', $context['settings_post_javascript'], '
996 1035
 					</script>';
1036
+	}
997 1037
 
998
-	if (!empty($context['settings_insert_below']))
999
-		echo $context['settings_insert_below'];
1038
+	if (!empty($context['settings_insert_below'])) {
1039
+			echo $context['settings_insert_below'];
1040
+	}
1000 1041
 
1001 1042
 	// We may have added a board listing. If we did, we need to make it work.
1002 1043
 	addInlineJavascript('
@@ -1019,9 +1060,10 @@  discard block
 block discarded – undo
1019 1060
 {
1020 1061
 	global $context, $txt;
1021 1062
 
1022
-	if (!empty($context['saved_successful']))
1023
-		echo '
1063
+	if (!empty($context['saved_successful'])) {
1064
+			echo '
1024 1065
 					<div class="infobox">', $txt['settings_saved'], '</div>';
1066
+	}
1025 1067
 
1026 1068
 	// Standard fields.
1027 1069
 	template_show_list('standard_profile_fields');
@@ -1053,11 +1095,12 @@  discard block
 block discarded – undo
1053 1095
 	if (isset($_GET['msg']))
1054 1096
 	{
1055 1097
 		loadLanguage('Errors');
1056
-		if (isset($txt['custom_option_' . $_GET['msg']]))
1057
-			echo '
1098
+		if (isset($txt['custom_option_' . $_GET['msg']])) {
1099
+					echo '
1058 1100
 					<div class="errorbox">',
1059 1101
 						$txt['custom_option_' . $_GET['msg']], '
1060 1102
 					</div>';
1103
+		}
1061 1104
 	}
1062 1105
 
1063 1106
 	echo '
@@ -1123,9 +1166,10 @@  discard block
 block discarded – undo
1123 1166
 										<dd>
1124 1167
 											<select name="placement" id="placement">';
1125 1168
 
1126
-	foreach ($context['cust_profile_fields_placement'] as $order => $name)
1127
-		echo '
1169
+	foreach ($context['cust_profile_fields_placement'] as $order => $name) {
1170
+			echo '
1128 1171
 												<option value="', $order, '"', $context['field']['placement'] == $order ? ' selected' : '', '>', $txt['custom_profile_placement_' . $name], '</option>';
1172
+	}
1129 1173
 
1130 1174
 	echo '
1131 1175
 											</select>
@@ -1148,9 +1192,10 @@  discard block
 block discarded – undo
1148 1192
 										</dt>
1149 1193
 										<dd>
1150 1194
 											<select name="field_type" id="field_type" onchange="updateInputBoxes();">';
1151
-	foreach (array('text', 'textarea', 'select', 'radio', 'check') as $field_type)
1152
-		echo '
1195
+	foreach (array('text', 'textarea', 'select', 'radio', 'check') as $field_type) {
1196
+			echo '
1153 1197
 												<option value="', $field_type, '"', $context['field']['type'] == $field_type ? ' selected' : '', '>', $txt['custom_profile_type_' . $field_type], '</option>';
1198
+	}
1154 1199
 
1155 1200
 	echo '
1156 1201
 											</select>
@@ -1251,9 +1296,10 @@  discard block
 block discarded – undo
1251 1296
 								</fieldset>
1252 1297
 									<input type="submit" name="save" value="', $txt['save'], '" class="button_submit">';
1253 1298
 
1254
-	if ($context['fid'])
1255
-		echo '
1299
+	if ($context['fid']) {
1300
+			echo '
1256 1301
 									<input type="submit" name="delete" value="', $txt['delete'], '" data-confirm="', $txt['custom_edit_delete_sure'], '" class="button_submit you_sure">';
1302
+	}
1257 1303
 
1258 1304
 	echo '
1259 1305
 							</div>
@@ -1296,8 +1342,7 @@  discard block
 block discarded – undo
1296 1342
 	{
1297 1343
 		echo '
1298 1344
 						<p class="centertext"><strong>', $txt['admin_search_results_none'], '</strong></p>';
1299
-	}
1300
-	else
1345
+	} else
1301 1346
 	{
1302 1347
 		echo '
1303 1348
 						<ol class="search_results">';
@@ -1323,9 +1368,10 @@  discard block
 block discarded – undo
1323 1368
 							<li>
1324 1369
 								<a href="', $result['url'], '"><strong>', $result['name'], '</strong></a> [', isset($txt['admin_search_section_' . $result['type']]) ? $txt['admin_search_section_' . $result['type']] : $result['type'], ']';
1325 1370
 
1326
-				if ($result['help'])
1327
-					echo '
1371
+				if ($result['help']) {
1372
+									echo '
1328 1373
 								<p class="double_height">', $result['help'], '</p>';
1374
+				}
1329 1375
 
1330 1376
 				echo '
1331 1377
 							</li>';
@@ -1365,18 +1411,20 @@  discard block
 block discarded – undo
1365 1411
 									<strong>', $txt['setup_verification_answer'], '</strong>
1366 1412
 								</dd>';
1367 1413
 
1368
-		if (!empty($context['qa_by_lang'][$lang_id]))
1369
-			foreach ($context['qa_by_lang'][$lang_id] as $q_id)
1414
+		if (!empty($context['qa_by_lang'][$lang_id])) {
1415
+					foreach ($context['qa_by_lang'][$lang_id] as $q_id)
1370 1416
 			{
1371 1417
 				$question = $context['question_answers'][$q_id];
1418
+		}
1372 1419
 				echo '
1373 1420
 								<dt>
1374 1421
 									<input type="text" name="question[', $lang_id, '][', $q_id, ']" value="', $question['question'], '" size="50" class="input_text verification_question">
1375 1422
 								</dt>
1376 1423
 								<dd>';
1377
-				foreach ($question['answers'] as $answer)
1378
-					echo '
1424
+				foreach ($question['answers'] as $answer) {
1425
+									echo '
1379 1426
 									<input type="text" name="answer[', $lang_id, '][', $q_id, '][]" value="', $answer, '" size="50" class="input_text verification_answer">';
1427
+				}
1380 1428
 
1381 1429
 				echo '
1382 1430
 									<div class="qa_add_answer"><a href="javascript:void(0);" onclick="return addAnswer(this);">[ ', $txt['setup_verification_add_answer'], ' ]</a></div>
@@ -1415,11 +1463,12 @@  discard block
 block discarded – undo
1415 1463
 							', $txt['errors_found'], ':
1416 1464
 							<ul>';
1417 1465
 
1418
-			foreach ($context['repair_errors'] as $error)
1419
-				echo '
1466
+			foreach ($context['repair_errors'] as $error) {
1467
+							echo '
1420 1468
 								<li>
1421 1469
 									', $error, '
1422 1470
 								</li>';
1471
+			}
1423 1472
 
1424 1473
 			echo '
1425 1474
 							</ul>
@@ -1429,16 +1478,15 @@  discard block
 block discarded – undo
1429 1478
 							<p class="padding">
1430 1479
 								<strong><a href="', $scripturl, '?action=admin;area=repairboards;fixErrors;', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $scripturl, '?action=admin;area=maintain">', $txt['no'], '</a></strong>
1431 1480
 							</p>';
1432
-		}
1433
-		else
1434
-			echo '
1481
+		} else {
1482
+					echo '
1435 1483
 							<p>', $txt['maintain_no_errors'], '</p>
1436 1484
 							<p class="padding">
1437 1485
 								<a href="', $scripturl, '?action=admin;area=maintain;sa=routine">', $txt['maintain_return'], '</a>
1438 1486
 							</p>';
1487
+		}
1439 1488
 
1440
-	}
1441
-	else
1489
+	} else
1442 1490
 	{
1443 1491
 		if (!empty($context['redirect_to_recount']))
1444 1492
 		{
@@ -1450,8 +1498,7 @@  discard block
 block discarded – undo
1450 1498
 								<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1451 1499
 								<input type="submit" name="recount" id="recount_now" value="', $txt['errors_recount_now'], '">
1452 1500
 							</form>';
1453
-		}
1454
-		else
1501
+		} else
1455 1502
 		{
1456 1503
 			echo '
1457 1504
 							<p>', $txt['errors_fixed'], '</p>
@@ -1603,8 +1650,8 @@  discard block
 block discarded – undo
1603 1650
 function template_admin_quick_search()
1604 1651
 {
1605 1652
 	global $context, $txt;
1606
-	if ($context['user']['is_admin'])
1607
-		echo '
1653
+	if ($context['user']['is_admin']) {
1654
+			echo '
1608 1655
 								<span class="floatright admin_search">
1609 1656
 									<span class="generic_icons filter centericon"></span>
1610 1657
 									<input type="search" name="search_term" value="', $txt['admin_search'], '" onclick="if (this.value == \'', $txt['admin_search'], '\') this.value = \'\';" class="input_text">
@@ -1615,6 +1662,7 @@  discard block
 block discarded – undo
1615 1662
 									</select>
1616 1663
 									<input type="submit" name="search_go" id="search_go" value="', $txt['admin_search_go'], '" class="button_submit">
1617 1664
 								</span>';
1618
-}
1665
+	}
1666
+	}
1619 1667
 
1620 1668
 ?>
1621 1669
\ No newline at end of file
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +35 added lines, -24 removed lines patch added patch discarded remove patch
@@ -32,16 +32,18 @@  discard block
 block discarded – undo
32 32
 ob_start();
33 33
 
34 34
 // Do some cleaning, just in case.
35
-foreach (array('db_character_set', 'cachedir') as $variable)
35
+foreach (array('db_character_set', 'cachedir') as $variable) {
36 36
 	if (isset($GLOBALS[$variable]))
37 37
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
38
+}
38 39
 
39 40
 // Load the settings...
40 41
 require_once(dirname(__FILE__) . '/Settings.php');
41 42
 
42 43
 // Make absolutely sure the cache directory is defined.
43
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
44
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
44 45
 	$cachedir = $boarddir . '/cache';
46
+}
45 47
 
46 48
 // Without those we can't go anywhere
47 49
 require_once($sourcedir . '/QueryString.php');
@@ -51,8 +53,9 @@  discard block
 block discarded – undo
51 53
 require_once($sourcedir . '/Load.php');
52 54
 
53 55
 // If $maintenance is set specifically to 2, then we're upgrading or something.
54
-if (!empty($maintenance) && $maintenance == 2)
56
+if (!empty($maintenance) && $maintenance == 2) {
55 57
 	display_maintenance_message();
58
+}
56 59
 
57 60
 // Create a variable to store some SMF specific functions in.
58 61
 $smcFunc = array();
@@ -67,8 +70,9 @@  discard block
 block discarded – undo
67 70
 cleanRequest();
68 71
 
69 72
 // Seed the random generator.
70
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
73
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
71 74
 	smf_seed_generator();
75
+}
72 76
 
73 77
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
74 78
 if (isset($_GET['scheduled']))
@@ -88,9 +92,9 @@  discard block
 block discarded – undo
88 92
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
89 93
 {
90 94
 	// If zlib is being used, turn off output compression.
91
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
92
-		$modSettings['enableCompressedOutput'] = '0';
93
-	else
95
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
96
+			$modSettings['enableCompressedOutput'] = '0';
97
+	} else
94 98
 	{
95 99
 		ob_end_clean();
96 100
 		ob_start('ob_gzhandler');
@@ -182,18 +186,21 @@  discard block
 block discarded – undo
182 186
 	loadPermissions();
183 187
 
184 188
 	// Attachments don't require the entire theme to be loaded.
185
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
186
-		detectBrowser();
189
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
190
+			detectBrowser();
191
+	}
187 192
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
188
-	else
189
-		loadTheme();
193
+	else {
194
+			loadTheme();
195
+	}
190 196
 
191 197
 	// Check if the user should be disallowed access.
192 198
 	is_not_banned();
193 199
 
194 200
 	// If we are in a topic and don't have permission to approve it then duck out now.
195
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
196
-		fatal_lang_error('not_a_topic', false);
201
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
202
+			fatal_lang_error('not_a_topic', false);
203
+	}
197 204
 
198 205
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
199 206
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 		writeLog();
205 212
 
206 213
 		// Track forum statistics and hits...?
207
-		if (!empty($modSettings['hitStats']))
208
-			trackStats(array('hits' => '+'));
214
+		if (!empty($modSettings['hitStats'])) {
215
+					trackStats(array('hits' => '+'));
216
+		}
209 217
 	}
210 218
 	unset($no_stat_actions);
211 219
 
@@ -219,13 +227,14 @@  discard block
 block discarded – undo
219 227
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
220 228
 		}
221 229
 		// Don't even try it, sonny.
222
-		else
223
-			return 'InMaintenance';
230
+		else {
231
+					return 'InMaintenance';
232
+		}
224 233
 	}
225 234
 	// If guest access is off, a guest can only do one of the very few following actions.
226
-	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2'))))
227
-		return 'KickGuest';
228
-	elseif (empty($_REQUEST['action']))
235
+	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) {
236
+			return 'KickGuest';
237
+	} elseif (empty($_REQUEST['action']))
229 238
 	{
230 239
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
231 240
 		if (empty($board) && empty($topic))
@@ -239,8 +248,9 @@  discard block
 block discarded – undo
239 248
 
240 249
 				$call = call_helper($defaultAction, true);
241 250
 
242
-				if (!empty($call))
243
-					return $call;
251
+				if (!empty($call)) {
252
+									return $call;
253
+				}
244 254
 			}
245 255
 
246 256
 			// No default action huh? then go to our good old BoardIndex.
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 
371 381
 			$call = call_helper($fallbackAction, true);
372 382
 
373
-			if (!empty($call))
374
-				return $call;
383
+			if (!empty($call)) {
384
+							return $call;
385
+			}
375 386
 		}
376 387
 
377 388
 		// No fallback action, huh?
Please login to merge, or discard this patch.
other/upgrade.php 2 patches
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
 
1626 1626
 	// Our custom error handler - does nothing but does stop public errors from XML!
1627 1627
 	set_error_handler(
1628
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1628
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1629 1629
 		{
1630 1630
 			if ($support_js)
1631 1631
 				return true;
@@ -2610,94 +2610,94 @@  discard block
 block discarded – undo
2610 2610
 		// Translation table for the character sets not native for MySQL.
2611 2611
 		$translation_tables = array(
2612 2612
 			'windows-1255' => array(
2613
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2614
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2615
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2616
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2617
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2618
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2619
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2620
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2621
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2622
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2623
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2624
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2625
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2626
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2627
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2628
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2629
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2630
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2631
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2632
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2633
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2634
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2635
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2636
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2637
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2638
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2639
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2640
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2641
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2642
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2643
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2644
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2645
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2646
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2647
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2648
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2649
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2650
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2651
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2652
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2653
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2654
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2613
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2614
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2615
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2616
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2617
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2618
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2619
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2620
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2621
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2622
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2623
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2624
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2625
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2626
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2627
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2628
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2629
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2630
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2631
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2632
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2633
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2634
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2635
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2636
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2637
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2638
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2639
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2640
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2641
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2642
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2643
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2644
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2645
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2646
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2647
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2648
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2649
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2650
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2651
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2652
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2653
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2654
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2655 2655
 				'0xFA' => '0xD7AA',
2656 2656
 			),
2657 2657
 			'windows-1253' => array(
2658
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2659
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2660
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2661
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2662
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2663
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2664
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2665
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2666
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2667
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2668
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2669
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2670
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2671
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2672
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2673
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2674
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2675
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2676
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2677
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2678
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2679
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2680
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2681
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2682
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2683
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2684
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2685
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2686
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2687
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2688
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2689
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2690
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2691
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2692
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2693
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2694
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2695
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2696
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2697
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2698
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2699
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2700
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2658
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2659
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2660
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2661
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2662
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2663
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2664
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2665
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2666
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2667
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2668
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2669
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2670
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2671
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2672
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2673
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2674
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2675
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2676
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2677
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2678
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2679
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2680
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2681
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2682
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2683
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2684
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2685
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2686
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2687
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2688
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2689
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2690
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2691
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2692
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2693
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2694
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2695
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2696
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2697
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2698
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2699
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2700
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2701 2701
 			),
2702 2702
 		);
2703 2703
 
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
3800 3800
 			<input type="hidden" name="backup_done" id="backup_done" value="0">
3801 3801
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
3802
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
3802
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
3803 3803
 			<span id="debuginfo"></span>
3804 3804
 			</div>';
3805 3805
 
@@ -4300,7 +4300,7 @@  discard block
 block discarded – undo
4300 4300
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4301 4301
 			<input type="hidden" name="utf8_done" id="utf8_done" value="0">
4302 4302
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4303
-			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12') , 'px; overflow: auto;">
4303
+			<div id="debug_section" style="height: ', ($is_debug ? '97' : '12'), 'px; overflow: auto;">
4304 4304
 			<span id="debuginfo"></span>
4305 4305
 			</div>';
4306 4306
 
@@ -4401,7 +4401,7 @@  discard block
 block discarded – undo
4401 4401
 			<form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post">
4402 4402
 			<input type="hidden" name="json_done" id="json_done" value="0">
4403 4403
 			<strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong>
4404
-			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;">
4404
+			<div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;">
4405 4405
 			<span id="debuginfo"></span>
4406 4406
 			</div>';
4407 4407
 
Please login to merge, or discard this patch.
Braces   +875 added lines, -643 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,9 +290,9 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			$_GET['substep'] = 0;
@@ -321,17 +336,18 @@  discard block
 block discarded – undo
321 336
 		// This should not happen my dear... HELP ME DEVELOPERS!!
322 337
 		if (!empty($command_line))
323 338
 		{
324
-			if (function_exists('debug_print_backtrace'))
325
-				debug_print_backtrace();
339
+			if (function_exists('debug_print_backtrace')) {
340
+							debug_print_backtrace();
341
+			}
326 342
 
327 343
 			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.';
328 344
 			flush();
329 345
 			die();
330 346
 		}
331 347
 
332
-		if (!isset($_GET['xml']))
333
-			template_upgrade_above();
334
-		else
348
+		if (!isset($_GET['xml'])) {
349
+					template_upgrade_above();
350
+		} else
335 351
 		{
336 352
 			header('Content-Type: text/xml; charset=UTF-8');
337 353
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -353,25 +369,29 @@  discard block
 block discarded – undo
353 369
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
354 370
 
355 371
 			// Custom stuff to pass back?
356
-			if (!empty($upcontext['query_string']))
357
-				$upcontext['form_url'] .= $upcontext['query_string'];
372
+			if (!empty($upcontext['query_string'])) {
373
+							$upcontext['form_url'] .= $upcontext['query_string'];
374
+			}
358 375
 
359 376
 			// Call the appropriate subtemplate
360
-			if (is_callable('template_' . $upcontext['sub_template']))
361
-				call_user_func('template_' . $upcontext['sub_template']);
362
-			else
363
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
377
+			if (is_callable('template_' . $upcontext['sub_template'])) {
378
+							call_user_func('template_' . $upcontext['sub_template']);
379
+			} else {
380
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
381
+			}
364 382
 		}
365 383
 
366 384
 		// Was there an error?
367
-		if (!empty($upcontext['forced_error_message']))
368
-			echo $upcontext['forced_error_message'];
385
+		if (!empty($upcontext['forced_error_message'])) {
386
+					echo $upcontext['forced_error_message'];
387
+		}
369 388
 
370 389
 		// Show the footer.
371
-		if (!isset($_GET['xml']))
372
-			template_upgrade_below();
373
-		else
374
-			template_xml_below();
390
+		if (!isset($_GET['xml'])) {
391
+					template_upgrade_below();
392
+		} else {
393
+					template_xml_below();
394
+		}
375 395
 	}
376 396
 
377 397
 
@@ -383,15 +403,19 @@  discard block
 block discarded – undo
383 403
 		$seconds = intval($active % 60);
384 404
 
385 405
 		$totalTime = '';
386
-		if ($hours > 0)
387
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
388
-		if ($minutes > 0)
389
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
390
-		if ($seconds > 0)
391
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
406
+		if ($hours > 0) {
407
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
408
+		}
409
+		if ($minutes > 0) {
410
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
411
+		}
412
+		if ($seconds > 0) {
413
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
414
+		}
392 415
 
393
-		if (!empty($totalTime))
394
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		if (!empty($totalTime)) {
417
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		}
395 419
 	}
396 420
 
397 421
 	// Bang - gone!
@@ -404,8 +428,9 @@  discard block
 block discarded – undo
404 428
 	global $upgradeurl, $upcontext, $command_line;
405 429
 
406 430
 	// Command line users can't be redirected.
407
-	if ($command_line)
408
-		upgradeExit(true);
431
+	if ($command_line) {
432
+			upgradeExit(true);
433
+	}
409 434
 
410 435
 	// Are we providing the core info?
411 436
 	if ($addForm)
@@ -431,12 +456,14 @@  discard block
 block discarded – undo
431 456
 	define('SMF', 1);
432 457
 
433 458
 	// Start the session.
434
-	if (@ini_get('session.save_handler') == 'user')
435
-		@ini_set('session.save_handler', 'files');
459
+	if (@ini_get('session.save_handler') == 'user') {
460
+			@ini_set('session.save_handler', 'files');
461
+	}
436 462
 	@session_start();
437 463
 
438
-	if (empty($smcFunc))
439
-		$smcFunc = array();
464
+	if (empty($smcFunc)) {
465
+			$smcFunc = array();
466
+	}
440 467
 
441 468
 	// We need this for authentication and some upgrade code
442 469
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -448,32 +475,36 @@  discard block
 block discarded – undo
448 475
 	initialize_inputs();
449 476
 
450 477
 	// Get the database going!
451
-	if (empty($db_type) || $db_type == 'mysqli')
452
-		$db_type = 'mysql';
478
+	if (empty($db_type) || $db_type == 'mysqli') {
479
+			$db_type = 'mysql';
480
+	}
453 481
 
454 482
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
455 483
 	{
456 484
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
457 485
 
458 486
 		// Make the connection...
459
-		if (empty($db_connection))
460
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
461
-		else
462
-			// If we've returned here, ping/reconnect to be safe
487
+		if (empty($db_connection)) {
488
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
489
+		} else {
490
+					// If we've returned here, ping/reconnect to be safe
463 491
 			$smcFunc['db_ping']($db_connection);
492
+		}
464 493
 
465 494
 		// Oh dear god!!
466
-		if ($db_connection === null)
467
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		if ($db_connection === null) {
496
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
497
+		}
468 498
 
469
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
470
-			$smcFunc['db_query']('', '
499
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
500
+					$smcFunc['db_query']('', '
471 501
 			SET NAMES {string:db_character_set}',
472 502
 			array(
473 503
 				'db_error_skip' => true,
474 504
 				'db_character_set' => $db_character_set,
475 505
 			)
476 506
 		);
507
+		}
477 508
 
478 509
 		// Load the modSettings data...
479 510
 		$request = $smcFunc['db_query']('', '
@@ -484,11 +515,11 @@  discard block
 block discarded – undo
484 515
 			)
485 516
 		);
486 517
 		$modSettings = array();
487
-		while ($row = $smcFunc['db_fetch_assoc']($request))
488
-			$modSettings[$row['variable']] = $row['value'];
518
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
519
+					$modSettings[$row['variable']] = $row['value'];
520
+		}
489 521
 		$smcFunc['db_free_result']($request);
490
-	}
491
-	else
522
+	} else
492 523
 	{
493 524
 		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.');
494 525
 	}
@@ -502,9 +533,10 @@  discard block
 block discarded – undo
502 533
 		cleanRequest();
503 534
 	}
504 535
 
505
-	if (!isset($_GET['substep']))
506
-		$_GET['substep'] = 0;
507
-}
536
+	if (!isset($_GET['substep'])) {
537
+			$_GET['substep'] = 0;
538
+	}
539
+	}
508 540
 
509 541
 function initialize_inputs()
510 542
 {
@@ -534,8 +566,9 @@  discard block
 block discarded – undo
534 566
 		$dh = opendir(dirname(__FILE__));
535 567
 		while ($file = readdir($dh))
536 568
 		{
537
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
538
-				@unlink(dirname(__FILE__) . '/' . $file);
569
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
570
+							@unlink(dirname(__FILE__) . '/' . $file);
571
+			}
539 572
 		}
540 573
 		closedir($dh);
541 574
 
@@ -564,8 +597,9 @@  discard block
 block discarded – undo
564 597
 	$temp = 'upgrade_php?step';
565 598
 	while (strlen($temp) > 4)
566 599
 	{
567
-		if (isset($_GET[$temp]))
568
-			unset($_GET[$temp]);
600
+		if (isset($_GET[$temp])) {
601
+					unset($_GET[$temp]);
602
+		}
569 603
 		$temp = substr($temp, 1);
570 604
 	}
571 605
 
@@ -592,32 +626,39 @@  discard block
 block discarded – undo
592 626
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
593 627
 
594 628
 	// Need legacy scripts?
595
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
596
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
597
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
598
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
599
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
600
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
629
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
630
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
631
+	}
632
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
633
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
634
+	}
635
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
636
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
637
+	}
601 638
 
602 639
 	// We don't need "-utf8" files anymore...
603 640
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
604 641
 
605 642
 	// This needs to exist!
606
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
607
-		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>]');
608
-	else
609
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
643
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
644
+			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>]');
645
+	} else {
646
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
647
+	}
610 648
 
611
-	if (!$check)
612
-		// 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.
649
+	if (!$check) {
650
+			// 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.
613 651
 		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.');
652
+	}
614 653
 
615 654
 	// Do they meet the install requirements?
616
-	if (!php_version_check())
617
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
655
+	if (!php_version_check()) {
656
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
657
+	}
618 658
 
619
-	if (!db_version_check())
620
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
659
+	if (!db_version_check()) {
660
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
661
+	}
621 662
 
622 663
 	// Do some checks to make sure they have proper privileges
623 664
 	db_extend('packages');
@@ -632,14 +673,16 @@  discard block
 block discarded – undo
632 673
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
633 674
 
634 675
 	// Sorry... we need CREATE, ALTER and DROP
635
-	if (!$create || !$alter || !$drop)
636
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
676
+	if (!$create || !$alter || !$drop) {
677
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
678
+	}
637 679
 
638 680
 	// Do a quick version spot check.
639 681
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
640 682
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
641
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
642
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
683
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
684
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
685
+	}
643 686
 
644 687
 	// What absolutely needs to be writable?
645 688
 	$writable_files = array(
@@ -661,12 +704,13 @@  discard block
 block discarded – undo
661 704
 	quickFileWritable($custom_av_dir);
662 705
 
663 706
 	// Are we good now?
664
-	if (!is_writable($custom_av_dir))
665
-		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));
666
-	elseif ($need_settings_update)
707
+	if (!is_writable($custom_av_dir)) {
708
+			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));
709
+	} elseif ($need_settings_update)
667 710
 	{
668
-		if (!function_exists('cache_put_data'))
669
-			require_once($sourcedir . '/Load.php');
711
+		if (!function_exists('cache_put_data')) {
712
+					require_once($sourcedir . '/Load.php');
713
+		}
670 714
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
671 715
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
672 716
 	}
@@ -675,28 +719,33 @@  discard block
 block discarded – undo
675 719
 
676 720
 	// Check the cache directory.
677 721
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
678
-	if (!file_exists($cachedir_temp))
679
-		@mkdir($cachedir_temp);
680
-	if (!file_exists($cachedir_temp))
681
-		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.');
682
-
683
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
684
-		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>.');
685
-	elseif (!isset($_GET['skiplang']))
722
+	if (!file_exists($cachedir_temp)) {
723
+			@mkdir($cachedir_temp);
724
+	}
725
+	if (!file_exists($cachedir_temp)) {
726
+			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.');
727
+	}
728
+
729
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
730
+			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>.');
731
+	} elseif (!isset($_GET['skiplang']))
686 732
 	{
687 733
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
688 734
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
689 735
 
690
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
691
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
736
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
737
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
738
+		}
692 739
 	}
693 740
 
694
-	if (!makeFilesWritable($writable_files))
695
-		return false;
741
+	if (!makeFilesWritable($writable_files)) {
742
+			return false;
743
+	}
696 744
 
697 745
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
698
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
699
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
746
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
747
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
748
+	}
700 749
 
701 750
 	// Upgrade the agreement.
702 751
 	elseif (isset($modSettings['agreement']))
@@ -707,8 +756,8 @@  discard block
 block discarded – undo
707 756
 	}
708 757
 
709 758
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
710
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
711
-		$upcontext['warning'] = '
759
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
760
+			$upcontext['warning'] = '
712 761
 			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>
713 762
 			<ul>
714 763
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -716,10 +765,12 @@  discard block
 block discarded – undo
716 765
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
717 766
 			</ul>
718 767
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
768
+	}
719 769
 
720 770
 	// Either we're logged in or we're going to present the login.
721
-	if (checkLogin())
722
-		return true;
771
+	if (checkLogin()) {
772
+			return true;
773
+	}
723 774
 
724 775
 	$upcontext += createToken('login');
725 776
 
@@ -733,15 +784,17 @@  discard block
 block discarded – undo
733 784
 	global $smcFunc, $db_type, $support_js;
734 785
 
735 786
 	// Don't bother if the security is disabled.
736
-	if ($disable_security)
737
-		return true;
787
+	if ($disable_security) {
788
+			return true;
789
+	}
738 790
 
739 791
 	// Are we trying to login?
740 792
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
741 793
 	{
742 794
 		// If we've disabled security pick a suitable name!
743
-		if (empty($_POST['user']))
744
-			$_POST['user'] = 'Administrator';
795
+		if (empty($_POST['user'])) {
796
+					$_POST['user'] = 'Administrator';
797
+		}
745 798
 
746 799
 		// Before 2.0 these column names were different!
747 800
 		$oldDB = false;
@@ -756,16 +809,17 @@  discard block
 block discarded – undo
756 809
 					'db_error_skip' => true,
757 810
 				)
758 811
 			);
759
-			if ($smcFunc['db_num_rows']($request) != 0)
760
-				$oldDB = true;
812
+			if ($smcFunc['db_num_rows']($request) != 0) {
813
+							$oldDB = true;
814
+			}
761 815
 			$smcFunc['db_free_result']($request);
762 816
 		}
763 817
 
764 818
 		// Get what we believe to be their details.
765 819
 		if (!$disable_security)
766 820
 		{
767
-			if ($oldDB)
768
-				$request = $smcFunc['db_query']('', '
821
+			if ($oldDB) {
822
+							$request = $smcFunc['db_query']('', '
769 823
 					SELECT id_member, memberName AS member_name, passwd, id_group,
770 824
 					additionalGroups AS additional_groups, lngfile
771 825
 					FROM {db_prefix}members
@@ -775,8 +829,8 @@  discard block
 block discarded – undo
775 829
 						'db_error_skip' => true,
776 830
 					)
777 831
 				);
778
-			else
779
-				$request = $smcFunc['db_query']('', '
832
+			} else {
833
+							$request = $smcFunc['db_query']('', '
780 834
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
781 835
 					FROM {db_prefix}members
782 836
 					WHERE member_name = {string:member_name}',
@@ -785,6 +839,7 @@  discard block
 block discarded – undo
785 839
 						'db_error_skip' => true,
786 840
 					)
787 841
 				);
842
+			}
788 843
 			if ($smcFunc['db_num_rows']($request) != 0)
789 844
 			{
790 845
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -792,16 +847,17 @@  discard block
 block discarded – undo
792 847
 				$groups = explode(',', $addGroups);
793 848
 				$groups[] = $id_group;
794 849
 
795
-				foreach ($groups as $k => $v)
796
-					$groups[$k] = (int) $v;
850
+				foreach ($groups as $k => $v) {
851
+									$groups[$k] = (int) $v;
852
+				}
797 853
 
798 854
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
799 855
 
800 856
 				// We don't use "-utf8" anymore...
801 857
 				$user_language = str_ireplace('-utf8', '', $user_language);
858
+			} else {
859
+							$upcontext['username_incorrect'] = true;
802 860
 			}
803
-			else
804
-				$upcontext['username_incorrect'] = true;
805 861
 			$smcFunc['db_free_result']($request);
806 862
 		}
807 863
 		$upcontext['username'] = $_POST['user'];
@@ -811,13 +867,14 @@  discard block
 block discarded – undo
811 867
 		{
812 868
 			$upcontext['upgrade_status']['js'] = 1;
813 869
 			$support_js = 1;
870
+		} else {
871
+					$support_js = 0;
814 872
 		}
815
-		else
816
-			$support_js = 0;
817 873
 
818 874
 		// Note down the version we are coming from.
819
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
820
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
875
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
876
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
877
+		}
821 878
 
822 879
 		// Didn't get anywhere?
823 880
 		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']))
@@ -851,15 +908,15 @@  discard block
 block discarded – undo
851 908
 							'db_error_skip' => true,
852 909
 						)
853 910
 					);
854
-					if ($smcFunc['db_num_rows']($request) == 0)
855
-						return throw_error('You need to be an admin to perform an upgrade!');
911
+					if ($smcFunc['db_num_rows']($request) == 0) {
912
+											return throw_error('You need to be an admin to perform an upgrade!');
913
+					}
856 914
 					$smcFunc['db_free_result']($request);
857 915
 				}
858 916
 
859 917
 				$upcontext['user']['id'] = $id_member;
860 918
 				$upcontext['user']['name'] = $name;
861
-			}
862
-			else
919
+			} else
863 920
 			{
864 921
 				$upcontext['user']['id'] = 1;
865 922
 				$upcontext['user']['name'] = 'Administrator';
@@ -875,11 +932,11 @@  discard block
 block discarded – undo
875 932
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
876 933
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
877 934
 
878
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
879
-					$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'] . '.';
880
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
881
-					$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'] . '.';
882
-				else
935
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
936
+									$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'] . '.';
937
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
938
+									$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'] . '.';
939
+				} else
883 940
 				{
884 941
 					// Set this as the new language.
885 942
 					$upcontext['language'] = $user_language;
@@ -923,8 +980,9 @@  discard block
 block discarded – undo
923 980
 	unset($member_columns);
924 981
 
925 982
 	// If we've not submitted then we're done.
926
-	if (empty($_POST['upcont']))
927
-		return false;
983
+	if (empty($_POST['upcont'])) {
984
+			return false;
985
+	}
928 986
 
929 987
 	// Firstly, if they're enabling SM stat collection just do it.
930 988
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -944,16 +1002,17 @@  discard block
 block discarded – undo
944 1002
 				fwrite($fp, $out);
945 1003
 
946 1004
 				$return_data = '';
947
-				while (!feof($fp))
948
-					$return_data .= fgets($fp, 128);
1005
+				while (!feof($fp)) {
1006
+									$return_data .= fgets($fp, 128);
1007
+				}
949 1008
 
950 1009
 				fclose($fp);
951 1010
 
952 1011
 				// Get the unique site ID.
953 1012
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
954 1013
 
955
-				if (!empty($ID[1]))
956
-					$smcFunc['db_insert']('replace',
1014
+				if (!empty($ID[1])) {
1015
+									$smcFunc['db_insert']('replace',
957 1016
 						$db_prefix . 'settings',
958 1017
 						array('variable' => 'string', 'value' => 'string'),
959 1018
 						array(
@@ -962,9 +1021,9 @@  discard block
 block discarded – undo
962 1021
 						),
963 1022
 						array('variable')
964 1023
 					);
1024
+				}
965 1025
 			}
966
-		}
967
-		else
1026
+		} else
968 1027
 		{
969 1028
 			$smcFunc['db_insert']('replace',
970 1029
 				$db_prefix . 'settings',
@@ -975,8 +1034,8 @@  discard block
 block discarded – undo
975 1034
 		}
976 1035
 	}
977 1036
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
978
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
979
-		$smcFunc['db_query']('', '
1037
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1038
+			$smcFunc['db_query']('', '
980 1039
 			DELETE FROM {db_prefix}settings
981 1040
 			WHERE variable = {string:enable_sm_stats}',
982 1041
 			array(
@@ -984,6 +1043,7 @@  discard block
 block discarded – undo
984 1043
 				'db_error_skip' => true,
985 1044
 			)
986 1045
 		);
1046
+	}
987 1047
 
988 1048
 	// Deleting old karma stuff?
989 1049
 	if (!empty($_POST['delete_karma']))
@@ -998,20 +1058,22 @@  discard block
 block discarded – undo
998 1058
 		);
999 1059
 
1000 1060
 		// Cleaning up old karma member settings.
1001
-		if ($upcontext['karma_installed']['good'])
1002
-			$smcFunc['db_query']('', '
1061
+		if ($upcontext['karma_installed']['good']) {
1062
+					$smcFunc['db_query']('', '
1003 1063
 				ALTER TABLE {db_prefix}members
1004 1064
 				DROP karma_good',
1005 1065
 				array()
1006 1066
 			);
1067
+		}
1007 1068
 
1008 1069
 		// Does karma bad was enable?
1009
-		if ($upcontext['karma_installed']['bad'])
1010
-			$smcFunc['db_query']('', '
1070
+		if ($upcontext['karma_installed']['bad']) {
1071
+					$smcFunc['db_query']('', '
1011 1072
 				ALTER TABLE {db_prefix}members
1012 1073
 				DROP karma_bad',
1013 1074
 				array()
1014 1075
 			);
1076
+		}
1015 1077
 
1016 1078
 		// Cleaning up old karma permissions.
1017 1079
 		$smcFunc['db_query']('', '
@@ -1024,26 +1086,29 @@  discard block
 block discarded – undo
1024 1086
 	}
1025 1087
 
1026 1088
 	// Emptying the error log?
1027
-	if (!empty($_POST['empty_error']))
1028
-		$smcFunc['db_query']('truncate_table', '
1089
+	if (!empty($_POST['empty_error'])) {
1090
+			$smcFunc['db_query']('truncate_table', '
1029 1091
 			TRUNCATE {db_prefix}log_errors',
1030 1092
 			array(
1031 1093
 			)
1032 1094
 		);
1095
+	}
1033 1096
 
1034 1097
 	$changes = array();
1035 1098
 
1036 1099
 	// Add proxy settings.
1037
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1038
-		$changes += array(
1100
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1101
+			$changes += array(
1039 1102
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1040 1103
 			'image_proxy_maxsize' => 5190,
1041 1104
 			'image_proxy_enabled' => 0,
1042 1105
 		);
1106
+	}
1043 1107
 
1044 1108
 	// If we're overriding the language follow it through.
1045
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1046
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1109
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1110
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1111
+	}
1047 1112
 
1048 1113
 	if (!empty($_POST['maint']))
1049 1114
 	{
@@ -1055,30 +1120,34 @@  discard block
 block discarded – undo
1055 1120
 		{
1056 1121
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1057 1122
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1058
-		}
1059
-		else
1123
+		} else
1060 1124
 		{
1061 1125
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1062 1126
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1063 1127
 		}
1064 1128
 	}
1065 1129
 
1066
-	if ($command_line)
1067
-		echo ' * Updating Settings.php...';
1130
+	if ($command_line) {
1131
+			echo ' * Updating Settings.php...';
1132
+	}
1068 1133
 
1069 1134
 	// Fix some old paths.
1070
-	if (substr($boarddir, 0, 1) == '.')
1071
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1135
+	if (substr($boarddir, 0, 1) == '.') {
1136
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1137
+	}
1072 1138
 
1073
-	if (substr($sourcedir, 0, 1) == '.')
1074
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1139
+	if (substr($sourcedir, 0, 1) == '.') {
1140
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1141
+	}
1075 1142
 
1076
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1077
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1143
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1144
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1145
+	}
1078 1146
 
1079 1147
 	// Not had the database type added before?
1080
-	if (empty($db_type))
1081
-		$changes['db_type'] = 'mysql';
1148
+	if (empty($db_type)) {
1149
+			$changes['db_type'] = 'mysql';
1150
+	}
1082 1151
 
1083 1152
 	// If they have a "host:port" setup for the host, split that into separate values
1084 1153
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1089,32 +1158,36 @@  discard block
 block discarded – undo
1089 1158
 		$changes['db_server'] = '\'' . $db_server . '\'';
1090 1159
 
1091 1160
 		// Only set this if we're not using the default port
1092
-		if ($db_port != ini_get('mysqli.default_port'))
1093
-			$changes['db_port'] = (int) $db_port;
1094
-	}
1095
-	elseif (!empty($db_port))
1161
+		if ($db_port != ini_get('mysqli.default_port')) {
1162
+					$changes['db_port'] = (int) $db_port;
1163
+		}
1164
+	} elseif (!empty($db_port))
1096 1165
 	{
1097 1166
 		// If db_port is set and is the same as the default, set it to ''
1098 1167
 		if ($db_type == 'mysql')
1099 1168
 		{
1100
-			if ($db_port == ini_get('mysqli.default_port'))
1101
-				$changes['db_port'] = '\'\'';
1102
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1103
-				$changes['db_port'] = '\'\'';
1169
+			if ($db_port == ini_get('mysqli.default_port')) {
1170
+							$changes['db_port'] = '\'\'';
1171
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1172
+							$changes['db_port'] = '\'\'';
1173
+			}
1104 1174
 		}
1105 1175
 	}
1106 1176
 
1107 1177
 	// Maybe we haven't had this option yet?
1108
-	if (empty($packagesdir))
1109
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1178
+	if (empty($packagesdir)) {
1179
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1180
+	}
1110 1181
 
1111 1182
 	// Add support for $tasksdir var.
1112
-	if (empty($tasksdir))
1113
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1183
+	if (empty($tasksdir)) {
1184
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1185
+	}
1114 1186
 
1115 1187
 	// Make sure we fix the language as well.
1116
-	if (stristr($language, '-utf8'))
1117
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1188
+	if (stristr($language, '-utf8')) {
1189
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1190
+	}
1118 1191
 
1119 1192
 	// @todo Maybe change the cookie name if going to 1.1, too?
1120 1193
 
@@ -1122,8 +1195,9 @@  discard block
 block discarded – undo
1122 1195
 	require_once($sourcedir . '/Subs-Admin.php');
1123 1196
 	updateSettingsFile($changes);
1124 1197
 
1125
-	if ($command_line)
1126
-		echo ' Successful.' . "\n";
1198
+	if ($command_line) {
1199
+			echo ' Successful.' . "\n";
1200
+	}
1127 1201
 
1128 1202
 	// Are we doing debug?
1129 1203
 	if (isset($_POST['debug']))
@@ -1133,8 +1207,9 @@  discard block
 block discarded – undo
1133 1207
 	}
1134 1208
 
1135 1209
 	// If we're not backing up then jump one.
1136
-	if (empty($_POST['backup']))
1137
-		$upcontext['current_step']++;
1210
+	if (empty($_POST['backup'])) {
1211
+			$upcontext['current_step']++;
1212
+	}
1138 1213
 
1139 1214
 	// If we've got here then let's proceed to the next step!
1140 1215
 	return true;
@@ -1149,8 +1224,9 @@  discard block
 block discarded – undo
1149 1224
 	$upcontext['page_title'] = 'Backup Database';
1150 1225
 
1151 1226
 	// Done it already - js wise?
1152
-	if (!empty($_POST['backup_done']))
1153
-		return true;
1227
+	if (!empty($_POST['backup_done'])) {
1228
+			return true;
1229
+	}
1154 1230
 
1155 1231
 	// Some useful stuff here.
1156 1232
 	db_extend();
@@ -1164,9 +1240,10 @@  discard block
 block discarded – undo
1164 1240
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1165 1241
 
1166 1242
 	$table_names = array();
1167
-	foreach ($tables as $table)
1168
-		if (substr($table, 0, 7) !== 'backup_')
1243
+	foreach ($tables as $table) {
1244
+			if (substr($table, 0, 7) !== 'backup_')
1169 1245
 			$table_names[] = $table;
1246
+	}
1170 1247
 
1171 1248
 	$upcontext['table_count'] = count($table_names);
1172 1249
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1176,12 +1253,14 @@  discard block
 block discarded – undo
1176 1253
 	$file_steps = $upcontext['table_count'];
1177 1254
 
1178 1255
 	// What ones have we already done?
1179
-	foreach ($table_names as $id => $table)
1180
-		if ($id < $_GET['substep'])
1256
+	foreach ($table_names as $id => $table) {
1257
+			if ($id < $_GET['substep'])
1181 1258
 			$upcontext['previous_tables'][] = $table;
1259
+	}
1182 1260
 
1183
-	if ($command_line)
1184
-		echo 'Backing Up Tables.';
1261
+	if ($command_line) {
1262
+			echo 'Backing Up Tables.';
1263
+	}
1185 1264
 
1186 1265
 	// If we don't support javascript we backup here.
1187 1266
 	if (!$support_js || isset($_GET['xml']))
@@ -1200,8 +1279,9 @@  discard block
 block discarded – undo
1200 1279
 			backupTable($table_names[$substep]);
1201 1280
 
1202 1281
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1203
-			if (isset($_GET['xml']))
1204
-				return upgradeExit();
1282
+			if (isset($_GET['xml'])) {
1283
+							return upgradeExit();
1284
+			}
1205 1285
 		}
1206 1286
 
1207 1287
 		if ($command_line)
@@ -1234,9 +1314,10 @@  discard block
 block discarded – undo
1234 1314
 
1235 1315
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1236 1316
 
1237
-	if ($command_line)
1238
-		echo ' done.';
1239
-}
1317
+	if ($command_line) {
1318
+			echo ' done.';
1319
+	}
1320
+	}
1240 1321
 
1241 1322
 // Step 2: Everything.
1242 1323
 function DatabaseChanges()
@@ -1245,8 +1326,9 @@  discard block
 block discarded – undo
1245 1326
 	global $upcontext, $support_js, $db_type;
1246 1327
 
1247 1328
 	// Have we just completed this?
1248
-	if (!empty($_POST['database_done']))
1249
-		return true;
1329
+	if (!empty($_POST['database_done'])) {
1330
+			return true;
1331
+	}
1250 1332
 
1251 1333
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1252 1334
 	$upcontext['page_title'] = 'Database Changes';
@@ -1261,15 +1343,16 @@  discard block
 block discarded – undo
1261 1343
 	);
1262 1344
 
1263 1345
 	// How many files are there in total?
1264
-	if (isset($_GET['filecount']))
1265
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1266
-	else
1346
+	if (isset($_GET['filecount'])) {
1347
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1348
+	} else
1267 1349
 	{
1268 1350
 		$upcontext['file_count'] = 0;
1269 1351
 		foreach ($files as $file)
1270 1352
 		{
1271
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1272
-				$upcontext['file_count']++;
1353
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1354
+							$upcontext['file_count']++;
1355
+			}
1273 1356
 		}
1274 1357
 	}
1275 1358
 
@@ -1279,9 +1362,9 @@  discard block
 block discarded – undo
1279 1362
 	$upcontext['cur_file_num'] = 0;
1280 1363
 	foreach ($files as $file)
1281 1364
 	{
1282
-		if ($did_not_do)
1283
-			$did_not_do--;
1284
-		else
1365
+		if ($did_not_do) {
1366
+					$did_not_do--;
1367
+		} else
1285 1368
 		{
1286 1369
 			$upcontext['cur_file_num']++;
1287 1370
 			$upcontext['cur_file_name'] = $file[0];
@@ -1308,12 +1391,13 @@  discard block
 block discarded – undo
1308 1391
 					// Flag to move on to the next.
1309 1392
 					$upcontext['completed_step'] = true;
1310 1393
 					// Did we complete the whole file?
1311
-					if ($nextFile)
1312
-						$upcontext['current_debug_item_num'] = -1;
1394
+					if ($nextFile) {
1395
+											$upcontext['current_debug_item_num'] = -1;
1396
+					}
1313 1397
 					return upgradeExit();
1398
+				} elseif ($support_js) {
1399
+									break;
1314 1400
 				}
1315
-				elseif ($support_js)
1316
-					break;
1317 1401
 			}
1318 1402
 			// Set the progress bar to be right as if we had - even if we hadn't...
1319 1403
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1338,8 +1422,9 @@  discard block
 block discarded – undo
1338 1422
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1339 1423
 
1340 1424
 	// Now it's nice to have some of the basic SMF source files.
1341
-	if (!isset($_GET['ssi']) && !$command_line)
1342
-		redirectLocation('&ssi=1');
1425
+	if (!isset($_GET['ssi']) && !$command_line) {
1426
+			redirectLocation('&ssi=1');
1427
+	}
1343 1428
 
1344 1429
 	$upcontext['sub_template'] = 'upgrade_complete';
1345 1430
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1355,14 +1440,16 @@  discard block
 block discarded – undo
1355 1440
 	// Are we in maintenance mode?
1356 1441
 	if (isset($upcontext['user']['main']))
1357 1442
 	{
1358
-		if ($command_line)
1359
-			echo ' * ';
1443
+		if ($command_line) {
1444
+					echo ' * ';
1445
+		}
1360 1446
 		$upcontext['removed_maintenance'] = true;
1361 1447
 		$changes['maintenance'] = $upcontext['user']['main'];
1362 1448
 	}
1363 1449
 	// Otherwise if somehow we are in 2 let's go to 1.
1364
-	elseif (!empty($maintenance) && $maintenance == 2)
1365
-		$changes['maintenance'] = 1;
1450
+	elseif (!empty($maintenance) && $maintenance == 2) {
1451
+			$changes['maintenance'] = 1;
1452
+	}
1366 1453
 
1367 1454
 	// Wipe this out...
1368 1455
 	$upcontext['user'] = array();
@@ -1377,9 +1464,9 @@  discard block
 block discarded – undo
1377 1464
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1378 1465
 
1379 1466
 	// Now is the perfect time to fetch the SM files.
1380
-	if ($command_line)
1381
-		cli_scheduled_fetchSMfiles();
1382
-	else
1467
+	if ($command_line) {
1468
+			cli_scheduled_fetchSMfiles();
1469
+	} else
1383 1470
 	{
1384 1471
 		require_once($sourcedir . '/ScheduledTasks.php');
1385 1472
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1387,8 +1474,9 @@  discard block
 block discarded – undo
1387 1474
 	}
1388 1475
 
1389 1476
 	// Log what we've done.
1390
-	if (empty($user_info['id']))
1391
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1477
+	if (empty($user_info['id'])) {
1478
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1479
+	}
1392 1480
 
1393 1481
 	// Log the action manually, so CLI still works.
1394 1482
 	$smcFunc['db_insert']('',
@@ -1407,8 +1495,9 @@  discard block
 block discarded – undo
1407 1495
 
1408 1496
 	// Save the current database version.
1409 1497
 	$server_version = $smcFunc['db_server_info']();
1410
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1411
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1498
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1499
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1500
+	}
1412 1501
 
1413 1502
 	if ($command_line)
1414 1503
 	{
@@ -1420,8 +1509,9 @@  discard block
 block discarded – undo
1420 1509
 
1421 1510
 	// Make sure it says we're done.
1422 1511
 	$upcontext['overall_percent'] = 100;
1423
-	if (isset($upcontext['step_progress']))
1424
-		unset($upcontext['step_progress']);
1512
+	if (isset($upcontext['step_progress'])) {
1513
+			unset($upcontext['step_progress']);
1514
+	}
1425 1515
 
1426 1516
 	$_GET['substep'] = 0;
1427 1517
 	return false;
@@ -1432,8 +1522,9 @@  discard block
 block discarded – undo
1432 1522
 {
1433 1523
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1434 1524
 
1435
-	if (empty($modSettings['time_format']))
1436
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1525
+	if (empty($modSettings['time_format'])) {
1526
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1527
+	}
1437 1528
 
1438 1529
 	// What files do we want to get
1439 1530
 	$request = $smcFunc['db_query']('', '
@@ -1467,8 +1558,9 @@  discard block
 block discarded – undo
1467 1558
 		$file_data = fetch_web_data($url);
1468 1559
 
1469 1560
 		// If we got an error - give up - the site might be down.
1470
-		if ($file_data === false)
1471
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1561
+		if ($file_data === false) {
1562
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1563
+		}
1472 1564
 
1473 1565
 		// Save the file to the database.
1474 1566
 		$smcFunc['db_query']('substring', '
@@ -1510,8 +1602,9 @@  discard block
 block discarded – undo
1510 1602
 	$themeData = array();
1511 1603
 	foreach ($values as $variable => $value)
1512 1604
 	{
1513
-		if (!isset($value) || $value === null)
1514
-			$value = 0;
1605
+		if (!isset($value) || $value === null) {
1606
+					$value = 0;
1607
+		}
1515 1608
 
1516 1609
 		$themeData[] = array(0, 1, $variable, $value);
1517 1610
 	}
@@ -1540,8 +1633,9 @@  discard block
 block discarded – undo
1540 1633
 
1541 1634
 	foreach ($values as $variable => $value)
1542 1635
 	{
1543
-		if (empty($modSettings[$value[0]]))
1544
-			continue;
1636
+		if (empty($modSettings[$value[0]])) {
1637
+					continue;
1638
+		}
1545 1639
 
1546 1640
 		$smcFunc['db_query']('', '
1547 1641
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1627,19 +1721,21 @@  discard block
 block discarded – undo
1627 1721
 	set_error_handler(
1628 1722
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1629 1723
 		{
1630
-			if ($support_js)
1631
-				return true;
1632
-			else
1633
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1724
+			if ($support_js) {
1725
+							return true;
1726
+			} else {
1727
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1728
+			}
1634 1729
 		}
1635 1730
 	);
1636 1731
 
1637 1732
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1638 1733
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1639
-	if ($db_type == 'mysql')
1640
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1641
-	else
1642
-		$db_collation = '';
1734
+	if ($db_type == 'mysql') {
1735
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1736
+	} else {
1737
+			$db_collation = '';
1738
+	}
1643 1739
 
1644 1740
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1645 1741
 
@@ -1651,8 +1747,9 @@  discard block
 block discarded – undo
1651 1747
 	$last_step = '';
1652 1748
 
1653 1749
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1654
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1655
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1750
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1751
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1752
+	}
1656 1753
 
1657 1754
 	// Count the total number of steps within this file - for progress.
1658 1755
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1672,15 +1769,18 @@  discard block
 block discarded – undo
1672 1769
 		$do_current = $substep >= $_GET['substep'];
1673 1770
 
1674 1771
 		// Get rid of any comments in the beginning of the line...
1675
-		if (substr(trim($line), 0, 2) === '/*')
1676
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1772
+		if (substr(trim($line), 0, 2) === '/*') {
1773
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1774
+		}
1677 1775
 
1678 1776
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1679
-		if ($is_debug && !$support_js && $command_line)
1680
-			flush();
1777
+		if ($is_debug && !$support_js && $command_line) {
1778
+					flush();
1779
+		}
1681 1780
 
1682
-		if (trim($line) === '')
1683
-			continue;
1781
+		if (trim($line) === '') {
1782
+					continue;
1783
+		}
1684 1784
 
1685 1785
 		if (trim(substr($line, 0, 3)) === '---')
1686 1786
 		{
@@ -1690,8 +1790,9 @@  discard block
 block discarded – undo
1690 1790
 			if (trim($current_data) != '' && $type !== '}')
1691 1791
 			{
1692 1792
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1693
-				if ($command_line)
1694
-					echo $upcontext['error_message'];
1793
+				if ($command_line) {
1794
+									echo $upcontext['error_message'];
1795
+				}
1695 1796
 			}
1696 1797
 
1697 1798
 			if ($type == ' ')
@@ -1709,17 +1810,18 @@  discard block
 block discarded – undo
1709 1810
 				if ($do_current)
1710 1811
 				{
1711 1812
 					$upcontext['actioned_items'][] = $last_step;
1712
-					if ($command_line)
1713
-						echo ' * ';
1813
+					if ($command_line) {
1814
+											echo ' * ';
1815
+					}
1714 1816
 				}
1715
-			}
1716
-			elseif ($type == '#')
1817
+			} elseif ($type == '#')
1717 1818
 			{
1718 1819
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1719 1820
 
1720 1821
 				$upcontext['current_debug_item_num']++;
1721
-				if (trim($line) != '---#')
1722
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1822
+				if (trim($line) != '---#') {
1823
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1824
+				}
1723 1825
 
1724 1826
 				// Have we already done something?
1725 1827
 				if (isset($_GET['xml']) && $done_something)
@@ -1730,34 +1832,36 @@  discard block
 block discarded – undo
1730 1832
 
1731 1833
 				if ($do_current)
1732 1834
 				{
1733
-					if (trim($line) == '---#' && $command_line)
1734
-						echo ' done.', $endl;
1735
-					elseif ($command_line)
1736
-						echo ' +++ ', rtrim(substr($line, 4));
1737
-					elseif (trim($line) != '---#')
1835
+					if (trim($line) == '---#' && $command_line) {
1836
+											echo ' done.', $endl;
1837
+					} elseif ($command_line) {
1838
+											echo ' +++ ', rtrim(substr($line, 4));
1839
+					} elseif (trim($line) != '---#')
1738 1840
 					{
1739
-						if ($is_debug)
1740
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1841
+						if ($is_debug) {
1842
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1843
+						}
1741 1844
 					}
1742 1845
 				}
1743 1846
 
1744 1847
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1745 1848
 				{
1746
-					if ($command_line)
1747
-						echo ' * ';
1748
-					else
1749
-						$upcontext['actioned_items'][] = $last_step;
1849
+					if ($command_line) {
1850
+											echo ' * ';
1851
+					} else {
1852
+											$upcontext['actioned_items'][] = $last_step;
1853
+					}
1750 1854
 				}
1751 1855
 
1752 1856
 				// Small step - only if we're actually doing stuff.
1753
-				if ($do_current)
1754
-					nextSubstep(++$substep);
1755
-				else
1756
-					$substep++;
1757
-			}
1758
-			elseif ($type == '{')
1759
-				$current_type = 'code';
1760
-			elseif ($type == '}')
1857
+				if ($do_current) {
1858
+									nextSubstep(++$substep);
1859
+				} else {
1860
+									$substep++;
1861
+				}
1862
+			} elseif ($type == '{') {
1863
+							$current_type = 'code';
1864
+			} elseif ($type == '}')
1761 1865
 			{
1762 1866
 				$current_type = 'sql';
1763 1867
 
@@ -1770,8 +1874,9 @@  discard block
 block discarded – undo
1770 1874
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1771 1875
 				{
1772 1876
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1773
-					if ($command_line)
1774
-						echo $upcontext['error_message'];
1877
+					if ($command_line) {
1878
+											echo $upcontext['error_message'];
1879
+					}
1775 1880
 				}
1776 1881
 
1777 1882
 				// Done with code!
@@ -1851,8 +1956,9 @@  discard block
 block discarded – undo
1851 1956
 	$db_unbuffered = false;
1852 1957
 
1853 1958
 	// Failure?!
1854
-	if ($result !== false)
1855
-		return $result;
1959
+	if ($result !== false) {
1960
+			return $result;
1961
+	}
1856 1962
 
1857 1963
 	$db_error_message = $smcFunc['db_error']($db_connection);
1858 1964
 	// If MySQL we do something more clever.
@@ -1880,54 +1986,61 @@  discard block
 block discarded – undo
1880 1986
 			{
1881 1987
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1882 1988
 				$result = mysqli_query($db_connection, $string);
1883
-				if ($result !== false)
1884
-					return $result;
1989
+				if ($result !== false) {
1990
+									return $result;
1991
+				}
1885 1992
 			}
1886
-		}
1887
-		elseif ($mysqli_errno == 2013)
1993
+		} elseif ($mysqli_errno == 2013)
1888 1994
 		{
1889 1995
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1890 1996
 			mysqli_select_db($db_connection, $db_name);
1891 1997
 			if ($db_connection)
1892 1998
 			{
1893 1999
 				$result = mysqli_query($db_connection, $string);
1894
-				if ($result !== false)
1895
-					return $result;
2000
+				if ($result !== false) {
2001
+									return $result;
2002
+				}
1896 2003
 			}
1897 2004
 		}
1898 2005
 		// Duplicate column name... should be okay ;).
1899
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1900
-			return false;
2006
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2007
+					return false;
2008
+		}
1901 2009
 		// Duplicate insert... make sure it's the proper type of query ;).
1902
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1903
-			return false;
2010
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2011
+					return false;
2012
+		}
1904 2013
 		// Creating an index on a non-existent column.
1905
-		elseif ($mysqli_errno == 1072)
1906
-			return false;
1907
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1908
-			return false;
2014
+		elseif ($mysqli_errno == 1072) {
2015
+					return false;
2016
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2017
+					return false;
2018
+		}
1909 2019
 	}
1910 2020
 	// If a table already exists don't go potty.
1911 2021
 	else
1912 2022
 	{
1913 2023
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1914 2024
 		{
1915
-			if (strpos($db_error_message, 'exist') !== false)
1916
-				return true;
1917
-		}
1918
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2025
+			if (strpos($db_error_message, 'exist') !== false) {
2026
+							return true;
2027
+			}
2028
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1919 2029
 		{
1920
-			if (strpos($db_error_message, 'duplicate') !== false)
1921
-				return true;
2030
+			if (strpos($db_error_message, 'duplicate') !== false) {
2031
+							return true;
2032
+			}
1922 2033
 		}
1923 2034
 	}
1924 2035
 
1925 2036
 	// Get the query string so we pass everything.
1926 2037
 	$query_string = '';
1927
-	foreach ($_GET as $k => $v)
1928
-		$query_string .= ';' . $k . '=' . $v;
1929
-	if (strlen($query_string) != 0)
1930
-		$query_string = '?' . substr($query_string, 1);
2038
+	foreach ($_GET as $k => $v) {
2039
+			$query_string .= ';' . $k . '=' . $v;
2040
+	}
2041
+	if (strlen($query_string) != 0) {
2042
+			$query_string = '?' . substr($query_string, 1);
2043
+	}
1931 2044
 
1932 2045
 	if ($command_line)
1933 2046
 	{
@@ -1982,16 +2095,18 @@  discard block
 block discarded – undo
1982 2095
 			{
1983 2096
 				$found |= 1;
1984 2097
 				// Do some checks on the data if we have it set.
1985
-				if (isset($change['col_type']))
1986
-					$found &= $change['col_type'] === $column['type'];
1987
-				if (isset($change['null_allowed']))
1988
-					$found &= $column['null'] == $change['null_allowed'];
1989
-				if (isset($change['default']))
1990
-					$found &= $change['default'] === $column['default'];
2098
+				if (isset($change['col_type'])) {
2099
+									$found &= $change['col_type'] === $column['type'];
2100
+				}
2101
+				if (isset($change['null_allowed'])) {
2102
+									$found &= $column['null'] == $change['null_allowed'];
2103
+				}
2104
+				if (isset($change['default'])) {
2105
+									$found &= $change['default'] === $column['default'];
2106
+				}
1991 2107
 			}
1992 2108
 		}
1993
-	}
1994
-	elseif ($change['type'] === 'index')
2109
+	} elseif ($change['type'] === 'index')
1995 2110
 	{
1996 2111
 		$request = upgrade_query('
1997 2112
 			SHOW INDEX
@@ -2000,9 +2115,10 @@  discard block
 block discarded – undo
2000 2115
 		{
2001 2116
 			$cur_index = array();
2002 2117
 
2003
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2004
-				if ($row['Key_name'] === $change['name'])
2118
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2119
+							if ($row['Key_name'] === $change['name'])
2005 2120
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2121
+			}
2006 2122
 
2007 2123
 			ksort($cur_index, SORT_NUMERIC);
2008 2124
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2012,14 +2128,17 @@  discard block
 block discarded – undo
2012 2128
 	}
2013 2129
 
2014 2130
 	// If we're trying to add and it's added, we're done.
2015
-	if ($found && in_array($change['method'], array('add', 'change')))
2016
-		return true;
2131
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2132
+			return true;
2133
+	}
2017 2134
 	// Otherwise if we're removing and it wasn't found we're also done.
2018
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2019
-		return true;
2135
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2136
+			return true;
2137
+	}
2020 2138
 	// Otherwise is it just a test?
2021
-	elseif ($is_test)
2022
-		return false;
2139
+	elseif ($is_test) {
2140
+			return false;
2141
+	}
2023 2142
 
2024 2143
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2025 2144
 	$running = false;
@@ -2030,8 +2149,9 @@  discard block
 block discarded – undo
2030 2149
 			SHOW FULL PROCESSLIST');
2031 2150
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2032 2151
 		{
2033
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2034
-				$found = true;
2152
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2153
+							$found = true;
2154
+			}
2035 2155
 		}
2036 2156
 
2037 2157
 		// Can't find it? Then we need to run it fools!
@@ -2043,8 +2163,9 @@  discard block
 block discarded – undo
2043 2163
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2044 2164
 				' . $change['text'], true) !== false;
2045 2165
 
2046
-			if (!$success)
2047
-				return false;
2166
+			if (!$success) {
2167
+							return false;
2168
+			}
2048 2169
 
2049 2170
 			// Return
2050 2171
 			$running = true;
@@ -2086,8 +2207,9 @@  discard block
 block discarded – undo
2086 2207
 			'db_error_skip' => true,
2087 2208
 		)
2088 2209
 	);
2089
-	if ($smcFunc['db_num_rows']($request) === 0)
2090
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2210
+	if ($smcFunc['db_num_rows']($request) === 0) {
2211
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2212
+	}
2091 2213
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2092 2214
 	$smcFunc['db_free_result']($request);
2093 2215
 
@@ -2109,18 +2231,19 @@  discard block
 block discarded – undo
2109 2231
 			)
2110 2232
 		);
2111 2233
 		// No results? Just forget it all together.
2112
-		if ($smcFunc['db_num_rows']($request) === 0)
2113
-			unset($table_row['Collation']);
2114
-		else
2115
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2234
+		if ($smcFunc['db_num_rows']($request) === 0) {
2235
+					unset($table_row['Collation']);
2236
+		} else {
2237
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2238
+		}
2116 2239
 		$smcFunc['db_free_result']($request);
2117 2240
 	}
2118 2241
 
2119 2242
 	if ($column_fix)
2120 2243
 	{
2121 2244
 		// Make sure there are no NULL's left.
2122
-		if ($null_fix)
2123
-			$smcFunc['db_query']('', '
2245
+		if ($null_fix) {
2246
+					$smcFunc['db_query']('', '
2124 2247
 				UPDATE {db_prefix}' . $change['table'] . '
2125 2248
 				SET ' . $change['column'] . ' = {string:default}
2126 2249
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2129,6 +2252,7 @@  discard block
 block discarded – undo
2129 2252
 					'db_error_skip' => true,
2130 2253
 				)
2131 2254
 			);
2255
+		}
2132 2256
 
2133 2257
 		// Do the actual alteration.
2134 2258
 		$smcFunc['db_query']('', '
@@ -2157,8 +2281,9 @@  discard block
 block discarded – undo
2157 2281
 	}
2158 2282
 
2159 2283
 	// Not a column we need to check on?
2160
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2161
-		return;
2284
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2285
+			return;
2286
+	}
2162 2287
 
2163 2288
 	// Break it up you (six|seven).
2164 2289
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2177,13 +2302,13 @@  discard block
 block discarded – undo
2177 2302
 				'new_name' => $temp[2],
2178 2303
 		));
2179 2304
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2180
-		if ($smcFunc['db_num_rows'] != 1)
2181
-			return;
2305
+		if ($smcFunc['db_num_rows'] != 1) {
2306
+					return;
2307
+		}
2182 2308
 
2183 2309
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2184 2310
 		$smcFunc['db_free_result']($request);
2185
-	}
2186
-	else
2311
+	} else
2187 2312
 	{
2188 2313
 		// Do this the old fashion, sure method way.
2189 2314
 		$request = $smcFunc['db_query']('', '
@@ -2194,21 +2319,24 @@  discard block
 block discarded – undo
2194 2319
 		));
2195 2320
 		// Mayday!
2196 2321
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2197
-		if ($smcFunc['db_num_rows'] == 0)
2198
-			return;
2322
+		if ($smcFunc['db_num_rows'] == 0) {
2323
+					return;
2324
+		}
2199 2325
 
2200 2326
 		// Oh where, oh where has my little field gone. Oh where can it be...
2201
-		while ($row = $smcFunc['db_query']($request))
2202
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2327
+		while ($row = $smcFunc['db_query']($request)) {
2328
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2203 2329
 			{
2204 2330
 				$current_type = $row['Type'];
2331
+		}
2205 2332
 				break;
2206 2333
 			}
2207 2334
 	}
2208 2335
 
2209 2336
 	// If this doesn't match, the column may of been altered for a reason.
2210
-	if (trim($current_type) != trim($temp[3]))
2211
-		$temp[3] = $current_type;
2337
+	if (trim($current_type) != trim($temp[3])) {
2338
+			$temp[3] = $current_type;
2339
+	}
2212 2340
 
2213 2341
 	// Piece this back together.
2214 2342
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2220,8 +2348,9 @@  discard block
 block discarded – undo
2220 2348
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2221 2349
 	global $step_progress, $is_debug, $upcontext;
2222 2350
 
2223
-	if ($_GET['substep'] < $substep)
2224
-		$_GET['substep'] = $substep;
2351
+	if ($_GET['substep'] < $substep) {
2352
+			$_GET['substep'] = $substep;
2353
+	}
2225 2354
 
2226 2355
 	if ($command_line)
2227 2356
 	{
@@ -2234,29 +2363,33 @@  discard block
 block discarded – undo
2234 2363
 	}
2235 2364
 
2236 2365
 	@set_time_limit(300);
2237
-	if (function_exists('apache_reset_timeout'))
2238
-		@apache_reset_timeout();
2366
+	if (function_exists('apache_reset_timeout')) {
2367
+			@apache_reset_timeout();
2368
+	}
2239 2369
 
2240
-	if (time() - $start_time <= $timeLimitThreshold)
2241
-		return;
2370
+	if (time() - $start_time <= $timeLimitThreshold) {
2371
+			return;
2372
+	}
2242 2373
 
2243 2374
 	// Do we have some custom step progress stuff?
2244 2375
 	if (!empty($step_progress))
2245 2376
 	{
2246 2377
 		$upcontext['substep_progress'] = 0;
2247 2378
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2248
-		if ($step_progress['current'] > $step_progress['total'])
2249
-			$upcontext['substep_progress'] = 99.9;
2250
-		else
2251
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2379
+		if ($step_progress['current'] > $step_progress['total']) {
2380
+					$upcontext['substep_progress'] = 99.9;
2381
+		} else {
2382
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2383
+		}
2252 2384
 
2253 2385
 		// Make it nicely rounded.
2254 2386
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2255 2387
 	}
2256 2388
 
2257 2389
 	// If this is XML we just exit right away!
2258
-	if (isset($_GET['xml']))
2259
-		return upgradeExit();
2390
+	if (isset($_GET['xml'])) {
2391
+			return upgradeExit();
2392
+	}
2260 2393
 
2261 2394
 	// We're going to pause after this!
2262 2395
 	$upcontext['pause'] = true;
@@ -2264,13 +2397,15 @@  discard block
 block discarded – undo
2264 2397
 	$upcontext['query_string'] = '';
2265 2398
 	foreach ($_GET as $k => $v)
2266 2399
 	{
2267
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2268
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2400
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2401
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2402
+		}
2269 2403
 	}
2270 2404
 
2271 2405
 	// Custom warning?
2272
-	if (!empty($custom_warning))
2273
-		$upcontext['custom_warning'] = $custom_warning;
2406
+	if (!empty($custom_warning)) {
2407
+			$upcontext['custom_warning'] = $custom_warning;
2408
+	}
2274 2409
 
2275 2410
 	upgradeExit();
2276 2411
 }
@@ -2285,25 +2420,26 @@  discard block
 block discarded – undo
2285 2420
 	ob_implicit_flush(true);
2286 2421
 	@set_time_limit(600);
2287 2422
 
2288
-	if (!isset($_SERVER['argv']))
2289
-		$_SERVER['argv'] = array();
2423
+	if (!isset($_SERVER['argv'])) {
2424
+			$_SERVER['argv'] = array();
2425
+	}
2290 2426
 	$_GET['maint'] = 1;
2291 2427
 
2292 2428
 	foreach ($_SERVER['argv'] as $i => $arg)
2293 2429
 	{
2294
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2295
-			$_GET['lang'] = $match[1];
2296
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2297
-			continue;
2298
-		elseif ($arg == '--no-maintenance')
2299
-			$_GET['maint'] = 0;
2300
-		elseif ($arg == '--debug')
2301
-			$is_debug = true;
2302
-		elseif ($arg == '--backup')
2303
-			$_POST['backup'] = 1;
2304
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2305
-			$_GET['conv'] = 1;
2306
-		elseif ($i != 0)
2430
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2431
+					$_GET['lang'] = $match[1];
2432
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2433
+					continue;
2434
+		} elseif ($arg == '--no-maintenance') {
2435
+					$_GET['maint'] = 0;
2436
+		} elseif ($arg == '--debug') {
2437
+					$is_debug = true;
2438
+		} elseif ($arg == '--backup') {
2439
+					$_POST['backup'] = 1;
2440
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2441
+					$_GET['conv'] = 1;
2442
+		} elseif ($i != 0)
2307 2443
 		{
2308 2444
 			echo 'SMF Command-line Upgrader
2309 2445
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2317,10 +2453,12 @@  discard block
 block discarded – undo
2317 2453
 		}
2318 2454
 	}
2319 2455
 
2320
-	if (!php_version_check())
2321
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2322
-	if (!db_version_check())
2323
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2456
+	if (!php_version_check()) {
2457
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2458
+	}
2459
+	if (!db_version_check()) {
2460
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2461
+	}
2324 2462
 
2325 2463
 	// Do some checks to make sure they have proper privileges
2326 2464
 	db_extend('packages');
@@ -2335,34 +2473,39 @@  discard block
 block discarded – undo
2335 2473
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2336 2474
 
2337 2475
 	// Sorry... we need CREATE, ALTER and DROP
2338
-	if (!$create || !$alter || !$drop)
2339
-		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);
2476
+	if (!$create || !$alter || !$drop) {
2477
+			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);
2478
+	}
2340 2479
 
2341 2480
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2342 2481
 		&& @file_exists($sourcedir . '/QueryString.php')
2343 2482
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2344
-	if (!$check && !isset($modSettings['smfVersion']))
2345
-		print_error('Error: Some files are missing or out-of-date.', true);
2483
+	if (!$check && !isset($modSettings['smfVersion'])) {
2484
+			print_error('Error: Some files are missing or out-of-date.', true);
2485
+	}
2346 2486
 
2347 2487
 	// Do a quick version spot check.
2348 2488
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2349 2489
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2350
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2351
-		print_error('Error: Some files have not yet been updated properly.');
2490
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2491
+			print_error('Error: Some files have not yet been updated properly.');
2492
+	}
2352 2493
 
2353 2494
 	// Make sure Settings.php is writable.
2354 2495
 		quickFileWritable($boarddir . '/Settings.php');
2355
-	if (!is_writable($boarddir . '/Settings.php'))
2356
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2496
+	if (!is_writable($boarddir . '/Settings.php')) {
2497
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2498
+	}
2357 2499
 
2358 2500
 	// Make sure Settings_bak.php is writable.
2359 2501
 		quickFileWritable($boarddir . '/Settings_bak.php');
2360
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2361
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2502
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2503
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2504
+	}
2362 2505
 
2363
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2364
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2365
-	elseif (isset($modSettings['agreement']))
2506
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2507
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2508
+	} elseif (isset($modSettings['agreement']))
2366 2509
 	{
2367 2510
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2368 2511
 		fwrite($fp, $modSettings['agreement']);
@@ -2372,31 +2515,36 @@  discard block
 block discarded – undo
2372 2515
 	// Make sure Themes is writable.
2373 2516
 	quickFileWritable($modSettings['theme_dir']);
2374 2517
 
2375
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2376
-		print_error('Error: Unable to obtain write access to "Themes".');
2518
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2519
+			print_error('Error: Unable to obtain write access to "Themes".');
2520
+	}
2377 2521
 
2378 2522
 	// Make sure cache directory exists and is writable!
2379 2523
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2380
-	if (!file_exists($cachedir_temp))
2381
-		@mkdir($cachedir_temp);
2524
+	if (!file_exists($cachedir_temp)) {
2525
+			@mkdir($cachedir_temp);
2526
+	}
2382 2527
 
2383 2528
 	// Make sure the cache temp dir is writable.
2384 2529
 	quickFileWritable($cachedir_temp);
2385 2530
 
2386
-	if (!is_writable($cachedir_temp))
2387
-		print_error('Error: Unable to obtain write access to "cache".', true);
2531
+	if (!is_writable($cachedir_temp)) {
2532
+			print_error('Error: Unable to obtain write access to "cache".', true);
2533
+	}
2388 2534
 
2389
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2390
-		print_error('Error: Unable to find language files!', true);
2391
-	else
2535
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2536
+			print_error('Error: Unable to find language files!', true);
2537
+	} else
2392 2538
 	{
2393 2539
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2394 2540
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2395 2541
 
2396
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2397
-			print_error('Error: Language files out of date.', true);
2398
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2399
-			print_error('Error: Install language is missing for selected language.', true);
2542
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2543
+					print_error('Error: Language files out of date.', true);
2544
+		}
2545
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2546
+					print_error('Error: Install language is missing for selected language.', true);
2547
+		}
2400 2548
 
2401 2549
 		// Otherwise include it!
2402 2550
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2415,8 +2563,9 @@  discard block
 block discarded – undo
2415 2563
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2416 2564
 
2417 2565
 	// Done it already?
2418
-	if (!empty($_POST['utf8_done']))
2419
-		return true;
2566
+	if (!empty($_POST['utf8_done'])) {
2567
+			return true;
2568
+	}
2420 2569
 
2421 2570
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2422 2571
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2429,8 +2578,7 @@  discard block
 block discarded – undo
2429 2578
 		);
2430 2579
 
2431 2580
 		return true;
2432
-	}
2433
-	else
2581
+	} else
2434 2582
 	{
2435 2583
 		$upcontext['page_title'] = 'Converting to UTF8';
2436 2584
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2474,8 +2622,9 @@  discard block
 block discarded – undo
2474 2622
 			)
2475 2623
 		);
2476 2624
 		$db_charsets = array();
2477
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2478
-			$db_charsets[] = $row['Charset'];
2625
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2626
+					$db_charsets[] = $row['Charset'];
2627
+		}
2479 2628
 
2480 2629
 		$smcFunc['db_free_result']($request);
2481 2630
 
@@ -2511,13 +2660,15 @@  discard block
 block discarded – undo
2511 2660
 		// If there's a fulltext index, we need to drop it first...
2512 2661
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2513 2662
 		{
2514
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2515
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2663
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2664
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2516 2665
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2666
+			}
2517 2667
 			$smcFunc['db_free_result']($request);
2518 2668
 
2519
-			if (isset($upcontext['fulltext_index']))
2520
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2669
+			if (isset($upcontext['fulltext_index'])) {
2670
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2671
+			}
2521 2672
 		}
2522 2673
 
2523 2674
 		// Drop it and make a note...
@@ -2707,8 +2858,9 @@  discard block
 block discarded – undo
2707 2858
 			$replace = '%field%';
2708 2859
 
2709 2860
 			// Build a huge REPLACE statement...
2710
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2711
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2861
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2862
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2863
+			}
2712 2864
 		}
2713 2865
 
2714 2866
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2718,9 +2870,10 @@  discard block
 block discarded – undo
2718 2870
 		$upcontext['table_count'] = count($queryTables);
2719 2871
 
2720 2872
 		// What ones have we already done?
2721
-		foreach ($queryTables as $id => $table)
2722
-			if ($id < $_GET['substep'])
2873
+		foreach ($queryTables as $id => $table) {
2874
+					if ($id < $_GET['substep'])
2723 2875
 				$upcontext['previous_tables'][] = $table;
2876
+		}
2724 2877
 
2725 2878
 		$upcontext['cur_table_num'] = $_GET['substep'];
2726 2879
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2757,8 +2910,9 @@  discard block
 block discarded – undo
2757 2910
 			nextSubstep($substep);
2758 2911
 
2759 2912
 			// Just to make sure it doesn't time out.
2760
-			if (function_exists('apache_reset_timeout'))
2761
-				@apache_reset_timeout();
2913
+			if (function_exists('apache_reset_timeout')) {
2914
+							@apache_reset_timeout();
2915
+			}
2762 2916
 
2763 2917
 			$table_charsets = array();
2764 2918
 
@@ -2781,8 +2935,9 @@  discard block
 block discarded – undo
2781 2935
 
2782 2936
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2783 2937
 						if ($charset != 'utf8') {
2784
-							if (!isset($table_charsets[$charset]))
2785
-								$table_charsets[$charset] = array();
2938
+							if (!isset($table_charsets[$charset])) {
2939
+															$table_charsets[$charset] = array();
2940
+							}
2786 2941
 
2787 2942
 							$table_charsets[$charset][] = $column_info;
2788 2943
 						}
@@ -2823,10 +2978,11 @@  discard block
 block discarded – undo
2823 2978
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2824 2979
 				{
2825 2980
 					$update = '';
2826
-					foreach ($table_charsets as $charset => $columns)
2827
-						foreach ($columns as $column)
2981
+					foreach ($table_charsets as $charset => $columns) {
2982
+											foreach ($columns as $column)
2828 2983
 							$update .= '
2829 2984
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2985
+					}
2830 2986
 
2831 2987
 					$smcFunc['db_query']('', '
2832 2988
 						UPDATE {raw:table_name}
@@ -2851,8 +3007,9 @@  discard block
 block discarded – undo
2851 3007
 			// Now do the actual conversion (if still needed).
2852 3008
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2853 3009
 			{
2854
-				if ($command_line)
2855
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3010
+				if ($command_line) {
3011
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3012
+				}
2856 3013
 
2857 3014
 				$smcFunc['db_query']('', '
2858 3015
 					ALTER TABLE {raw:table_name}
@@ -2862,12 +3019,14 @@  discard block
 block discarded – undo
2862 3019
 					)
2863 3020
 				);
2864 3021
 
2865
-				if ($command_line)
2866
-					echo " done.\n";
3022
+				if ($command_line) {
3023
+									echo " done.\n";
3024
+				}
2867 3025
 			}
2868 3026
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2869
-			if (isset($_GET['xml']))
2870
-				return upgradeExit();
3027
+			if (isset($_GET['xml'])) {
3028
+							return upgradeExit();
3029
+			}
2871 3030
 		}
2872 3031
 
2873 3032
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2896,8 +3055,8 @@  discard block
 block discarded – undo
2896 3055
 		);
2897 3056
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2898 3057
 		{
2899
-			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)
2900
-				$smcFunc['db_query']('', '
3058
+			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) {
3059
+							$smcFunc['db_query']('', '
2901 3060
 					UPDATE {db_prefix}log_actions
2902 3061
 					SET extra = {string:extra}
2903 3062
 					WHERE id_action = {int:current_action}',
@@ -2906,6 +3065,7 @@  discard block
 block discarded – undo
2906 3065
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2907 3066
 					)
2908 3067
 				);
3068
+			}
2909 3069
 		}
2910 3070
 		$smcFunc['db_free_result']($request);
2911 3071
 
@@ -2927,15 +3087,17 @@  discard block
 block discarded – undo
2927 3087
 	// First thing's first - did we already do this?
2928 3088
 	if (!empty($modSettings['json_done']))
2929 3089
 	{
2930
-		if ($command_line)
2931
-			return DeleteUpgrade();
2932
-		else
2933
-			return true;
3090
+		if ($command_line) {
3091
+					return DeleteUpgrade();
3092
+		} else {
3093
+					return true;
3094
+		}
2934 3095
 	}
2935 3096
 
2936 3097
 	// Done it already - js wise?
2937
-	if (!empty($_POST['json_done']))
2938
-		return true;
3098
+	if (!empty($_POST['json_done'])) {
3099
+			return true;
3100
+	}
2939 3101
 
2940 3102
 	// List of tables affected by this function
2941 3103
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2967,12 +3129,14 @@  discard block
 block discarded – undo
2967 3129
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2968 3130
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2969 3131
 
2970
-	foreach ($keys as $id => $table)
2971
-		if ($id < $_GET['substep'])
3132
+	foreach ($keys as $id => $table) {
3133
+			if ($id < $_GET['substep'])
2972 3134
 			$upcontext['previous_tables'][] = $table;
3135
+	}
2973 3136
 
2974
-	if ($command_line)
2975
-		echo 'Converting data from serialize() to json_encode().';
3137
+	if ($command_line) {
3138
+			echo 'Converting data from serialize() to json_encode().';
3139
+	}
2976 3140
 
2977 3141
 	if (!$support_js || isset($_GET['xml']))
2978 3142
 	{
@@ -3012,8 +3176,9 @@  discard block
 block discarded – undo
3012 3176
 
3013 3177
 				// Loop through and fix these...
3014 3178
 				$new_settings = array();
3015
-				if ($command_line)
3016
-					echo "\n" . 'Fixing some settings...';
3179
+				if ($command_line) {
3180
+									echo "\n" . 'Fixing some settings...';
3181
+				}
3017 3182
 
3018 3183
 				foreach ($serialized_settings as $var)
3019 3184
 				{
@@ -3021,22 +3186,24 @@  discard block
 block discarded – undo
3021 3186
 					{
3022 3187
 						// Attempt to unserialize the setting
3023 3188
 						$temp = @safe_unserialize($modSettings[$var]);
3024
-						if (!$temp && $command_line)
3025
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3026
-						elseif ($temp !== false)
3027
-							$new_settings[$var] = json_encode($temp);
3189
+						if (!$temp && $command_line) {
3190
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3191
+						} elseif ($temp !== false) {
3192
+													$new_settings[$var] = json_encode($temp);
3193
+						}
3028 3194
 					}
3029 3195
 				}
3030 3196
 
3031 3197
 				// Update everything at once
3032
-				if (!function_exists('cache_put_data'))
3033
-					require_once($sourcedir . '/Load.php');
3198
+				if (!function_exists('cache_put_data')) {
3199
+									require_once($sourcedir . '/Load.php');
3200
+				}
3034 3201
 				updateSettings($new_settings, true);
3035 3202
 
3036
-				if ($command_line)
3037
-					echo ' done.';
3038
-			}
3039
-			elseif ($table == 'themes')
3203
+				if ($command_line) {
3204
+									echo ' done.';
3205
+				}
3206
+			} elseif ($table == 'themes')
3040 3207
 			{
3041 3208
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3042 3209
 				$query = $smcFunc['db_query']('', '
@@ -3055,10 +3222,11 @@  discard block
 block discarded – undo
3055 3222
 
3056 3223
 						if ($command_line)
3057 3224
 						{
3058
-							if ($temp === false)
3059
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3060
-							else
3061
-								echo "\n" . 'Fixing admin preferences...';
3225
+							if ($temp === false) {
3226
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3227
+							} else {
3228
+															echo "\n" . 'Fixing admin preferences...';
3229
+							}
3062 3230
 						}
3063 3231
 
3064 3232
 						if ($temp !== false)
@@ -3080,15 +3248,15 @@  discard block
 block discarded – undo
3080 3248
 								)
3081 3249
 							);
3082 3250
 
3083
-							if ($command_line)
3084
-								echo ' done.';
3251
+							if ($command_line) {
3252
+															echo ' done.';
3253
+							}
3085 3254
 						}
3086 3255
 					}
3087 3256
 
3088 3257
 					$smcFunc['db_free_result']($query);
3089 3258
 				}
3090
-			}
3091
-			else
3259
+			} else
3092 3260
 			{
3093 3261
 				// First item is always the key...
3094 3262
 				$key = $info[0];
@@ -3099,8 +3267,7 @@  discard block
 block discarded – undo
3099 3267
 				{
3100 3268
 					$col_select = $info[1];
3101 3269
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3102
-				}
3103
-				else
3270
+				} else
3104 3271
 				{
3105 3272
 					$col_select = implode(', ', $info);
3106 3273
 				}
@@ -3133,8 +3300,7 @@  discard block
 block discarded – undo
3133 3300
 								if ($temp === false && $command_line)
3134 3301
 								{
3135 3302
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3136
-								}
3137
-								else
3303
+								} else
3138 3304
 								{
3139 3305
 									$row[$col] = json_encode($temp);
3140 3306
 
@@ -3159,16 +3325,18 @@  discard block
 block discarded – undo
3159 3325
 						}
3160 3326
 					}
3161 3327
 
3162
-					if ($command_line)
3163
-						echo ' done.';
3328
+					if ($command_line) {
3329
+											echo ' done.';
3330
+					}
3164 3331
 
3165 3332
 					// Free up some memory...
3166 3333
 					$smcFunc['db_free_result']($query);
3167 3334
 				}
3168 3335
 			}
3169 3336
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3170
-			if (isset($_GET['xml']))
3171
-				return upgradeExit();
3337
+			if (isset($_GET['xml'])) {
3338
+							return upgradeExit();
3339
+			}
3172 3340
 		}
3173 3341
 
3174 3342
 		if ($command_line)
@@ -3183,8 +3351,9 @@  discard block
 block discarded – undo
3183 3351
 
3184 3352
 		$_GET['substep'] = 0;
3185 3353
 		// Make sure we move on!
3186
-		if ($command_line)
3187
-			return DeleteUpgrade();
3354
+		if ($command_line) {
3355
+					return DeleteUpgrade();
3356
+		}
3188 3357
 
3189 3358
 		return true;
3190 3359
 	}
@@ -3204,14 +3373,16 @@  discard block
 block discarded – undo
3204 3373
 	global $upcontext, $txt, $settings;
3205 3374
 
3206 3375
 	// Don't call me twice!
3207
-	if (!empty($upcontext['chmod_called']))
3208
-		return;
3376
+	if (!empty($upcontext['chmod_called'])) {
3377
+			return;
3378
+	}
3209 3379
 
3210 3380
 	$upcontext['chmod_called'] = true;
3211 3381
 
3212 3382
 	// Nothing?
3213
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3214
-		return;
3383
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3384
+			return;
3385
+	}
3215 3386
 
3216 3387
 	// Was it a problem with Windows?
3217 3388
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3243,11 +3414,12 @@  discard block
 block discarded – undo
3243 3414
 					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\');
3244 3415
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3245 3416
 
3246
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3247
-		echo '
3417
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3418
+			echo '
3248 3419
 					content.write(\'<hr>\n\t\t\t\');
3249 3420
 					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\');
3250 3421
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3422
+	}
3251 3423
 
3252 3424
 	echo '
3253 3425
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3255,17 +3427,19 @@  discard block
 block discarded – undo
3255 3427
 				}
3256 3428
 			</script>';
3257 3429
 
3258
-	if (!empty($upcontext['chmod']['ftp_error']))
3259
-		echo '
3430
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3431
+			echo '
3260 3432
 			<div class="error_message red">
3261 3433
 				The following error was encountered when trying to connect:<br><br>
3262 3434
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3263 3435
 			</div>
3264 3436
 			<br>';
3437
+	}
3265 3438
 
3266
-	if (empty($upcontext['chmod_in_form']))
3267
-		echo '
3439
+	if (empty($upcontext['chmod_in_form'])) {
3440
+			echo '
3268 3441
 	<form action="', $upcontext['form_url'], '" method="post">';
3442
+	}
3269 3443
 
3270 3444
 	echo '
3271 3445
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3300,10 +3474,11 @@  discard block
 block discarded – undo
3300 3474
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3301 3475
 	</div>';
3302 3476
 
3303
-	if (empty($upcontext['chmod_in_form']))
3304
-		echo '
3477
+	if (empty($upcontext['chmod_in_form'])) {
3478
+			echo '
3305 3479
 	</form>';
3306
-}
3480
+	}
3481
+	}
3307 3482
 
3308 3483
 function template_upgrade_above()
3309 3484
 {
@@ -3363,9 +3538,10 @@  discard block
 block discarded – undo
3363 3538
 				<h2>', $txt['upgrade_progress'], '</h2>
3364 3539
 				<ul>';
3365 3540
 
3366
-	foreach ($upcontext['steps'] as $num => $step)
3367
-		echo '
3541
+	foreach ($upcontext['steps'] as $num => $step) {
3542
+			echo '
3368 3543
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3544
+	}
3369 3545
 
3370 3546
 	echo '
3371 3547
 					</ul>
@@ -3378,8 +3554,8 @@  discard block
 block discarded – undo
3378 3554
 				</div>
3379 3555
 			</div>';
3380 3556
 
3381
-	if (isset($upcontext['step_progress']))
3382
-		echo '
3557
+	if (isset($upcontext['step_progress'])) {
3558
+			echo '
3383 3559
 				<br>
3384 3560
 				<br>
3385 3561
 				<div id="progress_bar_step">
@@ -3388,6 +3564,7 @@  discard block
 block discarded – undo
3388 3564
 						<span>', $txt['upgrade_step_progress'], '</span>
3389 3565
 					</div>
3390 3566
 				</div>';
3567
+	}
3391 3568
 
3392 3569
 	echo '
3393 3570
 				<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>
@@ -3418,32 +3595,36 @@  discard block
 block discarded – undo
3418 3595
 {
3419 3596
 	global $upcontext, $txt;
3420 3597
 
3421
-	if (!empty($upcontext['pause']))
3422
-		echo '
3598
+	if (!empty($upcontext['pause'])) {
3599
+			echo '
3423 3600
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3424 3601
 
3425 3602
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3426 3603
 								<h3>
3427 3604
 									', $txt['upgrade_paused_overload'], '
3428 3605
 								</h3>';
3606
+	}
3429 3607
 
3430
-	if (!empty($upcontext['custom_warning']))
3431
-		echo '
3608
+	if (!empty($upcontext['custom_warning'])) {
3609
+			echo '
3432 3610
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3433 3611
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3434 3612
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3435 3613
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3436 3614
 								</div>';
3615
+	}
3437 3616
 
3438 3617
 	echo '
3439 3618
 								<div class="righttext" style="margin: 1ex;">';
3440 3619
 
3441
-	if (!empty($upcontext['continue']))
3442
-		echo '
3620
+	if (!empty($upcontext['continue'])) {
3621
+			echo '
3443 3622
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3444
-	if (!empty($upcontext['skip']))
3445
-		echo '
3623
+	}
3624
+	if (!empty($upcontext['skip'])) {
3625
+			echo '
3446 3626
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3627
+	}
3447 3628
 
3448 3629
 	echo '
3449 3630
 								</div>
@@ -3493,11 +3674,12 @@  discard block
 block discarded – undo
3493 3674
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3494 3675
 	<smf>';
3495 3676
 
3496
-	if (!empty($upcontext['get_data']))
3497
-		foreach ($upcontext['get_data'] as $k => $v)
3677
+	if (!empty($upcontext['get_data'])) {
3678
+			foreach ($upcontext['get_data'] as $k => $v)
3498 3679
 			echo '
3499 3680
 		<get key="', $k, '">', $v, '</get>';
3500
-}
3681
+	}
3682
+	}
3501 3683
 
3502 3684
 function template_xml_below()
3503 3685
 {
@@ -3538,8 +3720,8 @@  discard block
 block discarded – undo
3538 3720
 	template_chmod();
3539 3721
 
3540 3722
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3541
-	if ($upcontext['is_large_forum'])
3542
-		echo '
3723
+	if ($upcontext['is_large_forum']) {
3724
+			echo '
3543 3725
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3544 3726
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3545 3727
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3547,10 +3729,11 @@  discard block
 block discarded – undo
3547 3729
 				', $txt['upgrade_warning_lots_data'], '
3548 3730
 			</div>
3549 3731
 		</div>';
3732
+	}
3550 3733
 
3551 3734
 	// A warning message?
3552
-	if (!empty($upcontext['warning']))
3553
-		echo '
3735
+	if (!empty($upcontext['warning'])) {
3736
+			echo '
3554 3737
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3555 3738
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3556 3739
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3558,6 +3741,7 @@  discard block
 block discarded – undo
3558 3741
 				', $upcontext['warning'], '
3559 3742
 			</div>
3560 3743
 		</div>';
3744
+	}
3561 3745
 
3562 3746
 	// Paths are incorrect?
3563 3747
 	echo '
@@ -3573,20 +3757,22 @@  discard block
 block discarded – undo
3573 3757
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3574 3758
 	{
3575 3759
 		$ago = time() - $upcontext['started'];
3576
-		if ($ago < 60)
3577
-			$ago = $ago . ' seconds';
3578
-		elseif ($ago < 3600)
3579
-			$ago = (int) ($ago / 60) . ' minutes';
3580
-		else
3581
-			$ago = (int) ($ago / 3600) . ' hours';
3760
+		if ($ago < 60) {
3761
+					$ago = $ago . ' seconds';
3762
+		} elseif ($ago < 3600) {
3763
+					$ago = (int) ($ago / 60) . ' minutes';
3764
+		} else {
3765
+					$ago = (int) ($ago / 3600) . ' hours';
3766
+		}
3582 3767
 
3583 3768
 		$active = time() - $upcontext['updated'];
3584
-		if ($active < 60)
3585
-			$updated = $active . ' seconds';
3586
-		elseif ($active < 3600)
3587
-			$updated = (int) ($active / 60) . ' minutes';
3588
-		else
3589
-			$updated = (int) ($active / 3600) . ' hours';
3769
+		if ($active < 60) {
3770
+					$updated = $active . ' seconds';
3771
+		} elseif ($active < 3600) {
3772
+					$updated = (int) ($active / 60) . ' minutes';
3773
+		} else {
3774
+					$updated = (int) ($active / 3600) . ' hours';
3775
+		}
3590 3776
 
3591 3777
 		echo '
3592 3778
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3595,16 +3781,18 @@  discard block
 block discarded – undo
3595 3781
 			<div style="padding-left: 6ex;">
3596 3782
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3597 3783
 
3598
-		if ($active < 600)
3599
-			echo '
3784
+		if ($active < 600) {
3785
+					echo '
3600 3786
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3787
+		}
3601 3788
 
3602
-		if ($active > $upcontext['inactive_timeout'])
3603
-			echo '
3789
+		if ($active > $upcontext['inactive_timeout']) {
3790
+					echo '
3604 3791
 				<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.';
3605
-		else
3606
-			echo '
3792
+		} else {
3793
+					echo '
3607 3794
 				<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!');
3795
+		}
3608 3796
 
3609 3797
 		echo '
3610 3798
 			</div>
@@ -3620,9 +3808,10 @@  discard block
 block discarded – undo
3620 3808
 					<td>
3621 3809
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3622 3810
 
3623
-	if (!empty($upcontext['username_incorrect']))
3624
-		echo '
3811
+	if (!empty($upcontext['username_incorrect'])) {
3812
+			echo '
3625 3813
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3814
+	}
3626 3815
 
3627 3816
 	echo '
3628 3817
 					</td>
@@ -3633,9 +3822,10 @@  discard block
 block discarded – undo
3633 3822
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3634 3823
 						<input type="hidden" name="hash_passwrd" value="">';
3635 3824
 
3636
-	if (!empty($upcontext['password_failed']))
3637
-		echo '
3825
+	if (!empty($upcontext['password_failed'])) {
3826
+			echo '
3638 3827
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3828
+	}
3639 3829
 
3640 3830
 	echo '
3641 3831
 					</td>
@@ -3706,8 +3896,8 @@  discard block
 block discarded – undo
3706 3896
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3707 3897
 
3708 3898
 	// Warning message?
3709
-	if (!empty($upcontext['upgrade_options_warning']))
3710
-		echo '
3899
+	if (!empty($upcontext['upgrade_options_warning'])) {
3900
+			echo '
3711 3901
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3712 3902
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3713 3903
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3715,6 +3905,7 @@  discard block
 block discarded – undo
3715 3905
 				', $upcontext['upgrade_options_warning'], '
3716 3906
 			</div>
3717 3907
 		</div>';
3908
+	}
3718 3909
 
3719 3910
 	echo '
3720 3911
 				<table>
@@ -3757,8 +3948,8 @@  discard block
 block discarded – undo
3757 3948
 						</td>
3758 3949
 					</tr>';
3759 3950
 
3760
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3761
-		echo '
3951
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3952
+			echo '
3762 3953
 					<tr valign="top">
3763 3954
 						<td width="2%">
3764 3955
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3767,6 +3958,7 @@  discard block
 block discarded – undo
3767 3958
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3768 3959
 						</td>
3769 3960
 					</tr>';
3961
+	}
3770 3962
 
3771 3963
 	echo '
3772 3964
 					<tr valign="top">
@@ -3804,10 +3996,11 @@  discard block
 block discarded – undo
3804 3996
 			</div>';
3805 3997
 
3806 3998
 	// Dont any tables so far?
3807
-	if (!empty($upcontext['previous_tables']))
3808
-		foreach ($upcontext['previous_tables'] as $table)
3999
+	if (!empty($upcontext['previous_tables'])) {
4000
+			foreach ($upcontext['previous_tables'] as $table)
3809 4001
 			echo '
3810 4002
 			<br>Completed Table: &quot;', $table, '&quot;.';
4003
+	}
3811 4004
 
3812 4005
 	echo '
3813 4006
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3844,12 +4037,13 @@  discard block
 block discarded – undo
3844 4037
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3845 4038
 
3846 4039
 		// If debug flood the screen.
3847
-		if ($is_debug)
3848
-			echo '
4040
+		if ($is_debug) {
4041
+					echo '
3849 4042
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3850 4043
 
3851 4044
 				if (document.getElementById(\'debug_section\').scrollHeight)
3852 4045
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4046
+		}
3853 4047
 
3854 4048
 		echo '
3855 4049
 				// Get the next update...
@@ -3882,8 +4076,9 @@  discard block
 block discarded – undo
3882 4076
 {
3883 4077
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3884 4078
 
3885
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3886
-		$is_debug = true;
4079
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4080
+			$is_debug = true;
4081
+	}
3887 4082
 
3888 4083
 	echo '
3889 4084
 		<h3>Executing database changes</h3>
@@ -3898,8 +4093,9 @@  discard block
 block discarded – undo
3898 4093
 	{
3899 4094
 		foreach ($upcontext['actioned_items'] as $num => $item)
3900 4095
 		{
3901
-			if ($num != 0)
3902
-				echo ' Successful!';
4096
+			if ($num != 0) {
4097
+							echo ' Successful!';
4098
+			}
3903 4099
 			echo '<br>' . $item;
3904 4100
 		}
3905 4101
 		if (!empty($upcontext['changes_complete']))
@@ -3912,28 +4108,32 @@  discard block
 block discarded – undo
3912 4108
 				$seconds = intval($active % 60);
3913 4109
 
3914 4110
 				$totalTime = '';
3915
-				if ($hours > 0)
3916
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3917
-				if ($minutes > 0)
3918
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3919
-				if ($seconds > 0)
3920
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4111
+				if ($hours > 0) {
4112
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4113
+				}
4114
+				if ($minutes > 0) {
4115
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4116
+				}
4117
+				if ($seconds > 0) {
4118
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4119
+				}
3921 4120
 			}
3922 4121
 
3923
-			if ($is_debug && !empty($totalTime))
3924
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3925
-			else
3926
-				echo ' Successful!<br><br>';
4122
+			if ($is_debug && !empty($totalTime)) {
4123
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4124
+			} else {
4125
+							echo ' Successful!<br><br>';
4126
+			}
3927 4127
 
3928 4128
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3929 4129
 		}
3930
-	}
3931
-	else
4130
+	} else
3932 4131
 	{
3933 4132
 		// Tell them how many files we have in total.
3934
-		if ($upcontext['file_count'] > 1)
3935
-			echo '
4133
+		if ($upcontext['file_count'] > 1) {
4134
+					echo '
3936 4135
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4136
+		}
3937 4137
 
3938 4138
 		echo '
3939 4139
 		<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>
@@ -3949,19 +4149,23 @@  discard block
 block discarded – undo
3949 4149
 				$seconds = intval($active % 60);
3950 4150
 
3951 4151
 				$totalTime = '';
3952
-				if ($hours > 0)
3953
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3954
-				if ($minutes > 0)
3955
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3956
-				if ($seconds > 0)
3957
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4152
+				if ($hours > 0) {
4153
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4154
+				}
4155
+				if ($minutes > 0) {
4156
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4157
+				}
4158
+				if ($seconds > 0) {
4159
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4160
+				}
3958 4161
 			}
3959 4162
 
3960 4163
 			echo '
3961 4164
 			<br><span id="upgradeCompleted">';
3962 4165
 
3963
-			if (!empty($totalTime))
3964
-				echo 'Completed in ', $totalTime, '<br>';
4166
+			if (!empty($totalTime)) {
4167
+							echo 'Completed in ', $totalTime, '<br>';
4168
+			}
3965 4169
 
3966 4170
 			echo '</span>
3967 4171
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -3998,9 +4202,10 @@  discard block
 block discarded – undo
3998 4202
 			var getData = "";
3999 4203
 			var debugItems = ', $upcontext['debug_items'], ';';
4000 4204
 
4001
-		if ($is_debug)
4002
-			echo '
4205
+		if ($is_debug) {
4206
+					echo '
4003 4207
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4208
+		}
4004 4209
 
4005 4210
 		echo '
4006 4211
 			function getNextItem()
@@ -4040,9 +4245,10 @@  discard block
 block discarded – undo
4040 4245
 						document.getElementById("error_block").style.display = "";
4041 4246
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4042 4247
 
4043
-	if ($is_debug)
4044
-		echo '
4248
+	if ($is_debug) {
4249
+			echo '
4045 4250
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4251
+	}
4046 4252
 
4047 4253
 	echo '
4048 4254
 					}
@@ -4063,9 +4269,10 @@  discard block
 block discarded – undo
4063 4269
 						document.getElementById("error_block").style.display = "";
4064 4270
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4065 4271
 
4066
-	if ($is_debug)
4067
-		echo '
4272
+	if ($is_debug) {
4273
+			echo '
4068 4274
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4275
+	}
4069 4276
 
4070 4277
 	echo '
4071 4278
 					}
@@ -4124,8 +4331,8 @@  discard block
 block discarded – undo
4124 4331
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4125 4332
 				{';
4126 4333
 
4127
-		if ($is_debug)
4128
-			echo '
4334
+		if ($is_debug) {
4335
+					echo '
4129 4336
 					document.getElementById(\'debug_section\').style.display = "none";
4130 4337
 
4131 4338
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4143,6 +4350,7 @@  discard block
 block discarded – undo
4143 4350
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4144 4351
 
4145 4352
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4353
+		}
4146 4354
 
4147 4355
 		echo '
4148 4356
 
@@ -4150,9 +4358,10 @@  discard block
 block discarded – undo
4150 4358
 					document.getElementById(\'contbutt\').disabled = 0;
4151 4359
 					document.getElementById(\'database_done\').value = 1;';
4152 4360
 
4153
-		if ($upcontext['file_count'] > 1)
4154
-			echo '
4361
+		if ($upcontext['file_count'] > 1) {
4362
+					echo '
4155 4363
 					document.getElementById(\'info1\').style.display = "none";';
4364
+		}
4156 4365
 
4157 4366
 		echo '
4158 4367
 					document.getElementById(\'info2\').style.display = "none";
@@ -4165,9 +4374,10 @@  discard block
 block discarded – undo
4165 4374
 					lastItem = 0;
4166 4375
 					prevFile = curFile;';
4167 4376
 
4168
-		if ($is_debug)
4169
-			echo '
4377
+		if ($is_debug) {
4378
+					echo '
4170 4379
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4380
+		}
4171 4381
 
4172 4382
 		echo '
4173 4383
 					getNextItem();
@@ -4175,8 +4385,8 @@  discard block
 block discarded – undo
4175 4385
 				}';
4176 4386
 
4177 4387
 		// If debug scroll the screen.
4178
-		if ($is_debug)
4179
-			echo '
4388
+		if ($is_debug) {
4389
+					echo '
4180 4390
 				if (iLastSubStepProgress == -1)
4181 4391
 				{
4182 4392
 					// Give it consistent dots.
@@ -4195,6 +4405,7 @@  discard block
 block discarded – undo
4195 4405
 
4196 4406
 				if (document.getElementById(\'debug_section\').scrollHeight)
4197 4407
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4408
+		}
4198 4409
 
4199 4410
 		echo '
4200 4411
 				// Update the page.
@@ -4255,9 +4466,10 @@  discard block
 block discarded – undo
4255 4466
 			}';
4256 4467
 
4257 4468
 		// Start things off assuming we've not errored.
4258
-		if (empty($upcontext['error_message']))
4259
-			echo '
4469
+		if (empty($upcontext['error_message'])) {
4470
+					echo '
4260 4471
 			getNextItem();';
4472
+		}
4261 4473
 
4262 4474
 		echo '
4263 4475
 		//# sourceURL=dynamicScript-dbch.js
@@ -4275,18 +4487,21 @@  discard block
 block discarded – undo
4275 4487
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4276 4488
 	<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>';
4277 4489
 
4278
-	if (!empty($upcontext['error_message']))
4279
-		echo '
4490
+	if (!empty($upcontext['error_message'])) {
4491
+			echo '
4280 4492
 	<error>', $upcontext['error_message'], '</error>';
4493
+	}
4281 4494
 
4282
-	if (!empty($upcontext['error_string']))
4283
-		echo '
4495
+	if (!empty($upcontext['error_string'])) {
4496
+			echo '
4284 4497
 	<sql>', $upcontext['error_string'], '</sql>';
4498
+	}
4285 4499
 
4286
-	if ($is_debug)
4287
-		echo '
4500
+	if ($is_debug) {
4501
+			echo '
4288 4502
 	<curtime>', time(), '</curtime>';
4289
-}
4503
+	}
4504
+	}
4290 4505
 
4291 4506
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4292 4507
 function template_convert_utf8()
@@ -4305,18 +4520,20 @@  discard block
 block discarded – undo
4305 4520
 			</div>';
4306 4521
 
4307 4522
 	// Done any tables so far?
4308
-	if (!empty($upcontext['previous_tables']))
4309
-		foreach ($upcontext['previous_tables'] as $table)
4523
+	if (!empty($upcontext['previous_tables'])) {
4524
+			foreach ($upcontext['previous_tables'] as $table)
4310 4525
 			echo '
4311 4526
 			<br>Completed Table: &quot;', $table, '&quot;.';
4527
+	}
4312 4528
 
4313 4529
 	echo '
4314 4530
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4315 4531
 
4316 4532
 	// If we dropped their index, let's let them know
4317
-	if ($upcontext['dropping_index'])
4318
-		echo '
4533
+	if ($upcontext['dropping_index']) {
4534
+			echo '
4319 4535
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4536
+	}
4320 4537
 
4321 4538
 	// Completion notification
4322 4539
 	echo '
@@ -4353,12 +4570,13 @@  discard block
 block discarded – undo
4353 4570
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4354 4571
 
4355 4572
 		// If debug flood the screen.
4356
-		if ($is_debug)
4357
-			echo '
4573
+		if ($is_debug) {
4574
+					echo '
4358 4575
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4359 4576
 
4360 4577
 				if (document.getElementById(\'debug_section\').scrollHeight)
4361 4578
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4579
+		}
4362 4580
 
4363 4581
 		echo '
4364 4582
 				// Get the next update...
@@ -4406,19 +4624,21 @@  discard block
 block discarded – undo
4406 4624
 			</div>';
4407 4625
 
4408 4626
 	// Dont any tables so far?
4409
-	if (!empty($upcontext['previous_tables']))
4410
-		foreach ($upcontext['previous_tables'] as $table)
4627
+	if (!empty($upcontext['previous_tables'])) {
4628
+			foreach ($upcontext['previous_tables'] as $table)
4411 4629
 			echo '
4412 4630
 			<br>Completed Table: &quot;', $table, '&quot;.';
4631
+	}
4413 4632
 
4414 4633
 	echo '
4415 4634
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4416 4635
 			<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>';
4417 4636
 
4418 4637
 	// Try to make sure substep was reset.
4419
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4420
-		echo '
4638
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4639
+			echo '
4421 4640
 			<input type="hidden" name="substep" id="substep" value="0">';
4641
+	}
4422 4642
 
4423 4643
 	// Continue please!
4424 4644
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4451,12 +4671,13 @@  discard block
 block discarded – undo
4451 4671
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4452 4672
 
4453 4673
 		// If debug flood the screen.
4454
-		if ($is_debug)
4455
-			echo '
4674
+		if ($is_debug) {
4675
+					echo '
4456 4676
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4457 4677
 
4458 4678
 				if (document.getElementById(\'debug_section\').scrollHeight)
4459 4679
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4680
+		}
4460 4681
 
4461 4682
 		echo '
4462 4683
 				// Get the next update...
@@ -4492,8 +4713,8 @@  discard block
 block discarded – undo
4492 4713
 	<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>
4493 4714
 	<form action="', $boardurl, '/index.php">';
4494 4715
 
4495
-	if (!empty($upcontext['can_delete_script']))
4496
-		echo '
4716
+	if (!empty($upcontext['can_delete_script'])) {
4717
+			echo '
4497 4718
 			<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>
4498 4719
 			<script>
4499 4720
 				function doTheDelete(theCheck)
@@ -4505,6 +4726,7 @@  discard block
 block discarded – undo
4505 4726
 				}
4506 4727
 			</script>
4507 4728
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4729
+	}
4508 4730
 
4509 4731
 	$active = time() - $upcontext['started'];
4510 4732
 	$hours = floor($active / 3600);
@@ -4514,16 +4736,20 @@  discard block
 block discarded – undo
4514 4736
 	if ($is_debug)
4515 4737
 	{
4516 4738
 		$totalTime = '';
4517
-		if ($hours > 0)
4518
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4519
-		if ($minutes > 0)
4520
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4521
-		if ($seconds > 0)
4522
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4739
+		if ($hours > 0) {
4740
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4741
+		}
4742
+		if ($minutes > 0) {
4743
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4744
+		}
4745
+		if ($seconds > 0) {
4746
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4747
+		}
4523 4748
 	}
4524 4749
 
4525
-	if ($is_debug && !empty($totalTime))
4526
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4750
+	if ($is_debug && !empty($totalTime)) {
4751
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4752
+	}
4527 4753
 
4528 4754
 	echo '<br>
4529 4755
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4550,8 +4776,9 @@  discard block
 block discarded – undo
4550 4776
 
4551 4777
 	$current_substep = $_GET['substep'];
4552 4778
 
4553
-	if (empty($_GET['a']))
4554
-		$_GET['a'] = 0;
4779
+	if (empty($_GET['a'])) {
4780
+			$_GET['a'] = 0;
4781
+	}
4555 4782
 	$step_progress['name'] = 'Converting ips';
4556 4783
 	$step_progress['current'] = $_GET['a'];
4557 4784
 
@@ -4594,16 +4821,19 @@  discard block
 block discarded – undo
4594 4821
 				'empty' => '',
4595 4822
 				'limit' => $limit,
4596 4823
 		));
4597
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4598
-			$arIp[] = $row[$oldCol];
4824
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4825
+					$arIp[] = $row[$oldCol];
4826
+		}
4599 4827
 		$smcFunc['db_free_result']($request);
4600 4828
 
4601 4829
 		// Special case, null ip could keep us in a loop.
4602
-		if (is_null($arIp[0]))
4603
-			unset($arIp[0]);
4830
+		if (is_null($arIp[0])) {
4831
+					unset($arIp[0]);
4832
+		}
4604 4833
 
4605
-		if (empty($arIp))
4606
-			$is_done = true;
4834
+		if (empty($arIp)) {
4835
+					$is_done = true;
4836
+		}
4607 4837
 
4608 4838
 		$updates = array();
4609 4839
 		$cases = array();
@@ -4612,16 +4842,18 @@  discard block
 block discarded – undo
4612 4842
 		{
4613 4843
 			$arIp[$i] = trim($arIp[$i]);
4614 4844
 
4615
-			if (empty($arIp[$i]))
4616
-				continue;
4845
+			if (empty($arIp[$i])) {
4846
+							continue;
4847
+			}
4617 4848
 
4618 4849
 			$updates['ip' . $i] = $arIp[$i];
4619 4850
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4620 4851
 
4621 4852
 			if ($setSize > 0 && $i % $setSize === 0)
4622 4853
 			{
4623
-				if (count($updates) == 1)
4624
-					continue;
4854
+				if (count($updates) == 1) {
4855
+									continue;
4856
+				}
4625 4857
 
4626 4858
 				$updates['whereSet'] = array_values($updates);
4627 4859
 				$smcFunc['db_query']('', '
@@ -4655,8 +4887,7 @@  discard block
 block discarded – undo
4655 4887
 							'ip' => $ip
4656 4888
 					));
4657 4889
 				}
4658
-			}
4659
-			else
4890
+			} else
4660 4891
 			{
4661 4892
 				$updates['whereSet'] = array_values($updates);
4662 4893
 				$smcFunc['db_query']('', '
@@ -4670,9 +4901,9 @@  discard block
 block discarded – undo
4670 4901
 					$updates
4671 4902
 				);
4672 4903
 			}
4904
+		} else {
4905
+					$is_done = true;
4673 4906
 		}
4674
-		else
4675
-			$is_done = true;
4676 4907
 
4677 4908
 		$_GET['a'] += $limit;
4678 4909
 		$step_progress['current'] = $_GET['a'];
@@ -4698,10 +4929,11 @@  discard block
 block discarded – undo
4698 4929
 
4699 4930
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4700 4931
 
4701
-	if (isset($columns[$column]))
4702
-		return $columns[$column];
4703
-	else
4704
-		return null;
4705
-}
4932
+	if (isset($columns[$column])) {
4933
+			return $columns[$column];
4934
+	} else {
4935
+			return null;
4936
+	}
4937
+	}
4706 4938
 
4707 4939
 ?>
4708 4940
\ No newline at end of file
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting.
154 160
 	error_reporting(E_ALL);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -237,10 +246,11 @@  discard block
 block discarded – undo
237 246
 	{
238 247
 		// Get PHP's default timezone, if set
239 248
 		$ini_tz = ini_get('date.timezone');
240
-		if (!empty($ini_tz))
241
-			$timezone_id = $ini_tz;
242
-		else
243
-			$timezone_id = '';
249
+		if (!empty($ini_tz)) {
250
+					$timezone_id = $ini_tz;
251
+		} else {
252
+					$timezone_id = '';
253
+		}
244 254
 
245 255
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
246 256
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -270,8 +280,9 @@  discard block
 block discarded – undo
270 280
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
271 281
 		while ($entry = $dir->read())
272 282
 		{
273
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
274
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
283
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
284
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
285
+			}
275 286
 		}
276 287
 		$dir->close();
277 288
 	}
@@ -306,10 +317,11 @@  discard block
 block discarded – undo
306 317
 	}
307 318
 
308 319
 	// Override the language file?
309
-	if (isset($_GET['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
311
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
312
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	if (isset($_GET['lang_file'])) {
321
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
322
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
323
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
324
+	}
313 325
 
314 326
 	// Make sure it exists, if it doesn't reset it.
315 327
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -318,8 +330,9 @@  discard block
 block discarded – undo
318 330
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
319 331
 
320 332
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
321
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
322
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
333
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
334
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
335
+		}
323 336
 	}
324 337
 
325 338
 	// And now include the actual language file itself.
@@ -332,15 +345,18 @@  discard block
 block discarded – undo
332 345
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
333 346
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
334 347
 
335
-	if (empty($sourcedir))
336
-		$sourcedir = dirname(__FILE__) . '/Sources';
348
+	if (empty($sourcedir)) {
349
+			$sourcedir = dirname(__FILE__) . '/Sources';
350
+	}
337 351
 
338 352
 	// Need this to check whether we need the database password.
339 353
 	require(dirname(__FILE__) . '/Settings.php');
340
-	if (!defined('SMF'))
341
-		define('SMF', 1);
342
-	if (empty($smcFunc))
343
-		$smcFunc = array();
354
+	if (!defined('SMF')) {
355
+			define('SMF', 1);
356
+	}
357
+	if (empty($smcFunc)) {
358
+			$smcFunc = array();
359
+	}
344 360
 
345 361
 	$modSettings['disableQueryCheck'] = true;
346 362
 
@@ -348,8 +364,9 @@  discard block
 block discarded – undo
348 364
 	if (!$db_connection)
349 365
 	{
350 366
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
351
-		if (version_compare(PHP_VERSION, '5', '<'))
352
-			require_once($sourcedir . '/Subs-Compat.php');
367
+		if (version_compare(PHP_VERSION, '5', '<')) {
368
+					require_once($sourcedir . '/Subs-Compat.php');
369
+		}
353 370
 
354 371
 		$db_options = array('persist' => $db_persist);
355 372
 		$port = '';
@@ -360,19 +377,20 @@  discard block
 block discarded – undo
360 377
 			if ($db_type == 'mysql')
361 378
 			{
362 379
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
363
-			}
364
-			elseif ($db_type == 'postgresql')
380
+			} elseif ($db_type == 'postgresql')
365 381
 			{
366 382
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
367 383
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
368 384
 			}
369 385
 		}
370 386
 
371
-		if (!empty($port))
372
-			$db_options['port'] = $port;
387
+		if (!empty($port)) {
388
+					$db_options['port'] = $port;
389
+		}
373 390
 
374
-		if (!$db_connection)
375
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
391
+		if (!$db_connection) {
392
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
393
+		}
376 394
 	}
377 395
 }
378 396
 
@@ -400,8 +418,9 @@  discard block
 block discarded – undo
400 418
 		// @todo REMOVE THIS!!
401 419
 		else
402 420
 		{
403
-			if (function_exists('doStep' . $_GET['step']))
404
-				call_user_func('doStep' . $_GET['step']);
421
+			if (function_exists('doStep' . $_GET['step'])) {
422
+							call_user_func('doStep' . $_GET['step']);
423
+			}
405 424
 		}
406 425
 		// Show the footer.
407 426
 		template_install_below();
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 	$incontext['sub_template'] = 'welcome_message';
420 439
 
421 440
 	// Done the submission?
422
-	if (isset($_POST['contbutt']))
423
-		return true;
441
+	if (isset($_POST['contbutt'])) {
442
+			return true;
443
+	}
424 444
 
425 445
 	// See if we think they have already installed it?
426 446
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -428,14 +448,17 @@  discard block
 block discarded – undo
428 448
 		$probably_installed = 0;
429 449
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
430 450
 		{
431
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
432
-				$probably_installed++;
433
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
434
-				$probably_installed++;
451
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
452
+							$probably_installed++;
453
+			}
454
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
455
+							$probably_installed++;
456
+			}
435 457
 		}
436 458
 
437
-		if ($probably_installed == 2)
438
-			$incontext['warning'] = $txt['error_already_installed'];
459
+		if ($probably_installed == 2) {
460
+					$incontext['warning'] = $txt['error_already_installed'];
461
+		}
439 462
 	}
440 463
 
441 464
 	// Is some database support even compiled in?
@@ -450,36 +473,43 @@  discard block
 block discarded – undo
450 473
 				$databases[$key]['supported'] = false;
451 474
 				$notFoundSQLFile = true;
452 475
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
476
+			} else {
477
+							$incontext['supported_databases'][] = $db;
453 478
 			}
454
-			else
455
-				$incontext['supported_databases'][] = $db;
456 479
 		}
457 480
 	}
458 481
 
459 482
 	// Check the PHP version.
460
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
461
-		$error = 'error_php_too_low';
483
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
484
+			$error = 'error_php_too_low';
485
+	}
462 486
 	// Make sure we have a supported database
463
-	elseif (empty($incontext['supported_databases']))
464
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
487
+	elseif (empty($incontext['supported_databases'])) {
488
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
489
+	}
465 490
 	// How about session support?  Some crazy sysadmin remove it?
466
-	elseif (!function_exists('session_start'))
467
-		$error = 'error_session_missing';
491
+	elseif (!function_exists('session_start')) {
492
+			$error = 'error_session_missing';
493
+	}
468 494
 	// Make sure they uploaded all the files.
469
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
470
-		$error = 'error_missing_files';
495
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
496
+			$error = 'error_missing_files';
497
+	}
471 498
 	// Very simple check on the session.save_path for Windows.
472 499
 	// @todo Move this down later if they don't use database-driven sessions?
473
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
474
-		$error = 'error_session_save_path';
500
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
501
+			$error = 'error_session_save_path';
502
+	}
475 503
 
476 504
 	// Since each of the three messages would look the same, anyway...
477
-	if (isset($error))
478
-		$incontext['error'] = $txt[$error];
505
+	if (isset($error)) {
506
+			$incontext['error'] = $txt[$error];
507
+	}
479 508
 
480 509
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
481
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
482
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
510
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
511
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
512
+	}
483 513
 
484 514
 	return false;
485 515
 }
@@ -505,12 +535,14 @@  discard block
 block discarded – undo
505 535
 		'db_last_error.php',
506 536
 	);
507 537
 
508
-	foreach ($incontext['detected_languages'] as $lang => $temp)
509
-		$extra_files[] = 'Themes/default/languages/' . $lang;
538
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
539
+			$extra_files[] = 'Themes/default/languages/' . $lang;
540
+	}
510 541
 
511 542
 	// With mod_security installed, we could attempt to fix it with .htaccess.
512
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
513
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
543
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
544
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
545
+	}
514 546
 
515 547
 	$failed_files = array();
516 548
 
@@ -526,12 +558,14 @@  discard block
 block discarded – undo
526 558
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
527 559
 
528 560
 				// Well, 755 hopefully worked... if not, try 777.
529
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
530
-					$failed_files[] = $file;
561
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
562
+									$failed_files[] = $file;
563
+				}
531 564
 			}
532 565
 		}
533
-		foreach ($extra_files as $file)
534
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
566
+		foreach ($extra_files as $file) {
567
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
568
+		}
535 569
 	}
536 570
 	// Windows is trickier.  Let's try opening for r+...
537 571
 	else
@@ -541,30 +575,35 @@  discard block
 block discarded – undo
541 575
 		foreach ($writable_files as $file)
542 576
 		{
543 577
 			// Folders can't be opened for write... but the index.php in them can ;)
544
-			if (is_dir(dirname(__FILE__) . '/' . $file))
545
-				$file .= '/index.php';
578
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
579
+							$file .= '/index.php';
580
+			}
546 581
 
547 582
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
548 583
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
549 584
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
550 585
 
551 586
 			// Hmm, okay, try just for write in that case...
552
-			if (!is_resource($fp))
553
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
587
+			if (!is_resource($fp)) {
588
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
589
+			}
554 590
 
555
-			if (!is_resource($fp))
556
-				$failed_files[] = $file;
591
+			if (!is_resource($fp)) {
592
+							$failed_files[] = $file;
593
+			}
557 594
 
558 595
 			@fclose($fp);
559 596
 		}
560
-		foreach ($extra_files as $file)
561
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
597
+		foreach ($extra_files as $file) {
598
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
599
+		}
562 600
 	}
563 601
 
564 602
 	$failure = count($failed_files) >= 1;
565 603
 
566
-	if (!isset($_SERVER))
567
-		return !$failure;
604
+	if (!isset($_SERVER)) {
605
+			return !$failure;
606
+	}
568 607
 
569 608
 	// Put the list into context.
570 609
 	$incontext['failed_files'] = $failed_files;
@@ -612,19 +651,23 @@  discard block
 block discarded – undo
612 651
 
613 652
 		if (!isset($ftp) || $ftp->error !== false)
614 653
 		{
615
-			if (!isset($ftp))
616
-				$ftp = new ftp_connection(null);
654
+			if (!isset($ftp)) {
655
+							$ftp = new ftp_connection(null);
656
+			}
617 657
 			// Save the error so we can mess with listing...
618
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
619
-				$incontext['ftp_errors'][] = $ftp->last_message;
658
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
659
+							$incontext['ftp_errors'][] = $ftp->last_message;
660
+			}
620 661
 
621 662
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
622 663
 
623
-			if (empty($_POST['ftp_path']) && $found_path)
624
-				$_POST['ftp_path'] = $detect_path;
664
+			if (empty($_POST['ftp_path']) && $found_path) {
665
+							$_POST['ftp_path'] = $detect_path;
666
+			}
625 667
 
626
-			if (!isset($_POST['ftp_username']))
627
-				$_POST['ftp_username'] = $username;
668
+			if (!isset($_POST['ftp_username'])) {
669
+							$_POST['ftp_username'] = $username;
670
+			}
628 671
 
629 672
 			// Set the username etc, into context.
630 673
 			$incontext['ftp'] = array(
@@ -636,8 +679,7 @@  discard block
 block discarded – undo
636 679
 			);
637 680
 
638 681
 			return false;
639
-		}
640
-		else
682
+		} else
641 683
 		{
642 684
 			$_SESSION['installer_temp_ftp'] = array(
643 685
 				'server' => $_POST['ftp_server'],
@@ -651,10 +693,12 @@  discard block
 block discarded – undo
651 693
 
652 694
 			foreach ($failed_files as $file)
653 695
 			{
654
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
655
-					$ftp->chmod($file, 0755);
656
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
657
-					$ftp->chmod($file, 0777);
696
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
697
+									$ftp->chmod($file, 0755);
698
+				}
699
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
700
+									$ftp->chmod($file, 0777);
701
+				}
658 702
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
659 703
 				{
660 704
 					$failed_files_updated[] = $file;
@@ -710,15 +754,17 @@  discard block
 block discarded – undo
710 754
 
711 755
 			if (!$foundOne)
712 756
 			{
713
-				if (isset($db['default_host']))
714
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
757
+				if (isset($db['default_host'])) {
758
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
759
+				}
715 760
 				if (isset($db['default_user']))
716 761
 				{
717 762
 					$incontext['db']['user'] = ini_get($db['default_user']);
718 763
 					$incontext['db']['name'] = ini_get($db['default_user']);
719 764
 				}
720
-				if (isset($db['default_password']))
721
-					$incontext['db']['pass'] = ini_get($db['default_password']);
765
+				if (isset($db['default_password'])) {
766
+									$incontext['db']['pass'] = ini_get($db['default_password']);
767
+				}
722 768
 
723 769
 				// For simplicity and less confusion, leave the port blank by default
724 770
 				$incontext['db']['port'] = '';
@@ -737,10 +783,10 @@  discard block
 block discarded – undo
737 783
 		$incontext['db']['server'] = $_POST['db_server'];
738 784
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
739 785
 
740
-		if (!empty($_POST['db_port']))
741
-			$incontext['db']['port'] = $_POST['db_port'];
742
-	}
743
-	else
786
+		if (!empty($_POST['db_port'])) {
787
+					$incontext['db']['port'] = $_POST['db_port'];
788
+		}
789
+	} else
744 790
 	{
745 791
 		$incontext['db']['prefix'] = 'smf_';
746 792
 	}
@@ -776,10 +822,11 @@  discard block
 block discarded – undo
776 822
 		if (!empty($_POST['db_port']))
777 823
 		{
778 824
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
779
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
780
-				$vars['db_port'] = (int) $_POST['db_port'];
781
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
782
-				$vars['db_port'] = (int) $_POST['db_port'];
825
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
826
+							$vars['db_port'] = (int) $_POST['db_port'];
827
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
828
+							$vars['db_port'] = (int) $_POST['db_port'];
829
+			}
783 830
 		}
784 831
 
785 832
 		// God I hope it saved!
@@ -792,8 +839,9 @@  discard block
 block discarded – undo
792 839
 		// Make sure it works.
793 840
 		require(dirname(__FILE__) . '/Settings.php');
794 841
 
795
-		if (empty($sourcedir))
796
-			$sourcedir = dirname(__FILE__) . '/Sources';
842
+		if (empty($sourcedir)) {
843
+					$sourcedir = dirname(__FILE__) . '/Sources';
844
+		}
797 845
 
798 846
 		// Better find the database file!
799 847
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -803,18 +851,21 @@  discard block
 block discarded – undo
803 851
 		}
804 852
 
805 853
 		// Now include it for database functions!
806
-		if (!defined('SMF'))
807
-			define('SMF', 1);
854
+		if (!defined('SMF')) {
855
+					define('SMF', 1);
856
+		}
808 857
 
809 858
 		$modSettings['disableQueryCheck'] = true;
810
-		if (empty($smcFunc))
811
-			$smcFunc = array();
859
+		if (empty($smcFunc)) {
860
+					$smcFunc = array();
861
+		}
812 862
 
813 863
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
814 864
 
815 865
 		// What - running PHP4? The shame!
816
-		if (version_compare(PHP_VERSION, '5', '<'))
817
-			require_once($sourcedir . '/Subs-Compat.php');
866
+		if (version_compare(PHP_VERSION, '5', '<')) {
867
+					require_once($sourcedir . '/Subs-Compat.php');
868
+		}
818 869
 
819 870
 		// Attempt a connection.
820 871
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -902,12 +953,14 @@  discard block
 block discarded – undo
902 953
 	$incontext['page_title'] = $txt['install_settings'];
903 954
 
904 955
 	// Let's see if we got the database type correct.
905
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
906
-		$db_type = $_POST['db_type'];
956
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
957
+			$db_type = $_POST['db_type'];
958
+	}
907 959
 
908 960
 	// Else we'd better be able to get the connection.
909
-	else
910
-		load_database();
961
+	else {
962
+			load_database();
963
+	}
911 964
 
912 965
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
913 966
 
@@ -927,12 +980,14 @@  discard block
 block discarded – undo
927 980
 	// Submitting?
928 981
 	if (isset($_POST['boardurl']))
929 982
 	{
930
-		if (substr($_POST['boardurl'], -10) == '/index.php')
931
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
932
-		elseif (substr($_POST['boardurl'], -1) == '/')
933
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
934
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
935
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
983
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
984
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
985
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
986
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
987
+		}
988
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
989
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
990
+		}
936 991
 
937 992
 		// Save these variables.
938 993
 		$vars = array(
@@ -971,10 +1026,10 @@  discard block
 block discarded – undo
971 1026
 			{
972 1027
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
973 1028
 				return false;
974
-			}
975
-			else
976
-				// Set the character set here.
1029
+			} else {
1030
+							// Set the character set here.
977 1031
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1032
+			}
978 1033
 		}
979 1034
 
980 1035
 		// Good, skip on.
@@ -994,8 +1049,9 @@  discard block
 block discarded – undo
994 1049
 	$incontext['continue'] = 1;
995 1050
 
996 1051
 	// Already done?
997
-	if (isset($_POST['pop_done']))
998
-		return true;
1052
+	if (isset($_POST['pop_done'])) {
1053
+			return true;
1054
+	}
999 1055
 
1000 1056
 	// Reload settings.
1001 1057
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1013,8 +1069,9 @@  discard block
 block discarded – undo
1013 1069
 	$modSettings = array();
1014 1070
 	if ($result !== false)
1015 1071
 	{
1016
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1017
-			$modSettings[$row['variable']] = $row['value'];
1072
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1073
+					$modSettings[$row['variable']] = $row['value'];
1074
+		}
1018 1075
 		$smcFunc['db_free_result']($result);
1019 1076
 
1020 1077
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1027,20 +1084,22 @@  discard block
 block discarded – undo
1027 1084
 	$modSettings['disableQueryCheck'] = true;
1028 1085
 
1029 1086
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1030
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1031
-		$smcFunc['db_query']('', '
1087
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1088
+			$smcFunc['db_query']('', '
1032 1089
 			SET NAMES {string:utf8}',
1033 1090
 			array(
1034 1091
 				'db_error_skip' => true,
1035 1092
 				'utf8' => 'utf8',
1036 1093
 			)
1037 1094
 		);
1095
+	}
1038 1096
 
1039 1097
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1040
-	if (substr(__DIR__, -1) == '\\')
1041
-		$attachdir = __DIR__ . 'attachments';
1042
-	else
1043
-		$attachdir = __DIR__ . '/attachments';
1098
+	if (substr(__DIR__, -1) == '\\') {
1099
+			$attachdir = __DIR__ . 'attachments';
1100
+	} else {
1101
+			$attachdir = __DIR__ . '/attachments';
1102
+	}
1044 1103
 
1045 1104
 	$replaces = array(
1046 1105
 		'{$db_prefix}' => $db_prefix,
@@ -1057,8 +1116,9 @@  discard block
 block discarded – undo
1057 1116
 
1058 1117
 	foreach ($txt as $key => $value)
1059 1118
 	{
1060
-		if (substr($key, 0, 8) == 'default_')
1061
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1119
+		if (substr($key, 0, 8) == 'default_') {
1120
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1121
+		}
1062 1122
 	}
1063 1123
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1064 1124
 
@@ -1073,8 +1133,9 @@  discard block
 block discarded – undo
1073 1133
 
1074 1134
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1075 1135
 		{
1076
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1077
-				$engines[] = $row['Engine'];
1136
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1137
+							$engines[] = $row['Engine'];
1138
+			}
1078 1139
 		}
1079 1140
 
1080 1141
 		// Done with this now
@@ -1098,8 +1159,7 @@  discard block
 block discarded – undo
1098 1159
 			$replaces['START TRANSACTION;'] = '';
1099 1160
 			$replaces['COMMIT;'] = '';
1100 1161
 		}
1101
-	}
1102
-	else
1162
+	} else
1103 1163
 	{
1104 1164
 		$has_innodb = false;
1105 1165
 	}
@@ -1121,21 +1181,24 @@  discard block
 block discarded – undo
1121 1181
 	foreach ($sql_lines as $count => $line)
1122 1182
 	{
1123 1183
 		// No comments allowed!
1124
-		if (substr(trim($line), 0, 1) != '#')
1125
-			$current_statement .= "\n" . rtrim($line);
1184
+		if (substr(trim($line), 0, 1) != '#') {
1185
+					$current_statement .= "\n" . rtrim($line);
1186
+		}
1126 1187
 
1127 1188
 		// Is this the end of the query string?
1128
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1129
-			continue;
1189
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1190
+					continue;
1191
+		}
1130 1192
 
1131 1193
 		// Does this table already exist?  If so, don't insert more data into it!
1132 1194
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1133 1195
 		{
1134 1196
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1135
-			if (!empty($matches[0]))
1136
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1137
-			else
1138
-				$incontext['sql_results']['insert_dups']++;
1197
+			if (!empty($matches[0])) {
1198
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1199
+			} else {
1200
+							$incontext['sql_results']['insert_dups']++;
1201
+			}
1139 1202
 
1140 1203
 			$current_statement = '';
1141 1204
 			continue;
@@ -1144,8 +1207,9 @@  discard block
 block discarded – undo
1144 1207
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1145 1208
 		{
1146 1209
 			// Use the appropriate function based on the DB type
1147
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1148
-				$db_errorno = $db_type . '_errno';
1210
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1211
+							$db_errorno = $db_type . '_errno';
1212
+			}
1149 1213
 
1150 1214
 			// Error 1050: Table already exists!
1151 1215
 			// @todo Needs to be made better!
@@ -1160,18 +1224,18 @@  discard block
 block discarded – undo
1160 1224
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1161 1225
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1162 1226
 			}
1163
-		}
1164
-		else
1227
+		} else
1165 1228
 		{
1166
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1167
-				$incontext['sql_results']['tables']++;
1168
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1229
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1230
+							$incontext['sql_results']['tables']++;
1231
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1169 1232
 			{
1170 1233
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1171
-				if (!empty($matches[0]))
1172
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1173
-				else
1174
-					$incontext['sql_results']['inserts']++;
1234
+				if (!empty($matches[0])) {
1235
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1236
+				} else {
1237
+									$incontext['sql_results']['inserts']++;
1238
+				}
1175 1239
 			}
1176 1240
 		}
1177 1241
 
@@ -1184,15 +1248,17 @@  discard block
 block discarded – undo
1184 1248
 	// Sort out the context for the SQL.
1185 1249
 	foreach ($incontext['sql_results'] as $key => $number)
1186 1250
 	{
1187
-		if ($number == 0)
1188
-			unset($incontext['sql_results'][$key]);
1189
-		else
1190
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1251
+		if ($number == 0) {
1252
+					unset($incontext['sql_results'][$key]);
1253
+		} else {
1254
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1255
+		}
1191 1256
 	}
1192 1257
 
1193 1258
 	// Make sure UTF will be used globally.
1194
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1195
-		$newSettings[] = array('global_character_set', 'UTF-8');
1259
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1260
+			$newSettings[] = array('global_character_set', 'UTF-8');
1261
+	}
1196 1262
 
1197 1263
 	// Maybe we can auto-detect better cookie settings?
1198 1264
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1203,16 +1269,20 @@  discard block
 block discarded – undo
1203 1269
 		$globalCookies = false;
1204 1270
 
1205 1271
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1206
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1207
-			$globalCookies = true;
1272
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1273
+					$globalCookies = true;
1274
+		}
1208 1275
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1209
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1210
-			$localCookies = true;
1276
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1277
+					$localCookies = true;
1278
+		}
1211 1279
 
1212
-		if ($globalCookies)
1213
-			$newSettings[] = array('globalCookies', '1');
1214
-		if ($localCookies)
1215
-			$newSettings[] = array('localCookies', '1');
1280
+		if ($globalCookies) {
1281
+					$newSettings[] = array('globalCookies', '1');
1282
+		}
1283
+		if ($localCookies) {
1284
+					$newSettings[] = array('localCookies', '1');
1285
+		}
1216 1286
 	}
1217 1287
 
1218 1288
 	// Are we allowing stat collection?
@@ -1230,16 +1300,17 @@  discard block
 block discarded – undo
1230 1300
 			fwrite($fp, $out);
1231 1301
 
1232 1302
 			$return_data = '';
1233
-			while (!feof($fp))
1234
-				$return_data .= fgets($fp, 128);
1303
+			while (!feof($fp)) {
1304
+							$return_data .= fgets($fp, 128);
1305
+			}
1235 1306
 
1236 1307
 			fclose($fp);
1237 1308
 
1238 1309
 			// Get the unique site ID.
1239 1310
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1240 1311
 
1241
-			if (!empty($ID[1]))
1242
-				$smcFunc['db_insert']('replace',
1312
+			if (!empty($ID[1])) {
1313
+							$smcFunc['db_insert']('replace',
1243 1314
 					$db_prefix . 'settings',
1244 1315
 					array('variable' => 'string', 'value' => 'string'),
1245 1316
 					array(
@@ -1248,11 +1319,12 @@  discard block
 block discarded – undo
1248 1319
 					),
1249 1320
 					array('variable')
1250 1321
 				);
1322
+			}
1251 1323
 		}
1252 1324
 	}
1253 1325
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1254
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1255
-		$smcFunc['db_query']('', '
1326
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1327
+			$smcFunc['db_query']('', '
1256 1328
 			DELETE FROM {db_prefix}settings
1257 1329
 			WHERE variable = {string:enable_sm_stats}',
1258 1330
 			array(
@@ -1260,20 +1332,23 @@  discard block
 block discarded – undo
1260 1332
 				'db_error_skip' => true,
1261 1333
 			)
1262 1334
 		);
1335
+	}
1263 1336
 
1264 1337
 	// Are we enabling SSL?
1265
-	if (!empty($_POST['force_ssl']))
1266
-		$newSettings[] = array('force_ssl', 2);
1338
+	if (!empty($_POST['force_ssl'])) {
1339
+			$newSettings[] = array('force_ssl', 2);
1340
+	}
1267 1341
 
1268 1342
 	// Setting a timezone is required.
1269 1343
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1270 1344
 	{
1271 1345
 		// Get PHP's default timezone, if set
1272 1346
 		$ini_tz = ini_get('date.timezone');
1273
-		if (!empty($ini_tz))
1274
-			$timezone_id = $ini_tz;
1275
-		else
1276
-			$timezone_id = '';
1347
+		if (!empty($ini_tz)) {
1348
+					$timezone_id = $ini_tz;
1349
+		} else {
1350
+					$timezone_id = '';
1351
+		}
1277 1352
 
1278 1353
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1279 1354
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1282,8 +1357,9 @@  discard block
 block discarded – undo
1282 1357
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1283 1358
 		}
1284 1359
 
1285
-		if (date_default_timezone_set($timezone_id))
1286
-			$newSettings[] = array('default_timezone', $timezone_id);
1360
+		if (date_default_timezone_set($timezone_id)) {
1361
+					$newSettings[] = array('default_timezone', $timezone_id);
1362
+		}
1287 1363
 	}
1288 1364
 
1289 1365
 	if (!empty($newSettings))
@@ -1314,16 +1390,18 @@  discard block
 block discarded – undo
1314 1390
 	}
1315 1391
 
1316 1392
 	// MySQL specific stuff
1317
-	if (substr($db_type, 0, 5) != 'mysql')
1318
-		return false;
1393
+	if (substr($db_type, 0, 5) != 'mysql') {
1394
+			return false;
1395
+	}
1319 1396
 
1320 1397
 	// Find database user privileges.
1321 1398
 	$privs = array();
1322 1399
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1323 1400
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1324 1401
 	{
1325
-		if ($row['Privilege'] == 'Alter')
1326
-			$privs[] = $row['Privilege'];
1402
+		if ($row['Privilege'] == 'Alter') {
1403
+					$privs[] = $row['Privilege'];
1404
+		}
1327 1405
 	}
1328 1406
 	$smcFunc['db_free_result']($get_privs);
1329 1407
 
@@ -1353,8 +1431,9 @@  discard block
 block discarded – undo
1353 1431
 	$incontext['continue'] = 1;
1354 1432
 
1355 1433
 	// Skipping?
1356
-	if (!empty($_POST['skip']))
1357
-		return true;
1434
+	if (!empty($_POST['skip'])) {
1435
+			return true;
1436
+	}
1358 1437
 
1359 1438
 	// Need this to check whether we need the database password.
1360 1439
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1367,18 +1446,22 @@  discard block
 block discarded – undo
1367 1446
 	// We need this to properly hash the password for Admin
1368 1447
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1369 1448
 			global $sourcedir;
1370
-			if (function_exists('mb_strtolower'))
1371
-				return mb_strtolower($string, 'UTF-8');
1449
+			if (function_exists('mb_strtolower')) {
1450
+							return mb_strtolower($string, 'UTF-8');
1451
+			}
1372 1452
 			require_once($sourcedir . '/Subs-Charset.php');
1373 1453
 			return utf8_strtolower($string);
1374 1454
 		};
1375 1455
 
1376
-	if (!isset($_POST['username']))
1377
-		$_POST['username'] = '';
1378
-	if (!isset($_POST['email']))
1379
-		$_POST['email'] = '';
1380
-	if (!isset($_POST['server_email']))
1381
-		$_POST['server_email'] = '';
1456
+	if (!isset($_POST['username'])) {
1457
+			$_POST['username'] = '';
1458
+	}
1459
+	if (!isset($_POST['email'])) {
1460
+			$_POST['email'] = '';
1461
+	}
1462
+	if (!isset($_POST['server_email'])) {
1463
+			$_POST['server_email'] = '';
1464
+	}
1382 1465
 
1383 1466
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1384 1467
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1397,8 +1480,9 @@  discard block
 block discarded – undo
1397 1480
 			'admin_group' => 1,
1398 1481
 		)
1399 1482
 	);
1400
-	if ($smcFunc['db_num_rows']($request) != 0)
1401
-		$incontext['skip'] = 1;
1483
+	if ($smcFunc['db_num_rows']($request) != 0) {
1484
+			$incontext['skip'] = 1;
1485
+	}
1402 1486
 	$smcFunc['db_free_result']($request);
1403 1487
 
1404 1488
 	// Trying to create an account?
@@ -1429,8 +1513,9 @@  discard block
 block discarded – undo
1429 1513
 		}
1430 1514
 
1431 1515
 		// Update the webmaster's email?
1432
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1433
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1516
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1517
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1518
+		}
1434 1519
 
1435 1520
 		// Work out whether we're going to have dodgy characters and remove them.
1436 1521
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1453,32 +1538,27 @@  discard block
 block discarded – undo
1453 1538
 			$smcFunc['db_free_result']($result);
1454 1539
 
1455 1540
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1456
-		}
1457
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1541
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1458 1542
 		{
1459 1543
 			// Try the previous step again.
1460 1544
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1461 1545
 			return false;
1462
-		}
1463
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1546
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1464 1547
 		{
1465 1548
 			// Try the previous step again.
1466 1549
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1467 1550
 			return false;
1468
-		}
1469
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1551
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1470 1552
 		{
1471 1553
 			// One step back, this time fill out a proper admin email address.
1472 1554
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1473 1555
 			return false;
1474
-		}
1475
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1556
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1476 1557
 		{
1477 1558
 			// One step back, this time fill out a proper admin email address.
1478 1559
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1479 1560
 			return false;
1480
-		}
1481
-		elseif ($_POST['username'] != '')
1561
+		} elseif ($_POST['username'] != '')
1482 1562
 		{
1483 1563
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1484 1564
 
@@ -1543,17 +1623,19 @@  discard block
 block discarded – undo
1543 1623
 	require_once($sourcedir . '/Subs-Auth.php');
1544 1624
 
1545 1625
 	// Bring a warning over.
1546
-	if (!empty($incontext['account_existed']))
1547
-		$incontext['warning'] = $incontext['account_existed'];
1626
+	if (!empty($incontext['account_existed'])) {
1627
+			$incontext['warning'] = $incontext['account_existed'];
1628
+	}
1548 1629
 
1549
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1550
-		$smcFunc['db_query']('', '
1630
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1631
+			$smcFunc['db_query']('', '
1551 1632
 			SET NAMES {string:db_character_set}',
1552 1633
 			array(
1553 1634
 				'db_character_set' => $db_character_set,
1554 1635
 				'db_error_skip' => true,
1555 1636
 			)
1556 1637
 		);
1638
+	}
1557 1639
 
1558 1640
 	// As track stats is by default enabled let's add some activity.
1559 1641
 	$smcFunc['db_insert']('ignore',
@@ -1574,14 +1656,16 @@  discard block
 block discarded – undo
1574 1656
 	// Only proceed if we can load the data.
1575 1657
 	if ($request)
1576 1658
 	{
1577
-		while ($row = $smcFunc['db_fetch_row']($request))
1578
-			$modSettings[$row[0]] = $row[1];
1659
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1660
+					$modSettings[$row[0]] = $row[1];
1661
+		}
1579 1662
 		$smcFunc['db_free_result']($request);
1580 1663
 	}
1581 1664
 
1582 1665
 	// Automatically log them in ;)
1583
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1584
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1666
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1667
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1668
+	}
1585 1669
 
1586 1670
 	$result = $smcFunc['db_query']('', '
1587 1671
 		SELECT value
@@ -1592,13 +1676,14 @@  discard block
 block discarded – undo
1592 1676
 			'db_error_skip' => true,
1593 1677
 		)
1594 1678
 	);
1595
-	if ($smcFunc['db_num_rows']($result) != 0)
1596
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1679
+	if ($smcFunc['db_num_rows']($result) != 0) {
1680
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1681
+	}
1597 1682
 	$smcFunc['db_free_result']($result);
1598 1683
 
1599
-	if (empty($db_sessions))
1600
-		$_SESSION['admin_time'] = time();
1601
-	else
1684
+	if (empty($db_sessions)) {
1685
+			$_SESSION['admin_time'] = time();
1686
+	} else
1602 1687
 	{
1603 1688
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1604 1689
 
@@ -1622,8 +1707,9 @@  discard block
 block discarded – undo
1622 1707
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1623 1708
 		function($string){
1624 1709
 			global $sourcedir;
1625
-			if (function_exists('mb_strtolower'))
1626
-				return mb_strtolower($string, 'UTF-8');
1710
+			if (function_exists('mb_strtolower')) {
1711
+							return mb_strtolower($string, 'UTF-8');
1712
+			}
1627 1713
 			require_once($sourcedir . '/Subs-Charset.php');
1628 1714
 			return utf8_strtolower($string);
1629 1715
 		};
@@ -1639,8 +1725,9 @@  discard block
 block discarded – undo
1639 1725
 		)
1640 1726
 	);
1641 1727
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1642
-	if ($smcFunc['db_num_rows']($request) > 0)
1643
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1728
+	if ($smcFunc['db_num_rows']($request) > 0) {
1729
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1730
+	}
1644 1731
 	$smcFunc['db_free_result']($request);
1645 1732
 
1646 1733
 	// Now is the perfect time to fetch the SM files.
@@ -1659,8 +1746,9 @@  discard block
 block discarded – undo
1659 1746
 
1660 1747
 	// Check if we need some stupid MySQL fix.
1661 1748
 	$server_version = $smcFunc['db_server_info']();
1662
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1663
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1749
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1750
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1751
+	}
1664 1752
 
1665 1753
 	// Some final context for the template.
1666 1754
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1680,8 +1768,9 @@  discard block
 block discarded – undo
1680 1768
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1681 1769
 
1682 1770
 	// @todo Do we just want to read the file in clean, and split it this way always?
1683
-	if (count($settingsArray) == 1)
1684
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1771
+	if (count($settingsArray) == 1) {
1772
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1773
+	}
1685 1774
 
1686 1775
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1687 1776
 	{
@@ -1696,19 +1785,22 @@  discard block
 block discarded – undo
1696 1785
 			continue;
1697 1786
 		}
1698 1787
 
1699
-		if (trim($settingsArray[$i]) == '?' . '>')
1700
-			$settingsArray[$i] = '';
1788
+		if (trim($settingsArray[$i]) == '?' . '>') {
1789
+					$settingsArray[$i] = '';
1790
+		}
1701 1791
 
1702 1792
 		// Don't trim or bother with it if it's not a variable.
1703
-		if (substr($settingsArray[$i], 0, 1) != '$')
1704
-			continue;
1793
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1794
+					continue;
1795
+		}
1705 1796
 
1706 1797
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1707 1798
 
1708
-		foreach ($vars as $var => $val)
1709
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1799
+		foreach ($vars as $var => $val) {
1800
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1710 1801
 			{
1711 1802
 				$comment = strstr($settingsArray[$i], '#');
1803
+		}
1712 1804
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1713 1805
 				unset($vars[$var]);
1714 1806
 			}
@@ -1718,36 +1810,41 @@  discard block
 block discarded – undo
1718 1810
 	if (!empty($vars))
1719 1811
 	{
1720 1812
 		$settingsArray[$i++] = '';
1721
-		foreach ($vars as $var => $val)
1722
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1813
+		foreach ($vars as $var => $val) {
1814
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1815
+		}
1723 1816
 	}
1724 1817
 
1725 1818
 	// Blank out the file - done to fix a oddity with some servers.
1726 1819
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1727
-	if (!$fp)
1728
-		return false;
1820
+	if (!$fp) {
1821
+			return false;
1822
+	}
1729 1823
 	fclose($fp);
1730 1824
 
1731 1825
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1732 1826
 
1733 1827
 	// Gotta have one of these ;)
1734
-	if (trim($settingsArray[0]) != '<?php')
1735
-		fwrite($fp, "<?php\n");
1828
+	if (trim($settingsArray[0]) != '<?php') {
1829
+			fwrite($fp, "<?php\n");
1830
+	}
1736 1831
 
1737 1832
 	$lines = count($settingsArray);
1738 1833
 	for ($i = 0; $i < $lines - 1; $i++)
1739 1834
 	{
1740 1835
 		// Don't just write a bunch of blank lines.
1741
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1742
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1836
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1837
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1838
+		}
1743 1839
 	}
1744 1840
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1745 1841
 	fclose($fp);
1746 1842
 
1747 1843
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1748 1844
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1749
-	if (function_exists('opcache_invalidate'))
1750
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1845
+	if (function_exists('opcache_invalidate')) {
1846
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1847
+	}
1751 1848
 
1752 1849
 	return true;
1753 1850
 }
@@ -1772,9 +1869,9 @@  discard block
 block discarded – undo
1772 1869
 	SecFilterScanPOST Off
1773 1870
 </IfModule>';
1774 1871
 
1775
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1776
-		return true;
1777
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1872
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1873
+			return true;
1874
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1778 1875
 	{
1779 1876
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1780 1877
 
@@ -1786,29 +1883,28 @@  discard block
 block discarded – undo
1786 1883
 				fwrite($ht_handle, $htaccess_addition);
1787 1884
 				fclose($ht_handle);
1788 1885
 				return true;
1886
+			} else {
1887
+							return false;
1789 1888
 			}
1790
-			else
1791
-				return false;
1889
+		} else {
1890
+					return true;
1792 1891
 		}
1793
-		else
1794
-			return true;
1795
-	}
1796
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1797
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1798
-	elseif (is_writable(dirname(__FILE__)))
1892
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1893
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1894
+	} elseif (is_writable(dirname(__FILE__)))
1799 1895
 	{
1800 1896
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1801 1897
 		{
1802 1898
 			fwrite($ht_handle, $htaccess_addition);
1803 1899
 			fclose($ht_handle);
1804 1900
 			return true;
1901
+		} else {
1902
+					return false;
1805 1903
 		}
1806
-		else
1904
+	} else {
1807 1905
 			return false;
1808 1906
 	}
1809
-	else
1810
-		return false;
1811
-}
1907
+	}
1812 1908
 
1813 1909
 function template_install_above()
1814 1910
 {
@@ -1846,9 +1942,10 @@  discard block
 block discarded – undo
1846 1942
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1847 1943
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1848 1944
 
1849
-		foreach ($incontext['detected_languages'] as $lang => $name)
1850
-			echo '
1945
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1946
+					echo '
1851 1947
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1948
+		}
1852 1949
 
1853 1950
 		echo '
1854 1951
 								</select>
@@ -1868,9 +1965,10 @@  discard block
 block discarded – undo
1868 1965
 						<h2>', $txt['upgrade_progress'], '</h2>
1869 1966
 						<ul>';
1870 1967
 
1871
-	foreach ($incontext['steps'] as $num => $step)
1872
-		echo '
1968
+	foreach ($incontext['steps'] as $num => $step) {
1969
+			echo '
1873 1970
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1971
+	}
1874 1972
 
1875 1973
 	echo '
1876 1974
 						</ul>
@@ -1895,20 +1993,23 @@  discard block
 block discarded – undo
1895 1993
 		echo '
1896 1994
 								<div>';
1897 1995
 
1898
-		if (!empty($incontext['continue']))
1899
-			echo '
1996
+		if (!empty($incontext['continue'])) {
1997
+					echo '
1900 1998
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1901
-		if (!empty($incontext['skip']))
1902
-			echo '
1999
+		}
2000
+		if (!empty($incontext['skip'])) {
2001
+					echo '
1903 2002
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2003
+		}
1904 2004
 		echo '
1905 2005
 								</div>';
1906 2006
 	}
1907 2007
 
1908 2008
 	// Show the closing form tag and other data only if not in the last step
1909
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1910
-		echo '
2009
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2010
+			echo '
1911 2011
 							</form>';
2012
+	}
1912 2013
 
1913 2014
 	echo '
1914 2015
 						</div>
@@ -1943,13 +2044,15 @@  discard block
 block discarded – undo
1943 2044
 		</div>';
1944 2045
 
1945 2046
 	// Show the warnings, or not.
1946
-	if (template_warning_divs())
1947
-		echo '
2047
+	if (template_warning_divs()) {
2048
+			echo '
1948 2049
 		<h3>', $txt['install_all_lovely'], '</h3>';
2050
+	}
1949 2051
 
1950 2052
 	// Say we want the continue button!
1951
-	if (empty($incontext['error']))
1952
-		$incontext['continue'] = 1;
2053
+	if (empty($incontext['error'])) {
2054
+			$incontext['continue'] = 1;
2055
+	}
1953 2056
 
1954 2057
 	// For the latest version stuff.
1955 2058
 	echo '
@@ -1983,8 +2086,8 @@  discard block
 block discarded – undo
1983 2086
 	global $txt, $incontext;
1984 2087
 
1985 2088
 	// Errors are very serious..
1986
-	if (!empty($incontext['error']))
1987
-		echo '
2089
+	if (!empty($incontext['error'])) {
2090
+			echo '
1988 2091
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1989 2092
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1990 2093
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1992,9 +2095,10 @@  discard block
 block discarded – undo
1992 2095
 				', $incontext['error'], '
1993 2096
 			</div>
1994 2097
 		</div>';
2098
+	}
1995 2099
 	// A warning message?
1996
-	elseif (!empty($incontext['warning']))
1997
-		echo '
2100
+	elseif (!empty($incontext['warning'])) {
2101
+			echo '
1998 2102
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1999 2103
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2000 2104
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2002,6 +2106,7 @@  discard block
 block discarded – undo
2002 2106
 				', $incontext['warning'], '
2003 2107
 			</div>
2004 2108
 		</div>';
2109
+	}
2005 2110
 
2006 2111
 	return empty($incontext['error']) && empty($incontext['warning']);
2007 2112
 }
@@ -2017,27 +2122,30 @@  discard block
 block discarded – undo
2017 2122
 			<li>', $incontext['failed_files']), '</li>
2018 2123
 		</ul>';
2019 2124
 
2020
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2021
-		echo '
2125
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2126
+			echo '
2022 2127
 		<hr>
2023 2128
 		<p>', $txt['chmod_linux_info'], '</p>
2024 2129
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2130
+	}
2025 2131
 
2026 2132
 	// This is serious!
2027
-	if (!template_warning_divs())
2028
-		return;
2133
+	if (!template_warning_divs()) {
2134
+			return;
2135
+	}
2029 2136
 
2030 2137
 	echo '
2031 2138
 		<hr>
2032 2139
 		<p>', $txt['ftp_setup_info'], '</p>';
2033 2140
 
2034
-	if (!empty($incontext['ftp_errors']))
2035
-		echo '
2141
+	if (!empty($incontext['ftp_errors'])) {
2142
+			echo '
2036 2143
 		<div class="error_message">
2037 2144
 			', $txt['error_ftp_no_connect'], '<br><br>
2038 2145
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2039 2146
 		</div>
2040 2147
 		<br>';
2148
+	}
2041 2149
 
2042 2150
 	echo '
2043 2151
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2097,17 +2205,17 @@  discard block
 block discarded – undo
2097 2205
 				<td>
2098 2206
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2099 2207
 
2100
-	foreach ($incontext['supported_databases'] as $key => $db)
2101
-			echo '
2208
+	foreach ($incontext['supported_databases'] as $key => $db) {
2209
+				echo '
2102 2210
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2211
+	}
2103 2212
 
2104 2213
 	echo '
2105 2214
 					</select>
2106 2215
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2107 2216
 				</td>
2108 2217
 			</tr>';
2109
-	}
2110
-	else
2218
+	} else
2111 2219
 	{
2112 2220
 		echo '
2113 2221
 			<tr style="display: none;">
@@ -2299,9 +2407,10 @@  discard block
 block discarded – undo
2299 2407
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2300 2408
 				<ul>';
2301 2409
 
2302
-		foreach ($incontext['failures'] as $line => $fail)
2303
-			echo '
2410
+		foreach ($incontext['failures'] as $line => $fail) {
2411
+					echo '
2304 2412
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2413
+		}
2305 2414
 
2306 2415
 		echo '
2307 2416
 				</ul>';
@@ -2362,15 +2471,16 @@  discard block
 block discarded – undo
2362 2471
 			</tr>
2363 2472
 		</table>';
2364 2473
 
2365
-	if ($incontext['require_db_confirm'])
2366
-		echo '
2474
+	if ($incontext['require_db_confirm']) {
2475
+			echo '
2367 2476
 		<h2>', $txt['user_settings_database'], '</h2>
2368 2477
 		<p>', $txt['user_settings_database_info'], '</p>
2369 2478
 
2370 2479
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2371 2480
 			<input type="password" name="password3" size="30" class="input_password" />
2372 2481
 		</div>';
2373
-}
2482
+	}
2483
+	}
2374 2484
 
2375 2485
 // Tell them it's done, and to delete.
2376 2486
 function template_delete_install()
@@ -2383,14 +2493,15 @@  discard block
 block discarded – undo
2383 2493
 	template_warning_divs();
2384 2494
 
2385 2495
 	// Install directory still writable?
2386
-	if ($incontext['dir_still_writable'])
2387
-		echo '
2496
+	if ($incontext['dir_still_writable']) {
2497
+			echo '
2388 2498
 		<em>', $txt['still_writable'], '</em><br>
2389 2499
 		<br>';
2500
+	}
2390 2501
 
2391 2502
 	// Don't show the box if it's like 99% sure it won't work :P.
2392
-	if ($incontext['probably_delete_install'])
2393
-		echo '
2503
+	if ($incontext['probably_delete_install']) {
2504
+			echo '
2394 2505
 		<div style="margin: 1ex; font-weight: bold;">
2395 2506
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2396 2507
 		</div>
@@ -2406,6 +2517,7 @@  discard block
 block discarded – undo
2406 2517
 			}
2407 2518
 		</script>
2408 2519
 		<br>';
2520
+	}
2409 2521
 
2410 2522
 	echo '
2411 2523
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.