Completed
Pull Request — release-2.1 (#5077)
by Mathias
06:33
created
Sources/ShowAttachments.php 1 patch
Braces   +59 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
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
  * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count.
@@ -40,11 +41,11 @@  discard block
 block discarded – undo
40 41
 
41 42
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
42 43
 	{
43
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
44
-			$modSettings['enableCompressedOutput'] = 0;
45
-
46
-		else
47
-			ob_start('ob_gzhandler');
44
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
45
+					$modSettings['enableCompressedOutput'] = 0;
46
+		} else {
47
+					ob_start('ob_gzhandler');
48
+		}
48 49
 	}
49 50
 
50 51
 	if (empty($modSettings['enableCompressedOutput']))
@@ -76,8 +77,9 @@  discard block
 block discarded – undo
76 77
 	}
77 78
 
78 79
 	// Use cache when possible.
79
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
80
-		list($file, $thumbFile) = $cache;
80
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
81
+			list($file, $thumbFile) = $cache;
82
+	}
81 83
 
82 84
 	// Get the info from the DB.
83 85
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -85,10 +87,9 @@  discard block
 block discarded – undo
85 87
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
86 88
 		$attachRequest = null;
87 89
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
88
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
89
-			$request = $attachRequest;
90
-
91
-		else
90
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
91
+					$request = $attachRequest;
92
+		} else
92 93
 		{
93 94
 			// Make sure this attachment is on this board and load its info while we are at it.
94 95
 			$request = $smcFunc['db_query']('', '
@@ -181,13 +182,15 @@  discard block
 block discarded – undo
181 182
 		}
182 183
 
183 184
 		// Cache it.
184
-		if (!empty($file) || !empty($thumbFile))
185
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), random_int(850, 900));
185
+		if (!empty($file) || !empty($thumbFile)) {
186
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), random_int(850, 900));
187
+		}
186 188
 	}
187 189
 
188 190
 	// Replace the normal file with its thumbnail if it has one!
189
-	if (!empty($showThumb) && !empty($thumbFile))
190
-		$file = $thumbFile;
191
+	if (!empty($showThumb) && !empty($thumbFile)) {
192
+			$file = $thumbFile;
193
+	}
191 194
 
192 195
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
193 196
 	if (!file_exists($file['filePath']))
@@ -237,8 +240,8 @@  discard block
 block discarded – undo
237 240
 	}
238 241
 
239 242
 	// Update the download counter (unless it's a thumbnail or resuming an incomplete download).
240
-	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0)
241
-		$smcFunc['db_query']('', '
243
+	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) {
244
+			$smcFunc['db_query']('', '
242 245
 			UPDATE {db_prefix}attachments
243 246
 			SET downloads = downloads + 1
244 247
 			WHERE id_attach = {int:id_attach}',
@@ -246,12 +249,14 @@  discard block
 block discarded – undo
246 249
 				'id_attach' => $attachId,
247 250
 			)
248 251
 		);
252
+	}
249 253
 
250 254
 	// Send the attachment headers.
251 255
 	header('pragma: ');
252 256
 
253
-	if (!isBrowser('gecko'))
254
-		header('content-transfer-encoding: binary');
257
+	if (!isBrowser('gecko')) {
258
+			header('content-transfer-encoding: binary');
259
+	}
255 260
 
256 261
 	header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
257 262
 	header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -260,18 +265,19 @@  discard block
 block discarded – undo
260 265
 	header('etag: ' . $eTag);
261 266
 
262 267
 	// Make sure the mime type warrants an inline display.
263
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
264
-		unset($_REQUEST['image']);
268
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
269
+			unset($_REQUEST['image']);
270
+	}
265 271
 
266 272
 	// Does this have a mime type?
267
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
268
-		header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
269
-
270
-	else
273
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
274
+			header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
275
+	} else
271 276
 	{
272 277
 		header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
273
-		if (isset($_REQUEST['image']))
274
-			unset($_REQUEST['image']);
278
+		if (isset($_REQUEST['image'])) {
279
+					unset($_REQUEST['image']);
280
+		}
275 281
 	}
276 282
 
277 283
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -279,24 +285,22 @@  discard block
 block discarded – undo
279 285
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
280 286
 
281 287
 	// Different browsers like different standards...
282
-	if (isBrowser('firefox'))
283
-		header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
284
-
285
-	elseif (isBrowser('opera'))
286
-		header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
287
-
288
-	elseif (isBrowser('ie'))
289
-		header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
290
-
291
-	else
292
-		header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"');
288
+	if (isBrowser('firefox')) {
289
+			header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
290
+	} elseif (isBrowser('opera')) {
291
+			header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
292
+	} elseif (isBrowser('ie')) {
293
+			header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
294
+	} else {
295
+			header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"');
296
+	}
293 297
 
294 298
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
295
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
296
-		header('cache-control: no-cache');
297
-
298
-	else
299
-		header('cache-control: max-age=' . (525600 * 60) . ', private');
299
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
300
+			header('cache-control: no-cache');
301
+	} else {
302
+			header('cache-control: max-age=' . (525600 * 60) . ', private');
303
+	}
300 304
 
301 305
 	// Multipart and resuming support
302 306
 	if (isset($_SERVER['HTTP_RANGE']))
@@ -304,9 +308,9 @@  discard block
 block discarded – undo
304 308
 		send_http_status(206);
305 309
 		header("content-length: $new_length");
306 310
 		header("content-range: bytes $range-$range_end/$size");
311
+	} else {
312
+			header("content-length: " . $size);
307 313
 	}
308
-	else
309
-		header("content-length: " . $size);
310 314
 
311 315
 
312 316
 	// Try to buy some time...
@@ -315,8 +319,9 @@  discard block
 block discarded – undo
315 319
 	// For multipart/resumable downloads, send the requested chunk(s) of the file
316 320
 	if (isset($_SERVER['HTTP_RANGE']))
317 321
 	{
318
-		while (@ob_get_level() > 0)
319
-			@ob_end_clean();
322
+		while (@ob_get_level() > 0) {
323
+					@ob_end_clean();
324
+		}
320 325
 
321 326
 		// 40 kilobytes is a good-ish amount
322 327
 		$chunksize = 40 * 1024;
@@ -340,8 +345,9 @@  discard block
 block discarded – undo
340 345
 	elseif ($size > 4194304)
341 346
 	{
342 347
 		// Forcibly end any output buffering going on.
343
-		while (@ob_get_level() > 0)
344
-			@ob_end_clean();
348
+		while (@ob_get_level() > 0) {
349
+					@ob_end_clean();
350
+		}
345 351
 
346 352
 		$fp = fopen($file['filePath'], 'rb');
347 353
 		while (!feof($fp))
@@ -353,8 +359,9 @@  discard block
 block discarded – undo
353 359
 	}
354 360
 
355 361
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
356
-	elseif (@readfile($file['filePath']) === null)
357
-		echo file_get_contents($file['filePath']);
362
+	elseif (@readfile($file['filePath']) === null) {
363
+			echo file_get_contents($file['filePath']);
364
+	}
358 365
 
359 366
 	die();
360 367
 }
Please login to merge, or discard this patch.
Sources/Subs-Sound.php 1 patch
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(send_http_status(400));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(send_http_status(400));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -42,16 +44,19 @@  discard block
 block discarded – undo
42 44
 	mt_srand(end($tmp));
43 45
 
44 46
 	// Try to see if there's a sound font in the user's language.
45
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
46
-		$sound_language = $user_info['language'];
47
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
48
+			$sound_language = $user_info['language'];
49
+	}
47 50
 
48 51
 	// English should be there.
49
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
50
-		$sound_language = 'english';
52
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
53
+			$sound_language = 'english';
54
+	}
51 55
 
52 56
 	// Guess not...
53
-	else
54
-		return false;
57
+	else {
58
+			return false;
59
+	}
55 60
 
56 61
 	// File names are in lower case so lets make sure that we are only using a lower case string
57 62
 	$word = strtolower($word);
@@ -61,20 +66,25 @@  discard block
 block discarded – undo
61 66
 	for ($i = 0; $i < strlen($word); $i++)
62 67
 	{
63 68
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
64
-		if (strpos($sound_letter, 'data') === false)
65
-			return false;
69
+		if (strpos($sound_letter, 'data') === false) {
70
+					return false;
71
+		}
66 72
 
67 73
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
68 74
 		switch ($word{$i} === 's' ? 0 : random_int(0, 2))
69 75
 		{
70
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
71
-					for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++)
72
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(random_int(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
76
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
77
+								for ($k = 0, $m = round(random_int(15, 25) / 10);
78
+			}
79
+			$k < $m; $k++) {
80
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(random_int(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
81
+					}
73 82
 			break;
74 83
 
75 84
 			case 1:
76
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
77
-					$sound_word .= (random_int(0, 3) == 0 ? '' : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (random_int(0, 3) == 0 ? $sound_letter{$j + 1} : '');
85
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
86
+									$sound_word .= (random_int(0, 3) == 0 ? '' : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (random_int(0, 3) == 0 ? $sound_letter{$j + 1} : '');
87
+				}
78 88
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
79 89
 			break;
80 90
 
@@ -82,10 +92,12 @@  discard block
 block discarded – undo
82 92
 				$shift = 0;
83 93
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
84 94
 				{
85
-					if (random_int(0, 10) === 0)
86
-						$shift += random_int(-3, 3);
87
-					for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++)
88
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
95
+					if (random_int(0, 10) === 0) {
96
+											$shift += random_int(-3, 3);
97
+					}
98
+					for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++) {
99
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
100
+					}
89 101
 				}
90 102
 			break;
91 103
 		}
Please login to merge, or discard this patch.
Sources/Subs-Graphics.php 1 patch
Braces   +240 added lines, -196 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
  * @version 2.1 Beta 4
19 19
  */
20 20
 
21
-if (!defined('SMF'))
21
+if (!defined('SMF')) {
22 22
 	die('No direct access...');
23
+}
23 24
 
24 25
 /**
25 26
  * downloads a file from a url and stores it locally for avatar use by id_member.
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
45 46
 
46 47
 	// Just making sure there is a non-zero member.
47
-	if (empty($memID))
48
-		return false;
48
+	if (empty($memID)) {
49
+			return false;
50
+	}
49 51
 
50 52
 	require_once($sourcedir . '/ManageAttachments.php');
51 53
 	removeAttachments(array('id_member' => $memID));
@@ -76,10 +78,11 @@  discard block
 block discarded – undo
76 78
 	$destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp';
77 79
 
78 80
 	// Resize it.
79
-	if (!empty($modSettings['avatar_download_png']))
80
-		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
81
-	else
82
-		$success = resizeImageFile($url, $destName, $max_width, $max_height);
81
+	if (!empty($modSettings['avatar_download_png'])) {
82
+			$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
83
+	} else {
84
+			$success = resizeImageFile($url, $destName, $max_width, $max_height);
85
+	}
83 86
 
84 87
 	// Remove the .tmp extension.
85 88
 	$destName = substr($destName, 0, -4);
@@ -108,11 +111,10 @@  discard block
 block discarded – undo
108 111
 				)
109 112
 			);
110 113
 			return true;
114
+		} else {
115
+					return false;
111 116
 		}
112
-		else
113
-			return false;
114
-	}
115
-	else
117
+	} else
116 118
 	{
117 119
 		$smcFunc['db_query']('', '
118 120
 			DELETE FROM {db_prefix}attachments
@@ -144,17 +146,18 @@  discard block
 block discarded – undo
144 146
 	$destName = $source . '_thumb.tmp';
145 147
 
146 148
 	// Do the actual resize.
147
-	if (!empty($modSettings['attachment_thumb_png']))
148
-		$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
149
-	else
150
-		$success = resizeImageFile($source, $destName, $max_width, $max_height);
149
+	if (!empty($modSettings['attachment_thumb_png'])) {
150
+			$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
151
+	} else {
152
+			$success = resizeImageFile($source, $destName, $max_width, $max_height);
153
+	}
151 154
 
152 155
 	// Okay, we're done with the temporary stuff.
153 156
 	$destName = substr($destName, 0, -4);
154 157
 
155
-	if ($success && @rename($destName . '.tmp', $destName))
156
-		return true;
157
-	else
158
+	if ($success && @rename($destName . '.tmp', $destName)) {
159
+			return true;
160
+	} else
158 161
 	{
159 162
 		@unlink($destName . '.tmp');
160 163
 		@touch($destName);
@@ -176,18 +179,21 @@  discard block
 block discarded – undo
176 179
 {
177 180
 	if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format))
178 181
 	{
179
-		if (file_exists($fileName . '.tmp'))
180
-			unlink($fileName . '.tmp');
182
+		if (file_exists($fileName . '.tmp')) {
183
+					unlink($fileName . '.tmp');
184
+		}
181 185
 
182 186
 		return false;
183 187
 	}
184 188
 
185
-	if (!unlink($fileName))
186
-		return false;
189
+	if (!unlink($fileName)) {
190
+			return false;
191
+	}
187 192
 
188
-	if (!rename($fileName . '.tmp', $fileName))
189
-		return false;
190
-}
193
+	if (!rename($fileName . '.tmp', $fileName)) {
194
+			return false;
195
+	}
196
+	}
191 197
 
192 198
 /**
193 199
  * Searches through the file to see if there's potentially harmful non-binary content.
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 function checkImageContents($fileName, $extensiveCheck = false)
201 207
 {
202 208
 	$fp = fopen($fileName, 'rb');
203
-	if (!$fp)
204
-		fatal_lang_error('attach_timeout');
209
+	if (!$fp) {
210
+			fatal_lang_error('attach_timeout');
211
+	}
205 212
 
206 213
 	$prev_chunk = '';
207 214
 	while (!feof($fp))
@@ -218,8 +225,7 @@  discard block
 block discarded – undo
218 225
 				fclose($fp);
219 226
 				return false;
220 227
 			}
221
-		}
222
-		else
228
+		} else
223 229
 		{
224 230
 			// Check for potential infection - focus on clues for inline php & flash.
225 231
 			// Will result in significantly fewer false positives than the paranoid check.
@@ -247,8 +253,9 @@  discard block
 block discarded – undo
247 253
 	global $gd2;
248 254
 
249 255
 	// Check to see if GD is installed and what version.
250
-	if (($extensionFunctions = get_extension_funcs('gd')) === false)
251
-		return false;
256
+	if (($extensionFunctions = get_extension_funcs('gd')) === false) {
257
+			return false;
258
+	}
252 259
 
253 260
 	// Also determine if GD2 is installed and store it in a global.
254 261
 	$gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor');
@@ -320,8 +327,9 @@  discard block
 block discarded – undo
320 327
 	global $sourcedir;
321 328
 
322 329
 	// Nothing to do without GD or IM/MW
323
-	if (!checkGD() && !checkImagick() && !checkMagickWand())
324
-		return false;
330
+	if (!checkGD() && !checkImagick() && !checkMagickWand()) {
331
+			return false;
332
+	}
325 333
 
326 334
 	static $default_formats = array(
327 335
 		'1' => 'gif',
@@ -341,38 +349,39 @@  discard block
 block discarded – undo
341 349
 		fclose($fp_destination);
342 350
 
343 351
 		$sizes = @getimagesize($destination);
344
-	}
345
-	elseif ($fp_destination)
352
+	} elseif ($fp_destination)
346 353
 	{
347 354
 		$sizes = @getimagesize($source);
348 355
 
349 356
 		$fp_source = fopen($source, 'rb');
350 357
 		if ($fp_source !== false)
351 358
 		{
352
-			while (!feof($fp_source))
353
-				fwrite($fp_destination, fread($fp_source, 8192));
359
+			while (!feof($fp_source)) {
360
+							fwrite($fp_destination, fread($fp_source, 8192));
361
+			}
354 362
 			fclose($fp_source);
363
+		} else {
364
+					$sizes = array(-1, -1, -1);
355 365
 		}
356
-		else
357
-			$sizes = array(-1, -1, -1);
358 366
 		fclose($fp_destination);
359 367
 	}
360 368
 	// We can't get to the file.
361
-	else
362
-		$sizes = array(-1, -1, -1);
369
+	else {
370
+			$sizes = array(-1, -1, -1);
371
+	}
363 372
 
364 373
 	// See if we have -or- can get the needed memory for this operation
365 374
 	// ImageMagick isn't subject to PHP's memory limits :)
366
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
367
-		return false;
375
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
376
+			return false;
377
+	}
368 378
 
369 379
 	// A known and supported format?
370 380
 	// @todo test PSD and gif.
371 381
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
372 382
 	{
373 383
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
374
-	}
375
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
384
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
376 385
 	{
377 386
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
378 387
 		if ($src_img = @$imagecreatefrom($destination))
@@ -425,14 +434,14 @@  discard block
 block discarded – undo
425 434
 			$dest_width = empty($max_width) ? $src_width : $max_width;
426 435
 			$dest_height = empty($max_height) ? $src_height : $max_height;
427 436
 
428
-			if ($default_formats[$preferred_format] == 'jpeg')
429
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
437
+			if ($default_formats[$preferred_format] == 'jpeg') {
438
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			}
430 440
 
431 441
 			$imagick->setImageFormat($default_formats[$preferred_format]);
432 442
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
433 443
 			$success = $imagick->writeImage($destName);
434
-		}
435
-		else
444
+		} else
436 445
 		{
437 446
 			$magick_wand = newMagickWand();
438 447
 			MagickReadImage($magick_wand, $destName);
@@ -441,8 +450,9 @@  discard block
 block discarded – undo
441 450
 			$dest_width = empty($max_width) ? $src_width : $max_width;
442 451
 			$dest_height = empty($max_height) ? $src_height : $max_height;
443 452
 
444
-			if ($default_formats[$preferred_format] == 'jpeg')
445
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
453
+			if ($default_formats[$preferred_format] == 'jpeg') {
454
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			}
446 456
 
447 457
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
448 458
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -450,8 +460,7 @@  discard block
 block discarded – undo
450 460
 		}
451 461
 
452 462
 		return !empty($success);
453
-	}
454
-	elseif (checkGD())
463
+	} elseif (checkGD())
455 464
 	{
456 465
 		$success = false;
457 466
 
@@ -462,8 +471,7 @@  discard block
 block discarded – undo
462 471
 			{
463 472
 				$dst_width = $max_width;
464 473
 				$dst_height = round($src_height * $max_width / $src_width);
465
-			}
466
-			elseif (!empty($max_height))
474
+			} elseif (!empty($max_height))
467 475
 			{
468 476
 				$dst_width = round($src_width * $max_height / $src_height);
469 477
 				$dst_height = $max_height;
@@ -481,44 +489,48 @@  discard block
 block discarded – undo
481 489
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
482 490
 					{
483 491
 						imagealphablending($dst_img, false);
484
-						if (function_exists('imagesavealpha'))
485
-							imagesavealpha($dst_img, true);
492
+						if (function_exists('imagesavealpha')) {
493
+													imagesavealpha($dst_img, true);
494
+						}
486 495
 					}
496
+				} else {
497
+									$dst_img = imagecreate($dst_width, $dst_height);
487 498
 				}
488
-				else
489
-					$dst_img = imagecreate($dst_width, $dst_height);
490 499
 
491 500
 				// Resize it!
492
-				if ($gd2)
493
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
494
-				else
495
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
501
+				if ($gd2) {
502
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				} else {
504
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				}
506
+			} else {
507
+							$dst_img = $src_img;
496 508
 			}
497
-			else
498
-				$dst_img = $src_img;
509
+		} else {
510
+					$dst_img = $src_img;
499 511
 		}
500
-		else
501
-			$dst_img = $src_img;
502 512
 
503 513
 		// Save the image as ...
504
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
505
-			$success = imagepng($dst_img, $destName);
506
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
507
-			$success = imagegif($dst_img, $destName);
508
-		elseif (function_exists('imagejpeg'))
509
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
514
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
515
+					$success = imagepng($dst_img, $destName);
516
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
517
+					$success = imagegif($dst_img, $destName);
518
+		} elseif (function_exists('imagejpeg')) {
519
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
520
+		}
510 521
 
511 522
 		// Free the memory.
512 523
 		imagedestroy($src_img);
513
-		if ($dst_img != $src_img)
514
-			imagedestroy($dst_img);
524
+		if ($dst_img != $src_img) {
525
+					imagedestroy($dst_img);
526
+		}
515 527
 
516 528
 		return $success;
517
-	}
518
-	else
519
-		// Without GD, no image resizing at all.
529
+	} else {
530
+			// Without GD, no image resizing at all.
520 531
 		return false;
521
-}
532
+	}
533
+	}
522 534
 
523 535
 /**
524 536
  * Copy image.
@@ -572,8 +584,9 @@  discard block
 block discarded – undo
572 584
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
573 585
 			if ($color == -1)
574 586
 			{
575
-				if ($palsize++ < 256)
576
-					imagecolorallocate($dst_img, $red, $green, $blue);
587
+				if ($palsize++ < 256) {
588
+									imagecolorallocate($dst_img, $red, $green, $blue);
589
+				}
577 590
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
578 591
 			}
579 592
 
@@ -603,13 +616,15 @@  discard block
 block discarded – undo
603 616
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
604 617
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
605 618
 
606
-		if ($header['type'] != 0x4D42)
607
-			return false;
619
+		if ($header['type'] != 0x4D42) {
620
+					return false;
621
+		}
608 622
 
609
-		if ($gd2)
610
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
611
-		else
612
-			$dst_img = imagecreate($info['width'], $info['height']);
623
+		if ($gd2) {
624
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
625
+		} else {
626
+					$dst_img = imagecreate($info['width'], $info['height']);
627
+		}
613 628
 
614 629
 		$palette_size = $header['offset'] - 54;
615 630
 		$info['ncolor'] = $palette_size / 4;
@@ -635,8 +650,9 @@  discard block
 block discarded – undo
635 650
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
636 651
 			$scan_line = fread($fp, $scan_line_size);
637 652
 
638
-			if (strlen($scan_line) < $scan_line_size)
639
-				continue;
653
+			if (strlen($scan_line) < $scan_line_size) {
654
+							continue;
655
+			}
640 656
 
641 657
 			if ($info['bits'] == 32)
642 658
 			{
@@ -654,14 +670,14 @@  discard block
 block discarded – undo
654 670
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
655 671
 
656 672
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
657
-						if ($color == -1)
658
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
673
+						if ($color == -1) {
674
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						}
659 676
 					}
660 677
 
661 678
 					imagesetpixel($dst_img, $x, $y, $color);
662 679
 				}
663
-			}
664
-			elseif ($info['bits'] == 24)
680
+			} elseif ($info['bits'] == 24)
665 681
 			{
666 682
 				$x = 0;
667 683
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -676,14 +692,14 @@  discard block
 block discarded – undo
676 692
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
677 693
 
678 694
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
679
-						if ($color == -1)
680
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
695
+						if ($color == -1) {
696
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						}
681 698
 					}
682 699
 
683 700
 					imagesetpixel($dst_img, $x, $y, $color);
684 701
 				}
685
-			}
686
-			elseif ($info['bits'] == 16)
702
+			} elseif ($info['bits'] == 16)
687 703
 			{
688 704
 				$x = 0;
689 705
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -704,20 +720,20 @@  discard block
 block discarded – undo
704 720
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
705 721
 
706 722
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
707
-						if ($color == -1)
708
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
723
+						if ($color == -1) {
724
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						}
709 726
 					}
710 727
 
711 728
 					imagesetpixel($dst_img, $x, $y, $color);
712 729
 				}
713
-			}
714
-			elseif ($info['bits'] == 8)
730
+			} elseif ($info['bits'] == 8)
715 731
 			{
716 732
 				$x = 0;
717
-				for ($j = 0; $j < $scan_line_size; $x++)
718
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
719
-			}
720
-			elseif ($info['bits'] == 4)
733
+				for ($j = 0; $j < $scan_line_size; $x++) {
734
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
735
+				}
736
+			} elseif ($info['bits'] == 4)
721 737
 			{
722 738
 				$x = 0;
723 739
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -726,11 +742,11 @@  discard block
 block discarded – undo
726 742
 
727 743
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
728 744
 
729
-					if (++$x < $info['width'])
730
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
745
+					if (++$x < $info['width']) {
746
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
747
+					}
731 748
 				}
732
-			}
733
-			elseif ($info['bits'] == 1)
749
+			} elseif ($info['bits'] == 1)
734 750
 			{
735 751
 				$x = 0;
736 752
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -741,8 +757,9 @@  discard block
 block discarded – undo
741 757
 
742 758
 					for ($shift = 1; $shift < 8; $shift++)
743 759
 					{
744
-						if (++$x < $info['width'])
745
-							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
760
+						if (++$x < $info['width']) {
761
+													imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
762
+						}
746 763
 					}
747 764
 				}
748 765
 			}
@@ -766,15 +783,18 @@  discard block
 block discarded – undo
766 783
  */
767 784
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
768 785
 {
769
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
770
-		return false;
786
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
787
+			return false;
788
+	}
771 789
 
772 790
 	$fd = $gif->get_png_data($background_color);
773
-	if (strlen($fd) <= 0)
774
-		return false;
791
+	if (strlen($fd) <= 0) {
792
+			return false;
793
+	}
775 794
 
776
-	if (!($fh = @fopen($lpszFileName, 'wb')))
777
-		return false;
795
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
796
+			return false;
797
+	}
778 798
 
779 799
 	@fwrite($fh, $fd, strlen($fd));
780 800
 	@fflush($fh);
@@ -801,8 +821,9 @@  discard block
 block discarded – undo
801 821
 	// What type are we going to be doing?
802 822
 	$imageType = $modSettings['visual_verification_type'];
803 823
 	// Special case to allow the admin center to show samples.
804
-	if ($user_info['is_admin'] && isset($_GET['type']))
805
-		$imageType = (int) $_GET['type'];
824
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
825
+			$imageType = (int) $_GET['type'];
826
+	}
806 827
 
807 828
 	// Some quick references for what we do.
808 829
 	// Do we show no, low or high noise?
@@ -836,25 +857,28 @@  discard block
 block discarded – undo
836 857
 	$character_spacing = 1;
837 858
 
838 859
 	// What color is the background - generally white unless we're on "hard".
839
-	if ($simpleBGColor)
840
-		$background_color = array(255, 255, 255);
841
-	else
842
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
860
+	if ($simpleBGColor) {
861
+			$background_color = array(255, 255, 255);
862
+	} else {
863
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
864
+	}
843 865
 
844 866
 	// The color of the characters shown (red, green, blue).
845
-	if ($simpleFGColor)
846
-		$foreground_color = array(0, 0, 0);
847
-	else
867
+	if ($simpleFGColor) {
868
+			$foreground_color = array(0, 0, 0);
869
+	} else
848 870
 	{
849 871
 		$foreground_color = array(64, 101, 136);
850 872
 
851 873
 		// Has the theme author requested a custom color?
852
-		if (isset($settings['verification_foreground']))
853
-			$foreground_color = $settings['verification_foreground'];
874
+		if (isset($settings['verification_foreground'])) {
875
+					$foreground_color = $settings['verification_foreground'];
876
+		}
854 877
 	}
855 878
 
856
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
857
-		return false;
879
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
880
+			return false;
881
+	}
858 882
 
859 883
 	// Get a list of the available fonts.
860 884
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -865,25 +889,28 @@  discard block
 block discarded – undo
865 889
 	{
866 890
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
867 891
 		{
868
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
869
-				$font_list[] = $entry;
892
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
893
+							$font_list[] = $entry;
894
+			}
895
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
896
+					$ttfont_list[] = $entry;
870 897
 		}
871
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
872
-			$ttfont_list[] = $entry;
873 898
 	}
874 899
 
875
-	if (empty($font_list))
876
-		return false;
900
+	if (empty($font_list)) {
901
+			return false;
902
+	}
877 903
 
878 904
 	// For non-hard things don't even change fonts.
879 905
 	if (!$varyFonts)
880 906
 	{
881 907
 		$font_list = array($font_list[0]);
882 908
 		// Try use Screenge if we can - it looks good!
883
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
884
-			$ttfont_list = array('AnonymousPro.ttf');
885
-		else
886
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
909
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
910
+					$ttfont_list = array('AnonymousPro.ttf');
911
+		} else {
912
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
913
+		}
887 914
 	}
888 915
 
889 916
 	// Create a list of characters to be shown.
@@ -900,14 +927,16 @@  discard block
 block discarded – undo
900 927
 	}
901 928
 
902 929
 	// Load all fonts and determine the maximum font height.
903
-	foreach ($loaded_fonts as $font_index => $dummy)
904
-		$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
930
+	foreach ($loaded_fonts as $font_index => $dummy) {
931
+			$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
932
+	}
905 933
 
906 934
 	// Determine the dimensions of each character.
907
-	if ($imageType == 4 || $imageType == 5)
908
-		$extra = 80;
909
-	else
910
-		$extra = 45;
935
+	if ($imageType == 4 || $imageType == 5) {
936
+			$extra = 80;
937
+	} else {
938
+			$extra = 45;
939
+	}
911 940
 
912 941
 	$total_width = $character_spacing * strlen($code) + $extra;
913 942
 	$max_height = 0;
@@ -928,13 +957,15 @@  discard block
 block discarded – undo
928 957
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
929 958
 
930 959
 	// Randomize the foreground color a little.
931
-	for ($i = 0; $i < 3; $i++)
932
-		$foreground_color[$i] = random_int(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
960
+	for ($i = 0; $i < 3; $i++) {
961
+			$foreground_color[$i] = random_int(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
962
+	}
933 963
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
934 964
 
935 965
 	// Color for the dots.
936
-	for ($i = 0; $i < 3; $i++)
937
-		$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? random_int(0, max($foreground_color[$i] - 20, 0)) : random_int(min($foreground_color[$i] + 20, 255), 255);
966
+	for ($i = 0; $i < 3; $i++) {
967
+			$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? random_int(0, max($foreground_color[$i] - 20, 0)) : random_int(min($foreground_color[$i] + 20, 255), 255);
968
+	}
938 969
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
939 970
 
940 971
 	// Some squares/rectanges for new extreme level
@@ -960,10 +991,11 @@  discard block
 block discarded – undo
960 991
 			$can_do_ttf = function_exists('imagettftext');
961 992
 
962 993
 			// How much rotation will we give?
963
-			if ($rotationType == 'none')
964
-				$angle = 0;
965
-			else
966
-				$angle = random_int(-100, 100) / ($rotationType == 'high' ? 6 : 10);
994
+			if ($rotationType == 'none') {
995
+							$angle = 0;
996
+			} else {
997
+							$angle = random_int(-100, 100) / ($rotationType == 'high' ? 6 : 10);
998
+			}
967 999
 
968 1000
 			// What color shall we do it?
969 1001
 			if ($fontColorType == 'cyclic')
@@ -977,51 +1009,56 @@  discard block
 block discarded – undo
977 1009
 					array(0, 0, 0),
978 1010
 					array(143, 39, 31),
979 1011
 				);
980
-				if (!isset($last_index))
981
-					$last_index = -1;
1012
+				if (!isset($last_index)) {
1013
+									$last_index = -1;
1014
+				}
982 1015
 				$new_index = $last_index;
983
-				while ($last_index == $new_index)
984
-					$new_index = random_int(0, count($colors) - 1);
1016
+				while ($last_index == $new_index) {
1017
+									$new_index = random_int(0, count($colors) - 1);
1018
+				}
985 1019
 				$char_fg_color = $colors[$new_index];
986 1020
 				$last_index = $new_index;
1021
+			} elseif ($fontColorType == 'random') {
1022
+							$char_fg_color = array(random_int(max($foreground_color[0] - 2, 0), $foreground_color[0]), random_int(max($foreground_color[1] - 2, 0), $foreground_color[1]), random_int(max($foreground_color[2] - 2, 0), $foreground_color[2]));
1023
+			} else {
1024
+							$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
987 1025
 			}
988
-			elseif ($fontColorType == 'random')
989
-				$char_fg_color = array(random_int(max($foreground_color[0] - 2, 0), $foreground_color[0]), random_int(max($foreground_color[1] - 2, 0), $foreground_color[1]), random_int(max($foreground_color[2] - 2, 0), $foreground_color[2]));
990
-			else
991
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
992 1026
 
993 1027
 			if (!empty($can_do_ttf))
994 1028
 			{
995 1029
 				// GD2 handles font size differently.
996
-				if ($fontSizeRandom)
997
-					$font_size = $gd2 ? random_int(17, 19) : random_int(18, 25);
998
-				else
999
-					$font_size = $gd2 ? 18 : 24;
1030
+				if ($fontSizeRandom) {
1031
+									$font_size = $gd2 ? random_int(17, 19) : random_int(18, 25);
1032
+				} else {
1033
+									$font_size = $gd2 ? 18 : 24;
1034
+				}
1000 1035
 
1001 1036
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
1002 1037
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1003 1038
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? random_int(2, 8) : ($fontVerPos == 'random' ? random_int(3, 5) : 5));
1004 1039
 
1005 1040
 				// What font face?
1006
-				if (!empty($ttfont_list))
1007
-					$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)];
1041
+				if (!empty($ttfont_list)) {
1042
+									$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)];
1043
+				}
1008 1044
 
1009 1045
 				// What color are we to do it in?
1010 1046
 				$is_reverse = $showReverseChars ? random_int(0, 1) : false;
1011 1047
 				$char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]);
1012 1048
 
1013 1049
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1014
-				if (empty($fontcord))
1015
-					$can_do_ttf = false;
1016
-				elseif ($is_reverse)
1050
+				if (empty($fontcord)) {
1051
+									$can_do_ttf = false;
1052
+				} elseif ($is_reverse)
1017 1053
 				{
1018 1054
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1019 1055
 					// Put the character back!
1020 1056
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1021 1057
 				}
1022 1058
 
1023
-				if ($can_do_ttf)
1024
-					$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1059
+				if ($can_do_ttf) {
1060
+									$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1061
+				}
1025 1062
 			}
1026 1063
 
1027 1064
 			if (!$can_do_ttf)
@@ -1040,8 +1077,9 @@  discard block
 block discarded – undo
1040 1077
 				}
1041 1078
 
1042 1079
 				// Sorry, no rotation available.
1043
-				else
1044
-					imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1080
+				else {
1081
+									imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1082
+				}
1045 1083
 				$cur_x += $character['width'] + $character_spacing;
1046 1084
 			}
1047 1085
 		}
@@ -1054,17 +1092,22 @@  discard block
 block discarded – undo
1054 1092
 	}
1055 1093
 
1056 1094
 	// Make the background color transparent on the hard image.
1057
-	if (!$simpleBGColor)
1058
-		imagecolortransparent($code_image, $bg_color);
1059
-	if ($hasBorder)
1060
-		imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1095
+	if (!$simpleBGColor) {
1096
+			imagecolortransparent($code_image, $bg_color);
1097
+	}
1098
+	if ($hasBorder) {
1099
+			imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1100
+	}
1061 1101
 
1062 1102
 	// Add some noise to the background?
1063 1103
 	if ($noiseType != 'none')
1064 1104
 	{
1065
-		for ($i = random_int(0, 2); $i < $max_height; $i += random_int(1, 2))
1066
-			for ($j = random_int(0, 10); $j < $total_width; $j += random_int(1, 10))
1067
-				imagesetpixel($code_image, $j, $i, random_int(0, 1) ? $fg_color : $randomness_color);
1105
+		for ($i = random_int(0, 2); $i < $max_height; $i += random_int(1, 2)) {
1106
+					for ($j = random_int(0, 10);
1107
+		}
1108
+		$j < $total_width; $j += random_int(1, 10)) {
1109
+							imagesetpixel($code_image, $j, $i, random_int(0, 1) ? $fg_color : $randomness_color);
1110
+			}
1068 1111
 
1069 1112
 		// Put in some lines too?
1070 1113
 		if ($noiseType != 'extreme')
@@ -1077,8 +1120,7 @@  discard block
 block discarded – undo
1077 1120
 					$x1 = random_int(0, $total_width);
1078 1121
 					$x2 = random_int(0, $total_width);
1079 1122
 					$y1 = 0; $y2 = $max_height;
1080
-				}
1081
-				else
1123
+				} else
1082 1124
 				{
1083 1125
 					$y1 = random_int(0, $max_height);
1084 1126
 					$y2 = random_int(0, $max_height);
@@ -1087,8 +1129,7 @@  discard block
 block discarded – undo
1087 1129
 				imagesetthickness($code_image, random_int(1, 2));
1088 1130
 				imageline($code_image, $x1, $y1, $x2, $y2, random_int(0, 1) ? $fg_color : $randomness_color);
1089 1131
 			}
