Completed
Pull Request — release-2.1 (#4908)
by Rick
07:52
created
Sources/Subs.php 2 patches
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			{
392 392
 				$val = 'CASE ';
393 393
 				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
394
+					$val .= 'WHEN id_member = ' . $v . ' THEN ' . count(fetch_alerts($v, false, 0, array(), false)) . ' ';
395 395
 				$val = $val . ' END';
396 396
 				$type = 'raw';
397 397
 			}
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	static $non_twelve_hour, $locale_cache;
745 745
 	static $unsupportedFormats, $finalizedFormats;
746 746
 
747
-	$unsupportedFormatsWindows = array('z','Z');
747
+	$unsupportedFormatsWindows = array('z', 'Z');
748 748
 
749 749
 	// Ensure required values are set
750 750
 	$user_info['time_offset'] = !empty($user_info['time_offset']) ? $user_info['time_offset'] : 0;
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
830 830
 		if (empty($unsupportedFormats))
831 831
 		{
832
-			foreach($strftimeFormatSubstitutions as $format => $substitution)
832
+			foreach ($strftimeFormatSubstitutions as $format => $substitution)
833 833
 			{
834 834
 				// Avoid a crashing bug with PHP 7 on certain versions of Windows
835 835
 				if ($context['server']['is_windows'] && in_array($format, $unsupportedFormatsWindows))
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1207 1207
 				),
1208 1208
 				'content' => '$1',
1209
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1209
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1210 1210
 				{
1211 1211
 					$returnContext = '';
1212 1212
 
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 						}
1242 1242
 
1243 1243
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1244
-							$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>';
1244
+							$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>';
1245 1245
 						else
1246 1246
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1247 1247
 					}
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
 				'type' => 'unparsed_content',
1294 1294
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1295 1295
 				// @todo Maybe this can be simplified?
1296
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1296
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1297 1297
 				{
1298 1298
 					if (!isset($disabled['code']))
1299 1299
 					{
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
 				'type' => 'unparsed_equals_content',
1331 1331
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1332 1332
 				// @todo Maybe this can be simplified?
1333
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1333
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1334 1334
 				{
1335 1335
 					if (!isset($disabled['code']))
1336 1336
 					{
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 				'type' => 'unparsed_content',
1375 1375
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1376 1376
 				// @todo Should this respect guest_hideContacts?
1377
-				'validate' => function (&$tag, &$data, $disabled)
1377
+				'validate' => function(&$tag, &$data, $disabled)
1378 1378
 				{
1379 1379
 					$data = strtr($data, array('<br>' => ''));
1380 1380
 				},
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1395 1395
 				'before' => '<div $1>',
1396 1396
 				'after' => '</div>',
1397
-				'validate' => function (&$tag, &$data, $disabled)
1397
+				'validate' => function(&$tag, &$data, $disabled)
1398 1398
 				{
1399 1399
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1400 1400
 
@@ -1480,7 +1480,7 @@  discard block
 block discarded – undo
1480 1480
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1481 1481
 				),
1482 1482
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1483
-				'validate' => function (&$tag, &$data, $disabled)
1483
+				'validate' => function(&$tag, &$data, $disabled)
1484 1484
 				{
1485 1485
 					global $image_proxy_enabled, $user_info;
1486 1486
 
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
 				'tag' => 'img',
1507 1507
 				'type' => 'unparsed_content',
1508 1508
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1509
-				'validate' => function (&$tag, &$data, $disabled)
1509
+				'validate' => function(&$tag, &$data, $disabled)
1510 1510
 				{
1511 1511
 					global $image_proxy_enabled, $user_info;
1512 1512
 
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
 				'tag' => 'iurl',
1533 1533
 				'type' => 'unparsed_content',
1534 1534
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1535
-				'validate' => function (&$tag, &$data, $disabled)
1535
+				'validate' => function(&$tag, &$data, $disabled)
1536 1536
 				{
1537 1537
 					$data = strtr($data, array('<br>' => ''));
1538 1538
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
 				'quoted' => 'optional',
1547 1547
 				'before' => '<a href="$1" class="bbc_link">',
1548 1548
 				'after' => '</a>',
1549
-				'validate' => function (&$tag, &$data, $disabled)
1549
+				'validate' => function(&$tag, &$data, $disabled)
1550 1550
 				{
1551 1551
 					if (substr($data, 0, 1) == '#')
1552 1552
 						$data = '#post_' . substr($data, 1);
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
 				'tag' => 'php',
1640 1640
 				'type' => 'unparsed_content',
1641 1641
 				'content' => '<span class="phpcode">$1</span>',
1642
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1642
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1643 1643
 				{
1644 1644
 					if (!isset($disabled['php']))
1645 1645
 					{
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
 				'test' => '[1-7]\]',
1789 1789
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1790 1790
 				'after' => '</span>',
1791
-				'validate' => function (&$tag, &$data, $disabled)
1791
+				'validate' => function(&$tag, &$data, $disabled)
1792 1792
 				{
1793 1793
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1794 1794
 					$data = $sizes[$data] . 'em';
@@ -1826,7 +1826,7 @@  discard block
 block discarded – undo
1826 1826
 				'tag' => 'time',
1827 1827
 				'type' => 'unparsed_content',
1828 1828
 				'content' => '$1',
1829
-				'validate' => function (&$tag, &$data, $disabled)
1829
+				'validate' => function(&$tag, &$data, $disabled)
1830 1830
 				{
1831 1831
 					if (is_numeric($data))
1832 1832
 						$data = timeformat($data);
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
 				'tag' => 'url',
1860 1860
 				'type' => 'unparsed_content',
1861 1861
 				'content' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>',
1862
-				'validate' => function (&$tag, &$data, $disabled)
1862
+				'validate' => function(&$tag, &$data, $disabled)
1863 1863
 				{
1864 1864
 					$data = strtr($data, array('<br>' => ''));
1865 1865
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1873,7 +1873,7 @@  discard block
 block discarded – undo
1873 1873
 				'quoted' => 'optional',
1874 1874
 				'before' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">',
1875 1875
 				'after' => '</a>',
1876
-				'validate' => function (&$tag, &$data, $disabled)
1876
+				'validate' => function(&$tag, &$data, $disabled)
1877 1877
 				{
1878 1878
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1879 1879
 					if (empty($scheme))
@@ -1912,7 +1912,7 @@  discard block
 block discarded – undo
1912 1912
 		{
1913 1913
 			if (isset($temp_bbc))
1914 1914
 				$bbc_codes = $temp_bbc;
1915
-			usort($codes, function ($a, $b) {
1915
+			usort($codes, function($a, $b) {
1916 1916
 				return strcmp($a['tag'], $b['tag']);
1917 1917
 			});
1918 1918
 			return $codes;
@@ -2128,7 +2128,7 @@  discard block
 block discarded – undo
2128 2128
 										# a run of Unicode domain name characters and a dot
2129 2129
 										[\p{L}\p{M}\p{N}\-.:@]+\.
2130 2130
 										# and then a TLD valid in the DNS or the reserved "local" TLD
2131
-										(?:'. $modSettings['tld_regex'] .'|local)
2131
+										(?:'. $modSettings['tld_regex'] . '|local)
2132 2132
 									)
2133 2133
 									# followed by a non-domain character or end of line
2134 2134
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
 						)?
2197 2197
 						';
2198 2198
 
2199
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
2199
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
2200 2200
 							$url = array_shift($matches);
2201 2201
 
2202 2202
 							// If this isn't a clean URL, bail out
@@ -2221,7 +2221,7 @@  discard block
 block discarded – undo
2221 2221
 								$fullUrl = $url;
2222 2222
 
2223 2223
 							// Make sure that $fullUrl really is valid
2224
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2224
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '') . $fullUrl) === false)
2225 2225
 								return $url;
2226 2226
 
2227 2227
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2286 2286
 
2287 2287
 			// A closing tag that doesn't match any open tags? Skip it.
2288
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2288
+			if (!in_array($look_for, array_map(function($code) {return $code['tag']; }, $open_tags)))
2289 2289
 				continue;
2290 2290
 
2291 2291
 			$to_close = array();
@@ -2958,7 +2958,7 @@  discard block
 block discarded – undo
2958 2958
 			{
2959 2959
 				$exts = array('svg', 'png', 'gif', 'jpg');
2960 2960
 				$fname = pathinfo($smileysto[$i], PATHINFO_FILENAME);
2961
-				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2961
+				$alt_images = glob($smileys_dir . $fname . '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2962 2962
 				if (!empty($alt_images))
2963 2963
 				{
2964 2964
 					foreach ($exts as $ext)
@@ -2974,7 +2974,7 @@  discard block
 block discarded – undo
2974 2974
 			}
2975 2975
 
2976 2976
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2977
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2977
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2978 2978
 
2979 2979
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2980 2980
 
@@ -2991,7 +2991,7 @@  discard block
 block discarded – undo
2991 2991
 
2992 2992
 	// Replace away!
2993 2993
 	$message = preg_replace_callback($smileyPregSearch,
2994
-		function ($matches) use ($smileyPregReplacements)
2994
+		function($matches) use ($smileyPregReplacements)
2995 2995
 		{
2996 2996
 			return $smileyPregReplacements[$matches[1]];
2997 2997
 		}, $message);
@@ -3088,13 +3088,13 @@  discard block
 block discarded – undo
3088 3088
 	{
3089 3089
 		if (defined('SID') && SID != '')
3090 3090
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3091
-				function ($m) use ($scripturl)
3091
+				function($m) use ($scripturl)
3092 3092
 				{
3093
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3093
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
3094 3094
 				}, $setLocation);
3095 3095
 		else
3096 3096
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3097
-				function ($m) use ($scripturl)
3097
+				function($m) use ($scripturl)
3098 3098
 				{
3099 3099
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3100 3100
 				}, $setLocation);
@@ -3415,7 +3415,7 @@  discard block
 block discarded – undo
3415 3415
 
3416 3416
 	// Add a generic "Are you sure?" confirmation message.
3417 3417
 	addInlineJavaScript('
3418
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3418
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3419 3419
 
3420 3420
 	// Now add the capping code for avatars.
3421 3421
 	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')
@@ -3881,7 +3881,7 @@  discard block
 block discarded – undo
3881 3881
 	if (!empty($normal))
3882 3882
 		foreach ($normal as $nf)
3883 3883
 			echo '
3884
-	<link rel="stylesheet" href="', $nf ,'">';
3884
+	<link rel="stylesheet" href="', $nf, '">';
3885 3885
 
3886 3886
 	if ($db_show_debug === true)
3887 3887
 	{
@@ -3897,7 +3897,7 @@  discard block
 block discarded – undo
3897 3897
 	<style>';
3898 3898
 
3899 3899
 		foreach ($context['css_header'] as $css)
3900
-			echo $css .'
3900
+			echo $css . '
3901 3901
 	';
3902 3902
 
3903 3903
 		echo'
@@ -3941,7 +3941,7 @@  discard block
 block discarded – undo
3941 3941
 
3942 3942
 
3943 3943
 	// No namespaces, sorry!
3944
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3944
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3945 3945
 
3946 3946
 	// Temp path.
3947 3947
 	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
@@ -4121,7 +4121,7 @@  discard block
 block discarded – undo
4121 4121
 	else
4122 4122
 		$path = $modSettings['attachmentUploadDir'];
4123 4123
 
4124
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4124
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
4125 4125
 }
4126 4126
 
4127 4127
 /**
@@ -4165,10 +4165,10 @@  discard block
 block discarded – undo
4165 4165
 		$valid_low = isValidIP($ip_parts[0]);
4166 4166
 		$valid_high = isValidIP($ip_parts[1]);
4167 4167
 		$count = 0;
4168
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
4168
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
4169 4169
 		$max = ($mode == ':' ? 'ffff' : '255');
4170 4170
 		$min = 0;
4171
-		if(!$valid_low)
4171
+		if (!$valid_low)
4172 4172
 		{
4173 4173
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
4174 4174
 			$valid_low = isValidIP($ip_parts[0]);
@@ -4182,7 +4182,7 @@  discard block
 block discarded – undo
4182 4182
 		}
4183 4183
 
4184 4184
 		$count = 0;
4185
-		if(!$valid_high)
4185
+		if (!$valid_high)
4186 4186
 		{
4187 4187
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
4188 4188
 			$valid_high = isValidIP($ip_parts[1]);
@@ -4195,7 +4195,7 @@  discard block
 block discarded – undo
4195 4195
 			}
4196 4196
 		}
4197 4197
 
4198
-		if($valid_high && $valid_low)
4198
+		if ($valid_high && $valid_low)
4199 4199
 		{
4200 4200
 			$ip_array['low'] = $ip_parts[0];
4201 4201
 			$ip_array['high'] = $ip_parts[1];
@@ -4376,7 +4376,7 @@  discard block
 block discarded – undo
4376 4376
 		addInlineJavaScript('
4377 4377
 	var user_menus = new smc_PopupMenu();
4378 4378
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4379
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4379
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4380 4380
 		if ($context['allow_pm'])
4381 4381
 			addInlineJavaScript('
4382 4382
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -5012,7 +5012,7 @@  discard block
 block discarded – undo
5012 5012
 		// No? try a fallback to $sourcedir
5013 5013
 		else
5014 5014
 		{
5015
-			$absPath = $sourcedir .'/'. $file;
5015
+			$absPath = $sourcedir . '/' . $file;
5016 5016
 
5017 5017
 			if (file_exists($absPath))
5018 5018
 				require_once($absPath);
@@ -5279,15 +5279,15 @@  discard block
 block discarded – undo
5279 5279
 
5280 5280
 	// UTF-8 occurences of MS special characters
5281 5281
 	$findchars_utf8 = array(
5282
-		"\xe2\x80\x9a",	// single low-9 quotation mark
5283
-		"\xe2\x80\x9e",	// double low-9 quotation mark
5284
-		"\xe2\x80\xa6",	// horizontal ellipsis
5285
-		"\xe2\x80\x98",	// left single curly quote
5286
-		"\xe2\x80\x99",	// right single curly quote
5287
-		"\xe2\x80\x9c",	// left double curly quote
5288
-		"\xe2\x80\x9d",	// right double curly quote
5289
-		"\xe2\x80\x93",	// en dash
5290
-		"\xe2\x80\x94",	// em dash
5282
+		"\xe2\x80\x9a", // single low-9 quotation mark
5283
+		"\xe2\x80\x9e", // double low-9 quotation mark
5284
+		"\xe2\x80\xa6", // horizontal ellipsis
5285
+		"\xe2\x80\x98", // left single curly quote
5286
+		"\xe2\x80\x99", // right single curly quote
5287
+		"\xe2\x80\x9c", // left double curly quote
5288
+		"\xe2\x80\x9d", // right double curly quote
5289
+		"\xe2\x80\x93", // en dash
5290
+		"\xe2\x80\x94", // em dash
5291 5291
 	);
5292 5292
 
5293 5293
 	// windows 1252 / iso equivalents
@@ -5305,15 +5305,15 @@  discard block
 block discarded – undo
5305 5305
 
5306 5306
 	// safe replacements
5307 5307
 	$replacechars = array(
5308
-		',',	// &sbquo;
5309
-		',,',	// &bdquo;
5310
-		'...',	// &hellip;
5311
-		"'",	// &lsquo;
5312
-		"'",	// &rsquo;
5313
-		'"',	// &ldquo;
5314
-		'"',	// &rdquo;
5315
-		'-',	// &ndash;
5316
-		'--',	// &mdash;
5308
+		',', // &sbquo;
5309
+		',,', // &bdquo;
5310
+		'...', // &hellip;
5311
+		"'", // &lsquo;
5312
+		"'", // &rsquo;
5313
+		'"', // &ldquo;
5314
+		'"', // &rdquo;
5315
+		'-', // &ndash;
5316
+		'--', // &mdash;
5317 5317
 	);
5318 5318
 
5319 5319
 	if ($context['utf8'])
@@ -5633,7 +5633,7 @@  discard block
 block discarded – undo
5633 5633
  */
5634 5634
 function inet_dtop($bin)
5635 5635
 {
5636
-	if(empty($bin))
5636
+	if (empty($bin))
5637 5637
 		return '';
5638 5638
 
5639 5639
 	global $db_type;
@@ -5664,28 +5664,28 @@  discard block
 block discarded – undo
5664 5664
  */
5665 5665
 function _safe_serialize($value)
5666 5666
 {
5667
-	if(is_null($value))
5667
+	if (is_null($value))
5668 5668
 		return 'N;';
5669 5669
 
5670
-	if(is_bool($value))
5671
-		return 'b:'. (int) $value .';';
5670
+	if (is_bool($value))
5671
+		return 'b:' . (int) $value . ';';
5672 5672
 
5673
-	if(is_int($value))
5674
-		return 'i:'. $value .';';
5673
+	if (is_int($value))
5674
+		return 'i:' . $value . ';';
5675 5675
 
5676
-	if(is_float($value))
5677
-		return 'd:'. str_replace(',', '.', $value) .';';
5676
+	if (is_float($value))
5677
+		return 'd:' . str_replace(',', '.', $value) . ';';
5678 5678
 
5679
-	if(is_string($value))
5680
-		return 's:'. strlen($value) .':"'. $value .'";';
5679
+	if (is_string($value))
5680
+		return 's:' . strlen($value) . ':"' . $value . '";';
5681 5681
 
5682
-	if(is_array($value))
5682
+	if (is_array($value))
5683 5683
 	{
5684 5684
 		$out = '';
5685
-		foreach($value as $k => $v)
5685
+		foreach ($value as $k => $v)
5686 5686
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5687 5687
 
5688
-		return 'a:'. count($value) .':{'. $out .'}';
5688
+		return 'a:' . count($value) . ':{' . $out . '}';
5689 5689
 	}
5690 5690
 
5691 5691
 	// safe_serialize cannot serialize resources or objects.
@@ -5727,7 +5727,7 @@  discard block
 block discarded – undo
5727 5727
 function _safe_unserialize($str)
5728 5728
 {
5729 5729
 	// Input  is not a string.
5730
-	if(empty($str) || !is_string($str))
5730
+	if (empty($str) || !is_string($str))
5731 5731
 		return false;
5732 5732
 
5733 5733
 	$stack = array();
@@ -5741,40 +5741,40 @@  discard block
 block discarded – undo
5741 5741
 	 *   3 - in array, expecting value or another array
5742 5742
 	 */
5743 5743
 	$state = 0;
5744
-	while($state != 1)
5744
+	while ($state != 1)
5745 5745
 	{
5746 5746
 		$type = isset($str[0]) ? $str[0] : '';
5747
-		if($type == '}')
5747
+		if ($type == '}')
5748 5748
 			$str = substr($str, 1);
5749 5749
 
5750
-		else if($type == 'N' && $str[1] == ';')
5750
+		else if ($type == 'N' && $str[1] == ';')
5751 5751
 		{
5752 5752
 			$value = null;
5753 5753
 			$str = substr($str, 2);
5754 5754
 		}
5755
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5755
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5756 5756
 		{
5757 5757
 			$value = $matches[1] == '1' ? true : false;
5758 5758
 			$str = substr($str, 4);
5759 5759
 		}
5760
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5760
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5761 5761
 		{
5762
-			$value = (int)$matches[1];
5762
+			$value = (int) $matches[1];
5763 5763
 			$str = $matches[2];
5764 5764
 		}
5765
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5765
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5766 5766
 		{
5767
-			$value = (float)$matches[1];
5767
+			$value = (float) $matches[1];
5768 5768
 			$str = $matches[3];
5769 5769
 		}
5770
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5770
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5771 5771
 		{
5772
-			$value = substr($matches[2], 0, (int)$matches[1]);
5773
-			$str = substr($matches[2], (int)$matches[1] + 2);
5772
+			$value = substr($matches[2], 0, (int) $matches[1]);
5773
+			$str = substr($matches[2], (int) $matches[1] + 2);
5774 5774
 		}
5775
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5775
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5776 5776
 		{
5777
-			$expectedLength = (int)$matches[1];
5777
+			$expectedLength = (int) $matches[1];
5778 5778
 			$str = $matches[2];
5779 5779
 		}
5780 5780
 
@@ -5782,10 +5782,10 @@  discard block
 block discarded – undo
5782 5782
 		else
5783 5783
 			return false;
5784 5784
 
5785
-		switch($state)
5785
+		switch ($state)
5786 5786
 		{
5787 5787
 			case 3: // In array, expecting value or another array.
5788
-				if($type == 'a')
5788
+				if ($type == 'a')
5789 5789
 				{
5790 5790
 					$stack[] = &$list;
5791 5791
 					$list[$key] = array();
@@ -5794,7 +5794,7 @@  discard block
 block discarded – undo
5794 5794
 					$state = 2;
5795 5795
 					break;
5796 5796
 				}
5797
-				if($type != '}')
5797
+				if ($type != '}')
5798 5798
 				{
5799 5799
 					$list[$key] = $value;
5800 5800
 					$state = 2;
@@ -5805,29 +5805,29 @@  discard block
 block discarded – undo
5805 5805
 				return false;
5806 5806
 
5807 5807
 			case 2: // in array, expecting end of array or a key
5808
-				if($type == '}')
5808
+				if ($type == '}')
5809 5809
 				{
5810 5810
 					// Array size is less than expected.
5811
-					if(count($list) < end($expected))
5811
+					if (count($list) < end($expected))
5812 5812
 						return false;
5813 5813
 
5814 5814
 					unset($list);
5815
-					$list = &$stack[count($stack)-1];
5815
+					$list = &$stack[count($stack) - 1];
5816 5816
 					array_pop($stack);
5817 5817
 
5818 5818
 					// Go to terminal state if we're at the end of the root array.
5819 5819
 					array_pop($expected);
5820 5820
 
5821
-					if(count($expected) == 0)
5821
+					if (count($expected) == 0)
5822 5822
 						$state = 1;
5823 5823
 
5824 5824
 					break;
5825 5825
 				}
5826 5826
 
5827
-				if($type == 'i' || $type == 's')
5827
+				if ($type == 'i' || $type == 's')
5828 5828
 				{
5829 5829
 					// Array size exceeds expected length.
5830
-					if(count($list) >= end($expected))
5830
+					if (count($list) >= end($expected))
5831 5831
 						return false;
5832 5832
 
5833 5833
 					$key = $value;
@@ -5840,7 +5840,7 @@  discard block
 block discarded – undo
5840 5840
 
5841 5841
 			// Expecting array or value.
5842 5842
 			case 0:
5843
-				if($type == 'a')
5843
+				if ($type == 'a')
5844 5844
 				{
5845 5845
 					$data = array();
5846 5846
 					$list = &$data;
@@ -5849,7 +5849,7 @@  discard block
 block discarded – undo
5849 5849
 					break;
5850 5850
 				}
5851 5851
 
5852
-				if($type != '}')
5852
+				if ($type != '}')
5853 5853
 				{
5854 5854
 					$data = $value;
5855 5855
 					$state = 1;
@@ -5862,7 +5862,7 @@  discard block
 block discarded – undo
5862 5862
 	}
5863 5863
 
5864 5864
 	// Trailing data in input.
5865
-	if(!empty($str))
5865
+	if (!empty($str))
5866 5866
 		return false;
5867 5867
 
5868 5868
 	return $data;
@@ -5916,7 +5916,7 @@  discard block
 block discarded – undo
5916 5916
 	// Set different modes.
5917 5917
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5918 5918
 
5919
-	foreach($chmodValues as $val)
5919
+	foreach ($chmodValues as $val)
5920 5920
 	{
5921 5921
 		// If it's writable, break out of the loop.
5922 5922
 		if (is_writable($file))
@@ -5951,13 +5951,13 @@  discard block
 block discarded – undo
5951 5951
 	$returnArray = @json_decode($json, $returnAsArray);
5952 5952
 
5953 5953
 	// PHP 5.3 so no json_last_error_msg()
5954
-	switch(json_last_error())
5954
+	switch (json_last_error())
5955 5955
 	{
5956 5956
 		case JSON_ERROR_NONE:
5957 5957
 			$jsonError = false;
5958 5958
 			break;
5959 5959
 		case JSON_ERROR_DEPTH:
5960
-			$jsonError =  'JSON_ERROR_DEPTH';
5960
+			$jsonError = 'JSON_ERROR_DEPTH';
5961 5961
 			break;
5962 5962
 		case JSON_ERROR_STATE_MISMATCH:
5963 5963
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5985,10 +5985,10 @@  discard block
 block discarded – undo
5985 5985
 		loadLanguage('Errors');
5986 5986
 
5987 5987
 		if (!empty($jsonDebug))
5988
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5988
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5989 5989
 
5990 5990
 		else
5991
-			log_error($txt['json_'. $jsonError], 'critical');
5991
+			log_error($txt['json_' . $jsonError], 'critical');
5992 5992
 
5993 5993
 		// Everyone expects an array.
5994 5994
 		return array();
@@ -6105,7 +6105,7 @@  discard block
 block discarded – undo
6105 6105
 		// Convert Punycode to Unicode
6106 6106
 		require_once($sourcedir . '/Class-Punycode.php');
6107 6107
 		$Punycode = new Punycode();
6108
-		$tlds = array_map(function ($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
6108
+		$tlds = array_map(function($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
6109 6109
 	}
6110 6110
 	// Otherwise, use the 2012 list of gTLDs and ccTLDs for now and schedule a background update
6111 6111
 	else
@@ -6199,7 +6199,7 @@  discard block
 block discarded – undo
6199 6199
 	}
6200 6200
 
6201 6201
 	// This recursive function creates the index array from the strings
6202
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6202
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6203 6203
 	{
6204 6204
 		static $depth = 0;
6205 6205
 		$depth++;
@@ -6226,7 +6226,7 @@  discard block
 block discarded – undo
6226 6226
 	};
6227 6227
 
6228 6228
 	// This recursive function turns the index array into a regular expression
6229
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
6229
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
6230 6230
 	{
6231 6231
 		static $depth = 0;
6232 6232
 		$depth++;
@@ -6250,11 +6250,11 @@  discard block
 block discarded – undo
6250 6250
 
6251 6251
 				if (count(array_keys($value)) == 1)
6252 6252
 				{
6253
-					$new_key_array = explode('(?'.'>', $sub_regex);
6253
+					$new_key_array = explode('(?' . '>', $sub_regex);
6254 6254
 					$new_key .= $new_key_array[0];
6255 6255
 				}
6256 6256
 				else
6257
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6257
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
6258 6258
 			}
6259 6259
 
6260 6260
 			if ($depth > 1)
@@ -6297,10 +6297,10 @@  discard block
 block discarded – undo
6297 6297
 	{
6298 6298
 		$regex = array();
6299 6299
 		while (!empty($index))
6300
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6300
+			$regex[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6301 6301
 	}
6302 6302
 	else
6303
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6303
+		$regex = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6304 6304
 
6305 6305
 	// Restore PHP's internal character encoding to whatever it was originally
6306 6306
 	if (!empty($current_encoding))
@@ -6524,7 +6524,7 @@  discard block
 block discarded – undo
6524 6524
 function sanitize_iri($iri)
6525 6525
 {
6526 6526
 	// Encode any non-ASCII characters (but not space or control characters of any sort)
6527
-	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function ($matches) {
6527
+	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function($matches) {
6528 6528
 		return rawurlencode($matches[0]);
6529 6529
 	}, $iri);
6530 6530
 
@@ -6566,7 +6566,7 @@  discard block
 block discarded – undo
6566 6566
 	$unescaped = array(
6567 6567
 		'%21'=>'!', '%23'=>'#', '%24'=>'$', '%26'=>'&',
6568 6568
 		'%27'=>"'", '%28'=>'(', '%29'=>')', '%2A'=>'*',
6569
-		'%2B'=>'+', '%2C'=>',',	'%2F'=>'/', '%3A'=>':',
6569
+		'%2B'=>'+', '%2C'=>',', '%2F'=>'/', '%3A'=>':',
6570 6570
 		'%3B'=>';', '%3D'=>'=', '%3F'=>'?', '%40'=>'@',
6571 6571
 	);
6572 6572
 	$iri = strtr(rawurlencode($iri), $unescaped);
Please login to merge, or discard this patch.
Braces   +1471 added lines, -1100 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
@@ -913,16 +956,19 @@  discard block
 block discarded – undo
913 956
 	static $translation = array();
914 957
 
915 958
 	// Determine the character set... Default to UTF-8
916
-	if (empty($context['character_set']))
917
-		$charset = 'UTF-8';
959
+	if (empty($context['character_set'])) {
960
+			$charset = 'UTF-8';
961
+	}
918 962
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
919
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
920
-		$charset = 'ISO-8859-1';
921
-	else
922
-		$charset = $context['character_set'];
963
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
964
+			$charset = 'ISO-8859-1';
965
+	} else {
966
+			$charset = $context['character_set'];
967
+	}
923 968
 
924
-	if (empty($translation))
925
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	if (empty($translation)) {
970
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
971
+	}
926 972
 
927 973
 	return strtr($string, $translation);
928 974
 }
@@ -944,8 +990,9 @@  discard block
 block discarded – undo
944 990
 	global $smcFunc;
945 991
 
946 992
 	// It was already short enough!
947
-	if ($smcFunc['strlen']($subject) <= $len)
948
-		return $subject;
993
+	if ($smcFunc['strlen']($subject) <= $len) {
994
+			return $subject;
995
+	}
949 996
 
950 997
 	// Shorten it by the length it was too long, and strip off junk from the end.
951 998
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -964,10 +1011,11 @@  discard block
 block discarded – undo
964 1011
 {
965 1012
 	global $user_info, $modSettings;
966 1013
 
967
-	if ($timestamp === null)
968
-		$timestamp = time();
969
-	elseif ($timestamp == 0)
970
-		return 0;
1014
+	if ($timestamp === null) {
1015
+			$timestamp = time();
1016
+	} elseif ($timestamp == 0) {
1017
+			return 0;
1018
+	}
971 1019
 
972 1020
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
973 1021
 }
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 		$array[$i] = $array[$j];
997 1045
 		$array[$j] = $temp;
998 1046
 
999
-		for ($i = 1; $p[$i] == 0; $i++)
1000
-			$p[$i] = 1;
1047
+		for ($i = 1; $p[$i] == 0; $i++) {
1048
+					$p[$i] = 1;
1049
+		}
1001 1050
 
1002 1051
 		$orders[] = $array;
1003 1052
 	}
@@ -1029,12 +1078,14 @@  discard block
 block discarded – undo
1029 1078
 	static $disabled;
1030 1079
 
1031 1080
 	// Don't waste cycles
1032
-	if ($message === '')
1033
-		return '';
1081
+	if ($message === '') {
1082
+			return '';
1083
+	}
1034 1084
 
1035 1085
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1036
-	if (!isset($context['utf8']))
1037
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	if (!isset($context['utf8'])) {
1087
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1088
+	}
1038 1089
 
1039 1090
 	// Clean up any cut/paste issues we may have
1040 1091
 	$message = sanitizeMSCutPaste($message);
@@ -1046,13 +1097,15 @@  discard block
 block discarded – undo
1046 1097
 		return $message;
1047 1098
 	}
1048 1099
 
1049
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1050
-		$smileys = (bool) $smileys;
1100
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1101
+			$smileys = (bool) $smileys;
1102
+	}
1051 1103
 
1052 1104
 	if (empty($modSettings['enableBBC']) && $message !== false)
1053 1105
 	{
1054
-		if ($smileys === true)
1055
-			parsesmileys($message);
1106
+		if ($smileys === true) {
1107
+					parsesmileys($message);
1108
+		}
1056 1109
 
1057 1110
 		return $message;
1058 1111
 	}
@@ -1065,8 +1118,9 @@  discard block
 block discarded – undo
1065 1118
 	}
1066 1119
 
1067 1120
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1068
-	if (!empty($modSettings['autoLinkUrls']))
1069
-		set_tld_regex();
1121
+	if (!empty($modSettings['autoLinkUrls'])) {
1122
+			set_tld_regex();
1123
+	}
1070 1124
 
1071 1125
 	// Allow mods access before entering the main parse_bbc loop
1072 1126
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1080,8 +1134,9 @@  discard block
 block discarded – undo
1080 1134
 
1081 1135
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1082 1136
 
1083
-			foreach ($temp as $tag)
1084
-				$disabled[trim($tag)] = true;
1137
+			foreach ($temp as $tag) {
1138
+							$disabled[trim($tag)] = true;
1139
+			}
1085 1140
 		}
1086 1141
 
1087 1142
 		/* The following bbc are formatted as an array, with keys as follows:
@@ -1211,8 +1266,9 @@  discard block
 block discarded – undo
1211 1266
 					$returnContext = '';
1212 1267
 
1213 1268
 					// BBC or the entire attachments feature is disabled
1214
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1215
-						return $data;
1269
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1270
+											return $data;
1271
+					}
1216 1272
 
1217 1273
 					// Save the attach ID.
1218 1274
 					$attachID = $data;
@@ -1223,8 +1279,9 @@  discard block
 block discarded – undo
1223 1279
 					$currentAttachment = parseAttachBBC($attachID);
1224 1280
 
1225 1281
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1226
-					if (is_string($currentAttachment))
1227
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1282
+					if (is_string($currentAttachment)) {
1283
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1284
+					}
1228 1285
 
1229 1286
 					if (!empty($currentAttachment['is_image']))
1230 1287
 					{
@@ -1240,15 +1297,17 @@  discard block
 block discarded – undo
1240 1297
 							$height = ' height="' . $currentAttachment['height'] . '"';
1241 1298
 						}
1242 1299
 
1243
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1244
-							$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>';
1245
-						else
1246
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1300
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1301
+													$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>';
1302
+						} else {
1303
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1304
+						}
1247 1305
 					}
1248 1306
 
1249 1307
 					// No image. Show a link.
1250
-					else
1251
-						$returnContext .= $currentAttachment['link'];
1308
+					else {
1309
+											$returnContext .= $currentAttachment['link'];
1310
+					}
1252 1311
 
1253 1312
 					// Gotta append what we just did.
1254 1313
 					$data = $returnContext;
@@ -1302,8 +1361,9 @@  discard block
 block discarded – undo
1302 1361
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1303 1362
 						{
1304 1363
 							// Do PHP code coloring?
1305
-							if ($php_parts[$php_i] != '&lt;?php')
1306
-								continue;
1364
+							if ($php_parts[$php_i] != '&lt;?php') {
1365
+															continue;
1366
+							}
1307 1367
 
1308 1368
 							$php_string = '';
1309 1369
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1319,8 +1379,9 @@  discard block
 block discarded – undo
1319 1379
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1320 1380
 
1321 1381
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1322
-						if ($context['browser']['is_opera'])
1323
-							$data .= '&nbsp;';
1382
+						if ($context['browser']['is_opera']) {
1383
+													$data .= '&nbsp;';
1384
+						}
1324 1385
 					}
1325 1386
 				},
1326 1387
 				'block_level' => true,
@@ -1339,8 +1400,9 @@  discard block
 block discarded – undo
1339 1400
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1340 1401
 						{
1341 1402
 							// Do PHP code coloring?
1342
-							if ($php_parts[$php_i] != '&lt;?php')
1343
-								continue;
1403
+							if ($php_parts[$php_i] != '&lt;?php') {
1404
+															continue;
1405
+							}
1344 1406
 
1345 1407
 							$php_string = '';
1346 1408
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1356,8 +1418,9 @@  discard block
 block discarded – undo
1356 1418
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1357 1419
 
1358 1420
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1359
-						if ($context['browser']['is_opera'])
1360
-							$data[0] .= '&nbsp;';
1421
+						if ($context['browser']['is_opera']) {
1422
+													$data[0] .= '&nbsp;';
1423
+						}
1361 1424
 					}
1362 1425
 				},
1363 1426
 				'block_level' => true,
@@ -1398,10 +1461,11 @@  discard block
 block discarded – undo
1398 1461
 				{
1399 1462
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1400 1463
 
1401
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1402
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1403
-					else
1404
-						$css = '';
1464
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1465
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1466
+					} else {
1467
+											$css = '';
1468
+					}
1405 1469
 
1406 1470
 					$data = $class . $css;
1407 1471
 				},
@@ -1416,8 +1480,9 @@  discard block
 block discarded – undo
1416 1480
 				{
1417 1481
 					$data = strtr($data, array('<br />' => ''));
1418 1482
 
1419
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1420
-						$data = 'ftp://' . $data;
1483
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1484
+											$data = 'ftp://' . $data;
1485
+					}
1421 1486
 				},
1422 1487
 			),
1423 1488
 			array(
@@ -1427,8 +1492,9 @@  discard block
 block discarded – undo
1427 1492
 				'after' => '</a>',
1428 1493
 				'validate' => function(&$tag, &$data, $disabled)
1429 1494
 				{
1430
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1431
-						$data = 'ftp://' . $data;
1495
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1496
+											$data = 'ftp://' . $data;
1497
+					}
1432 1498
 				},
1433 1499
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1434 1500
 				'disabled_after' => ' ($1)',
@@ -1488,17 +1554,20 @@  discard block
 block discarded – undo
1488 1554
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1489 1555
 					if ($image_proxy_enabled)
1490 1556
 					{
1491
-						if (!empty($user_info['possibly_robot']))
1492
-							return;
1557
+						if (!empty($user_info['possibly_robot'])) {
1558
+													return;
1559
+						}
1493 1560
 
1494
-						if (empty($scheme))
1495
-							$data = 'http://' . ltrim($data, ':/');
1561
+						if (empty($scheme)) {
1562
+													$data = 'http://' . ltrim($data, ':/');
1563
+						}
1496 1564
 
1497
-						if ($scheme != 'https')
1498
-							$data = get_proxied_url($data);
1565
+						if ($scheme != 'https') {
1566
+													$data = get_proxied_url($data);
1567
+						}
1568
+					} elseif (empty($scheme)) {
1569
+											$data = '//' . ltrim($data, ':/');
1499 1570
 					}
1500
-					elseif (empty($scheme))
1501
-						$data = '//' . ltrim($data, ':/');
1502 1571
 				},
1503 1572
 				'disabled_content' => '($1)',
1504 1573
 			),
@@ -1514,17 +1583,20 @@  discard block
 block discarded – undo
1514 1583
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1515 1584
 					if ($image_proxy_enabled)
1516 1585
 					{
1517
-						if (!empty($user_info['possibly_robot']))
1518
-							return;
1586
+						if (!empty($user_info['possibly_robot'])) {
1587
+													return;
1588
+						}
1519 1589
 
1520
-						if (empty($scheme))
1521
-							$data = 'http://' . ltrim($data, ':/');
1590
+						if (empty($scheme)) {
1591
+													$data = 'http://' . ltrim($data, ':/');
1592
+						}
1522 1593
 
1523
-						if ($scheme != 'https')
1524
-							$data = get_proxied_url($data);
1594
+						if ($scheme != 'https') {
1595
+													$data = get_proxied_url($data);
1596
+						}
1597
+					} elseif (empty($scheme)) {
1598
+											$data = '//' . ltrim($data, ':/');
1525 1599
 					}
1526
-					elseif (empty($scheme))
1527
-						$data = '//' . ltrim($data, ':/');
1528 1600
 				},
1529 1601
 				'disabled_content' => '($1)',
1530 1602
 			),
@@ -1536,8 +1608,9 @@  discard block
 block discarded – undo
1536 1608
 				{
1537 1609
 					$data = strtr($data, array('<br>' => ''));
1538 1610
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1539
-					if (empty($scheme))
1540
-						$data = '//' . ltrim($data, ':/');
1611
+					if (empty($scheme)) {
1612
+											$data = '//' . ltrim($data, ':/');
1613
+					}
1541 1614
 				},
1542 1615
 			),
1543 1616
 			array(
@@ -1548,13 +1621,14 @@  discard block
 block discarded – undo
1548 1621
 				'after' => '</a>',
1549 1622
 				'validate' => function (&$tag, &$data, $disabled)
1550 1623
 				{
1551
-					if (substr($data, 0, 1) == '#')
1552
-						$data = '#post_' . substr($data, 1);
1553
-					else
1624
+					if (substr($data, 0, 1) == '#') {
1625
+											$data = '#post_' . substr($data, 1);
1626
+					} else
1554 1627
 					{
1555 1628
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1556
-						if (empty($scheme))
1557
-							$data = '//' . ltrim($data, ':/');
1629
+						if (empty($scheme)) {
1630
+													$data = '//' . ltrim($data, ':/');
1631
+						}
1558 1632
 					}
1559 1633
 				},
1560 1634
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1645,8 +1719,9 @@  discard block
 block discarded – undo
1645 1719
 					{
1646 1720
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1647 1721
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1648
-						if ($add_begin)
1649
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1722
+						if ($add_begin) {
1723
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1724
+						}
1650 1725
 					}
1651 1726
 				},
1652 1727
 				'block_level' => false,
@@ -1759,20 +1834,17 @@  discard block
 block discarded – undo
1759 1834
 					: function(&$tag, &$data, $disabled)
1760 1835
 					{
1761 1836
 
1762
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1763
-							$data[1] = '0 -2px 1px';
1764
-
1765
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1766
-							$data[1] = '2px 0 1px';
1767
-
1768
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1769
-							$data[1] = '0 2px 1px';
1770
-
1771
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1772
-							$data[1] = '-2px 0 1px';
1773
-
1774
-						else
1775
-							$data[1] = '1px 1px 1px';
1837
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1838
+													$data[1] = '0 -2px 1px';
1839
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1840
+													$data[1] = '2px 0 1px';
1841
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1842
+													$data[1] = '0 2px 1px';
1843
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1844
+													$data[1] = '-2px 0 1px';
1845
+						} else {
1846
+													$data[1] = '1px 1px 1px';
1847
+						}
1776 1848
 					},
1777 1849
 			),
1778 1850
 			array(
@@ -1828,10 +1900,11 @@  discard block
 block discarded – undo
1828 1900
 				'content' => '$1',
1829 1901
 				'validate' => function (&$tag, &$data, $disabled)
1830 1902
 				{
1831
-					if (is_numeric($data))
1832
-						$data = timeformat($data);
1833
-					else
1834
-						$tag['content'] = '[time]$1[/time]';
1903
+					if (is_numeric($data)) {
1904
+											$data = timeformat($data);
1905
+					} else {
1906
+											$tag['content'] = '[time]$1[/time]';
1907
+					}
1835 1908
 				},
1836 1909
 			),
1837 1910
 			array(
@@ -1863,8 +1936,9 @@  discard block
 block discarded – undo
1863 1936
 				{
1864 1937
 					$data = strtr($data, array('<br>' => ''));
1865 1938
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1866
-					if (empty($scheme))
1867
-						$data = '//' . ltrim($data, ':/');
1939
+					if (empty($scheme)) {
1940
+											$data = '//' . ltrim($data, ':/');
1941
+					}
1868 1942
 				},
1869 1943
 			),
1870 1944
 			array(
@@ -1876,8 +1950,9 @@  discard block
 block discarded – undo
1876 1950
 				'validate' => function (&$tag, &$data, $disabled)
1877 1951
 				{
1878 1952
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1879
-					if (empty($scheme))
1880
-						$data = '//' . ltrim($data, ':/');
1953
+					if (empty($scheme)) {
1954
+											$data = '//' . ltrim($data, ':/');
1955
+					}
1881 1956
 				},
1882 1957
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1883 1958
 				'disabled_after' => ' ($1)',
@@ -1897,12 +1972,13 @@  discard block
 block discarded – undo
1897 1972
 		);
1898 1973
 
1899 1974
 		// Handle legacy bbc codes.
1900
-		foreach ($context['legacy_bbc'] as $bbc)
1901
-			$codes[] = array(
1975
+		foreach ($context['legacy_bbc'] as $bbc) {
1976
+					$codes[] = array(
1902 1977
 				'tag' => $bbc,
1903 1978
 				'before' => '',
1904 1979
 				'after' => '',
1905 1980
 			);
1981
+		}
1906 1982
 
1907 1983
 		// Let mods add new BBC without hassle.
1908 1984
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1910,8 +1986,9 @@  discard block
 block discarded – undo
1910 1986
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1911 1987
 		if ($message === false)
1912 1988
 		{
1913
-			if (isset($temp_bbc))
1914
-				$bbc_codes = $temp_bbc;
1989
+			if (isset($temp_bbc)) {
1990
+							$bbc_codes = $temp_bbc;
1991
+			}
1915 1992
 			usort($codes, function ($a, $b) {
1916 1993
 				return strcmp($a['tag'], $b['tag']);
1917 1994
 			});
@@ -1931,8 +2008,9 @@  discard block
 block discarded – undo
1931 2008
 		);
1932 2009
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1933 2010
 		{
1934
-			foreach ($itemcodes as $c => $dummy)
1935
-				$bbc_codes[$c] = array();
2011
+			foreach ($itemcodes as $c => $dummy) {
2012
+							$bbc_codes[$c] = array();
2013
+			}
1936 2014
 		}
1937 2015
 
1938 2016
 		// Shhhh!
@@ -1953,12 +2031,14 @@  discard block
 block discarded – undo
1953 2031
 		foreach ($codes as $code)
1954 2032
 		{
1955 2033
 			// Make it easier to process parameters later
1956
-			if (!empty($code['parameters']))
1957
-				ksort($code['parameters'], SORT_STRING);
2034
+			if (!empty($code['parameters'])) {
2035
+							ksort($code['parameters'], SORT_STRING);
2036
+			}
1958 2037
 
1959 2038
 			// If we are not doing every tag only do ones we are interested in.
1960
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1961
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2039
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2040
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2041
+			}
1962 2042
 		}
1963 2043
 		$codes = null;
1964 2044
 	}
@@ -1969,8 +2049,9 @@  discard block
 block discarded – undo
1969 2049
 		// It's likely this will change if the message is modified.
1970 2050
 		$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']);
1971 2051
 
1972
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1973
-			return $temp;
2052
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2053
+					return $temp;
2054
+		}
1974 2055
 
1975 2056
 		$cache_t = microtime();
1976 2057
 	}
@@ -2002,8 +2083,9 @@  discard block
 block discarded – undo
2002 2083
 		$disabled['flash'] = true;
2003 2084
 
2004 2085
 		// @todo Change maybe?
2005
-		if (!isset($_GET['images']))
2006
-			$disabled['img'] = true;
2086
+		if (!isset($_GET['images'])) {
2087
+					$disabled['img'] = true;
2088
+		}
2007 2089
 
2008 2090
 		// @todo Interface/setting to add more?
2009 2091
 	}
@@ -2014,8 +2096,9 @@  discard block
 block discarded – undo
2014 2096
 	$alltags = array();
2015 2097
 	foreach ($bbc_codes as $section)
2016 2098
 	{
2017
-		foreach ($section as $code)
2018
-			$alltags[] = $code['tag'];
2099
+		foreach ($section as $code) {
2100
+					$alltags[] = $code['tag'];
2101
+		}
2019 2102
 	}
2020 2103
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2021 2104
 
@@ -2027,8 +2110,9 @@  discard block
 block discarded – undo
2027 2110
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2028 2111
 
2029 2112
 		// Failsafe.
2030
-		if ($pos === false || $last_pos > $pos)
2031
-			$pos = strlen($message) + 1;
2113
+		if ($pos === false || $last_pos > $pos) {
2114
+					$pos = strlen($message) + 1;
2115
+		}
2032 2116
 
2033 2117
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2034 2118
 		if ($last_pos < $pos - 1)
@@ -2046,8 +2130,9 @@  discard block
 block discarded – undo
2046 2130
 
2047 2131
 				// <br> should be empty.
2048 2132
 				$empty_tags = array('br', 'hr');
2049
-				foreach ($empty_tags as $tag)
2050
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2133
+				foreach ($empty_tags as $tag) {
2134
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2135
+				}
2051 2136
 
2052 2137
 				// b, u, i, s, pre... basic tags.
2053 2138
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2056,8 +2141,9 @@  discard block
 block discarded – undo
2056 2141
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2057 2142
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2058 2143
 
2059
-					if ($diff > 0)
2060
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2144
+					if ($diff > 0) {
2145
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2146
+					}
2061 2147
 				}
2062 2148
 
2063 2149
 				// Do <img ...> - with security... action= -> action-.
@@ -2070,8 +2156,9 @@  discard block
 block discarded – undo
2070 2156
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2071 2157
 
2072 2158
 						// Remove action= from the URL - no funny business, now.
2073
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2074
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2159
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2160
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2161
+						}
2075 2162
 
2076 2163
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2077 2164
 					}
@@ -2086,16 +2173,18 @@  discard block
 block discarded – undo
2086 2173
 				$no_autolink_area = false;
2087 2174
 				if (!empty($open_tags))
2088 2175
 				{
2089
-					foreach ($open_tags as $open_tag)
2090
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2176
+					foreach ($open_tags as $open_tag) {
2177
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2091 2178
 							$no_autolink_area = true;
2179
+					}
2092 2180
 				}
2093 2181
 
2094 2182
 				// Don't go backwards.
2095 2183
 				// @todo Don't think is the real solution....
2096 2184
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2097
-				if ($pos < $lastAutoPos)
2098
-					$no_autolink_area = true;
2185
+				if ($pos < $lastAutoPos) {
2186
+									$no_autolink_area = true;
2187
+				}
2099 2188
 				$lastAutoPos = $pos;
2100 2189
 
2101 2190
 				if (!$no_autolink_area)
@@ -2200,29 +2289,33 @@  discard block
 block discarded – undo
2200 2289
 							$url = array_shift($matches);
2201 2290
 
2202 2291
 							// If this isn't a clean URL, bail out
2203
-							if ($url != sanitize_iri($url))
2204
-								return $url;
2292
+							if ($url != sanitize_iri($url)) {
2293
+															return $url;
2294
+							}
2205 2295
 
2206 2296
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2207 2297
 
2208 2298
 							if ($scheme == 'mailto')
2209 2299
 							{
2210 2300
 								$email_address = str_replace('mailto:', '', $url);
2211
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2212
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2213
-								else
2214
-									return $url;
2301
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2302
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2303
+								} else {
2304
+																	return $url;
2305
+								}
2215 2306
 							}
2216 2307
 
2217 2308
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2218
-							if (empty($scheme))
2219
-								$fullUrl = '//' . ltrim($url, ':/');
2220
-							else
2221
-								$fullUrl = $url;
2309
+							if (empty($scheme)) {
2310
+															$fullUrl = '//' . ltrim($url, ':/');
2311
+							} else {
2312
+															$fullUrl = $url;
2313
+							}
2222 2314
 
2223 2315
 							// Make sure that $fullUrl really is valid
2224
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2225
-								return $url;
2316
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2317
+															return $url;
2318
+							}
2226 2319
 
2227 2320
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2228 2321
 						}, $data);
@@ -2271,22 +2364,25 @@  discard block
 block discarded – undo
2271 2364
 		}
2272 2365
 
2273 2366
 		// Are we there yet?  Are we there yet?
2274
-		if ($pos >= strlen($message) - 1)
2275
-			break;
2367
+		if ($pos >= strlen($message) - 1) {
2368
+					break;
2369
+		}
2276 2370
 
2277 2371
 		$tags = strtolower($message[$pos + 1]);
2278 2372
 
2279 2373
 		if ($tags == '/' && !empty($open_tags))
2280 2374
 		{
2281 2375
 			$pos2 = strpos($message, ']', $pos + 1);
2282
-			if ($pos2 == $pos + 2)
2283
-				continue;
2376
+			if ($pos2 == $pos + 2) {
2377
+							continue;
2378
+			}
2284 2379
 
2285 2380
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2286 2381
 
2287 2382
 			// A closing tag that doesn't match any open tags? Skip it.
2288
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2289
-				continue;
2383
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2384
+							continue;
2385
+			}
2290 2386
 
2291 2387
 			$to_close = array();
2292 2388
 			$block_level = null;
@@ -2294,8 +2390,9 @@  discard block
 block discarded – undo
2294 2390
 			do
2295 2391
 			{
2296 2392
 				$tag = array_pop($open_tags);
2297
-				if (!$tag)
2298
-					break;
2393
+				if (!$tag) {
2394
+									break;
2395
+				}
2299 2396
 
2300 2397
 				if (!empty($tag['block_level']))
2301 2398
 				{
@@ -2309,10 +2406,11 @@  discard block
 block discarded – undo
2309 2406
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2310 2407
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2311 2408
 					{
2312
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2313
-							if ($temp['tag'] == $look_for)
2409
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2410
+													if ($temp['tag'] == $look_for)
2314 2411
 							{
2315 2412
 								$block_level = !empty($temp['block_level']);
2413
+						}
2316 2414
 								break;
2317 2415
 							}
2318 2416
 					}
@@ -2334,15 +2432,15 @@  discard block
 block discarded – undo
2334 2432
 			{
2335 2433
 				$open_tags = $to_close;
2336 2434
 				continue;
2337
-			}
2338
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2435
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2339 2436
 			{
2340 2437
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2341 2438
 				{
2342
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2343
-						if ($temp['tag'] == $look_for)
2439
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2440
+											if ($temp['tag'] == $look_for)
2344 2441
 						{
2345 2442
 							$block_level = !empty($temp['block_level']);
2443
+					}
2346 2444
 							break;
2347 2445
 						}
2348 2446
 				}
@@ -2350,8 +2448,9 @@  discard block
 block discarded – undo
2350 2448
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2351 2449
 				if (!$block_level)
2352 2450
 				{
2353
-					foreach ($to_close as $tag)
2354
-						array_push($open_tags, $tag);
2451
+					foreach ($to_close as $tag) {
2452
+											array_push($open_tags, $tag);
2453
+					}
2355 2454
 					continue;
2356 2455
 				}
2357 2456
 			}
@@ -2364,14 +2463,17 @@  discard block
 block discarded – undo
2364 2463
 
2365 2464
 				// See the comment at the end of the big loop - just eating whitespace ;).
2366 2465
 				$whitespace_regex = '';
2367
-				if (!empty($tag['block_level']))
2368
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2466
+				if (!empty($tag['block_level'])) {
2467
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2468
+				}
2369 2469
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2370
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2371
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2470
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2471
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2472
+				}
2372 2473
 
2373
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2374
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2474
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2475
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2476
+				}
2375 2477
 			}
2376 2478
 
2377 2479
 			if (!empty($to_close))
@@ -2384,8 +2486,9 @@  discard block
 block discarded – undo
2384 2486
 		}
2385 2487
 
2386 2488
 		// No tags for this character, so just keep going (fastest possible course.)
2387
-		if (!isset($bbc_codes[$tags]))
2388
-			continue;
2489
+		if (!isset($bbc_codes[$tags])) {
2490
+					continue;
2491
+		}
2389 2492
 
2390 2493
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2391 2494
 		$tag = null;
@@ -2394,48 +2497,57 @@  discard block
 block discarded – undo
2394 2497
 			$pt_strlen = strlen($possible['tag']);
2395 2498
 
2396 2499
 			// Not a match?
2397
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2398
-				continue;
2500
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2501
+							continue;
2502
+			}
2399 2503
 
2400 2504
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2401 2505
 
2402 2506
 			// A tag is the last char maybe
2403
-			if ($next_c == '')
2404
-				break;
2507
+			if ($next_c == '') {
2508
+							break;
2509
+			}
2405 2510
 
2406 2511
 			// A test validation?
2407
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2408
-				continue;
2512
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2513
+							continue;
2514
+			}
2409 2515
 			// Do we want parameters?
2410 2516
 			elseif (!empty($possible['parameters']))
2411 2517
 			{
2412
-				if ($next_c != ' ')
2413
-					continue;
2414
-			}
2415
-			elseif (isset($possible['type']))
2518
+				if ($next_c != ' ') {
2519
+									continue;
2520
+				}
2521
+			} elseif (isset($possible['type']))
2416 2522
 			{
2417 2523
 				// Do we need an equal sign?
2418
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2419
-					continue;
2524
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2525
+									continue;
2526
+				}
2420 2527
 				// Maybe we just want a /...
2421
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2422
-					continue;
2528
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2529
+									continue;
2530
+				}
2423 2531
 				// An immediate ]?
2424
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2425
-					continue;
2532
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2533
+									continue;
2534
+				}
2426 2535
 			}
2427 2536
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2428
-			elseif ($next_c != ']')
2429
-				continue;
2537
+			elseif ($next_c != ']') {
2538
+							continue;
2539
+			}
2430 2540
 
2431 2541
 			// Check allowed tree?
2432
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2433
-				continue;
2434
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2435
-				continue;
2542
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2543
+							continue;
2544
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2545
+							continue;
2546
+			}
2436 2547
 			// If this is in the list of disallowed child tags, don't parse it.
2437
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2438
-				continue;
2548
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2549
+							continue;
2550
+			}
2439 2551
 
2440 2552
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2441 2553
 
@@ -2447,8 +2559,9 @@  discard block
 block discarded – undo
2447 2559
 				foreach ($open_tags as $open_quote)
2448 2560
 				{
2449 2561
 					// Every parent quote this quote has flips the styling
2450
-					if ($open_quote['tag'] == 'quote')
2451
-						$quote_alt = !$quote_alt;
2562
+					if ($open_quote['tag'] == 'quote') {
2563
+											$quote_alt = !$quote_alt;
2564
+					}
2452 2565
 				}
2453 2566
 				// Add a class to the quote to style alternating blockquotes
2454 2567
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2459,8 +2572,9 @@  discard block
 block discarded – undo
2459 2572
 			{
2460 2573
 				// Build a regular expression for each parameter for the current tag.
2461 2574
 				$preg = array();
2462
-				foreach ($possible['parameters'] as $p => $info)
2463
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2575
+				foreach ($possible['parameters'] as $p => $info) {
2576
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2577
+				}
2464 2578
 
2465 2579
 				// Extract the string that potentially holds our parameters.
2466 2580
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2479,24 +2593,27 @@  discard block
 block discarded – undo
2479 2593
 
2480 2594
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2481 2595
 
2482
-					if ($match)
2483
-						$blob_counter = count($blobs) + 1;
2596
+					if ($match) {
2597
+											$blob_counter = count($blobs) + 1;
2598
+					}
2484 2599
 				}
2485 2600
 
2486 2601
 				// Didn't match our parameter list, try the next possible.
2487
-				if (!$match)
2488
-					continue;
2602
+				if (!$match) {
2603
+									continue;
2604
+				}
2489 2605
 
2490 2606
 				$params = array();
2491 2607
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2492 2608
 				{
2493 2609
 					$key = strtok(ltrim($matches[$i]), '=');
2494
-					if (isset($possible['parameters'][$key]['value']))
2495
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2496
-					elseif (isset($possible['parameters'][$key]['validate']))
2497
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2498
-					else
2499
-						$params['{' . $key . '}'] = $matches[$i + 1];
2610
+					if (isset($possible['parameters'][$key]['value'])) {
2611
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2612
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2613
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2614
+					} else {
2615
+											$params['{' . $key . '}'] = $matches[$i + 1];
2616
+					}
2500 2617
 
2501 2618
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2502 2619
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2504,23 +2621,26 @@  discard block
 block discarded – undo
2504 2621
 
2505 2622
 				foreach ($possible['parameters'] as $p => $info)
2506 2623
 				{
2507
-					if (!isset($params['{' . $p . '}']))
2508
-						$params['{' . $p . '}'] = '';
2624
+					if (!isset($params['{' . $p . '}'])) {
2625
+											$params['{' . $p . '}'] = '';
2626
+					}
2509 2627
 				}
2510 2628
 
2511 2629
 				$tag = $possible;
2512 2630
 
2513 2631
 				// Put the parameters into the string.
2514
-				if (isset($tag['before']))
2515
-					$tag['before'] = strtr($tag['before'], $params);
2516
-				if (isset($tag['after']))
2517
-					$tag['after'] = strtr($tag['after'], $params);
2518
-				if (isset($tag['content']))
2519
-					$tag['content'] = strtr($tag['content'], $params);
2632
+				if (isset($tag['before'])) {
2633
+									$tag['before'] = strtr($tag['before'], $params);
2634
+				}
2635
+				if (isset($tag['after'])) {
2636
+									$tag['after'] = strtr($tag['after'], $params);
2637
+				}
2638
+				if (isset($tag['content'])) {
2639
+									$tag['content'] = strtr($tag['content'], $params);
2640
+				}
2520 2641
 
2521 2642
 				$pos1 += strlen($given_param_string);
2522
-			}
2523
-			else
2643
+			} else
2524 2644
 			{
2525 2645
 				$tag = $possible;
2526 2646
 				$params = array();
@@ -2531,8 +2651,9 @@  discard block
 block discarded – undo
2531 2651
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2532 2652
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2533 2653
 		{
2534
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2535
-				continue;
2654
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2655
+							continue;
2656
+			}
2536 2657
 
2537 2658
 			$tag = $itemcodes[$message[$pos + 1]];
2538 2659
 
@@ -2553,9 +2674,9 @@  discard block
 block discarded – undo
2553 2674
 			{
2554 2675
 				array_pop($open_tags);
2555 2676
 				$code = '</li>';
2677
+			} else {
2678
+							$code = '';
2556 2679
 			}
2557
-			else
2558
-				$code = '';
2559 2680
 
2560 2681
 			// Now we open a new tag.
2561 2682
 			$open_tags[] = array(
@@ -2602,12 +2723,14 @@  discard block
 block discarded – undo
2602 2723
 		}
2603 2724
 
2604 2725
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2605
-		if ($tag === null)
2606
-			continue;
2726
+		if ($tag === null) {
2727
+					continue;
2728
+		}
2607 2729
 
2608 2730
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2609
-		if (isset($inside['disallow_children']))
2610
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2731
+		if (isset($inside['disallow_children'])) {
2732
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2733
+		}
2611 2734
 
2612 2735
 		// Is this tag disabled?
2613 2736
 		if (isset($disabled[$tag['tag']]))
@@ -2617,14 +2740,13 @@  discard block
 block discarded – undo
2617 2740
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2618 2741
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2619 2742
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2620
-			}
2621
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2743
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2622 2744
 			{
2623 2745
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2624 2746
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2747
+			} else {
2748
+							$tag['content'] = $tag['disabled_content'];
2625 2749
 			}
2626
-			else
2627
-				$tag['content'] = $tag['disabled_content'];
2628 2750
 		}
2629 2751
 
2630 2752
 		// we use this a lot
@@ -2634,8 +2756,9 @@  discard block
 block discarded – undo
2634 2756
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2635 2757
 		{
2636 2758
 			$n = count($open_tags) - 1;
2637
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2638
-				$n--;
2759
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2760
+							$n--;
2761
+			}
2639 2762
 
2640 2763
 			// Close all the non block level tags so this tag isn't surrounded by them.
2641 2764
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2647,12 +2770,15 @@  discard block
 block discarded – undo
2647 2770
 
2648 2771
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2649 2772
 				$whitespace_regex = '';
2650
-				if (!empty($tag['block_level']))
2651
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2652
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2653
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2654
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2655
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2773
+				if (!empty($tag['block_level'])) {
2774
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2775
+				}
2776
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2777
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2778
+				}
2779
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2780
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2781
+				}
2656 2782
 
2657 2783
 				array_pop($open_tags);
2658 2784
 			}
@@ -2673,16 +2799,19 @@  discard block
 block discarded – undo
2673 2799
 		elseif ($tag['type'] == 'unparsed_content')
2674 2800
 		{
2675 2801
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2676
-			if ($pos2 === false)
2677
-				continue;
2802
+			if ($pos2 === false) {
2803
+							continue;
2804
+			}
2678 2805
 
2679 2806
 			$data = substr($message, $pos1, $pos2 - $pos1);
2680 2807
 
2681
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2682
-				$data = substr($data, 4);
2808
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2809
+							$data = substr($data, 4);
2810
+			}
2683 2811
 
2684
-			if (isset($tag['validate']))
2685
-				$tag['validate']($tag, $data, $disabled, $params);
2812
+			if (isset($tag['validate'])) {
2813
+							$tag['validate']($tag, $data, $disabled, $params);
2814
+			}
2686 2815
 
2687 2816
 			$code = strtr($tag['content'], array('$1' => $data));
2688 2817
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2697,34 +2826,40 @@  discard block
 block discarded – undo
2697 2826
 			if (isset($tag['quoted']))
2698 2827
 			{
2699 2828
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2700
-				if ($tag['quoted'] != 'optional' && !$quoted)
2701
-					continue;
2829
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2830
+									continue;
2831
+				}
2702 2832
 
2703
-				if ($quoted)
2704
-					$pos1 += 6;
2833
+				if ($quoted) {
2834
+									$pos1 += 6;
2835
+				}
2836
+			} else {
2837
+							$quoted = false;
2705 2838
 			}
2706
-			else
2707
-				$quoted = false;
2708 2839
 
2709 2840
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2710
-			if ($pos2 === false)
2711
-				continue;
2841
+			if ($pos2 === false) {
2842
+							continue;
2843
+			}
2712 2844
 
2713 2845
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2714
-			if ($pos3 === false)
2715
-				continue;
2846
+			if ($pos3 === false) {
2847
+							continue;
2848
+			}
2716 2849
 
2717 2850
 			$data = array(
2718 2851
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2719 2852
 				substr($message, $pos1, $pos2 - $pos1)
2720 2853
 			);
2721 2854
 
2722
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2723
-				$data[0] = substr($data[0], 4);
2855
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2856
+							$data[0] = substr($data[0], 4);
2857
+			}
2724 2858
 
2725 2859
 			// Validation for my parking, please!
2726
-			if (isset($tag['validate']))
2727
-				$tag['validate']($tag, $data, $disabled, $params);
2860
+			if (isset($tag['validate'])) {
2861
+							$tag['validate']($tag, $data, $disabled, $params);
2862
+			}
2728 2863
 
2729 2864
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2730 2865
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2741,23 +2876,27 @@  discard block
 block discarded – undo
2741 2876
 		elseif ($tag['type'] == 'unparsed_commas_content')
2742 2877
 		{
2743 2878
 			$pos2 = strpos($message, ']', $pos1);
2744
-			if ($pos2 === false)
2745
-				continue;
2879
+			if ($pos2 === false) {
2880
+							continue;
2881
+			}
2746 2882
 
2747 2883
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2748
-			if ($pos3 === false)
2749
-				continue;
2884
+			if ($pos3 === false) {
2885
+							continue;
2886
+			}
2750 2887
 
2751 2888
 			// We want $1 to be the content, and the rest to be csv.
2752 2889
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2753 2890
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2754 2891
 
2755
-			if (isset($tag['validate']))
2756
-				$tag['validate']($tag, $data, $disabled, $params);
2892
+			if (isset($tag['validate'])) {
2893
+							$tag['validate']($tag, $data, $disabled, $params);
2894
+			}
2757 2895
 
2758 2896
 			$code = $tag['content'];
2759
-			foreach ($data as $k => $d)
2760
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2897
+			foreach ($data as $k => $d) {
2898
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2899
+			}
2761 2900
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2762 2901
 			$pos += strlen($code) - 1 + 2;
2763 2902
 		}
@@ -2765,24 +2904,28 @@  discard block
 block discarded – undo
2765 2904
 		elseif ($tag['type'] == 'unparsed_commas')
2766 2905
 		{
2767 2906
 			$pos2 = strpos($message, ']', $pos1);
2768
-			if ($pos2 === false)
2769
-				continue;
2907
+			if ($pos2 === false) {
2908
+							continue;
2909
+			}
2770 2910
 
2771 2911
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2772 2912
 
2773
-			if (isset($tag['validate']))
2774
-				$tag['validate']($tag, $data, $disabled, $params);
2913
+			if (isset($tag['validate'])) {
2914
+							$tag['validate']($tag, $data, $disabled, $params);
2915
+			}
2775 2916
 
2776 2917
 			// Fix after, for disabled code mainly.
2777
-			foreach ($data as $k => $d)
2778
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2918
+			foreach ($data as $k => $d) {
2919
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2920
+			}
2779 2921
 
2780 2922
 			$open_tags[] = $tag;
2781 2923
 
2782 2924
 			// Replace them out, $1, $2, $3, $4, etc.
2783 2925
 			$code = $tag['before'];
2784
-			foreach ($data as $k => $d)
2785
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2926
+			foreach ($data as $k => $d) {
2927
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2928
+			}
2786 2929
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2787 2930
 			$pos += strlen($code) - 1 + 2;
2788 2931
 		}
@@ -2793,28 +2936,33 @@  discard block
 block discarded – undo
2793 2936
 			if (isset($tag['quoted']))
2794 2937
 			{
2795 2938
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2796
-				if ($tag['quoted'] != 'optional' && !$quoted)
2797
-					continue;
2939
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2940
+									continue;
2941
+				}
2798 2942
 
2799
-				if ($quoted)
2800
-					$pos1 += 6;
2943
+				if ($quoted) {
2944
+									$pos1 += 6;
2945
+				}
2946
+			} else {
2947
+							$quoted = false;
2801 2948
 			}
2802
-			else
2803
-				$quoted = false;
2804 2949
 
2805 2950
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2806
-			if ($pos2 === false)
2807
-				continue;
2951
+			if ($pos2 === false) {
2952
+							continue;
2953
+			}
2808 2954
 
2809 2955
 			$data = substr($message, $pos1, $pos2 - $pos1);
2810 2956
 
2811 2957
 			// Validation for my parking, please!
2812
-			if (isset($tag['validate']))
2813
-				$tag['validate']($tag, $data, $disabled, $params);
2958
+			if (isset($tag['validate'])) {
2959
+							$tag['validate']($tag, $data, $disabled, $params);
2960
+			}
2814 2961
 
2815 2962
 			// For parsed content, we must recurse to avoid security problems.
2816
-			if ($tag['type'] != 'unparsed_equals')
2817
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2963
+			if ($tag['type'] != 'unparsed_equals') {
2964
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2965
+			}
2818 2966
 
2819 2967
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2820 2968
 
@@ -2826,34 +2974,40 @@  discard block
 block discarded – undo
2826 2974
 		}
2827 2975
 
2828 2976
 		// If this is block level, eat any breaks after it.
2829
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2830
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2977
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2978
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2979
+		}
2831 2980
 
2832 2981
 		// Are we trimming outside this tag?
2833
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2834
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2982
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2983
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2984
+		}
2835 2985
 	}
2836 2986
 
2837 2987
 	// Close any remaining tags.
2838
-	while ($tag = array_pop($open_tags))
2839
-		$message .= "\n" . $tag['after'] . "\n";
2988
+	while ($tag = array_pop($open_tags)) {
2989
+			$message .= "\n" . $tag['after'] . "\n";
2990
+	}
2840 2991
 
2841 2992
 	// Parse the smileys within the parts where it can be done safely.
2842 2993
 	if ($smileys === true)
2843 2994
 	{
2844 2995
 		$message_parts = explode("\n", $message);
2845
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2846
-			parsesmileys($message_parts[$i]);
2996
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2997
+					parsesmileys($message_parts[$i]);
2998
+		}
2847 2999
 
2848 3000
 		$message = implode('', $message_parts);
2849 3001
 	}
2850 3002
 
2851 3003
 	// No smileys, just get rid of the markers.
2852
-	else
2853
-		$message = strtr($message, array("\n" => ''));
3004
+	else {
3005
+			$message = strtr($message, array("\n" => ''));
3006
+	}
2854 3007
 
2855
-	if ($message !== '' && $message[0] === ' ')
2856
-		$message = '&nbsp;' . substr($message, 1);
3008
+	if ($message !== '' && $message[0] === ' ') {
3009
+			$message = '&nbsp;' . substr($message, 1);
3010
+	}
2857 3011
 
2858 3012
 	// Cleanup whitespace.
2859 3013
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2862,15 +3016,16 @@  discard block
 block discarded – undo
2862 3016
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2863 3017
 
2864 3018
 	// Cache the output if it took some time...
2865
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2866
-		cache_put_data($cache_key, $message, 240);
3019
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3020
+			cache_put_data($cache_key, $message, 240);
3021
+	}
2867 3022
 
2868 3023
 	// If this was a force parse revert if needed.
2869 3024
 	if (!empty($parse_tags))
2870 3025
 	{
2871
-		if (empty($temp_bbc))
2872
-			$bbc_codes = array();
2873
-		else
3026
+		if (empty($temp_bbc)) {
3027
+					$bbc_codes = array();
3028
+		} else
2874 3029
 		{
2875 3030
 			$bbc_codes = $temp_bbc;
2876 3031
 			unset($temp_bbc);
@@ -2897,8 +3052,9 @@  discard block
 block discarded – undo
2897 3052
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2898 3053
 
2899 3054
 	// No smiley set at all?!
2900
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2901
-		return;
3055
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3056
+			return;
3057
+	}
2902 3058
 
2903 3059
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2904 3060
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2912,8 +3068,7 @@  discard block
 block discarded – undo
2912 3068
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2913 3069
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2914 3070
 			$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'], '', '', '', '');
2915
-		}
2916
-		else
3071
+		} else
2917 3072
 		{
2918 3073
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2919 3074
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2937,9 +3092,9 @@  discard block
 block discarded – undo
2937 3092
 				$smcFunc['db_free_result']($result);
2938 3093
 
2939 3094
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3095
+			} else {
3096
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2940 3097
 			}
2941
-			else
2942
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2943 3098
 		}
2944 3099
 
2945 3100
 		// The non-breaking-space is a complex thing...
@@ -2961,16 +3116,18 @@  discard block
 block discarded – undo
2961 3116
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2962 3117
 				if (!empty($alt_images))
2963 3118
 				{
2964
-					foreach ($exts as $ext)
2965
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3119
+					foreach ($exts as $ext) {
3120
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2966 3121
 						{
2967 3122
 							$smileysto[$i] = $fname . '.' . $ext;
3123
+					}
2968 3124
 							break;
2969 3125
 						}
2970 3126
 				}
2971 3127
 				// If we have no image, just leave the text version in place
2972
-				else
2973
-					continue;
3128
+				else {
3129
+									continue;
3130
+				}
2974 3131
 			}
2975 3132
 
2976 3133
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3038,12 +3195,14 @@  discard block
 block discarded – undo
3038 3195
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3039 3196
 
3040 3197
 	// Only use the proxy if enabled and necessary
3041
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3042
-		return $url;
3198
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3199
+			return $url;
3200
+	}
3043 3201
 
3044 3202
 	// We don't need to proxy our own resources
3045
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3046
-		return strtr($url, array('http://' => 'https://'));
3203
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3204
+			return strtr($url, array('http://' => 'https://'));
3205
+	}
3047 3206
 
3048 3207
 	// By default, use SMF's own image proxy script
3049 3208
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3068,35 +3227,41 @@  discard block
 block discarded – undo
3068 3227
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3069 3228
 
3070 3229
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3071
-	if (!empty($context['flush_mail']))
3072
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3230
+	if (!empty($context['flush_mail'])) {
3231
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3073 3232
 		AddMailQueue(true);
3233
+	}
3074 3234
 
3075 3235
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3076 3236
 
3077
-	if ($add)
3078
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3237
+	if ($add) {
3238
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3239
+	}
3079 3240
 
3080 3241
 	// Put the session ID in.
3081
-	if (defined('SID') && SID != '')
3082
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3242
+	if (defined('SID') && SID != '') {
3243
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3244
+	}
3083 3245
 	// Keep that debug in their for template debugging!
3084
-	elseif (isset($_GET['debug']))
3085
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3246
+	elseif (isset($_GET['debug'])) {
3247
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3248
+	}
3086 3249
 
3087 3250
 	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'])))
3088 3251
 	{
3089
-		if (defined('SID') && SID != '')
3090
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3252
+		if (defined('SID') && SID != '') {
3253
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3091 3254
 				function ($m) use ($scripturl)
3092 3255
 				{
3093 3256
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3257
+		}
3094 3258
 				}, $setLocation);
3095
-		else
3096
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3259
+		else {
3260
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3097 3261
 				function ($m) use ($scripturl)
3098 3262
 				{
3099 3263
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3264
+		}
3100 3265
 				}, $setLocation);
3101 3266
 	}
3102 3267
 
@@ -3107,8 +3272,9 @@  discard block
 block discarded – undo
3107 3272
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3108 3273
 
3109 3274
 	// Debugging.
3110
-	if (isset($db_show_debug) && $db_show_debug === true)
3111
-		$_SESSION['debug_redirect'] = $db_cache;
3275
+	if (isset($db_show_debug) && $db_show_debug === true) {
3276
+			$_SESSION['debug_redirect'] = $db_cache;
3277
+	}
3112 3278
 
3113 3279
 	obExit(false);
3114 3280
 }
@@ -3127,51 +3293,60 @@  discard block
 block discarded – undo
3127 3293
 
3128 3294
 	// Attempt to prevent a recursive loop.
3129 3295
 	++$level;
3130
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3131
-		exit;
3132
-	if ($from_fatal_error)
3133
-		$has_fatal_error = true;
3296
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3297
+			exit;
3298
+	}
3299
+	if ($from_fatal_error) {
3300
+			$has_fatal_error = true;
3301
+	}
3134 3302
 
3135 3303
 	// Clear out the stat cache.
3136 3304
 	trackStats();
3137 3305
 
3138 3306
 	// If we have mail to send, send it.
3139
-	if (!empty($context['flush_mail']))
3140
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3307
+	if (!empty($context['flush_mail'])) {
3308
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3141 3309
 		AddMailQueue(true);
3310
+	}
3142 3311
 
3143 3312
 	$do_header = $header === null ? !$header_done : $header;
3144
-	if ($do_footer === null)
3145
-		$do_footer = $do_header;
3313
+	if ($do_footer === null) {
3314
+			$do_footer = $do_header;
3315
+	}
3146 3316
 
3147 3317
 	// Has the template/header been done yet?
3148 3318
 	if ($do_header)
3149 3319
 	{
3150 3320
 		// Was the page title set last minute? Also update the HTML safe one.
3151
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3152
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3321
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3322
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3323
+		}
3153 3324
 
3154 3325
 		// Start up the session URL fixer.
3155 3326
 		ob_start('ob_sessrewrite');
3156 3327
 
3157
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3158
-			$buffers = explode(',', $settings['output_buffers']);
3159
-		elseif (!empty($settings['output_buffers']))
3160
-			$buffers = $settings['output_buffers'];
3161
-		else
3162
-			$buffers = array();
3328
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3329
+					$buffers = explode(',', $settings['output_buffers']);
3330
+		} elseif (!empty($settings['output_buffers'])) {
3331
+					$buffers = $settings['output_buffers'];
3332
+		} else {
3333
+					$buffers = array();
3334
+		}
3163 3335
 
3164
-		if (isset($modSettings['integrate_buffer']))
3165
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3336
+		if (isset($modSettings['integrate_buffer'])) {
3337
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3338
+		}
3166 3339
 
3167
-		if (!empty($buffers))
3168
-			foreach ($buffers as $function)
3340
+		if (!empty($buffers)) {
3341
+					foreach ($buffers as $function)
3169 3342
 			{
3170 3343
 				$call = call_helper($function, true);
3344
+		}
3171 3345
 
3172 3346
 				// Is it valid?
3173
-				if (!empty($call))
3174
-					ob_start($call);
3347
+				if (!empty($call)) {
3348
+									ob_start($call);
3349
+				}
3175 3350
 			}
3176 3351
 
3177 3352
 		// Display the screen in the logical order.
@@ -3183,8 +3358,9 @@  discard block
 block discarded – undo
3183 3358
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3184 3359
 
3185 3360
 		// Anything special to put out?
3186
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3187
-			echo $context['insert_after_template'];
3361
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3362
+					echo $context['insert_after_template'];
3363
+		}
3188 3364
 
3189 3365
 		// Just so we don't get caught in an endless loop of errors from the footer...
3190 3366
 		if (!$footer_done)
@@ -3193,14 +3369,16 @@  discard block
 block discarded – undo
3193 3369
 			template_footer();
3194 3370
 
3195 3371
 			// (since this is just debugging... it's okay that it's after </html>.)
3196
-			if (!isset($_REQUEST['xml']))
3197
-				displayDebug();
3372
+			if (!isset($_REQUEST['xml'])) {
3373
+							displayDebug();
3374
+			}
3198 3375
 		}
3199 3376
 	}
3200 3377
 
3201 3378
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3202
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3203
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3379
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3380
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3381
+	}
3204 3382
 
3205 3383
 	// For session check verification.... don't switch browsers...
3206 3384
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3209,9 +3387,10 @@  discard block
 block discarded – undo
3209 3387
 	call_integration_hook('integrate_exit', array($do_footer));
3210 3388
 
3211 3389
 	// Don't exit if we're coming from index.php; that will pass through normally.
3212
-	if (!$from_index)
3213
-		exit;
3214
-}
3390
+	if (!$from_index) {
3391
+			exit;
3392
+	}
3393
+	}
3215 3394
 
3216 3395
 /**
3217 3396
  * Get the size of a specified image with better error handling.
@@ -3230,8 +3409,9 @@  discard block
 block discarded – undo
3230 3409
 	$url = str_replace(' ', '%20', $url);
3231 3410
 
3232 3411
 	// Can we pull this from the cache... please please?
3233
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3234
-		return $temp;
3412
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3413
+			return $temp;
3414
+	}
3235 3415
 	$t = microtime();
3236 3416
 
3237 3417
 	// Get the host to pester...
@@ -3241,12 +3421,10 @@  discard block
 block discarded – undo
3241 3421
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3242 3422
 	{
3243 3423
 		return false;
3244
-	}
3245
-	elseif (!isset($match[1]))
3424
+	} elseif (!isset($match[1]))
3246 3425
 	{
3247 3426
 		$size = @getimagesize($url);
3248
-	}
3249
-	else
3427
+	} else
3250 3428
 	{
3251 3429
 		// Try to connect to the server... give it half a second.
3252 3430
 		$temp = 0;
@@ -3283,12 +3461,14 @@  discard block
 block discarded – undo
3283 3461
 	}
3284 3462
 
3285 3463
 	// If we didn't get it, we failed.
3286
-	if (!isset($size))
3287
-		$size = false;
3464
+	if (!isset($size)) {
3465
+			$size = false;
3466
+	}
3288 3467
 
3289 3468
 	// If this took a long time, we may never have to do it again, but then again we might...
3290
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3291
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3469
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3470
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3471
+	}
3292 3472
 
3293 3473
 	// Didn't work.
3294 3474
 	return $size;
@@ -3306,8 +3486,9 @@  discard block
 block discarded – undo
3306 3486
 
3307 3487
 	// Under SSI this function can be called more then once.  That can cause some problems.
3308 3488
 	//   So only run the function once unless we are forced to run it again.
3309
-	if ($loaded && !$forceload)
3310
-		return;
3489
+	if ($loaded && !$forceload) {
3490
+			return;
3491
+	}
3311 3492
 
3312 3493
 	$loaded = true;
3313 3494
 
@@ -3319,14 +3500,16 @@  discard block
 block discarded – undo
3319 3500
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3320 3501
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3321 3502
 	{
3322
-		if (trim($context['news_lines'][$i]) == '')
3323
-			continue;
3503
+		if (trim($context['news_lines'][$i]) == '') {
3504
+					continue;
3505
+		}
3324 3506
 
3325 3507
 		// Clean it up for presentation ;).
3326 3508
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3327 3509
 	}
3328
-	if (!empty($context['news_lines']))
3329
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3510
+	if (!empty($context['news_lines'])) {
3511
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3512
+	}
3330 3513
 
3331 3514
 	if (!$user_info['is_guest'])
3332 3515
 	{
@@ -3335,40 +3518,48 @@  discard block
 block discarded – undo
3335 3518
 		$context['user']['alerts'] = &$user_info['alerts'];
3336 3519
 
3337 3520
 		// Personal message popup...
3338
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3339
-			$context['user']['popup_messages'] = true;
3340
-		else
3341
-			$context['user']['popup_messages'] = false;
3521
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3522
+					$context['user']['popup_messages'] = true;
3523
+		} else {
3524
+					$context['user']['popup_messages'] = false;
3525
+		}
3342 3526
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3343 3527
 
3344
-		if (allowedTo('moderate_forum'))
3345
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3528
+		if (allowedTo('moderate_forum')) {
3529
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3530
+		}
3346 3531
 
3347 3532
 		$context['user']['avatar'] = array();
3348 3533
 
3349 3534
 		// Check for gravatar first since we might be forcing them...
3350 3535
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3351 3536
 		{
3352
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3353
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3354
-			else
3355
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3537
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3538
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3539
+			} else {
3540
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3541
+			}
3356 3542
 		}
3357 3543
 		// Uploaded?
3358
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3359
-			$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';
3544
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3545
+					$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';
3546
+		}
3360 3547
 		// Full URL?
3361
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3362
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3548
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3549
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3550
+		}
3363 3551
 		// Otherwise we assume it's server stored.
3364
-		elseif ($user_info['avatar']['url'] != '')
3365
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3552
+		elseif ($user_info['avatar']['url'] != '') {
3553
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3554
+		}
3366 3555
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3367
-		else
3368
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3556
+		else {
3557
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3558
+		}
3369 3559
 
3370
-		if (!empty($context['user']['avatar']))
3371
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3560
+		if (!empty($context['user']['avatar'])) {
3561
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3562
+		}
3372 3563
 
3373 3564
 		// Figure out how long they've been logged in.
3374 3565
 		$context['user']['total_time_logged_in'] = array(
@@ -3376,8 +3567,7 @@  discard block
 block discarded – undo
3376 3567
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3377 3568
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3378 3569
 		);
3379
-	}
3380
-	else
3570
+	} else
3381 3571
 	{
3382 3572
 		$context['user']['messages'] = 0;
3383 3573
 		$context['user']['unread_messages'] = 0;
@@ -3385,12 +3575,14 @@  discard block
 block discarded – undo
3385 3575
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3386 3576
 		$context['user']['popup_messages'] = false;
3387 3577
 
3388
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3389
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3578
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3579
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3580
+		}
3390 3581
 
3391 3582
 		// If we've upgraded recently, go easy on the passwords.
3392
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3393
-			$context['disable_login_hashing'] = true;
3583
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3584
+					$context['disable_login_hashing'] = true;
3585
+		}
3394 3586
 	}
3395 3587
 
3396 3588
 	// Setup the main menu items.
@@ -3403,8 +3595,8 @@  discard block
 block discarded – undo
3403 3595
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3404 3596
 
3405 3597
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3406
-	if ($context['show_pm_popup'])
3407
-		addInlineJavaScript('
3598
+	if ($context['show_pm_popup']) {
3599
+			addInlineJavaScript('
3408 3600
 		jQuery(document).ready(function($) {
3409 3601
 			new smc_Popup({
3410 3602
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3412,24 +3604,28 @@  discard block
 block discarded – undo
3412 3604
 				icon_class: \'generic_icons mail_new\'
3413 3605
 			});
3414 3606
 		});');
3607
+	}
3415 3608
 
3416 3609
 	// Add a generic "Are you sure?" confirmation message.
3417 3610
 	addInlineJavaScript('
3418 3611
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3419 3612
 
3420 3613
 	// Now add the capping code for avatars.
3421
-	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')
3422
-		addInlineCss('
3614
+	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') {
3615
+			addInlineCss('
3423 3616
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3617
+	}
3424 3618
 
3425 3619
 	// Add max image limits
3426
-	if (!empty($modSettings['max_image_width']))
3427
-		addInlineCss('
3620
+	if (!empty($modSettings['max_image_width'])) {
3621
+			addInlineCss('
3428 3622
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3623
+	}
3429 3624
 
3430
-	if (!empty($modSettings['max_image_height']))
3431
-		addInlineCss('
3625
+	if (!empty($modSettings['max_image_height'])) {
3626
+			addInlineCss('
3432 3627
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3628
+	}
3433 3629
 
3434 3630
 	// This looks weird, but it's because BoardIndex.php references the variable.
3435 3631
 	$context['common_stats']['latest_member'] = array(
@@ -3446,11 +3642,13 @@  discard block
 block discarded – undo
3446 3642
 	);
3447 3643
 	$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']);
3448 3644
 
3449
-	if (empty($settings['theme_version']))
3450
-		addJavaScriptVar('smf_scripturl', $scripturl);
3645
+	if (empty($settings['theme_version'])) {
3646
+			addJavaScriptVar('smf_scripturl', $scripturl);
3647
+	}
3451 3648
 
3452
-	if (!isset($context['page_title']))
3453
-		$context['page_title'] = '';
3649
+	if (!isset($context['page_title'])) {
3650
+			$context['page_title'] = '';
3651
+	}
3454 3652
 
3455 3653
 	// Set some specific vars.
3456 3654
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3460,21 +3658,23 @@  discard block
 block discarded – undo
3460 3658
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3461 3659
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3462 3660
 
3463
-	if (!empty($context['meta_keywords']))
3464
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3661
+	if (!empty($context['meta_keywords'])) {
3662
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3663
+	}
3465 3664
 
3466
-	if (!empty($context['canonical_url']))
3467
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3665
+	if (!empty($context['canonical_url'])) {
3666
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3667
+	}
3468 3668
 
3469
-	if (!empty($settings['og_image']))
3470
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3669
+	if (!empty($settings['og_image'])) {
3670
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3671
+	}
3471 3672
 
3472 3673
 	if (!empty($context['meta_description']))
3473 3674
 	{
3474 3675
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3475 3676
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3476
-	}
3477
-	else
3677
+	} else
3478 3678
 	{
3479 3679
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3480 3680
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3499,8 +3699,9 @@  discard block
 block discarded – undo
3499 3699
 	$memory_needed = memoryReturnBytes($needed);
3500 3700
 
3501 3701
 	// should we account for how much is currently being used?
3502
-	if ($in_use)
3503
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3702
+	if ($in_use) {
3703
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3704
+	}
3504 3705
 
3505 3706
 	// if more is needed, request it
3506 3707
 	if ($memory_current < $memory_needed)
@@ -3523,8 +3724,9 @@  discard block
 block discarded – undo
3523 3724
  */
3524 3725
 function memoryReturnBytes($val)
3525 3726
 {
3526
-	if (is_integer($val))
3527
-		return $val;
3727
+	if (is_integer($val)) {
3728
+			return $val;
3729
+	}
3528 3730
 
3529 3731
 	// Separate the number from the designator
3530 3732
 	$val = trim($val);
@@ -3560,10 +3762,11 @@  discard block
 block discarded – undo
3560 3762
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3561 3763
 
3562 3764
 		// Are we debugging the template/html content?
3563
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3564
-			header('content-type: application/xhtml+xml');
3565
-		elseif (!isset($_REQUEST['xml']))
3566
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3765
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3766
+					header('content-type: application/xhtml+xml');
3767
+		} elseif (!isset($_REQUEST['xml'])) {
3768
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3769
+		}
3567 3770
 	}
3568 3771
 
3569 3772
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3572,8 +3775,9 @@  discard block
 block discarded – undo
3572 3775
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3573 3776
 	{
3574 3777
 		$position = array_search('body', $context['template_layers']);
3575
-		if ($position === false)
3576
-			$position = array_search('main', $context['template_layers']);
3778
+		if ($position === false) {
3779
+					$position = array_search('main', $context['template_layers']);
3780
+		}
3577 3781
 
3578 3782
 		if ($position !== false)
3579 3783
 		{
@@ -3601,23 +3805,25 @@  discard block
 block discarded – undo
3601 3805
 
3602 3806
 			foreach ($securityFiles as $i => $securityFile)
3603 3807
 			{
3604
-				if (!file_exists($boarddir . '/' . $securityFile))
3605
-					unset($securityFiles[$i]);
3808
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3809
+									unset($securityFiles[$i]);
3810
+				}
3606 3811
 			}
3607 3812
 
3608 3813
 			// We are already checking so many files...just few more doesn't make any difference! :P
3609
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3610
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3611
-
3612
-			else
3613
-				$path = $modSettings['attachmentUploadDir'];
3814
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3815
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3816
+			} else {
3817
+							$path = $modSettings['attachmentUploadDir'];
3818
+			}
3614 3819
 
3615 3820
 			secureDirectory($path, true);
3616 3821
 			secureDirectory($cachedir);
3617 3822
 
3618 3823
 			// If agreement is enabled, at least the english version shall exists
3619
-			if ($modSettings['requireAgreement'])
3620
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3824
+			if ($modSettings['requireAgreement']) {
3825
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3826
+			}
3621 3827
 
3622 3828
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3623 3829
 			{
@@ -3632,18 +3838,21 @@  discard block
 block discarded – undo
3632 3838
 					echo '
3633 3839
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3634 3840
 
3635
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3636
-						echo '
3841
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3842
+											echo '
3637 3843
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3844
+					}
3638 3845
 				}
3639 3846
 
3640
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3641
-					echo '
3847
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3848
+									echo '
3642 3849
 				<strong>', $txt['cache_writable'], '</strong><br>';
3850
+				}
3643 3851
 
3644
-				if (!empty($agreement))
3645
-					echo '
3852
+				if (!empty($agreement)) {
3853
+									echo '
3646 3854
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3855
+				}
3647 3856
 
3648 3857
 				echo '
3649 3858
 			</p>
@@ -3658,16 +3867,18 @@  discard block
 block discarded – undo
3658 3867
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3659 3868
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3660 3869
 
3661
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3662
-				echo '
3870
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3871
+							echo '
3663 3872
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3873
+			}
3664 3874
 
3665
-			if (!empty($_SESSION['ban']['expire_time']))
3666
-				echo '
3875
+			if (!empty($_SESSION['ban']['expire_time'])) {
3876
+							echo '
3667 3877
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3668
-			else
3669
-				echo '
3878
+			} else {
3879
+							echo '
3670 3880
 					<div>', $txt['your_ban_expires_never'], '</div>';
3881
+			}
3671 3882
 
3672 3883
 			echo '
3673 3884
 				</div>';
@@ -3683,8 +3894,9 @@  discard block
 block discarded – undo
3683 3894
 	global $forum_copyright, $software_year, $forum_version;
3684 3895
 
3685 3896
 	// Don't display copyright for things like SSI.
3686
-	if (!isset($forum_version) || !isset($software_year))
3687
-		return;
3897
+	if (!isset($forum_version) || !isset($software_year)) {
3898
+			return;
3899
+	}
3688 3900
 
3689 3901
 	// Put in the version...
3690 3902
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3702,9 +3914,10 @@  discard block
 block discarded – undo
3702 3914
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3703 3915
 	$context['load_queries'] = $db_count;
3704 3916
 
3705
-	foreach (array_reverse($context['template_layers']) as $layer)
3706
-		loadSubTemplate($layer . '_below', true);
3707
-}
3917
+	foreach (array_reverse($context['template_layers']) as $layer) {
3918
+			loadSubTemplate($layer . '_below', true);
3919
+	}
3920
+	}
3708 3921
 
3709 3922
 /**
3710 3923
  * Output the Javascript files
@@ -3738,8 +3951,7 @@  discard block
 block discarded – undo
3738 3951
 			{
3739 3952
 				echo '
3740 3953
 		var ', $key, ';';
3741
-			}
3742
-			else
3954
+			} else
3743 3955
 			{
3744 3956
 				echo '
3745 3957
 		var ', $key, ' = ', $value, ';';
@@ -3758,27 +3970,29 @@  discard block
 block discarded – undo
3758 3970
 		foreach ($context['javascript_files'] as $id => $js_file)
3759 3971
 		{
3760 3972
 			// Last minute call! allow theme authors to disable single files.
3761
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3762
-				continue;
3973
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3974
+							continue;
3975
+			}
3763 3976
 
3764 3977
 			// By default files don't get minimized unless the file explicitly says so!
3765 3978
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3766 3979
 			{
3767
-				if (!empty($js_file['options']['async']))
3768
-					$toMinify['async'][] = $js_file;
3769
-				elseif (!empty($js_file['options']['defer']))
3770
-					$toMinify['defer'][] = $js_file;
3771
-				else
3772
-					$toMinify['standard'][] = $js_file;
3980
+				if (!empty($js_file['options']['async'])) {
3981
+									$toMinify['async'][] = $js_file;
3982
+				} elseif (!empty($js_file['options']['defer'])) {
3983
+									$toMinify['defer'][] = $js_file;
3984
+				} else {
3985
+									$toMinify['standard'][] = $js_file;
3986
+				}
3773 3987
 
3774 3988
 				// Grab a random seed.
3775
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3776
-					$minSeed = $js_file['options']['seed'];
3777
-			}
3778
-
3779
-			else
3780
-				echo '
3989
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3990
+									$minSeed = $js_file['options']['seed'];
3991
+				}
3992
+			} else {
3993
+							echo '
3781 3994
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3995
+			}
3782 3996
 		}
3783 3997
 
3784 3998
 		foreach ($toMinify as $js_files)
@@ -3789,9 +4003,10 @@  discard block
 block discarded – undo
3789 4003
 
3790 4004
 				$minSuccessful = array_keys($result) === array('smf_minified');
3791 4005
 
3792
-				foreach ($result as $minFile)
3793
-					echo '
4006
+				foreach ($result as $minFile) {
4007
+									echo '
3794 4008
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4009
+				}
3795 4010
 			}
3796 4011
 		}
3797 4012
 	}
@@ -3805,8 +4020,9 @@  discard block
 block discarded – undo
3805 4020
 <script>
3806 4021
 window.addEventListener("DOMContentLoaded", function() {';
3807 4022
 
3808
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3809
-				echo $js_code;
4023
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4024
+							echo $js_code;
4025
+			}
3810 4026
 
3811 4027
 			echo '
3812 4028
 });
@@ -3818,8 +4034,9 @@  discard block
 block discarded – undo
3818 4034
 			echo '
3819 4035
 	<script>';
3820 4036
 
3821
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3822
-				echo $js_code;
4037
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4038
+							echo $js_code;
4039
+			}
3823 4040
 
3824 4041
 			echo '
3825 4042
 	</script>';
@@ -3847,23 +4064,26 @@  discard block
 block discarded – undo
3847 4064
 	foreach ($context['css_files'] as $id => $file)
3848 4065
 	{
3849 4066
 		// Last minute call! allow theme authors to disable single files.
3850
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3851
-			continue;
4067
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4068
+					continue;
4069
+		}
3852 4070
 
3853 4071
 		// Files are minimized unless they explicitly opt out.
3854
-		if (!isset($file['options']['minimize']))
3855
-			$file['options']['minimize'] = true;
4072
+		if (!isset($file['options']['minimize'])) {
4073
+					$file['options']['minimize'] = true;
4074
+		}
3856 4075
 
3857 4076
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3858 4077
 		{
3859 4078
 			$toMinify[] = $file;
3860 4079
 
3861 4080
 			// Grab a random seed.
3862
-			if (!isset($minSeed) && isset($file['options']['seed']))
3863
-				$minSeed = $file['options']['seed'];
4081
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4082
+							$minSeed = $file['options']['seed'];
4083
+			}
4084
+		} else {
4085
+					$normal[] = $file['fileUrl'];
3864 4086
 		}
3865
-		else
3866
-			$normal[] = $file['fileUrl'];
3867 4087
 	}
3868 4088
 
3869 4089
 	if (!empty($toMinify))
@@ -3872,23 +4092,26 @@  discard block
 block discarded – undo
3872 4092
 
3873 4093
 		$minSuccessful = array_keys($result) === array('smf_minified');
3874 4094
 
3875
-		foreach ($result as $minFile)
3876
-			echo '
4095
+		foreach ($result as $minFile) {
4096
+					echo '
3877 4097
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4098
+		}
3878 4099
 	}
3879 4100
 
3880 4101
 	// Print the rest after the minified files.
3881
-	if (!empty($normal))
3882
-		foreach ($normal as $nf)
4102
+	if (!empty($normal)) {
4103
+			foreach ($normal as $nf)
3883 4104
 			echo '
3884 4105
 	<link rel="stylesheet" href="', $nf ,'">';
4106
+	}
3885 4107
 
3886 4108
 	if ($db_show_debug === true)
3887 4109
 	{
3888 4110
 		// Try to keep only what's useful.
3889 4111
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3890
-		foreach ($context['css_files'] as $file)
3891
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4112
+		foreach ($context['css_files'] as $file) {
4113
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4114
+		}
3892 4115
 	}
3893 4116
 
3894 4117
 	if (!empty($context['css_header']))
@@ -3896,9 +4119,10 @@  discard block
 block discarded – undo
3896 4119
 		echo '
3897 4120
 	<style>';
3898 4121
 
3899
-		foreach ($context['css_header'] as $css)
3900
-			echo $css .'
4122
+		foreach ($context['css_header'] as $css) {
4123
+					echo $css .'
3901 4124
 	';
4125
+		}
3902 4126
 
3903 4127
 		echo'
3904 4128
 	</style>';
@@ -3921,8 +4145,9 @@  discard block
 block discarded – undo
3921 4145
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3922 4146
 	$data = is_array($data) ? $data : array();
3923 4147
 
3924
-	if (empty($type) || empty($data))
3925
-		return $data;
4148
+	if (empty($type) || empty($data)) {
4149
+			return $data;
4150
+	}
3926 4151
 
3927 4152
 	// Different pages include different files, so we use a hash to label the different combinations
3928 4153
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3931,13 +4156,14 @@  discard block
 block discarded – undo
3931 4156
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3932 4157
 
3933 4158
 	// Already done?
3934
-	if (!empty($toCache))
3935
-		return array('smf_minified' => array(
4159
+	if (!empty($toCache)) {
4160
+			return array('smf_minified' => array(
3936 4161
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3937 4162
 			'filePath' => $toCache,
3938 4163
 			'fileName' => basename($toCache),
3939 4164
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3940 4165
 		));
4166
+	}
3941 4167
 
3942 4168
 
3943 4169
 	// No namespaces, sorry!
@@ -3967,9 +4193,9 @@  discard block
 block discarded – undo
3967 4193
 
3968 4194
 	foreach ($data as $id => $file)
3969 4195
 	{
3970
-		if (empty($file['filePath']))
3971
-			$toAdd = false;
3972
-		else
4196
+		if (empty($file['filePath'])) {
4197
+					$toAdd = false;
4198
+		} else
3973 4199
 		{
3974 4200
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3975 4201
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3977,12 +4203,14 @@  discard block
 block discarded – undo
3977 4203
 		}
3978 4204
 
3979 4205
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3980
-		if (empty($file['options']['async']))
3981
-			$async = false;
4206
+		if (empty($file['options']['async'])) {
4207
+					$async = false;
4208
+		}
3982 4209
 
3983 4210
 		// A minified script should only be deferred if all its components wanted to be.
3984
-		if (empty($file['options']['defer']))
3985
-			$defer = false;
4211
+		if (empty($file['options']['defer'])) {
4212
+					$defer = false;
4213
+		}
3986 4214
 
3987 4215
 		// The file couldn't be located so it won't be added. Log this error.
3988 4216
 		if (empty($toAdd))
@@ -4048,12 +4276,14 @@  discard block
 block discarded – undo
4048 4276
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4049 4277
 			{
4050 4278
 				// Remove the cache entry
4051
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4052
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4279
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4280
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4281
+				}
4053 4282
 
4054 4283
 				// Try to delete the file. Add it to our error list if it fails.
4055
-				if (!@unlink($filename))
4056
-					$not_deleted[] = $filename;
4284
+				if (!@unlink($filename)) {
4285
+									$not_deleted[] = $filename;
4286
+				}
4057 4287
 			}
4058 4288
 		}
4059 4289
 	}
@@ -4085,8 +4315,9 @@  discard block
 block discarded – undo
4085 4315
 	global $modSettings, $smcFunc;
4086 4316
 
4087 4317
 	// Just make up a nice hash...
4088
-	if ($new)
4089
-		return sha1(md5($filename . time()) . mt_rand());
4318
+	if ($new) {
4319
+			return sha1(md5($filename . time()) . mt_rand());
4320
+	}
4090 4321
 
4091 4322
 	// Just make sure that attachment id is only a int
4092 4323
 	$attachment_id = (int) $attachment_id;
@@ -4103,23 +4334,25 @@  discard block
 block discarded – undo
4103 4334
 				'id_attach' => $attachment_id,
4104 4335
 			));
4105 4336
 
4106
-		if ($smcFunc['db_num_rows']($request) === 0)
4107
-			return false;
4337
+		if ($smcFunc['db_num_rows']($request) === 0) {
4338
+					return false;
4339
+		}
4108 4340
 
4109 4341
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4110 4342
 		$smcFunc['db_free_result']($request);
4111 4343
 	}
4112 4344
 
4113 4345
 	// Still no hash? mmm...
4114
-	if (empty($file_hash))
4115
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4346
+	if (empty($file_hash)) {
4347
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4348
+	}
4116 4349
 
4117 4350
 	// Are we using multiple directories?
4118
-	if (is_array($modSettings['attachmentUploadDir']))
4119
-		$path = $modSettings['attachmentUploadDir'][$dir];
4120
-
4121
-	else
4122
-		$path = $modSettings['attachmentUploadDir'];
4351
+	if (is_array($modSettings['attachmentUploadDir'])) {
4352
+			$path = $modSettings['attachmentUploadDir'][$dir];
4353
+	} else {
4354
+			$path = $modSettings['attachmentUploadDir'];
4355
+	}
4123 4356
 
4124 4357
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4125 4358
 }
@@ -4134,8 +4367,9 @@  discard block
 block discarded – undo
4134 4367
 function ip2range($fullip)
4135 4368
 {
4136 4369
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4137
-	if ($fullip == 'unknown')
4138
-		$fullip = '255.255.255.255';
4370
+	if ($fullip == 'unknown') {
4371
+			$fullip = '255.255.255.255';
4372
+	}
4139 4373
 
4140 4374
 	$ip_parts = explode('-', $fullip);
4141 4375
 	$ip_array = array();
@@ -4159,10 +4393,11 @@  discard block
 block discarded – undo
4159 4393
 		$ip_array['low'] = $ip_parts[0];
4160 4394
 		$ip_array['high'] = $ip_parts[1];
4161 4395
 		return $ip_array;
4162
-	}
4163
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4396
+	} elseif (count($ip_parts) == 2) {
4397
+		// if ip 22.22.*-22.22.*
4164 4398
 	{
4165 4399
 		$valid_low = isValidIP($ip_parts[0]);
4400
+	}
4166 4401
 		$valid_high = isValidIP($ip_parts[1]);
4167 4402
 		$count = 0;
4168 4403
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4177,7 +4412,9 @@  discard block
 block discarded – undo
4177 4412
 				$ip_parts[0] .= $mode . $min;
4178 4413
 				$valid_low = isValidIP($ip_parts[0]);
4179 4414
 				$count++;
4180
-				if ($count > 9) break;
4415
+				if ($count > 9) {
4416
+					break;
4417
+				}
4181 4418
 			}
4182 4419
 		}
4183 4420
 
@@ -4191,7 +4428,9 @@  discard block
 block discarded – undo
4191 4428
 				$ip_parts[1] .= $mode . $max;
4192 4429
 				$valid_high = isValidIP($ip_parts[1]);
4193 4430
 				$count++;
4194
-				if ($count > 9) break;
4431
+				if ($count > 9) {
4432
+					break;
4433
+				}
4195 4434
 			}
4196 4435
 		}
4197 4436
 
@@ -4215,46 +4454,54 @@  discard block
 block discarded – undo
4215 4454
 {
4216 4455
 	global $modSettings;
4217 4456
 
4218
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4219
-		return $host;
4457
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4458
+			return $host;
4459
+	}
4220 4460
 	$t = microtime();
4221 4461
 
4222 4462
 	// Try the Linux host command, perhaps?
4223 4463
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4224 4464
 	{
4225
-		if (!isset($modSettings['host_to_dis']))
4226
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4227
-		else
4228
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4465
+		if (!isset($modSettings['host_to_dis'])) {
4466
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4467
+		} else {
4468
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4469
+		}
4229 4470
 
4230 4471
 		// Did host say it didn't find anything?
4231
-		if (strpos($test, 'not found') !== false)
4232
-			$host = '';
4472
+		if (strpos($test, 'not found') !== false) {
4473
+					$host = '';
4474
+		}
4233 4475
 		// Invalid server option?
4234
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4235
-			updateSettings(array('host_to_dis' => 1));
4476
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4477
+					updateSettings(array('host_to_dis' => 1));
4478
+		}
4236 4479
 		// Maybe it found something, after all?
4237
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4238
-			$host = $match[1];
4480
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4481
+					$host = $match[1];
4482
+		}
4239 4483
 	}
4240 4484
 
4241 4485
 	// This is nslookup; usually only Windows, but possibly some Unix?
4242 4486
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4243 4487
 	{
4244 4488
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4245
-		if (strpos($test, 'Non-existent domain') !== false)
4246
-			$host = '';
4247
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4248
-			$host = $match[1];
4489
+		if (strpos($test, 'Non-existent domain') !== false) {
4490
+					$host = '';
4491
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4492
+					$host = $match[1];
4493
+		}
4249 4494
 	}
4250 4495
 
4251 4496
 	// This is the last try :/.
4252
-	if (!isset($host) || $host === false)
4253
-		$host = @gethostbyaddr($ip);
4497
+	if (!isset($host) || $host === false) {
4498
+			$host = @gethostbyaddr($ip);
4499
+	}
4254 4500
 
4255 4501
 	// It took a long time, so let's cache it!
4256
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4257
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4502
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4503
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4504
+	}
4258 4505
 
4259 4506
 	return $host;
4260 4507
 }
@@ -4290,20 +4537,21 @@  discard block
 block discarded – undo
4290 4537
 			{
4291 4538
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4292 4539
 				$total = 0;
4293
-				for ($i = 0; $i < $max_chars; $i++)
4294
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4540
+				for ($i = 0; $i < $max_chars; $i++) {
4541
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4542
+				}
4295 4543
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4296 4544
 			}
4297 4545
 		}
4298 4546
 		return array_unique($returned_ints);
4299
-	}
4300
-	else
4547
+	} else
4301 4548
 	{
4302 4549
 		// Trim characters before and after and add slashes for database insertion.
4303 4550
 		$returned_words = array();
4304
-		foreach ($words as $word)
4305
-			if (($word = trim($word, '-_\'')) !== '')
4551
+		foreach ($words as $word) {
4552
+					if (($word = trim($word, '-_\'')) !== '')
4306 4553
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4554
+		}
4307 4555
 
4308 4556
 		// Filter out all words that occur more than once.
4309 4557
 		return array_unique($returned_words);
@@ -4325,16 +4573,18 @@  discard block
 block discarded – undo
4325 4573
 	global $settings, $txt;
4326 4574
 
4327 4575
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4328
-	if (function_exists('template_create_button') && !$force_use)
4329
-		return template_create_button($name, $alt, $label = '', $custom = '');
4576
+	if (function_exists('template_create_button') && !$force_use) {
4577
+			return template_create_button($name, $alt, $label = '', $custom = '');
4578
+	}
4330 4579
 
4331
-	if (!$settings['use_image_buttons'])
4332
-		return $txt[$alt];
4333
-	elseif (!empty($settings['use_buttons']))
4334
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4335
-	else
4336
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4337
-}
4580
+	if (!$settings['use_image_buttons']) {
4581
+			return $txt[$alt];
4582
+	} elseif (!empty($settings['use_buttons'])) {
4583
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4584
+	} else {
4585
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4586
+	}
4587
+	}
4338 4588
 
4339 4589
 /**
4340 4590
  * Sets up all of the top menu buttons
@@ -4377,9 +4627,10 @@  discard block
 block discarded – undo
4377 4627
 	var user_menus = new smc_PopupMenu();
4378 4628
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4379 4629
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4380
-		if ($context['allow_pm'])
4381
-			addInlineJavaScript('
4630
+		if ($context['allow_pm']) {
4631
+					addInlineJavaScript('
4382 4632
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4633
+		}
4383 4634
 
4384 4635
 		if (!empty($modSettings['enable_ajax_alerts']))
4385 4636
 		{
@@ -4539,88 +4790,96 @@  discard block
 block discarded – undo
4539 4790
 
4540 4791
 		// Now we put the buttons in the context so the theme can use them.
4541 4792
 		$menu_buttons = array();
4542
-		foreach ($buttons as $act => $button)
4543
-			if (!empty($button['show']))
4793
+		foreach ($buttons as $act => $button) {
4794
+					if (!empty($button['show']))
4544 4795
 			{
4545 4796
 				$button['active_button'] = false;
4797
+		}
4546 4798
 
4547 4799
 				// This button needs some action.
4548
-				if (isset($button['action_hook']))
4549
-					$needs_action_hook = true;
4800
+				if (isset($button['action_hook'])) {
4801
+									$needs_action_hook = true;
4802
+				}
4550 4803
 
4551 4804
 				// Make sure the last button truly is the last button.
4552 4805
 				if (!empty($button['is_last']))
4553 4806
 				{
4554
-					if (isset($last_button))
4555
-						unset($menu_buttons[$last_button]['is_last']);
4807
+					if (isset($last_button)) {
4808
+											unset($menu_buttons[$last_button]['is_last']);
4809
+					}
4556 4810
 					$last_button = $act;
4557 4811
 				}
4558 4812
 
4559 4813
 				// Go through the sub buttons if there are any.
4560
-				if (!empty($button['sub_buttons']))
4561
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4814
+				if (!empty($button['sub_buttons'])) {
4815
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4562 4816
 					{
4563 4817
 						if (empty($subbutton['show']))
4564 4818
 							unset($button['sub_buttons'][$key]);
4819
+				}
4565 4820
 
4566 4821
 						// 2nd level sub buttons next...
4567 4822
 						if (!empty($subbutton['sub_buttons']))
4568 4823
 						{
4569 4824
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4570 4825
 							{
4571
-								if (empty($sub_button2['show']))
4572
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4826
+								if (empty($sub_button2['show'])) {
4827
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4828
+								}
4573 4829
 							}
4574 4830
 						}
4575 4831
 					}
4576 4832
 
4577 4833
 				// Does this button have its own icon?
4578
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4579
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4580
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4581
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4582
-				elseif (isset($button['icon']))
4583
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4584
-				else
4585
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4834
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4835
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4836
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4837
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4838
+				} elseif (isset($button['icon'])) {
4839
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4840
+				} else {
4841
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4842
+				}
4586 4843
 
4587 4844
 				$menu_buttons[$act] = $button;
4588 4845
 			}
4589 4846
 
4590
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4591
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4847
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4848
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4849
+		}
4592 4850
 	}
4593 4851
 
4594 4852
 	$context['menu_buttons'] = $menu_buttons;
4595 4853
 
4596 4854
 	// Logging out requires the session id in the url.
4597
-	if (isset($context['menu_buttons']['logout']))
4598
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4855
+	if (isset($context['menu_buttons']['logout'])) {
4856
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4857
+	}
4599 4858
 
4600 4859
 	// Figure out which action we are doing so we can set the active tab.
4601 4860
 	// Default to home.
4602 4861
 	$current_action = 'home';
4603 4862
 
4604
-	if (isset($context['menu_buttons'][$context['current_action']]))
4605
-		$current_action = $context['current_action'];
4606
-	elseif ($context['current_action'] == 'search2')
4607
-		$current_action = 'search';
4608
-	elseif ($context['current_action'] == 'theme')
4609
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4610
-	elseif ($context['current_action'] == 'register2')
4611
-		$current_action = 'register';
4612
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4613
-		$current_action = 'login';
4614
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4615
-		$current_action = 'moderate';
4863
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4864
+			$current_action = $context['current_action'];
4865
+	} elseif ($context['current_action'] == 'search2') {
4866
+			$current_action = 'search';
4867
+	} elseif ($context['current_action'] == 'theme') {
4868
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4869
+	} elseif ($context['current_action'] == 'register2') {
4870
+			$current_action = 'register';
4871
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4872
+			$current_action = 'login';
4873
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4874
+			$current_action = 'moderate';
4875
+	}
4616 4876
 
4617 4877
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4618 4878
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4619 4879
 	{
4620 4880
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4621 4881
 		$context[$current_action] = true;
4622
-	}
4623
-	elseif ($context['current_action'] == 'pm')
4882
+	} elseif ($context['current_action'] == 'pm')
4624 4883
 	{
4625 4884
 		$current_action = 'self_pm';
4626 4885
 		$context['self_pm'] = true;
@@ -4677,12 +4936,14 @@  discard block
 block discarded – undo
4677 4936
 	}
4678 4937
 
4679 4938
 	// Not all actions are simple.
4680
-	if (!empty($needs_action_hook))
4681
-		call_integration_hook('integrate_current_action', array(&$current_action));
4939
+	if (!empty($needs_action_hook)) {
4940
+			call_integration_hook('integrate_current_action', array(&$current_action));
4941
+	}
4682 4942
 
4683
-	if (isset($context['menu_buttons'][$current_action]))
4684
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4685
-}
4943
+	if (isset($context['menu_buttons'][$current_action])) {
4944
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4945
+	}
4946
+	}
4686 4947
 
4687 4948
 /**
4688 4949
  * Generate a random seed and ensure it's stored in settings.
@@ -4706,30 +4967,35 @@  discard block
 block discarded – undo
4706 4967
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4707 4968
 	global $context, $txt;
4708 4969
 
4709
-	if ($db_show_debug === true)
4710
-		$context['debug']['hooks'][] = $hook;
4970
+	if ($db_show_debug === true) {
4971
+			$context['debug']['hooks'][] = $hook;
4972
+	}
4711 4973
 
4712 4974
 	// Need to have some control.
4713
-	if (!isset($context['instances']))
4714
-		$context['instances'] = array();
4975
+	if (!isset($context['instances'])) {
4976
+			$context['instances'] = array();
4977
+	}
4715 4978
 
4716 4979
 	$results = array();
4717
-	if (empty($modSettings[$hook]))
4718
-		return $results;
4980
+	if (empty($modSettings[$hook])) {
4981
+			return $results;
4982
+	}
4719 4983
 
4720 4984
 	$functions = explode(',', $modSettings[$hook]);
4721 4985
 	// Loop through each function.
4722 4986
 	foreach ($functions as $function)
4723 4987
 	{
4724 4988
 		// Hook has been marked as "disabled". Skip it!
4725
-		if (strpos($function, '!') !== false)
4726
-			continue;
4989
+		if (strpos($function, '!') !== false) {
4990
+					continue;
4991
+		}
4727 4992
 
4728 4993
 		$call = call_helper($function, true);
4729 4994
 
4730 4995
 		// Is it valid?
4731
-		if (!empty($call))
4732
-			$results[$function] = call_user_func_array($call, $parameters);
4996
+		if (!empty($call)) {
4997
+					$results[$function] = call_user_func_array($call, $parameters);
4998
+		}
4733 4999
 
4734 5000
 		// Whatever it was suppose to call, it failed :(
4735 5001
 		elseif (!empty($function))
@@ -4745,8 +5011,9 @@  discard block
 block discarded – undo
4745 5011
 			}
4746 5012
 
4747 5013
 			// "Assume" the file resides on $boarddir somewhere...
4748
-			else
4749
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5014
+			else {
5015
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5016
+			}
4750 5017
 		}
4751 5018
 	}
4752 5019
 
@@ -4768,12 +5035,14 @@  discard block
 block discarded – undo
4768 5035
 	global $smcFunc, $modSettings;
4769 5036
 
4770 5037
 	// Any objects?
4771
-	if ($object)
4772
-		$function = $function . '#';
5038
+	if ($object) {
5039
+			$function = $function . '#';
5040
+	}
4773 5041
 
4774 5042
 	// Any files  to load?
4775
-	if (!empty($file) && is_string($file))
4776
-		$function = $file . (!empty($function) ? '|' . $function : '');
5043
+	if (!empty($file) && is_string($file)) {
5044
+			$function = $file . (!empty($function) ? '|' . $function : '');
5045
+	}
4777 5046
 
4778 5047
 	// Get the correct string.
4779 5048
 	$integration_call = $function;
@@ -4795,13 +5064,14 @@  discard block
 block discarded – undo
4795 5064
 		if (!empty($current_functions))
4796 5065
 		{
4797 5066
 			$current_functions = explode(',', $current_functions);
4798
-			if (in_array($integration_call, $current_functions))
4799
-				return;
5067
+			if (in_array($integration_call, $current_functions)) {
5068
+							return;
5069
+			}
4800 5070
 
4801 5071
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5072
+		} else {
5073
+					$permanent_functions = array($integration_call);
4802 5074
 		}
4803
-		else
4804
-			$permanent_functions = array($integration_call);
4805 5075
 
4806 5076
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4807 5077
 	}
@@ -4810,8 +5080,9 @@  discard block
 block discarded – undo
4810 5080
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4811 5081
 
4812 5082
 	// Do nothing, if it's already there.
4813
-	if (in_array($integration_call, $functions))
4814
-		return;
5083
+	if (in_array($integration_call, $functions)) {
5084
+			return;
5085
+	}
4815 5086
 
4816 5087
 	$functions[] = $integration_call;
4817 5088
 	$modSettings[$hook] = implode(',', $functions);
@@ -4834,12 +5105,14 @@  discard block
 block discarded – undo
4834 5105
 	global $smcFunc, $modSettings;
4835 5106
 
4836 5107
 	// Any objects?
4837
-	if ($object)
4838
-		$function = $function . '#';
5108
+	if ($object) {
5109
+			$function = $function . '#';
5110
+	}
4839 5111
 
4840 5112
 	// Any files  to load?
4841
-	if (!empty($file) && is_string($file))
4842
-		$function = $file . '|' . $function;
5113
+	if (!empty($file) && is_string($file)) {
5114
+			$function = $file . '|' . $function;
5115
+	}
4843 5116
 
4844 5117
 	// Get the correct string.
4845 5118
 	$integration_call = $function;
@@ -4860,16 +5133,18 @@  discard block
 block discarded – undo
4860 5133
 	{
4861 5134
 		$current_functions = explode(',', $current_functions);
4862 5135
 
4863
-		if (in_array($integration_call, $current_functions))
4864
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5136
+		if (in_array($integration_call, $current_functions)) {
5137
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5138
+		}
4865 5139
 	}
4866 5140
 
4867 5141
 	// Turn the function list into something usable.
4868 5142
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4869 5143
 
4870 5144
 	// You can only remove it if it's available.
4871
-	if (!in_array($integration_call, $functions))
4872
-		return;
5145
+	if (!in_array($integration_call, $functions)) {
5146
+			return;
5147
+	}
4873 5148
 
4874 5149
 	$functions = array_diff($functions, array($integration_call));
4875 5150
 	$modSettings[$hook] = implode(',', $functions);
@@ -4890,17 +5165,20 @@  discard block
 block discarded – undo
4890 5165
 	global $context, $smcFunc, $txt, $db_show_debug;
4891 5166
 
4892 5167
 	// Really?
4893
-	if (empty($string))
4894
-		return false;
5168
+	if (empty($string)) {
5169
+			return false;
5170
+	}
4895 5171
 
4896 5172
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4897 5173
 	// A closure? should be a callable one.
4898
-	if (is_array($string) || $string instanceof Closure)
4899
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5174
+	if (is_array($string) || $string instanceof Closure) {
5175
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5176
+	}
4900 5177
 
4901 5178
 	// No full objects, sorry! pass a method or a property instead!
4902
-	if (is_object($string))
4903
-		return false;
5179
+	if (is_object($string)) {
5180
+			return false;
5181
+	}
4904 5182
 
4905 5183
 	// Stay vitaminized my friends...
4906 5184
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4909,8 +5187,9 @@  discard block
 block discarded – undo
4909 5187
 	$string = load_file($string);
4910 5188
 
4911 5189
 	// Loaded file failed
4912
-	if (empty($string))
4913
-		return false;
5190
+	if (empty($string)) {
5191
+			return false;
5192
+	}
4914 5193
 
4915 5194
 	// Found a method.
4916 5195
 	if (strpos($string, '::') !== false)
@@ -4931,8 +5210,9 @@  discard block
 block discarded – undo
4931 5210
 				// Add another one to the list.
4932 5211
 				if ($db_show_debug === true)
4933 5212
 				{
4934
-					if (!isset($context['debug']['instances']))
4935
-						$context['debug']['instances'] = array();
5213
+					if (!isset($context['debug']['instances'])) {
5214
+											$context['debug']['instances'] = array();
5215
+					}
4936 5216
 
4937 5217
 					$context['debug']['instances'][$class] = $class;
4938 5218
 				}
@@ -4942,13 +5222,15 @@  discard block
 block discarded – undo
4942 5222
 		}
4943 5223
 
4944 5224
 		// Right then. This is a call to a static method.
4945
-		else
4946
-			$func = array($class, $method);
5225
+		else {
5226
+					$func = array($class, $method);
5227
+		}
4947 5228
 	}
4948 5229
 
4949 5230
 	// Nope! just a plain regular function.
4950
-	else
4951
-		$func = $string;
5231
+	else {
5232
+			$func = $string;
5233
+	}
4952 5234
 
4953 5235
 	// Right, we got what we need, time to do some checks.
4954 5236
 	if (!is_callable($func, false, $callable_name))
@@ -4964,17 +5246,18 @@  discard block
 block discarded – undo
4964 5246
 	else
4965 5247
 	{
4966 5248
 		// What are we gonna do about it?
4967
-		if ($return)
4968
-			return $func;
5249
+		if ($return) {
5250
+					return $func;
5251
+		}
4969 5252
 
4970 5253
 		// If this is a plain function, avoid the heat of calling call_user_func().
4971 5254
 		else
4972 5255
 		{
4973
-			if (is_array($func))
4974
-				call_user_func($func);
4975
-
4976
-			else
4977
-				$func();
5256
+			if (is_array($func)) {
5257
+							call_user_func($func);
5258
+			} else {
5259
+							$func();
5260
+			}
4978 5261
 		}
4979 5262
 	}
4980 5263
 }
@@ -4991,31 +5274,34 @@  discard block
 block discarded – undo
4991 5274
 {
4992 5275
 	global $sourcedir, $txt, $boarddir, $settings;
4993 5276
 
4994
-	if (empty($string))
4995
-		return false;
5277
+	if (empty($string)) {
5278
+			return false;
5279
+	}
4996 5280
 
4997 5281
 	if (strpos($string, '|') !== false)
4998 5282
 	{
4999 5283
 		list ($file, $string) = explode('|', $string);
5000 5284
 
5001 5285
 		// Match the wildcards to their regular vars.
5002
-		if (empty($settings['theme_dir']))
5003
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5004
-
5005
-		else
5006
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5286
+		if (empty($settings['theme_dir'])) {
5287
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5288
+		} else {
5289
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5290
+		}
5007 5291
 
5008 5292
 		// Load the file if it can be loaded.
5009
-		if (file_exists($absPath))
5010
-			require_once($absPath);
5293
+		if (file_exists($absPath)) {
5294
+					require_once($absPath);
5295
+		}
5011 5296
 
5012 5297
 		// No? try a fallback to $sourcedir
5013 5298
 		else
5014 5299
 		{
5015 5300
 			$absPath = $sourcedir .'/'. $file;
5016 5301
 
5017
-			if (file_exists($absPath))
5018
-				require_once($absPath);
5302
+			if (file_exists($absPath)) {
5303
+							require_once($absPath);
5304
+			}
5019 5305
 
5020 5306
 			// Sorry, can't do much for you at this point.
5021 5307
 			else
@@ -5054,8 +5340,9 @@  discard block
 block discarded – undo
5054 5340
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5055 5341
 
5056 5342
 	// No scheme? No data for you!
5057
-	if (empty($match[1]))
5058
-		return false;
5343
+	if (empty($match[1])) {
5344
+			return false;
5345
+	}
5059 5346
 
5060 5347
 	// An FTP url. We should try connecting and RETRieving it...
5061 5348
 	elseif ($match[1] == 'ftp')
@@ -5065,23 +5352,26 @@  discard block
 block discarded – undo
5065 5352
 
5066 5353
 		// Establish a connection and attempt to enable passive mode.
5067 5354
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5068
-		if ($ftp->error !== false || !$ftp->passive())
5069
-			return false;
5355
+		if ($ftp->error !== false || !$ftp->passive()) {
5356
+					return false;
5357
+		}
5070 5358
 
5071 5359
 		// I want that one *points*!
5072 5360
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5073 5361
 
5074 5362
 		// Since passive mode worked (or we would have returned already!) open the connection.
5075 5363
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5076
-		if (!$fp)
5077
-			return false;
5364
+		if (!$fp) {
5365
+					return false;
5366
+		}
5078 5367
 
5079 5368
 		// The server should now say something in acknowledgement.
5080 5369
 		$ftp->check_response(150);
5081 5370
 
5082 5371
 		$data = '';
5083
-		while (!feof($fp))
5084
-			$data .= fread($fp, 4096);
5372
+		while (!feof($fp)) {
5373
+					$data .= fread($fp, 4096);
5374
+		}
5085 5375
 		fclose($fp);
5086 5376
 
5087 5377
 		// All done, right?  Good.
@@ -5093,8 +5383,9 @@  discard block
 block discarded – undo
5093 5383
 	elseif (isset($match[1]) && $match[1] == 'http')
5094 5384
 	{
5095 5385
 		// First try to use fsockopen, because it is fastest.
5096
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5097
-			$fp = $keep_alive_fp;
5386
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5387
+					$fp = $keep_alive_fp;
5388
+		}
5098 5389
 		if (empty($fp))
5099 5390
 		{
5100 5391
 			// Open the socket on the port we want...
@@ -5114,20 +5405,21 @@  discard block
 block discarded – undo
5114 5405
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $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\r\n");
5119
-				else
5120
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5121
-			}
5122
-			else
5408
+				if ($keep_alive) {
5409
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5410
+				} else {
5411
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5412
+				}
5413
+			} else
5123 5414
 			{
5124 5415
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5125 5416
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5126 5417
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5127
-				if ($keep_alive)
5128
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5129
-				else
5130
-					fwrite($fp, 'connection: close' . "\r\n");
5418
+				if ($keep_alive) {
5419
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5420
+				} else {
5421
+									fwrite($fp, 'connection: close' . "\r\n");
5422
+				}
5131 5423
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5132 5424
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5133 5425
 				fwrite($fp, $post_data);
@@ -5140,30 +5432,33 @@  discard block
 block discarded – undo
5140 5432
 			{
5141 5433
 				$header = '';
5142 5434
 				$location = '';
5143
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5144
-					if (strpos($header, 'location:') !== false)
5435
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5436
+									if (strpos($header, 'location:') !== false)
5145 5437
 						$location = trim(substr($header, strpos($header, ':') + 1));
5438
+				}
5146 5439
 
5147
-				if (empty($location))
5148
-					return false;
5149
-				else
5440
+				if (empty($location)) {
5441
+									return false;
5442
+				} else
5150 5443
 				{
5151
-					if (!$keep_alive)
5152
-						fclose($fp);
5444
+					if (!$keep_alive) {
5445
+											fclose($fp);
5446
+					}
5153 5447
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5154 5448
 				}
5155 5449
 			}
5156 5450
 
5157 5451
 			// Make sure we get a 200 OK.
5158
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5159
-				return false;
5452
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5453
+							return false;
5454
+			}
5160 5455
 
5161 5456
 			// Skip the headers...
5162 5457
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5163 5458
 			{
5164
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5165
-					$content_length = $match[1];
5166
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5459
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5460
+									$content_length = $match[1];
5461
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5167 5462
 				{
5168 5463
 					$keep_alive_dom = null;
5169 5464
 					$keep_alive = false;
@@ -5175,17 +5470,19 @@  discard block
 block discarded – undo
5175 5470
 			$data = '';
5176 5471
 			if (isset($content_length))
5177 5472
 			{
5178
-				while (!feof($fp) && strlen($data) < $content_length)
5179
-					$data .= fread($fp, $content_length - strlen($data));
5180
-			}
5181
-			else
5473
+				while (!feof($fp) && strlen($data) < $content_length) {
5474
+									$data .= fread($fp, $content_length - strlen($data));
5475
+				}
5476
+			} else
5182 5477
 			{
5183
-				while (!feof($fp))
5184
-					$data .= fread($fp, 4096);
5478
+				while (!feof($fp)) {
5479
+									$data .= fread($fp, 4096);
5480
+				}
5185 5481
 			}
5186 5482
 
5187
-			if (!$keep_alive)
5188
-				fclose($fp);
5483
+			if (!$keep_alive) {
5484
+							fclose($fp);
5485
+			}
5189 5486
 		}
5190 5487
 
5191 5488
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5198,17 +5495,18 @@  discard block
 block discarded – undo
5198 5495
 			$fetch_data->get_url_data($url, $post_data);
5199 5496
 
5200 5497
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5201
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5202
-				$data = $fetch_data->result('body');
5203
-			else
5204
-				return false;
5498
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5499
+							$data = $fetch_data->result('body');
5500
+			} else {
5501
+							return false;
5502
+			}
5205 5503
 		}
5206 5504
 
5207 5505
 		// Neither fsockopen nor curl are available. Well, phooey.
5208
-		else
5209
-			return false;
5210
-	}
5211
-	else
5506
+		else {
5507
+					return false;
5508
+		}
5509
+	} else
5212 5510
 	{
5213 5511
 		// Umm, this shouldn't happen?
5214 5512
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5228,8 +5526,9 @@  discard block
 block discarded – undo
5228 5526
 	global $user_info, $smcFunc;
5229 5527
 
5230 5528
 	// Make sure we have something to work with.
5231
-	if (empty($topic))
5232
-		return array();
5529
+	if (empty($topic)) {
5530
+			return array();
5531
+	}
5233 5532
 
5234 5533
 
5235 5534
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5252,8 +5551,9 @@  discard block
 block discarded – undo
5252 5551
 				'topic' => $topic,
5253 5552
 			)
5254 5553
 		);
5255
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5256
-			$temp[] = (int) $row['content_id'];
5554
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5555
+					$temp[] = (int) $row['content_id'];
5556
+		}
5257 5557
 
5258 5558
 		cache_put_data($cache_key, $temp, $ttl);
5259 5559
 	}
@@ -5274,8 +5574,9 @@  discard block
 block discarded – undo
5274 5574
 {
5275 5575
 	global $context;
5276 5576
 
5277
-	if (empty($string))
5278
-		return $string;
5577
+	if (empty($string)) {
5578
+			return $string;
5579
+	}
5279 5580
 
5280 5581
 	// UTF-8 occurences of MS special characters
5281 5582
 	$findchars_utf8 = array(
@@ -5316,10 +5617,11 @@  discard block
 block discarded – undo
5316 5617
 		'--',	// &mdash;
5317 5618
 	);
5318 5619
 
5319
-	if ($context['utf8'])
5320
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5321
-	else
5322
-		$string = str_replace($findchars_iso, $replacechars, $string);
5620
+	if ($context['utf8']) {
5621
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5622
+	} else {
5623
+			$string = str_replace($findchars_iso, $replacechars, $string);
5624
+	}
5323 5625
 
5324 5626
 	return $string;
5325 5627
 }
@@ -5338,49 +5640,59 @@  discard block
 block discarded – undo
5338 5640
 {
5339 5641
 	global $context;
5340 5642
 
5341
-	if (!isset($matches[2]))
5342
-		return '';
5643
+	if (!isset($matches[2])) {
5644
+			return '';
5645
+	}
5343 5646
 
5344 5647
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5345 5648
 
5346 5649
 	// remove left to right / right to left overrides
5347
-	if ($num === 0x202D || $num === 0x202E)
5348
-		return '';
5650
+	if ($num === 0x202D || $num === 0x202E) {
5651
+			return '';
5652
+	}
5349 5653
 
5350 5654
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5351
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5352
-		return '&#' . $num . ';';
5655
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5656
+			return '&#' . $num . ';';
5657
+	}
5353 5658
 
5354 5659
 	if (empty($context['utf8']))
5355 5660
 	{
5356 5661
 		// no control characters
5357
-		if ($num < 0x20)
5358
-			return '';
5662
+		if ($num < 0x20) {
5663
+					return '';
5664
+		}
5359 5665
 		// text is text
5360
-		elseif ($num < 0x80)
5361
-			return chr($num);
5666
+		elseif ($num < 0x80) {
5667
+					return chr($num);
5668
+		}
5362 5669
 		// all others get html-ised
5363
-		else
5364
-			return '&#' . $matches[2] . ';';
5365
-	}
5366
-	else
5670
+		else {
5671
+					return '&#' . $matches[2] . ';';
5672
+		}
5673
+	} else
5367 5674
 	{
5368 5675
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5369 5676
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5370
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5371
-			return '';
5677
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5678
+					return '';
5679
+		}
5372 5680
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5373
-		elseif ($num < 0x80)
5374
-			return chr($num);
5681
+		elseif ($num < 0x80) {
5682
+					return chr($num);
5683
+		}
5375 5684
 		// <0x800 (2048)
5376
-		elseif ($num < 0x800)
5377
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5685
+		elseif ($num < 0x800) {
5686
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5687
+		}
5378 5688
 		// < 0x10000 (65536)
5379
-		elseif ($num < 0x10000)
5380
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5689
+		elseif ($num < 0x10000) {
5690
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5691
+		}
5381 5692
 		// <= 0x10FFFF (1114111)
5382
-		else
5383
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5693
+		else {
5694
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5695
+		}
5384 5696
 	}
5385 5697
 }
5386 5698
 
@@ -5396,28 +5708,34 @@  discard block
 block discarded – undo
5396 5708
  */
5397 5709
 function fixchar__callback($matches)
5398 5710
 {
5399
-	if (!isset($matches[1]))
5400
-		return '';
5711
+	if (!isset($matches[1])) {
5712
+			return '';
5713
+	}
5401 5714
 
5402 5715
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5403 5716
 
5404 5717
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5405 5718
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5406
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5407
-		return '';
5719
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5720
+			return '';
5721
+	}
5408 5722
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5409
-	elseif ($num < 0x80)
5410
-		return chr($num);
5723
+	elseif ($num < 0x80) {
5724
+			return chr($num);
5725
+	}
5411 5726
 	// <0x800 (2048)
5412
-	elseif ($num < 0x800)
5413
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5727
+	elseif ($num < 0x800) {
5728
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5729
+	}
5414 5730
 	// < 0x10000 (65536)
5415
-	elseif ($num < 0x10000)
5416
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5731
+	elseif ($num < 0x10000) {
5732
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5733
+	}
5417 5734
 	// <= 0x10FFFF (1114111)
5418
-	else
5419
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5420
-}
5735
+	else {
5736
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5737
+	}
5738
+	}
5421 5739
 
5422 5740
 /**
5423 5741
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5430,17 +5748,19 @@  discard block
 block discarded – undo
5430 5748
  */
5431 5749
 function entity_fix__callback($matches)
5432 5750
 {
5433
-	if (!isset($matches[2]))
5434
-		return '';
5751
+	if (!isset($matches[2])) {
5752
+			return '';
5753
+	}
5435 5754
 
5436 5755
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5437 5756
 
5438 5757
 	// we don't allow control characters, characters out of range, byte markers, etc
5439
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5440
-		return '';
5441
-	else
5442
-		return '&#' . $num . ';';
5443
-}
5758
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5759
+			return '';
5760
+	} else {
5761
+			return '&#' . $num . ';';
5762
+	}
5763
+	}
5444 5764
 
5445 5765
 /**
5446 5766
  * Return a Gravatar URL based on
@@ -5464,18 +5784,23 @@  discard block
 block discarded – undo
5464 5784
 		$ratings = array('G', 'PG', 'R', 'X');
5465 5785
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5466 5786
 		$url_params = array();
5467
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5468
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5469
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5470
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5471
-		if (!empty($modSettings['avatar_max_width_external']))
5472
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5473
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5474
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5787
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5788
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5789
+		}
5790
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5791
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5792
+		}
5793
+		if (!empty($modSettings['avatar_max_width_external'])) {
5794
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5795
+		}
5796
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5797
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5475 5798
 				$size_string = $modSettings['avatar_max_height_external'];
5799
+		}
5476 5800
 
5477
-		if (!empty($size_string))
5478
-			$url_params[] = 's=' . $size_string;
5801
+		if (!empty($size_string)) {
5802
+					$url_params[] = 's=' . $size_string;
5803
+		}
5479 5804
 	}
5480 5805
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5481 5806
 
@@ -5494,22 +5819,26 @@  discard block
 block discarded – undo
5494 5819
 	static $timezones = null, $lastwhen = null;
5495 5820
 
5496 5821
 	// No point doing this over if we already did it once
5497
-	if (!empty($timezones) && $when == $lastwhen)
5498
-		return $timezones;
5499
-	else
5500
-		$lastwhen = $when;
5822
+	if (!empty($timezones) && $when == $lastwhen) {
5823
+			return $timezones;
5824
+	} else {
5825
+			$lastwhen = $when;
5826
+	}
5501 5827
 
5502 5828
 	// Parseable datetime string?
5503
-	if (is_int($timestamp = strtotime($when)))
5504
-		$when = $timestamp;
5829
+	if (is_int($timestamp = strtotime($when))) {
5830
+			$when = $timestamp;
5831
+	}
5505 5832
 
5506 5833
 	// A Unix timestamp?
5507
-	elseif (is_numeric($when))
5508
-		$when = intval($when);
5834
+	elseif (is_numeric($when)) {
5835
+			$when = intval($when);
5836
+	}
5509 5837
 
5510 5838
 	// Invalid value? Just get current Unix timestamp.
5511
-	else
5512
-		$when = time();
5839
+	else {
5840
+			$when = time();
5841
+	}
5513 5842
 
5514 5843
 	// We'll need these too
5515 5844
 	$date_when = date_create('@' . $when);
@@ -5524,8 +5853,9 @@  discard block
 block discarded – undo
5524 5853
 	foreach ($priority_countries as $country)
5525 5854
 	{
5526 5855
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5527
-		if (!empty($country_tzids))
5528
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5856
+		if (!empty($country_tzids)) {
5857
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5858
+		}
5529 5859
 	}
5530 5860
 
5531 5861
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5539,8 +5869,9 @@  discard block
 block discarded – undo
5539 5869
 	foreach ($tzids as $tzid)
5540 5870
 	{
5541 5871
 		// We don't want UTC right now
5542
-		if ($tzid == 'UTC')
5543
-			continue;
5872
+		if ($tzid == 'UTC') {
5873
+					continue;
5874
+		}
5544 5875
 
5545 5876
 		$tz = timezone_open($tzid);
5546 5877
 
@@ -5561,13 +5892,14 @@  discard block
 block discarded – undo
5561 5892
 		}
5562 5893
 
5563 5894
 		// A time zone from a prioritized country?
5564
-		if (in_array($tzid, $priority_tzids))
5565
-			$priority_zones[$tzkey] = true;
5895
+		if (in_array($tzid, $priority_tzids)) {
5896
+					$priority_zones[$tzkey] = true;
5897
+		}
5566 5898
 
5567 5899
 		// Keep track of the location and offset for this tzid
5568
-		if (!empty($txt[$tzid]))
5569
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5570
-		else
5900
+		if (!empty($txt[$tzid])) {
5901
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5902
+		} else
5571 5903
 		{
5572 5904
 			$tzid_parts = explode('/', $tzid);
5573 5905
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5587,23 +5919,27 @@  discard block
 block discarded – undo
5587 5919
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5588 5920
 
5589 5921
 		// Use the custom description, if there is one
5590
-		if (!empty($tztxt[$tzvalue['tzid']]))
5591
-			$desc = $tztxt[$tzvalue['tzid']];
5922
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5923
+					$desc = $tztxt[$tzvalue['tzid']];
5924
+		}
5592 5925
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5593
-		else
5594
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5926
+		else {
5927
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5928
+		}
5595 5929
 
5596 5930
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5597 5931
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5598 5932
 
5599
-		if (isset($priority_zones[$tzkey]))
5600
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5601
-		else
5602
-			$timezones[$tzvalue['tzid']] = $desc;
5933
+		if (isset($priority_zones[$tzkey])) {
5934
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5935
+		} else {
5936
+					$timezones[$tzvalue['tzid']] = $desc;
5937
+		}
5603 5938
 	}
5604 5939
 
5605
-	if (!empty($priority_timezones))
5606
-		$priority_timezones[] = '-----';
5940
+	if (!empty($priority_timezones)) {
5941
+			$priority_timezones[] = '-----';
5942
+	}
5607 5943
 
5608 5944
 	$timezones = array_merge(
5609 5945
 		$priority_timezones,
@@ -5620,8 +5956,9 @@  discard block
 block discarded – undo
5620 5956
  */
5621 5957
 function inet_ptod($ip_address)
5622 5958
 {
5623
-	if (!isValidIP($ip_address))
5624
-		return $ip_address;
5959
+	if (!isValidIP($ip_address)) {
5960
+			return $ip_address;
5961
+	}
5625 5962
 
5626 5963
 	$bin = inet_pton($ip_address);
5627 5964
 	return $bin;
@@ -5633,13 +5970,15 @@  discard block
 block discarded – undo
5633 5970
  */
5634 5971
 function inet_dtop($bin)
5635 5972
 {
5636
-	if(empty($bin))
5637
-		return '';
5973
+	if(empty($bin)) {
5974
+			return '';
5975
+	}
5638 5976
 
5639 5977
 	global $db_type;
5640 5978
 
5641
-	if ($db_type == 'postgresql')
5642
-		return $bin;
5979
+	if ($db_type == 'postgresql') {
5980
+			return $bin;
5981
+	}
5643 5982
 
5644 5983
 	$ip_address = inet_ntop($bin);
5645 5984
 
@@ -5664,26 +6003,32 @@  discard block
 block discarded – undo
5664 6003
  */
5665 6004
 function _safe_serialize($value)
5666 6005
 {
5667
-	if(is_null($value))
5668
-		return 'N;';
6006
+	if(is_null($value)) {
6007
+			return 'N;';
6008
+	}
5669 6009
 
5670
-	if(is_bool($value))
5671
-		return 'b:'. (int) $value .';';
6010
+	if(is_bool($value)) {
6011
+			return 'b:'. (int) $value .';';
6012
+	}
5672 6013
 
5673
-	if(is_int($value))
5674
-		return 'i:'. $value .';';
6014
+	if(is_int($value)) {
6015
+			return 'i:'. $value .';';
6016
+	}
5675 6017
 
5676
-	if(is_float($value))
5677
-		return 'd:'. str_replace(',', '.', $value) .';';
6018
+	if(is_float($value)) {
6019
+			return 'd:'. str_replace(',', '.', $value) .';';
6020
+	}
5678 6021
 
5679
-	if(is_string($value))
5680
-		return 's:'. strlen($value) .':"'. $value .'";';
6022
+	if(is_string($value)) {
6023
+			return 's:'. strlen($value) .':"'. $value .'";';
6024
+	}
5681 6025
 
5682 6026
 	if(is_array($value))
5683 6027
 	{
5684 6028
 		$out = '';
5685
-		foreach($value as $k => $v)
5686
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6029
+		foreach($value as $k => $v) {
6030
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6031
+		}
5687 6032
 
5688 6033
 		return 'a:'. count($value) .':{'. $out .'}';
5689 6034
 	}
@@ -5709,8 +6054,9 @@  discard block
 block discarded – undo
5709 6054
 
5710 6055
 	$out = _safe_serialize($value);
5711 6056
 
5712
-	if (isset($mbIntEnc))
5713
-		mb_internal_encoding($mbIntEnc);
6057
+	if (isset($mbIntEnc)) {
6058
+			mb_internal_encoding($mbIntEnc);
6059
+	}
5714 6060
 
5715 6061
 	return $out;
5716 6062
 }
@@ -5727,8 +6073,9 @@  discard block
 block discarded – undo
5727 6073
 function _safe_unserialize($str)
5728 6074
 {
5729 6075
 	// Input  is not a string.
5730
-	if(empty($str) || !is_string($str))
5731
-		return false;
6076
+	if(empty($str) || !is_string($str)) {
6077
+			return false;
6078
+	}
5732 6079
 
5733 6080
 	$stack = array();
5734 6081
 	$expected = array();
@@ -5744,43 +6091,38 @@  discard block
 block discarded – undo
5744 6091
 	while($state != 1)
5745 6092
 	{
5746 6093
 		$type = isset($str[0]) ? $str[0] : '';
5747
-		if($type == '}')
5748
-			$str = substr($str, 1);
5749
-
5750
-		else if($type == 'N' && $str[1] == ';')
6094
+		if($type == '}') {
6095
+					$str = substr($str, 1);
6096
+		} else if($type == 'N' && $str[1] == ';')
5751 6097
 		{
5752 6098
 			$value = null;
5753 6099
 			$str = substr($str, 2);
5754
-		}
5755
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6100
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5756 6101
 		{
5757 6102
 			$value = $matches[1] == '1' ? true : false;
5758 6103
 			$str = substr($str, 4);
5759
-		}
5760
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6104
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5761 6105
 		{
5762 6106
 			$value = (int)$matches[1];
5763 6107
 			$str = $matches[2];
5764
-		}
5765
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6108
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5766 6109
 		{
5767 6110
 			$value = (float)$matches[1];
5768 6111
 			$str = $matches[3];
5769
-		}
5770
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6112
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5771 6113
 		{
5772 6114
 			$value = substr($matches[2], 0, (int)$matches[1]);
5773 6115
 			$str = substr($matches[2], (int)$matches[1] + 2);
5774
-		}
5775
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6116
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5776 6117
 		{
5777 6118
 			$expectedLength = (int)$matches[1];
5778 6119
 			$str = $matches[2];
5779 6120
 		}
5780 6121
 
5781 6122
 		// Object or unknown/malformed type.
5782
-		else
5783
-			return false;
6123
+		else {
6124
+					return false;
6125
+		}
5784 6126
 
5785 6127
 		switch($state)
5786 6128
 		{
@@ -5808,8 +6150,9 @@  discard block
 block discarded – undo
5808 6150
 				if($type == '}')
5809 6151
 				{
5810 6152
 					// Array size is less than expected.
5811
-					if(count($list) < end($expected))
5812
-						return false;
6153
+					if(count($list) < end($expected)) {
6154
+											return false;
6155
+					}
5813 6156
 
5814 6157
 					unset($list);
5815 6158
 					$list = &$stack[count($stack)-1];
@@ -5818,8 +6161,9 @@  discard block
 block discarded – undo
5818 6161
 					// Go to terminal state if we're at the end of the root array.
5819 6162
 					array_pop($expected);
5820 6163
 
5821
-					if(count($expected) == 0)
5822
-						$state = 1;
6164
+					if(count($expected) == 0) {
6165
+											$state = 1;
6166
+					}
5823 6167
 
5824 6168
 					break;
5825 6169
 				}
@@ -5827,8 +6171,9 @@  discard block
 block discarded – undo
5827 6171
 				if($type == 'i' || $type == 's')
5828 6172
 				{
5829 6173
 					// Array size exceeds expected length.
5830
-					if(count($list) >= end($expected))
5831
-						return false;
6174
+					if(count($list) >= end($expected)) {
6175
+											return false;
6176
+					}
5832 6177
 
5833 6178
 					$key = $value;
5834 6179
 					$state = 3;
@@ -5862,8 +6207,9 @@  discard block
 block discarded – undo
5862 6207
 	}
5863 6208
 
5864 6209
 	// Trailing data in input.
5865
-	if(!empty($str))
5866
-		return false;
6210
+	if(!empty($str)) {
6211
+			return false;
6212
+	}
5867 6213
 
5868 6214
 	return $data;
5869 6215
 }
@@ -5886,8 +6232,9 @@  discard block
 block discarded – undo
5886 6232
 
5887 6233
 	$out = _safe_unserialize($str);
5888 6234
 
5889
-	if (isset($mbIntEnc))
5890
-		mb_internal_encoding($mbIntEnc);
6235
+	if (isset($mbIntEnc)) {
6236
+			mb_internal_encoding($mbIntEnc);
6237
+	}
5891 6238
 
5892 6239
 	return $out;
5893 6240
 }
@@ -5902,12 +6249,14 @@  discard block
 block discarded – undo
5902 6249
 function smf_chmod($file, $value = 0)
5903 6250
 {
5904 6251
 	// No file? no checks!
5905
-	if (empty($file))
5906
-		return false;
6252
+	if (empty($file)) {
6253
+			return false;
6254
+	}
5907 6255
 
5908 6256
 	// Already writable?
5909
-	if (is_writable($file))
5910
-		return true;
6257
+	if (is_writable($file)) {
6258
+			return true;
6259
+	}
5911 6260
 
5912 6261
 	// Do we have a file or a dir?
5913 6262
 	$isDir = is_dir($file);
@@ -5923,10 +6272,9 @@  discard block
 block discarded – undo
5923 6272
 		{
5924 6273
 			$isWritable = true;
5925 6274
 			break;
6275
+		} else {
6276
+					@chmod($file, $val);
5926 6277
 		}
5927
-
5928
-		else
5929
-			@chmod($file, $val);
5930 6278
 	}
5931 6279
 
5932 6280
 	return $isWritable;
@@ -5945,8 +6293,9 @@  discard block
 block discarded – undo
5945 6293
 	global $txt;
5946 6294
 
5947 6295
 	// Come on...
5948
-	if (empty($json) || !is_string($json))
5949
-		return array();
6296
+	if (empty($json) || !is_string($json)) {
6297
+			return array();
6298
+	}
5950 6299
 
5951 6300
 	$returnArray = @json_decode($json, $returnAsArray);
5952 6301
 
@@ -5984,11 +6333,11 @@  discard block
 block discarded – undo
5984 6333
 		$jsonDebug = $jsonDebug[0];
5985 6334
 		loadLanguage('Errors');
5986 6335
 
5987
-		if (!empty($jsonDebug))
5988
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5989
-
5990
-		else
5991
-			log_error($txt['json_'. $jsonError], 'critical');
6336
+		if (!empty($jsonDebug)) {
6337
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6338
+		} else {
6339
+					log_error($txt['json_'. $jsonError], 'critical');
6340
+		}
5992 6341
 
5993 6342
 		// Everyone expects an array.
5994 6343
 		return array();
@@ -6022,8 +6371,9 @@  discard block
 block discarded – undo
6022 6371
 	global $db_show_debug, $modSettings;
6023 6372
 
6024 6373
 	// Defensive programming anyone?
6025
-	if (empty($data))
6026
-		return false;
6374
+	if (empty($data)) {
6375
+			return false;
6376
+	}
6027 6377
 
6028 6378
 	// Don't need extra stuff...
6029 6379
 	$db_show_debug = false;
@@ -6031,11 +6381,11 @@  discard block
 block discarded – undo
6031 6381
 	// Kill anything else.
6032 6382
 	ob_end_clean();
6033 6383
 
6034
-	if (!empty($modSettings['CompressedOutput']))
6035
-		@ob_start('ob_gzhandler');
6036
-
6037
-	else
6038
-		ob_start();
6384
+	if (!empty($modSettings['CompressedOutput'])) {
6385
+			@ob_start('ob_gzhandler');
6386
+	} else {
6387
+			ob_start();
6388
+	}
6039 6389
 
6040 6390
 	// Set the header.
6041 6391
 	header($type);
@@ -6067,8 +6417,9 @@  discard block
 block discarded – undo
6067 6417
 	static $done = false;
6068 6418
 
6069 6419
 	// If we don't need to do anything, don't
6070
-	if (!$update && $done)
6071
-		return;
6420
+	if (!$update && $done) {
6421
+			return;
6422
+	}
6072 6423
 
6073 6424
 	// Should we get a new copy of the official list of TLDs?
6074 6425
 	if ($update)
@@ -6080,8 +6431,9 @@  discard block
 block discarded – undo
6080 6431
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6081 6432
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6082 6433
 		// update to see if civilization has been restored.
6083
-		if ($tlds === false)
6084
-			$postapocalypticNightmare = true;
6434
+		if ($tlds === false) {
6435
+					$postapocalypticNightmare = true;
6436
+		}
6085 6437
 	}
6086 6438
 	// If we aren't updating and the regex is valid, we're done
6087 6439
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6096,10 +6448,11 @@  discard block
 block discarded – undo
6096 6448
 		// Clean $tlds and convert it to an array
6097 6449
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6098 6450
 			$line = trim($line);
6099
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6100
-				return false;
6101
-			else
6102
-				return true;
6451
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6452
+							return false;
6453
+			} else {
6454
+							return true;
6455
+			}
6103 6456
 		});
6104 6457
 
6105 6458
 		// Convert Punycode to Unicode
@@ -6191,8 +6544,7 @@  discard block
 block discarded – undo
6191 6544
 
6192 6545
 		$strlen = 'mb_strlen';
6193 6546
 		$substr = 'mb_substr';
6194
-	}
6195
-	else
6547
+	} else
6196 6548
 	{
6197 6549
 		$strlen = $smcFunc['strlen'];
6198 6550
 		$substr = $smcFunc['substr'];
@@ -6206,20 +6558,21 @@  discard block
 block discarded – undo
6206 6558
 
6207 6559
 		$first = $substr($string, 0, 1);
6208 6560
 
6209
-		if (empty($index[$first]))
6210
-			$index[$first] = array();
6561
+		if (empty($index[$first])) {
6562
+					$index[$first] = array();
6563
+		}
6211 6564
 
6212 6565
 		if ($strlen($string) > 1)
6213 6566
 		{
6214 6567
 			// Sanity check on recursion
6215
-			if ($depth > 99)
6216
-				$index[$first][$substr($string, 1)] = '';
6217
-
6218
-			else
6219
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6568
+			if ($depth > 99) {
6569
+							$index[$first][$substr($string, 1)] = '';
6570
+			} else {
6571
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6572
+			}
6573
+		} else {
6574
+					$index[$first][''] = '';
6220 6575
 		}
6221
-		else
6222
-			$index[$first][''] = '';
6223 6576
 
6224 6577
 		$depth--;
6225 6578
 		return $index;
@@ -6242,9 +6595,9 @@  discard block
 block discarded – undo
6242 6595
 			$key_regex = preg_quote($key, $delim);
6243 6596
 			$new_key = $key;
6244 6597
 
6245
-			if (empty($value))
6246
-				$sub_regex = '';
6247
-			else
6598
+			if (empty($value)) {
6599
+							$sub_regex = '';
6600
+			} else
6248 6601
 			{
6249 6602
 				$sub_regex = $index_to_regex($value, $delim);
6250 6603
 
@@ -6252,22 +6605,22 @@  discard block
 block discarded – undo
6252 6605
 				{
6253 6606
 					$new_key_array = explode('(?'.'>', $sub_regex);
6254 6607
 					$new_key .= $new_key_array[0];
6608
+				} else {
6609
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6255 6610
 				}
6256
-				else
6257
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6258 6611
 			}
6259 6612
 
6260
-			if ($depth > 1)
6261
-				$regex[$new_key] = $key_regex . $sub_regex;
6262
-			else
6613
+			if ($depth > 1) {
6614
+							$regex[$new_key] = $key_regex . $sub_regex;
6615
+			} else
6263 6616
 			{
6264 6617
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6265 6618
 				{
6266 6619
 					$regex[$new_key] = $key_regex . $sub_regex;
6267 6620
 					unset($index[$key]);
6621
+				} else {
6622
+									break;
6268 6623
 				}
6269
-				else
6270
-					break;
6271 6624
 			}
6272 6625
 		}
6273 6626
 
@@ -6276,10 +6629,11 @@  discard block
 block discarded – undo
6276 6629
 			$l1 = $strlen($k1);
6277 6630
 			$l2 = $strlen($k2);
6278 6631
 
6279
-			if ($l1 == $l2)
6280
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6281
-			else
6282
-				return $l1 > $l2 ? -1 : 1;
6632
+			if ($l1 == $l2) {
6633
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6634
+			} else {
6635
+							return $l1 > $l2 ? -1 : 1;
6636
+			}
6283 6637
 		});
6284 6638
 
6285 6639
 		$depth--;
@@ -6290,21 +6644,24 @@  discard block
 block discarded – undo
6290 6644
 	$index = array();
6291 6645
 	$regex = '';
6292 6646
 
6293
-	foreach ($strings as $string)
6294
-		$index = $add_string_to_index($string, $index);
6647
+	foreach ($strings as $string) {
6648
+			$index = $add_string_to_index($string, $index);
6649
+	}
6295 6650
 
6296 6651
 	if ($returnArray === true)
6297 6652
 	{
6298 6653
 		$regex = array();
6299
-		while (!empty($index))
6300
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6654
+		while (!empty($index)) {
6655
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6656
+		}
6657
+	} else {
6658
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6301 6659
 	}
6302
-	else
6303
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6304 6660
 
6305 6661
 	// Restore PHP's internal character encoding to whatever it was originally
6306
-	if (!empty($current_encoding))
6307
-		mb_internal_encoding($current_encoding);
6662
+	if (!empty($current_encoding)) {
6663
+			mb_internal_encoding($current_encoding);
6664
+	}
6308 6665
 
6309 6666
 	return $regex;
6310 6667
 }
@@ -6347,13 +6704,15 @@  discard block
 block discarded – undo
6347 6704
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6348 6705
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6349 6706
 	$headers = @get_headers($url);
6350
-	if ($headers === false)
6351
-		return false;
6707
+	if ($headers === false) {
6708
+			return false;
6709
+	}
6352 6710
 
6353 6711
 	// Now to see if it came back https...
6354 6712
 	// First check for a redirect status code in first row (301, 302, 307)
6355
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6356
-		return false;
6713
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6714
+			return false;
6715
+	}
6357 6716
 
6358 6717
 	// Search for the location entry to confirm https
6359 6718
 	$result = false;
@@ -6391,8 +6750,7 @@  discard block
 block discarded – undo
6391 6750
 		$is_admin = $user_info['is_admin'];
6392 6751
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6393 6752
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6394
-	}
6395
-	else
6753
+	} else
6396 6754
 	{
6397 6755
 		$request = $smcFunc['db_query']('', '
6398 6756
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6406,17 +6764,19 @@  discard block
 block discarded – undo
6406 6764
 
6407 6765
 		$row = $smcFunc['db_fetch_assoc']($request);
6408 6766
 
6409
-		if (empty($row['additional_groups']))
6410
-			$groups = array($row['id_group'], $row['id_post_group']);
6411
-		else
6412
-			$groups = array_merge(
6767
+		if (empty($row['additional_groups'])) {
6768
+					$groups = array($row['id_group'], $row['id_post_group']);
6769
+		} else {
6770
+					$groups = array_merge(
6413 6771
 					array($row['id_group'], $row['id_post_group']),
6414 6772
 					explode(',', $row['additional_groups'])
6415 6773
 			);
6774
+		}
6416 6775
 
6417 6776
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6418
-		foreach ($groups as $k => $v)
6419
-			$groups[$k] = (int) $v;
6777
+		foreach ($groups as $k => $v) {
6778
+					$groups[$k] = (int) $v;
6779
+		}
6420 6780
 
6421 6781
 		$is_admin = in_array(1, $groups);
6422 6782
 
@@ -6433,8 +6793,9 @@  discard block
 block discarded – undo
6433 6793
 				'current_member' => $userid,
6434 6794
 			)
6435 6795
 		);
6436
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6437
-			$boards_mod[] = $row['id_board'];
6796
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6797
+					$boards_mod[] = $row['id_board'];
6798
+		}
6438 6799
 		$smcFunc['db_free_result']($request);
6439 6800
 
6440 6801
 		// Can any of the groups they're in moderate any of the boards?
@@ -6446,8 +6807,9 @@  discard block
 block discarded – undo
6446 6807
 				'groups' => $groups,
6447 6808
 			)
6448 6809
 		);