1090
-		}
1091
-		else
1132
+		} else
1092 1133
 		{
1093 1134
 			// Put in some ellipse
1094 1135
 			$num_ellipse = $noiseType == 'extreme' ? random_int(6, 12) : random_int(2, 6);
@@ -1108,8 +1149,7 @@  discard block
 block discarded – undo
1108 1149
 	{
1109 1150
 		header('content-type: image/gif');
1110 1151
 		imagegif($code_image);
1111
-	}
1112
-	else
1152
+	} else
1113 1153
 	{
1114 1154
 		header('content-type: image/png');
1115 1155
 		imagepng($code_image);
@@ -1132,25 +1172,29 @@  discard block
 block discarded – undo
1132 1172
 {
1133 1173
 	global $settings;
1134 1174
 
1135
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1136
-		return false;
1175
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1176
+			return false;
1177
+	}
1137 1178
 
1138 1179
 	// Get a list of the available font directories.
1139 1180
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1140 1181
 	$font_list = array();
1141
-	while ($entry = $font_dir->read())
1142
-		if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1182
+	while ($entry = $font_dir->read()) {
1183
+			if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1143 1184
 			$font_list[] = $entry;
1185
+	}
1144 1186
 
1145
-	if (empty($font_list))
1146
-		return false;
1187
+	if (empty($font_list)) {
1188
+			return false;
1189
+	}
1147 1190
 
1148 1191
 	// Pick a random font.
1149 1192
 	$random_font = $font_list[array_rand($font_list)];
1150 1193
 
1151 1194
 	// Check if the given letter exists.
1152
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1153
-		return false;
1195
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1196
+			return false;
1197
+	}
1154 1198
 
1155 1199
 	// Include it!
1156 1200
 	header('content-type: image/png');
Please login to merge, or discard this patch.
Sources/ManageSettings.php 1 patch
Braces   +276 added lines, -201 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -209,16 +210,18 @@  discard block
 block discarded – undo
209 210
 	{
210 211
 		$all_zones = timezone_identifiers_list();
211 212
 		// Make sure we set the value to the same as the printed value.
212
-		foreach ($all_zones as $zone)
213
-			$config_vars['default_timezone'][2][$zone] = $zone;
213
+		foreach ($all_zones as $zone) {
214
+					$config_vars['default_timezone'][2][$zone] = $zone;
215
+		}
216
+	} else {
217
+			unset($config_vars['default_timezone']);
214 218
 	}
215
-	else
216
-		unset($config_vars['default_timezone']);
217 219
 
218 220
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
219 221
 
220
-	if ($return_config)
221
-		return $config_vars;
222
+	if ($return_config) {
223
+			return $config_vars;
224
+	}
222 225
 
223 226
 	// Saving?
224 227
 	if (isset($_GET['save']))
@@ -226,8 +229,9 @@  discard block
 block discarded – undo
226 229
 		checkSession();
227 230
 
228 231
 		// Prevent absurd boundaries here - make it a day tops.
229
-		if (isset($_POST['lastActive']))
230
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
232
+		if (isset($_POST['lastActive'])) {
233
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
234
+		}
231 235
 
232 236
 		call_integration_hook('integrate_save_basic_settings');
233 237
 
@@ -235,8 +239,9 @@  discard block
 block discarded – undo
235 239
 		$_SESSION['adm-save'] = true;
236 240
 
237 241
 		// Do a bit of housekeeping
238
-		if (empty($_POST['minimize_files']))
239
-			deleteAllMinified();
242
+		if (empty($_POST['minimize_files'])) {
243
+					deleteAllMinified();
244
+		}
240 245
 
241 246
 		writeLog();
242 247
 		redirectexit('action=admin;area=featuresettings;sa=basic');
@@ -276,8 +281,9 @@  discard block
 block discarded – undo
276 281
 
277 282
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
278 283
 
279
-	if ($return_config)
280
-		return $config_vars;
284
+	if ($return_config) {
285
+			return $config_vars;
286
+	}
281 287
 
282 288
 	// Setup the template.
283 289
 	require_once($sourcedir . '/ManageServer.php');
@@ -294,13 +300,15 @@  discard block
 block discarded – undo
294 300
 
295 301
 		// Clean up the tags.
296 302
 		$bbcTags = array();
297
-		foreach (parse_bbc(false) as $tag)
298
-			$bbcTags[] = $tag['tag'];
303
+		foreach (parse_bbc(false) as $tag) {
304
+					$bbcTags[] = $tag['tag'];
305
+		}
299 306
 
300
-		if (!isset($_POST['disabledBBC_enabledTags']))
301
-			$_POST['disabledBBC_enabledTags'] = array();
302
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
303
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
307
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
308
+					$_POST['disabledBBC_enabledTags'] = array();
309
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
310
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
311
+		}
304 312
 		// Work out what is actually disabled!
305 313
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
306 314
 
@@ -344,8 +352,9 @@  discard block
 block discarded – undo
344 352
 
345 353
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
346 354
 
347
-	if ($return_config)
348
-		return $config_vars;
355
+	if ($return_config) {
356
+			return $config_vars;
357
+	}
349 358
 
350 359
 	// Saving?
351 360
 	if (isset($_GET['save']))
@@ -385,8 +394,9 @@  discard block
 block discarded – undo
385 394
 
386 395
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
387 396
 
388
-	if ($return_config)
389
-		return $config_vars;
397
+	if ($return_config) {
398
+			return $config_vars;
399
+	}
390 400
 
391 401
 	// Saving?
392 402
 	if (isset($_GET['save']))
@@ -424,8 +434,9 @@  discard block
 block discarded – undo
424 434
 
425 435
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
426 436
 
427
-	if ($return_config)
428
-		return $config_vars;
437
+	if ($return_config) {
438
+			return $config_vars;
439
+	}
429 440
 
430 441
 	// Saving?
431 442
 	if (isset($_GET['save']))
@@ -469,8 +480,8 @@  discard block
 block discarded – undo
469 480
 			'enable' => array('check', 'warning_enable'),
470 481
 	);
471 482
 
472
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
473
-		$config_vars += array(
483
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
484
+			$config_vars += array(
474 485
 			'',
475 486
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
476 487
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -479,15 +490,18 @@  discard block
 block discarded – undo
479 490
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
480 491
 				array('permissions', 'view_warning'),
481 492
 		);
493
+	}
482 494
 
483 495
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
484 496
 
485
-	if ($return_config)
486
-		return $config_vars;
497
+	if ($return_config) {
498
+			return $config_vars;
499
+	}
487 500
 
488 501
 	// Cannot use moderation if post moderation is not enabled.
489
-	if (!$modSettings['postmod_active'])
490
-		unset($config_vars['moderate']);
502
+	if (!$modSettings['postmod_active']) {
503
+			unset($config_vars['moderate']);
504
+	}
491 505
 
492 506
 	// Will need the utility functions from here.
493 507
 	require_once($sourcedir . '/ManageServer.php');
@@ -512,16 +526,16 @@  discard block
 block discarded – undo
512 526
 				'warning_watch' => 10,
513 527
 				'warning_mute' => 60,
514 528
 			);
515
-			if ($modSettings['postmod_active'])
516
-				$vars['warning_moderate'] = 35;
529
+			if ($modSettings['postmod_active']) {
530
+							$vars['warning_moderate'] = 35;
531
+			}
517 532
 
518 533
 			foreach ($vars as $var => $value)
519 534
 			{
520 535
 				$config_vars[] = array('int', $var);
521 536
 				$_POST[$var] = $value;
522 537
 			}
523
-		}
524
-		else
538
+		} else
525 539
 		{
526 540
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
527 541
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -609,8 +623,9 @@  discard block
 block discarded – undo
609 623
 
610 624
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
611 625
 
612
-	if ($return_config)
613
-		return $config_vars;
626
+	if ($return_config) {
627
+			return $config_vars;
628
+	}
614 629
 
615 630
 	// You need to be an admin to edit settings!
616 631
 	isAllowedTo('admin_forum');
@@ -644,8 +659,9 @@  discard block
 block discarded – undo
644 659
 
645 660
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
646 661
 	{
647
-		if (empty($context['settings_insert_above']))
648
-			$context['settings_insert_above'] = '';
662
+		if (empty($context['settings_insert_above'])) {
663
+					$context['settings_insert_above'] = '';
664
+		}
649 665
 
650 666
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
651 667
 	}
@@ -687,8 +703,9 @@  discard block
 block discarded – undo
687 703
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
688 704
 
689 705
 		// Hack in guest requiring verification!
690
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
691
-			$_POST['posts_require_captcha'] = -1;
706
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
707
+					$_POST['posts_require_captcha'] = -1;
708
+		}
692 709
 
693 710
 		$save_vars = $config_vars;
694 711
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -705,14 +722,16 @@  discard block
 block discarded – undo
705 722
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
706 723
 		{
707 724
 			// If we had some questions for this language before, but don't now, delete everything from that language.
708
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
709
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
725
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
726
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
727
+			}
710 728
 
711 729
 			// Now step through and see if any existing questions no longer exist.
712
-			if (!empty($context['qa_by_lang'][$lang_id]))
713
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
730
+			if (!empty($context['qa_by_lang'][$lang_id])) {
731
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
714 732
 					if (empty($_POST['question'][$lang_id][$q_id]))
715 733
 						$changes['delete'][] = $q_id;
734
+			}
716 735
 
717 736
 			// Now let's see if there are new questions or ones that need updating.
718 737
 			if (isset($_POST['question'][$lang_id]))
@@ -721,14 +740,16 @@  discard block
 block discarded – undo
721 740
 				{
722 741
 					// Ignore junky ids.
723 742
 					$q_id = (int) $q_id;
724
-					if ($q_id <= 0)
725
-						continue;
743
+					if ($q_id <= 0) {
744
+											continue;
745
+					}
726 746
 
727 747
 					// Check the question isn't empty (because they want to delete it?)
728 748
 					if (empty($question) || trim($question) == '')
729 749
 					{
730
-						if (isset($context['question_answers'][$q_id]))
731
-							$changes['delete'][] = $q_id;
750
+						if (isset($context['question_answers'][$q_id])) {
751
+													$changes['delete'][] = $q_id;
752
+						}
732 753
 						continue;
733 754
 					}
734 755
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -736,19 +757,22 @@  discard block
 block discarded – undo
736 757
 					// Get the answers. Firstly check there actually might be some.
737 758
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
738 759
 					{
739
-						if (isset($context['question_answers'][$q_id]))
740
-							$changes['delete'][] = $q_id;
760
+						if (isset($context['question_answers'][$q_id])) {
761
+													$changes['delete'][] = $q_id;
762
+						}
741 763
 						continue;
742 764
 					}
743 765
 					// Now get them and check that they might be viable.
744 766
 					$answers = array();
745
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
746
-						if (!empty($answer) && trim($answer) !== '')
767
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
768
+											if (!empty($answer) && trim($answer) !== '')
747 769
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
770
+					}
748 771
 					if (empty($answers))
749 772
 					{
750
-						if (isset($context['question_answers'][$q_id]))
751
-							$changes['delete'][] = $q_id;
773
+						if (isset($context['question_answers'][$q_id])) {
774
+													$changes['delete'][] = $q_id;
775
+						}
752 776
 						continue;
753 777
 					}
754 778
 					$answers = $smcFunc['json_encode']($answers);
@@ -758,16 +782,17 @@  discard block
 block discarded – undo
758 782
 					{
759 783
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
760 784
 						$changes['insert'][] = array($lang_id, $question, $answers);
761
-					}
762
-					else
785
+					} else
763 786
 					{
764 787
 						// It's an existing question. Let's see what's changed, if anything.
765
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
766
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
788
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
789
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
790
+						}
767 791
 					}
768 792
 
769
-					if (!isset($qs_per_lang[$lang_id]))
770
-						$qs_per_lang[$lang_id] = 0;
793
+					if (!isset($qs_per_lang[$lang_id])) {
794
+											$qs_per_lang[$lang_id] = 0;
795
+					}
771 796
 					$qs_per_lang[$lang_id]++;
772 797
 				}
773 798
 			}
@@ -817,8 +842,9 @@  discard block
 block discarded – undo
817 842
 
818 843
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
819 844
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
820
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
821
-			$_POST['qa_verification_number'] = $count_questions;
845
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
846
+					$_POST['qa_verification_number'] = $count_questions;
847
+		}
822 848
 
823 849
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
824 850
 
@@ -833,24 +859,27 @@  discard block
 block discarded – undo
833 859
 
834 860
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
835 861
 	$_SESSION['visual_verification_code'] = '';
836
-	for ($i = 0; $i < 6; $i++)
837
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
862
+	for ($i = 0; $i < 6; $i++) {
863
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
864
+	}
838 865
 
839 866
 	// Some javascript for CAPTCHA.
840 867
 	$context['settings_post_javascript'] = '';
841
-	if ($context['use_graphic_library'])
842
-		$context['settings_post_javascript'] .= '
868
+	if ($context['use_graphic_library']) {
869
+			$context['settings_post_javascript'] .= '
843 870
 		function refreshImages()
844 871
 		{
845 872
 			var imageType = document.getElementById(\'visual_verification_type\').value;
846 873
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
847 874
 		}';
875
+	}
848 876
 
849 877
 	// Show the image itself, or text saying we can't.
850
-	if ($context['use_graphic_library'])
851
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
852
-	else
853
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
878
+	if ($context['use_graphic_library']) {
879
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
880
+	} else {
881
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
882
+	}
854 883
 
855 884
 	// Hack for PM spam settings.
856 885
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -860,9 +889,10 @@  discard block
 block discarded – undo
860 889
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
861 890
 
862 891
 	// Some minor javascript for the guest post setting.
863
-	if ($modSettings['posts_require_captcha'])
864
-		$context['settings_post_javascript'] .= '
892
+	if ($modSettings['posts_require_captcha']) {
893
+			$context['settings_post_javascript'] .= '
865 894
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
895
+	}
866 896
 
867 897
 	// And everything else.
868 898
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -909,8 +939,9 @@  discard block
 block discarded – undo
909 939
 
910 940
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
911 941
 
912
-	if ($return_config)
913
-		return $config_vars;
942
+	if ($return_config) {
943
+			return $config_vars;
944
+	}
914 945
 
915 946
 	// Setup the template.
916 947
 	$context['page_title'] = $txt['signature_settings'];
@@ -965,8 +996,9 @@  discard block
 block discarded – undo
965 996
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
966 997
 
967 998
 				// Max characters...
968
-				if (!empty($sig_limits[1]))
969
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
999
+				if (!empty($sig_limits[1])) {
1000
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
1001
+				}
970 1002
 				// Max lines...
971 1003
 				if (!empty($sig_limits[2]))
972 1004
 				{
@@ -976,8 +1008,9 @@  discard block
 block discarded – undo
976 1008
 						if ($sig[$i] == "\n")
977 1009
 						{
978 1010
 							$count++;
979
-							if ($count >= $sig_limits[2])
980
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1011
+							if ($count >= $sig_limits[2]) {
1012
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1013
+							}
981 1014
 						}
982 1015
 					}
983 1016
 				}
@@ -988,17 +1021,19 @@  discard block
 block discarded – undo
988 1021
 					{
989 1022
 						$limit_broke = 0;
990 1023
 						// Attempt to allow all sizes of abuse, so to speak.
991
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
992
-							$limit_broke = $sig_limits[7] . 'px';
993
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
994
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
995
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
996
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
997
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
998
-							$limit_broke = 'large';
999
-
1000
-						if ($limit_broke)
1001
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1024
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1025
+													$limit_broke = $sig_limits[7] . 'px';
1026
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1027
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1028
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1029
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1030
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1031
+													$limit_broke = 'large';
1032
+						}
1033
+
1034
+						if ($limit_broke) {
1035
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1036
+						}
1002 1037
 					}
1003 1038
 				}
1004 1039
 
@@ -1054,32 +1089,34 @@  discard block
 block discarded – undo
1054 1089
 											$img_offset = false;
1055 1090
 										}
1056 1091
 									}
1092
+								} else {
1093
+																	$replaces[$image] = '';
1057 1094
 								}
1058
-								else
1059
-									$replaces[$image] = '';
1060 1095
 
1061 1096
 								continue;
1062 1097
 							}
1063 1098
 
1064 1099
 							// Does it have predefined restraints? Width first.
1065
-							if ($matches[6][$key])
1066
-								$matches[2][$key] = $matches[6][$key];
1100
+							if ($matches[6][$key]) {
1101
+															$matches[2][$key] = $matches[6][$key];
1102
+							}
1067 1103
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1068 1104
 							{
1069 1105
 								$width = $sig_limits[5];
1070 1106
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1107
+							} elseif ($matches[2][$key]) {
1108
+															$width = $matches[2][$key];
1071 1109
 							}
1072
-							elseif ($matches[2][$key])
1073
-								$width = $matches[2][$key];
1074 1110
 							// ... and height.
1075 1111
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1076 1112
 							{
1077 1113
 								$height = $sig_limits[6];
1078
-								if ($width != -1)
1079
-									$width = $width * ($height / $matches[4][$key]);
1114
+								if ($width != -1) {
1115
+																	$width = $width * ($height / $matches[4][$key]);
1116
+								}
1117
+							} elseif ($matches[4][$key]) {
1118
+															$height = $matches[4][$key];
1080 1119
 							}
1081
-							elseif ($matches[4][$key])
1082
-								$height = $matches[4][$key];
1083 1120
 
1084 1121
 							// If the dimensions are still not fixed - we need to check the actual image.
1085 1122
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1097,12 +1134,13 @@  discard block
 block discarded – undo
1097 1134
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1098 1135
 									{
1099 1136
 										$height = $sig_limits[6];
1100
-										if ($width == -1)
1101
-											$width = $sizes[0];
1137
+										if ($width == -1) {
1138
+																					$width = $sizes[0];
1139
+										}
1102 1140
 										$width = $width * ($height / $sizes[1]);
1141
+									} elseif ($width != -1) {
1142
+																			$height = $sizes[1];
1103 1143
 									}
1104
-									elseif ($width != -1)
1105
-										$height = $sizes[1];
1106 1144
 								}
1107 1145
 							}
1108 1146
 
@@ -1115,8 +1153,9 @@  discard block
 block discarded – undo
1115 1153
 							// Record that we got one.
1116 1154
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1117 1155
 						}
1118
-						if (!empty($replaces))
1119
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1156
+						if (!empty($replaces)) {
1157
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1158
+						}
1120 1159
 					}
1121 1160
 				}
1122 1161
 				// Try to fix disabled tags.
@@ -1128,18 +1167,20 @@  discard block
 block discarded – undo
1128 1167
 
1129 1168
 				$sig = strtr($sig, array("\n" => '<br>'));
1130 1169
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1131
-				if ($sig != $row['signature'])
1132
-					$changes[$row['id_member']] = $sig;
1170
+				if ($sig != $row['signature']) {
1171
+									$changes[$row['id_member']] = $sig;
1172
+				}
1173
+			}
1174
+			if ($smcFunc['db_num_rows']($request) == 0) {
1175
+							$done = true;
1133 1176
 			}
1134
-			if ($smcFunc['db_num_rows']($request) == 0)
1135
-				$done = true;
1136 1177
 			$smcFunc['db_free_result']($request);
1137 1178
 
1138 1179
 			// Do we need to delete what we have?
1139 1180
 			if (!empty($changes))
1140 1181
 			{
1141
-				foreach ($changes as $id => $sig)
1142
-					$smcFunc['db_query']('', '
1182
+				foreach ($changes as $id => $sig) {
1183
+									$smcFunc['db_query']('', '
1143 1184
 						UPDATE {db_prefix}members
1144 1185
 						SET signature = {string:signature}
1145 1186
 						WHERE id_member = {int:id_member}',
@@ -1148,11 +1189,13 @@  discard block
 block discarded – undo
1148 1189
 							'signature' => $sig,
1149 1190
 						)
1150 1191
 					);
1192
+				}
1151 1193
 			}
1152 1194
 
1153 1195
 			$_GET['step'] += 50;
1154
-			if (!$done)
1155
-				pauseSignatureApplySettings();
1196
+			if (!$done) {
1197
+							pauseSignatureApplySettings();
1198
+			}
1156 1199
 		}
1157 1200
 		$settings_applied = true;
1158 1201
 	}
@@ -1170,8 +1213,9 @@  discard block
 block discarded – undo
1170 1213
 	);
1171 1214
 
1172 1215
 	// Temporarily make each setting a modSetting!
1173
-	foreach ($context['signature_settings'] as $key => $value)
1174
-		$modSettings['signature_' . $key] = $value;
1216
+	foreach ($context['signature_settings'] as $key => $value) {
1217
+			$modSettings['signature_' . $key] = $value;
1218
+	}
1175 1219
 
1176 1220
 	// Make sure we check the right tags!
1177 1221
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1183,23 +1227,26 @@  discard block
 block discarded – undo
1183 1227
 
1184 1228
 		// Clean up the tag stuff!
1185 1229
 		$bbcTags = array();
1186
-		foreach (parse_bbc(false) as $tag)
1187
-			$bbcTags[] = $tag['tag'];
1230
+		foreach (parse_bbc(false) as $tag) {
1231
+					$bbcTags[] = $tag['tag'];
1232
+		}
1188 1233
 
1189
-		if (!isset($_POST['signature_bbc_enabledTags']))
1190
-			$_POST['signature_bbc_enabledTags'] = array();
1191
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1192
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1234
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1235
+					$_POST['signature_bbc_enabledTags'] = array();
1236
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1237
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1238
+		}
1193 1239
 
1194 1240
 		$sig_limits = array();
1195 1241
 		foreach ($context['signature_settings'] as $key => $value)
1196 1242
 		{
1197
-			if ($key == 'allow_smileys')
1198
-				continue;
1199
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1200
-				$sig_limits[] = -1;
1201
-			else
1202
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1243
+			if ($key == 'allow_smileys') {
1244
+							continue;
1245
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1246
+							$sig_limits[] = -1;
1247
+			} else {
1248
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1249
+			}
1203 1250
 		}
1204 1251
 
1205 1252
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1232,12 +1279,14 @@  discard block
 block discarded – undo
1232 1279
 
1233 1280
 	// Try get more time...
1234 1281
 	@set_time_limit(600);
1235
-	if (function_exists('apache_reset_timeout'))
1236
-		@apache_reset_timeout();
1282
+	if (function_exists('apache_reset_timeout')) {
1283
+			@apache_reset_timeout();
1284
+	}
1237 1285
 
1238 1286
 	// Have we exhausted all the time we allowed?
1239
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1240
-		return;
1287
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1288
+			return;
1289
+	}
1241 1290
 
1242 1291
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1243 1292
 	$context['page_title'] = $txt['not_done_title'];
@@ -1283,9 +1332,10 @@  discard block
 block discarded – undo
1283 1332
 		$disable_fields = array_flip($standard_fields);
1284 1333
 		if (!empty($_POST['active']))
1285 1334
 		{
1286
-			foreach ($_POST['active'] as $value)
1287
-				if (isset($disable_fields[$value]))
1335
+			foreach ($_POST['active'] as $value) {
1336
+							if (isset($disable_fields[$value]))
1288 1337
 					unset($disable_fields[$value]);
1338
+			}
1289 1339
 		}
1290 1340
 		// What we have left!
1291 1341
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1294,16 +1344,18 @@  discard block
 block discarded – undo
1294 1344
 		$reg_fields = array();
1295 1345
 		if (!empty($_POST['reg']))
1296 1346
 		{
1297
-			foreach ($_POST['reg'] as $value)
1298
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1347
+			foreach ($_POST['reg'] as $value) {
1348
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1299 1349
 					$reg_fields[] = $value;
1350
+			}
1300 1351
 		}
1301 1352
 		// What we have left!
1302 1353
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1303 1354
 
1304 1355
 		$_SESSION['adm-save'] = true;
1305
-		if (!empty($changes))
1306
-			updateSettings($changes);
1356
+		if (!empty($changes)) {
1357
+					updateSettings($changes);
1358
+		}
1307 1359
 	}
1308 1360
 
1309 1361
 	createToken('admin-scp');
@@ -1406,11 +1458,13 @@  discard block
 block discarded – undo
1406 1458
 					{
1407 1459
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1408 1460
 
1409
-						if ($rowData['field_order'] > 1)
1410
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1461
+						if ($rowData['field_order'] > 1) {
1462
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1463
+						}
1411 1464
 
1412
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1413
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1465
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1466
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1467
+						}
1414 1468
 
1415 1469
 						$return .= '</p>';
1416 1470
 
@@ -1548,16 +1602,16 @@  discard block
 block discarded – undo
1548 1602
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1549 1603
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1550 1604
 
1551
-		foreach ($standard_fields as $field)
1552
-			$list[] = array(
1605
+		foreach ($standard_fields as $field) {
1606
+					$list[] = array(
1553 1607
 				'id' => $field,
1554 1608
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1555 1609
 				'disabled' => in_array($field, $disabled_fields),
1556 1610
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1557 1611
 				'can_show_register' => !in_array($field, $fields_no_registration),
1558 1612
 			);
1559
-	}
1560
-	else
1613
+		}
1614
+	} else
1561 1615
 	{
1562 1616
 		// Load all the fields.
1563 1617
 		$request = $smcFunc['db_query']('', '
@@ -1571,8 +1625,9 @@  discard block
 block discarded – undo
1571 1625
 				'items_per_page' => $items_per_page,
1572 1626
 			)
1573 1627
 		);
1574
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1575
-			$list[] = $row;
1628
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1629
+					$list[] = $row;
1630
+		}
1576 1631
 		$smcFunc['db_free_result']($request);
1577 1632
 	}
1578 1633
 
@@ -1638,9 +1693,9 @@  discard block
 block discarded – undo
1638 1693
 		$context['field'] = array();
1639 1694
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1640 1695
 		{
1641
-			if ($row['field_type'] == 'textarea')
1642
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1643
-			else
1696
+			if ($row['field_type'] == 'textarea') {
1697
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1698
+			} else
1644 1699
 			{
1645 1700
 				$rows = 3;
1646 1701
 				$cols = 30;
@@ -1676,8 +1731,8 @@  discard block
 block discarded – undo
1676 1731
 	}
1677 1732
 
1678 1733
 	// Setup the default values as needed.
1679
-	if (empty($context['field']))
1680
-		$context['field'] = array(
1734
+	if (empty($context['field'])) {
1735
+			$context['field'] = array(
1681 1736
 			'name' => '',
1682 1737
 			'col_name' => '???',
1683 1738
 			'desc' => '',
@@ -1702,6 +1757,7 @@  discard block
 block discarded – undo
1702 1757
 			'enclose' => '',
1703 1758
 			'placement' => 0,
1704 1759
 		);
1760
+	}
1705 1761
 
1706 1762
 	// Are we moving it?
1707 1763
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1710,8 +1766,10 @@  discard block
 block discarded – undo
1710 1766
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1711 1767
 
1712 1768
 		// Is this a valid position?
1713
-		if ($new_order <= 0 || $new_order > $order_count)
1714
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1769
+		if ($new_order <= 0 || $new_order > $order_count) {
1770
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1771
+		}
1772
+		// @todo implement an error handler
1715 1773
 
1716 1774
 		// All good, proceed.
1717 1775
 		$smcFunc['db_query']('','
@@ -1742,12 +1800,14 @@  discard block
 block discarded – undo
1742 1800
 		validateToken('admin-ecp');
1743 1801
 
1744 1802
 		// Everyone needs a name - even the (bracket) unknown...
1745
-		if (trim($_POST['field_name']) == '')
1746
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1803
+		if (trim($_POST['field_name']) == '') {
1804
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1805
+		}
1747 1806
 
1748 1807
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1749
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1750
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1808
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1809
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1810
+		}
1751 1811
 
1752 1812
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1753 1813
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1764,8 +1824,9 @@  discard block
 block discarded – undo
1764 1824
 
1765 1825
 		// Some masking stuff...
1766 1826
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1767
-		if ($mask == 'regex' && isset($_POST['regex']))
1768
-			$mask .= $_POST['regex'];
1827
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1828
+					$mask .= $_POST['regex'];
1829
+		}
1769 1830
 
1770 1831
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1771 1832
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1784,8 +1845,9 @@  discard block
 block discarded – undo
1784 1845
 				$v = strtr($v, array(',' => ''));
1785 1846
 
1786 1847
 				// Nada, zip, etc...
1787
-				if (trim($v) == '')
1788
-					continue;
1848
+				if (trim($v) == '') {
1849
+									continue;
1850
+				}
1789 1851
 
1790 1852
 				// Otherwise, save it boy.
1791 1853
 				$field_options .= $v . ',';
@@ -1793,15 +1855,17 @@  discard block
 block discarded – undo
1793 1855
 				$newOptions[$k] = $v;
1794 1856
 
1795 1857
 				// Is it default?
1796
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1797
-					$default = $v;
1858
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1859
+									$default = $v;
1860
+				}
1798 1861
 			}
1799 1862
 			$field_options = substr($field_options, 0, -1);
1800 1863
 		}
1801 1864
 
1802 1865
 		// Text area has default has dimensions
1803
-		if ($_POST['field_type'] == 'textarea')
1804
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1866
+		if ($_POST['field_type'] == 'textarea') {
1867
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1868
+		}
1805 1869
 
1806 1870
 		// Come up with the unique name?
1807 1871
 		if (empty($context['fid']))
@@ -1810,32 +1874,36 @@  discard block
 block discarded – undo
1810 1874
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1811 1875
 
1812 1876
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1813
-			if (isset($matches[1]))
1814
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1815
-			else
1816
-				$col_name = $initial_col_name = 'cust_' . random_int(1, 9999);
1877
+			if (isset($matches[1])) {
1878
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1879
+			} else {
1880
+							$col_name = $initial_col_name = 'cust_' . random_int(1, 9999);
1881
+			}
1817 1882
 
1818 1883
 			// Make sure this is unique.
1819 1884
 			$current_fields = array();
1820 1885
 			$request = $smcFunc['db_query']('', '
1821 1886
 				SELECT id_field, col_name
1822 1887
 				FROM {db_prefix}custom_fields');
1823
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1824
-				$current_fields[$row['id_field']] = $row['col_name'];
1888
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1889
+							$current_fields[$row['id_field']] = $row['col_name'];
1890
+			}
1825 1891
 			$smcFunc['db_free_result']($request);
1826 1892
 
1827 1893
 			$unique = false;
1828 1894
 			for ($i = 0; !$unique && $i < 9; $i ++)
1829 1895
 			{
1830
-				if (!in_array($col_name, $current_fields))
1831
-					$unique = true;
1832
-				else
1833
-					$col_name = $initial_col_name . $i;
1896
+				if (!in_array($col_name, $current_fields)) {
1897
+									$unique = true;
1898
+				} else {
1899
+									$col_name = $initial_col_name . $i;
1900
+				}
1834 1901
 			}
1835 1902
 
1836 1903
 			// Still not a unique column name? Leave it up to the user, then.
1837
-			if (!$unique)
1838
-				fatal_lang_error('custom_option_not_unique');
1904
+			if (!$unique) {
1905
+							fatal_lang_error('custom_option_not_unique');
1906
+			}
1839 1907
 		}
1840 1908
 		// Work out what to do with the user data otherwise...
1841 1909
 		else
@@ -1863,8 +1931,9 @@  discard block
 block discarded – undo
1863 1931
 				// Work out what's changed!
1864 1932
 				foreach ($context['field']['options'] as $k => $option)
1865 1933
 				{
1866
-					if (trim($option) == '')
1867
-						continue;
1934
+					if (trim($option) == '') {
1935
+											continue;
1936
+					}
1868 1937
 
1869 1938
 					// Still exists?
1870 1939
 					if (in_array($option, $newOptions))
@@ -1878,8 +1947,8 @@  discard block
 block discarded – undo
1878 1947
 				foreach ($optionChanges as $k => $option)
1879 1948
 				{
1880 1949
 					// Just been renamed?
1881
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1882
-						$smcFunc['db_query']('', '
1950
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1951
+											$smcFunc['db_query']('', '
1883 1952
 							UPDATE {db_prefix}themes
1884 1953
 							SET value = {string:new_value}
1885 1954
 							WHERE variable = {string:current_column}
@@ -1892,6 +1961,7 @@  discard block
 block discarded – undo
1892 1961
 								'old_value' => $option,
1893 1962
 							)
1894 1963
 						);
1964
+					}
1895 1965
 				}
1896 1966
 			}
1897 1967
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1934,8 +2004,8 @@  discard block
 block discarded – undo
1934 2004
 			);
1935 2005
 
1936 2006
 			// Just clean up any old selects - these are a pain!
1937
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1938
-				$smcFunc['db_query']('', '
2007
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
2008
+							$smcFunc['db_query']('', '
1939 2009
 					DELETE FROM {db_prefix}themes
1940 2010
 					WHERE variable = {string:current_column}
1941 2011
 						AND value NOT IN ({array_string:new_option_values})
@@ -1946,8 +2016,8 @@  discard block
 block discarded – undo
1946 2016
 						'current_column' => $context['field']['col_name'],
1947 2017
 					)
1948 2018
 				);
1949
-		}
1950
-		else
2019
+			}
2020
+		} else
1951 2021
 		{
1952 2022
 			// Gotta figure it out the order.
1953 2023
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2122,11 +2192,13 @@  discard block
 block discarded – undo
2122 2192
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2123 2193
 
2124 2194
 	$prune_toggle_dt = array();
2125
-	foreach ($prune_toggle as $item)
2126
-		$prune_toggle_dt[] = 'setting_' . $item;
2195
+	foreach ($prune_toggle as $item) {
2196
+			$prune_toggle_dt[] = 'setting_' . $item;
2197
+	}
2127 2198
 
2128
-	if ($return_config)
2129
-		return $config_vars;
2199
+	if ($return_config) {
2200
+			return $config_vars;
2201
+	}
2130 2202
 
2131 2203
 	addInlineJavaScript('
2132 2204
 	function togglePruned()
@@ -2164,15 +2236,16 @@  discard block
 block discarded – undo
2164 2236
 			$vals = array();
2165 2237
 			foreach ($config_vars as $index => $dummy)
2166 2238
 			{
2167
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2168
-					continue;
2239
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2240
+									continue;
2241
+				}
2169 2242
 
2170 2243
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2171 2244
 			}
2172 2245
 			$_POST['pruningOptions'] = implode(',', $vals);
2246
+		} else {
2247
+					$_POST['pruningOptions'] = '';
2173 2248
 		}
2174
-		else
2175
-			$_POST['pruningOptions'] = '';
2176 2249
 
2177 2250
 		saveDBSettings($savevar);
2178 2251
 		$_SESSION['adm-save'] = true;
@@ -2184,10 +2257,11 @@  discard block
 block discarded – undo
2184 2257
 	$context['sub_template'] = 'show_settings';
2185 2258
 
2186 2259
 	// Get the actual values
2187
-	if (!empty($modSettings['pruningOptions']))
2188
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2189
-	else
2190
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2260
+	if (!empty($modSettings['pruningOptions'])) {
2261
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2262
+	} else {
2263
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2264
+	}
2191 2265
 
2192 2266
 	prepareDBSettingContext($config_vars);
2193 2267
 }
@@ -2209,8 +2283,9 @@  discard block
 block discarded – undo
2209 2283
 	// Make it even easier to add new settings.
2210 2284
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2211 2285
 
2212
-	if ($return_config)
2213
-		return $config_vars;
2286
+	if ($return_config) {
2287
+			return $config_vars;
2288
+	}
2214 2289
 
2215 2290
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2216 2291
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(random_int(0, PHP_INT_MAX)), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(random_int(0, PHP_INT_MAX)), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason, COALESCE(bg.expire_time, 0) AS expire_time
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -298,14 +315,15 @@  discard block
 block discarded – undo
298 315
 	if (isset($_SESSION['ban']['cannot_access']))
299 316
 	{
300 317
 		// We don't wanna see you!
301
-		if (!$user_info['is_guest'])
302
-			$smcFunc['db_query']('', '
318
+		if (!$user_info['is_guest']) {
319
+					$smcFunc['db_query']('', '
303 320
 				DELETE FROM {db_prefix}log_online
304 321
 				WHERE id_member = {int:current_member}',
305 322
 				array(
306 323
 					'current_member' => $user_info['id'],
307 324
 				)
308 325
 			);
326
+		}
309 327
 
310 328
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
311 329
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -391,9 +409,10 @@  discard block
 block discarded – undo
391 409
 	}
392 410
 
393 411
 	// Fix up the banning permissions.
394
-	if (isset($user_info['permissions']))
395
-		banPermissions();
396
-}
412
+	if (isset($user_info['permissions'])) {
413
+			banPermissions();
414
+	}
415
+	}
397 416
 
398 417
 /**
399 418
  * Fix permissions according to ban status.
@@ -404,8 +423,9 @@  discard block
 block discarded – undo
404 423
 	global $user_info, $sourcedir, $modSettings, $context;
405 424
 
406 425
 	// Somehow they got here, at least take away all permissions...
407
-	if (isset($_SESSION['ban']['cannot_access']))
408
-		$user_info['permissions'] = array();
426
+	if (isset($_SESSION['ban']['cannot_access'])) {
427
+			$user_info['permissions'] = array();
428
+	}
409 429
 	// Okay, well, you can watch, but don't touch a thing.
410 430
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
411 431
 	{
@@ -447,19 +467,20 @@  discard block
 block discarded – undo
447 467
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
448 468
 		foreach ($permission_change as $old => $new)
449 469
 		{
450
-			if (!in_array($old, $user_info['permissions']))
451
-				unset($permission_change[$old]);
452
-			else
453
-				$user_info['permissions'][] = $new;
470
+			if (!in_array($old, $user_info['permissions'])) {
471
+							unset($permission_change[$old]);
472
+			} else {
473
+							$user_info['permissions'][] = $new;
474
+			}
454 475
 		}
455 476
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
456 477
 	}
457 478
 
458 479
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
459 480
 	// Finally, some bits we cache in the session because it saves queries.
460
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
461
-		$user_info['mod_cache'] = $_SESSION['mc'];
462
-	else
481
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
482
+			$user_info['mod_cache'] = $_SESSION['mc'];
483
+	} else
463 484
 	{
464 485
 		require_once($sourcedir . '/Subs-Auth.php');
465 486
 		rebuildModCache();
@@ -470,14 +491,12 @@  discard block
 block discarded – undo
470 491
 	{
471 492
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
472 493
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
473
-	}
474
-	elseif ($_SESSION['mc']['bq'] != '0=1')
494
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
475 495
 	{
476 496
 		require_once($sourcedir . '/Subs-ReportedContent.php');
477 497
 		$context['open_mod_reports'] = recountOpenReports('posts');
478 498
 		$context['open_member_reports'] = recountOpenReports('members');
479
-	}
480
-	else
499
+	} else
481 500
 	{
482 501
 		$context['open_mod_reports'] = 0;
483 502
 		$context['open_member_reports'] = 0;
@@ -497,8 +516,9 @@  discard block
 block discarded – undo
497 516
 	global $user_info, $smcFunc;
498 517
 
499 518
 	// Don't log web accelerators, it's very confusing...
500
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
501
-		return;
519
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
520
+			return;
521
+	}
502 522
 
503 523
 	$smcFunc['db_insert']('',
504 524
 		'{db_prefix}log_banned',
@@ -508,8 +528,8 @@  discard block
 block discarded – undo
508 528
 	);
509 529
 
510 530
 	// One extra point for these bans.
511
-	if (!empty($ban_ids))
512
-		$smcFunc['db_query']('', '
531
+	if (!empty($ban_ids)) {
532
+			$smcFunc['db_query']('', '
513 533
 			UPDATE {db_prefix}ban_items
514 534
 			SET hits = hits + 1
515 535
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -517,7 +537,8 @@  discard block
 block discarded – undo
517 537
 				'ban_ids' => $ban_ids,
518 538
 			)
519 539
 		);
520
-}
540
+	}
541
+	}
521 542
 
522 543
 /**
523 544
  * Checks if a given email address might be banned.
@@ -533,8 +554,9 @@  discard block
 block discarded – undo
533 554
 	global $txt, $smcFunc;
534 555
 
535 556
 	// Can't ban an empty email
536
-	if (empty($email) || trim($email) == '')
537
-		return;
557
+	if (empty($email) || trim($email) == '') {
558
+			return;
559
+	}
538 560
 
539 561
 	// Let's start with the bans based on your IP/hostname/memberID...
540 562
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -607,16 +629,18 @@  discard block
 block discarded – undo
607 629
 	if ($type == 'post')
608 630
 	{
609 631
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
610
-		if ($check !== $sc)
611
-			$error = 'session_timeout';
632
+		if ($check !== $sc) {
633
+					$error = 'session_timeout';
634
+		}
612 635
 	}
613 636
 
614 637
 	// How about $_GET['sesc']?
615 638
 	elseif ($type == 'get')
616 639
 	{
617 640
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
618
-		if ($check !== $sc)
619
-			$error = 'session_verify_fail';
641
+		if ($check !== $sc) {
642
+					$error = 'session_verify_fail';
643
+		}
620 644
 	}
621 645
 
622 646
 	// Or can it be in either?
@@ -624,13 +648,15 @@  discard block
 block discarded – undo
624 648
 	{
625 649
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
626 650
 
627
-		if ($check !== $sc)
628
-			$error = 'session_verify_fail';
651
+		if ($check !== $sc) {
652
+					$error = 'session_verify_fail';
653
+		}
629 654
 	}
630 655
 
631 656
 	// Verify that they aren't changing user agents on us - that could be bad.
632
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
633
-		$error = 'session_verify_fail';
657
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
658
+			$error = 'session_verify_fail';
659
+	}
634 660
 
635 661
 	// Make sure a page with session check requirement is not being prefetched.
636 662
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -641,30 +667,35 @@  discard block
 block discarded – undo
641 667
 	}
642 668
 
643 669
 	// Check the referring site - it should be the same server at least!
644
-	if (isset($_SESSION['request_referer']))
645
-		$referrer = $_SESSION['request_referer'];
646
-	else
647
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
670
+	if (isset($_SESSION['request_referer'])) {
671
+			$referrer = $_SESSION['request_referer'];
672
+	} else {
673
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
674
+	}
648 675
 	if (!empty($referrer['host']))
649 676
 	{
650
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
651
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
652
-		else
653
-			$real_host = $_SERVER['HTTP_HOST'];
677
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
678
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
679
+		} else {
680
+					$real_host = $_SERVER['HTTP_HOST'];
681
+		}
654 682
 
655 683
 		$parsed_url = parse_url($boardurl);
656 684
 
657 685
 		// Are global cookies on?  If so, let's check them ;).
658 686
 		if (!empty($modSettings['globalCookies']))
659 687
 		{
660
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
661
-				$parsed_url['host'] = $parts[1];
688
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
689
+							$parsed_url['host'] = $parts[1];
690
+			}
662 691
 
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
664
-				$referrer['host'] = $parts[1];
692
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
693
+							$referrer['host'] = $parts[1];
694
+			}
665 695
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
667
-				$real_host = $parts[1];
696
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
697
+							$real_host = $parts[1];
698
+			}
668 699
 		}
669 700
 
670 701
 		// Okay: referrer must either match parsed_url or real_host.
@@ -682,12 +713,14 @@  discard block
 block discarded – undo
682 713
 		$log_error = true;
683 714
 	}
684 715
 
685
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
686
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
716
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
717
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
718
+	}
687 719
 
688 720
 	// Everything is ok, return an empty string.
689
-	if (!isset($error))
690
-		return '';
721
+	if (!isset($error)) {
722
+			return '';
723
+	}
691 724
 	// A session error occurred, show the error.
692 725
 	elseif ($is_fatal)
693 726
 	{
@@ -696,13 +729,14 @@  discard block
 block discarded – undo
696 729
 			ob_end_clean();
697 730
 			send_http_status(403, 'Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(random_int(0, PHP_INT_MAX) . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (random_int(0, 138) == 23)
813
-		cleanTokens();
846
+	if (random_int(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = random_int(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = random_int(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -899,16 +939,19 @@  discard block
 block discarded – undo
899 939
 	global $user_info, $smcFunc;
900 940
 
901 941
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
902
-	if (empty($permission))
903
-		return true;
942
+	if (empty($permission)) {
943
+			return true;
944
+	}
904 945
 
905 946
 	// You're never allowed to do something if your data hasn't been loaded yet!
906
-	if (empty($user_info))
907
-		return false;
947
+	if (empty($user_info)) {
948
+			return false;
949
+	}
908 950
 
909 951
 	// Administrators are supermen :P.
910
-	if ($user_info['is_admin'])
911
-		return true;
952
+	if ($user_info['is_admin']) {
953
+			return true;
954
+	}
912 955
 
913 956
 	// Let's ensure this is an array.
914 957
 	$permission = (array) $permission;
@@ -916,14 +959,16 @@  discard block
 block discarded – undo
916 959
 	// Are we checking the _current_ board, or some other boards?
917 960
 	if ($boards === null)
918 961
 	{
919
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
920
-			return true;
962
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
963
+					return true;
964
+		}
921 965
 		// You aren't allowed, by default.
922
-		else
923
-			return false;
966
+		else {
967
+					return false;
968
+		}
969
+	} elseif (!is_array($boards)) {
970
+			$boards = array($boards);
924 971
 	}
925
-	elseif (!is_array($boards))
926
-		$boards = array($boards);
927 972
 
928 973
 	$request = $smcFunc['db_query']('', '
929 974
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -951,20 +996,23 @@  discard block
 block discarded – undo
951 996
 		while ($row = $smcFunc['db_fetch_assoc']($request))
952 997
 		{
953 998
 			$result = !empty($row['add_deny']);
954
-			if ($result == true)
955
-				break;
999
+			if ($result == true) {
1000
+							break;
1001
+			}
956 1002
 		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 		return $result;
959 1005
 	}
960 1006
 
961 1007
 	// Make sure they can do it on all of the boards.
962
-	if ($smcFunc['db_num_rows']($request) != count($boards))
963
-		return false;
1008
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1009
+			return false;
1010
+	}
964 1011
 
965 1012
 	$result = true;
966
-	while ($row = $smcFunc['db_fetch_assoc']($request))
967
-		$result &= !empty($row['add_deny']);
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$result &= !empty($row['add_deny']);
1015
+	}
968 1016
 	$smcFunc['db_free_result']($request);
969 1017
 
970 1018
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1031,9 +1079,10 @@  discard block
 block discarded – undo
1031 1079
 
1032 1080
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1033 1081
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1034
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1035
-		validateSession();
1036
-}
1082
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1083
+			validateSession();
1084
+	}
1085
+	}
1037 1086
 
1038 1087
 /**
1039 1088
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1064,13 +1113,14 @@  discard block
 block discarded – undo
1064 1113
 	// Administrators are all powerful, sorry.
1065 1114
 	if ($user_info['is_admin'])
1066 1115
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1116
+		if ($simple) {
1117
+					return array(0);
1118
+		} else
1070 1119
 		{
1071 1120
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1121
+			foreach ($permissions as $permission) {
1122
+							$boards[$permission] = array(0);
1123
+			}
1074 1124
 
1075 1125
 			return $boards;
1076 1126
 		}
@@ -1102,31 +1152,32 @@  discard block
 block discarded – undo
1102 1152
 	{
1103 1153
 		if ($simple)
1104 1154
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1155
+			if (empty($row['add_deny'])) {
1156
+							$deny_boards[] = $row['id_board'];
1157
+			} else {
1158
+							$boards[] = $row['id_board'];
1159
+			}
1160
+		} else
1111 1161
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1162
+			if (empty($row['add_deny'])) {
1163
+							$deny_boards[$row['permission']][] = $row['id_board'];
1164
+			} else {
1165
+							$boards[$row['permission']][] = $row['id_board'];
1166
+			}
1116 1167
 		}
1117 1168
 	}
1118 1169
 	$smcFunc['db_free_result']($request);
1119 1170
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1171
+	if ($simple) {
1172
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1173
+	} else
1123 1174
 	{
1124 1175
 		foreach ($permissions as $permission)
1125 1176
 		{
1126 1177
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1178
+			if (empty($boards[$permission])) {
1179
+							$boards[$permission] = array();
1180
+			} else
1130 1181
 			{
1131 1182
 				// Or it may have been removed
1132 1183
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1213,11 @@  discard block
 block discarded – undo
1162 1213
 
1163 1214
 
1164 1215
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1216
+	if (!allowedTo('moderate_board')) {
1217
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1218
+	} else {
1219
+			$timeLimit = 2;
1220
+	}
1169 1221
 
1170 1222
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1223
 
@@ -1192,8 +1244,9 @@  discard block
 block discarded – undo
1192 1244
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1245
 	{
1194 1246
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1247
+		if (!$only_return_result) {
1248
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1249
+		}
1197 1250
 
1198 1251
 		return true;
1199 1252
 	}
@@ -1211,11 +1264,13 @@  discard block
 block discarded – undo
1211 1264
  */
1212 1265
 function secureDirectory($path, $attachments = false)
1213 1266
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1267
+	if (empty($path)) {
1268
+			return 'empty_path';
1269
+	}
1216 1270
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1271
+	if (!is_writable($path)) {
1272
+			return 'path_not_writable';
1273
+	}
1219 1274
 
1220 1275
 	$directoryname = basename($path);
1221 1276
 
@@ -1227,9 +1282,9 @@  discard block
 block discarded – undo
1227 1282
 
1228 1283
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1284
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1285
+	if (file_exists($path . '/.htaccess')) {
1286
+			$errors[] = 'htaccess_exists';
1287
+	} else
1233 1288
 	{
1234 1289
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1290
 		if ($fh)
@@ -1242,9 +1297,9 @@  discard block
 block discarded – undo
1242 1297
 		$errors[] = 'htaccess_cannot_create_file';
1243 1298
 	}
1244 1299
 
1245
-	if (file_exists($path . '/index.php'))
1246
-		$errors[] = 'index-php_exists';
1247
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1248 1303
 	{
1249 1304
 		$fh = @fopen($path . '/index.php', 'w');
1250 1305
 		if ($fh)
@@ -1272,11 +1327,12 @@  discard block
 block discarded – undo
1272 1327
 		$errors[] = 'index-php_cannot_create_file';
1273 1328
 	}
1274 1329
 
1275
-	if (!empty($errors))
1276
-		return $errors;
1277
-	else
1278
-		return true;
1279
-}
1330
+	if (!empty($errors)) {
1331
+			return $errors;
1332
+	} else {
1333
+			return true;
1334
+	}
1335
+	}
1280 1336
 