6449
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6450
-			$boards_mod[] = $row['id_board'];
6810
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6811
+					$boards_mod[] = $row['id_board'];
6812
+		}
6451 6813
 		$smcFunc['db_free_result']($request);
6452 6814
 
6453 6815
 		// Just in case we've got duplicates here...
@@ -6457,21 +6819,25 @@  discard block
 block discarded – undo
6457 6819
 	}
6458 6820
 
6459 6821
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6460
-	if ($is_admin)
6461
-		$query_part['query_see_board'] = '1=1';
6822
+	if ($is_admin) {
6823
+			$query_part['query_see_board'] = '1=1';
6824
+	}
6462 6825
 	// Otherwise just the groups in $user_info['groups'].
6463
-	else
6464
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6826
+	else {
6827
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6828
+	}
6465 6829
 
6466 6830
 	// Build the list of boards they WANT to see.
6467 6831
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6468 6832
 
6469 6833
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6470
-	if (empty($ignoreboards))
6471
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6834
+	if (empty($ignoreboards)) {
6835
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6836
+	}
6472 6837
 	// Ok I guess they don't want to see all the boards
6473
-	else
6474
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6838
+	else {
6839
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6840
+	}
6475 6841
 
6476 6842
 	return $query_part;
6477 6843
 }
@@ -6485,10 +6851,11 @@  discard block
 block discarded – undo