1281 1337
 /**
1282 1338
 * This sets the X-Frame-Options header.
@@ -1289,14 +1345,16 @@  discard block
 block discarded – undo
1289 1345
 	global $modSettings;
1290 1346
 
1291 1347
 	$option = 'SAMEORIGIN';
1292
-	if (is_null($override) && !empty($modSettings['frame_security']))
1293
-		$option = $modSettings['frame_security'];
1294
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1295
-		$option = $override;
1348
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1349
+			$option = $modSettings['frame_security'];
1350
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1351
+			$option = $override;
1352
+	}
1296 1353
 
1297 1354
 	// Don't bother setting the header if we have disabled it.
1298
-	if ($option == 'DISABLE')
1299
-		return;
1355
+	if ($option == 'DISABLE') {
1356
+			return;
1357
+	}
1300 1358
 
1301 1359
 	// Finally set it.
1302 1360
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $smcFunc, $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $smcFunc, $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(random_int(0, PHP_INT_MAX))
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['valid_image_types'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['valid_image_types'][$size[2]];
562
+				if (isset($context['valid_image_types'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['valid_image_types'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['valid_image_types'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['valid_image_types'][$size[2]];
713
+		elseif (isset($context['valid_image_types'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['valid_image_types'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['valid_image_types'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['valid_image_types'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['valid_image_types'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['valid_image_types'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['valid_image_types'][$size[2]]) ? $context['valid_image_types'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1236,11 +1307,12 @@  discard block
 block discarded – undo
1236 1307
 				}
1237 1308
 			}
1238 1309
 
1239
-			if (!empty($attachment['id_thumb']))
1240
-				$attachmentData[$i]['thumbnail'] = array(
1310
+			if (!empty($attachment['id_thumb'])) {
1311
+							$attachmentData[$i]['thumbnail'] = array(
1241 1312
 					'id' => $attachment['id_thumb'],
1242 1313
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1243 1314
 				);
1315
+			}
1244 1316
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1245 1317
 
1246 1318
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1250,30 +1322,31 @@  discard block
 block discarded – undo
1250 1322
 				{
1251 1323
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1252 1324
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1253
-				}
1254
-				elseif (!empty($modSettings['max_image_width']))
1325
+				} elseif (!empty($modSettings['max_image_width']))
1255 1326
 				{
1256 1327
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1257 1328
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1258 1329
 				}
1259
-			}
1260
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1330
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1261 1331
 			{
1262 1332
 				// If the image is too large to show inline, make it a popup.
1263
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1264
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1265
-				else
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1333
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1334
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1335
+				} else {
1336
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1337
+				}
1267 1338
 			}
1268 1339
 
1269
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1270
-				$attachmentData[$i]['downloads']++;
1340
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1341
+							$attachmentData[$i]['downloads']++;
1342
+			}
1271 1343
 		}
1272 1344
 	}
1273 1345
 
1274 1346
 	// Do we need to instigate a sort?
1275
-	if ($have_unapproved)
1276
-		usort($attachmentData, 'approved_attach_sort');
1347
+	if ($have_unapproved) {
1348
+			usort($attachmentData, 'approved_attach_sort');
1349
+	}
1277 1350
 
1278 1351
 	return $attachmentData;
1279 1352
 }
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1477 added lines, -1105 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
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,24 +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
-
195
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
196 199
 			{
197 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
198 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -213,8 +216,9 @@  discard block
 block discarded – undo
213 216
 
214 217
 		case 'postgroups':
215 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
216
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
217
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
218 222
 
219 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
220 224
 			if ($postgroups == null || $parameter1 == null)
@@ -229,8 +233,9 @@  discard block
 block discarded – undo
229 233
 					)
230 234
 				);
231 235
 				$postgroups = array();
232
-				while ($row = $smcFunc['db_fetch_assoc']($request))
233
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
234 239
 
235 240
 				$smcFunc['db_free_result']($request);
236 241
 
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 			}
242 247
 
243 248
 			// Oh great, they've screwed their post groups.
244
-			if (empty($postgroups))
245
-				return;
249
+			if (empty($postgroups)) {
250
+							return;
251
+			}
246 252
 
247 253
 			// Set all membergroups from most posts to least posts.
248 254
 			$conditions = '';
@@ -301,12 +307,9 @@  discard block
 block discarded – undo
301 307
 	{
302 308
 		$condition = 'id_member IN ({array_int:members})';
303 309
 		$parameters['members'] = $members;
304
-	}
305
-
306
-	elseif ($members === null)
307
-		$condition = '1=1';
308
-
309
-	else
310
+	} elseif ($members === null) {
311
+			$condition = '1=1';
312
+	} else
310 313
 	{
311 314
 		$condition = 'id_member = {int:member}';
312 315
 		$parameters['member'] = $members;
@@ -346,9 +349,9 @@  discard block
 block discarded – undo
346 349
 		if (count($vars_to_integrate) != 0)
347 350
 		{
348 351
 			// Fetch a list of member_names if necessary
349
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
350
-				$member_names = array($user_info['username']);
351
-			else
352
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
353
+							$member_names = array($user_info['username']);
354
+			} else
352 355
 			{
353 356
 				$member_names = array();
354 357
 				$request = $smcFunc['db_query']('', '
@@ -357,14 +360,16 @@  discard block
 block discarded – undo
357 360
 					WHERE ' . $condition,
358 361
 					$parameters
359 362
 				);
360
-				while ($row = $smcFunc['db_fetch_assoc']($request))
361
-					$member_names[] = $row['member_name'];
363
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
364
+									$member_names[] = $row['member_name'];
365
+				}
362 366
 				$smcFunc['db_free_result']($request);
363 367
 			}
364 368
 
365
-			if (!empty($member_names))
366
-				foreach ($vars_to_integrate as $var)
369
+			if (!empty($member_names)) {
370
+							foreach ($vars_to_integrate as $var)
367 371
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
372
+			}
368 373
 		}
369 374
 	}
370 375
 
@@ -372,16 +377,17 @@  discard block
 block discarded – undo
372 377
 	foreach ($data as $var => $val)
373 378
 	{
374 379
 		$type = 'string';
375
-		if (in_array($var, $knownInts))
376
-			$type = 'int';
377
-		elseif (in_array($var, $knownFloats))
378
-			$type = 'float';
379
-		elseif ($var == 'birthdate')
380
-			$type = 'date';
381
-		elseif ($var == 'member_ip')
382
-			$type = 'inet';
383
-		elseif ($var == 'member_ip2')
384
-			$type = 'inet';
380
+		if (in_array($var, $knownInts)) {
381
+					$type = 'int';
382
+		} elseif (in_array($var, $knownFloats)) {
383
+					$type = 'float';
384
+		} elseif ($var == 'birthdate') {
385
+					$type = 'date';
386
+		} elseif ($var == 'member_ip') {
387
+					$type = 'inet';
388
+		} elseif ($var == 'member_ip2') {
389
+					$type = 'inet';
390
+		}
385 391
 
386 392
 		// Doing an increment?
387 393
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -390,18 +396,17 @@  discard block
 block discarded – undo
390 396
 			if (is_array($members))
391 397
 			{
392 398
 				$val = 'CASE ';
393
-				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				foreach ($members as $k => $v) {
400
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
401
+				}
395 402
 				$val = $val . ' END';
396 403
 				$type = 'raw';
397
-			}
398
-			else
404
+			} else
399 405
 			{
400 406
 				$blub = fetch_alerts($members, false, 0, array(), false);
401 407
 				$val = count($blub);
402 408
 			}
403
-		}
404
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
409
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
405 410
 		{
406 411
 			$val = $var . ' ' . $val . ' 1';
407 412
 			$type = 'raw';
@@ -412,8 +417,9 @@  discard block
 block discarded – undo
412 417
 		{
413 418
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
414 419
 			{
415
-				if ($match[1] != '+ ')
416
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				if ($match[1] != '+ ') {
421
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
422
+				}
417 423
 				$type = 'raw';
418 424
 			}
419 425
 		}
@@ -434,8 +440,9 @@  discard block
 block discarded – undo
434 440
 	// Clear any caching?
435 441
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
436 442
 	{
437
-		if (!is_array($members))
438
-			$members = array($members);
443
+		if (!is_array($members)) {
444
+					$members = array($members);
445
+		}
439 446
 
440 447
 		foreach ($members as $member)
441 448
 		{
@@ -468,29 +475,32 @@  discard block
 block discarded – undo
468 475
 {
469 476
 	global $modSettings, $smcFunc;
470 477
 
471
-	if (empty($changeArray) || !is_array($changeArray))
472
-		return;
478
+	if (empty($changeArray) || !is_array($changeArray)) {
479
+			return;
480
+	}
473 481
 
474 482
 	$toRemove = array();
475 483
 
476 484
 	// Go check if there is any setting to be removed.
477
-	foreach ($changeArray as $k => $v)
478
-		if ($v === null)
485
+	foreach ($changeArray as $k => $v) {
486
+			if ($v === null)
479 487
 		{
480 488
 			// Found some, remove them from the original array and add them to ours.
481 489
 			unset($changeArray[$k]);
490
+	}
482 491
 			$toRemove[] = $k;
483 492
 		}
484 493
 
485 494
 	// Proceed with the deletion.
486
-	if (!empty($toRemove))
487
-		$smcFunc['db_query']('', '
495
+	if (!empty($toRemove)) {
496
+			$smcFunc['db_query']('', '
488 497
 			DELETE FROM {db_prefix}settings
489 498
 			WHERE variable IN ({array_string:remove})',
490 499
 			array(
491 500
 				'remove' => $toRemove,
492 501
 			)
493 502
 		);
503
+	}
494 504
 
495 505
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
496 506
 	if ($update)
@@ -519,19 +529,22 @@  discard block
 block discarded – undo
519 529
 	foreach ($changeArray as $variable => $value)
520 530
 	{
521 531
 		// Don't bother if it's already like that ;).
522
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
523
-			continue;
532
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
533
+					continue;
534
+		}
524 535
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
525
-		elseif (!isset($modSettings[$variable]) && empty($value))
526
-			continue;
536
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
537
+					continue;
538
+		}
527 539
 
528 540
 		$replaceArray[] = array($variable, $value);
529 541
 
530 542
 		$modSettings[$variable] = $value;
531 543
 	}
532 544
 
533
-	if (empty($replaceArray))
534
-		return;
545
+	if (empty($replaceArray)) {
546
+			return;
547
+	}
535 548
 
536 549
 	$smcFunc['db_insert']('replace',
537 550
 		'{db_prefix}settings',
@@ -577,14 +590,17 @@  discard block
 block discarded – undo
577 590
 	$start_invalid = $start < 0;
578 591
 
579 592
 	// Make sure $start is a proper variable - not less than 0.
580
-	if ($start_invalid)
581
-		$start = 0;
593
+	if ($start_invalid) {
594
+			$start = 0;
595
+	}
582 596
 	// Not greater than the upper bound.
583
-	elseif ($start >= $max_value)
584
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	elseif ($start >= $max_value) {
598
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
599
+	}
585 600
 	// And it has to be a multiple of $num_per_page!
586
-	else
587
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	else {
602
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
603
+	}
588 604
 
589 605
 	$context['current_page'] = $start / $num_per_page;
590 606
 
@@ -614,77 +630,87 @@  discard block
 block discarded – undo
614 630
 
615 631
 		// Show all the pages.
616 632
 		$display_page = 1;
617
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
618
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
634
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
635
+		}
619 636
 
620 637
 		// Show the right arrow.
621 638
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
622
-		if ($start != $counter - $max_value && !$start_invalid)
623
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
624
-	}
625
-	else
639
+		if ($start != $counter - $max_value && !$start_invalid) {
640
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
641
+		}
642
+	} else
626 643
 	{
627 644
 		// If they didn't enter an odd value, pretend they did.
628 645
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
629 646
 
630 647
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
631
-		if (!empty($start) && $show_prevnext)
632
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
633
-		else
634
-			$pageindex .= '';
648
+		if (!empty($start) && $show_prevnext) {
649
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
650
+		} else {
651
+					$pageindex .= '';
652
+		}
635 653
 
636 654
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
637
-		if ($start > $num_per_page * $PageContiguous)
638
-			$pageindex .= sprintf($base_link, 0, '1');
655
+		if ($start > $num_per_page * $PageContiguous) {
656
+					$pageindex .= sprintf($base_link, 0, '1');
657
+		}
639 658
 
640 659
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
641
-		if ($start > $num_per_page * ($PageContiguous + 1))
642
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
660
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
661
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
643 662
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
644 663
 				'{FIRST_PAGE}' => $num_per_page,
645 664
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
646 665
 				'{PER_PAGE}' => $num_per_page,
647 666
 			));
667
+		}
648 668
 
649 669
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
650
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
651
-			if ($start >= $num_per_page * $nCont)
670
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
671
+					if ($start >= $num_per_page * $nCont)
652 672
 			{
653 673
 				$tmpStart = $start - $num_per_page * $nCont;
674
+		}
654 675
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
655 676
 			}
656 677
 
657 678
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
679
+		if (!$start_invalid) {
680
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
681
+		} else {
682
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
683
+		}
662 684
 
663 685
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 686
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
687
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
688
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 689
 			{
668 690
 				$tmpStart = $start + $num_per_page * $nCont;
691
+		}
669 692
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
670 693
 			}
671 694
 
672 695
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
673
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
674
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
696
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
697
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
675 698
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
676 699
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
677 700
 				'{LAST_PAGE}' => $tmpMaxPages,
678 701
 				'{PER_PAGE}' => $num_per_page,
679 702
 			));
703
+		}
680 704
 
681 705
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
682
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
683
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
707
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
708
+		}
684 709
 
685 710
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
686
-		if ($start != $tmpMaxPages && $show_prevnext)
687
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		if ($start != $tmpMaxPages && $show_prevnext) {
712
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
713
+		}
688 714
 	}
689 715
 	$pageindex .= $settings['page_index']['extra_after'];
690 716
 
@@ -710,8 +736,9 @@  discard block
 block discarded – undo
710 736
 	if ($decimal_separator === null)
711 737
 	{
712 738
 		// Not set for whatever reason?
713
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
714
-			return $number;
739
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
740
+					return $number;
741
+		}
715 742
 
716 743
 		// Cache these each load...
717 744
 		$thousands_separator = $matches[1];
@@ -752,17 +779,20 @@  discard block
 block discarded – undo
752 779
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
753 780
 
754 781
 	// Offset the time.
755
-	if (!$offset_type)
756
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	if (!$offset_type) {
783
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
784
+	}
757 785
 	// Just the forum offset?
758
-	elseif ($offset_type == 'forum')
759
-		$time = $log_time + $modSettings['time_offset'] * 3600;
760
-	else
761
-		$time = $log_time;
786
+	elseif ($offset_type == 'forum') {
787
+			$time = $log_time + $modSettings['time_offset'] * 3600;
788
+	} else {
789
+			$time = $log_time;
790
+	}
762 791
 
763 792
 	// We can't have a negative date (on Windows, at least.)
764
-	if ($log_time < 0)
765
-		$log_time = 0;
793
+	if ($log_time < 0) {
794
+			$log_time = 0;
795
+	}
766 796
 
767 797
 	// Today and Yesterday?
768 798
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -779,24 +809,27 @@  discard block
 block discarded – undo
779 809
 		{
780 810
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
781 811
 			$today_fmt = $h . ':%M' . $s . ' %p';
812
+		} else {
813
+					$today_fmt = '%H:%M' . $s;
782 814
 		}
783
-		else
784
-			$today_fmt = '%H:%M' . $s;
785 815
 
786 816
 		// Same day of the year, same year.... Today!
787
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
788
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
818
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
819
+		}
789 820
 
790 821
 		// 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...
791
-		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))
792
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		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)) {
823
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		}
793 825
 	}
794 826
 
795 827
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
796 828
 
797 829
 	// Use the cached formats if available
798
-	if (is_null($finalizedFormats))
799
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	if (is_null($finalizedFormats)) {
831
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
832
+	}
800 833
 
801 834
 	// Make a supported version for this format if we don't already have one
802 835
 	if (empty($finalizedFormats[$str]))
@@ -825,8 +858,9 @@  discard block
 block discarded – undo
825 858
 		);
826 859
 
827 860
 		// No need to do this part again if we already did it once
828
-		if (is_null($unsupportedFormats))
829
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		if (is_null($unsupportedFormats)) {
862
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
863
+		}
830 864
 		if (empty($unsupportedFormats))
831 865
 		{
832 866
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -842,20 +876,23 @@  discard block
 block discarded – undo
842 876
 
843 877
 				// Windows will return false for unsupported formats
844 878
 				// Other operating systems return the format string as a literal
845
-				if ($value === false || $value === $format)
846
-					$unsupportedFormats[] = $format;
879
+				if ($value === false || $value === $format) {
880
+									$unsupportedFormats[] = $format;
881
+				}
847 882
 			}
848 883
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
849 884
 		}
850 885
 
851 886
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
852
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
853
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
888
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
889
+		}
854 890
 
855 891
 		// Substitute unsupported formats with supported ones
856
-		if (!empty($unsupportedFormats))
857
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
892
+		if (!empty($unsupportedFormats)) {
893
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
858 894
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
895
+		}
859 896
 
860 897
 		// Remember this so we don't need to do it again
861 898
 		$finalizedFormats[$str] = $timeformat;
@@ -864,33 +901,39 @@  discard block
 block discarded – undo
864 901
 
865 902
 	$str = $finalizedFormats[$str];
866 903
 
867
-	if (!isset($locale_cache))
868
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	if (!isset($locale_cache)) {
905
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
906
+	}
869 907
 
870 908
 	if ($locale_cache !== false)
871 909
 	{
872 910
 		// Check if another process changed the locale
873
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
874
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
912
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
913
+		}
875 914
 
876
-		if (!isset($non_twelve_hour))
877
-			$non_twelve_hour = trim(strftime('%p')) === '';
878
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
915
+		if (!isset($non_twelve_hour)) {
916
+					$non_twelve_hour = trim(strftime('%p')) === '';
917
+		}
918
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
880 921
 
881
-		foreach (array('%a', '%A', '%b', '%B') as $token)
882
-			if (strpos($str, $token) !== false)
922
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
923
+					if (strpos($str, $token) !== false)
883 924
 				$str = str_replace($token, strftime($token, $time), $str);
884
-	}
885
-	else
925
+		}
926
+	} else
886 927
 	{
887 928
 		// Do-it-yourself time localization.  Fun.
888
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
889
-			if (strpos($str, $token) !== false)
929
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
930
+					if (strpos($str, $token) !== false)
890 931
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
932
+		}
891 933
 
892
-		if (strpos($str, '%p') !== false)
893
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		if (strpos($str, '%p') !== false) {
935
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
936
+		}
894 937
 	}
895 938
 
896 939
 	// Format the time and then restore any literal percent characters
@@ -912,16 +955,19 @@  discard block
 block discarded – undo
912 955
 	static $translation = array();
913 956
 
914 957
 	// Determine the character set... Default to UTF-8
915
-	if (empty($context['character_set']))
916
-		$charset = 'UTF-8';
958
+	if (empty($context['character_set'])) {
959
+			$charset = 'UTF-8';
960
+	}
917 961
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
918
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
919
-		$charset = 'ISO-8859-1';
920
-	else
921
-		$charset = $context['character_set'];
962
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
963
+			$charset = 'ISO-8859-1';
964
+	} else {
965
+			$charset = $context['character_set'];
966
+	}
922 967
 
923
-	if (empty($translation))
924
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
968
+	if (empty($translation)) {
969
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
970
+	}
925 971
 
926 972
 	return strtr($string, $translation);
927 973
 }
@@ -943,8 +989,9 @@  discard block
 block discarded – undo
943 989
 	global $smcFunc;
944 990
 
945 991
 	// It was already short enough!
946
-	if ($smcFunc['strlen']($subject) <= $len)
947
-		return $subject;
992
+	if ($smcFunc['strlen']($subject) <= $len) {
993
+			return $subject;
994
+	}
948 995
 
949 996
 	// Shorten it by the length it was too long, and strip off junk from the end.
950 997
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -963,10 +1010,11 @@  discard block
 block discarded – undo
963 1010
 {
964 1011
 	global $user_info, $modSettings;
965 1012
 
966
-	if ($timestamp === null)
967
-		$timestamp = time();
968
-	elseif ($timestamp == 0)
969
-		return 0;
1013
+	if ($timestamp === null) {
1014
+			$timestamp = time();
1015
+	} elseif ($timestamp == 0) {
1016
+			return 0;
1017
+	}
970 1018
 
971 1019
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
972 1020
 }
@@ -995,8 +1043,9 @@  discard block
 block discarded – undo
995 1043
 		$array[$i] = $array[$j];
996 1044
 		$array[$j] = $temp;
997 1045
 
998
-		for ($i = 1; $p[$i] == 0; $i++)
999
-			$p[$i] = 1;
1046
+		for ($i = 1; $p[$i] == 0; $i++) {
1047
+					$p[$i] = 1;
1048
+		}
1000 1049
 
1001 1050
 		$orders[] = $array;
1002 1051
 	}
@@ -1028,12 +1077,14 @@  discard block
 block discarded – undo
1028 1077
 	static $disabled;
1029 1078
 
1030 1079
 	// Don't waste cycles
1031
-	if ($message === '')
1032
-		return '';
1080
+	if ($message === '') {
1081
+			return '';
1082
+	}
1033 1083
 
1034 1084
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1035
-	if (!isset($context['utf8']))
1036
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1085
+	if (!isset($context['utf8'])) {
1086
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1087
+	}
1037 1088
 
1038 1089
 	// Clean up any cut/paste issues we may have
1039 1090
 	$message = sanitizeMSCutPaste($message);
@@ -1045,13 +1096,15 @@  discard block
 block discarded – undo
1045 1096
 		return $message;
1046 1097
 	}
1047 1098
 
1048
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1049
-		$smileys = (bool) $smileys;
1099
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1100
+			$smileys = (bool) $smileys;
1101
+	}
1050 1102
 
1051 1103
 	if (empty($modSettings['enableBBC']) && $message !== false)
1052 1104
 	{
1053
-		if ($smileys === true)
1054
-			parsesmileys($message);
1105
+		if ($smileys === true) {
1106
+					parsesmileys($message);
1107
+		}
1055 1108
 
1056 1109
 		return $message;
1057 1110
 	}
@@ -1064,8 +1117,9 @@  discard block
 block discarded – undo
1064 1117
 	}
1065 1118
 
1066 1119
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1067
-	if (!empty($modSettings['autoLinkUrls']))
1068
-		set_tld_regex();
1120
+	if (!empty($modSettings['autoLinkUrls'])) {
1121
+			set_tld_regex();
1122
+	}
1069 1123
 
1070 1124
 	// Allow mods access before entering the main parse_bbc loop
1071 1125
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1079,8 +1133,9 @@  discard block
 block discarded – undo
1079 1133
 
1080 1134
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1081 1135
 
1082
-			foreach ($temp as $tag)
1083
-				$disabled[trim($tag)] = true;
1136
+			foreach ($temp as $tag) {
1137
+							$disabled[trim($tag)] = true;
1138
+			}
1084 1139
 		}
1085 1140
 
1086 1141
 		// The YouTube bbc needs this for its origin parameter
@@ -1214,8 +1269,9 @@  discard block
 block discarded – undo
1214 1269
 					$returnContext = '';
1215 1270
 
1216 1271
 					// BBC or the entire attachments feature is disabled
1217
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1218
-						return $data;
1272
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1273
+											return $data;
1274
+					}
1219 1275
 
1220 1276
 					// Save the attach ID.
1221 1277
 					$attachID = $data;
@@ -1226,8 +1282,9 @@  discard block
 block discarded – undo
1226 1282
 					$currentAttachment = parseAttachBBC($attachID);
1227 1283
 
1228 1284
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1229
-					if (is_string($currentAttachment))
1230
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1285
+					if (is_string($currentAttachment)) {
1286
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1287
+					}
1231 1288
 
1232 1289
 					if (!empty($currentAttachment['is_image']))
1233 1290
 					{
@@ -1243,15 +1300,17 @@  discard block
 block discarded – undo
1243 1300
 							$height = ' height="' . $currentAttachment['height'] . '"';
1244 1301
 						}
1245 1302
 
1246
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1247
-							$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>';
1248
-						else
1249
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1303
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1304
+													$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>';
1305
+						} else {
1306
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1307
+						}
1250 1308
 					}
1251 1309
 
1252 1310
 					// No image. Show a link.
1253
-					else
1254
-						$returnContext .= $currentAttachment['link'];
1311
+					else {
1312
+											$returnContext .= $currentAttachment['link'];
1313
+					}
1255 1314
 
1256 1315
 					// Gotta append what we just did.
1257 1316
 					$data = $returnContext;
@@ -1305,8 +1364,9 @@  discard block
 block discarded – undo
1305 1364
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1306 1365
 						{
1307 1366
 							// Do PHP code coloring?
1308
-							if ($php_parts[$php_i] != '&lt;?php')
1309
-								continue;
1367
+							if ($php_parts[$php_i] != '&lt;?php') {
1368
+															continue;
1369
+							}
1310 1370
 
1311 1371
 							$php_string = '';
1312 1372
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1322,8 +1382,9 @@  discard block
 block discarded – undo
1322 1382
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1323 1383
 
1324 1384
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1325
-						if (!empty($context['browser']['is_opera']))
1326
-							$data .= '&nbsp;';
1385
+						if (!empty($context['browser']['is_opera'])) {
1386
+													$data .= '&nbsp;';
1387
+						}
1327 1388
 					}
1328 1389
 				},
1329 1390
 				'block_level' => true,
@@ -1342,8 +1403,9 @@  discard block
 block discarded – undo
1342 1403
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1343 1404
 						{
1344 1405
 							// Do PHP code coloring?
1345
-							if ($php_parts[$php_i] != '&lt;?php')
1346
-								continue;
1406
+							if ($php_parts[$php_i] != '&lt;?php') {
1407
+															continue;
1408
+							}
1347 1409
 
1348 1410
 							$php_string = '';
1349 1411
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1359,8 +1421,9 @@  discard block
 block discarded – undo
1359 1421
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1360 1422
 
1361 1423
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1362
-						if (!empty($context['browser']['is_opera']))
1363
-							$data[0] .= '&nbsp;';
1424
+						if (!empty($context['browser']['is_opera'])) {
1425
+													$data[0] .= '&nbsp;';
1426
+						}
1364 1427
 					}
1365 1428
 				},
1366 1429
 				'block_level' => true,
@@ -1401,10 +1464,11 @@  discard block
 block discarded – undo
1401 1464
 				{
1402 1465
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1403 1466
 
1404
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1405
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1406
-					else
1407
-						$css = '';
1467
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1468
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1469
+					} else {
1470
+											$css = '';
1471
+					}
1408 1472
 
1409 1473
 					$data = $class . $css;
1410 1474
 				},
@@ -1419,8 +1483,9 @@  discard block
 block discarded – undo
1419 1483
 				{
1420 1484
 					$data = strtr($data, array('<br />' => ''));
1421 1485
 
1422
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1423
-						$data = 'ftp://' . $data;
1486
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1487
+											$data = 'ftp://' . $data;
1488
+					}
1424 1489
 				},
1425 1490
 			),
1426 1491
 			array(
@@ -1430,8 +1495,9 @@  discard block
 block discarded – undo
1430 1495
 				'after' => '</a>',
1431 1496
 				'validate' => function(&$tag, &$data, $disabled)
1432 1497
 				{
1433
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1434
-						$data = 'ftp://' . $data;
1498
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1499
+											$data = 'ftp://' . $data;
1500
+					}
1435 1501
 				},
1436 1502
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1437 1503
 				'disabled_after' => ' ($1)',
@@ -1491,17 +1557,20 @@  discard block
 block discarded – undo
1491 1557
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1492 1558
 					if ($image_proxy_enabled)
1493 1559
 					{
1494
-						if (!empty($user_info['possibly_robot']))
1495
-							return;
1560
+						if (!empty($user_info['possibly_robot'])) {
1561
+													return;
1562
+						}
1496 1563
 
1497
-						if (empty($scheme))
1498
-							$data = 'http://' . ltrim($data, ':/');
1564
+						if (empty($scheme)) {
1565
+													$data = 'http://' . ltrim($data, ':/');
1566
+						}
1499 1567
 
1500
-						if ($scheme != 'https')
1501
-							$data = get_proxied_url($data);
1568
+						if ($scheme != 'https') {
1569
+													$data = get_proxied_url($data);
1570
+						}
1571
+					} elseif (empty($scheme)) {
1572
+											$data = '//' . ltrim($data, ':/');
1502 1573
 					}
1503
-					elseif (empty($scheme))
1504
-						$data = '//' . ltrim($data, ':/');
1505 1574
 				},
1506 1575
 				'disabled_content' => '($1)',
1507 1576
 			),
@@ -1517,17 +1586,20 @@  discard block
 block discarded – undo
1517 1586
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1518 1587
 					if ($image_proxy_enabled)
1519 1588
 					{
1520
-						if (!empty($user_info['possibly_robot']))
1521
-							return;
1589
+						if (!empty($user_info['possibly_robot'])) {
1590
+													return;
1591
+						}
1522 1592
 
1523
-						if (empty($scheme))
1524
-							$data = 'http://' . ltrim($data, ':/');
1593
+						if (empty($scheme)) {
1594
+													$data = 'http://' . ltrim($data, ':/');
1595
+						}
1525 1596
 
1526
-						if ($scheme != 'https')
1527
-							$data = get_proxied_url($data);
1597
+						if ($scheme != 'https') {
1598
+													$data = get_proxied_url($data);
1599
+						}
1600
+					} elseif (empty($scheme)) {
1601
+											$data = '//' . ltrim($data, ':/');
1528 1602
 					}
1529
-					elseif (empty($scheme))
1530
-						$data = '//' . ltrim($data, ':/');
1531 1603
 				},
1532 1604
 				'disabled_content' => '($1)',
1533 1605
 			),
@@ -1539,8 +1611,9 @@  discard block
 block discarded – undo
1539 1611
 				{
1540 1612
 					$data = strtr($data, array('<br>' => ''));
1541 1613
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1542
-					if (empty($scheme))
1543
-						$data = '//' . ltrim($data, ':/');
1614
+					if (empty($scheme)) {
1615
+											$data = '//' . ltrim($data, ':/');
1616
+					}
1544 1617
 				},
1545 1618
 			),
1546 1619
 			array(
@@ -1551,13 +1624,14 @@  discard block
 block discarded – undo
1551 1624
 				'after' => '</a>',
1552 1625
 				'validate' => function (&$tag, &$data, $disabled)
1553 1626
 				{
1554
-					if (substr($data, 0, 1) == '#')
1555
-						$data = '#post_' . substr($data, 1);
1556
-					else
1627
+					if (substr($data, 0, 1) == '#') {
1628
+											$data = '#post_' . substr($data, 1);
1629
+					} else
1557 1630
 					{
1558 1631
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1559
-						if (empty($scheme))
1560
-							$data = '//' . ltrim($data, ':/');
1632
+						if (empty($scheme)) {
1633
+													$data = '//' . ltrim($data, ':/');
1634
+						}
1561 1635
 					}
1562 1636
 				},
1563 1637
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1648,8 +1722,9 @@  discard block
 block discarded – undo
1648 1722
 					{
1649 1723
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1650 1724
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1651
-						if ($add_begin)
1652
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1725
+						if ($add_begin) {
1726
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1727
+						}
1653 1728
 					}
1654 1729
 				},
1655 1730
 				'block_level' => false,
@@ -1741,20 +1816,17 @@  discard block
 block discarded – undo
1741 1816
 				'validate' => function(&$tag, &$data, $disabled)
1742 1817
 					{
1743 1818
 
1744
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1745
-							$data[1] = '0 -2px 1px';
1746
-
1747
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1748
-							$data[1] = '2px 0 1px';
1749
-
1750
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1751
-							$data[1] = '0 2px 1px';
1752
-
1753
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1754
-							$data[1] = '-2px 0 1px';
1755
-
1756
-						else
1757
-							$data[1] = '1px 1px 1px';
1819
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1820
+													$data[1] = '0 -2px 1px';
1821
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1822
+													$data[1] = '2px 0 1px';
1823
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1824
+													$data[1] = '0 2px 1px';
1825
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1826
+													$data[1] = '-2px 0 1px';
1827
+						} else {
1828
+													$data[1] = '1px 1px 1px';
1829
+						}
1758 1830
 					},
1759 1831
 			),
1760 1832
 			array(
@@ -1810,10 +1882,11 @@  discard block
 block discarded – undo
1810 1882
 				'content' => '$1',
1811 1883
 				'validate' => function (&$tag, &$data, $disabled)
1812 1884
 				{
1813
-					if (is_numeric($data))
1814
-						$data = timeformat($data);
1815
-					else
1816
-						$tag['content'] = '[time]$1[/time]';
1885
+					if (is_numeric($data)) {
1886
+											$data = timeformat($data);
1887
+					} else {
1888
+											$tag['content'] = '[time]$1[/time]';
1889
+					}
1817 1890
 				},
1818 1891
 			),
1819 1892
 			array(
@@ -1845,8 +1918,9 @@  discard block
 block discarded – undo
1845 1918
 				{
1846 1919
 					$data = strtr($data, array('<br>' => ''));
1847 1920
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1848
-					if (empty($scheme))
1849
-						$data = '//' . ltrim($data, ':/');
1921
+					if (empty($scheme)) {
1922
+											$data = '//' . ltrim($data, ':/');
1923
+					}
1850 1924
 				},
1851 1925
 			),
1852 1926
 			array(
@@ -1858,8 +1932,9 @@  discard block
 block discarded – undo
1858 1932
 				'validate' => function (&$tag, &$data, $disabled)
1859 1933
 				{
1860 1934
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1861
-					if (empty($scheme))
1862
-						$data = '//' . ltrim($data, ':/');
1935
+					if (empty($scheme)) {
1936
+											$data = '//' . ltrim($data, ':/');
1937
+					}
1863 1938
 				},
1864 1939
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1865 1940
 				'disabled_after' => ' ($1)',
@@ -1886,12 +1961,13 @@  discard block
 block discarded – undo
1886 1961
 		);
1887 1962
 
1888 1963
 		// Handle legacy bbc codes.
1889
-		foreach ($context['legacy_bbc'] as $bbc)
1890
-			$codes[] = array(
1964
+		foreach ($context['legacy_bbc'] as $bbc) {
1965
+					$codes[] = array(
1891 1966
 				'tag' => $bbc,
1892 1967
 				'before' => '',
1893 1968
 				'after' => '',
1894 1969
 			);
1970
+		}
1895 1971
 
1896 1972
 		// Let mods add new BBC without hassle.
1897 1973
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1899,8 +1975,9 @@  discard block
 block discarded – undo
1899 1975
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1900 1976
 		if ($message === false)
1901 1977
 		{
1902
-			if (isset($temp_bbc))
1903
-				$bbc_codes = $temp_bbc;
1978
+			if (isset($temp_bbc)) {
1979
+							$bbc_codes = $temp_bbc;
1980
+			}
1904 1981
 			usort($codes, function ($a, $b) {
1905 1982
 				return strcmp($a['tag'], $b['tag']);
1906 1983
 			});
@@ -1920,8 +1997,9 @@  discard block
 block discarded – undo
1920 1997
 		);
1921 1998
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1922 1999
 		{
1923
-			foreach ($itemcodes as $c => $dummy)
1924
-				$bbc_codes[$c] = array();
2000
+			foreach ($itemcodes as $c => $dummy) {
2001
+							$bbc_codes[$c] = array();
2002
+			}
1925 2003
 		}
1926 2004
 
1927 2005
 		// Shhhh!
@@ -1942,12 +2020,14 @@  discard block
 block discarded – undo
1942 2020
 		foreach ($codes as $code)
1943 2021
 		{
1944 2022
 			// Make it easier to process parameters later
1945
-			if (!empty($code['parameters']))
1946
-				ksort($code['parameters'], SORT_STRING);
2023
+			if (!empty($code['parameters'])) {
2024
+							ksort($code['parameters'], SORT_STRING);
2025
+			}
1947 2026
 
1948 2027
 			// If we are not doing every tag only do ones we are interested in.
1949
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1950
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2028
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2029
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2030
+			}
1951 2031
 		}
1952 2032
 		$codes = null;
1953 2033
 	}
@@ -1958,8 +2038,9 @@  discard block
 block discarded – undo
1958 2038
 		// It's likely this will change if the message is modified.
1959 2039
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1960 2040
 
1961
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1962
-			return $temp;
2041
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2042
+					return $temp;
2043
+		}
1963 2044
 
1964 2045
 		$cache_t = microtime(true);
1965 2046
 	}
@@ -1991,8 +2072,9 @@  discard block
 block discarded – undo
1991 2072
 		$disabled['flash'] = true;
1992 2073
 
1993 2074
 		// @todo Change maybe?
1994
-		if (!isset($_GET['images']))
1995
-			$disabled['img'] = true;
2075
+		if (!isset($_GET['images'])) {
2076
+					$disabled['img'] = true;
2077
+		}
1996 2078
 
1997 2079
 		// @todo Interface/setting to add more?
1998 2080
 	}
@@ -2003,8 +2085,9 @@  discard block
 block discarded – undo
2003 2085
 	$alltags = array();
2004 2086
 	foreach ($bbc_codes as $section)
2005 2087
 	{
2006
-		foreach ($section as $code)
2007
-			$alltags[] = $code['tag'];
2088
+		foreach ($section as $code) {
2089
+					$alltags[] = $code['tag'];
2090
+		}
2008 2091
 	}
2009 2092
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2010 2093
 
@@ -2016,8 +2099,9 @@  discard block
 block discarded – undo
2016 2099
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2017 2100
 
2018 2101
 		// Failsafe.
2019
-		if ($pos === false || $last_pos > $pos)
2020
-			$pos = strlen($message) + 1;
2102
+		if ($pos === false || $last_pos > $pos) {
2103
+					$pos = strlen($message) + 1;
2104
+		}
2021 2105
 
2022 2106
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2023 2107
 		if ($last_pos < $pos - 1)
@@ -2035,8 +2119,9 @@  discard block
 block discarded – undo
2035 2119
 
2036 2120
 				// <br> should be empty.
2037 2121
 				$empty_tags = array('br', 'hr');
2038
-				foreach ($empty_tags as $tag)
2039
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2122
+				foreach ($empty_tags as $tag) {
2123
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2124
+				}
2040 2125
 
2041 2126
 				// b, u, i, s, pre... basic tags.
2042 2127
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2045,8 +2130,9 @@  discard block
 block discarded – undo
2045 2130
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2046 2131
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2047 2132
 
2048
-					if ($diff > 0)
2049
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2133
+					if ($diff > 0) {
2134
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2135
+					}
2050 2136
 				}
2051 2137
 
2052 2138
 				// Do <img ...> - with security... action= -> action-.
@@ -2059,8 +2145,9 @@  discard block
 block discarded – undo
2059 2145
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2060 2146
 
2061 2147
 						// Remove action= from the URL - no funny business, now.
2062
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2063
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2148
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2149
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2150
+						}
2064 2151
 
2065 2152
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2066 2153
 					}
@@ -2075,16 +2162,18 @@  discard block
 block discarded – undo
2075 2162
 				$no_autolink_area = false;
2076 2163
 				if (!empty($open_tags))
2077 2164
 				{
2078
-					foreach ($open_tags as $open_tag)
2079
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2165
+					foreach ($open_tags as $open_tag) {
2166
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2080 2167
 							$no_autolink_area = true;
2168
+					}
2081 2169
 				}
2082 2170
 
2083 2171
 				// Don't go backwards.
2084 2172
 				// @todo Don't think is the real solution....
2085 2173
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2086
-				if ($pos < $lastAutoPos)
2087
-					$no_autolink_area = true;
2174
+				if ($pos < $lastAutoPos) {
2175
+									$no_autolink_area = true;
2176
+				}
2088 2177
 				$lastAutoPos = $pos;
2089 2178
 
2090 2179
 				if (!$no_autolink_area)
@@ -2189,29 +2278,33 @@  discard block
 block discarded – undo
2189 2278
 							$url = array_shift($matches);
2190 2279
 
2191 2280
 							// If this isn't a clean URL, bail out
2192
-							if ($url != sanitize_iri($url))
2193
-								return $url;
2281
+							if ($url != sanitize_iri($url)) {
2282
+															return $url;
2283
+							}
2194 2284
 
2195 2285
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2196 2286
 
2197 2287
 							if ($scheme == 'mailto')
2198 2288
 							{
2199 2289
 								$email_address = str_replace('mailto:', '', $url);
2200
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2201
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2202
-								else
2203
-									return $url;
2290
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2291
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2292
+								} else {
2293
+																	return $url;
2294
+								}
2204 2295
 							}
2205 2296
 
2206 2297
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2207
-							if (empty($scheme))
2208
-								$fullUrl = '//' . ltrim($url, ':/');
2209
-							else
2210
-								$fullUrl = $url;
2298
+							if (empty($scheme)) {
2299
+															$fullUrl = '//' . ltrim($url, ':/');
2300
+							} else {
2301
+															$fullUrl = $url;
2302
+							}
2211 2303
 
2212 2304
 							// Make sure that $fullUrl really is valid
2213
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2214
-								return $url;
2305
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2306
+															return $url;
2307
+							}
2215 2308
 
2216 2309
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2217 2310
 						}, $data);
@@ -2260,22 +2353,25 @@  discard block
 block discarded – undo
2260 2353
 		}
2261 2354
 
2262 2355
 		// Are we there yet?  Are we there yet?
2263
-		if ($pos >= strlen($message) - 1)
2264
-			break;
2356
+		if ($pos >= strlen($message) - 1) {
2357
+					break;
2358
+		}
2265 2359
 
2266 2360
 		$tags = strtolower($message[$pos + 1]);
2267 2361
 
2268 2362
 		if ($tags == '/' && !empty($open_tags))
2269 2363
 		{
2270 2364
 			$pos2 = strpos($message, ']', $pos + 1);
2271
-			if ($pos2 == $pos + 2)
2272
-				continue;
2365
+			if ($pos2 == $pos + 2) {
2366
+							continue;
2367
+			}
2273 2368
 
2274 2369
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2275 2370
 
2276 2371
 			// A closing tag that doesn't match any open tags? Skip it.
2277
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2278
-				continue;
2372
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2373
+							continue;
2374
+			}
2279 2375
 
2280 2376
 			$to_close = array();
2281 2377
 			$block_level = null;
@@ -2283,8 +2379,9 @@  discard block
 block discarded – undo
2283 2379
 			do
2284 2380
 			{
2285 2381
 				$tag = array_pop($open_tags);
2286
-				if (!$tag)
2287
-					break;
2382
+				if (!$tag) {
2383
+									break;
2384
+				}
2288 2385
 
2289 2386
 				if (!empty($tag['block_level']))
2290 2387
 				{
@@ -2298,10 +2395,11 @@  discard block
 block discarded – undo
2298 2395
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2299 2396
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2300 2397
 					{
2301
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2302
-							if ($temp['tag'] == $look_for)
2398
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2399
+													if ($temp['tag'] == $look_for)
2303 2400
 							{
2304 2401
 								$block_level = !empty($temp['block_level']);
2402
+						}
2305 2403
 								break;
2306 2404
 							}
2307 2405
 					}
@@ -2323,15 +2421,15 @@  discard block
 block discarded – undo
2323 2421
 			{
2324 2422
 				$open_tags = $to_close;
2325 2423
 				continue;
2326
-			}
2327
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2424
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2328 2425
 			{
2329 2426
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2330 2427
 				{
2331
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2332
-						if ($temp['tag'] == $look_for)
2428
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2429
+											if ($temp['tag'] == $look_for)
2333 2430
 						{
2334 2431
 							$block_level = !empty($temp['block_level']);
2432
+					}
2335 2433
 							break;
2336 2434
 						}
2337 2435
 				}
@@ -2339,8 +2437,9 @@  discard block
 block discarded – undo
2339 2437
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2340 2438
 				if (!$block_level)
2341 2439
 				{
2342
-					foreach ($to_close as $tag)
2343
-						array_push($open_tags, $tag);
2440
+					foreach ($to_close as $tag) {
2441
+											array_push($open_tags, $tag);
2442
+					}
2344 2443
 					continue;
2345 2444
 				}
2346 2445
 			}
@@ -2353,14 +2452,17 @@  discard block
 block discarded – undo
2353 2452
 
2354 2453
 				// See the comment at the end of the big loop - just eating whitespace ;).
2355 2454
 				$whitespace_regex = '';
2356
-				if (!empty($tag['block_level']))
2357
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2455
+				if (!empty($tag['block_level'])) {
2456
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2457
+				}
2358 2458
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2359
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2360
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2459
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2460
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2461
+				}
2361 2462
 
2362
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2363
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2463
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2464
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2465
+				}
2364 2466
 			}
2365 2467
 
2366 2468
 			if (!empty($to_close))
@@ -2373,8 +2475,9 @@  discard block
 block discarded – undo
2373 2475
 		}
2374 2476
 
2375 2477
 		// No tags for this character, so just keep going (fastest possible course.)
2376
-		if (!isset($bbc_codes[$tags]))
2377
-			continue;
2478
+		if (!isset($bbc_codes[$tags])) {
2479
+					continue;
2480
+		}
2378 2481
 
2379 2482
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2380 2483
 		$tag = null;
@@ -2383,48 +2486,57 @@  discard block
 block discarded – undo
2383 2486
 			$pt_strlen = strlen($possible['tag']);
2384 2487
 
2385 2488
 			// Not a match?
2386
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2387
-				continue;
2489
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2490
+							continue;
2491
+			}
2388 2492
 
2389 2493
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2390 2494
 
2391 2495
 			// A tag is the last char maybe
2392
-			if ($next_c == '')
2393
-				break;
2496
+			if ($next_c == '') {
2497
+							break;
2498
+			}
2394 2499
 
2395 2500
 			// A test validation?
2396
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2397
-				continue;
2501
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2502
+							continue;
2503
+			}
2398 2504
 			// Do we want parameters?
2399 2505
 			elseif (!empty($possible['parameters']))
2400 2506
 			{
2401
-				if ($next_c != ' ')
2402
-					continue;
2403
-			}
2404
-			elseif (isset($possible['type']))
2507
+				if ($next_c != ' ') {
2508
+									continue;
2509
+				}
2510
+			} elseif (isset($possible['type']))
2405 2511
 			{
2406 2512
 				// Do we need an equal sign?
2407
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2408
-					continue;
2513
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2514
+									continue;
2515
+				}
2409 2516
 				// Maybe we just want a /...
2410
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2411
-					continue;
2517
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2518
+									continue;
2519
+				}
2412 2520
 				// An immediate ]?
2413
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2414
-					continue;
2521
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2522
+									continue;
2523
+				}
2415 2524
 			}
2416 2525
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2417
-			elseif ($next_c != ']')
2418
-				continue;
2526
+			elseif ($next_c != ']') {
2527
+							continue;
2528
+			}
2419 2529
 
2420 2530
 			// Check allowed tree?
2421
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2422
-				continue;
2423
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2424
-				continue;
2531
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2532
+							continue;
2533
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2534
+							continue;
2535
+			}
2425 2536
 			// If this is in the list of disallowed child tags, don't parse it.
2426
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2427
-				continue;
2537
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2538
+							continue;
2539
+			}
2428 2540
 
2429 2541
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2430 2542
 
@@ -2436,8 +2548,9 @@  discard block
 block discarded – undo
2436 2548
 				foreach ($open_tags as $open_quote)
2437 2549
 				{
2438 2550
 					// Every parent quote this quote has flips the styling
2439
-					if ($open_quote['tag'] == 'quote')
2440
-						$quote_alt = !$quote_alt;
2551
+					if ($open_quote['tag'] == 'quote') {
2552
+											$quote_alt = !$quote_alt;
2553
+					}
2441 2554
 				}
2442 2555
 				// Add a class to the quote to style alternating blockquotes
2443 2556
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2448,8 +2561,9 @@  discard block
 block discarded – undo
2448 2561
 			{
2449 2562
 				// Build a regular expression for each parameter for the current tag.
2450 2563
 				$preg = array();
2451
-				foreach ($possible['parameters'] as $p => $info)
2452
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2564
+				foreach ($possible['parameters'] as $p => $info) {
2565
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2566
+				}
2453 2567
 
2454 2568
 				// Extract the string that potentially holds our parameters.
2455 2569
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2468,24 +2582,27 @@  discard block
 block discarded – undo
2468 2582
 
2469 2583
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2470 2584
 
2471
-					if ($match)
2472
-						$blob_counter = count($blobs) + 1;
2585
+					if ($match) {
2586
+											$blob_counter = count($blobs) + 1;
2587
+					}
2473 2588
 				}
2474 2589
 
2475 2590
 				// Didn't match our parameter list, try the next possible.
2476
-				if (!$match)
2477
-					continue;
2591
+				if (!$match) {
2592
+									continue;
2593
+				}
2478 2594
 
2479 2595
 				$params = array();
2480 2596
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2481 2597
 				{
2482 2598
 					$key = strtok(ltrim($matches[$i]), '=');
2483
-					if (isset($possible['parameters'][$key]['value']))
2484
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2485
-					elseif (isset($possible['parameters'][$key]['validate']))
2486
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2487
-					else
2488
-						$params['{' . $key . '}'] = $matches[$i + 1];
2599
+					if (isset($possible['parameters'][$key]['value'])) {
2600
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2601
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2602
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2603
+					} else {
2604
+											$params['{' . $key . '}'] = $matches[$i + 1];
2605
+					}
2489 2606
 
2490 2607
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2491 2608
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2493,23 +2610,26 @@  discard block
 block discarded – undo
2493 2610
 
2494 2611
 				foreach ($possible['parameters'] as $p => $info)
2495 2612
 				{
2496
-					if (!isset($params['{' . $p . '}']))
2497
-						$params['{' . $p . '}'] = '';
2613
+					if (!isset($params['{' . $p . '}'])) {
2614
+											$params['{' . $p . '}'] = '';
2615
+					}
2498 2616
 				}
2499 2617
 
2500 2618
 				$tag = $possible;
2501 2619
 
2502 2620
 				// Put the parameters into the string.
2503
-				if (isset($tag['before']))
2504
-					$tag['before'] = strtr($tag['before'], $params);
2505
-				if (isset($tag['after']))
2506
-					$tag['after'] = strtr($tag['after'], $params);
2507
-				if (isset($tag['content']))
2508
-					$tag['content'] = strtr($tag['content'], $params);
2621
+				if (isset($tag['before'])) {
2622
+									$tag['before'] = strtr($tag['before'], $params);
2623
+				}
2624
+				if (isset($tag['after'])) {
2625
+									$tag['after'] = strtr($tag['after'], $params);
2626
+				}
2627
+				if (isset($tag['content'])) {
2628
+									$tag['content'] = strtr($tag['content'], $params);
2629
+				}
2509 2630
 
2510 2631
 				$pos1 += strlen($given_param_string);
2511
-			}
2512
-			else
2632
+			} else
2513 2633
 			{
2514 2634
 				$tag = $possible;
2515 2635
 				$params = array();
@@ -2520,8 +2640,9 @@  discard block
 block discarded – undo
2520 2640
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2521 2641
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2522 2642
 		{
2523
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2524
-				continue;
2643
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2644
+							continue;
2645
+			}
2525 2646
 
2526 2647
 			$tag = $itemcodes[$message[$pos + 1]];
2527 2648
 
@@ -2542,9 +2663,9 @@  discard block
 block discarded – undo
2542 2663
 			{
2543 2664
 				array_pop($open_tags);
2544 2665
 				$code = '</li>';
2666
+			} else {
2667
+							$code = '';
2545 2668
 			}
2546
-			else
2547
-				$code = '';
2548 2669
 
2549 2670
 			// Now we open a new tag.
2550 2671
 			$open_tags[] = array(
@@ -2591,12 +2712,14 @@  discard block
 block discarded – undo
2591 2712
 		}
2592 2713
 
2593 2714
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2594
-		if ($tag === null)
2595
-			continue;
2715
+		if ($tag === null) {
2716
+					continue;
2717
+		}
2596 2718
 
2597 2719
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2598
-		if (isset($inside['disallow_children']))
2599
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2720
+		if (isset($inside['disallow_children'])) {
2721
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2722
+		}
2600 2723
 
2601 2724
 		// Is this tag disabled?
2602 2725
 		if (isset($disabled[$tag['tag']]))
@@ -2606,14 +2729,13 @@  discard block
 block discarded – undo
2606 2729
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2607 2730
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2608 2731
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2609
-			}
2610
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2732
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2611 2733
 			{
2612 2734
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2613 2735
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2736
+			} else {
2737
+							$tag['content'] = $tag['disabled_content'];
2614 2738
 			}
2615
-			else
2616
-				$tag['content'] = $tag['disabled_content'];
2617 2739
 		}
2618 2740
 
2619 2741
 		// we use this a lot
@@ -2623,8 +2745,9 @@  discard block
 block discarded – undo
2623 2745
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2624 2746
 		{
2625 2747
 			$n = count($open_tags) - 1;
2626
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2627
-				$n--;
2748
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2749
+							$n--;
2750
+			}
2628 2751
 
2629 2752
 			// Close all the non block level tags so this tag isn't surrounded by them.
2630 2753
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2636,12 +2759,15 @@  discard block
 block discarded – undo
2636 2759
 
2637 2760
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2638 2761
 				$whitespace_regex = '';
2639
-				if (!empty($tag['block_level']))
2640
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2641
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2642
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2643
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2644
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2762
+				if (!empty($tag['block_level'])) {
2763
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2764
+				}
2765
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2766
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2767
+				}
2768
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2769
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2770
+				}
2645 2771
 
2646 2772
 				array_pop($open_tags);
2647 2773
 			}
@@ -2662,16 +2788,19 @@  discard block
 block discarded – undo
2662 2788
 		elseif ($tag['type'] == 'unparsed_content')
2663 2789
 		{
2664 2790
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2665
-			if ($pos2 === false)
2666
-				continue;
2791
+			if ($pos2 === false) {
2792
+							continue;
2793
+			}
2667 2794
 
2668 2795
 			$data = substr($message, $pos1, $pos2 - $pos1);
2669 2796
 
2670
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2671
-				$data = substr($data, 4);
2797
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2798
+							$data = substr($data, 4);
2799
+			}
2672 2800
 
2673
-			if (isset($tag['validate']))
2674
-				$tag['validate']($tag, $data, $disabled, $params);
2801
+			if (isset($tag['validate'])) {
2802
+							$tag['validate']($tag, $data, $disabled, $params);
2803
+			}
2675 2804
 
2676 2805
 			$code = strtr($tag['content'], array('$1' => $data));
2677 2806
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2686,34 +2815,40 @@  discard block
 block discarded – undo
2686 2815
 			if (isset($tag['quoted']))
2687 2816
 			{
2688 2817
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2689
-				if ($tag['quoted'] != 'optional' && !$quoted)
2690
-					continue;
2818
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2819
+									continue;
2820
+				}
2691 2821
 
2692
-				if ($quoted)
2693
-					$pos1 += 6;
2822
+				if ($quoted) {
2823
+									$pos1 += 6;
2824
+				}
2825
+			} else {
2826
+							$quoted = false;
2694 2827
 			}
2695
-			else
2696
-				$quoted = false;
2697 2828
 
2698 2829
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2699
-			if ($pos2 === false)
2700
-				continue;
2830
+			if ($pos2 === false) {
2831
+							continue;
2832
+			}
2701 2833
 
2702 2834
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2703
-			if ($pos3 === false)
2704
-				continue;
2835
+			if ($pos3 === false) {
2836
+							continue;
2837
+			}
2705 2838
 
2706 2839
 			$data = array(
2707 2840
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2708 2841
 				substr($message, $pos1, $pos2 - $pos1)
2709 2842
 			);
2710 2843
 
2711
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2712
-				$data[0] = substr($data[0], 4);
2844
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2845
+							$data[0] = substr($data[0], 4);
2846
+			}
2713 2847
 
2714 2848
 			// Validation for my parking, please!
2715
-			if (isset($tag['validate']))
2716
-				$tag['validate']($tag, $data, $disabled, $params);
2849
+			if (isset($tag['validate'])) {
2850
+							$tag['validate']($tag, $data, $disabled, $params);
2851
+			}
2717 2852
 
2718 2853
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2719 2854
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2730,23 +2865,27 @@  discard block
 block discarded – undo
2730 2865
 		elseif ($tag['type'] == 'unparsed_commas_content')
2731 2866
 		{
2732 2867
 			$pos2 = strpos($message, ']', $pos1);
2733
-			if ($pos2 === false)
2734
-				continue;
2868
+			if ($pos2 === false) {
2869
+							continue;
2870
+			}
2735 2871
 
2736 2872
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2737
-			if ($pos3 === false)
2738
-				continue;
2873
+			if ($pos3 === false) {
2874
+							continue;
2875
+			}
2739 2876
 
2740 2877
 			// We want $1 to be the content, and the rest to be csv.
2741 2878
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2742 2879
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2743 2880
 
2744
-			if (isset($tag['validate']))
2745
-				$tag['validate']($tag, $data, $disabled, $params);
2881
+			if (isset($tag['validate'])) {
2882
+							$tag['validate']($tag, $data, $disabled, $params);
2883
+			}
2746 2884
 
2747 2885
 			$code = $tag['content'];
2748
-			foreach ($data as $k => $d)
2749
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2886
+			foreach ($data as $k => $d) {
2887
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2888
+			}
2750 2889
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2751 2890
 			$pos += strlen($code) - 1 + 2;
2752 2891
 		}
@@ -2754,24 +2893,28 @@  discard block
 block discarded – undo
2754 2893
 		elseif ($tag['type'] == 'unparsed_commas')
2755 2894
 		{
2756 2895
 			$pos2 = strpos($message, ']', $pos1);
2757
-			if ($pos2 === false)
2758
-				continue;
2896
+			if ($pos2 === false) {
2897
+							continue;
2898
+			}
2759 2899
 
2760 2900
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2761 2901
 
2762
-			if (isset($tag['validate']))
2763
-				$tag['validate']($tag, $data, $disabled, $params);
2902
+			if (isset($tag['validate'])) {
2903
+							$tag['validate']($tag, $data, $disabled, $params);
2904
+			}
2764 2905
 
2765 2906
 			// Fix after, for disabled code mainly.
2766
-			foreach ($data as $k => $d)
2767
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2907
+			foreach ($data as $k => $d) {
2908
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2909
+			}
2768 2910
 
2769 2911
 			$open_tags[] = $tag;
2770 2912
 
2771 2913
 			// Replace them out, $1, $2, $3, $4, etc.
2772 2914
 			$code = $tag['before'];
2773
-			foreach ($data as $k => $d)
2774
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2915
+			foreach ($data as $k => $d) {
2916
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2917
+			}
2775 2918
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2776 2919
 			$pos += strlen($code) - 1 + 2;
2777 2920
 		}
@@ -2782,28 +2925,33 @@  discard block
 block discarded – undo
2782 2925
 			if (isset($tag['quoted']))
2783 2926
 			{
2784 2927
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2785
-				if ($tag['quoted'] != 'optional' && !$quoted)
2786
-					continue;
2928
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2929
+									continue;
2930
+				}
2787 2931
 
2788
-				if ($quoted)
2789
-					$pos1 += 6;
2932
+				if ($quoted) {
2933
+									$pos1 += 6;
2934
+				}
2935
+			} else {
2936
+							$quoted = false;
2790 2937
 			}
2791
-			else
2792
-				$quoted = false;
2793 2938
 
2794 2939
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2795
-			if ($pos2 === false)
2796
-				continue;
2940
+			if ($pos2 === false) {
2941
+							continue;
2942
+			}
2797 2943
 
2798 2944
 			$data = substr($message, $pos1, $pos2 - $pos1);
2799 2945
 
2800 2946
 			// Validation for my parking, please!
2801
-			if (isset($tag['validate']))
2802
-				$tag['validate']($tag, $data, $disabled, $params);
2947
+			if (isset($tag['validate'])) {
2948
+							$tag['validate']($tag, $data, $disabled, $params);
2949
+			}
2803 2950
 
2804 2951
 			// For parsed content, we must recurse to avoid security problems.
2805
-			if ($tag['type'] != 'unparsed_equals')
2806
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2952
+			if ($tag['type'] != 'unparsed_equals') {
2953
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2954
+			}
2807 2955
 
2808 2956
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2809 2957
 
@@ -2815,34 +2963,40 @@  discard block
 block discarded – undo
2815 2963
 		}
2816 2964
 
2817 2965
 		// If this is block level, eat any breaks after it.
2818
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2819
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2966
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2967
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2968
+		}
2820 2969
 
2821 2970
 		// Are we trimming outside this tag?
2822
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2823
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2971
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2972
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2973
+		}
2824 2974
 	}
2825 2975
 
2826 2976
 	// Close any remaining tags.
2827
-	while ($tag = array_pop($open_tags))
2828
-		$message .= "\n" . $tag['after'] . "\n";
2977
+	while ($tag = array_pop($open_tags)) {
2978
+			$message .= "\n" . $tag['after'] . "\n";
2979
+	}
2829 2980
 
2830 2981
 	// Parse the smileys within the parts where it can be done safely.
2831 2982
 	if ($smileys === true)
2832 2983
 	{
2833 2984
 		$message_parts = explode("\n", $message);
2834
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2835
-			parsesmileys($message_parts[$i]);
2985
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2986
+					parsesmileys($message_parts[$i]);
2987
+		}
2836 2988
 
2837 2989
 		$message = implode('', $message_parts);
2838 2990
 	}
2839 2991
 
2840 2992
 	// No smileys, just get rid of the markers.
2841
-	else
2842
-		$message = strtr($message, array("\n" => ''));
2993
+	else {
2994
+			$message = strtr($message, array("\n" => ''));
2995
+	}
2843 2996
 
2844
-	if ($message !== '' && $message[0] === ' ')
2845
-		$message = '&nbsp;' . substr($message, 1);
2997
+	if ($message !== '' && $message[0] === ' ') {
2998
+			$message = '&nbsp;' . substr($message, 1);
2999
+	}
2846 3000
 
2847 3001
 	// Cleanup whitespace.
2848 3002
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2851,15 +3005,16 @@  discard block
 block discarded – undo
2851 3005
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2852 3006
 
2853 3007
 	// Cache the output if it took some time...
2854
-	if (isset($cache_key, $cache_t) && microtime(true) - $cache_t > 0.05)
2855
-		cache_put_data($cache_key, $message, 240);
3008
+	if (isset($cache_key, $cache_t) && microtime(true) - $cache_t > 0.05) {
3009
+			cache_put_data($cache_key, $message, 240);
3010
+	}
2856 3011
 
2857 3012
 	// If this was a force parse revert if needed.
2858 3013
 	if (!empty($parse_tags))
2859 3014
 	{
2860
-		if (empty($temp_bbc))
2861
-			$bbc_codes = array();
2862
-		else
3015
+		if (empty($temp_bbc)) {
3016
+					$bbc_codes = array();
3017
+		} else
2863 3018
 		{
2864 3019
 			$bbc_codes = $temp_bbc;
2865 3020
 			unset($temp_bbc);
@@ -2886,8 +3041,9 @@  discard block
 block discarded – undo
2886 3041
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2887 3042
 
2888 3043
 	// No smiley set at all?!
2889
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2890
-		return;
3044
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3045
+			return;
3046
+	}
2891 3047
 
2892 3048
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2893 3049
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2901,8 +3057,7 @@  discard block
 block discarded – undo
2901 3057
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)');
2902 3058
 			$smileysto = array('evil', 'cheesy', 'rolleyes', 'angry', 'laugh', 'smiley', 'wink', 'grin', 'sad', 'shocked', 'cool', 'tongue', 'huh', 'embarrassed', 'lipsrsealed', 'kiss', 'cry', 'undecided', 'azn', 'afro', 'police', 'angel');
2903 3059
 			$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'], '', '', '', '');
2904
-		}
2905
-		else
3060
+		} else
2906 3061
 		{
2907 3062
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2908 3063
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2926,18 +3081,20 @@  discard block
 block discarded – undo
2926 3081
 				$smcFunc['db_free_result']($result);
2927 3082
 
2928 3083
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3084
+			} else {
3085
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2929 3086
 			}
2930
-			else
2931
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2932 3087
 		}
2933 3088
 
2934 3089
 		// Set proper extensions; do this post caching so cache doesn't become extension-specific
2935
-		foreach($smileysto AS $ix=>$file)
2936
-			// Need to use the default if user selection is disabled
3090
+		foreach($smileysto AS $ix=>$file) {
3091
+					// Need to use the default if user selection is disabled
2937 3092
 			if (empty($modSettings['smiley_sets_enable']))
2938 3093
 				$smileysto[$ix] = $file . $context['user']['smiley_set_default_ext'];
2939
-			else
2940
-				$smileysto[$ix] = $file . $user_info['smiley_set_ext'];
3094
+		}
3095
+			else {
3096
+							$smileysto[$ix] = $file . $user_info['smiley_set_ext'];
3097
+			}
2941 3098
 
2942 3099
 		// The non-breaking-space is a complex thing...
2943 3100
 		$non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0';
@@ -3022,12 +3179,14 @@  discard block
 block discarded – undo
3022 3179
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3023 3180
 
3024 3181
 	// Only use the proxy if enabled and necessary
3025
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3026
-		return $url;
3182
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3183
+			return $url;
3184
+	}
3027 3185
 
3028 3186
 	// We don't need to proxy our own resources
3029
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3030
-		return strtr($url, array('http://' => 'https://'));
3187
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3188
+			return strtr($url, array('http://' => 'https://'));
3189
+	}
3031 3190
 
3032 3191
 	// By default, use SMF's own image proxy script
3033 3192
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3052,35 +3211,41 @@  discard block
 block discarded – undo
3052 3211
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3053 3212
 
3054 3213
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3055
-	if (!empty($context['flush_mail']))
3056
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3214
+	if (!empty($context['flush_mail'])) {
3215
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3057 3216
 		AddMailQueue(true);
3217
+	}
3058 3218
 
3059 3219
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3060 3220
 
3061
-	if ($add)
3062
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3221
+	if ($add) {
3222
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3223
+	}
3063 3224
 
3064 3225
 	// Put the session ID in.
3065
-	if (defined('SID') && SID != '')
3066
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3226
+	if (defined('SID') && SID != '') {
3227
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3228
+	}
3067 3229
 	// Keep that debug in their for template debugging!
3068
-	elseif (isset($_GET['debug']))
3069
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3230
+	elseif (isset($_GET['debug'])) {
3231
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3232
+	}
3070 3233
 
3071 3234
 	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'])))
3072 3235
 	{
3073
-		if (defined('SID') && SID != '')
3074
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3236
+		if (defined('SID') && SID != '') {
3237
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3075 3238
 				function ($m) use ($scripturl)
3076 3239
 				{
3077 3240
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3241
+		}
3078 3242
 				}, $setLocation);
3079
-		else
3080
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3243
+		else {
3244
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3081 3245
 				function ($m) use ($scripturl)
3082 3246
 				{
3083 3247
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3248
+		}
3084 3249
 				}, $setLocation);
3085 3250
 	}
3086 3251
 
@@ -3091,8 +3256,9 @@  discard block
 block discarded – undo
3091 3256
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3092 3257
 
3093 3258
 	// Debugging.
3094
-	if (isset($db_show_debug) && $db_show_debug === true)
3095
-		$_SESSION['debug_redirect'] = $db_cache;
3259
+	if (isset($db_show_debug) && $db_show_debug === true) {
3260
+			$_SESSION['debug_redirect'] = $db_cache;
3261
+	}
3096 3262
 
3097 3263
 	obExit(false);
3098 3264
 }
@@ -3111,51 +3277,60 @@  discard block
 block discarded – undo
3111 3277
 
3112 3278
 	// Attempt to prevent a recursive loop.
3113 3279
 	++$level;
3114
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3115
-		exit;
3116
-	if ($from_fatal_error)
3117
-		$has_fatal_error = true;
3280
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3281
+			exit;
3282
+	}
3283
+	if ($from_fatal_error) {
3284
+			$has_fatal_error = true;
3285
+	}
3118 3286
 
3119 3287
 	// Clear out the stat cache.
3120 3288
 	trackStats();
3121 3289
 
3122 3290
 	// If we have mail to send, send it.
3123
-	if (!empty($context['flush_mail']))
3124
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3291
+	if (!empty($context['flush_mail'])) {
3292
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3125 3293
 		AddMailQueue(true);
3294
+	}
3126 3295
 
3127 3296
 	$do_header = $header === null ? !$header_done : $header;
3128
-	if ($do_footer === null)
3129
-		$do_footer = $do_header;
3297
+	if ($do_footer === null) {
3298
+			$do_footer = $do_header;
3299
+	}
3130 3300
 
3131 3301
 	// Has the template/header been done yet?
3132 3302
 	if ($do_header)
3133 3303
 	{
3134 3304
 		// Was the page title set last minute? Also update the HTML safe one.
3135
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3136
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3305
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3306
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3307
+		}
3137 3308
 
3138 3309
 		// Start up the session URL fixer.
3139 3310
 		ob_start('ob_sessrewrite');
3140 3311
 
3141
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3142
-			$buffers = explode(',', $settings['output_buffers']);
3143
-		elseif (!empty($settings['output_buffers']))
3144
-			$buffers = $settings['output_buffers'];
3145
-		else
3146
-			$buffers = array();
3312
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3313
+					$buffers = explode(',', $settings['output_buffers']);
3314
+		} elseif (!empty($settings['output_buffers'])) {
3315
+					$buffers = $settings['output_buffers'];
3316
+		} else {
3317
+					$buffers = array();
3318
+		}
3147 3319
 
3148
-		if (isset($modSettings['integrate_buffer']))
3149
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3320
+		if (isset($modSettings['integrate_buffer'])) {
3321
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3322
+		}
3150 3323
 
3151
-		if (!empty($buffers))
3152
-			foreach ($buffers as $function)
3324
+		if (!empty($buffers)) {
3325
+					foreach ($buffers as $function)
3153 3326
 			{
3154 3327
 				$call = call_helper($function, true);
3328
+		}
3155 3329
 
3156 3330
 				// Is it valid?
3157
-				if (!empty($call))
3158
-					ob_start($call);
3331
+				if (!empty($call)) {
3332
+									ob_start($call);
3333
+				}
3159 3334
 			}
3160 3335
 
3161 3336
 		// Display the screen in the logical order.
@@ -3167,8 +3342,9 @@  discard block
 block discarded – undo
3167 3342
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3168 3343
 
3169 3344
 		// Anything special to put out?
3170
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3171
-			echo $context['insert_after_template'];
3345
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3346
+					echo $context['insert_after_template'];
3347
+		}
3172 3348
 
3173 3349
 		// Just so we don't get caught in an endless loop of errors from the footer...
3174 3350
 		if (!$footer_done)
@@ -3177,14 +3353,16 @@  discard block
 block discarded – undo
3177 3353
 			template_footer();
3178 3354
 
3179 3355
 			// (since this is just debugging... it's okay that it's after </html>.)
3180
-			if (!isset($_REQUEST['xml']))
3181
-				displayDebug();
3356
+			if (!isset($_REQUEST['xml'])) {
3357
+							displayDebug();
3358
+			}
3182 3359
 		}
3183 3360
 	}
3184 3361
 
3185 3362
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3186
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3187
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3363
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3364
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3365
+	}
3188 3366
 
3189 3367
 	// For session check verification.... don't switch browsers...
3190 3368
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3193,9 +3371,10 @@  discard block
 block discarded – undo
3193 3371
 	call_integration_hook('integrate_exit', array($do_footer));
3194 3372
 
3195 3373
 	// Don't exit if we're coming from index.php; that will pass through normally.
3196
-	if (!$from_index)
3197
-		exit;
3198
-}
3374
+	if (!$from_index) {
3375
+			exit;
3376
+	}
3377
+	}
3199 3378
 
3200 3379
 /**
3201 3380
  * Get the size of a specified image with better error handling.
@@ -3214,8 +3393,9 @@  discard block
 block discarded – undo
3214 3393
 	$url = str_replace(' ', '%20', $url);
3215 3394
 
3216 3395
 	// Can we pull this from the cache... please please?
3217
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3218
-		return $temp;
3396
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3397
+			return $temp;
3398
+	}
3219 3399
 	$t = microtime(true);
3220 3400
 
3221 3401
 	// Get the host to pester...
@@ -3225,12 +3405,10 @@  discard block
 block discarded – undo
3225 3405
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3226 3406
 	{
3227 3407
 		return false;
3228
-	}
3229
-	elseif (!isset($match[1]))
3408
+	} elseif (!isset($match[1]))
3230 3409
 	{
3231 3410
 		$size = @getimagesize($url);
3232
-	}
3233
-	else
3411
+	} else
3234 3412
 	{
3235 3413
 		// Try to connect to the server... give it half a second.
3236 3414
 		$temp = 0;
@@ -3267,12 +3445,14 @@  discard block
 block discarded – undo
3267 3445
 	}
3268 3446
 
3269 3447
 	// If we didn't get it, we failed.
3270
-	if (!isset($size))
3271
-		$size = false;
3448
+	if (!isset($size)) {
3449
+			$size = false;
3450
+	}
3272 3451
 
3273 3452
 	// If this took a long time, we may never have to do it again, but then again we might...
3274
-	if (microtime(true) - $t > 0.8)
3275
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3453
+	if (microtime(true) - $t > 0.8) {
3454
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3455
+	}
3276 3456
 
3277 3457
 	// Didn't work.
3278 3458
 	return $size;
@@ -3290,8 +3470,9 @@  discard block
 block discarded – undo
3290 3470
 
3291 3471
 	// Under SSI this function can be called more then once.  That can cause some problems.
3292 3472
 	//   So only run the function once unless we are forced to run it again.
3293
-	if ($loaded && !$forceload)
3294
-		return;
3473
+	if ($loaded && !$forceload) {
3474
+			return;
3475
+	}
3295 3476
 
3296 3477
 	$loaded = true;
3297 3478
 
@@ -3303,14 +3484,16 @@  discard block
 block discarded – undo
3303 3484
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3304 3485
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3305 3486
 	{
3306
-		if (trim($context['news_lines'][$i]) == '')
3307
-			continue;
3487
+		if (trim($context['news_lines'][$i]) == '') {
3488
+					continue;
3489
+		}
3308 3490
 
3309 3491
 		// Clean it up for presentation ;).
3310 3492
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3311 3493
 	}
3312
-	if (!empty($context['news_lines']))
3313
-		$context['random_news_line'] = $context['news_lines'][random_int(0, count($context['news_lines']) - 1)];
3494
+	if (!empty($context['news_lines'])) {
3495
+			$context['random_news_line'] = $context['news_lines'][random_int(0, count($context['news_lines']) - 1)];
3496
+	}
3314 3497
 
3315 3498
 	if (!$user_info['is_guest'])
3316 3499
 	{
@@ -3319,40 +3502,48 @@  discard block
 block discarded – undo
3319 3502
 		$context['user']['alerts'] = &$user_info['alerts'];
3320 3503
 
3321 3504
 		// Personal message popup...
3322
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3323
-			$context['user']['popup_messages'] = true;
3324
-		else
3325
-			$context['user']['popup_messages'] = false;
3505
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3506
+					$context['user']['popup_messages'] = true;
3507
+		} else {
3508
+					$context['user']['popup_messages'] = false;
3509
+		}
3326 3510
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3327 3511
 
3328
-		if (allowedTo('moderate_forum'))
3329
-			$context['unapproved_members'] = !empty($modSettings['unapprovedMembers']) ? $modSettings['unapprovedMembers'] : 0;
3512
+		if (allowedTo('moderate_forum')) {
3513
+					$context['unapproved_members'] = !empty($modSettings['unapprovedMembers']) ? $modSettings['unapprovedMembers'] : 0;
3514
+		}
3330 3515
 
3331 3516
 		$context['user']['avatar'] = array();
3332 3517
 
3333 3518
 		// Check for gravatar first since we might be forcing them...
3334 3519
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3335 3520
 		{
3336
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3337
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3338
-			else
3339
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3521
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3522
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3523
+			} else {
3524
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3525
+			}
3340 3526
 		}
3341 3527
 		// Uploaded?
3342
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3343
-			$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';
3528
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3529
+					$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';
3530
+		}
3344 3531
 		// Full URL?
3345
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3346
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3532
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3533
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3534
+		}
3347 3535
 		// Otherwise we assume it's server stored.
3348
-		elseif ($user_info['avatar']['url'] != '')
3349
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3536
+		elseif ($user_info['avatar']['url'] != '') {
3537
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3538
+		}
3350 3539
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3351
-		else
3352
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3540
+		else {
3541
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3542
+		}
3353 3543
 
3354
-		if (!empty($context['user']['avatar']))
3355
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3544
+		if (!empty($context['user']['avatar'])) {
3545
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3546
+		}
3356 3547
 
3357 3548
 		// Figure out how long they've been logged in.
3358 3549
 		$context['user']['total_time_logged_in'] = array(
@@ -3360,8 +3551,7 @@  discard block
 block discarded – undo
3360 3551
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3361 3552
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3362 3553
 		);
3363
-	}
3364
-	else
3554
+	} else
3365 3555
 	{
3366 3556
 		$context['user']['messages'] = 0;
3367 3557
 		$context['user']['unread_messages'] = 0;
@@ -3369,12 +3559,14 @@  discard block
 block discarded – undo
3369 3559
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3370 3560
 		$context['user']['popup_messages'] = false;
3371 3561
 
3372
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3373
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3562
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3563
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3564
+		}
3374 3565
 
3375 3566
 		// If we've upgraded recently, go easy on the passwords.
3376
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3377
-			$context['disable_login_hashing'] = true;
3567
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3568
+					$context['disable_login_hashing'] = true;
3569
+		}
3378 3570
 	}
3379 3571
 
3380 3572
 	// Setup the main menu items.
@@ -3387,8 +3579,8 @@  discard block
 block discarded – undo
3387 3579
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3388 3580
 
3389 3581
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3390
-	if ($context['show_pm_popup'])
3391
-		addInlineJavaScript('
3582
+	if ($context['show_pm_popup']) {
3583
+			addInlineJavaScript('
3392 3584
 		jQuery(document).ready(function($) {
3393 3585
 			new smc_Popup({
3394 3586
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3396,24 +3588,28 @@  discard block
 block discarded – undo
3396 3588
 				icon_class: \'generic_icons mail_new\'
3397 3589
 			});
3398 3590
 		});');
3591
+	}
3399 3592
 
3400 3593
 	// Add a generic "Are you sure?" confirmation message.
3401 3594
 	addInlineJavaScript('
3402 3595
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3403 3596
 
3404 3597
 	// Now add the capping code for avatars.
3405
-	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')
3406
-		addInlineCss('
3598
+	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') {
3599
+			addInlineCss('
3407 3600
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3601
+	}
3408 3602
 
3409 3603
 	// Add max image limits
3410
-	if (!empty($modSettings['max_image_width']))
3411
-		addInlineCss('
3604
+	if (!empty($modSettings['max_image_width'])) {
3605
+			addInlineCss('
3412 3606
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3607
+	}
3413 3608
 
3414
-	if (!empty($modSettings['max_image_height']))
3415
-		addInlineCss('
3609
+	if (!empty($modSettings['max_image_height'])) {
3610
+			addInlineCss('
3416 3611
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3612
+	}
3417 3613
 
3418 3614
 	// This looks weird, but it's because BoardIndex.php references the variable.
3419 3615
 	$context['common_stats']['latest_member'] = array(
@@ -3430,11 +3626,13 @@  discard block
 block discarded – undo
3430 3626
 	);
3431 3627
 	$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']);
3432 3628
 
3433
-	if (empty($settings['theme_version']))
3434
-		addJavaScriptVar('smf_scripturl', $scripturl);
3629
+	if (empty($settings['theme_version'])) {
3630
+			addJavaScriptVar('smf_scripturl', $scripturl);
3631
+	}
3435 3632
 
3436
-	if (!isset($context['page_title']))
3437
-		$context['page_title'] = '';
3633
+	if (!isset($context['page_title'])) {
3634
+			$context['page_title'] = '';
3635
+	}
3438 3636
 
3439 3637
 	// Set some specific vars.
3440 3638
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3444,21 +3642,23 @@  discard block
 block discarded – undo
3444 3642
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3445 3643
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3446 3644
 
3447
-	if (!empty($context['meta_keywords']))
3448
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3645
+	if (!empty($context['meta_keywords'])) {
3646
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3647
+	}
3449 3648
 
3450
-	if (!empty($context['canonical_url']))
3451
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3649
+	if (!empty($context['canonical_url'])) {
3650
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3651
+	}
3452 3652
 
3453
-	if (!empty($settings['og_image']))
3454
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3653
+	if (!empty($settings['og_image'])) {
3654
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3655
+	}
3455 3656
 
3456 3657
 	if (!empty($context['meta_description']))
3457 3658
 	{
3458 3659
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3459 3660
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3460
-	}
3461
-	else
3661
+	} else
3462 3662
 	{
3463 3663
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3464 3664
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3483,8 +3683,9 @@  discard block
 block discarded – undo
3483 3683
 	$memory_needed = memoryReturnBytes($needed);
3484 3684
 
3485 3685
 	// should we account for how much is currently being used?
3486
-	if ($in_use)
3487
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3686
+	if ($in_use) {
3687
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3688
+	}
3488 3689
 
3489 3690
 	// if more is needed, request it
3490 3691
 	if ($memory_current < $memory_needed)
@@ -3507,8 +3708,9 @@  discard block
 block discarded – undo
3507 3708
  */
3508 3709
 function memoryReturnBytes($val)
3509 3710
 {
3510
-	if (is_integer($val))
3511
-		return $val;
3711
+	if (is_integer($val)) {
3712
+			return $val;
3713
+	}
3512 3714
 
3513 3715
 	// Separate the number from the designator
3514 3716
 	$val = trim($val);
@@ -3544,10 +3746,11 @@  discard block
 block discarded – undo
3544 3746
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3545 3747
 
3546 3748
 		// Are we debugging the template/html content?
3547
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3548
-			header('content-type: application/xhtml+xml');
3549
-		elseif (!isset($_REQUEST['xml']))
3550
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3749
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3750
+					header('content-type: application/xhtml+xml');
3751
+		} elseif (!isset($_REQUEST['xml'])) {
3752
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3753
+		}
3551 3754
 	}
3552 3755
 
3553 3756
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3556,8 +3759,9 @@  discard block
 block discarded – undo
3556 3759
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3557 3760
 	{
3558 3761
 		$position = array_search('body', $context['template_layers']);
3559
-		if ($position === false)
3560
-			$position = array_search('main', $context['template_layers']);
3762
+		if ($position === false) {
3763
+					$position = array_search('main', $context['template_layers']);
3764
+		}
3561 3765
 
3562 3766
 		if ($position !== false)
3563 3767
 		{
@@ -3585,23 +3789,25 @@  discard block
 block discarded – undo
3585 3789
 
3586 3790
 			foreach ($securityFiles as $i => $securityFile)
3587 3791
 			{
3588
-				if (!file_exists($boarddir . '/' . $securityFile))
3589
-					unset($securityFiles[$i]);
3792
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3793
+									unset($securityFiles[$i]);
3794
+				}
3590 3795
 			}
3591 3796
 
3592 3797
 			// We are already checking so many files...just few more doesn't make any difference! :P
3593
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3594
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3595
-
3596
-			else
3597
-				$path = $modSettings['attachmentUploadDir'];
3798
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3799
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3800
+			} else {
3801
+							$path = $modSettings['attachmentUploadDir'];
3802
+			}
3598 3803
 
3599 3804
 			secureDirectory($path, true);
3600 3805
 			secureDirectory($cachedir);
3601 3806
 
3602 3807
 			// If agreement is enabled, at least the english version shall exists
3603
-			if ($modSettings['requireAgreement'])
3604
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3808
+			if ($modSettings['requireAgreement']) {
3809
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3810
+			}
3605 3811
 
3606 3812
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3607 3813
 			{
@@ -3616,18 +3822,21 @@  discard block
 block discarded – undo
3616 3822
 					echo '
3617 3823
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3618 3824
 
3619
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3620
-						echo '
3825
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3826
+											echo '
3621 3827
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3828
+					}
3622 3829
 				}
3623 3830
 
3624
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3625
-					echo '
3831
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3832
+									echo '
3626 3833
 				<strong>', $txt['cache_writable'], '</strong><br>';
3834
+				}
3627 3835
 
3628
-				if (!empty($agreement))
3629
-					echo '
3836
+				if (!empty($agreement)) {
3837
+									echo '
3630 3838
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3839
+				}
3631 3840
 
3632 3841
 				echo '
3633 3842
 			</p>
@@ -3642,16 +3851,18 @@  discard block
 block discarded – undo
3642 3851
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3643 3852
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3644 3853
 
3645
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3646
-				echo '
3854
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3855
+							echo '
3647 3856
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3857
+			}
3648 3858
 
3649
-			if (!empty($_SESSION['ban']['expire_time']))
3650
-				echo '
3859
+			if (!empty($_SESSION['ban']['expire_time'])) {
3860
+							echo '
3651 3861
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3652
-			else
3653
-				echo '
3862
+			} else {
3863
+							echo '
3654 3864
 					<div>', $txt['your_ban_expires_never'], '</div>';
3865
+			}
3655 3866
 
3656 3867
 			echo '
3657 3868
 				</div>';
@@ -3667,8 +3878,9 @@  discard block
 block discarded – undo
3667 3878
 	global $forum_copyright, $software_year, $forum_version;
3668 3879
 
3669 3880
 	// Don't display copyright for things like SSI.
3670
-	if (!isset($forum_version) || !isset($software_year))
3671
-		return;
3881
+	if (!isset($forum_version) || !isset($software_year)) {
3882
+			return;
3883
+	}
3672 3884
 
3673 3885
 	// Put in the version...
3674 3886
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3686,9 +3898,10 @@  discard block
 block discarded – undo
3686 3898
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3687 3899
 	$context['load_queries'] = $db_count;
3688 3900
 
3689
-	foreach (array_reverse($context['template_layers']) as $layer)
3690
-		loadSubTemplate($layer . '_below', true);
3691
-}
3901
+	foreach (array_reverse($context['template_layers']) as $layer) {
3902
+			loadSubTemplate($layer . '_below', true);
3903
+	}
3904
+	}
3692 3905
 