6485 6851
 {
6486 6852
 	$secure = false;
6487 6853
 
6488
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6489
-		$secure = true;
6490
-	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')
6491
-		$secure = true;
6854
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6855
+			$secure = true;
6856
+	} 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') {
6857
+			$secure = true;
6858
+	}
6492 6859
 
6493 6860
 	return $secure;
6494 6861
 }
@@ -6505,11 +6872,12 @@  discard block
 block discarded – undo
6505 6872
 {
6506 6873
 	$url = iri_to_url($iri);
6507 6874
 
6508
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6509
-		return $iri;
6510
-	else
6511
-		return false;
6512
-}
6875
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6876
+			return $iri;
6877
+	} else {
6878
+			return false;
6879
+	}
6880
+	}
6513 6881
 
6514 6882
 /**
6515 6883
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6552,8 +6920,9 @@  discard block
 block discarded – undo
6552 6920
 
6553 6921
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6554 6922
 
6555
-	if (empty($host))
6556
-		return $iri;
6923
+	if (empty($host)) {
6924
+			return $iri;
6925
+	}
6557 6926
 
6558 6927
 	// Convert the domain using the Punycode algorithm
6559 6928
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6589,8 +6958,9 @@  discard block
 block discarded – undo
6589 6958
 
6590 6959
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6591 6960
 
6592
-	if (empty($host))
6593
-		return $url;
6961
+	if (empty($host)) {
6962
+			return $url;
6963
+	}
6594 6964
 
6595 6965
 	// Decode the domain from Punycode
6596 6966
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6616,8 +6986,9 @@  discard block
 block discarded – undo
6616 6986
 {
6617 6987
 	global $user_info, $modSettings, $smcFunc, $txt;
6618 6988
 
6619
-	if (empty($modSettings['cron_last_checked']))
6620
-		$modSettings['cron_last_checked'] = 0;
6989
+	if (empty($modSettings['cron_last_checked'])) {
6990
+			$modSettings['cron_last_checked'] = 0;
6991
+	}
6621 6992
 
6622 6993
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6623 6994
 	{
@@ -6637,9 +7008,9 @@  discard block
 block discarded – undo
6637 7008
 			loadLanguage('ManageScheduledTasks');
6638 7009
 			log_error($txt['cron_not_working']);
6639 7010
 			updateSettings(array('cron_is_real_cron' => 0));
7011
+		} else {
7012
+					updateSettings(array('cron_last_checked' => time()));
6640 7013
 		}
6641
-		else
6642
-			updateSettings(array('cron_last_checked' => time()));
6643 7014
 	}
6644 7015
 }
6645 7016
 
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +403 added lines, -303 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
  * !!!Compatibility!!!
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 {
32 33
 	global $modSettings;
33 34
 
34
-	if (!$compat_mode)
35
-		return $text;
35
+	if (!$compat_mode) {
36
+			return $text;
37
+	}
36 38
 
37 39
 	// Turn line breaks back into br's.
38 40
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
50 52
 			{
51 53
 				// Value of 2 means we're inside the tag.
52
-				if ($i % 4 == 2)
53
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
54
+				if ($i % 4 == 2) {
55
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
56
+				}
54 57
 			}
55 58
 			// Put our humpty dumpty message back together again.
56 59
 			$text = implode('', $parts);
@@ -109,8 +112,9 @@  discard block
 block discarded – undo
109 112
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
110 113
 
111 114
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
112
-	if (isBrowser('webkit'))
113
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	if (isBrowser('webkit')) {
116
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
117
+	}
114 118
 
115 119
 	// If there's a trailing break get rid of it - Firefox tends to add one.
116 120
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -125,8 +129,9 @@  discard block
 block discarded – undo
125 129
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
126 130
 		{
127 131
 			// Value of 2 means we're inside the tag.
128
-			if ($i % 4 == 2)
129
-				$parts[$i] = strip_tags($parts[$i]);
132
+			if ($i % 4 == 2) {
133
+							$parts[$i] = strip_tags($parts[$i]);
134
+			}
130 135
 		}
131 136
 
132 137
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -152,18 +157,19 @@  discard block
 block discarded – undo
152 157
 			{
153 158
 				$found = array_search($file, $smileysto);
154 159
 				// Note the weirdness here is to stop double spaces between smileys.
155
-				if ($found)
156
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
157
-				else
158
-					$matches[1][$k] = '';
160
+				if ($found) {
161
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
162
+				} else {
163
+									$matches[1][$k] = '';
164
+				}
159 165
 			}
160
-		}
161
-		else
166
+		} else
162 167
 		{
163 168
 			// Load all the smileys.
164 169
 			$names = array();
165
-			foreach ($matches[1] as $file)
166
-				$names[] = $file;
170
+			foreach ($matches[1] as $file) {
171
+							$names[] = $file;
172
+			}
167 173
 			$names = array_unique($names);
168 174
 
169 175
 			if (!empty($names))
@@ -177,13 +183,15 @@  discard block
 block discarded – undo
177 183
 					)
178 184
 				);
179 185
 				$mappings = array();
180
-				while ($row = $smcFunc['db_fetch_assoc']($request))
181
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
187
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
188
+				}
182 189
 				$smcFunc['db_free_result']($request);
183 190
 
184
-				foreach ($matches[1] as $k => $file)
185
-					if (isset($mappings[$file]))
191
+				foreach ($matches[1] as $k => $file) {
192
+									if (isset($mappings[$file]))
186 193
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
194
+				}
187 195
 			}
188 196
 		}
189 197
 
@@ -195,8 +203,9 @@  discard block
 block discarded – undo
195 203
 	}
196 204
 
197 205
 	// Only try to buy more time if the client didn't quit.
198
-	if (connection_aborted() && $context['server']['is_apache'])
199
-		@apache_reset_timeout();
206
+	if (connection_aborted() && $context['server']['is_apache']) {
207
+			@apache_reset_timeout();
208
+	}
200 209
 
201 210
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
202 211
 	$replacement = '';
@@ -207,9 +216,9 @@  discard block
 block discarded – undo
207 216
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
208 217
 		{
209 218
 			// If it's being closed instantly, we can't deal with it...yet.
210
-			if ($matches[5] === '/')
211
-				continue;
212
-			else
219
+			if ($matches[5] === '/') {
220
+							continue;
221
+			} else
213 222
 			{
214 223
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
215 224
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -225,8 +234,9 @@  discard block
 block discarded – undo
225 234
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
226 235
 
227 236
 					// Something like 'font-weight: bold' is expected here.
228
-					if (strpos($clean_type_value_pair, ':') === false)
229
-						continue;
237
+					if (strpos($clean_type_value_pair, ':') === false) {
238
+											continue;
239
+					}
230 240
 
231 241
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
232 242
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -248,8 +258,7 @@  discard block
 block discarded – undo
248 258
 							{
249 259
 								$curCloseTags .= '[/u]';
250 260
 								$replacement .= '[u]';
251
-							}
252
-							elseif ($style_value == 'line-through')
261
+							} elseif ($style_value == 'line-through')
253 262
 							{
254 263
 								$curCloseTags .= '[/s]';
255 264
 								$replacement .= '[s]';
@@ -261,13 +270,11 @@  discard block
 block discarded – undo
261 270
 							{
262 271
 								$curCloseTags .= '[/left]';
263 272
 								$replacement .= '[left]';
264
-							}
265
-							elseif ($style_value == 'center')
273
+							} elseif ($style_value == 'center')
266 274
 							{
267 275
 								$curCloseTags .= '[/center]';
268 276
 								$replacement .= '[center]';
269
-							}
270
-							elseif ($style_value == 'right')
277
+							} elseif ($style_value == 'right')
271 278
 							{
272 279
 								$curCloseTags .= '[/right]';
273 280
 								$replacement .= '[right]';
@@ -289,8 +296,9 @@  discard block
 block discarded – undo
289 296
 
290 297
 						case 'font-size':
291 298
 							// Sometimes people put decimals where decimals should not be.
292
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
293
-								$style_value = $dec_matches[1] . $dec_matches[2];
299
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
300
+															$style_value = $dec_matches[1] . $dec_matches[2];
301
+							}
294 302
 
295 303
 							$curCloseTags .= '[/size]';
296 304
 							$replacement .= '[size=' . $style_value . ']';
@@ -298,8 +306,9 @@  discard block
 block discarded – undo
298 306
 
299 307
 						case 'font-family':
300 308
 							// Only get the first freaking font if there's a list!
301
-							if (strpos($style_value, ',') !== false)
302
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							if (strpos($style_value, ',') !== false) {
310
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
311
+							}
303 312
 
304 313
 							$curCloseTags .= '[/font]';
305 314
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -308,13 +317,15 @@  discard block
 block discarded – undo
308 317
 						// This is a hack for images with dimensions embedded.
309 318
 						case 'width':
310 319
 						case 'height':
311
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
312
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
321
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
322
+							}
313 323
 						break;
314 324
 
315 325
 						case 'list-style-type':
316
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
317
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
327
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
328
+							}
318 329
 						break;
319 330
 					}
320 331
 				}
@@ -327,18 +338,17 @@  discard block
 block discarded – undo
327 338
 				}
328 339
 
329 340
 				// If there's something that still needs closing, push it to the stack.
330
-				if (!empty($curCloseTags))
331
-					array_push($stack, array(
341
+				if (!empty($curCloseTags)) {
342
+									array_push($stack, array(
332 343
 							'element' => strtolower($curElement),
333 344
 							'closeTags' => $curCloseTags
334 345
 						)
335 346
 					);
336
-				elseif (!empty($extra_attr))
337
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				} elseif (!empty($extra_attr)) {
348
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
349
+				}
338 350
 			}
339
-		}
340
-
341
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
351
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
342 352
 		{
343 353
 			// Is this the element that we've been waiting for to be closed?
344 354
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -348,28 +358,32 @@  discard block
 block discarded – undo
348 358
 			}
349 359
 
350 360
 			// Must've been something else.
351
-			else
352
-				$replacement .= $part;
361
+			else {
362
+							$replacement .= $part;
363
+			}
353 364
 		}
354 365
 		// In all other cases, just add the part to the replacement.
355
-		else
356
-			$replacement .= $part;
366
+		else {
367
+					$replacement .= $part;
368
+		}
357 369
 	}
358 370
 
359 371
 	// Now put back the replacement in the text.
360 372
 	$text = $replacement;
361 373
 
362 374
 	// We are not finished yet, request more time.
363
-	if (connection_aborted() && $context['server']['is_apache'])
364
-		@apache_reset_timeout();
375
+	if (connection_aborted() && $context['server']['is_apache']) {
376
+			@apache_reset_timeout();
377
+	}
365 378
 
366 379
 	// Let's pull out any legacy alignments.
367 380
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
368 381
 	{
369 382
 		// Find the position in the text of this tag over again.
370 383
 		$start_pos = strpos($text, $matches[0]);
371
-		if ($start_pos === false)
372
-			break;
384
+		if ($start_pos === false) {
385
+					break;
386
+		}
373 387
 
374 388
 		// End tag?
375 389
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -383,8 +397,7 @@  discard block
 block discarded – undo
383 397
 
384 398
 			// Put the tags back into the body.
385 399
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
386
-		}
387
-		else
400
+		} else
388 401
 		{
389 402
 			// Just get rid of this evil tag.
390 403
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -397,8 +410,9 @@  discard block
 block discarded – undo
397 410
 		// Find the position of this again.
398 411
 		$start_pos = strpos($text, $matches[0]);
399 412
 		$end_pos = false;
400
-		if ($start_pos === false)
401
-			break;
413
+		if ($start_pos === false) {
414
+					break;
415
+		}
402 416
 
403 417
 		// This must have an end tag - and we must find the right one.
404 418
 		$lower_text = strtolower($text);
@@ -431,8 +445,9 @@  discard block
 block discarded – undo
431 445
 				break;
432 446
 			}
433 447
 		}
434
-		if ($end_pos === false)
435
-			break;
448
+		if ($end_pos === false) {
449
+					break;
450
+		}
436 451
 
437 452
 		// Now work out what the attributes are.
438 453
 		$attribs = fetchTagAttributes($matches[1]);
@@ -446,11 +461,11 @@  discard block
 block discarded – undo
446 461
 				$v = (int) trim($v);
447 462
 				$v = empty($v) ? 1 : $v;
448 463
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
464
+			} elseif ($s == 'face') {
465
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
466
+			} elseif ($s == 'color') {
467
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
449 468
 			}
450
-			elseif ($s == 'face')
451
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
452
-			elseif ($s == 'color')
453
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
454 469
 		}
455 470
 
456 471
 		// As before add in our tags.
@@ -458,8 +473,9 @@  discard block
 block discarded – undo
458 473
 		foreach ($tags as $tag)
459 474
 		{
460 475
 			$before .= $tag[0];
461
-			if (isset($tag[1]))
462
-				$after = $tag[1] . $after;
476
+			if (isset($tag[1])) {
477
+							$after = $tag[1] . $after;
478
+			}
463 479
 		}
464 480
 
465 481
 		// Remove the tag so it's never checked again.
@@ -470,8 +486,9 @@  discard block
 block discarded – undo
470 486
 	}
471 487
 
472 488
 	// Almost there, just a little more time.
473
-	if (connection_aborted() && $context['server']['is_apache'])
474
-		@apache_reset_timeout();
489
+	if (connection_aborted() && $context['server']['is_apache']) {
490
+			@apache_reset_timeout();
491
+	}
475 492
 
476 493
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
477 494
 	{
@@ -527,12 +544,13 @@  discard block
 block discarded – undo
527 544
 						{
528 545
 							$inList = true;
529 546
 
530
-							if ($tag === 'ol')
531
-								$listType = 'decimal';
532
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
533
-								$listType = $listTypeMapping[$match[1]];
534
-							else
535
-								$listType = null;
547
+							if ($tag === 'ol') {
548
+															$listType = 'decimal';
549
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
550
+															$listType = $listTypeMapping[$match[1]];
551
+							} else {
552
+															$listType = null;
553
+							}
536 554
 
537 555
 							$listDepth++;
538 556
 
@@ -596,9 +614,7 @@  discard block
 block discarded – undo
596 614
 							$parts[$i + 1] = '';
597 615
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
598 616
 							$parts[$i + 3] = '';
599
-						}
600
-
601
-						else
617
+						} else
602 618
 						{
603 619
 							// We're in a list item.
604 620
 							if ($listDepth > 0)
@@ -635,9 +651,7 @@  discard block
 block discarded – undo
635 651
 							$parts[$i + 1] = '';
636 652
 							$parts[$i + 2] = '';
637 653
 							$parts[$i + 3] = '';
638
-						}
639
-
640
-						else
654
+						} else
641 655
 						{
642 656
 							// Remove the trailing breaks from the list item.
643 657
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -675,8 +689,9 @@  discard block
 block discarded – undo
675 689
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
676 690
 		}
677 691
 
678
-		for ($i = $listDepth; $i > 0; $i--)
679
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		for ($i = $listDepth; $i > 0; $i--) {
693
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
694
+		}
680 695
 	}
681 696
 
682 697
 	// I love my own image...
@@ -684,8 +699,9 @@  discard block
 block discarded – undo
684 699
 	{
685 700
 		// Find the position of the image.
686 701
 		$start_pos = strpos($text, $matches[0]);
687
-		if ($start_pos === false)
688
-			break;
702
+		if ($start_pos === false) {
703
+					break;
704
+		}
689 705
 		$end_pos = $start_pos + strlen($matches[0]);
690 706
 
691 707
 		$params = '';
@@ -694,12 +710,13 @@  discard block
 block discarded – undo
694 710
 		$attrs = fetchTagAttributes($matches[1]);
695 711
 		foreach ($attrs as $attrib => $value)
696 712
 		{
697
-			if (in_array($attrib, array('width', 'height')))
698
-				$params .= ' ' . $attrib . '=' . (int) $value;
699
-			elseif ($attrib == 'alt' && trim($value) != '')
700
-				$params .= ' alt=' . trim($value);
701
-			elseif ($attrib == 'src')
702
-				$src = trim($value);
713
+			if (in_array($attrib, array('width', 'height'))) {
714
+							$params .= ' ' . $attrib . '=' . (int) $value;
715
+			} elseif ($attrib == 'alt' && trim($value) != '') {
716
+							$params .= ' alt=' . trim($value);
717
+			} elseif ($attrib == 'src') {
718
+							$src = trim($value);
719
+			}
703 720
 		}
704 721
 
705 722
 		$tag = '';
@@ -710,10 +727,11 @@  discard block
 block discarded – undo
710 727
 			{
711 728
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
712 729
 
713
-				if (substr($src, 0, 1) === '/')
714
-					$src = $baseURL . $src;
715
-				else
716
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
730
+				if (substr($src, 0, 1) === '/') {
731
+									$src = $baseURL . $src;
732
+				} else {
733
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
734
+				}
717 735
 			}
718 736
 
719 737
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -891,20 +909,23 @@  discard block
 block discarded – undo
891 909
 		},
892 910
 	);
893 911
 
894
-	foreach ($tags as $tag => $replace)
895
-		$text = preg_replace_callback($tag, $replace, $text);
912
+	foreach ($tags as $tag => $replace) {
913
+			$text = preg_replace_callback($tag, $replace, $text);
914
+	}
896 915
 
897 916
 	// Please give us just a little more time.
898
-	if (connection_aborted() && $context['server']['is_apache'])
899
-		@apache_reset_timeout();
917
+	if (connection_aborted() && $context['server']['is_apache']) {
918
+			@apache_reset_timeout();
919
+	}
900 920
 
901 921
 	// What about URL's - the pain in the ass of the tag world.
902 922
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
903 923
 	{
904 924
 		// Find the position of the URL.
905 925
 		$start_pos = strpos($text, $matches[0]);
906
-		if ($start_pos === false)
907
-			break;
926
+		if ($start_pos === false) {
927
+					break;
928
+		}
908 929
 		$end_pos = $start_pos + strlen($matches[0]);
909 930
 
910 931
 		$tag_type = 'url';
@@ -918,8 +939,9 @@  discard block
 block discarded – undo
918 939
 				$href = trim($value);
919 940
 
920 941
 				// Are we dealing with an FTP link?
921
-				if (preg_match('~^ftps?://~', $href) === 1)
922
-					$tag_type = 'ftp';
942
+				if (preg_match('~^ftps?://~', $href) === 1) {
943
+									$tag_type = 'ftp';
944
+				}
923 945
 
924 946
 				// Or is this a link to an email address?
925 947
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -933,28 +955,31 @@  discard block
 block discarded – undo
933 955
 				{
934 956
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
935 957
 
936
-					if (substr($href, 0, 1) === '/')
937
-						$href = $baseURL . $href;
938
-					else
939
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
958
+					if (substr($href, 0, 1) === '/') {
959
+											$href = $baseURL . $href;
960
+					} else {
961
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
962
+					}
940 963
 				}
941 964
 			}
942 965
 
943 966
 			// External URL?
944 967
 			if ($attrib == 'target' && $tag_type == 'url')
945 968
 			{
946
-				if (trim($value) == '_blank')
947
-					$tag_type == 'iurl';
969
+				if (trim($value) == '_blank') {
970
+									$tag_type == 'iurl';
971
+				}
948 972
 			}
949 973
 		}
950 974
 
951 975
 		$tag = '';
952 976
 		if ($href != '')
953 977
 		{
954
-			if ($matches[2] == $href)
955
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
956
-			else
957
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
978
+			if ($matches[2] == $href) {
979
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
980
+			} else {
981
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
982
+			}
958 983
 		}
959 984
 
960 985
 		// Replace the tag
@@ -994,17 +1019,18 @@  discard block
 block discarded – undo
994 1019
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
995 1020
 		if ($text[$i] == '=')
996 1021
 		{
997
-			if ($tag_state == 0)
998
-				$tag_state = 1;
999
-			elseif ($tag_state == 2)
1000
-				$value .= '=';
1022
+			if ($tag_state == 0) {
1023
+							$tag_state = 1;
1024
+			} elseif ($tag_state == 2) {
1025
+							$value .= '=';
1026
+			}
1001 1027
 		}
1002 1028
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1003 1029
 		elseif ($text[$i] == ' ')
1004 1030
 		{
1005
-			if ($tag_state == 2)
1006
-				$value .= ' ';
1007
-			elseif ($tag_state == 1)
1031
+			if ($tag_state == 2) {
1032
+							$value .= ' ';
1033
+			} elseif ($tag_state == 1)
1008 1034
 			{
1009 1035
 				$attribs[$key] = $value;
1010 1036
 				$key = $value = '';
@@ -1015,24 +1041,27 @@  discard block
 block discarded – undo
1015 1041
 		elseif ($text[$i] == '"')
1016 1042
 		{
1017 1043
 			// Must be either going into or out of a string.
1018
-			if ($tag_state == 1)
1019
-				$tag_state = 2;
1020
-			else
1021
-				$tag_state = 1;
1044
+			if ($tag_state == 1) {
1045
+							$tag_state = 2;
1046
+			} else {
1047
+							$tag_state = 1;
1048
+			}
1022 1049
 		}
1023 1050
 		// Otherwise it's fine.
1024 1051
 		else
1025 1052
 		{
1026
-			if ($tag_state == 0)
1027
-				$key .= $text[$i];
1028
-			else
1029
-				$value .= $text[$i];
1053
+			if ($tag_state == 0) {
1054
+							$key .= $text[$i];
1055
+			} else {
1056
+							$value .= $text[$i];
1057
+			}
1030 1058
 		}
1031 1059
 	}
1032 1060
 
1033 1061
 	// Anything left?
1034
-	if ($key != '' && $value != '')
1035
-		$attribs[$key] = $value;
1062
+	if ($key != '' && $value != '') {
1063
+			$attribs[$key] = $value;
1064
+	}
1036 1065
 
1037 1066
 	return $attribs;
1038 1067
 }
@@ -1050,8 +1079,9 @@  discard block
 block discarded – undo
1050 1079
 	global $modSettings;
1051 1080
 
1052 1081
 	// Don't care about the texts that are too short.
1053
-	if (strlen($text) < 3)
1054
-		return $text;
1082
+	if (strlen($text) < 3) {
1083
+			return $text;
1084
+	}
1055 1085
 
1056 1086
 	// A list of tags that's disabled by the admin.
1057 1087
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
@@ -1062,10 +1092,12 @@  discard block
 block discarded – undo
1062 1092
 	$self_closing_tags = array();
1063 1093
 	foreach ($all_tags as $tag)
1064 1094
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1095
+		if (!isset($disabled[$tag['tag']])) {
1096
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1097
+		}
1098
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1099
+					$self_closing_tags[] = $tag['tag'];
1100
+		}
1069 1101
 	}
1070 1102
 
1071 1103
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1092,16 +1124,19 @@  discard block
 block discarded – undo
1092 1124
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1125
 
1094 1126
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1127
+				if ($isClosingTag && $insideTag === $tagName) {
1128
+									$insideTag = null;
1129
+				}
1097 1130
 
1098 1131
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1132
+				elseif (!$isClosingTag && $insideTag === null) {
1133
+									$insideTag = $tagName;
1134
+				}
1101 1135
 
1102 1136
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1137
+				else {
1138
+									unset($matches[$i]);
1139
+				}
1105 1140
 			}
1106 1141
 
1107 1142
 			// The next one is gonna be the other one.
@@ -1109,8 +1144,9 @@  discard block
 block discarded – undo
1109 1144
 		}
1110 1145
 
1111 1146
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1147
+		if ($insideTag !== null) {
1148
+					$matches[] = '[/' . $insideTag . ']';
1149
+		}
1114 1150
 
1115 1151
 		// And a complete text string again.
1116 1152
 		$text = implode('', $matches);
@@ -1119,8 +1155,9 @@  discard block
 block discarded – undo
1119 1155
 	// Quickly remove any tags which are back to back.
1120 1156
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1157
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1158
+	while (strlen($text) !== $lastlen) {
1159
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1160
+	}
1124 1161
 
1125 1162
 	// Need to sort the tags my name length.
1126 1163
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1194,9 @@  discard block
 block discarded – undo
1157 1194
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1195
 
1159 1196
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1197
+			if ($tag === '') {
1198
+							continue;
1199
+			}
1162 1200
 
1163 1201
 			// Special case: inside [code] blocks any code is left untouched.
1164 1202
 			elseif ($tag === 'code')
@@ -1169,8 +1207,9 @@  discard block
 block discarded – undo
1169 1207
 					$inCode = false;
1170 1208
 
1171 1209
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1210
+					if (!empty($inlineElements)) {
1211
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1212
+					}
1174 1213
 				}
1175 1214
 
1176 1215
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1238,9 @@  discard block
 block discarded – undo
1199 1238
 					$inNoBbc = false;
1200 1239
 
1201 1240
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1241
+					if (!empty($inlineElements)) {
1242
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1243
+					}
1204 1244
 				}
1205 1245
 
1206 1246
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1260,9 @@  discard block
 block discarded – undo
1220 1260
 			}
1221 1261
 
1222 1262
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1263
+			elseif ($inCode || $inNoBbc) {
1264
+							continue;
1265
+			}
1225 1266
 
1226 1267
 			// We're dealing with an opening tag.
1227 1268
 			if ($isOpeningTag)
@@ -1262,8 +1303,9 @@  discard block
 block discarded – undo
1262 1303
 							if ($parts[$j + 3] === $tag)
1263 1304
 							{
1264 1305
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1306
+								if ($parts[$j + 2] === '') {
1307
+																	$curLevel++;
1308
+								}
1267 1309
 
1268 1310
 								// A closing tag, decrease the level.
1269 1311
 								else
@@ -1286,13 +1328,15 @@  discard block
 block discarded – undo
1286 1328
 					{
1287 1329
 						if ($isCompetingTag)
1288 1330
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1331
+							if (!isset($competingElements[$tag])) {
1332
+															$competingElements[$tag] = array();
1333
+							}
1291 1334
 
1292 1335
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1336
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1337
+							if (count($competingElements[$tag]) > 1) {
1338
+															$parts[$i] .= '[/' . $tag . ']';
1339
+							}
1296 1340
 						}
1297 1341
 
1298 1342
 						$inlineElements[$elementContent] = $tag;
@@ -1312,15 +1356,17 @@  discard block
 block discarded – undo
1312 1356
 						$addClosingTags = array();
1313 1357
 						while ($element = array_pop($blockElements))
1314 1358
 						{
1315
-							if ($element === $tag)
1316
-								break;
1359
+							if ($element === $tag) {
1360
+															break;
1361
+							}
1317 1362
 
1318 1363
 							// Still a block tag was open not equal to this tag.
1319 1364
 							$addClosingTags[] = $element['type'];
1320 1365
 						}
1321 1366
 
1322
-						if (!empty($addClosingTags))
1323
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1367
+						if (!empty($addClosingTags)) {
1368
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						}
1324 1370
 
1325 1371
 						// Apparently the closing tag was not found on the stack.
1326 1372
 						if (!is_string($element) || $element !== $tag)
@@ -1330,8 +1376,7 @@  discard block
 block discarded – undo
1330 1376
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1331 1377
 							continue;
1332 1378
 						}
1333
-					}
1334
-					else
1379
+					} else
1335 1380
 					{
1336 1381
 						// Get rid of this closing tag!
1337 1382
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1360,53 +1405,62 @@  discard block
 block discarded – undo
1360 1405
 							unset($inlineElements[$tagContentToBeClosed]);
1361 1406
 
1362 1407
 							// Was this the tag we were looking for?
1363
-							if ($tagToBeClosed === $tag)
1364
-								break;
1408
+							if ($tagToBeClosed === $tag) {
1409
+															break;
1410
+							}
1365 1411
 
1366 1412
 							// Nope, close it and look further!
1367
-							else
1368
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1413
+							else {
1414
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							}
1369 1416
 						}
1370 1417
 
1371 1418
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1372 1419
 						{
1373 1420
 							array_pop($competingElements[$tag]);
1374 1421
 
1375
-							if (count($competingElements[$tag]) > 0)
1376
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1422
+							if (count($competingElements[$tag]) > 0) {
1423
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							}
1377 1425
 						}
1378 1426
 					}
1379 1427
 
1380 1428
 					// Unexpected closing tag, ex-ter-mi-nate.
1381
-					else
1382
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1429
+					else {
1430
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					}
1383 1432
 				}
1384 1433
 			}
1385 1434
 		}
1386 1435
 
1387 1436
 		// Close the code tags.
1388
-		if ($inCode)
1389
-			$parts[$i] .= '[/code]';
1437
+		if ($inCode) {
1438
+					$parts[$i] .= '[/code]';
1439
+		}
1390 1440
 
1391 1441
 		// The same for nobbc tags.
1392
-		elseif ($inNoBbc)
1393
-			$parts[$i] .= '[/nobbc]';
1442
+		elseif ($inNoBbc) {
1443
+					$parts[$i] .= '[/nobbc]';
1444
+		}
1394 1445
 
1395 1446
 		// Still inline tags left unclosed? Close them now, better late than never.
1396
-		elseif (!empty($inlineElements))
1397
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1447
+		elseif (!empty($inlineElements)) {
1448
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		}
1398 1450
 
1399 1451
 		// Now close the block elements.
1400
-		if (!empty($blockElements))
1401
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1452
+		if (!empty($blockElements)) {
1453
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		}
1402 1455
 
1403 1456
 		$text = implode('', $parts);
1404 1457
 	}
1405 1458
 
1406 1459
 	// Final clean up of back to back tags.
1407 1460
 	$lastlen = 0;
1408
-	while (strlen($text) !== $lastlen)
1409
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1461
+	while (strlen($text) !== $lastlen) {
1462
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	}
1410 1464
 
1411 1465
 	return $text;
1412 1466
 }
@@ -1437,22 +1491,25 @@  discard block
 block discarded – undo
1437 1491
 	$context['template_layers'] = array();
1438 1492
 	// Lets make sure we aren't going to output anything nasty.
1439 1493
 	@ob_end_clean();
1440
-	if (!empty($modSettings['enableCompressedOutput']))
1441
-		@ob_start('ob_gzhandler');
1442
-	else
1443
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1444 1499
 
1445 1500
 	// If we don't have any locale better avoid broken js
1446
-	if (empty($txt['lang_locale']))
1447
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1448 1504
 
1449 1505
 	$file_data = '(function ($) {
1450 1506
 	\'use strict\';
1451 1507
 
1452 1508
 	$.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {';
1453
-	foreach ($editortxt as $key => $val)
1454
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1455 1511
 		' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ',';
1512
+	}
1456 1513
 
1457 1514
 	$file_data .= '
1458 1515
 		dateFormat: "day.month.year"
@@ -1520,8 +1577,9 @@  discard block
 block discarded – undo
1520 1577
 				)
1521 1578
 			);
1522 1579
 			$icon_data = array();
1523
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1524
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1525 1583
 			$smcFunc['db_free_result']($request);
1526 1584
 
1527 1585
 			$icons = array();
@@ -1536,9 +1594,9 @@  discard block
 block discarded – undo
1536 1594
 			}
1537 1595
 
1538 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1539 1599
 		}
1540
-		else
1541
-			$icons = $temp;
1542 1600
 	}
1543 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1544 1602
 
@@ -1581,8 +1639,9 @@  discard block
 block discarded – undo
1581 1639
 	{
1582 1640
 		// Some general stuff.
1583 1641
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1584
-		if (!empty($context['drafts_autosave']))
1585
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1642
+		if (!empty($context['drafts_autosave'])) {
1643
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1644
+		}
1586 1645
 
1587 1646
 		// This really has some WYSIWYG stuff.
1588 1647
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1599,8 +1658,9 @@  discard block
 block discarded – undo
1599 1658
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1600 1659
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1601 1660
 		// editor language file
1602
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1603
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1661
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1662
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1663
+		}
1604 1664
 
1605 1665
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1606 1666
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1609,11 +1669,12 @@  discard block
 block discarded – undo
1609 1669
 			loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck');
1610 1670
 
1611 1671
 			// Some hidden information is needed in order to make the spell checking work.
1612
-			if (!isset($_REQUEST['xml']))
1613
-				$context['insert_after_template'] .= '
1672
+			if (!isset($_REQUEST['xml'])) {
1673
+							$context['insert_after_template'] .= '
1614 1674
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1615 1675
 			<input type="hidden" name="spellstring" value="">
1616 1676
 		</form>';
1677
+			}
1617 1678
 		}
1618 1679
 	}
1619 1680
 
@@ -1805,8 +1866,9 @@  discard block
 block discarded – undo
1805 1866
 
1806 1867
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1807 1868
 		$disabled_tags = array();
1808
-		if (!empty($modSettings['disabledBBC']))
1809
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1869
+		if (!empty($modSettings['disabledBBC'])) {
1870
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1871
+		}
1810 1872
 
1811 1873
 		foreach ($disabled_tags as $tag)
1812 1874
 		{
@@ -1818,9 +1880,10 @@  discard block
 block discarded – undo
1818 1880
 				$context['disabled_tags']['orderedlist'] = true;
1819 1881
 			}
1820 1882
 
1821
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1822
-				if ($tag === $thisTag)
1883
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1884
+							if ($tag === $thisTag)
1823 1885
 					$context['disabled_tags'][$tagNameBBC] = true;
1886
+			}
1824 1887
 
1825 1888
 			$context['disabled_tags'][$tag] = true;
1826 1889
 		}
@@ -1831,8 +1894,9 @@  discard block
 block discarded – undo
1831 1894
 
1832 1895
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1833 1896
 		{
1834
-			if (!isset($context['bbc_toolbar'][$row]))
1835
-				$context['bbc_toolbar'][$row] = array();
1897
+			if (!isset($context['bbc_toolbar'][$row])) {
1898
+							$context['bbc_toolbar'][$row] = array();
1899
+			}
1836 1900
 
1837 1901
 			$tagsRow = array();
1838 1902
 
@@ -1868,20 +1932,21 @@  discard block
 block discarded – undo
1868 1932
 
1869 1933
 					$context['bbcodes_handlers'] .= '
1870 1934
 						});';
1871
-				}
1872
-				else
1935
+				} else
1873 1936
 				{
1874 1937
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1875 1938
 					$tagsRow = array();
1876 1939
 				}
1877 1940
 			}
1878 1941
 
1879
-			if (!empty($tagsRow))
1880
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1942
+			if (!empty($tagsRow)) {
1943
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1944
+			}
1881 1945
 		}
1882 1946
 
1883
-		if (!empty($bbcodes_styles))
1884
-			addInlineCss($bbcodes_styles);
1947
+		if (!empty($bbcodes_styles)) {
1948
+					addInlineCss($bbcodes_styles);
1949
+		}
1885 1950
 	}
1886 1951
 
1887 1952
 	// Initialize smiley array... if not loaded before.
@@ -1893,8 +1958,8 @@  discard block
 block discarded – undo
1893 1958
 		);
1894 1959
 
1895 1960
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1896
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1897
-			$context['smileys']['postform'][] = array(
1961
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1962
+					$context['smileys']['postform'][] = array(
1898 1963
 				'smileys' => array(
1899 1964
 					array(
1900 1965
 						'code' => ':)',
@@ -1980,7 +2045,7 @@  discard block
 block discarded – undo
1980 2045
 				),
1981 2046
 				'isLast' => true,
1982 2047
 			);
1983
-		elseif ($user_info['smiley_set'] != 'none')
2048
+		} elseif ($user_info['smiley_set'] != 'none')
1984 2049
 		{
1985 2050
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1986 2051
 			{
@@ -2003,17 +2068,19 @@  discard block
 block discarded – undo
2003 2068
 
2004 2069
 				foreach ($context['smileys'] as $section => $smileyRows)
2005 2070
 				{
2006
-					foreach ($smileyRows as $rowIndex => $smileys)
2007
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2071
+					foreach ($smileyRows as $rowIndex => $smileys) {
2072
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2073
+					}
2008 2074
 
2009
-					if (!empty($smileyRows))
2010
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2075
+					if (!empty($smileyRows)) {
2076
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2077
+					}
2011 2078
 				}
2012 2079
 
2013 2080
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2081
+			} else {
2082
+							$context['smileys'] = $temp;
2014 2083
 			}
2015
-			else
2016
-				$context['smileys'] = $temp;
2017 2084
 		}
2018 2085
 	}
2019 2086
 
@@ -2029,12 +2096,15 @@  discard block
 block discarded – undo
2029 2096
 		'plugins' => 'undo',
2030 2097
 		'bbcodeTrim' => true,
2031 2098
 	);
2032
-	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale']))
2033
-		$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2034
-	if (!empty($context['right_to_left']))
2035
-		$sce_options['rtl'] = true;
2036
-	if ($editorOptions['id'] != 'quickReply')
2037
-		$sce_options['autofocus'] = true;
2099
+	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) {
2100
+			$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2101
+	}
2102
+	if (!empty($context['right_to_left'])) {
2103
+			$sce_options['rtl'] = true;
2104
+	}
2105
+	if ($editorOptions['id'] != 'quickReply') {
2106
+			$sce_options['autofocus'] = true;
2107
+	}
2038 2108
 
2039 2109
 	$sce_options['emoticons'] = array();
2040 2110
 	$sce_options['emoticonsDescriptions'] = array();
@@ -2051,10 +2121,11 @@  discard block
 block discarded – undo
2051 2121
 			$countLocations--;
2052 2122
 
2053 2123
 			unset($smiley_location);
2054
-			if ($location == 'postform')
2055
-				$smiley_location = &$sce_options['emoticons']['dropdown'];
2056
-			elseif ($location == 'popup')
2057
-				$smiley_location = &$sce_options['emoticons']['popup'];
2124
+			if ($location == 'postform') {
2125
+							$smiley_location = &$sce_options['emoticons']['dropdown'];
2126
+			} elseif ($location == 'popup') {
2127
+							$smiley_location = &$sce_options['emoticons']['popup'];
2128
+			}
2058 2129
 
2059 2130
 			$numRows = count($smileyRows);
2060 2131
 
@@ -2068,8 +2139,9 @@  discard block
 block discarded – undo
2068 2139
 					$sce_options['emoticonsDescriptions'][$smiley['code']] = $smiley['description'];
2069 2140
 				}
2070 2141
 
2071
-				if (empty($smileyRow['isLast']) && $numRows != 1)
2072
-					$smiley_location['-' . $emptyPlaceholder++] = '';
2142
+				if (empty($smileyRow['isLast']) && $numRows != 1) {
2143
+									$smiley_location['-' . $emptyPlaceholder++] = '';
2144
+				}
2073 2145
 			}
2074 2146
 		}
2075 2147
 	}
@@ -2084,8 +2156,9 @@  discard block
 block discarded – undo
2084 2156
 
2085 2157
 			$count_tags--;
2086 2158
 
2087
-			if (!empty($count_tags))
2088
-				$sce_options['toolbar'] .= '||';
2159
+			if (!empty($count_tags)) {
2160
+							$sce_options['toolbar'] .= '||';
2161
+			}
2089 2162
 		}
2090 2163
 	}
2091 2164
 
@@ -2113,8 +2186,9 @@  discard block
 block discarded – undo
2113 2186
 		loadTemplate('GenericControls');
2114 2187
 
2115 2188
 		// Some javascript ma'am?
2116
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2117
-			loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2189
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2190
+					loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2191
+		}
2118 2192
 
2119 2193
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2120 2194
 
@@ -2127,8 +2201,8 @@  discard block
 block discarded – undo
2127 2201
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2128 2202
 
2129 2203
 	// Log this into our collection.
2130
-	if ($isNew)
2131
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2204
+	if ($isNew) {
2205
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2132 2206
 			'id' => $verificationOptions['id'],
2133 2207
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2134 2208
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2139,13 +2213,15 @@  discard block
 block discarded – undo
2139 2213
 			'questions' => array(),
2140 2214
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2141 2215
 		);
2216
+	}
2142 2217
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2143 2218
 
2144 2219
 	// Is there actually going to be anything?
2145
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2146
-		return false;
2147
-	elseif (!$isNew && !$do_test)
2148
-		return true;
2220
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2221
+			return false;
2222
+	} elseif (!$isNew && !$do_test) {
2223
+			return true;
2224
+	}
2149 2225
 
2150 2226
 	// Sanitize reCAPTCHA fields?
2151 2227
 	if ($thisVerification['can_recaptcha'])
@@ -2158,11 +2234,12 @@  discard block
 block discarded – undo
2158 2234
 	}
2159 2235
 
2160 2236
 	// Add javascript for the object.
2161
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2162
-		$context['insert_after_template'] .= '
2237
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2238
+			$context['insert_after_template'] .= '
2163 2239
 			<script>
2164 2240
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2165 2241
 			</script>';
2242
+	}
2166 2243
 
2167 2244
 	// If we want questions do we have a cache of all the IDs?
2168 2245
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2185,8 +2262,9 @@  discard block
 block discarded – undo
2185 2262
 				unset ($row['id_question']);
2186 2263
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2187 2264
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2188
-				foreach ($row['answers'] as $k => $v)
2189
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2265
+				foreach ($row['answers'] as $k => $v) {
2266
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2267
+				}
2190 2268
 
2191 2269
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2192 2270
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2197,35 +2275,42 @@  discard block
 block discarded – undo
2197 2275
 		}
2198 2276
 	}
2199 2277
 
2200
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2201
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2278
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2279
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2280
+	}
2202 2281
 
2203 2282
 	// Do we need to refresh the verification?
2204
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2205
-		$force_refresh = true;
2206
-	else
2207
-		$force_refresh = false;
2283
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2284
+			$force_refresh = true;
2285
+	} else {
2286
+			$force_refresh = false;
2287
+	}
2208 2288
 
2209 2289
 	// This can also force a fresh, although unlikely.
2210
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2211
-		$force_refresh = true;
2290
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2291
+			$force_refresh = true;
2292
+	}
2212 2293
 
2213 2294
 	$verification_errors = array();
2214 2295
 	// Start with any testing.
2215 2296
 	if ($do_test)
2216 2297
 	{
2217 2298
 		// This cannot happen!
2218
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2219
-			fatal_lang_error('no_access', false);
2299
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2300
+					fatal_lang_error('no_access', false);
2301
+		}
2220 2302
 		// ... nor this!
2221
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2222
-			fatal_lang_error('no_access', false);
2303
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2304
+					fatal_lang_error('no_access', false);
2305
+		}
2223 2306
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2224
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2225
-			fatal_lang_error('no_access', false);
2307
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2308
+					fatal_lang_error('no_access', false);
2309
+		}
2226 2310
 		// While we're here, did the user do something bad?
2227
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2228
-			$verification_errors[] = 'wrong_verification_answer';
2311
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2312
+					$verification_errors[] = 'wrong_verification_answer';
2313
+		}
2229 2314
 
2230 2315
 		if ($thisVerification['can_recaptcha'])
2231 2316
 		{
@@ -2236,22 +2321,25 @@  discard block
 block discarded – undo
2236 2321
 			{
2237 2322
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2238 2323
 
2239
-				if (!$resp->isSuccess())
2240
-					$verification_errors[] = 'wrong_verification_code';
2324
+				if (!$resp->isSuccess()) {
2325
+									$verification_errors[] = 'wrong_verification_code';
2326
+				}
2327
+			} else {
2328
+							$verification_errors[] = 'wrong_verification_code';
2241 2329
 			}
2242
-			else
2243
-				$verification_errors[] = 'wrong_verification_code';
2244 2330
 		}
2245
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2246
-			$verification_errors[] = 'wrong_verification_code';
2331
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2332
+					$verification_errors[] = 'wrong_verification_code';
2333
+		}
2247 2334
 		if ($thisVerification['number_questions'])
2248 2335
 		{
2249 2336
 			$incorrectQuestions = array();
2250 2337
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2251 2338
 			{
2252 2339
 				// We don't have this question any more, thus no answers.
2253
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2254
-					continue;
2340
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2341
+									continue;
2342
+				}
2255 2343
 				// This is quite complex. We have our question but it might have multiple answers.
2256 2344
 				// First, did they actually answer this question?
2257 2345
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2263,24 +2351,28 @@  discard block
 block discarded – undo
2263 2351
 				else
2264 2352
 				{
2265 2353
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2266
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2267
-						$incorrectQuestions[] = $q;
2354
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2355
+											$incorrectQuestions[] = $q;
2356
+					}
2268 2357
 				}
2269 2358
 			}
2270 2359
 
2271
-			if (!empty($incorrectQuestions))
2272
-				$verification_errors[] = 'wrong_verification_answer';
2360
+			if (!empty($incorrectQuestions)) {
2361
+							$verification_errors[] = 'wrong_verification_answer';
2362
+			}
2273 2363
 		}
2274 2364
 	}
2275 2365
 
2276 2366
 	// Any errors means we refresh potentially.
2277 2367
 	if (!empty($verification_errors))
2278 2368
 	{
2279
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2280
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2369
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2370
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2371
+		}
2281 2372
 		// Too many errors?
2282
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2283
-			$force_refresh = true;
2373
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2374
+					$force_refresh = true;
2375
+		}
2284 2376
 
2285 2377
 		// Keep a track of these.
2286 2378
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2313,8 +2405,9 @@  discard block
 block discarded – undo
2313 2405
 			// Are we overriding the range?
2314 2406
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2315 2407
 
2316
-			for ($i = 0; $i < 6; $i++)
2317
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2408
+			for ($i = 0; $i < 6; $i++) {
2409
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2410
+			}
2318 2411
 		}
2319 2412
 
2320 2413
 		// Getting some new questions?
@@ -2322,8 +2415,9 @@  discard block
 block discarded – undo
2322 2415
 		{
2323 2416
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2324 2417
 			$possible_langs = array();
2325
-			if (isset($_SESSION['language']))
2326
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2418
+			if (isset($_SESSION['language'])) {
2419
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2420
+			}
2327 2421
 			if (!empty($user_info['language']));
2328 2422
 			$possible_langs[] = $user_info['language'];
2329 2423
 			$possible_langs[] = $language;
@@ -2342,8 +2436,7 @@  discard block
 block discarded – undo
2342 2436
 				}
2343 2437
 			}
2344 2438
 		}
2345
-	}
2346
-	else
2439
+	} else
2347 2440
 	{
2348 2441
 		// Same questions as before.
2349 2442
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2353,8 +2446,9 @@  discard block
 block discarded – undo
2353 2446
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2354 2447
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2355 2448
 	{
2356
-		if (!isset($context['html_headers']))
2357
-			$context['html_headers'] = '';
2449
+		if (!isset($context['html_headers'])) {
2450
+					$context['html_headers'] = '';
2451
+		}
2358 2452
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2359 2453
 	}
2360 2454
 
@@ -2380,11 +2474,13 @@  discard block
 block discarded – undo
2380 2474
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2381 2475
 
2382 2476
 	// Return errors if we have them.
2383
-	if (!empty($verification_errors))
2384
-		return $verification_errors;
2477
+	if (!empty($verification_errors)) {
2478
+			return $verification_errors;
2479
+	}
2385 2480
 	// If we had a test that one, make a note.
2386
-	elseif ($do_test)
2387
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2481
+	elseif ($do_test) {
2482
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2483
+	}
2388 2484
 
2389 2485
 	// Say that everything went well chaps.
2390 2486
 	return true;
@@ -2409,8 +2505,9 @@  discard block
 block discarded – undo
2409 2505
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2410 2506
 
2411 2507
 	// If we're just checking the callback function is registered return true or false.
2412
-	if ($checkRegistered != null)
2413
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2508
+	if ($checkRegistered != null) {
2509
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2510
+	}
2414 2511
 
2415 2512
 	checkSession('get');
2416 2513
 	loadTemplate('Xml');
@@ -2561,24 +2658,27 @@  discard block
 block discarded – undo
2561 2658
 		foreach ($possible_versions as $ver)
2562 2659
 		{
2563 2660
 			$ver = trim($ver);
2564
-			if (strpos($ver, 'SMF') === 0)
2565
-				$versions[] = $ver;
2661
+			if (strpos($ver, 'SMF') === 0) {
2662
+							$versions[] = $ver;
2663
+			}
2566 2664
 		}
2567 2665
 	}
2568 2666
 	$smcFunc['db_free_result']($request);
2569 2667
 
2570 2668
 	// Just in case we don't have ANYthing.
2571
-	if (empty($versions))
2572
-		$versions = array('SMF 2.0');
2669
+	if (empty($versions)) {
2670
+			$versions = array('SMF 2.0');
2671
+	}
2573 2672
 
2574
-	foreach ($versions as $id => $version)
2575
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2673
+	foreach ($versions as $id => $version) {
2674
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2576 2675
 			$xml_data['items']['children'][] = array(
2577 2676
 				'attributes' => array(
2578 2677
 					'id' => $id,
2579 2678
 				),
2580 2679
 				'value' => $version,
2581 2680
 			);
2681
+	}
2582 2682
 
2583 2683
 	return $xml_data;
2584 2684
 }
Please login to merge, or discard this patch.