3693 3906
 /**
3694 3907
  * Output the Javascript files
@@ -3722,8 +3935,7 @@  discard block
 block discarded – undo
3722 3935
 			{
3723 3936
 				echo '
3724 3937
 		var ', $key, ';';
3725
-			}
3726
-			else
3938
+			} else
3727 3939
 			{
3728 3940
 				echo '
3729 3941
 		var ', $key, ' = ', $value, ';';
@@ -3742,27 +3954,29 @@  discard block
 block discarded – undo
3742 3954
 		foreach ($context['javascript_files'] as $id => $js_file)
3743 3955
 		{
3744 3956
 			// Last minute call! allow theme authors to disable single files.
3745
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3746
-				continue;
3957
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3958
+							continue;
3959
+			}
3747 3960
 
3748 3961
 			// By default files don't get minimized unless the file explicitly says so!
3749 3962
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3750 3963
 			{
3751
-				if (!empty($js_file['options']['async']))
3752
-					$toMinify['async'][] = $js_file;
3753
-				elseif (!empty($js_file['options']['defer']))
3754
-					$toMinify['defer'][] = $js_file;
3755
-				else
3756
-					$toMinify['standard'][] = $js_file;
3964
+				if (!empty($js_file['options']['async'])) {
3965
+									$toMinify['async'][] = $js_file;
3966
+				} elseif (!empty($js_file['options']['defer'])) {
3967
+									$toMinify['defer'][] = $js_file;
3968
+				} else {
3969
+									$toMinify['standard'][] = $js_file;
3970
+				}
3757 3971
 
3758 3972
 				// Grab a random seed.
3759
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3760
-					$minSeed = $js_file['options']['seed'];
3761
-			}
3762
-
3763
-			else
3764
-				echo '
3973
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3974
+									$minSeed = $js_file['options']['seed'];
3975
+				}
3976
+			} else {
3977
+							echo '
3765 3978
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3979
+			}
3766 3980
 		}
3767 3981
 
3768 3982
 		foreach ($toMinify as $js_files)
@@ -3773,9 +3987,10 @@  discard block
 block discarded – undo
3773 3987
 
3774 3988
 				$minSuccessful = array_keys($result) === array('smf_minified');
3775 3989
 
3776
-				foreach ($result as $minFile)
3777
-					echo '
3990
+				foreach ($result as $minFile) {
3991
+									echo '
3778 3992
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
3993
+				}
3779 3994
 			}
3780 3995
 		}
3781 3996
 	}
@@ -3789,8 +4004,9 @@  discard block
 block discarded – undo
3789 4004
 <script>
3790 4005
 window.addEventListener("DOMContentLoaded", function() {';
3791 4006
 
3792
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3793
-				echo $js_code;
4007
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4008
+							echo $js_code;
4009
+			}
3794 4010
 
3795 4011
 			echo '
3796 4012
 });
@@ -3802,8 +4018,9 @@  discard block
 block discarded – undo
3802 4018
 			echo '
3803 4019
 	<script>';
3804 4020
 
3805
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3806
-				echo $js_code;
4021
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4022
+							echo $js_code;
4023
+			}
3807 4024
 
3808 4025
 			echo '
3809 4026
 	</script>';
@@ -3831,23 +4048,26 @@  discard block
 block discarded – undo
3831 4048
 	foreach ($context['css_files'] as $id => $file)
3832 4049
 	{
3833 4050
 		// Last minute call! allow theme authors to disable single files.
3834
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3835
-			continue;
4051
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4052
+					continue;
4053
+		}
3836 4054
 
3837 4055
 		// Files are minimized unless they explicitly opt out.
3838
-		if (!isset($file['options']['minimize']))
3839
-			$file['options']['minimize'] = true;
4056
+		if (!isset($file['options']['minimize'])) {
4057
+					$file['options']['minimize'] = true;
4058
+		}
3840 4059
 
3841 4060
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']) && !isset($_REQUEST['normalcss']))
3842 4061
 		{
3843 4062
 			$toMinify[] = $file;
3844 4063
 
3845 4064
 			// Grab a random seed.
3846
-			if (!isset($minSeed) && isset($file['options']['seed']))
3847
-				$minSeed = $file['options']['seed'];
4065
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4066
+							$minSeed = $file['options']['seed'];
4067
+			}
4068
+		} else {
4069
+					$normal[] = $file['fileUrl'];
3848 4070
 		}
3849
-		else
3850
-			$normal[] = $file['fileUrl'];
3851 4071
 	}
3852 4072
 
3853 4073
 	if (!empty($toMinify))
@@ -3856,23 +4076,26 @@  discard block
 block discarded – undo
3856 4076
 
3857 4077
 		$minSuccessful = array_keys($result) === array('smf_minified');
3858 4078
 
3859
-		foreach ($result as $minFile)
3860
-			echo '
4079
+		foreach ($result as $minFile) {
4080
+					echo '
3861 4081
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4082
+		}
3862 4083
 	}
3863 4084
 
3864 4085
 	// Print the rest after the minified files.
3865
-	if (!empty($normal))
3866
-		foreach ($normal as $nf)
4086
+	if (!empty($normal)) {
4087
+			foreach ($normal as $nf)
3867 4088
 			echo '
3868 4089
 	<link rel="stylesheet" href="', $nf ,'">';
4090
+	}
3869 4091
 
3870 4092
 	if ($db_show_debug === true)
3871 4093
 	{
3872 4094
 		// Try to keep only what's useful.
3873 4095
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3874
-		foreach ($context['css_files'] as $file)
3875
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4096
+		foreach ($context['css_files'] as $file) {
4097
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4098
+		}
3876 4099
 	}
3877 4100
 
3878 4101
 	if (!empty($context['css_header']))
@@ -3880,9 +4103,10 @@  discard block
 block discarded – undo
3880 4103
 		echo '
3881 4104
 	<style>';
3882 4105
 
3883
-		foreach ($context['css_header'] as $css)
3884
-			echo $css .'
4106
+		foreach ($context['css_header'] as $css) {
4107
+					echo $css .'
3885 4108
 	';
4109
+		}
3886 4110
 
3887 4111
 		echo'
3888 4112
 	</style>';
@@ -3905,8 +4129,9 @@  discard block
 block discarded – undo
3905 4129
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3906 4130
 	$data = is_array($data) ? $data : array();
3907 4131
 
3908
-	if (empty($type) || empty($data))
3909
-		return $data;
4132
+	if (empty($type) || empty($data)) {
4133
+			return $data;
4134
+	}
3910 4135
 
3911 4136
 	// Different pages include different files, so we use a hash to label the different combinations
3912 4137
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3915,13 +4140,14 @@  discard block
 block discarded – undo
3915 4140
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3916 4141
 
3917 4142
 	// Already done?
3918
-	if (!empty($toCache))
3919
-		return array('smf_minified' => array(
4143
+	if (!empty($toCache)) {
4144
+			return array('smf_minified' => array(
3920 4145
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3921 4146
 			'filePath' => $toCache,
3922 4147
 			'fileName' => basename($toCache),
3923 4148
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3924 4149
 		));
4150
+	}
3925 4151
 
3926 4152
 
3927 4153
 	// No namespaces, sorry!
@@ -3951,9 +4177,9 @@  discard block
 block discarded – undo
3951 4177
 
3952 4178
 	foreach ($data as $id => $file)
3953 4179
 	{
3954
-		if (empty($file['filePath']))
3955
-			$toAdd = false;
3956
-		else
4180
+		if (empty($file['filePath'])) {
4181
+					$toAdd = false;
4182
+		} else
3957 4183
 		{
3958 4184
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3959 4185
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3961,12 +4187,14 @@  discard block
 block discarded – undo
3961 4187
 		}
3962 4188
 
3963 4189
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3964
-		if (empty($file['options']['async']))
3965
-			$async = false;
4190
+		if (empty($file['options']['async'])) {
4191
+					$async = false;
4192
+		}
3966 4193
 
3967 4194
 		// A minified script should only be deferred if all its components wanted to be.
3968
-		if (empty($file['options']['defer']))
3969
-			$defer = false;
4195
+		if (empty($file['options']['defer'])) {
4196
+					$defer = false;
4197
+		}
3970 4198
 
3971 4199
 		// The file couldn't be located so it won't be added. Log this error.
3972 4200
 		if (empty($toAdd))
@@ -4032,12 +4260,14 @@  discard block
 block discarded – undo
4032 4260
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4033 4261
 			{
4034 4262
 				// Remove the cache entry
4035
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4036
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4263
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4264
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4265
+				}
4037 4266
 
4038 4267
 				// Try to delete the file. Add it to our error list if it fails.
4039
-				if (!@unlink($filename))
4040
-					$not_deleted[] = $filename;
4268
+				if (!@unlink($filename)) {
4269
+									$not_deleted[] = $filename;
4270
+				}
4041 4271
 			}
4042 4272
 		}
4043 4273
 	}
@@ -4069,8 +4299,9 @@  discard block
 block discarded – undo
4069 4299
 	global $modSettings, $smcFunc;
4070 4300
 
4071 4301
 	// Just make up a nice hash...
4072
-	if ($new)
4073
-		return sha1(md5($filename . time()) . random_int(0, PHP_INT_MAX));
4302
+	if ($new) {
4303
+			return sha1(md5($filename . time()) . random_int(0, PHP_INT_MAX));
4304
+	}
4074 4305
 
4075 4306
 	// Just make sure that attachment id is only a int
4076 4307
 	$attachment_id = (int) $attachment_id;
@@ -4087,23 +4318,25 @@  discard block
 block discarded – undo
4087 4318
 				'id_attach' => $attachment_id,
4088 4319
 			));
4089 4320
 
4090
-		if ($smcFunc['db_num_rows']($request) === 0)
4091
-			return false;
4321
+		if ($smcFunc['db_num_rows']($request) === 0) {
4322
+					return false;
4323
+		}
4092 4324
 
4093 4325
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4094 4326
 		$smcFunc['db_free_result']($request);
4095 4327
 	}
4096 4328
 
4097 4329
 	// Still no hash? mmm...
4098
-	if (empty($file_hash))
4099
-		$file_hash = sha1(md5($filename . time()) . random_int(0, PHP_INT_MAX));
4330
+	if (empty($file_hash)) {
4331
+			$file_hash = sha1(md5($filename . time()) . random_int(0, PHP_INT_MAX));
4332
+	}
4100 4333
 
4101 4334
 	// Are we using multiple directories?
4102
-	if (is_array($modSettings['attachmentUploadDir']))
4103
-		$path = $modSettings['attachmentUploadDir'][$dir];
4104
-
4105
-	else
4106
-		$path = $modSettings['attachmentUploadDir'];
4335
+	if (is_array($modSettings['attachmentUploadDir'])) {
4336
+			$path = $modSettings['attachmentUploadDir'][$dir];
4337
+	} else {
4338
+			$path = $modSettings['attachmentUploadDir'];
4339
+	}
4107 4340
 
4108 4341
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4109 4342
 }
@@ -4118,8 +4351,9 @@  discard block
 block discarded – undo
4118 4351
 function ip2range($fullip)
4119 4352
 {
4120 4353
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4121
-	if ($fullip == 'unknown')
4122
-		$fullip = '255.255.255.255';
4354
+	if ($fullip == 'unknown') {
4355
+			$fullip = '255.255.255.255';
4356
+	}
4123 4357
 
4124 4358
 	$ip_parts = explode('-', $fullip);
4125 4359
 	$ip_array = array();
@@ -4143,10 +4377,11 @@  discard block
 block discarded – undo
4143 4377
 		$ip_array['low'] = $ip_parts[0];
4144 4378
 		$ip_array['high'] = $ip_parts[1];
4145 4379
 		return $ip_array;
4146
-	}
4147
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4380
+	} elseif (count($ip_parts) == 2) {
4381
+		// if ip 22.22.*-22.22.*
4148 4382
 	{
4149 4383
 		$valid_low = isValidIP($ip_parts[0]);
4384
+	}
4150 4385
 		$valid_high = isValidIP($ip_parts[1]);
4151 4386
 		$count = 0;
4152 4387
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4161,7 +4396,9 @@  discard block
 block discarded – undo
4161 4396
 				$ip_parts[0] .= $mode . $min;
4162 4397
 				$valid_low = isValidIP($ip_parts[0]);
4163 4398
 				$count++;
4164
-				if ($count > 9) break;
4399
+				if ($count > 9) {
4400
+					break;
4401
+				}
4165 4402
 			}
4166 4403
 		}
4167 4404
 
@@ -4175,7 +4412,9 @@  discard block
 block discarded – undo
4175 4412
 				$ip_parts[1] .= $mode . $max;
4176 4413
 				$valid_high = isValidIP($ip_parts[1]);
4177 4414
 				$count++;
4178
-				if ($count > 9) break;
4415
+				if ($count > 9) {
4416
+					break;
4417
+				}
4179 4418
 			}
4180 4419
 		}
4181 4420
 
@@ -4199,46 +4438,54 @@  discard block
 block discarded – undo
4199 4438
 {
4200 4439
 	global $modSettings;
4201 4440
 
4202
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4203
-		return $host;
4441
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4442
+			return $host;
4443
+	}
4204 4444
 	$t = microtime(true);
4205 4445
 
4206 4446
 	// Try the Linux host command, perhaps?
4207 4447
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && random_int(0, 1) == 1)
4208 4448
 	{
4209
-		if (!isset($modSettings['host_to_dis']))
4210
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4211
-		else
4212
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4449
+		if (!isset($modSettings['host_to_dis'])) {
4450
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4451
+		} else {
4452
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4453
+		}
4213 4454
 
4214 4455
 		// Did host say it didn't find anything?
4215
-		if (strpos($test, 'not found') !== false)
4216
-			$host = '';
4456
+		if (strpos($test, 'not found') !== false) {
4457
+					$host = '';
4458
+		}
4217 4459
 		// Invalid server option?
4218
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4219
-			updateSettings(array('host_to_dis' => 1));
4460
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4461
+					updateSettings(array('host_to_dis' => 1));
4462
+		}
4220 4463
 		// Maybe it found something, after all?
4221
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4222
-			$host = $match[1];
4464
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4465
+					$host = $match[1];
4466
+		}
4223 4467
 	}
4224 4468
 
4225 4469
 	// This is nslookup; usually only Windows, but possibly some Unix?
4226 4470
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && random_int(0, 1) == 1)
4227 4471
 	{
4228 4472
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4229
-		if (strpos($test, 'Non-existent domain') !== false)
4230
-			$host = '';
4231
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4232
-			$host = $match[1];
4473
+		if (strpos($test, 'Non-existent domain') !== false) {
4474
+					$host = '';
4475
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4476
+					$host = $match[1];
4477
+		}
4233 4478
 	}
4234 4479
 
4235 4480
 	// This is the last try :/.
4236
-	if (!isset($host) || $host === false)
4237
-		$host = @gethostbyaddr($ip);
4481
+	if (!isset($host) || $host === false) {
4482
+			$host = @gethostbyaddr($ip);
4483
+	}
4238 4484
 
4239 4485
 	// It took a long time, so let's cache it!
4240
-	if (microtime(true) - $t > 0.5)
4241
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4486
+	if (microtime(true) - $t > 0.5) {
4487
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4488
+	}
4242 4489
 
4243 4490
 	return $host;
4244 4491
 }
@@ -4274,20 +4521,21 @@  discard block
 block discarded – undo
4274 4521
 			{
4275 4522
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4276 4523
 				$total = 0;
4277
-				for ($i = 0; $i < $max_chars; $i++)
4278
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4524
+				for ($i = 0; $i < $max_chars; $i++) {
4525
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4526
+				}
4279 4527
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4280 4528
 			}
4281 4529
 		}
4282 4530
 		return array_unique($returned_ints);
4283
-	}
4284
-	else
4531
+	} else
4285 4532
 	{
4286 4533
 		// Trim characters before and after and add slashes for database insertion.
4287 4534
 		$returned_words = array();
4288
-		foreach ($words as $word)
4289
-			if (($word = trim($word, '-_\'')) !== '')
4535
+		foreach ($words as $word) {
4536
+					if (($word = trim($word, '-_\'')) !== '')
4290 4537
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4538
+		}
4291 4539
 
4292 4540
 		// Filter out all words that occur more than once.
4293 4541
 		return array_unique($returned_words);
@@ -4309,16 +4557,18 @@  discard block
 block discarded – undo
4309 4557
 	global $settings, $txt;
4310 4558
 
4311 4559
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4312
-	if (function_exists('template_create_button') && !$force_use)
4313
-		return template_create_button($name, $alt, $label = '', $custom = '');
4560
+	if (function_exists('template_create_button') && !$force_use) {
4561
+			return template_create_button($name, $alt, $label = '', $custom = '');
4562
+	}
4314 4563
 
4315
-	if (!$settings['use_image_buttons'])
4316
-		return $txt[$alt];
4317
-	elseif (!empty($settings['use_buttons']))
4318
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4319
-	else
4320
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4321
-}
4564
+	if (!$settings['use_image_buttons']) {
4565
+			return $txt[$alt];
4566
+	} elseif (!empty($settings['use_buttons'])) {
4567
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4568
+	} else {
4569
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4570
+	}
4571
+	}
4322 4572
 
4323 4573
 /**
4324 4574
  * Sets up all of the top menu buttons
@@ -4361,9 +4611,10 @@  discard block
 block discarded – undo
4361 4611
 	var user_menus = new smc_PopupMenu();
4362 4612
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4363 4613
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4364
-		if ($context['allow_pm'])
4365
-			addInlineJavaScript('
4614
+		if ($context['allow_pm']) {
4615
+					addInlineJavaScript('
4366 4616
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4617
+		}
4367 4618
 
4368 4619
 		if (!empty($modSettings['enable_ajax_alerts']))
4369 4620
 		{
@@ -4523,88 +4774,96 @@  discard block
 block discarded – undo
4523 4774
 
4524 4775
 		// Now we put the buttons in the context so the theme can use them.
4525 4776
 		$menu_buttons = array();
4526
-		foreach ($buttons as $act => $button)
4527
-			if (!empty($button['show']))
4777
+		foreach ($buttons as $act => $button) {
4778
+					if (!empty($button['show']))
4528 4779
 			{
4529 4780
 				$button['active_button'] = false;
4781
+		}
4530 4782
 
4531 4783
 				// This button needs some action.
4532
-				if (isset($button['action_hook']))
4533
-					$needs_action_hook = true;
4784
+				if (isset($button['action_hook'])) {
4785
+									$needs_action_hook = true;
4786
+				}
4534 4787
 
4535 4788
 				// Make sure the last button truly is the last button.
4536 4789
 				if (!empty($button['is_last']))
4537 4790
 				{
4538
-					if (isset($last_button))
4539
-						unset($menu_buttons[$last_button]['is_last']);
4791
+					if (isset($last_button)) {
4792
+											unset($menu_buttons[$last_button]['is_last']);
4793
+					}
4540 4794
 					$last_button = $act;
4541 4795
 				}
4542 4796
 
4543 4797
 				// Go through the sub buttons if there are any.
4544
-				if (!empty($button['sub_buttons']))
4545
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4798
+				if (!empty($button['sub_buttons'])) {
4799
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4546 4800
 					{
4547 4801
 						if (empty($subbutton['show']))
4548 4802
 							unset($button['sub_buttons'][$key]);
4803
+				}
4549 4804
 
4550 4805
 						// 2nd level sub buttons next...
4551 4806
 						if (!empty($subbutton['sub_buttons']))
4552 4807
 						{
4553 4808
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4554 4809
 							{
4555
-								if (empty($sub_button2['show']))
4556
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4810
+								if (empty($sub_button2['show'])) {
4811
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4812
+								}
4557 4813
 							}
4558 4814
 						}
4559 4815
 					}
4560 4816
 
4561 4817
 				// Does this button have its own icon?
4562
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4563
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4564
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4565
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4566
-				elseif (isset($button['icon']))
4567
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4568
-				else
4569
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4818
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4819
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4820
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4821
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4822
+				} elseif (isset($button['icon'])) {
4823
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4824
+				} else {
4825
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4826
+				}
4570 4827
 
4571 4828
 				$menu_buttons[$act] = $button;
4572 4829
 			}
4573 4830
 
4574
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4575
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4831
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4832
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4833
+		}
4576 4834
 	}
4577 4835
 
4578 4836
 	$context['menu_buttons'] = $menu_buttons;
4579 4837
 
4580 4838
 	// Logging out requires the session id in the url.
4581
-	if (isset($context['menu_buttons']['logout']))
4582
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4839
+	if (isset($context['menu_buttons']['logout'])) {
4840
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4841
+	}
4583 4842
 
4584 4843
 	// Figure out which action we are doing so we can set the active tab.
4585 4844
 	// Default to home.
4586 4845
 	$current_action = 'home';
4587 4846
 
4588
-	if (isset($context['menu_buttons'][$context['current_action']]))
4589
-		$current_action = $context['current_action'];
4590
-	elseif ($context['current_action'] == 'search2')
4591
-		$current_action = 'search';
4592
-	elseif ($context['current_action'] == 'theme')
4593
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4594
-	elseif ($context['current_action'] == 'register2')
4595
-		$current_action = 'register';
4596
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4597
-		$current_action = 'login';
4598
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4599
-		$current_action = 'moderate';
4847
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4848
+			$current_action = $context['current_action'];
4849
+	} elseif ($context['current_action'] == 'search2') {
4850
+			$current_action = 'search';
4851
+	} elseif ($context['current_action'] == 'theme') {
4852
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4853
+	} elseif ($context['current_action'] == 'register2') {
4854
+			$current_action = 'register';
4855
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4856
+			$current_action = 'login';
4857
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4858
+			$current_action = 'moderate';
4859
+	}
4600 4860
 
4601 4861
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4602 4862
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4603 4863
 	{
4604 4864
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4605 4865
 		$context[$current_action] = true;
4606
-	}
4607
-	elseif ($context['current_action'] == 'pm')
4866
+	} elseif ($context['current_action'] == 'pm')
4608 4867
 	{
4609 4868
 		$current_action = 'self_pm';
4610 4869
 		$context['self_pm'] = true;
@@ -4667,12 +4926,14 @@  discard block
 block discarded – undo
4667 4926
 	}
4668 4927
 
4669 4928
 	// Not all actions are simple.
4670
-	if (!empty($needs_action_hook))
4671
-		call_integration_hook('integrate_current_action', array(&$current_action));
4929
+	if (!empty($needs_action_hook)) {
4930
+			call_integration_hook('integrate_current_action', array(&$current_action));
4931
+	}
4672 4932
 
4673
-	if (isset($context['menu_buttons'][$current_action]))
4674
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4675
-}
4933
+	if (isset($context['menu_buttons'][$current_action])) {
4934
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4935
+	}
4936
+	}
4676 4937
 
4677 4938
 /**
4678 4939
  * Generate a random seed and ensure it's stored in settings.
@@ -4696,30 +4957,35 @@  discard block
 block discarded – undo
4696 4957
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4697 4958
 	global $context, $txt;
4698 4959
 
4699
-	if ($db_show_debug === true)
4700
-		$context['debug']['hooks'][] = $hook;
4960
+	if ($db_show_debug === true) {
4961
+			$context['debug']['hooks'][] = $hook;
4962
+	}
4701 4963
 
4702 4964
 	// Need to have some control.
4703
-	if (!isset($context['instances']))
4704
-		$context['instances'] = array();
4965
+	if (!isset($context['instances'])) {
4966
+			$context['instances'] = array();
4967
+	}
4705 4968
 
4706 4969
 	$results = array();
4707
-	if (empty($modSettings[$hook]))
4708
-		return $results;
4970
+	if (empty($modSettings[$hook])) {
4971
+			return $results;
4972
+	}
4709 4973
 
4710 4974
 	$functions = explode(',', $modSettings[$hook]);
4711 4975
 	// Loop through each function.
4712 4976
 	foreach ($functions as $function)
4713 4977
 	{
4714 4978
 		// Hook has been marked as "disabled". Skip it!
4715
-		if (strpos($function, '!') !== false)
4716
-			continue;
4979
+		if (strpos($function, '!') !== false) {
4980
+					continue;
4981
+		}
4717 4982
 
4718 4983
 		$call = call_helper($function, true);
4719 4984
 
4720 4985
 		// Is it valid?
4721
-		if (!empty($call))
4722
-			$results[$function] = call_user_func_array($call, $parameters);
4986
+		if (!empty($call)) {
4987
+					$results[$function] = call_user_func_array($call, $parameters);
4988
+		}
4723 4989
 
4724 4990
 		// Whatever it was suppose to call, it failed :(
4725 4991
 		elseif (!empty($function))
@@ -4735,8 +5001,9 @@  discard block
 block discarded – undo
4735 5001
 			}
4736 5002
 
4737 5003
 			// "Assume" the file resides on $boarddir somewhere...
4738
-			else
4739
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5004
+			else {
5005
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5006
+			}
4740 5007
 		}
4741 5008
 	}
4742 5009
 
@@ -4758,12 +5025,14 @@  discard block
 block discarded – undo
4758 5025
 	global $smcFunc, $modSettings;
4759 5026
 
4760 5027
 	// Any objects?
4761
-	if ($object)
4762
-		$function = $function . '#';
5028
+	if ($object) {
5029
+			$function = $function . '#';
5030
+	}
4763 5031
 
4764 5032
 	// Any files  to load?
4765
-	if (!empty($file) && is_string($file))
4766
-		$function = $file . (!empty($function) ? '|' . $function : '');
5033
+	if (!empty($file) && is_string($file)) {
5034
+			$function = $file . (!empty($function) ? '|' . $function : '');
5035
+	}
4767 5036
 
4768 5037
 	// Get the correct string.
4769 5038
 	$integration_call = $function;
@@ -4785,13 +5054,14 @@  discard block
 block discarded – undo
4785 5054
 		if (!empty($current_functions))
4786 5055
 		{
4787 5056
 			$current_functions = explode(',', $current_functions);
4788
-			if (in_array($integration_call, $current_functions))
4789
-				return;
5057
+			if (in_array($integration_call, $current_functions)) {
5058
+							return;
5059
+			}
4790 5060
 
4791 5061
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5062
+		} else {
5063
+					$permanent_functions = array($integration_call);
4792 5064
 		}
4793
-		else
4794
-			$permanent_functions = array($integration_call);
4795 5065
 
4796 5066
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4797 5067
 	}
@@ -4800,8 +5070,9 @@  discard block
 block discarded – undo
4800 5070
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4801 5071
 
4802 5072
 	// Do nothing, if it's already there.
4803
-	if (in_array($integration_call, $functions))
4804
-		return;
5073
+	if (in_array($integration_call, $functions)) {
5074
+			return;
5075
+	}
4805 5076
 
4806 5077
 	$functions[] = $integration_call;
4807 5078
 	$modSettings[$hook] = implode(',', $functions);
@@ -4824,12 +5095,14 @@  discard block
 block discarded – undo
4824 5095
 	global $smcFunc, $modSettings;
4825 5096
 
4826 5097
 	// Any objects?
4827
-	if ($object)
4828
-		$function = $function . '#';
5098
+	if ($object) {
5099
+			$function = $function . '#';
5100
+	}
4829 5101
 
4830 5102
 	// Any files  to load?
4831
-	if (!empty($file) && is_string($file))
4832
-		$function = $file . '|' . $function;
5103
+	if (!empty($file) && is_string($file)) {
5104
+			$function = $file . '|' . $function;
5105
+	}
4833 5106
 
4834 5107
 	// Get the correct string.
4835 5108
 	$integration_call = $function;
@@ -4850,16 +5123,18 @@  discard block
 block discarded – undo
4850 5123
 	{
4851 5124
 		$current_functions = explode(',', $current_functions);
4852 5125
 
4853
-		if (in_array($integration_call, $current_functions))
4854
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5126
+		if (in_array($integration_call, $current_functions)) {
5127
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5128
+		}
4855 5129
 	}
4856 5130
 
4857 5131
 	// Turn the function list into something usable.
4858 5132
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4859 5133
 
4860 5134
 	// You can only remove it if it's available.
4861
-	if (!in_array($integration_call, $functions))
4862
-		return;
5135
+	if (!in_array($integration_call, $functions)) {
5136
+			return;
5137
+	}
4863 5138
 
4864 5139
 	$functions = array_diff($functions, array($integration_call));
4865 5140
 	$modSettings[$hook] = implode(',', $functions);
@@ -4880,17 +5155,20 @@  discard block
 block discarded – undo
4880 5155
 	global $context, $smcFunc, $txt, $db_show_debug;
4881 5156
 
4882 5157
 	// Really?
4883
-	if (empty($string))
4884
-		return false;
5158
+	if (empty($string)) {
5159
+			return false;
5160
+	}
4885 5161
 
4886 5162
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4887 5163
 	// A closure? should be a callable one.
4888
-	if (is_array($string) || $string instanceof Closure)
4889
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5164
+	if (is_array($string) || $string instanceof Closure) {
5165
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5166
+	}
4890 5167
 
4891 5168
 	// No full objects, sorry! pass a method or a property instead!
4892
-	if (is_object($string))
4893
-		return false;
5169
+	if (is_object($string)) {
5170
+			return false;
5171
+	}
4894 5172
 
4895 5173
 	// Stay vitaminized my friends...
4896 5174
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4899,8 +5177,9 @@  discard block
 block discarded – undo
4899 5177
 	$string = load_file($string);
4900 5178
 
4901 5179
 	// Loaded file failed
4902
-	if (empty($string))
4903
-		return false;
5180
+	if (empty($string)) {
5181
+			return false;
5182
+	}
4904 5183
 
4905 5184
 	// Found a method.
4906 5185
 	if (strpos($string, '::') !== false)
@@ -4921,8 +5200,9 @@  discard block
 block discarded – undo
4921 5200
 				// Add another one to the list.
4922 5201
 				if ($db_show_debug === true)
4923 5202
 				{
4924
-					if (!isset($context['debug']['instances']))
4925
-						$context['debug']['instances'] = array();
5203
+					if (!isset($context['debug']['instances'])) {
5204
+											$context['debug']['instances'] = array();
5205
+					}
4926 5206
 
4927 5207
 					$context['debug']['instances'][$class] = $class;
4928 5208
 				}
@@ -4932,13 +5212,15 @@  discard block
 block discarded – undo
4932 5212
 		}
4933 5213
 
4934 5214
 		// Right then. This is a call to a static method.
4935
-		else
4936
-			$func = array($class, $method);
5215
+		else {
5216
+					$func = array($class, $method);
5217
+		}
4937 5218
 	}
4938 5219
 
4939 5220
 	// Nope! just a plain regular function.
4940
-	else
4941
-		$func = $string;
5221
+	else {
5222
+			$func = $string;
5223
+	}
4942 5224
 
4943 5225
 	// Right, we got what we need, time to do some checks.
4944 5226
 	if (!is_callable($func, false, $callable_name))
@@ -4954,17 +5236,18 @@  discard block
 block discarded – undo
4954 5236
 	else
4955 5237
 	{
4956 5238
 		// What are we gonna do about it?
4957
-		if ($return)
4958
-			return $func;
5239
+		if ($return) {
5240
+					return $func;
5241
+		}
4959 5242
 
4960 5243
 		// If this is a plain function, avoid the heat of calling call_user_func().
4961 5244
 		else
4962 5245
 		{
4963
-			if (is_array($func))
4964
-				call_user_func($func);
4965
-
4966
-			else
4967
-				$func();
5246
+			if (is_array($func)) {
5247
+							call_user_func($func);
5248
+			} else {
5249
+							$func();
5250
+			}
4968 5251
 		}
4969 5252
 	}
4970 5253
 }
@@ -4981,31 +5264,34 @@  discard block
 block discarded – undo
4981 5264
 {
4982 5265
 	global $sourcedir, $txt, $boarddir, $settings;
4983 5266
 
4984
-	if (empty($string))
4985
-		return false;
5267
+	if (empty($string)) {
5268
+			return false;
5269
+	}
4986 5270
 
4987 5271
 	if (strpos($string, '|') !== false)
4988 5272
 	{
4989 5273
 		list ($file, $string) = explode('|', $string);
4990 5274
 
4991 5275
 		// Match the wildcards to their regular vars.
4992
-		if (empty($settings['theme_dir']))
4993
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4994
-
4995
-		else
4996
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5276
+		if (empty($settings['theme_dir'])) {
5277
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5278
+		} else {
5279
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5280
+		}
4997 5281
 
4998 5282
 		// Load the file if it can be loaded.
4999
-		if (file_exists($absPath))
5000
-			require_once($absPath);
5283
+		if (file_exists($absPath)) {
5284
+					require_once($absPath);
5285
+		}
5001 5286
 
5002 5287
 		// No? try a fallback to $sourcedir
5003 5288
 		else
5004 5289
 		{
5005 5290
 			$absPath = $sourcedir .'/'. $file;
5006 5291
 
5007
-			if (file_exists($absPath))
5008
-				require_once($absPath);
5292
+			if (file_exists($absPath)) {
5293
+							require_once($absPath);
5294
+			}
5009 5295
 
5010 5296
 			// Sorry, can't do much for you at this point.
5011 5297
 			else
@@ -5044,8 +5330,9 @@  discard block
 block discarded – undo
5044 5330
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5045 5331
 
5046 5332
 	// No scheme? No data for you!
5047
-	if (empty($match[1]))
5048
-		return false;
5333
+	if (empty($match[1])) {
5334
+			return false;
5335
+	}
5049 5336
 
5050 5337
 	// An FTP url. We should try connecting and RETRieving it...
5051 5338
 	elseif ($match[1] == 'ftp')
@@ -5055,23 +5342,26 @@  discard block
 block discarded – undo
5055 5342
 
5056 5343
 		// Establish a connection and attempt to enable passive mode.
5057 5344
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5058
-		if ($ftp->error !== false || !$ftp->passive())
5059
-			return false;
5345
+		if ($ftp->error !== false || !$ftp->passive()) {
5346
+					return false;
5347
+		}
5060 5348
 
5061 5349
 		// I want that one *points*!
5062 5350
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5063 5351
 
5064 5352
 		// Since passive mode worked (or we would have returned already!) open the connection.
5065 5353
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5066
-		if (!$fp)
5067
-			return false;
5354
+		if (!$fp) {
5355
+					return false;
5356
+		}
5068 5357
 
5069 5358
 		// The server should now say something in acknowledgement.
5070 5359
 		$ftp->check_response(150);
5071 5360
 
5072 5361
 		$data = '';
5073
-		while (!feof($fp))
5074
-			$data .= fread($fp, 4096);
5362
+		while (!feof($fp)) {
5363
+					$data .= fread($fp, 4096);
5364
+		}
5075 5365
 		fclose($fp);
5076 5366
 
5077 5367
 		// All done, right?  Good.
@@ -5083,8 +5373,9 @@  discard block
 block discarded – undo
5083 5373
 	elseif (isset($match[1]) && $match[1] == 'http')
5084 5374
 	{
5085 5375
 		// First try to use fsockopen, because it is fastest.
5086
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5087
-			$fp = $keep_alive_fp;
5376
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5377
+					$fp = $keep_alive_fp;
5378
+		}
5088 5379
 		if (empty($fp))
5089 5380
 		{
5090 5381
 			// Open the socket on the port we want...
@@ -5104,20 +5395,21 @@  discard block
 block discarded – undo
5104 5395
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5105 5396
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5106 5397
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5107
-				if ($keep_alive)
5108
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5109
-				else
5110
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5111
-			}
5112
-			else
5398
+				if ($keep_alive) {
5399
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5400
+				} else {
5401
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5402
+				}
5403
+			} else
5113 5404
 			{
5114 5405
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5115 5406
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5116 5407
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5117
-				if ($keep_alive)
5118
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5119
-				else
5120
-					fwrite($fp, 'connection: close' . "\r\n");
5408
+				if ($keep_alive) {
5409
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5410
+				} else {
5411
+									fwrite($fp, 'connection: close' . "\r\n");
5412
+				}
5121 5413
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5122 5414
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5123 5415
 				fwrite($fp, $post_data);
@@ -5130,30 +5422,33 @@  discard block
 block discarded – undo
5130 5422
 			{
5131 5423
 				$header = '';
5132 5424
 				$location = '';
5133
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5134
-					if (strpos($header, 'location:') !== false)
5425
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5426
+									if (strpos($header, 'location:') !== false)
5135 5427
 						$location = trim(substr($header, strpos($header, ':') + 1));
5428
+				}
5136 5429
 
5137
-				if (empty($location))
5138
-					return false;
5139
-				else
5430
+				if (empty($location)) {
5431
+									return false;
5432
+				} else
5140 5433
 				{
5141
-					if (!$keep_alive)
5142
-						fclose($fp);
5434
+					if (!$keep_alive) {
5435
+											fclose($fp);
5436
+					}
5143 5437
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5144 5438
 				}
5145 5439
 			}
5146 5440
 
5147 5441
 			// Make sure we get a 200 OK.
5148
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5149
-				return false;
5442
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5443
+							return false;
5444
+			}
5150 5445
 
5151 5446
 			// Skip the headers...
5152 5447
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5153 5448
 			{
5154
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5155
-					$content_length = $match[1];
5156
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5449
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5450
+									$content_length = $match[1];
5451
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5157 5452
 				{
5158 5453
 					$keep_alive_dom = null;
5159 5454
 					$keep_alive = false;
@@ -5165,17 +5460,19 @@  discard block
 block discarded – undo
5165 5460
 			$data = '';
5166 5461
 			if (isset($content_length))
5167 5462
 			{
5168
-				while (!feof($fp) && strlen($data) < $content_length)
5169
-					$data .= fread($fp, $content_length - strlen($data));
5170
-			}
5171
-			else
5463
+				while (!feof($fp) && strlen($data) < $content_length) {
5464
+									$data .= fread($fp, $content_length - strlen($data));
5465
+				}
5466
+			} else
5172 5467
 			{
5173
-				while (!feof($fp))
5174
-					$data .= fread($fp, 4096);
5468
+				while (!feof($fp)) {
5469
+									$data .= fread($fp, 4096);
5470
+				}
5175 5471
 			}
5176 5472
 
5177
-			if (!$keep_alive)
5178
-				fclose($fp);
5473
+			if (!$keep_alive) {
5474
+							fclose($fp);
5475
+			}
5179 5476
 		}
5180 5477
 
5181 5478
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5188,17 +5485,18 @@  discard block
 block discarded – undo
5188 5485
 			$fetch_data->get_url_data($url, $post_data);
5189 5486
 
5190 5487
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5191
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5192
-				$data = $fetch_data->result('body');
5193
-			else
5194
-				return false;
5488
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5489
+							$data = $fetch_data->result('body');
5490
+			} else {
5491
+							return false;
5492
+			}
5195 5493
 		}
5196 5494
 
5197 5495
 		// Neither fsockopen nor curl are available. Well, phooey.
5198
-		else
5199
-			return false;
5200
-	}
5201
-	else
5496
+		else {
5497
+					return false;
5498
+		}
5499
+	} else
5202 5500
 	{
5203 5501
 		// Umm, this shouldn't happen?
5204 5502
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5218,8 +5516,9 @@  discard block
 block discarded – undo
5218 5516
 	global $user_info, $smcFunc;
5219 5517
 
5220 5518
 	// Make sure we have something to work with.
5221
-	if (empty($topic))
5222
-		return array();
5519
+	if (empty($topic)) {
5520
+			return array();
5521
+	}
5223 5522
 
5224 5523
 
5225 5524
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5242,8 +5541,9 @@  discard block
 block discarded – undo
5242 5541
 				'topic' => $topic,
5243 5542
 			)
5244 5543
 		);
5245
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5246
-			$temp[] = (int) $row['content_id'];
5544
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5545
+					$temp[] = (int) $row['content_id'];
5546
+		}
5247 5547
 
5248 5548
 		cache_put_data($cache_key, $temp, $ttl);
5249 5549
 	}
@@ -5264,8 +5564,9 @@  discard block
 block discarded – undo
5264 5564
 {
5265 5565
 	global $context;
5266 5566
 
5267
-	if (empty($string))
5268
-		return $string;
5567
+	if (empty($string)) {
5568
+			return $string;
5569
+	}
5269 5570
 
5270 5571
 	// UTF-8 occurences of MS special characters
5271 5572
 	$findchars_utf8 = array(
@@ -5306,10 +5607,11 @@  discard block
 block discarded – undo
5306 5607
 		'--',	// &mdash;
5307 5608
 	);
5308 5609
 
5309
-	if ($context['utf8'])
5310
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5311
-	else
5312
-		$string = str_replace($findchars_iso, $replacechars, $string);
5610
+	if ($context['utf8']) {
5611
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5612
+	} else {
5613
+			$string = str_replace($findchars_iso, $replacechars, $string);
5614
+	}
5313 5615
 
5314 5616
 	return $string;
5315 5617
 }
@@ -5328,49 +5630,59 @@  discard block
 block discarded – undo
5328 5630
 {
5329 5631
 	global $context;
5330 5632
 
5331
-	if (!isset($matches[2]))
5332
-		return '';
5633
+	if (!isset($matches[2])) {
5634
+			return '';
5635
+	}
5333 5636
 
5334 5637
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5335 5638
 
5336 5639
 	// remove left to right / right to left overrides
5337
-	if ($num === 0x202D || $num === 0x202E)
5338
-		return '';
5640
+	if ($num === 0x202D || $num === 0x202E) {
5641
+			return '';
5642
+	}
5339 5643
 
5340 5644
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5341
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5342
-		return '&#' . $num . ';';
5645
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5646
+			return '&#' . $num . ';';
5647
+	}
5343 5648
 
5344 5649
 	if (empty($context['utf8']))
5345 5650
 	{
5346 5651
 		// no control characters
5347
-		if ($num < 0x20)
5348
-			return '';
5652
+		if ($num < 0x20) {
5653
+					return '';
5654
+		}
5349 5655
 		// text is text
5350
-		elseif ($num < 0x80)
5351
-			return chr($num);
5656
+		elseif ($num < 0x80) {
5657
+					return chr($num);
5658
+		}
5352 5659
 		// all others get html-ised
5353
-		else
5354
-			return '&#' . $matches[2] . ';';
5355
-	}
5356
-	else
5660
+		else {
5661
+					return '&#' . $matches[2] . ';';
5662
+		}
5663
+	} else
5357 5664
 	{
5358 5665
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5359 5666
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5360
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5361
-			return '';
5667
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5668
+					return '';
5669
+		}
5362 5670
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5363
-		elseif ($num < 0x80)
5364
-			return chr($num);
5671
+		elseif ($num < 0x80) {
5672
+					return chr($num);
5673
+		}
5365 5674
 		// <0x800 (2048)
5366
-		elseif ($num < 0x800)
5367
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5675
+		elseif ($num < 0x800) {
5676
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5677
+		}
5368 5678
 		// < 0x10000 (65536)
5369
-		elseif ($num < 0x10000)
5370
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5679
+		elseif ($num < 0x10000) {
5680
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5681
+		}
5371 5682
 		// <= 0x10FFFF (1114111)
5372
-		else
5373
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5683
+		else {
5684
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5685
+		}
5374 5686
 	}
5375 5687
 }
5376 5688
 
@@ -5386,28 +5698,34 @@  discard block
 block discarded – undo
5386 5698
  */
5387 5699
 function fixchar__callback($matches)
5388 5700
 {
5389
-	if (!isset($matches[1]))
5390
-		return '';
5701
+	if (!isset($matches[1])) {
5702
+			return '';
5703
+	}
5391 5704
 
5392 5705
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5393 5706
 
5394 5707
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5395 5708
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5396
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5397
-		return '';
5709
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5710
+			return '';
5711
+	}
5398 5712
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5399
-	elseif ($num < 0x80)
5400
-		return chr($num);
5713
+	elseif ($num < 0x80) {
5714
+			return chr($num);
5715
+	}
5401 5716
 	// <0x800 (2048)
5402
-	elseif ($num < 0x800)
5403
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5717
+	elseif ($num < 0x800) {
5718
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5719
+	}
5404 5720
 	// < 0x10000 (65536)
5405
-	elseif ($num < 0x10000)
5406
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5721
+	elseif ($num < 0x10000) {
5722
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5723
+	}
5407 5724
 	// <= 0x10FFFF (1114111)
5408
-	else
5409
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5410
-}
5725
+	else {
5726
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5727
+	}
5728
+	}
5411 5729
 
5412 5730
 /**
5413 5731
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5420,17 +5738,19 @@  discard block
 block discarded – undo
5420 5738
  */
5421 5739
 function entity_fix__callback($matches)
5422 5740
 {
5423
-	if (!isset($matches[2]))
5424
-		return '';
5741
+	if (!isset($matches[2])) {
5742
+			return '';
5743
+	}
5425 5744
 
5426 5745
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5427 5746
 
5428 5747
 	// we don't allow control characters, characters out of range, byte markers, etc
5429
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5430
-		return '';
5431
-	else
5432
-		return '&#' . $num . ';';
5433
-}
5748
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5749
+			return '';
5750
+	} else {
5751
+			return '&#' . $num . ';';
5752
+	}
5753
+	}
5434 5754
 
5435 5755
 /**
5436 5756
  * Return a Gravatar URL based on
@@ -5454,18 +5774,23 @@  discard block
 block discarded – undo
5454 5774
 		$ratings = array('G', 'PG', 'R', 'X');
5455 5775
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5456 5776
 		$url_params = array();
5457
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5458
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5459
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5460
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5461
-		if (!empty($modSettings['avatar_max_width_external']))
5462
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5463
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5464
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5777
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5778
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5779
+		}
5780
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5781
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5782
+		}
5783
+		if (!empty($modSettings['avatar_max_width_external'])) {
5784
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5785
+		}
5786
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5787
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5465 5788
 				$size_string = $modSettings['avatar_max_height_external'];
5789
+		}
5466 5790
 
5467
-		if (!empty($size_string))
5468
-			$url_params[] = 's=' . $size_string;
5791
+		if (!empty($size_string)) {
5792
+					$url_params[] = 's=' . $size_string;
5793
+		}
5469 5794
 	}
5470 5795
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5471 5796
 
@@ -5484,22 +5809,26 @@  discard block
 block discarded – undo
5484 5809
 	static $timezones = null, $lastwhen = null;
5485 5810
 
5486 5811
 	// No point doing this over if we already did it once
5487
-	if (!empty($timezones) && $when == $lastwhen)
5488
-		return $timezones;
5489
-	else
5490
-		$lastwhen = $when;
5812
+	if (!empty($timezones) && $when == $lastwhen) {
5813
+			return $timezones;
5814
+	} else {
5815
+			$lastwhen = $when;
5816
+	}
5491 5817
 
5492 5818
 	// Parseable datetime string?
5493
-	if (is_int($timestamp = strtotime($when)))
5494
-		$when = $timestamp;
5819
+	if (is_int($timestamp = strtotime($when))) {
5820
+			$when = $timestamp;
5821
+	}
5495 5822
 
5496 5823
 	// A Unix timestamp?
5497
-	elseif (is_numeric($when))
5498
-		$when = intval($when);
5824
+	elseif (is_numeric($when)) {
5825
+			$when = intval($when);
5826
+	}
5499 5827
 
5500 5828
 	// Invalid value? Just get current Unix timestamp.
5501
-	else
5502
-		$when = time();
5829
+	else {
5830
+			$when = time();
5831
+	}
5503 5832
 
5504 5833
 	// We'll need these too
5505 5834
 	$date_when = date_create('@' . $when);
@@ -5514,8 +5843,9 @@  discard block
 block discarded – undo
5514 5843
 	foreach ($priority_countries as $country)
5515 5844
 	{
5516 5845
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5517
-		if (!empty($country_tzids))
5518
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5846
+		if (!empty($country_tzids)) {
5847
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5848
+		}
5519 5849
 	}
5520 5850
 
5521 5851
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5529,8 +5859,9 @@  discard block
 block discarded – undo
5529 5859
 	foreach ($tzids as $tzid)
5530 5860
 	{
5531 5861
 		// We don't want UTC right now
5532
-		if ($tzid == 'UTC')
5533
-			continue;
5862
+		if ($tzid == 'UTC') {
5863
+					continue;
5864
+		}
5534 5865
 
5535 5866
 		$tz = timezone_open($tzid);
5536 5867
 
@@ -5551,13 +5882,14 @@  discard block
 block discarded – undo
5551 5882
 		}
5552 5883
 
5553 5884
 		// A time zone from a prioritized country?
5554
-		if (in_array($tzid, $priority_tzids))
5555
-			$priority_zones[$tzkey] = true;
5885
+		if (in_array($tzid, $priority_tzids)) {
5886
+					$priority_zones[$tzkey] = true;
5887
+		}
5556 5888
 
5557 5889
 		// Keep track of the location and offset for this tzid
5558
-		if (!empty($txt[$tzid]))
5559
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5560
-		else
5890
+		if (!empty($txt[$tzid])) {
5891
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5892
+		} else
5561 5893
 		{
5562 5894
 			$tzid_parts = explode('/', $tzid);
5563 5895
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5577,23 +5909,27 @@  discard block
 block discarded – undo
5577 5909
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5578 5910
 
5579 5911
 		// Use the custom description, if there is one
5580
-		if (!empty($tztxt[$tzvalue['tzid']]))
5581
-			$desc = $tztxt[$tzvalue['tzid']];
5912
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5913
+					$desc = $tztxt[$tzvalue['tzid']];
5914
+		}
5582 5915
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5583
-		else
5584
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5916
+		else {
5917
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5918
+		}
5585 5919
 
5586 5920
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5587 5921
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5588 5922
 
5589
-		if (isset($priority_zones[$tzkey]))
5590
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5591
-		else
5592
-			$timezones[$tzvalue['tzid']] = $desc;
5923
+		if (isset($priority_zones[$tzkey])) {
5924
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5925
+		} else {
5926
+					$timezones[$tzvalue['tzid']] = $desc;
5927
+		}
5593 5928
 	}
5594 5929
 
5595
-	if (!empty($priority_timezones))
5596
-		$priority_timezones[] = '-----';
5930
+	if (!empty($priority_timezones)) {
5931
+			$priority_timezones[] = '-----';
5932
+	}
5597 5933
 
5598 5934
 	$timezones = array_merge(
5599 5935
 		$priority_timezones,
@@ -5610,8 +5946,9 @@  discard block
 block discarded – undo
5610 5946
  */
5611 5947
 function inet_ptod($ip_address)
5612 5948
 {
5613
-	if (!isValidIP($ip_address))
5614
-		return $ip_address;
5949
+	if (!isValidIP($ip_address)) {
5950
+			return $ip_address;
5951
+	}
5615 5952
 
5616 5953
 	$bin = inet_pton($ip_address);
5617 5954
 	return $bin;
@@ -5623,13 +5960,15 @@  discard block
 block discarded – undo
5623 5960
  */
5624 5961
 function inet_dtop($bin)
5625 5962
 {
5626
-	if(empty($bin))
5627
-		return '';
5963
+	if(empty($bin)) {
5964
+			return '';
5965
+	}
5628 5966
 
5629 5967
 	global $db_type;
5630 5968
 
5631
-	if ($db_type == 'postgresql')
5632
-		return $bin;
5969
+	if ($db_type == 'postgresql') {
5970
+			return $bin;
5971
+	}
5633 5972
 
5634 5973
 	$ip_address = inet_ntop($bin);
5635 5974
 
@@ -5654,26 +5993,32 @@  discard block
 block discarded – undo
5654 5993
  */
5655 5994
 function _safe_serialize($value)
5656 5995
 {
5657
-	if(is_null($value))
5658
-		return 'N;';
5996
+	if(is_null($value)) {
5997
+			return 'N;';
5998
+	}
5659 5999
 
5660
-	if(is_bool($value))
5661
-		return 'b:'. (int) $value .';';
6000
+	if(is_bool($value)) {
6001
+			return 'b:'. (int) $value .';';
6002
+	}
5662 6003
 
5663
-	if(is_int($value))
5664
-		return 'i:'. $value .';';
6004
+	if(is_int($value)) {
6005
+			return 'i:'. $value .';';
6006
+	}
5665 6007
 
5666
-	if(is_float($value))
5667
-		return 'd:'. str_replace(',', '.', $value) .';';
6008
+	if(is_float($value)) {
6009
+			return 'd:'. str_replace(',', '.', $value) .';';
6010
+	}
5668 6011
 
5669
-	if(is_string($value))
5670
-		return 's:'. strlen($value) .':"'. $value .'";';
6012
+	if(is_string($value)) {
6013
+			return 's:'. strlen($value) .':"'. $value .'";';
6014
+	}
5671 6015
 
5672 6016
 	if(is_array($value))
5673 6017
 	{
5674 6018
 		$out = '';
5675
-		foreach($value as $k => $v)
5676
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6019
+		foreach($value as $k => $v) {
6020
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6021
+		}
5677 6022
 
5678 6023
 		return 'a:'. count($value) .':{'. $out .'}';
5679 6024
 	}
@@ -5699,8 +6044,9 @@  discard block
 block discarded – undo
5699 6044
 
5700 6045
 	$out = _safe_serialize($value);
5701 6046
 
5702
-	if (isset($mbIntEnc))
5703
-		mb_internal_encoding($mbIntEnc);
6047
+	if (isset($mbIntEnc)) {
6048
+			mb_internal_encoding($mbIntEnc);
6049
+	}
5704 6050
 
5705 6051
 	return $out;
5706 6052
 }
@@ -5717,8 +6063,9 @@  discard block
 block discarded – undo
5717 6063
 function _safe_unserialize($str)
5718 6064
 {
5719 6065
 	// Input  is not a string.
5720
-	if(empty($str) || !is_string($str))
5721
-		return false;
6066
+	if(empty($str) || !is_string($str)) {
6067
+			return false;
6068
+	}
5722 6069
 
5723 6070
 	$stack = array();
5724 6071
 	$expected = array();
@@ -5734,43 +6081,38 @@  discard block
 block discarded – undo
5734 6081
 	while($state != 1)
5735 6082
 	{
5736 6083
 		$type = isset($str[0]) ? $str[0] : '';
5737
-		if($type == '}')
5738
-			$str = substr($str, 1);
5739
-
5740
-		else if($type == 'N' && $str[1] == ';')
6084
+		if($type == '}') {
6085
+					$str = substr($str, 1);
6086
+		} else if($type == 'N' && $str[1] == ';')
5741 6087
 		{
5742 6088
 			$value = null;
5743 6089
 			$str = substr($str, 2);
5744
-		}
5745
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6090
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5746 6091
 		{
5747 6092
 			$value = $matches[1] == '1' ? true : false;
5748 6093
 			$str = substr($str, 4);
5749
-		}
5750
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6094
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5751 6095
 		{
5752 6096
 			$value = (int)$matches[1];
5753 6097
 			$str = $matches[2];
5754
-		}
5755
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6098
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5756 6099
 		{
5757 6100
 			$value = (float)$matches[1];
5758 6101
 			$str = $matches[3];
5759
-		}
5760
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6102
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5761 6103
 		{
5762 6104
 			$value = substr($matches[2], 0, (int)$matches[1]);
5763 6105
 			$str = substr($matches[2], (int)$matches[1] + 2);
5764
-		}
5765
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6106
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5766 6107
 		{
5767 6108
 			$expectedLength = (int)$matches[1];
5768 6109
 			$str = $matches[2];
5769 6110
 		}
5770 6111
 
5771 6112
 		// Object or unknown/malformed type.
5772
-		else
5773
-			return false;
6113
+		else {
6114
+					return false;
6115
+		}
5774 6116
 
5775 6117
 		switch($state)
5776 6118
 		{
@@ -5798,8 +6140,9 @@  discard block
 block discarded – undo
5798 6140
 				if($type == '}')
5799 6141
 				{
5800 6142
 					// Array size is less than expected.
5801
-					if(count($list) < end($expected))
5802
-						return false;
6143
+					if(count($list) < end($expected)) {
6144
+											return false;
6145
+					}
5803 6146
 
5804 6147
 					unset($list);
5805 6148
 					$list = &$stack[count($stack)-1];
@@ -5808,8 +6151,9 @@  discard block
 block discarded – undo
5808 6151
 					// Go to terminal state if we're at the end of the root array.
5809 6152
 					array_pop($expected);
5810 6153
 
5811
-					if(count($expected) == 0)
5812
-						$state = 1;
6154
+					if(count($expected) == 0) {
6155
+											$state = 1;
6156
+					}
5813 6157
 
5814 6158
 					break;
5815 6159
 				}
@@ -5817,8 +6161,9 @@  discard block
 block discarded – undo
5817 6161
 				if($type == 'i' || $type == 's')
5818 6162
 				{
5819 6163
 					// Array size exceeds expected length.
5820
-					if(count($list) >= end($expected))
5821
-						return false;
6164
+					if(count($list) >= end($expected)) {
6165
+											return false;
6166
+					}
5822 6167
 
5823 6168
 					$key = $value;
5824 6169
 					$state = 3;
@@ -5852,8 +6197,9 @@  discard block
 block discarded – undo
5852 6197
 	}
5853 6198
 
5854 6199
 	// Trailing data in input.
5855
-	if(!empty($str))
5856
-		return false;
6200
+	if(!empty($str)) {
6201
+			return false;
6202
+	}
5857 6203
 
5858 6204
 	return $data;
5859 6205
 }
@@ -5876,8 +6222,9 @@  discard block
 block discarded – undo
5876 6222
 
5877 6223
 	$out = _safe_unserialize($str);
5878 6224
 
5879
-	if (isset($mbIntEnc))
5880
-		mb_internal_encoding($mbIntEnc);
6225
+	if (isset($mbIntEnc)) {
6226
+			mb_internal_encoding($mbIntEnc);
6227
+	}
5881 6228
 
5882 6229
 	return $out;
5883 6230
 }
@@ -5892,12 +6239,14 @@  discard block
 block discarded – undo
5892 6239
 function smf_chmod($file, $value = 0)
5893 6240
 {
5894 6241
 	// No file? no checks!
5895
-	if (empty($file))
5896
-		return false;
6242
+	if (empty($file)) {
6243
+			return false;
6244
+	}
5897 6245
 
5898 6246
 	// Already writable?
5899
-	if (is_writable($file))
5900
-		return true;
6247
+	if (is_writable($file)) {
6248
+			return true;
6249
+	}
5901 6250
 
5902 6251
 	// Do we have a file or a dir?
5903 6252
 	$isDir = is_dir($file);
@@ -5913,10 +6262,9 @@  discard block
 block discarded – undo
5913 6262
 		{
5914 6263
 			$isWritable = true;
5915 6264
 			break;
6265
+		} else {
6266
+					@chmod($file, $val);
5916 6267
 		}
5917
-
5918
-		else
5919
-			@chmod($file, $val);
5920 6268
 	}
5921 6269
 
5922 6270
 	return $isWritable;
@@ -5935,8 +6283,9 @@  discard block
 block discarded – undo
5935 6283
 	global $txt;
5936 6284
 
5937 6285
 	// Come on...
5938
-	if (empty($json) || !is_string($json))
5939
-		return array();
6286
+	if (empty($json) || !is_string($json)) {
6287
+			return array();
6288
+	}
5940 6289
 
5941 6290
 	$returnArray = @json_decode($json, $returnAsArray);
5942 6291
 
@@ -5974,11 +6323,11 @@  discard block
 block discarded – undo
5974 6323
 		$jsonDebug = $jsonDebug[0];
5975 6324
 		loadLanguage('Errors');
5976 6325
 
5977
-		if (!empty($jsonDebug))
5978
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5979
-
5980
-		else
5981
-			log_error($txt['json_'. $jsonError], 'critical');
6326
+		if (!empty($jsonDebug)) {
6327
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6328
+		} else {
6329
+					log_error($txt['json_'. $jsonError], 'critical');
6330
+		}
5982 6331
 
5983 6332
 		// Everyone expects an array.
5984 6333
 		return array();
@@ -6012,8 +6361,9 @@  discard block
 block discarded – undo
6012 6361
 	global $db_show_debug, $modSettings;
6013 6362
 
6014 6363
 	// Defensive programming anyone?
6015
-	if (empty($data))
6016
-		return false;
6364
+	if (empty($data)) {
6365
+			return false;
6366
+	}
6017 6367
 
6018 6368
 	// Don't need extra stuff...
6019 6369
 	$db_show_debug = false;
@@ -6021,11 +6371,11 @@  discard block
 block discarded – undo
6021 6371
 	// Kill anything else.
6022 6372
 	ob_end_clean();
6023 6373
 
6024
-	if (!empty($modSettings['CompressedOutput']))
6025
-		@ob_start('ob_gzhandler');
6026
-
6027
-	else
6028
-		ob_start();
6374
+	if (!empty($modSettings['CompressedOutput'])) {
6375
+			@ob_start('ob_gzhandler');
6376
+	} else {
6377
+			ob_start();
6378
+	}
6029 6379
 
6030 6380
 	// Set the header.
6031 6381
 	header($type);
@@ -6057,8 +6407,9 @@  discard block
 block discarded – undo
6057 6407
 	static $done = false;
6058 6408
 
6059 6409
 	// If we don't need to do anything, don't
6060
-	if (!$update && $done)
6061
-		return;
6410
+	if (!$update && $done) {
6411
+			return;
6412
+	}
6062 6413
 
6063 6414
 	// Should we get a new copy of the official list of TLDs?
6064 6415
 	if ($update)
@@ -6070,8 +6421,9 @@  discard block
 block discarded – undo
6070 6421
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6071 6422
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6072 6423
 		// update to see if civilization has been restored.
6073
-		if ($tlds === false)
6074
-			$postapocalypticNightmare = true;
6424
+		if ($tlds === false) {
6425
+					$postapocalypticNightmare = true;
6426
+		}
6075 6427
 	}
6076 6428
 	// If we aren't updating and the regex is valid, we're done
6077 6429
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6086,10 +6438,11 @@  discard block
 block discarded – undo
6086 6438
 		// Clean $tlds and convert it to an array
6087 6439
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6088 6440
 			$line = trim($line);
6089
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6090
-				return false;
6091
-			else
6092
-				return true;
6441
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6442
+							return false;
6443
+			} else {
6444
+							return true;
6445
+			}
6093 6446
 		});
6094 6447
 
6095 6448
 		// Convert Punycode to Unicode
@@ -6181,8 +6534,7 @@  discard block
 block discarded – undo
6181 6534
 
6182 6535
 		$strlen = 'mb_strlen';
6183 6536
 		$substr = 'mb_substr';
6184
-	}
6185
-	else
6537
+	} else
6186 6538
 	{
6187 6539
 		$strlen = $smcFunc['strlen'];
6188 6540
 		$substr = $smcFunc['substr'];
@@ -6196,20 +6548,21 @@  discard block
 block discarded – undo
6196 6548
 
6197 6549
 		$first = $substr($string, 0, 1);
6198 6550
 
6199
-		if (empty($index[$first]))
6200
-			$index[$first] = array();
6551
+		if (empty($index[$first])) {
6552
+					$index[$first] = array();
6553
+		}
6201 6554
 
6202 6555
 		if ($strlen($string) > 1)
6203 6556
 		{
6204 6557
 			// Sanity check on recursion
6205
-			if ($depth > 99)
6206
-				$index[$first][$substr($string, 1)] = '';
6207
-
6208
-			else
6209
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6558
+			if ($depth > 99) {
6559
+							$index[$first][$substr($string, 1)] = '';
6560
+			} else {
6561
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6562
+			}
6563
+		} else {
6564
+					$index[$first][''] = '';
6210 6565
 		}
6211
-		else
6212
-			$index[$first][''] = '';
6213 6566
 
6214 6567
 		$depth--;
6215 6568
 		return $index;
@@ -6232,9 +6585,9 @@  discard block
 block discarded – undo
6232 6585
 			$key_regex = preg_quote($key, $delim);
6233 6586
 			$new_key = $key;
6234 6587
 
6235
-			if (empty($value))
6236
-				$sub_regex = '';
6237
-			else
6588
+			if (empty($value)) {
6589
+							$sub_regex = '';
6590
+			} else
6238 6591
 			{
6239 6592
 				$sub_regex = $index_to_regex($value, $delim);
6240 6593
 
@@ -6242,22 +6595,22 @@  discard block
 block discarded – undo
6242 6595
 				{
6243 6596
 					$new_key_array = explode('(?'.'>', $sub_regex);
6244 6597
 					$new_key .= $new_key_array[0];
6598
+				} else {
6599
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6245 6600
 				}
6246
-				else
6247
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6248 6601
 			}
6249 6602
 
6250
-			if ($depth > 1)
6251
-				$regex[$new_key] = $key_regex . $sub_regex;
6252
-			else
6603
+			if ($depth > 1) {
6604
+							$regex[$new_key] = $key_regex . $sub_regex;
6605
+			} else
6253 6606
 			{
6254 6607
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6255 6608
 				{
6256 6609
 					$regex[$new_key] = $key_regex . $sub_regex;
6257 6610
 					unset($index[$key]);
6611
+				} else {
6612
+									break;
6258 6613
 				}
6259
-				else
6260
-					break;
6261 6614
 			}
6262 6615
 		}
6263 6616
 
@@ -6266,10 +6619,11 @@  discard block
 block discarded – undo
6266 6619
 			$l1 = $strlen($k1);
6267 6620
 			$l2 = $strlen($k2);
6268 6621
 
6269
-			if ($l1 == $l2)
6270
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6271
-			else
6272
-				return $l1 > $l2 ? -1 : 1;
6622
+			if ($l1 == $l2) {
6623
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6624
+			} else {
6625
+							return $l1 > $l2 ? -1 : 1;
6626
+			}
6273 6627
 		});
6274 6628
 
6275 6629
 		$depth--;
@@ -6280,21 +6634,24 @@  discard block
 block discarded – undo
6280 6634
 	$index = array();
6281 6635
 	$regex = '';
6282 6636
 
6283
-	foreach ($strings as $string)
6284
-		$index = $add_string_to_index($string, $index);
6637
+	foreach ($strings as $string) {
6638
+			$index = $add_string_to_index($string, $index);
6639
+	}
6285 6640
 
6286 6641
 	if ($returnArray === true)
6287 6642
 	{
6288 6643
 		$regex = array();
6289
-		while (!empty($index))
6290
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6644
+		while (!empty($index)) {
6645
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6646
+		}
6647
+	} else {
6648
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6291 6649
 	}
6292
-	else
6293
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6294 6650
 
6295 6651
 	// Restore PHP's internal character encoding to whatever it was originally
6296
-	if (!empty($current_encoding))
6297
-		mb_internal_encoding($current_encoding);
6652
+	if (!empty($current_encoding)) {
6653
+			mb_internal_encoding($current_encoding);
6654
+	}
6298 6655
 
6299 6656
 	return $regex;
6300 6657
 }
@@ -6337,13 +6694,15 @@  discard block
 block discarded – undo
6337 6694
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6338 6695
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6339 6696
 	$headers = @get_headers($url);
6340
-	if ($headers === false)
6341
-		return false;
6697
+	if ($headers === false) {
6698
+			return false;
6699
+	}
6342 6700
 
6343 6701
 	// Now to see if it came back https...
6344 6702
 	// First check for a redirect status code in first row (301, 302, 307)
6345
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6346
-		return false;
6703
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6704
+			return false;
6705
+	}
6347 6706
 
6348 6707
 	// Search for the location entry to confirm https
6349 6708
 	$result = false;
@@ -6381,8 +6740,7 @@  discard block
 block discarded – undo
6381 6740
 		$is_admin = $user_info['is_admin'];
6382 6741
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6383 6742
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6384
-	}
6385
-	else
6743
+	} else
6386 6744
 	{
6387 6745
 		$request = $smcFunc['db_query']('', '
6388 6746
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6396,17 +6754,19 @@  discard block
 block discarded – undo
6396 6754
 
6397 6755
 		$row = $smcFunc['db_fetch_assoc']($request);
6398 6756
 
6399
-		if (empty($row['additional_groups']))
6400
-			$groups = array($row['id_group'], $row['id_post_group']);
6401
-		else
6402
-			$groups = array_merge(
6757
+		if (empty($row['additional_groups'])) {
6758
+					$groups = array($row['id_group'], $row['id_post_group']);
6759
+		} else {
6760
+					$groups = array_merge(
6403 6761
 					array($row['id_group'], $row['id_post_group']),
6404 6762
 					explode(',', $row['additional_groups'])
6405 6763
 			);
6764
+		}
6406 6765
 
6407 6766
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6408
-		foreach ($groups as $k => $v)
6409
-			$groups[$k] = (int) $v;
6767
+		foreach ($groups as $k => $v) {
6768
+					$groups[$k] = (int) $v;
6769
+		}
6410 6770
 
6411 6771
 		$is_admin = in_array(1, $groups);
6412 6772
 
@@ -6423,8 +6783,9 @@  discard block
 block discarded – undo
6423 6783
 				'current_member' => $userid,
6424 6784
 			)
6425 6785
 		);
6426
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6427
-			$boards_mod[] = $row['id_board'];
6786
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6787
+					$boards_mod[] = $row['id_board'];
6788
+		}
6428 6789
 		$smcFunc['db_free_result']($request);
6429 6790
 
6430 6791
 		// Can any of the groups they're in moderate any of the boards?
@@ -6436,8 +6797,9 @@  discard block
 block discarded – undo
6436 6797
 				'groups' => $groups,
6437 6798
 			)
6438 6799
 		);
6439
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6440
-			$boards_mod[] = $row['id_board'];
6800
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6801
+					$boards_mod[] = $row['id_board'];
6802
+		}
6441 6803
 		$smcFunc['db_free_result']($request);
6442 6804
 
6443 6805
 		// Just in case we've got duplicates here...
@@ -6447,23 +6809,27 @@  discard block
 block discarded – undo
6447 6809
 	}
6448 6810
 
6449 6811
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6450
-	if ($is_admin)
6451
-		$query_part['query_see_board'] = '1=1';
6812
+	if ($is_admin) {
6813
+			$query_part['query_see_board'] = '1=1';
6814
+	}
6452 6815
 	// Otherwise just the groups in $user_info['groups'].
6453
-	else
6454
-		$query_part['query_see_board'] = 'EXISTS (SELECT DISTINCT bpv.id_board FROM ' . $db_prefix . 'board_permissions_view bpv WHERE (bpv.id_group IN ( '. implode(',', $groups) .') AND bpv.deny = 0) '
6816
+	else {
6817
+			$query_part['query_see_board'] = 'EXISTS (SELECT DISTINCT bpv.id_board FROM ' . $db_prefix . 'board_permissions_view bpv WHERE (bpv.id_group IN ( '. implode(',', $groups) .') AND bpv.deny = 0) '
6455 6818
 				.  ( !empty($deny_boards_access) ? ' AND (bpv.id_group NOT IN ( '. implode(',', $groups) .') and bpv.deny = 1)' : '')
6456 6819
 				. ' AND bpv.id_board = b.id_board)';
6820
+	}
6457 6821
 		
6458 6822
 	// Build the list of boards they WANT to see.
6459 6823
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6460 6824
 
6461 6825
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6462
-	if (empty($ignoreboards))
6463
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6826
+	if (empty($ignoreboards)) {
6827
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6828
+	}
6464 6829
 	// Ok I guess they don't want to see all the boards
6465
-	else
6466
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6830
+	else {
6831
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6832
+	}
6467 6833
 
6468 6834
 	return $query_part;
6469 6835
 }
@@ -6477,10 +6843,11 @@  discard block
 block discarded – undo
6477 6843
 {
6478 6844
 	$secure = false;
6479 6845
 
6480
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6481
-		$secure = true;
6482
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6483
-		$secure = true;
6846
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6847
+			$secure = true;
6848
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6849
+			$secure = true;
6850
+	}
6484 6851
 
6485 6852
 	return $secure;
6486 6853
 }
@@ -6497,11 +6864,12 @@  discard block
 block discarded – undo
6497 6864
 {
6498 6865
 	$url = iri_to_url($iri);
6499 6866
 
6500
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6501
-		return $iri;
6502
-	else
6503
-		return false;
6504
-}
6867
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6868
+			return $iri;
6869
+	} else {
6870
+			return false;
6871
+	}
6872
+	}
6505 6873
 
6506 6874
 /**
6507 6875
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6544,8 +6912,9 @@  discard block
 block discarded – undo
6544 6912
 
6545 6913
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6546 6914
 
6547
-	if (empty($host))
6548
-		return $iri;
6915
+	if (empty($host)) {
6916
+			return $iri;
6917
+	}
6549 6918
 
6550 6919
 	// Convert the domain using the Punycode algorithm
6551 6920
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6581,8 +6950,9 @@  discard block
 block discarded – undo
6581 6950
 
6582 6951
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6583 6952
 
6584
-	if (empty($host))
6585
-		return $url;
6953
+	if (empty($host)) {
6954
+			return $url;
6955
+	}
6586 6956
 
6587 6957
 	// Decode the domain from Punycode
6588 6958
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6608,8 +6978,9 @@  discard block
 block discarded – undo
6608 6978
 {
6609 6979
 	global $user_info, $modSettings, $smcFunc, $txt;
6610 6980
 
6611
-	if (empty($modSettings['cron_last_checked']))
6612
-		$modSettings['cron_last_checked'] = 0;
6981
+	if (empty($modSettings['cron_last_checked'])) {
6982
+			$modSettings['cron_last_checked'] = 0;
6983
+	}
6613 6984
 
6614 6985
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6615 6986
 	{
@@ -6629,9 +7000,9 @@  discard block
 block discarded – undo
6629 7000
 			loadLanguage('ManageScheduledTasks');
6630 7001
 			log_error($txt['cron_not_working']);
6631 7002
 			updateSettings(array('cron_is_real_cron' => 0));
7003
+		} else {
7004
+					updateSettings(array('cron_last_checked' => time()));
6632 7005
 		}
6633
-		else
6634
-			updateSettings(array('cron_last_checked' => time()));
6635 7006
 	}
6636 7007
 }
6637 7008
 
@@ -6655,10 +7026,11 @@  discard block
 block discarded – undo
6655 7026
 
6656 7027
 	$protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0';
6657 7028
 
6658
-	if (!isset($statuses[$code]) && empty($status))
6659
-		header($protocol . ' 500 Internal Server Error');
6660
-	else
6661
-		header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code]));
6662
-}
7029
+	if (!isset($statuses[$code]) && empty($status)) {
7030
+			header($protocol . ' 500 Internal Server Error');
7031
+	} else {
7032
+			header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code]));
7033
+	}
7034
+	}
6663 7035
 
6664 7036
 ?>
6665 7037
\ No newline at end of file
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +469 added lines, -348 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 for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -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
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	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']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -355,15 +369,18 @@  discard block
 block discarded – undo
355 369
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port;
356 370
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4;
357 371
 
358
-	if (empty($sourcedir))
359
-		$sourcedir = dirname(__FILE__) . '/Sources';
372
+	if (empty($sourcedir)) {
373
+			$sourcedir = dirname(__FILE__) . '/Sources';
374
+	}
360 375
 
361 376
 	// Need this to check whether we need the database password.
362 377
 	require(dirname(__FILE__) . '/Settings.php');
363
-	if (!defined('SMF'))
364
-		define('SMF', 1);
365
-	if (empty($smcFunc))
366
-		$smcFunc = array();
378
+	if (!defined('SMF')) {
379
+			define('SMF', 1);
380
+	}
381
+	if (empty($smcFunc)) {
382
+			$smcFunc = array();
383
+	}
367 384
 
368 385
 	$modSettings['disableQueryCheck'] = true;
369 386
 
@@ -374,14 +391,17 @@  discard block
 block discarded – undo
374 391
 
375 392
 		$options = array('persist' => $db_persist);
376 393
 
377
-		if (!empty($db_port))
378
-			$options['port'] = $db_port;
394
+		if (!empty($db_port)) {
395
+					$options['port'] = $db_port;
396
+		}
379 397
 
380
-		if (!empty($db_mb4))
381
-			$options['db_mb4'] = $db_mb4;
398
+		if (!empty($db_mb4)) {
399
+					$options['db_mb4'] = $db_mb4;
400
+		}
382 401
 
383
-		if (!$db_connection)
384
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
402
+		if (!$db_connection) {
403
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
404
+		}
385 405
 	}
386 406
 }
387 407
 
@@ -409,8 +429,9 @@  discard block
 block discarded – undo
409 429
 		// @todo REMOVE THIS!!
410 430
 		else
411 431
 		{
412
-			if (function_exists('doStep' . $_GET['step']))
413
-				call_user_func('doStep' . $_GET['step']);
432
+			if (function_exists('doStep' . $_GET['step'])) {
433
+							call_user_func('doStep' . $_GET['step']);
434
+			}
414 435
 		}
415 436
 		// Show the footer.
416 437
 		template_install_below();
@@ -428,8 +449,9 @@  discard block
 block discarded – undo
428 449
 	$incontext['sub_template'] = 'welcome_message';
429 450
 
430 451
 	// Done the submission?
431
-	if (isset($_POST['contbutt']))
432
-		return true;
452
+	if (isset($_POST['contbutt'])) {
453
+			return true;
454
+	}
433 455
 
434 456
 	// See if we think they have already installed it?
435 457
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -437,14 +459,17 @@  discard block
 block discarded – undo
437 459
 		$probably_installed = 0;
438 460
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
439 461
 		{
440
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
441
-				$probably_installed++;
442
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
443
-				$probably_installed++;
462
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
463
+							$probably_installed++;
464
+			}
465
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
466
+							$probably_installed++;
467
+			}
444 468
 		}
445 469
 
446
-		if ($probably_installed == 2)
447
-			$incontext['warning'] = $txt['error_already_installed'];
470
+		if ($probably_installed == 2) {
471
+					$incontext['warning'] = $txt['error_already_installed'];
472
+		}
448 473
 	}
449 474
 
450 475
 	// Is some database support even compiled in?
@@ -459,45 +484,54 @@  discard block
 block discarded – undo
459 484
 				$databases[$key]['supported'] = false;
460 485
 				$notFoundSQLFile = true;
461 486
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
487
+			} else {
488
+							$incontext['supported_databases'][] = $db;
462 489
 			}
463
-			else
464
-				$incontext['supported_databases'][] = $db;
465 490
 		}
466 491
 	}
467 492
 
468 493
 	// Check the PHP version.
469
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
470
-		$error = 'error_php_too_low';
494
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
495
+			$error = 'error_php_too_low';
496
+	}
471 497
 	// Make sure we have a supported database
472
-	elseif (empty($incontext['supported_databases']))
473
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
498
+	elseif (empty($incontext['supported_databases'])) {
499
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
500
+	}
474 501
 	// How about session support?  Some crazy sysadmin remove it?
475
-	elseif (!function_exists('session_start'))
476
-		$error = 'error_session_missing';
502
+	elseif (!function_exists('session_start')) {
503
+			$error = 'error_session_missing';
504
+	}
477 505
 	// Make sure they uploaded all the files.
478
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
479
-		$error = 'error_missing_files';
506
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
507
+			$error = 'error_missing_files';
508
+	}
480 509
 	// Very simple check on the session.save_path for Windows.
481 510
 	// @todo Move this down later if they don't use database-driven sessions?
482
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
483
-		$error = 'error_session_save_path';
511
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
512
+			$error = 'error_session_save_path';
513
+	}
484 514
 
485 515
 	// Since each of the three messages would look the same, anyway...
486
-	if (isset($error))
487
-		$incontext['error'] = $txt[$error];
516
+	if (isset($error)) {
517
+			$incontext['error'] = $txt[$error];
518
+	}
488 519
 
489 520
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
490
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
491
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
521
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
522
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
523
+	}
492 524
 
493 525
 	// Confirm mbstring is loaded...
494
-	if (!extension_loaded('mbstring'))
495
-		$incontext['error'] = $txt['install_no_mbstring'];
526
+	if (!extension_loaded('mbstring')) {
527
+			$incontext['error'] = $txt['install_no_mbstring'];
528
+	}
496 529
 
497 530
 	// Check for https stream support.
498 531
 	$supported_streams = stream_get_wrappers();
499
-	if (!in_array('https', $supported_streams))
500
-		$incontext['warning'] = $txt['install_no_https'];
532
+	if (!in_array('https', $supported_streams)) {
533
+			$incontext['warning'] = $txt['install_no_https'];
534
+	}
501 535
 
502 536
 	return false;
503 537
 }
@@ -522,12 +556,14 @@  discard block
 block discarded – undo
522 556
 		'Settings_bak.php',
523 557
 	);
524 558
 
525
-	foreach ($incontext['detected_languages'] as $lang => $temp)
526
-		$extra_files[] = 'Themes/default/languages/' . $lang;
559
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
560
+			$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	}
527 562
 
528 563
 	// With mod_security installed, we could attempt to fix it with .htaccess.
529
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
530
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
564
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
565
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	}
531 567
 
532 568
 	$failed_files = array();
533 569
 
@@ -539,20 +575,23 @@  discard block
 block discarded – undo
539 575
 		foreach ($writable_files as $file)
540 576
 		{
541 577
 			// Some files won't exist, try to address up front
542
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
543
-				@touch(dirname(__FILE__) . '/' . $file);
578
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
579
+							@touch(dirname(__FILE__) . '/' . $file);
580
+			}
544 581
 			// NOW do the writable check...
545 582
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
546 583
 			{
547 584
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
548 585
 
549 586
 				// Well, 755 hopefully worked... if not, try 777.
550
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
551
-					$failed_files[] = $file;
587
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
588
+									$failed_files[] = $file;
589
+				}
552 590
 			}
553 591
 		}
554
-		foreach ($extra_files as $file)
555
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
592
+		foreach ($extra_files as $file) {
593
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
594
+		}
556 595
 	}
557 596
 	// Windows is trickier.  Let's try opening for r+...
558 597
 	else
@@ -562,30 +601,35 @@  discard block
 block discarded – undo
562 601
 		foreach ($writable_files as $file)
563 602
 		{
564 603
 			// Folders can't be opened for write... but the index.php in them can ;)
565
-			if (is_dir(dirname(__FILE__) . '/' . $file))
566
-				$file .= '/index.php';
604
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
605
+							$file .= '/index.php';
606
+			}
567 607
 
568 608
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
569 609
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
570 610
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
571 611
 
572 612
 			// Hmm, okay, try just for write in that case...
573
-			if (!is_resource($fp))
574
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
613
+			if (!is_resource($fp)) {
614
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
615
+			}
575 616
 
576
-			if (!is_resource($fp))
577
-				$failed_files[] = $file;
617
+			if (!is_resource($fp)) {
618
+							$failed_files[] = $file;
619
+			}
578 620
 
579 621
 			@fclose($fp);
580 622
 		}
581
-		foreach ($extra_files as $file)
582
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
623
+		foreach ($extra_files as $file) {
624
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
625
+		}
583 626
 	}
584 627
 
585 628
 	$failure = count($failed_files) >= 1;
586 629
 
587
-	if (!isset($_SERVER))
588
-		return !$failure;
630
+	if (!isset($_SERVER)) {
631
+			return !$failure;
632
+	}
589 633
 
590 634
 	// Put the list into context.
591 635
 	$incontext['failed_files'] = $failed_files;
@@ -633,19 +677,23 @@  discard block
 block discarded – undo
633 677
 
634 678
 		if (!isset($ftp) || $ftp->error !== false)
635 679
 		{
636
-			if (!isset($ftp))
637
-				$ftp = new ftp_connection(null);
680
+			if (!isset($ftp)) {
681
+							$ftp = new ftp_connection(null);
682
+			}
638 683
 			// Save the error so we can mess with listing...
639
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
640
-				$incontext['ftp_errors'][] = $ftp->last_message;
684
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
685
+							$incontext['ftp_errors'][] = $ftp->last_message;
686
+			}
641 687
 
642 688
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
643 689
 
644
-			if (empty($_POST['ftp_path']) && $found_path)
645
-				$_POST['ftp_path'] = $detect_path;
690
+			if (empty($_POST['ftp_path']) && $found_path) {
691
+							$_POST['ftp_path'] = $detect_path;
692
+			}
646 693
 
647
-			if (!isset($_POST['ftp_username']))
648
-				$_POST['ftp_username'] = $username;
694
+			if (!isset($_POST['ftp_username'])) {
695
+							$_POST['ftp_username'] = $username;
696
+			}
649 697
 
650 698
 			// Set the username etc, into context.
651 699
 			$incontext['ftp'] = array(
@@ -657,8 +705,7 @@  discard block
 block discarded – undo
657 705
 			);
658 706
 
659 707
 			return false;
660
-		}
661
-		else
708
+		} else
662 709
 		{
663 710
 			$_SESSION['installer_temp_ftp'] = array(
664 711
 				'server' => $_POST['ftp_server'],
@@ -672,10 +719,12 @@  discard block
 block discarded – undo
672 719
 
673 720
 			foreach ($failed_files as $file)
674 721
 			{
675
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
676
-					$ftp->chmod($file, 0755);
677
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
678
-					$ftp->chmod($file, 0777);
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0755);
724
+				}
725
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
726
+									$ftp->chmod($file, 0777);
727
+				}
679 728
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
680 729
 				{
681 730
 					$failed_files_updated[] = $file;
@@ -731,15 +780,17 @@  discard block
 block discarded – undo
731 780
 
732 781
 			if (!$foundOne)
733 782
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
783
+				if (isset($db['default_host'])) {
784
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
785
+				}
736 786
 				if (isset($db['default_user']))
737 787
 				{
738 788
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 789
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 790
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
791
+				if (isset($db['default_password'])) {
792
+									$incontext['db']['pass'] = ini_get($db['default_password']);
793
+				}
743 794
 
744 795
 				// For simplicity and less confusion, leave the port blank by default
745 796
 				$incontext['db']['port'] = '';
@@ -758,10 +809,10 @@  discard block
 block discarded – undo
758 809
 		$incontext['db']['server'] = $_POST['db_server'];
759 810
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 811
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
812
+		if (!empty($_POST['db_port'])) {
813
+					$incontext['db']['port'] = $_POST['db_port'];
814
+		}
815
+	} else
765 816
 	{
766 817
 		$incontext['db']['prefix'] = 'smf_';
767 818
 	}
@@ -797,10 +848,11 @@  discard block
 block discarded – undo
797 848
 		if (!empty($_POST['db_port']))
798 849
 		{
799 850
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
851
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
852
+							$vars['db_port'] = (int) $_POST['db_port'];
853
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
854
+							$vars['db_port'] = (int) $_POST['db_port'];
855
+			}
804 856
 		}
805 857
 
806 858
 		// God I hope it saved!
@@ -813,8 +865,9 @@  discard block
 block discarded – undo
813 865
 		// Make sure it works.
814 866
 		require(dirname(__FILE__) . '/Settings.php');
815 867
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
868
+		if (empty($sourcedir)) {
869
+					$sourcedir = dirname(__FILE__) . '/Sources';
870
+		}
818 871
 
819 872
 		// Better find the database file!
820 873
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,12 +877,14 @@  discard block
 block discarded – undo
824 877
 		}
825 878
 
826 879
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
880
+		if (!defined('SMF')) {
881
+					define('SMF', 1);
882
+		}
829 883
 
830 884
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
885
+		if (empty($smcFunc)) {
886
+					$smcFunc = array();
887
+		}
833 888
 
834 889
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 890
 
@@ -838,11 +893,13 @@  discard block
 block discarded – undo
838 893
 
839 894
 		$options = array('non_fatal' => true, 'dont_select_db' => !$needsDB);
840 895
 		// Add in the port if needed
841
-		if (!empty($db_port))
842
-			$options['port'] = $db_port;
896
+		if (!empty($db_port)) {
897
+					$options['port'] = $db_port;
898
+		}
843 899
 		
844
-		if (!empty($db_mb4))
845
-			$options['db_mb4'] = $db_mb4;
900
+		if (!empty($db_mb4)) {
901
+					$options['db_mb4'] = $db_mb4;
902
+		}
846 903
 
847 904
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
848 905
 
@@ -928,12 +985,14 @@  discard block
 block discarded – undo
928 985
 	$incontext['page_title'] = $txt['install_settings'];
929 986
 
930 987
 	// Let's see if we got the database type correct.
931
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
932
-		$db_type = $_POST['db_type'];
988
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
989
+			$db_type = $_POST['db_type'];
990
+	}
933 991
 
934 992
 	// Else we'd better be able to get the connection.
935
-	else
936
-		load_database();
993
+	else {
994
+			load_database();
995
+	}
937 996
 
938 997
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
939 998
 
@@ -942,10 +1001,11 @@  discard block
 block discarded – undo
942 1001
 
943 1002
 		$secure = false;
944 1003
 
945
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
946
-			$secure = true;
947
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
948
-			$secure = true;
1004
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1005
+					$secure = true;
1006
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1007
+					$secure = true;
1008
+		}
949 1009
 
950 1010
 	// Now, to put what we've learned together... and add a path.
951 1011
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -977,18 +1037,21 @@  discard block
 block discarded – undo
977 1037
 	// Submitting?
978 1038
 	if (isset($_POST['boardurl']))
979 1039
 	{
980
-		if (substr($_POST['boardurl'], -10) == '/index.php')
981
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
982
-		elseif (substr($_POST['boardurl'], -1) == '/')
983
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
984
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
985
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1040
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1041
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1042
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1043
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1044
+		}
1045
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1046
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1047
+		}
986 1048
 
987 1049
 		//Make sure boardurl is aligned with ssl setting
988
-		if (empty($_POST['force_ssl']))
989
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
990
-		else
991
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1050
+		if (empty($_POST['force_ssl'])) {
1051
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1052
+		} else {
1053
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1054
+		}
992 1055
 
993 1056
 		// Save these variables.
994 1057
 		$vars = array(
@@ -1027,10 +1090,10 @@  discard block
 block discarded – undo
1027 1090
 			{
1028 1091
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1029 1092
 				return false;
1030
-			}
1031
-			else
1032
-				// Set the character set here.
1093
+			} else {
1094
+							// Set the character set here.
1033 1095
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1096
+			}
1034 1097
 		}
1035 1098
 
1036 1099
 		// Good, skip on.
@@ -1050,8 +1113,9 @@  discard block
 block discarded – undo
1050 1113
 	$incontext['continue'] = 1;
1051 1114
 
1052 1115
 	// Already done?
1053
-	if (isset($_POST['pop_done']))
1054
-		return true;
1116
+	if (isset($_POST['pop_done'])) {
1117
+			return true;
1118
+	}
1055 1119
 
1056 1120
 	// Reload settings.
1057 1121
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1069,8 +1133,9 @@  discard block
 block discarded – undo
1069 1133
 	$modSettings = array();
1070 1134
 	if ($result !== false)
1071 1135
 	{
1072
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1073
-			$modSettings[$row['variable']] = $row['value'];
1136
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1137
+					$modSettings[$row['variable']] = $row['value'];
1138
+		}
1074 1139
 		$smcFunc['db_free_result']($result);
1075 1140
 
1076 1141
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1083,20 +1148,22 @@  discard block
 block discarded – undo
1083 1148
 	$modSettings['disableQueryCheck'] = true;
1084 1149
 
1085 1150
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1086
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1087
-		$smcFunc['db_query']('', '
1151
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1152
+			$smcFunc['db_query']('', '
1088 1153
 			SET NAMES {string:utf8}',
1089 1154
 			array(
1090 1155
 				'db_error_skip' => true,
1091 1156
 				'utf8' => 'utf8',
1092 1157
 			)
1093 1158
 		);
1159
+	}
1094 1160
 
1095 1161
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1096
-	if (substr(__DIR__, -1) == '\\')
1097
-		$attachdir = __DIR__ . 'attachments';
1098
-	else
1099
-		$attachdir = __DIR__ . '/attachments';
1162
+	if (substr(__DIR__, -1) == '\\') {
1163
+			$attachdir = __DIR__ . 'attachments';
1164
+	} else {
1165
+			$attachdir = __DIR__ . '/attachments';
1166
+	}
1100 1167
 
1101 1168
 	$replaces = array(
1102 1169
 		'{$db_prefix}' => $db_prefix,
@@ -1113,8 +1180,9 @@  discard block
 block discarded – undo
1113 1180
 
1114 1181
 	foreach ($txt as $key => $value)
1115 1182
 	{
1116
-		if (substr($key, 0, 8) == 'default_')
1117
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1183
+		if (substr($key, 0, 8) == 'default_') {
1184
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1185
+		}
1118 1186
 	}
1119 1187
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1120 1188
 
@@ -1129,8 +1197,9 @@  discard block
 block discarded – undo
1129 1197
 
1130 1198
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1131 1199
 		{
1132
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1133
-				$engines[] = $row['Engine'];
1200
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1201
+							$engines[] = $row['Engine'];
1202
+			}
1134 1203
 		}
1135 1204
 
1136 1205
 		// Done with this now
@@ -1154,8 +1223,7 @@  discard block
 block discarded – undo
1154 1223
 			$replaces['START TRANSACTION;'] = '';
1155 1224
 			$replaces['COMMIT;'] = '';
1156 1225
 		}
1157
-	}
1158
-	else
1226
+	} else
1159 1227
 	{
1160 1228
 		$has_innodb = false;
1161 1229
 	}
@@ -1177,21 +1245,24 @@  discard block
 block discarded – undo
1177 1245
 	foreach ($sql_lines as $count => $line)
1178 1246
 	{
1179 1247
 		// No comments allowed!
1180
-		if (substr(trim($line), 0, 1) != '#')
1181
-			$current_statement .= "\n" . rtrim($line);
1248
+		if (substr(trim($line), 0, 1) != '#') {
1249
+					$current_statement .= "\n" . rtrim($line);
1250
+		}
1182 1251
 
1183 1252
 		// Is this the end of the query string?
1184
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1185
-			continue;
1253
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1254
+					continue;
1255
+		}
1186 1256
 
1187 1257
 		// Does this table already exist?  If so, don't insert more data into it!
1188 1258
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1189 1259
 		{
1190 1260
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1191
-			if (!empty($matches[0]))
1192
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1193
-			else
1194
-				$incontext['sql_results']['insert_dups']++;
1261
+			if (!empty($matches[0])) {
1262
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1263
+			} else {
1264
+							$incontext['sql_results']['insert_dups']++;
1265
+			}
1195 1266
 
1196 1267
 			$current_statement = '';
1197 1268
 			continue;
@@ -1212,18 +1283,18 @@  discard block
 block discarded – undo
1212 1283
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1213 1284
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1214 1285
 			}
1215
-		}
1216
-		else
1286
+		} else
1217 1287
 		{
1218
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1219
-				$incontext['sql_results']['tables']++;
1220
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1288
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1289
+							$incontext['sql_results']['tables']++;
1290
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1221 1291
 			{
1222 1292
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1223
-				if (!empty($matches[0]))
1224
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1225
-				else
1226
-					$incontext['sql_results']['inserts']++;
1293
+				if (!empty($matches[0])) {
1294
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1295
+				} else {
1296
+									$incontext['sql_results']['inserts']++;
1297
+				}
1227 1298
 			}
1228 1299
 		}
1229 1300
 
@@ -1236,15 +1307,17 @@  discard block
 block discarded – undo
1236 1307
 	// Sort out the context for the SQL.
1237 1308
 	foreach ($incontext['sql_results'] as $key => $number)
1238 1309
 	{
1239
-		if ($number == 0)
1240
-			unset($incontext['sql_results'][$key]);
1241
-		else
1242
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1310
+		if ($number == 0) {
1311
+					unset($incontext['sql_results'][$key]);
1312
+		} else {
1313
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1314
+		}
1243 1315
 	}
1244 1316
 
1245 1317
 	// Make sure UTF will be used globally.
1246
-	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'])))
1247
-		$newSettings[] = array('global_character_set', 'UTF-8');
1318
+	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']))) {
1319
+			$newSettings[] = array('global_character_set', 'UTF-8');
1320
+	}
1248 1321
 
1249 1322
 	// Auto-detect local & global cookie settings
1250 1323
 	$url_parts = parse_url($boardurl);
@@ -1273,15 +1346,19 @@  discard block
 block discarded – undo
1273 1346
 
1274 1347
 		// Look for subfolder, if found, set localCookie
1275 1348
 		// Checking for len > 1 ensures you don't have just a slash...
1276
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1277
-			$localCookies = '1';
1349
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1350
+					$localCookies = '1';
1351
+		}
1278 1352
 
1279
-		if (isset($globalCookies))
1280
-			$newSettings[] = array('globalCookies', $globalCookies);
1281
-		if (isset($globalCookiesDomain))
1282
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1283
-		if (isset($localCookies))
1284
-			$newSettings[] = array('localCookies', $localCookies);
1353
+		if (isset($globalCookies)) {
1354
+					$newSettings[] = array('globalCookies', $globalCookies);
1355
+		}
1356
+		if (isset($globalCookiesDomain)) {
1357
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1358
+		}
1359
+		if (isset($localCookies)) {
1360
+					$newSettings[] = array('localCookies', $localCookies);
1361
+		}
1285 1362
 	}
1286 1363
 
1287 1364
 	// Are we allowing stat collection?
@@ -1299,16 +1376,17 @@  discard block
 block discarded – undo
1299 1376
 			fwrite($fp, $out);
1300 1377
 
1301 1378
 			$return_data = '';
1302
-			while (!feof($fp))
1303
-				$return_data .= fgets($fp, 128);
1379
+			while (!feof($fp)) {
1380
+							$return_data .= fgets($fp, 128);
1381
+			}
1304 1382
 
1305 1383
 			fclose($fp);
1306 1384
 
1307 1385
 			// Get the unique site ID.
1308 1386
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1309 1387
 
1310
-			if (!empty($ID[1]))
1311
-				$smcFunc['db_insert']('replace',
1388
+			if (!empty($ID[1])) {
1389
+							$smcFunc['db_insert']('replace',
1312 1390
 					$db_prefix . 'settings',
1313 1391
 					array('variable' => 'string', 'value' => 'string'),
1314 1392
 					array(
@@ -1317,11 +1395,12 @@  discard block
 block discarded – undo
1317 1395
 					),
1318 1396
 					array('variable')
1319 1397
 				);
1398
+			}
1320 1399
 		}
1321 1400
 	}
1322 1401
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1323
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1324
-		$smcFunc['db_query']('', '
1402
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1403
+			$smcFunc['db_query']('', '
1325 1404
 			DELETE FROM {db_prefix}settings
1326 1405
 			WHERE variable = {string:enable_sm_stats}',
1327 1406
 			array(
@@ -1329,20 +1408,23 @@  discard block
 block discarded – undo
1329 1408
 				'db_error_skip' => true,
1330 1409
 			)
1331 1410
 		);
1411
+	}
1332 1412
 
1333 1413
 	// Are we enabling SSL?
1334
-	if (!empty($_POST['force_ssl']))
1335
-		$newSettings[] = array('force_ssl', 1);
1414
+	if (!empty($_POST['force_ssl'])) {
1415
+			$newSettings[] = array('force_ssl', 1);
1416
+	}
1336 1417
 
1337 1418
 	// Setting a timezone is required.
1338 1419
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1339 1420
 	{
1340 1421
 		// Get PHP's default timezone, if set
1341 1422
 		$ini_tz = ini_get('date.timezone');
1342
-		if (!empty($ini_tz))
1343
-			$timezone_id = $ini_tz;
1344
-		else
1345
-			$timezone_id = '';
1423
+		if (!empty($ini_tz)) {
1424
+					$timezone_id = $ini_tz;
1425
+		} else {
1426
+					$timezone_id = '';
1427
+		}
1346 1428
 
1347 1429
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1348 1430
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1351,8 +1433,9 @@  discard block
 block discarded – undo
1351 1433
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1352 1434
 		}
1353 1435
 
1354
-		if (date_default_timezone_set($timezone_id))
1355
-			$newSettings[] = array('default_timezone', $timezone_id);
1436
+		if (date_default_timezone_set($timezone_id)) {
1437
+					$newSettings[] = array('default_timezone', $timezone_id);
1438
+		}
1356 1439
 	}
1357 1440
 
1358 1441
 	if (!empty($newSettings))
@@ -1383,16 +1466,18 @@  discard block
 block discarded – undo
1383 1466
 	}
1384 1467
 
1385 1468
 	// MySQL specific stuff
1386
-	if (substr($db_type, 0, 5) != 'mysql')
1387
-		return false;
1469
+	if (substr($db_type, 0, 5) != 'mysql') {
1470
+			return false;
1471
+	}
1388 1472
 
1389 1473
 	// Find database user privileges.
1390 1474
 	$privs = array();
1391 1475
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1392 1476
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1393 1477
 	{
1394
-		if ($row['Privilege'] == 'Alter')
1395
-			$privs[] = $row['Privilege'];
1478
+		if ($row['Privilege'] == 'Alter') {
1479
+					$privs[] = $row['Privilege'];
1480
+		}
1396 1481
 	}
1397 1482
 	$smcFunc['db_free_result']($get_privs);
1398 1483
 
@@ -1422,8 +1507,9 @@  discard block
 block discarded – undo
1422 1507
 	$incontext['continue'] = 1;
1423 1508
 
1424 1509
 	// Skipping?
1425
-	if (!empty($_POST['skip']))
1426
-		return true;
1510
+	if (!empty($_POST['skip'])) {
1511
+			return true;
1512
+	}
1427 1513
 
1428 1514
 	// Need this to check whether we need the database password.
1429 1515
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1440,18 +1526,22 @@  discard block
 block discarded – undo
1440 1526
 	// We need this to properly hash the password for Admin
1441 1527
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1442 1528
 			global $sourcedir;
1443
-			if (function_exists('mb_strtolower'))
1444
-				return mb_strtolower($string, 'UTF-8');
1529
+			if (function_exists('mb_strtolower')) {
1530
+							return mb_strtolower($string, 'UTF-8');
1531
+			}
1445 1532
 			require_once($sourcedir . '/Subs-Charset.php');
1446 1533
 			return utf8_strtolower($string);
1447 1534
 		};
1448 1535
 
1449
-	if (!isset($_POST['username']))
1450
-		$_POST['username'] = '';
1451
-	if (!isset($_POST['email']))
1452
-		$_POST['email'] = '';
1453
-	if (!isset($_POST['server_email']))
1454
-		$_POST['server_email'] = '';
1536
+	if (!isset($_POST['username'])) {
1537
+			$_POST['username'] = '';
1538
+	}
1539
+	if (!isset($_POST['email'])) {
1540
+			$_POST['email'] = '';
1541
+	}
1542
+	if (!isset($_POST['server_email'])) {
1543
+			$_POST['server_email'] = '';
1544
+	}
1455 1545
 
1456 1546
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1457 1547
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1470,8 +1560,9 @@  discard block
 block discarded – undo
1470 1560
 			'admin_group' => 1,
1471 1561
 		)
1472 1562
 	);
1473
-	if ($smcFunc['db_num_rows']($request) != 0)
1474
-		$incontext['skip'] = 1;
1563
+	if ($smcFunc['db_num_rows']($request) != 0) {
1564
+			$incontext['skip'] = 1;
1565
+	}
1475 1566
 	$smcFunc['db_free_result']($request);
1476 1567
 
1477 1568
 	// Trying to create an account?
@@ -1502,8 +1593,9 @@  discard block
 block discarded – undo
1502 1593
 		}
1503 1594
 
1504 1595
 		// Update the webmaster's email?
1505
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1506
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1596
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1597
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1598
+		}
1507 1599
 
1508 1600
 		// Work out whether we're going to have dodgy characters and remove them.
1509 1601
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1526,32 +1618,27 @@  discard block
 block discarded – undo
1526 1618
 			$smcFunc['db_free_result']($result);
1527 1619
 
1528 1620
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1529
-		}
1530
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1621
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1531 1622
 		{
1532 1623
 			// Try the previous step again.
1533 1624
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1534 1625
 			return false;
1535
-		}
1536
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1626
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1537 1627
 		{
1538 1628
 			// Try the previous step again.
1539 1629
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1540 1630
 			return false;
1541
-		}
1542
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1631
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1543 1632
 		{
1544 1633
 			// One step back, this time fill out a proper admin email address.
1545 1634
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1546 1635
 			return false;
1547
-		}
1548
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1636
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1549 1637
 		{
1550 1638
 			// One step back, this time fill out a proper admin email address.
1551 1639
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1552 1640
 			return false;
1553
-		}
1554
-		elseif ($_POST['username'] != '')
1641
+		} elseif ($_POST['username'] != '')
1555 1642
 		{
1556 1643
 			$incontext['member_salt'] = substr(md5(random_int(0, PHP_INT_MAX)), 0, 4);
1557 1644
 
@@ -1619,17 +1706,19 @@  discard block
 block discarded – undo
1619 1706
 	reloadSettings();
1620 1707
 
1621 1708
 	// Bring a warning over.
1622
-	if (!empty($incontext['account_existed']))
1623
-		$incontext['warning'] = $incontext['account_existed'];
1709
+	if (!empty($incontext['account_existed'])) {
1710
+			$incontext['warning'] = $incontext['account_existed'];
1711
+	}
1624 1712
 
1625
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1626
-		$smcFunc['db_query']('', '
1713
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1714
+			$smcFunc['db_query']('', '
1627 1715
 			SET NAMES {string:db_character_set}',
1628 1716
 			array(
1629 1717
 				'db_character_set' => $db_character_set,
1630 1718
 				'db_error_skip' => true,
1631 1719
 			)
1632 1720
 		);
1721
+	}
1633 1722
 
1634 1723
 	// As track stats is by default enabled let's add some activity.
1635 1724
 	$smcFunc['db_insert']('ignore',
@@ -1650,14 +1739,16 @@  discard block
 block discarded – undo
1650 1739
 	// Only proceed if we can load the data.
1651 1740
 	if ($request)
1652 1741
 	{
1653
-		while ($row = $smcFunc['db_fetch_row']($request))
1654
-			$modSettings[$row[0]] = $row[1];
1742
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1743
+					$modSettings[$row[0]] = $row[1];
1744
+		}
1655 1745
 		$smcFunc['db_free_result']($request);
1656 1746
 	}
1657 1747
 
1658 1748
 	// Automatically log them in ;)
1659
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1660
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1749
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1750
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1751
+	}
1661 1752
 
1662 1753
 	$result = $smcFunc['db_query']('', '
1663 1754
 		SELECT value
@@ -1668,13 +1759,14 @@  discard block
 block discarded – undo
1668 1759
 			'db_error_skip' => true,
1669 1760
 		)
1670 1761
 	);
1671
-	if ($smcFunc['db_num_rows']($result) != 0)
1672
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1762
+	if ($smcFunc['db_num_rows']($result) != 0) {
1763
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1764
+	}
1673 1765
 	$smcFunc['db_free_result']($result);
1674 1766
 
1675
-	if (empty($db_sessions))
1676
-		$_SESSION['admin_time'] = time();
1677
-	else
1767
+	if (empty($db_sessions)) {
1768
+			$_SESSION['admin_time'] = time();
1769
+	} else
1678 1770
 	{
1679 1771
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1680 1772
 
@@ -1698,8 +1790,9 @@  discard block
 block discarded – undo
1698 1790
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1699 1791
 		function($string){
1700 1792
 			global $sourcedir;
1701
-			if (function_exists('mb_strtolower'))
1702
-				return mb_strtolower($string, 'UTF-8');
1793
+			if (function_exists('mb_strtolower')) {
1794
+							return mb_strtolower($string, 'UTF-8');
1795
+			}
1703 1796
 			require_once($sourcedir . '/Subs-Charset.php');
1704 1797
 			return utf8_strtolower($string);
1705 1798
 		};
@@ -1715,8 +1808,9 @@  discard block
 block discarded – undo
1715 1808
 		)
1716 1809
 	);
1717 1810
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1718
-	if ($smcFunc['db_num_rows']($request) > 0)
1719
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1811
+	if ($smcFunc['db_num_rows']($request) > 0) {
1812
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1813
+	}
1720 1814
 	$smcFunc['db_free_result']($request);
1721 1815
 
1722 1816
 	// Now is the perfect time to fetch the SM files.
@@ -1735,8 +1829,9 @@  discard block
 block discarded – undo
1735 1829
 
1736 1830
 	// Check if we need some stupid MySQL fix.
1737 1831
 	$server_version = $smcFunc['db_server_info']();
1738
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1739
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1832
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1833
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1834
+	}
1740 1835
 
1741 1836
 	// Some final context for the template.
1742 1837
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1756,8 +1851,9 @@  discard block
 block discarded – undo
1756 1851
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1757 1852
 
1758 1853
 	// @todo Do we just want to read the file in clean, and split it this way always?
1759
-	if (count($settingsArray) == 1)
1760
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1854
+	if (count($settingsArray) == 1) {
1855
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1856
+	}
1761 1857
 
1762 1858
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1763 1859
 	{
@@ -1765,25 +1861,29 @@  discard block
 block discarded – undo
1765 1861
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1766 1862
 		{
1767 1863
 			// Set the ten lines to nothing.
1768
-			for ($j=0; $j < 10; $j++)
1769
-				$settingsArray[$i++] = '';
1864
+			for ($j=0; $j < 10; $j++) {
1865
+							$settingsArray[$i++] = '';
1866
+			}
1770 1867
 
1771 1868
 			continue;
1772 1869
 		}
1773 1870
 
1774
-		if (trim($settingsArray[$i]) == '?' . '>')
1775
-			$settingsArray[$i] = '';
1871
+		if (trim($settingsArray[$i]) == '?' . '>') {
1872
+					$settingsArray[$i] = '';
1873
+		}
1776 1874
 
1777 1875
 		// Don't trim or bother with it if it's not a variable.
1778
-		if (substr($settingsArray[$i], 0, 1) != '$')
1779
-			continue;
1876
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1877
+					continue;
1878
+		}
1780 1879
 
1781 1880
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1782 1881
 
1783
-		foreach ($vars as $var => $val)
1784
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1882
+		foreach ($vars as $var => $val) {
1883
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1785 1884
 			{
1786 1885
 				$comment = strstr($settingsArray[$i], '#');
1886
+		}
1787 1887
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1788 1888
 				unset($vars[$var]);
1789 1889
 			}
@@ -1793,36 +1893,41 @@  discard block
 block discarded – undo
1793 1893
 	if (!empty($vars))
1794 1894
 	{
1795 1895
 		$settingsArray[$i++] = '';
1796
-		foreach ($vars as $var => $val)
1797
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1896
+		foreach ($vars as $var => $val) {
1897
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1898
+		}
1798 1899
 	}
1799 1900
 
1800 1901
 	// Blank out the file - done to fix a oddity with some servers.
1801 1902
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1802
-	if (!$fp)
1803
-		return false;
1903
+	if (!$fp) {
1904
+			return false;
1905
+	}
1804 1906
 	fclose($fp);
1805 1907
 
1806 1908
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1807 1909
 
1808 1910
 	// Gotta have one of these ;)
1809
-	if (trim($settingsArray[0]) != '<?php')
1810
-		fwrite($fp, "<?php\n");
1911
+	if (trim($settingsArray[0]) != '<?php') {
1912
+			fwrite($fp, "<?php\n");
1913
+	}
1811 1914
 
1812 1915
 	$lines = count($settingsArray);
1813 1916
 	for ($i = 0; $i < $lines - 1; $i++)
1814 1917
 	{
1815 1918
 		// Don't just write a bunch of blank lines.
1816
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1817
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1919
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1920
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1921
+		}
1818 1922
 	}
1819 1923
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1820 1924
 	fclose($fp);
1821 1925
 
1822 1926
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1823 1927
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1824
-	if (function_exists('opcache_invalidate'))
1825
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1928
+	if (function_exists('opcache_invalidate')) {
1929
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1930
+	}
1826 1931
 
1827 1932
 	return true;
1828 1933
 }
@@ -1832,10 +1937,11 @@  discard block
 block discarded – undo
1832 1937
 	global $cachedir;
1833 1938
 
1834 1939
 	// Write out the db_last_error file with the error timestamp
1835
-	if (!empty($cachedir) && is_writable($cachedir))
1836
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1837
-	else
1838
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1940
+	if (!empty($cachedir) && is_writable($cachedir)) {
1941
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1942
+	} else {
1943
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1944
+	}
1839 1945
 
1840 1946
 	return true;
1841 1947
 }
@@ -1852,9 +1958,9 @@  discard block
 block discarded – undo
1852 1958
 	SecFilterScanPOST Off
1853 1959
 </IfModule>';
1854 1960
 
1855
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1856
-		return true;
1857
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1961
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1962
+			return true;
1963
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1858 1964
 	{
1859 1965
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1860 1966
 
@@ -1866,29 +1972,28 @@  discard block
 block discarded – undo
1866 1972
 				fwrite($ht_handle, $htaccess_addition);
1867 1973
 				fclose($ht_handle);
1868 1974
 				return true;
1975
+			} else {
1976
+							return false;
1869 1977
 			}
1870
-			else
1871
-				return false;
1978
+		} else {
1979
+					return true;
1872 1980
 		}
1873
-		else
1874
-			return true;
1875
-	}
1876
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1877
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1878
-	elseif (is_writable(dirname(__FILE__)))
1981
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1982
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1983
+	} elseif (is_writable(dirname(__FILE__)))
1879 1984
 	{
1880 1985
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1881 1986
 		{
1882 1987
 			fwrite($ht_handle, $htaccess_addition);
1883 1988
 			fclose($ht_handle);
1884 1989
 			return true;
1990
+		} else {
1991
+					return false;
1885 1992
 		}
1886
-		else
1993
+	} else {
1887 1994
 			return false;
1888 1995
 	}
1889
-	else
1890
-		return false;
1891
-}
1996
+	}
1892 1997
 
1893 1998
 function template_install_above()
1894 1999
 {
@@ -1927,9 +2032,10 @@  discard block
 block discarded – undo
1927 2032
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1928 2033
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1929 2034
 
1930
-		foreach ($incontext['detected_languages'] as $lang => $name)
1931
-			echo '
2035
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2036
+					echo '
1932 2037
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2038
+		}
1933 2039
 
1934 2040
 		echo '
1935 2041
 							</select>
@@ -1949,9 +2055,10 @@  discard block
 block discarded – undo
1949 2055
 					<h2>', $txt['upgrade_progress'], '</h2>
1950 2056
 					<ul>';
1951 2057
 
1952
-	foreach ($incontext['steps'] as $num => $step)
1953
-		echo '
2058
+	foreach ($incontext['steps'] as $num => $step) {
2059
+			echo '
1954 2060
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2061
+	}
1955 2062
 
1956 2063
 	echo '
1957 2064
 					</ul>
@@ -1977,20 +2084,23 @@  discard block
 block discarded – undo
1977 2084
 		echo '
1978 2085
 							<div class="floatright">';
1979 2086
 
1980
-		if (!empty($incontext['continue']))
1981
-			echo '
2087
+		if (!empty($incontext['continue'])) {
2088
+					echo '
1982 2089
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1983
-		if (!empty($incontext['skip']))
1984
-			echo '
2090
+		}
2091
+		if (!empty($incontext['skip'])) {
2092
+					echo '
1985 2093
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2094
+		}
1986 2095
 		echo '
1987 2096
 							</div>';
1988 2097
 	}
1989 2098
 
1990 2099
 	// Show the closing form tag and other data only if not in the last step
1991
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1992
-		echo '
2100
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2101
+			echo '
1993 2102
 						</form>';
2103
+	}
1994 2104
 
1995 2105
 	echo '
1996 2106
 					</div><!-- .panel -->
@@ -2023,13 +2133,15 @@  discard block
 block discarded – undo
2023 2133
 		</div>';
2024 2134
 
2025 2135
 	// Show the warnings, or not.
2026
-	if (template_warning_divs())
2027
-		echo '
2136
+	if (template_warning_divs()) {
2137
+			echo '
2028 2138
 		<h3>', $txt['install_all_lovely'], '</h3>';
2139
+	}
2029 2140
 
2030 2141
 	// Say we want the continue button!
2031
-	if (empty($incontext['error']))
2032
-		$incontext['continue'] = 1;
2142
+	if (empty($incontext['error'])) {
2143
+			$incontext['continue'] = 1;
2144
+	}
2033 2145
 
2034 2146
 	// For the latest version stuff.
2035 2147
 	echo '
@@ -2063,19 +2175,21 @@  discard block
 block discarded – undo
2063 2175
 	global $txt, $incontext;
2064 2176
 
2065 2177
 	// Errors are very serious..
2066
-	if (!empty($incontext['error']))
2067
-		echo '
2178
+	if (!empty($incontext['error'])) {
2179
+			echo '
2068 2180
 		<div class="errorbox">
2069 2181
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2070 2182
 			', $incontext['error'], '
2071 2183
 		</div>';
2184
+	}
2072 2185
 	// A warning message?
2073
-	elseif (!empty($incontext['warning']))
2074
-		echo '
2186
+	elseif (!empty($incontext['warning'])) {
2187
+			echo '
2075 2188
 		<div class="errorbox">
2076 2189
 			<h3>', $txt['upgrade_warning'], '</h3>
2077 2190
 			', $incontext['warning'], '
2078 2191
 		</div>';
2192
+	}
2079 2193
 
2080 2194
 	return empty($incontext['error']) && empty($incontext['warning']);
2081 2195
 }
@@ -2091,26 +2205,29 @@  discard block
 block discarded – undo
2091 2205
 			<li>', $incontext['failed_files']), '</li>
2092 2206
 		</ul>';
2093 2207
 
2094
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2095
-		echo '
2208
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2209
+			echo '
2096 2210
 		<hr>
2097 2211
 		<p>', $txt['chmod_linux_info'], '</p>
2098 2212
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2213
+	}
2099 2214
 
2100 2215
 	// This is serious!
2101
-	if (!template_warning_divs())
2102
-		return;
2216
+	if (!template_warning_divs()) {
2217
+			return;
2218
+	}
2103 2219
 
2104 2220
 	echo '
2105 2221
 		<hr>
2106 2222
 		<p>', $txt['ftp_setup_info'], '</p>';
2107 2223
 
2108
-	if (!empty($incontext['ftp_errors']))
2109
-		echo '
2224
+	if (!empty($incontext['ftp_errors'])) {
2225
+			echo '
2110 2226
 		<div class="error_message">
2111 2227
 			', $txt['error_ftp_no_connect'], '<br><br>
2112 2228
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2113 2229
 		</div>';
2230
+	}
2114 2231
 
2115 2232
 	echo '
2116 2233
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2179,16 +2296,16 @@  discard block
 block discarded – undo
2179 2296
 			<dd>
2180 2297
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2181 2298
 
2182
-	foreach ($incontext['supported_databases'] as $key => $db)
2183
-			echo '
2299
+	foreach ($incontext['supported_databases'] as $key => $db) {
2300
+				echo '
2184 2301
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2302
+	}
2185 2303
 
2186 2304
 	echo '
2187 2305
 				</select>
2188 2306
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2189 2307
 			</dd>';
2190
-	}
2191
-	else
2308
+	} else
2192 2309
 	{
2193 2310
 		echo '
2194 2311
 			<dd>
@@ -2356,9 +2473,10 @@  discard block
 block discarded – undo
2356 2473
 		<div class="red">', $txt['error_db_queries'], '</div>
2357 2474
 		<ul>';
2358 2475
 
2359
-		foreach ($incontext['failures'] as $line => $fail)
2360
-			echo '
2476
+		foreach ($incontext['failures'] as $line => $fail) {
2477
+					echo '
2361 2478
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2479
+		}
2362 2480
 
2363 2481
 		echo '
2364 2482
 		</ul>';
@@ -2423,15 +2541,16 @@  discard block
 block discarded – undo
2423 2541
 			</dd>
2424 2542
 		</dl>';
2425 2543
 
2426
-	if ($incontext['require_db_confirm'])
2427
-		echo '
2544
+	if ($incontext['require_db_confirm']) {
2545
+			echo '
2428 2546
 		<h2>', $txt['user_settings_database'], '</h2>
2429 2547
 		<p>', $txt['user_settings_database_info'], '</p>
2430 2548
 
2431 2549
 		<div class="lefttext">
2432 2550
 			<input type="password" name="password3" size="30">
2433 2551
 		</div>';
2434
-}
2552
+	}
2553
+	}
2435 2554
 
2436 2555
 // Tell them it's done, and to delete.
2437 2556
 function template_delete_install()
@@ -2444,13 +2563,14 @@  discard block
 block discarded – undo
2444 2563
 	template_warning_divs();
2445 2564
 
2446 2565
 	// Install directory still writable?
2447
-	if ($incontext['dir_still_writable'])
2448
-		echo '
2566
+	if ($incontext['dir_still_writable']) {
2567
+			echo '
2449 2568
 		<p><em>', $txt['still_writable'], '</em></p>';
2569
+	}
2450 2570
 
2451 2571
 	// Don't show the box if it's like 99% sure it won't work :P.
2452
-	if ($incontext['probably_delete_install'])
2453
-		echo '
2572
+	if ($incontext['probably_delete_install']) {
2573
+			echo '
2454 2574
 		<label>
2455 2575
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2456 2576
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2466,6 +2586,7 @@  discard block
 block discarded – undo
2466 2586
 				theCheck.disabled = true;
2467 2587
 			}
2468 2588
 		</script>';
2589
+	}
2469 2590
 
2470 2591
 	echo '
2471 2592
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.