Completed
Push — release-2.1 ( 4466de...b69d19 )
by Michael
25s
created
Sources/Subs.php 2 patches
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1098 1098
 				),
1099 1099
 				'content' => '$1',
1100
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1100
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1101 1101
 				{
1102 1102
 					$returnContext = '';
1103 1103
 
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 						}
1133 1133
 
1134 1134
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1135
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>';
1136 1136
 						else
1137 1137
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1138 1138
 					}
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 				'type' => 'unparsed_content',
1162 1162
 				'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>',
1163 1163
 				// @todo Maybe this can be simplified?
1164
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1164
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1165 1165
 				{
1166 1166
 					if (!isset($disabled['code']))
1167 1167
 					{
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 				'type' => 'unparsed_equals_content',
1199 1199
 				'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>',
1200 1200
 				// @todo Maybe this can be simplified?
1201
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1201
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1202 1202
 				{
1203 1203
 					if (!isset($disabled['code']))
1204 1204
 					{
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 				'type' => 'unparsed_content',
1243 1243
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1244 1244
 				// @todo Should this respect guest_hideContacts?
1245
-				'validate' => function (&$tag, &$data, $disabled)
1245
+				'validate' => function(&$tag, &$data, $disabled)
1246 1246
 				{
1247 1247
 					$data = strtr($data, array('<br>' => ''));
1248 1248
 				},
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 				'type' => 'unparsed_commas_content',
1262 1262
 				'test' => '\d+,\d+\]',
1263 1263
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264
-				'validate' => function (&$tag, &$data, $disabled)
1264
+				'validate' => function(&$tag, &$data, $disabled)
1265 1265
 				{
1266 1266
 					if (isset($disabled['url']))
1267 1267
 						$tag['content'] = '$1';
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1278 1278
 				'before' => '<div $1>',
1279 1279
 				'after' => '</div>',
1280
-				'validate' => function (&$tag, &$data, $disabled)
1280
+				'validate' => function(&$tag, &$data, $disabled)
1281 1281
 				{
1282 1282
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1283
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1327 1327
 				),
1328 1328
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1329
-				'validate' => function (&$tag, &$data, $disabled)
1329
+				'validate' => function(&$tag, &$data, $disabled)
1330 1330
 				{
1331 1331
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1332 1332
 
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 				'tag' => 'img',
1350 1350
 				'type' => 'unparsed_content',
1351 1351
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1352
-				'validate' => function (&$tag, &$data, $disabled)
1352
+				'validate' => function(&$tag, &$data, $disabled)
1353 1353
 				{
1354 1354
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1355 1355
 
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
 				'tag' => 'iurl',
1373 1373
 				'type' => 'unparsed_content',
1374 1374
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1375
-				'validate' => function (&$tag, &$data, $disabled)
1375
+				'validate' => function(&$tag, &$data, $disabled)
1376 1376
 				{
1377 1377
 					$data = strtr($data, array('<br>' => ''));
1378 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 				'quoted' => 'optional',
1387 1387
 				'before' => '<a href="$1" class="bbc_link">',
1388 1388
 				'after' => '</a>',
1389
-				'validate' => function (&$tag, &$data, $disabled)
1389
+				'validate' => function(&$tag, &$data, $disabled)
1390 1390
 				{
1391 1391
 					if (substr($data, 0, 1) == '#')
1392 1392
 						$data = '#post_' . substr($data, 1);
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
 				'tag' => 'php',
1467 1467
 				'type' => 'unparsed_content',
1468 1468
 				'content' => '<span class="phpcode">$1</span>',
1469
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1469
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1470 1470
 				{
1471 1471
 					if (!isset($disabled['php']))
1472 1472
 					{
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
 				'test' => '[1-7]\]',
1565 1565
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1566 1566
 				'after' => '</span>',
1567
-				'validate' => function (&$tag, &$data, $disabled)
1567
+				'validate' => function(&$tag, &$data, $disabled)
1568 1568
 				{
1569 1569
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1570 1570
 					$data = $sizes[$data] . 'em';
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 				'tag' => 'time',
1603 1603
 				'type' => 'unparsed_content',
1604 1604
 				'content' => '$1',
1605
-				'validate' => function (&$tag, &$data, $disabled)
1605
+				'validate' => function(&$tag, &$data, $disabled)
1606 1606
 				{
1607 1607
 					if (is_numeric($data))
1608 1608
 						$data = timeformat($data);
@@ -1630,7 +1630,7 @@  discard block
 block discarded – undo
1630 1630
 				'tag' => 'url',
1631 1631
 				'type' => 'unparsed_content',
1632 1632
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1633
-				'validate' => function (&$tag, &$data, $disabled)
1633
+				'validate' => function(&$tag, &$data, $disabled)
1634 1634
 				{
1635 1635
 					$data = strtr($data, array('<br>' => ''));
1636 1636
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1644,7 +1644,7 @@  discard block
 block discarded – undo
1644 1644
 				'quoted' => 'optional',
1645 1645
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1646 1646
 				'after' => '</a>',
1647
-				'validate' => function (&$tag, &$data, $disabled)
1647
+				'validate' => function(&$tag, &$data, $disabled)
1648 1648
 				{
1649 1649
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650 1650
 					if (empty($scheme))
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 		{
1671 1671
 			if (isset($temp_bbc))
1672 1672
 				$bbc_codes = $temp_bbc;
1673
-			usort($codes, function ($a, $b) {
1673
+			usort($codes, function($a, $b) {
1674 1674
 				return strcmp($a['tag'], $b['tag']);
1675 1675
 			});
1676 1676
 			return $codes;
@@ -1908,7 +1908,7 @@  discard block
 block discarded – undo
1908 1908
 										# a run of Unicode domain name characters and a dot
1909 1909
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1910 1910
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1911
-										(?:'. $modSettings['tld_regex'] .'|local)
1911
+										(?:'. $modSettings['tld_regex'] . '|local)
1912 1912
 									)
1913 1913
 									# followed by a non-domain character or end of line
1914 1914
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -1976,7 +1976,7 @@  discard block
 block discarded – undo
1976 1976
 						)?
1977 1977
 						';
1978 1978
 
1979
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
1979
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
1980 1980
 							$url = array_shift($matches);
1981 1981
 
1982 1982
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2705,7 +2705,7 @@  discard block
 block discarded – undo
2705 2705
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2706 2706
 		{
2707 2707
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2708
-			$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">';
2708
+			$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">';
2709 2709
 
2710 2710
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2711 2711
 
@@ -2722,7 +2722,7 @@  discard block
 block discarded – undo
2722 2722
 
2723 2723
 	// Replace away!
2724 2724
 	$message = preg_replace_callback($smileyPregSearch,
2725
-		function ($matches) use ($smileyPregReplacements)
2725
+		function($matches) use ($smileyPregReplacements)
2726 2726
 		{
2727 2727
 			return $smileyPregReplacements[$matches[1]];
2728 2728
 		}, $message);
@@ -2788,13 +2788,13 @@  discard block
 block discarded – undo
2788 2788
 	{
2789 2789
 		if (defined('SID') && SID != '')
2790 2790
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2791
-				function ($m) use ($scripturl)
2791
+				function($m) use ($scripturl)
2792 2792
 				{
2793
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2793
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2794 2794
 				}, $setLocation);
2795 2795
 		else
2796 2796
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2797
-				function ($m) use ($scripturl)
2797
+				function($m) use ($scripturl)
2798 2798
 				{
2799 2799
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2800 2800
 				}, $setLocation);
@@ -3117,7 +3117,7 @@  discard block
 block discarded – undo
3117 3117
 
3118 3118
 	// Add a generic "Are you sure?" confirmation message.
3119 3119
 	addInlineJavaScript('
3120
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3120
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3121 3121
 
3122 3122
 	// Now add the capping code for avatars.
3123 3123
 	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')
@@ -3478,7 +3478,7 @@  discard block
 block discarded – undo
3478 3478
 
3479 3479
 		else
3480 3480
 			echo '
3481
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3481
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3482 3482
 	}
3483 3483
 
3484 3484
 	// Inline JavaScript - Actually useful some times!
@@ -3556,14 +3556,14 @@  discard block
 block discarded – undo
3556 3556
 
3557 3557
 		else
3558 3558
 			echo '
3559
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3559
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3560 3560
 	}
3561 3561
 
3562 3562
 	// Print the rest after the minified files.
3563 3563
 	if (!empty($normal))
3564 3564
 		foreach ($normal as $nf)
3565 3565
 			echo '
3566
-	<link rel="stylesheet" href="', $nf ,'">';
3566
+	<link rel="stylesheet" href="', $nf, '">';
3567 3567
 
3568 3568
 	if ($db_show_debug === true)
3569 3569
 	{
@@ -3579,7 +3579,7 @@  discard block
 block discarded – undo
3579 3579
 	<style>';
3580 3580
 
3581 3581
 		foreach ($context['css_header'] as $css)
3582
-			echo $css .'
3582
+			echo $css . '
3583 3583
 	';
3584 3584
 
3585 3585
 		echo'
@@ -3608,27 +3608,27 @@  discard block
 block discarded – undo
3608 3608
 		return false;
3609 3609
 
3610 3610
 	// Did we already did this?
3611
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3611
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3612 3612
 
3613 3613
 	// Already done?
3614 3614
 	if (!empty($toCache))
3615 3615
 		return true;
3616 3616
 
3617 3617
 	// No namespaces, sorry!
3618
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3618
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3619 3619
 
3620 3620
 	// Temp path.
3621
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3621
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3622 3622
 
3623 3623
 	// What kind of file are we going to create?
3624
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3624
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3625 3625
 
3626 3626
 	// File has to exists, if it isn't try to create it.
3627 3627
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3628 3628
 	{
3629 3629
 		loadLanguage('Errors');
3630 3630
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3631
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3631
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3632 3632
 
3633 3633
 		// The process failed so roll back to print each individual file.
3634 3634
 		return $data;
@@ -3663,14 +3663,14 @@  discard block
 block discarded – undo
3663 3663
 	{
3664 3664
 		loadLanguage('Errors');
3665 3665
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3666
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3666
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3667 3667
 
3668 3668
 		// The process failed so roll back to print each individual file.
3669 3669
 		return $data;
3670 3670
 	}
3671 3671
 
3672 3672
 	// And create a long lived cache entry.
3673
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3673
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3674 3674
 
3675 3675
 	return true;
3676 3676
 }
@@ -3730,7 +3730,7 @@  discard block
 block discarded – undo
3730 3730
 	else
3731 3731
 		$path = $modSettings['attachmentUploadDir'];
3732 3732
 
3733
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3733
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3734 3734
 }
3735 3735
 
3736 3736
 /**
@@ -3774,10 +3774,10 @@  discard block
 block discarded – undo
3774 3774
 		$valid_low = isValidIP($ip_parts[0]);
3775 3775
 		$valid_high = isValidIP($ip_parts[1]);
3776 3776
 		$count = 0;
3777
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3777
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3778 3778
 		$max = ($mode == ':' ? 'ffff' : '255');
3779 3779
 		$min = 0;
3780
-		if(!$valid_low)
3780
+		if (!$valid_low)
3781 3781
 		{
3782 3782
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3783 3783
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3791,7 +3791,7 @@  discard block
 block discarded – undo
3791 3791
 		}
3792 3792
 
3793 3793
 		$count = 0;
3794
-		if(!$valid_high)
3794
+		if (!$valid_high)
3795 3795
 		{
3796 3796
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3797 3797
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3804,7 +3804,7 @@  discard block
 block discarded – undo
3804 3804
 			}
3805 3805
 		}
3806 3806
 
3807
-		if($valid_high && $valid_low)
3807
+		if ($valid_high && $valid_low)
3808 3808
 		{
3809 3809
 			$ip_array['low'] = $ip_parts[0];
3810 3810
 			$ip_array['high'] = $ip_parts[1];
@@ -3986,7 +3986,7 @@  discard block
 block discarded – undo
3986 3986
 		addInlineJavaScript('
3987 3987
 	var user_menus = new smc_PopupMenu();
3988 3988
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3989
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3989
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
3990 3990
 		if ($context['allow_pm'])
3991 3991
 			addInlineJavaScript('
3992 3992
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4611,7 +4611,7 @@  discard block
 block discarded – undo
4611 4611
 		// No? try a fallback to $sourcedir
4612 4612
 		else
4613 4613
 		{
4614
-			$absPath = $sourcedir .'/'. $file;
4614
+			$absPath = $sourcedir . '/' . $file;
4615 4615
 
4616 4616
 			if (file_exists($absPath))
4617 4617
 				require_once($absPath);
@@ -4692,15 +4692,15 @@  discard block
 block discarded – undo
4692 4692
 
4693 4693
 	// UTF-8 occurences of MS special characters
4694 4694
 	$findchars_utf8 = array(
4695
-		"\xe2\80\x9a",	// single low-9 quotation mark
4696
-		"\xe2\80\x9e",	// double low-9 quotation mark
4697
-		"\xe2\80\xa6",	// horizontal ellipsis
4698
-		"\xe2\x80\x98",	// left single curly quote
4699
-		"\xe2\x80\x99",	// right single curly quote
4700
-		"\xe2\x80\x9c",	// left double curly quote
4701
-		"\xe2\x80\x9d",	// right double curly quote
4702
-		"\xe2\x80\x93",	// en dash
4703
-		"\xe2\x80\x94",	// em dash
4695
+		"\xe2\80\x9a", // single low-9 quotation mark
4696
+		"\xe2\80\x9e", // double low-9 quotation mark
4697
+		"\xe2\80\xa6", // horizontal ellipsis
4698
+		"\xe2\x80\x98", // left single curly quote
4699
+		"\xe2\x80\x99", // right single curly quote
4700
+		"\xe2\x80\x9c", // left double curly quote
4701
+		"\xe2\x80\x9d", // right double curly quote
4702
+		"\xe2\x80\x93", // en dash
4703
+		"\xe2\x80\x94", // em dash
4704 4704
 	);
4705 4705
 
4706 4706
 	// windows 1252 / iso equivalents
@@ -4718,15 +4718,15 @@  discard block
 block discarded – undo
4718 4718
 
4719 4719
 	// safe replacements
4720 4720
 	$replacechars = array(
4721
-		',',	// &sbquo;
4722
-		',,',	// &bdquo;
4723
-		'...',	// &hellip;
4724
-		"'",	// &lsquo;
4725
-		"'",	// &rsquo;
4726
-		'"',	// &ldquo;
4727
-		'"',	// &rdquo;
4728
-		'-',	// &ndash;
4729
-		'--',	// &mdash;
4721
+		',', // &sbquo;
4722
+		',,', // &bdquo;
4723
+		'...', // &hellip;
4724
+		"'", // &lsquo;
4725
+		"'", // &rsquo;
4726
+		'"', // &ldquo;
4727
+		'"', // &rdquo;
4728
+		'-', // &ndash;
4729
+		'--', // &mdash;
4730 4730
 	);
4731 4731
 
4732 4732
 	if ($context['utf8'])
@@ -5089,7 +5089,7 @@  discard block
 block discarded – undo
5089 5089
  */
5090 5090
 function inet_dtop($bin)
5091 5091
 {
5092
-	if(empty($bin))
5092
+	if (empty($bin))
5093 5093
 		return '';
5094 5094
 
5095 5095
 	global $db_type;
@@ -5120,28 +5120,28 @@  discard block
 block discarded – undo
5120 5120
  */
5121 5121
 function _safe_serialize($value)
5122 5122
 {
5123
-	if(is_null($value))
5123
+	if (is_null($value))
5124 5124
 		return 'N;';
5125 5125
 
5126
-	if(is_bool($value))
5127
-		return 'b:'. (int) $value .';';
5126
+	if (is_bool($value))
5127
+		return 'b:' . (int) $value . ';';
5128 5128
 
5129
-	if(is_int($value))
5130
-		return 'i:'. $value .';';
5129
+	if (is_int($value))
5130
+		return 'i:' . $value . ';';
5131 5131
 
5132
-	if(is_float($value))
5133
-		return 'd:'. str_replace(',', '.', $value) .';';
5132
+	if (is_float($value))
5133
+		return 'd:' . str_replace(',', '.', $value) . ';';
5134 5134
 
5135
-	if(is_string($value))
5136
-		return 's:'. strlen($value) .':"'. $value .'";';
5135
+	if (is_string($value))
5136
+		return 's:' . strlen($value) . ':"' . $value . '";';
5137 5137
 
5138
-	if(is_array($value))
5138
+	if (is_array($value))
5139 5139
 	{
5140 5140
 		$out = '';
5141
-		foreach($value as $k => $v)
5141
+		foreach ($value as $k => $v)
5142 5142
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5143 5143
 
5144
-		return 'a:'. count($value) .':{'. $out .'}';
5144
+		return 'a:' . count($value) . ':{' . $out . '}';
5145 5145
 	}
5146 5146
 
5147 5147
 	// safe_serialize cannot serialize resources or objects.
@@ -5183,7 +5183,7 @@  discard block
 block discarded – undo
5183 5183
 function _safe_unserialize($str)
5184 5184
 {
5185 5185
 	// Input  is not a string.
5186
-	if(empty($str) || !is_string($str))
5186
+	if (empty($str) || !is_string($str))
5187 5187
 		return false;
5188 5188
 
5189 5189
 	$stack = array();
@@ -5197,40 +5197,40 @@  discard block
 block discarded – undo
5197 5197
 	 *   3 - in array, expecting value or another array
5198 5198
 	 */
5199 5199
 	$state = 0;
5200
-	while($state != 1)
5200
+	while ($state != 1)
5201 5201
 	{
5202 5202
 		$type = isset($str[0]) ? $str[0] : '';
5203
-		if($type == '}')
5203
+		if ($type == '}')
5204 5204
 			$str = substr($str, 1);
5205 5205
 
5206
-		else if($type == 'N' && $str[1] == ';')
5206
+		else if ($type == 'N' && $str[1] == ';')
5207 5207
 		{
5208 5208
 			$value = null;
5209 5209
 			$str = substr($str, 2);
5210 5210
 		}
5211
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5211
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5212 5212
 		{
5213 5213
 			$value = $matches[1] == '1' ? true : false;
5214 5214
 			$str = substr($str, 4);
5215 5215
 		}
5216
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5216
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5217 5217
 		{
5218
-			$value = (int)$matches[1];
5218
+			$value = (int) $matches[1];
5219 5219
 			$str = $matches[2];
5220 5220
 		}
5221
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5221
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5222 5222
 		{
5223
-			$value = (float)$matches[1];
5223
+			$value = (float) $matches[1];
5224 5224
 			$str = $matches[3];
5225 5225
 		}
5226
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5226
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5227 5227
 		{
5228
-			$value = substr($matches[2], 0, (int)$matches[1]);
5229
-			$str = substr($matches[2], (int)$matches[1] + 2);
5228
+			$value = substr($matches[2], 0, (int) $matches[1]);
5229
+			$str = substr($matches[2], (int) $matches[1] + 2);
5230 5230
 		}
5231
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5231
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5232 5232
 		{
5233
-			$expectedLength = (int)$matches[1];
5233
+			$expectedLength = (int) $matches[1];
5234 5234
 			$str = $matches[2];
5235 5235
 		}
5236 5236
 
@@ -5238,10 +5238,10 @@  discard block
 block discarded – undo
5238 5238
 		else
5239 5239
 			return false;
5240 5240
 
5241
-		switch($state)
5241
+		switch ($state)
5242 5242
 		{
5243 5243
 			case 3: // In array, expecting value or another array.
5244
-				if($type == 'a')
5244
+				if ($type == 'a')
5245 5245
 				{
5246 5246
 					$stack[] = &$list;
5247 5247
 					$list[$key] = array();
@@ -5250,7 +5250,7 @@  discard block
 block discarded – undo
5250 5250
 					$state = 2;
5251 5251
 					break;
5252 5252
 				}
5253
-				if($type != '}')
5253
+				if ($type != '}')
5254 5254
 				{
5255 5255
 					$list[$key] = $value;
5256 5256
 					$state = 2;
@@ -5261,29 +5261,29 @@  discard block
 block discarded – undo
5261 5261
 				return false;
5262 5262
 
5263 5263
 			case 2: // in array, expecting end of array or a key
5264
-				if($type == '}')
5264
+				if ($type == '}')
5265 5265
 				{
5266 5266
 					// Array size is less than expected.
5267
-					if(count($list) < end($expected))
5267
+					if (count($list) < end($expected))
5268 5268
 						return false;
5269 5269
 
5270 5270
 					unset($list);
5271
-					$list = &$stack[count($stack)-1];
5271
+					$list = &$stack[count($stack) - 1];
5272 5272
 					array_pop($stack);
5273 5273
 
5274 5274
 					// Go to terminal state if we're at the end of the root array.
5275 5275
 					array_pop($expected);
5276 5276
 
5277
-					if(count($expected) == 0)
5277
+					if (count($expected) == 0)
5278 5278
 						$state = 1;
5279 5279
 
5280 5280
 					break;
5281 5281
 				}
5282 5282
 
5283
-				if($type == 'i' || $type == 's')
5283
+				if ($type == 'i' || $type == 's')
5284 5284
 				{
5285 5285
 					// Array size exceeds expected length.
5286
-					if(count($list) >= end($expected))
5286
+					if (count($list) >= end($expected))
5287 5287
 						return false;
5288 5288
 
5289 5289
 					$key = $value;
@@ -5296,7 +5296,7 @@  discard block
 block discarded – undo
5296 5296
 
5297 5297
 			// Expecting array or value.
5298 5298
 			case 0:
5299
-				if($type == 'a')
5299
+				if ($type == 'a')
5300 5300
 				{
5301 5301
 					$data = array();
5302 5302
 					$list = &$data;
@@ -5305,7 +5305,7 @@  discard block
 block discarded – undo
5305 5305
 					break;
5306 5306
 				}
5307 5307
 
5308
-				if($type != '}')
5308
+				if ($type != '}')
5309 5309
 				{
5310 5310
 					$data = $value;
5311 5311
 					$state = 1;
@@ -5318,7 +5318,7 @@  discard block
 block discarded – undo
5318 5318
 	}
5319 5319
 
5320 5320
 	// Trailing data in input.
5321
-	if(!empty($str))
5321
+	if (!empty($str))
5322 5322
 		return false;
5323 5323
 
5324 5324
 	return $data;
@@ -5372,7 +5372,7 @@  discard block
 block discarded – undo
5372 5372
 	// Set different modes.
5373 5373
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5374 5374
 
5375
-	foreach($chmodValues as $val)
5375
+	foreach ($chmodValues as $val)
5376 5376
 	{
5377 5377
 		// If it's writable, break out of the loop.
5378 5378
 		if (is_writable($file))
@@ -5407,13 +5407,13 @@  discard block
 block discarded – undo
5407 5407
 	$returnArray = @json_decode($json, $returnAsArray);
5408 5408
 
5409 5409
 	// PHP 5.3 so no json_last_error_msg()
5410
-	switch(json_last_error())
5410
+	switch (json_last_error())
5411 5411
 	{
5412 5412
 		case JSON_ERROR_NONE:
5413 5413
 			$jsonError = false;
5414 5414
 			break;
5415 5415
 		case JSON_ERROR_DEPTH:
5416
-			$jsonError =  'JSON_ERROR_DEPTH';
5416
+			$jsonError = 'JSON_ERROR_DEPTH';
5417 5417
 			break;
5418 5418
 		case JSON_ERROR_STATE_MISMATCH:
5419 5419
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5441,10 +5441,10 @@  discard block
 block discarded – undo
5441 5441
 		loadLanguage('Errors');
5442 5442
 
5443 5443
 		if (!empty($jsonDebug))
5444
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5444
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5445 5445
 
5446 5446
 		else
5447
-			log_error($txt['json_'. $jsonError], 'critical');
5447
+			log_error($txt['json_' . $jsonError], 'critical');
5448 5448
 
5449 5449
 		// Everyone expects an array.
5450 5450
 		return array();
@@ -5548,7 +5548,7 @@  discard block
 block discarded – undo
5548 5548
 		});
5549 5549
 
5550 5550
 		// Convert Punycode to Unicode
5551
-		$tlds = array_map(function ($input) {
5551
+		$tlds = array_map(function($input) {
5552 5552
 			$prefix = 'xn--';
5553 5553
 			$safe_char = 0xFFFC;
5554 5554
 			$base = 36;
@@ -5564,7 +5564,7 @@  discard block
 block discarded – undo
5564 5564
 
5565 5565
 			foreach ($enco_parts as $encoded)
5566 5566
 			{
5567
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5567
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5568 5568
 				{
5569 5569
 					$output_parts[] = $encoded;
5570 5570
 					continue;
@@ -5575,7 +5575,7 @@  discard block
 block discarded – undo
5575 5575
 				$idx = 0;
5576 5576
 				$char = 0x80;
5577 5577
 				$decoded = array();
5578
-				$output='';
5578
+				$output = '';
5579 5579
 				$delim_pos = strrpos($encoded, '-');
5580 5580
 
5581 5581
 				if ($delim_pos > strlen($prefix))
@@ -5591,7 +5591,7 @@  discard block
 block discarded – undo
5591 5591
 
5592 5592
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5593 5593
 				{
5594
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5594
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5595 5595
 					{
5596 5596
 						$cp = ord($encoded{$enco_idx++});
5597 5597
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5632,15 +5632,15 @@  discard block
 block discarded – undo
5632 5632
 
5633 5633
 					// 2 bytes
5634 5634
 					elseif ($v < (1 << 11))
5635
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5635
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5636 5636
 
5637 5637
 					// 3 bytes
5638 5638
 					elseif ($v < (1 << 16))
5639
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5639
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5640 5640
 
5641 5641
 					// 4 bytes
5642 5642
 					elseif ($v < (1 << 21))
5643
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5643
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5644 5644
 
5645 5645
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5646 5646
 					else
@@ -5747,7 +5747,7 @@  discard block
 block discarded – undo
5747 5747
 	}
5748 5748
 
5749 5749
 	// This recursive function creates the index array from the strings
5750
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5750
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5751 5751
 	{
5752 5752
 		static $depth = 0;
5753 5753
 		$depth++;
@@ -5774,7 +5774,7 @@  discard block
 block discarded – undo
5774 5774
 	};
5775 5775
 
5776 5776
 	// This recursive function turns the index array into a regular expression
5777
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5777
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5778 5778
 	{
5779 5779
 		static $depth = 0;
5780 5780
 		$depth++;
@@ -5798,11 +5798,11 @@  discard block
 block discarded – undo
5798 5798
 
5799 5799
 				if (count(array_keys($value)) == 1)
5800 5800
 				{
5801
-					$new_key_array = explode('(?'.'>', $sub_regex);
5801
+					$new_key_array = explode('(?' . '>', $sub_regex);
5802 5802
 					$new_key .= $new_key_array[0];
5803 5803
 				}
5804 5804
 				else
5805
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5805
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5806 5806
 			}
5807 5807
 
5808 5808
 			if ($depth > 1)
@@ -5842,7 +5842,7 @@  discard block
 block discarded – undo
5842 5842
 		$index = $add_string_to_index($string, $index);
5843 5843
 
5844 5844
 	while (!empty($index))
5845
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5845
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5846 5846
 
5847 5847
 	// Restore PHP's internal character encoding to whatever it was originally
5848 5848
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Braces   +1284 added lines, -954 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
760
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1281,10 +1345,11 @@  discard block
 block discarded – undo
1281 1345
 				{
1282 1346
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1283 1347
 
1284
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1285
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1286
-					else
1287
-						$css = '';
1348
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1349
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1350
+					} else {
1351
+											$css = '';
1352
+					}
1288 1353
 
1289 1354
 					$data = $class . $css;
1290 1355
 				},
@@ -1334,14 +1399,16 @@  discard block
 block discarded – undo
1334 1399
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1335 1400
 					if ($image_proxy_enabled)
1336 1401
 					{
1337
-						if (empty($scheme))
1338
-							$data = 'http://' . ltrim($data, ':/');
1402
+						if (empty($scheme)) {
1403
+													$data = 'http://' . ltrim($data, ':/');
1404
+						}
1339 1405
 
1340
-						if ($scheme != 'https')
1341
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1406
+						if ($scheme != 'https') {
1407
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1408
+						}
1409
+					} elseif (empty($scheme)) {
1410
+											$data = '//' . ltrim($data, ':/');
1342 1411
 					}
1343
-					elseif (empty($scheme))
1344
-						$data = '//' . ltrim($data, ':/');
1345 1412
 				},
1346 1413
 				'disabled_content' => '($1)',
1347 1414
 			),
@@ -1357,14 +1424,16 @@  discard block
 block discarded – undo
1357 1424
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1358 1425
 					if ($image_proxy_enabled)
1359 1426
 					{
1360
-						if (empty($scheme))
1361
-							$data = 'http://' . ltrim($data, ':/');
1427
+						if (empty($scheme)) {
1428
+													$data = 'http://' . ltrim($data, ':/');
1429
+						}
1362 1430
 
1363
-						if ($scheme != 'https')
1364
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1431
+						if ($scheme != 'https') {
1432
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1433
+						}
1434
+					} elseif (empty($scheme)) {
1435
+											$data = '//' . ltrim($data, ':/');
1365 1436
 					}
1366
-					elseif (empty($scheme))
1367
-						$data = '//' . ltrim($data, ':/');
1368 1437
 				},
1369 1438
 				'disabled_content' => '($1)',
1370 1439
 			),
@@ -1376,8 +1445,9 @@  discard block
 block discarded – undo
1376 1445
 				{
1377 1446
 					$data = strtr($data, array('<br>' => ''));
1378 1447
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1379
-					if (empty($scheme))
1380
-						$data = '//' . ltrim($data, ':/');
1448
+					if (empty($scheme)) {
1449
+											$data = '//' . ltrim($data, ':/');
1450
+					}
1381 1451
 				},
1382 1452
 			),
1383 1453
 			array(
@@ -1388,13 +1458,14 @@  discard block
 block discarded – undo
1388 1458
 				'after' => '</a>',
1389 1459
 				'validate' => function (&$tag, &$data, $disabled)
1390 1460
 				{
1391
-					if (substr($data, 0, 1) == '#')
1392
-						$data = '#post_' . substr($data, 1);
1393
-					else
1461
+					if (substr($data, 0, 1) == '#') {
1462
+											$data = '#post_' . substr($data, 1);
1463
+					} else
1394 1464
 					{
1395 1465
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1396
-						if (empty($scheme))
1397
-							$data = '//' . ltrim($data, ':/');
1466
+						if (empty($scheme)) {
1467
+													$data = '//' . ltrim($data, ':/');
1468
+						}
1398 1469
 					}
1399 1470
 				},
1400 1471
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1472,8 +1543,9 @@  discard block
 block discarded – undo
1472 1543
 					{
1473 1544
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1474 1545
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1475
-						if ($add_begin)
1476
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1546
+						if ($add_begin) {
1547
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1548
+						}
1477 1549
 					}
1478 1550
 				},
1479 1551
 				'block_level' => false,
@@ -1604,10 +1676,11 @@  discard block
 block discarded – undo
1604 1676
 				'content' => '$1',
1605 1677
 				'validate' => function (&$tag, &$data, $disabled)
1606 1678
 				{
1607
-					if (is_numeric($data))
1608
-						$data = timeformat($data);
1609
-					else
1610
-						$tag['content'] = '[time]$1[/time]';
1679
+					if (is_numeric($data)) {
1680
+											$data = timeformat($data);
1681
+					} else {
1682
+											$tag['content'] = '[time]$1[/time]';
1683
+					}
1611 1684
 				},
1612 1685
 			),
1613 1686
 			array(
@@ -1634,8 +1707,9 @@  discard block
 block discarded – undo
1634 1707
 				{
1635 1708
 					$data = strtr($data, array('<br>' => ''));
1636 1709
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1637
-					if (empty($scheme))
1638
-						$data = '//' . ltrim($data, ':/');
1710
+					if (empty($scheme)) {
1711
+											$data = '//' . ltrim($data, ':/');
1712
+					}
1639 1713
 				},
1640 1714
 			),
1641 1715
 			array(
@@ -1647,8 +1721,9 @@  discard block
 block discarded – undo
1647 1721
 				'validate' => function (&$tag, &$data, $disabled)
1648 1722
 				{
1649 1723
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1650
-					if (empty($scheme))
1651
-						$data = '//' . ltrim($data, ':/');
1724
+					if (empty($scheme)) {
1725
+											$data = '//' . ltrim($data, ':/');
1726
+					}
1652 1727
 				},
1653 1728
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1654 1729
 				'disabled_after' => ' ($1)',
@@ -1668,8 +1743,9 @@  discard block
 block discarded – undo
1668 1743
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1669 1744
 		if ($message === false)
1670 1745
 		{
1671
-			if (isset($temp_bbc))
1672
-				$bbc_codes = $temp_bbc;
1746
+			if (isset($temp_bbc)) {
1747
+							$bbc_codes = $temp_bbc;
1748
+			}
1673 1749
 			usort($codes, function ($a, $b) {
1674 1750
 				return strcmp($a['tag'], $b['tag']);
1675 1751
 			});
@@ -1689,8 +1765,9 @@  discard block
 block discarded – undo
1689 1765
 		);
1690 1766
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1691 1767
 		{
1692
-			foreach ($itemcodes as $c => $dummy)
1693
-				$bbc_codes[$c] = array();
1768
+			foreach ($itemcodes as $c => $dummy) {
1769
+							$bbc_codes[$c] = array();
1770
+			}
1694 1771
 		}
1695 1772
 
1696 1773
 		// Shhhh!
@@ -1711,12 +1788,14 @@  discard block
 block discarded – undo
1711 1788
 		foreach ($codes as $code)
1712 1789
 		{
1713 1790
 			// Make it easier to process parameters later
1714
-			if (!empty($code['parameters']))
1715
-				ksort($code['parameters'], SORT_STRING);
1791
+			if (!empty($code['parameters'])) {
1792
+							ksort($code['parameters'], SORT_STRING);
1793
+			}
1716 1794
 
1717 1795
 			// If we are not doing every tag only do ones we are interested in.
1718
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1719
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1796
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1797
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1798
+			}
1720 1799
 		}
1721 1800
 		$codes = null;
1722 1801
 	}
@@ -1727,8 +1806,9 @@  discard block
 block discarded – undo
1727 1806
 		// It's likely this will change if the message is modified.
1728 1807
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1729 1808
 
1730
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1731
-			return $temp;
1809
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1810
+					return $temp;
1811
+		}
1732 1812
 
1733 1813
 		$cache_t = microtime();
1734 1814
 	}
@@ -1760,8 +1840,9 @@  discard block
 block discarded – undo
1760 1840
 		$disabled['flash'] = true;
1761 1841
 
1762 1842
 		// @todo Change maybe?
1763
-		if (!isset($_GET['images']))
1764
-			$disabled['img'] = true;
1843
+		if (!isset($_GET['images'])) {
1844
+					$disabled['img'] = true;
1845
+		}
1765 1846
 
1766 1847
 		// @todo Interface/setting to add more?
1767 1848
 	}
@@ -1785,8 +1866,9 @@  discard block
 block discarded – undo
1785 1866
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1786 1867
 
1787 1868
 		// Failsafe.
1788
-		if ($pos === false || $last_pos > $pos)
1789
-			$pos = strlen($message) + 1;
1869
+		if ($pos === false || $last_pos > $pos) {
1870
+					$pos = strlen($message) + 1;
1871
+		}
1790 1872
 
1791 1873
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1792 1874
 		if ($last_pos < $pos - 1)
@@ -1805,8 +1887,9 @@  discard block
 block discarded – undo
1805 1887
 
1806 1888
 				// <br> should be empty.
1807 1889
 				$empty_tags = array('br', 'hr');
1808
-				foreach ($empty_tags as $tag)
1809
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1890
+				foreach ($empty_tags as $tag) {
1891
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1892
+				}
1810 1893
 
1811 1894
 				// b, u, i, s, pre... basic tags.
1812 1895
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1815,8 +1898,9 @@  discard block
 block discarded – undo
1815 1898
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1816 1899
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1817 1900
 
1818
-					if ($diff > 0)
1819
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1901
+					if ($diff > 0) {
1902
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1903
+					}
1820 1904
 				}
1821 1905
 
1822 1906
 				// Do <img ...> - with security... action= -> action-.
@@ -1829,8 +1913,9 @@  discard block
 block discarded – undo
1829 1913
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1830 1914
 
1831 1915
 						// Remove action= from the URL - no funny business, now.
1832
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1833
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1916
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1917
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1918
+						}
1834 1919
 
1835 1920
 						// Check if the image is larger than allowed.
1836 1921
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1851,9 +1936,9 @@  discard block
 block discarded – undo
1851 1936
 
1852 1937
 							// Set the new image tag.
1853 1938
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1939
+						} else {
1940
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1854 1941
 						}
1855
-						else
1856
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1857 1942
 					}
1858 1943
 
1859 1944
 					$data = strtr($data, $replaces);
@@ -1866,16 +1951,18 @@  discard block
 block discarded – undo
1866 1951
 				$no_autolink_area = false;
1867 1952
 				if (!empty($open_tags))
1868 1953
 				{
1869
-					foreach ($open_tags as $open_tag)
1870
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1954
+					foreach ($open_tags as $open_tag) {
1955
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1871 1956
 							$no_autolink_area = true;
1957
+					}
1872 1958
 				}
1873 1959
 
1874 1960
 				// Don't go backwards.
1875 1961
 				// @todo Don't think is the real solution....
1876 1962
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1877
-				if ($pos < $lastAutoPos)
1878
-					$no_autolink_area = true;
1963
+				if ($pos < $lastAutoPos) {
1964
+									$no_autolink_area = true;
1965
+				}
1879 1966
 				$lastAutoPos = $pos;
1880 1967
 
1881 1968
 				if (!$no_autolink_area)
@@ -1984,17 +2071,19 @@  discard block
 block discarded – undo
1984 2071
 							if ($scheme == 'mailto')
1985 2072
 							{
1986 2073
 								$email_address = str_replace('mailto:', '', $url);
1987
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1988
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1989
-								else
1990
-									return $url;
2074
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2075
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2076
+								} else {
2077
+																	return $url;
2078
+								}
1991 2079
 							}
1992 2080
 
1993 2081
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1994
-							if (empty($scheme))
1995
-								$fullUrl = '//' . ltrim($url, ':/');
1996
-							else
1997
-								$fullUrl = $url;
2082
+							if (empty($scheme)) {
2083
+															$fullUrl = '//' . ltrim($url, ':/');
2084
+							} else {
2085
+															$fullUrl = $url;
2086
+							}
1998 2087
 
1999 2088
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2000 2089
 						}, $data);
@@ -2043,16 +2132,18 @@  discard block
 block discarded – undo
2043 2132
 		}
2044 2133
 
2045 2134
 		// Are we there yet?  Are we there yet?
2046
-		if ($pos >= strlen($message) - 1)
2047
-			break;
2135
+		if ($pos >= strlen($message) - 1) {
2136
+					break;
2137
+		}
2048 2138
 
2049 2139
 		$tags = strtolower($message[$pos + 1]);
2050 2140
 
2051 2141
 		if ($tags == '/' && !empty($open_tags))
2052 2142
 		{
2053 2143
 			$pos2 = strpos($message, ']', $pos + 1);
2054
-			if ($pos2 == $pos + 2)
2055
-				continue;
2144
+			if ($pos2 == $pos + 2) {
2145
+							continue;
2146
+			}
2056 2147
 
2057 2148
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2058 2149
 
@@ -2062,8 +2153,9 @@  discard block
 block discarded – undo
2062 2153
 			do
2063 2154
 			{
2064 2155
 				$tag = array_pop($open_tags);
2065
-				if (!$tag)
2066
-					break;
2156
+				if (!$tag) {
2157
+									break;
2158
+				}
2067 2159
 
2068 2160
 				if (!empty($tag['block_level']))
2069 2161
 				{
@@ -2077,10 +2169,11 @@  discard block
 block discarded – undo
2077 2169
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2078 2170
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2079 2171
 					{
2080
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2081
-							if ($temp['tag'] == $look_for)
2172
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2173
+													if ($temp['tag'] == $look_for)
2082 2174
 							{
2083 2175
 								$block_level = !empty($temp['block_level']);
2176
+						}
2084 2177
 								break;
2085 2178
 							}
2086 2179
 					}
@@ -2102,15 +2195,15 @@  discard block
 block discarded – undo
2102 2195
 			{
2103 2196
 				$open_tags = $to_close;
2104 2197
 				continue;
2105
-			}
2106
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2198
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2107 2199
 			{
2108 2200
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2109 2201
 				{
2110
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2111
-						if ($temp['tag'] == $look_for)
2202
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2203
+											if ($temp['tag'] == $look_for)
2112 2204
 						{
2113 2205
 							$block_level = !empty($temp['block_level']);
2206
+					}
2114 2207
 							break;
2115 2208
 						}
2116 2209
 				}
@@ -2118,8 +2211,9 @@  discard block
 block discarded – undo
2118 2211
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2119 2212
 				if (!$block_level)
2120 2213
 				{
2121
-					foreach ($to_close as $tag)
2122
-						array_push($open_tags, $tag);
2214
+					foreach ($to_close as $tag) {
2215
+											array_push($open_tags, $tag);
2216
+					}
2123 2217
 					continue;
2124 2218
 				}
2125 2219
 			}
@@ -2131,10 +2225,12 @@  discard block
 block discarded – undo
2131 2225
 				$pos2 = $pos - 1;
2132 2226
 
2133 2227
 				// See the comment at the end of the big loop - just eating whitespace ;).
2134
-				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>')
2135
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2136
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2137
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2228
+				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') {
2229
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2230
+				}
2231
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2232
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2233
+				}
2138 2234
 			}
2139 2235
 
2140 2236
 			if (!empty($to_close))
@@ -2147,8 +2243,9 @@  discard block
 block discarded – undo
2147 2243
 		}
2148 2244
 
2149 2245
 		// No tags for this character, so just keep going (fastest possible course.)
2150
-		if (!isset($bbc_codes[$tags]))
2151
-			continue;
2246
+		if (!isset($bbc_codes[$tags])) {
2247
+					continue;
2248
+		}
2152 2249
 
2153 2250
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2154 2251
 		$tag = null;
@@ -2157,44 +2254,52 @@  discard block
 block discarded – undo
2157 2254
 			$pt_strlen = strlen($possible['tag']);
2158 2255
 
2159 2256
 			// Not a match?
2160
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2161
-				continue;
2257
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2258
+							continue;
2259
+			}
2162 2260
 
2163 2261
 			$next_c = $message[$pos + 1 + $pt_strlen];
2164 2262
 
2165 2263
 			// A test validation?
2166
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2167
-				continue;
2264
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2265
+							continue;
2266
+			}
2168 2267
 			// Do we want parameters?
2169 2268
 			elseif (!empty($possible['parameters']))
2170 2269
 			{
2171
-				if ($next_c != ' ')
2172
-					continue;
2173
-			}
2174
-			elseif (isset($possible['type']))
2270
+				if ($next_c != ' ') {
2271
+									continue;
2272
+				}
2273
+			} elseif (isset($possible['type']))
2175 2274
 			{
2176 2275
 				// Do we need an equal sign?
2177
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2178
-					continue;
2276
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2277
+									continue;
2278
+				}
2179 2279
 				// Maybe we just want a /...
2180
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2181
-					continue;
2280
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2281
+									continue;
2282
+				}
2182 2283
 				// An immediate ]?
2183
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2184
-					continue;
2284
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2285
+									continue;
2286
+				}
2185 2287
 			}
2186 2288
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2187
-			elseif ($next_c != ']')
2188
-				continue;
2289
+			elseif ($next_c != ']') {
2290
+							continue;
2291
+			}
2189 2292
 
2190 2293
 			// Check allowed tree?
2191
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2192
-				continue;
2193
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2194
-				continue;
2294
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2295
+							continue;
2296
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2297
+							continue;
2298
+			}
2195 2299
 			// If this is in the list of disallowed child tags, don't parse it.
2196
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2197
-				continue;
2300
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2301
+							continue;
2302
+			}
2198 2303
 
2199 2304
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2200 2305
 
@@ -2206,8 +2311,9 @@  discard block
 block discarded – undo
2206 2311
 				foreach ($open_tags as $open_quote)
2207 2312
 				{
2208 2313
 					// Every parent quote this quote has flips the styling
2209
-					if ($open_quote['tag'] == 'quote')
2210
-						$quote_alt = !$quote_alt;
2314
+					if ($open_quote['tag'] == 'quote') {
2315
+											$quote_alt = !$quote_alt;
2316
+					}
2211 2317
 				}
2212 2318
 				// Add a class to the quote to style alternating blockquotes
2213 2319
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2218,8 +2324,9 @@  discard block
 block discarded – undo
2218 2324
 			{
2219 2325
 				// Build a regular expression for each parameter for the current tag.
2220 2326
 				$preg = array();
2221
-				foreach ($possible['parameters'] as $p => $info)
2222
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2327
+				foreach ($possible['parameters'] as $p => $info) {
2328
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2329
+				}
2223 2330
 
2224 2331
 				// Extract the string that potentially holds our parameters.
2225 2332
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2239,24 +2346,27 @@  discard block
 block discarded – undo
2239 2346
 
2240 2347
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2241 2348
 
2242
-					if ($match)
2243
-						$blob_counter = count($blobs) + 1;
2349
+					if ($match) {
2350
+											$blob_counter = count($blobs) + 1;
2351
+					}
2244 2352
 				}
2245 2353
 
2246 2354
 				// Didn't match our parameter list, try the next possible.
2247
-				if (!$match)
2248
-					continue;
2355
+				if (!$match) {
2356
+									continue;
2357
+				}
2249 2358
 
2250 2359
 				$params = array();
2251 2360
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2252 2361
 				{
2253 2362
 					$key = strtok(ltrim($matches[$i]), '=');
2254
-					if (isset($possible['parameters'][$key]['value']))
2255
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2256
-					elseif (isset($possible['parameters'][$key]['validate']))
2257
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2258
-					else
2259
-						$params['{' . $key . '}'] = $matches[$i + 1];
2363
+					if (isset($possible['parameters'][$key]['value'])) {
2364
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2365
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2366
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2367
+					} else {
2368
+											$params['{' . $key . '}'] = $matches[$i + 1];
2369
+					}
2260 2370
 
2261 2371
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2262 2372
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2264,23 +2374,26 @@  discard block
 block discarded – undo
2264 2374
 
2265 2375
 				foreach ($possible['parameters'] as $p => $info)
2266 2376
 				{
2267
-					if (!isset($params['{' . $p . '}']))
2268
-						$params['{' . $p . '}'] = '';
2377
+					if (!isset($params['{' . $p . '}'])) {
2378
+											$params['{' . $p . '}'] = '';
2379
+					}
2269 2380
 				}
2270 2381
 
2271 2382
 				$tag = $possible;
2272 2383
 
2273 2384
 				// Put the parameters into the string.
2274
-				if (isset($tag['before']))
2275
-					$tag['before'] = strtr($tag['before'], $params);
2276
-				if (isset($tag['after']))
2277
-					$tag['after'] = strtr($tag['after'], $params);
2278
-				if (isset($tag['content']))
2279
-					$tag['content'] = strtr($tag['content'], $params);
2385
+				if (isset($tag['before'])) {
2386
+									$tag['before'] = strtr($tag['before'], $params);
2387
+				}
2388
+				if (isset($tag['after'])) {
2389
+									$tag['after'] = strtr($tag['after'], $params);
2390
+				}
2391
+				if (isset($tag['content'])) {
2392
+									$tag['content'] = strtr($tag['content'], $params);
2393
+				}
2280 2394
 
2281 2395
 				$pos1 += strlen($given_param_string);
2282
-			}
2283
-			else
2396
+			} else
2284 2397
 			{
2285 2398
 				$tag = $possible;
2286 2399
 				$params = array();
@@ -2291,8 +2404,9 @@  discard block
 block discarded – undo
2291 2404
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2292 2405
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2293 2406
 		{
2294
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2295
-				continue;
2407
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2408
+							continue;
2409
+			}
2296 2410
 
2297 2411
 			$tag = $itemcodes[$message[$pos + 1]];
2298 2412
 
@@ -2313,9 +2427,9 @@  discard block
 block discarded – undo
2313 2427
 			{
2314 2428
 				array_pop($open_tags);
2315 2429
 				$code = '</li>';
2430
+			} else {
2431
+							$code = '';
2316 2432
 			}
2317
-			else
2318
-				$code = '';
2319 2433
 
2320 2434
 			// Now we open a new tag.
2321 2435
 			$open_tags[] = array(
@@ -2362,12 +2476,14 @@  discard block
 block discarded – undo
2362 2476
 		}
2363 2477
 
2364 2478
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2365
-		if ($tag === null)
2366
-			continue;
2479
+		if ($tag === null) {
2480
+					continue;
2481
+		}
2367 2482
 
2368 2483
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2369
-		if (isset($inside['disallow_children']))
2370
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2484
+		if (isset($inside['disallow_children'])) {
2485
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2486
+		}
2371 2487
 
2372 2488
 		// Is this tag disabled?
2373 2489
 		if (isset($disabled[$tag['tag']]))
@@ -2377,14 +2493,13 @@  discard block
 block discarded – undo
2377 2493
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2378 2494
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2379 2495
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2380
-			}
2381
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2496
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2382 2497
 			{
2383 2498
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2384 2499
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2500
+			} else {
2501
+							$tag['content'] = $tag['disabled_content'];
2385 2502
 			}
2386
-			else
2387
-				$tag['content'] = $tag['disabled_content'];
2388 2503
 		}
2389 2504
 
2390 2505
 		// we use this a lot
@@ -2394,8 +2509,9 @@  discard block
 block discarded – undo
2394 2509
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2395 2510
 		{
2396 2511
 			$n = count($open_tags) - 1;
2397
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2398
-				$n--;
2512
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2513
+							$n--;
2514
+			}
2399 2515
 
2400 2516
 			// Close all the non block level tags so this tag isn't surrounded by them.
2401 2517
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2406,10 +2522,12 @@  discard block
 block discarded – undo
2406 2522
 				$pos1 += $ot_strlen + 2;
2407 2523
 
2408 2524
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2409
-				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>')
2410
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2411
-				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2412
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2525
+				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') {
2526
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2527
+				}
2528
+				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2529
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2530
+				}
2413 2531
 
2414 2532
 				array_pop($open_tags);
2415 2533
 			}
@@ -2427,16 +2545,19 @@  discard block
 block discarded – undo
2427 2545
 		elseif ($tag['type'] == 'unparsed_content')
2428 2546
 		{
2429 2547
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2430
-			if ($pos2 === false)
2431
-				continue;
2548
+			if ($pos2 === false) {
2549
+							continue;
2550
+			}
2432 2551
 
2433 2552
 			$data = substr($message, $pos1, $pos2 - $pos1);
2434 2553
 
2435
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2436
-				$data = substr($data, 4);
2554
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2555
+							$data = substr($data, 4);
2556
+			}
2437 2557
 
2438
-			if (isset($tag['validate']))
2439
-				$tag['validate']($tag, $data, $disabled, $params);
2558
+			if (isset($tag['validate'])) {
2559
+							$tag['validate']($tag, $data, $disabled, $params);
2560
+			}
2440 2561
 
2441 2562
 			$code = strtr($tag['content'], array('$1' => $data));
2442 2563
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2452,34 +2573,40 @@  discard block
 block discarded – undo
2452 2573
 			if (isset($tag['quoted']))
2453 2574
 			{
2454 2575
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2455
-				if ($tag['quoted'] != 'optional' && !$quoted)
2456
-					continue;
2576
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2577
+									continue;
2578
+				}
2457 2579
 
2458
-				if ($quoted)
2459
-					$pos1 += 6;
2580
+				if ($quoted) {
2581
+									$pos1 += 6;
2582
+				}
2583
+			} else {
2584
+							$quoted = false;
2460 2585
 			}
2461
-			else
2462
-				$quoted = false;
2463 2586
 
2464 2587
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2465
-			if ($pos2 === false)
2466
-				continue;
2588
+			if ($pos2 === false) {
2589
+							continue;
2590
+			}
2467 2591
 
2468 2592
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2469
-			if ($pos3 === false)
2470
-				continue;
2593
+			if ($pos3 === false) {
2594
+							continue;
2595
+			}
2471 2596
 
2472 2597
 			$data = array(
2473 2598
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2474 2599
 				substr($message, $pos1, $pos2 - $pos1)
2475 2600
 			);
2476 2601
 
2477
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2478
-				$data[0] = substr($data[0], 4);
2602
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2603
+							$data[0] = substr($data[0], 4);
2604
+			}
2479 2605
 
2480 2606
 			// Validation for my parking, please!
2481
-			if (isset($tag['validate']))
2482
-				$tag['validate']($tag, $data, $disabled, $params);
2607
+			if (isset($tag['validate'])) {
2608
+							$tag['validate']($tag, $data, $disabled, $params);
2609
+			}
2483 2610
 
2484 2611
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2485 2612
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2496,23 +2623,27 @@  discard block
 block discarded – undo
2496 2623
 		elseif ($tag['type'] == 'unparsed_commas_content')
2497 2624
 		{
2498 2625
 			$pos2 = strpos($message, ']', $pos1);
2499
-			if ($pos2 === false)
2500
-				continue;
2626
+			if ($pos2 === false) {
2627
+							continue;
2628
+			}
2501 2629
 
2502 2630
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2503
-			if ($pos3 === false)
2504
-				continue;
2631
+			if ($pos3 === false) {
2632
+							continue;
2633
+			}
2505 2634
 
2506 2635
 			// We want $1 to be the content, and the rest to be csv.
2507 2636
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2508 2637
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2509 2638
 
2510
-			if (isset($tag['validate']))
2511
-				$tag['validate']($tag, $data, $disabled, $params);
2639
+			if (isset($tag['validate'])) {
2640
+							$tag['validate']($tag, $data, $disabled, $params);
2641
+			}
2512 2642
 
2513 2643
 			$code = $tag['content'];
2514
-			foreach ($data as $k => $d)
2515
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2644
+			foreach ($data as $k => $d) {
2645
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2646
+			}
2516 2647
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2517 2648
 			$pos += strlen($code) - 1 + 2;
2518 2649
 		}
@@ -2520,24 +2651,28 @@  discard block
 block discarded – undo
2520 2651
 		elseif ($tag['type'] == 'unparsed_commas')
2521 2652
 		{
2522 2653
 			$pos2 = strpos($message, ']', $pos1);
2523
-			if ($pos2 === false)
2524
-				continue;
2654
+			if ($pos2 === false) {
2655
+							continue;
2656
+			}
2525 2657
 
2526 2658
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2527 2659
 
2528
-			if (isset($tag['validate']))
2529
-				$tag['validate']($tag, $data, $disabled, $params);
2660
+			if (isset($tag['validate'])) {
2661
+							$tag['validate']($tag, $data, $disabled, $params);
2662
+			}
2530 2663
 
2531 2664
 			// Fix after, for disabled code mainly.
2532
-			foreach ($data as $k => $d)
2533
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2665
+			foreach ($data as $k => $d) {
2666
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2667
+			}
2534 2668
 
2535 2669
 			$open_tags[] = $tag;
2536 2670
 
2537 2671
 			// Replace them out, $1, $2, $3, $4, etc.
2538 2672
 			$code = $tag['before'];
2539
-			foreach ($data as $k => $d)
2540
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2673
+			foreach ($data as $k => $d) {
2674
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2675
+			}
2541 2676
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2542 2677
 			$pos += strlen($code) - 1 + 2;
2543 2678
 		}
@@ -2548,28 +2683,33 @@  discard block
 block discarded – undo
2548 2683
 			if (isset($tag['quoted']))
2549 2684
 			{
2550 2685
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2551
-				if ($tag['quoted'] != 'optional' && !$quoted)
2552
-					continue;
2686
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2687
+									continue;
2688
+				}
2553 2689
 
2554
-				if ($quoted)
2555
-					$pos1 += 6;
2690
+				if ($quoted) {
2691
+									$pos1 += 6;
2692
+				}
2693
+			} else {
2694
+							$quoted = false;
2556 2695
 			}
2557
-			else
2558
-				$quoted = false;
2559 2696
 
2560 2697
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2561
-			if ($pos2 === false)
2562
-				continue;
2698
+			if ($pos2 === false) {
2699
+							continue;
2700
+			}
2563 2701
 
2564 2702
 			$data = substr($message, $pos1, $pos2 - $pos1);
2565 2703
 
2566 2704
 			// Validation for my parking, please!
2567
-			if (isset($tag['validate']))
2568
-				$tag['validate']($tag, $data, $disabled, $params);
2705
+			if (isset($tag['validate'])) {
2706
+							$tag['validate']($tag, $data, $disabled, $params);
2707
+			}
2569 2708
 
2570 2709
 			// For parsed content, we must recurse to avoid security problems.
2571
-			if ($tag['type'] != 'unparsed_equals')
2572
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2710
+			if ($tag['type'] != 'unparsed_equals') {
2711
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2712
+			}
2573 2713
 
2574 2714
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2575 2715
 
@@ -2581,34 +2721,40 @@  discard block
 block discarded – undo
2581 2721
 		}
2582 2722
 
2583 2723
 		// If this is block level, eat any breaks after it.
2584
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2585
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2724
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2725
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2726
+		}
2586 2727
 
2587 2728
 		// Are we trimming outside this tag?
2588
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2589
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2729
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2730
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2731
+		}
2590 2732
 	}
2591 2733
 
2592 2734
 	// Close any remaining tags.
2593
-	while ($tag = array_pop($open_tags))
2594
-		$message .= "\n" . $tag['after'] . "\n";
2735
+	while ($tag = array_pop($open_tags)) {
2736
+			$message .= "\n" . $tag['after'] . "\n";
2737
+	}
2595 2738
 
2596 2739
 	// Parse the smileys within the parts where it can be done safely.
2597 2740
 	if ($smileys === true)
2598 2741
 	{
2599 2742
 		$message_parts = explode("\n", $message);
2600
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2601
-			parsesmileys($message_parts[$i]);
2743
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2744
+					parsesmileys($message_parts[$i]);
2745
+		}
2602 2746
 
2603 2747
 		$message = implode('', $message_parts);
2604 2748
 	}
2605 2749
 
2606 2750
 	// No smileys, just get rid of the markers.
2607
-	else
2608
-		$message = strtr($message, array("\n" => ''));
2751
+	else {
2752
+			$message = strtr($message, array("\n" => ''));
2753
+	}
2609 2754
 
2610
-	if ($message !== '' && $message[0] === ' ')
2611
-		$message = '&nbsp;' . substr($message, 1);
2755
+	if ($message !== '' && $message[0] === ' ') {
2756
+			$message = '&nbsp;' . substr($message, 1);
2757
+	}
2612 2758
 
2613 2759
 	// Cleanup whitespace.
2614 2760
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2617,15 +2763,16 @@  discard block
 block discarded – undo
2617 2763
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2618 2764
 
2619 2765
 	// Cache the output if it took some time...
2620
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2621
-		cache_put_data($cache_key, $message, 240);
2766
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2767
+			cache_put_data($cache_key, $message, 240);
2768
+	}
2622 2769
 
2623 2770
 	// If this was a force parse revert if needed.
2624 2771
 	if (!empty($parse_tags))
2625 2772
 	{
2626
-		if (empty($temp_bbc))
2627
-			$bbc_codes = array();
2628
-		else
2773
+		if (empty($temp_bbc)) {
2774
+					$bbc_codes = array();
2775
+		} else
2629 2776
 		{
2630 2777
 			$bbc_codes = $temp_bbc;
2631 2778
 			unset($temp_bbc);
@@ -2652,8 +2799,9 @@  discard block
 block discarded – undo
2652 2799
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2653 2800
 
2654 2801
 	// No smiley set at all?!
2655
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2656
-		return;
2802
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2803
+			return;
2804
+	}
2657 2805
 
2658 2806
 	// If smileyPregSearch hasn't been set, do it now.
2659 2807
 	if (empty($smileyPregSearch))
@@ -2664,8 +2812,7 @@  discard block
 block discarded – undo
2664 2812
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2665 2813
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2666 2814
 			$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'], '', '', '', '');
2667
-		}
2668
-		else
2815
+		} else
2669 2816
 		{
2670 2817
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2671 2818
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2689,9 +2836,9 @@  discard block
 block discarded – undo
2689 2836
 				$smcFunc['db_free_result']($result);
2690 2837
 
2691 2838
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2839
+			} else {
2840
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2692 2841
 			}
2693
-			else
2694
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2695 2842
 		}
2696 2843
 
2697 2844
 		// The non-breaking-space is a complex thing...
@@ -2768,35 +2915,41 @@  discard block
 block discarded – undo
2768 2915
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2769 2916
 
2770 2917
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2771
-	if (!empty($context['flush_mail']))
2772
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2918
+	if (!empty($context['flush_mail'])) {
2919
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2773 2920
 		AddMailQueue(true);
2921
+	}
2774 2922
 
2775 2923
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2776 2924
 
2777
-	if ($add)
2778
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2925
+	if ($add) {
2926
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2927
+	}
2779 2928
 
2780 2929
 	// Put the session ID in.
2781
-	if (defined('SID') && SID != '')
2782
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2930
+	if (defined('SID') && SID != '') {
2931
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2932
+	}
2783 2933
 	// Keep that debug in their for template debugging!
2784
-	elseif (isset($_GET['debug']))
2785
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2934
+	elseif (isset($_GET['debug'])) {
2935
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2936
+	}
2786 2937
 
2787 2938
 	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'])))
2788 2939
 	{
2789
-		if (defined('SID') && SID != '')
2790
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2940
+		if (defined('SID') && SID != '') {
2941
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2791 2942
 				function ($m) use ($scripturl)
2792 2943
 				{
2793 2944
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2945
+		}
2794 2946
 				}, $setLocation);
2795
-		else
2796
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2947
+		else {
2948
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2797 2949
 				function ($m) use ($scripturl)
2798 2950
 				{
2799 2951
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2952
+		}
2800 2953
 				}, $setLocation);
2801 2954
 	}
2802 2955
 
@@ -2807,8 +2960,9 @@  discard block
 block discarded – undo
2807 2960
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2808 2961
 
2809 2962
 	// Debugging.
2810
-	if (isset($db_show_debug) && $db_show_debug === true)
2811
-		$_SESSION['debug_redirect'] = $db_cache;
2963
+	if (isset($db_show_debug) && $db_show_debug === true) {
2964
+			$_SESSION['debug_redirect'] = $db_cache;
2965
+	}
2812 2966
 
2813 2967
 	obExit(false);
2814 2968
 }
@@ -2827,51 +2981,60 @@  discard block
 block discarded – undo
2827 2981
 
2828 2982
 	// Attempt to prevent a recursive loop.
2829 2983
 	++$level;
2830
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2831
-		exit;
2832
-	if ($from_fatal_error)
2833
-		$has_fatal_error = true;
2984
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2985
+			exit;
2986
+	}
2987
+	if ($from_fatal_error) {
2988
+			$has_fatal_error = true;
2989
+	}
2834 2990
 
2835 2991
 	// Clear out the stat cache.
2836 2992
 	trackStats();
2837 2993
 
2838 2994
 	// If we have mail to send, send it.
2839
-	if (!empty($context['flush_mail']))
2840
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2995
+	if (!empty($context['flush_mail'])) {
2996
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2841 2997
 		AddMailQueue(true);
2998
+	}
2842 2999
 
2843 3000
 	$do_header = $header === null ? !$header_done : $header;
2844
-	if ($do_footer === null)
2845
-		$do_footer = $do_header;
3001
+	if ($do_footer === null) {
3002
+			$do_footer = $do_header;
3003
+	}
2846 3004
 
2847 3005
 	// Has the template/header been done yet?
2848 3006
 	if ($do_header)
2849 3007
 	{
2850 3008
 		// Was the page title set last minute? Also update the HTML safe one.
2851
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2852
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3009
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3010
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3011
+		}
2853 3012
 
2854 3013
 		// Start up the session URL fixer.
2855 3014
 		ob_start('ob_sessrewrite');
2856 3015
 
2857
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2858
-			$buffers = explode(',', $settings['output_buffers']);
2859
-		elseif (!empty($settings['output_buffers']))
2860
-			$buffers = $settings['output_buffers'];
2861
-		else
2862
-			$buffers = array();
3016
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3017
+					$buffers = explode(',', $settings['output_buffers']);
3018
+		} elseif (!empty($settings['output_buffers'])) {
3019
+					$buffers = $settings['output_buffers'];
3020
+		} else {
3021
+					$buffers = array();
3022
+		}
2863 3023
 
2864
-		if (isset($modSettings['integrate_buffer']))
2865
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3024
+		if (isset($modSettings['integrate_buffer'])) {
3025
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3026
+		}
2866 3027
 
2867
-		if (!empty($buffers))
2868
-			foreach ($buffers as $function)
3028
+		if (!empty($buffers)) {
3029
+					foreach ($buffers as $function)
2869 3030
 			{
2870 3031
 				$call = call_helper($function, true);
3032
+		}
2871 3033
 
2872 3034
 				// Is it valid?
2873
-				if (!empty($call))
2874
-					ob_start($call);
3035
+				if (!empty($call)) {
3036
+									ob_start($call);
3037
+				}
2875 3038
 			}
2876 3039
 
2877 3040
 		// Display the screen in the logical order.
@@ -2883,8 +3046,9 @@  discard block
 block discarded – undo
2883 3046
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2884 3047
 
2885 3048
 		// Anything special to put out?
2886
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2887
-			echo $context['insert_after_template'];
3049
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3050
+					echo $context['insert_after_template'];
3051
+		}
2888 3052
 
2889 3053
 		// Just so we don't get caught in an endless loop of errors from the footer...
2890 3054
 		if (!$footer_done)
@@ -2893,14 +3057,16 @@  discard block
 block discarded – undo
2893 3057
 			template_footer();
2894 3058
 
2895 3059
 			// (since this is just debugging... it's okay that it's after </html>.)
2896
-			if (!isset($_REQUEST['xml']))
2897
-				displayDebug();
3060
+			if (!isset($_REQUEST['xml'])) {
3061
+							displayDebug();
3062
+			}
2898 3063
 		}
2899 3064
 	}
2900 3065
 
2901 3066
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2902
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2903
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3067
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3068
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3069
+	}
2904 3070
 
2905 3071
 	// For session check verification.... don't switch browsers...
2906 3072
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2909,9 +3075,10 @@  discard block
 block discarded – undo
2909 3075
 	call_integration_hook('integrate_exit', array($do_footer));
2910 3076
 
2911 3077
 	// Don't exit if we're coming from index.php; that will pass through normally.
2912
-	if (!$from_index)
2913
-		exit;
2914
-}
3078
+	if (!$from_index) {
3079
+			exit;
3080
+	}
3081
+	}
2915 3082
 
2916 3083
 /**
2917 3084
  * Get the size of a specified image with better error handling.
@@ -2930,8 +3097,9 @@  discard block
 block discarded – undo
2930 3097
 	$url = str_replace(' ', '%20', $url);
2931 3098
 
2932 3099
 	// Can we pull this from the cache... please please?
2933
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2934
-		return $temp;
3100
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3101
+			return $temp;
3102
+	}
2935 3103
 	$t = microtime();
2936 3104
 
2937 3105
 	// Get the host to pester...
@@ -2941,12 +3109,10 @@  discard block
 block discarded – undo
2941 3109
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2942 3110
 	{
2943 3111
 		return false;
2944
-	}
2945
-	elseif (!isset($match[1]))
3112
+	} elseif (!isset($match[1]))
2946 3113
 	{
2947 3114
 		$size = @getimagesize($url);
2948
-	}
2949
-	else
3115
+	} else
2950 3116
 	{
2951 3117
 		// Try to connect to the server... give it half a second.
2952 3118
 		$temp = 0;
@@ -2985,12 +3151,14 @@  discard block
 block discarded – undo
2985 3151
 	}
2986 3152
 
2987 3153
 	// If we didn't get it, we failed.
2988
-	if (!isset($size))
2989
-		$size = false;
3154
+	if (!isset($size)) {
3155
+			$size = false;
3156
+	}
2990 3157
 
2991 3158
 	// If this took a long time, we may never have to do it again, but then again we might...
2992
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
2993
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3159
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3160
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3161
+	}
2994 3162
 
2995 3163
 	// Didn't work.
2996 3164
 	return $size;
@@ -3008,8 +3176,9 @@  discard block
 block discarded – undo
3008 3176
 
3009 3177
 	// Under SSI this function can be called more then once.  That can cause some problems.
3010 3178
 	//   So only run the function once unless we are forced to run it again.
3011
-	if ($loaded && !$forceload)
3012
-		return;
3179
+	if ($loaded && !$forceload) {
3180
+			return;
3181
+	}
3013 3182
 
3014 3183
 	$loaded = true;
3015 3184
 
@@ -3021,14 +3190,16 @@  discard block
 block discarded – undo
3021 3190
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3022 3191
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3023 3192
 	{
3024
-		if (trim($context['news_lines'][$i]) == '')
3025
-			continue;
3193
+		if (trim($context['news_lines'][$i]) == '') {
3194
+					continue;
3195
+		}
3026 3196
 
3027 3197
 		// Clean it up for presentation ;).
3028 3198
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3029 3199
 	}
3030
-	if (!empty($context['news_lines']))
3031
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3200
+	if (!empty($context['news_lines'])) {
3201
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3202
+	}
3032 3203
 
3033 3204
 	if (!$user_info['is_guest'])
3034 3205
 	{
@@ -3037,40 +3208,48 @@  discard block
 block discarded – undo
3037 3208
 		$context['user']['alerts'] = &$user_info['alerts'];
3038 3209
 
3039 3210
 		// Personal message popup...
3040
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3041
-			$context['user']['popup_messages'] = true;
3042
-		else
3043
-			$context['user']['popup_messages'] = false;
3211
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3212
+					$context['user']['popup_messages'] = true;
3213
+		} else {
3214
+					$context['user']['popup_messages'] = false;
3215
+		}
3044 3216
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3045 3217
 
3046
-		if (allowedTo('moderate_forum'))
3047
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3218
+		if (allowedTo('moderate_forum')) {
3219
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3220
+		}
3048 3221
 
3049 3222
 		$context['user']['avatar'] = array();
3050 3223
 
3051 3224
 		// Check for gravatar first since we might be forcing them...
3052 3225
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3053 3226
 		{
3054
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3055
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3056
-			else
3057
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3227
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3228
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3229
+			} else {
3230
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3231
+			}
3058 3232
 		}
3059 3233
 		// Uploaded?
3060
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3061
-			$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';
3234
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3235
+					$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';
3236
+		}
3062 3237
 		// Full URL?
3063
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3064
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3238
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3239
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3240
+		}
3065 3241
 		// Otherwise we assume it's server stored.
3066
-		elseif ($user_info['avatar']['url'] != '')
3067
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3242
+		elseif ($user_info['avatar']['url'] != '') {
3243
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3244
+		}
3068 3245
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3069
-		else
3070
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3246
+		else {
3247
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3248
+		}
3071 3249
 
3072
-		if (!empty($context['user']['avatar']))
3073
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3250
+		if (!empty($context['user']['avatar'])) {
3251
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3252
+		}
3074 3253
 
3075 3254
 		// Figure out how long they've been logged in.
3076 3255
 		$context['user']['total_time_logged_in'] = array(
@@ -3078,8 +3257,7 @@  discard block
 block discarded – undo
3078 3257
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3079 3258
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3080 3259
 		);
3081
-	}
3082
-	else
3260
+	} else
3083 3261
 	{
3084 3262
 		$context['user']['messages'] = 0;
3085 3263
 		$context['user']['unread_messages'] = 0;
@@ -3087,12 +3265,14 @@  discard block
 block discarded – undo
3087 3265
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3088 3266
 		$context['user']['popup_messages'] = false;
3089 3267
 
3090
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3091
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3268
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3269
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3270
+		}
3092 3271
 
3093 3272
 		// If we've upgraded recently, go easy on the passwords.
3094
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3095
-			$context['disable_login_hashing'] = true;
3273
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3274
+					$context['disable_login_hashing'] = true;
3275
+		}
3096 3276
 	}
3097 3277
 
3098 3278
 	// Setup the main menu items.
@@ -3105,8 +3285,8 @@  discard block
 block discarded – undo
3105 3285
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3106 3286
 
3107 3287
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3108
-	if ($context['show_pm_popup'])
3109
-		addInlineJavaScript('
3288
+	if ($context['show_pm_popup']) {
3289
+			addInlineJavaScript('
3110 3290
 		jQuery(document).ready(function($) {
3111 3291
 			new smc_Popup({
3112 3292
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3114,15 +3294,17 @@  discard block
 block discarded – undo
3114 3294
 				icon_class: \'generic_icons mail_new\'
3115 3295
 			});
3116 3296
 		});');
3297
+	}
3117 3298
 
3118 3299
 	// Add a generic "Are you sure?" confirmation message.
3119 3300
 	addInlineJavaScript('
3120 3301
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3121 3302
 
3122 3303
 	// Now add the capping code for avatars.
3123
-	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')
3124
-		addInlineCss('
3304
+	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') {
3305
+			addInlineCss('
3125 3306
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3307
+	}
3126 3308
 
3127 3309
 	// This looks weird, but it's because BoardIndex.php references the variable.
3128 3310
 	$context['common_stats']['latest_member'] = array(
@@ -3139,11 +3321,13 @@  discard block
 block discarded – undo
3139 3321
 	);
3140 3322
 	$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']);
3141 3323
 
3142
-	if (empty($settings['theme_version']))
3143
-		addJavaScriptVar('smf_scripturl', $scripturl);
3324
+	if (empty($settings['theme_version'])) {
3325
+			addJavaScriptVar('smf_scripturl', $scripturl);
3326
+	}
3144 3327
 
3145
-	if (!isset($context['page_title']))
3146
-		$context['page_title'] = '';
3328
+	if (!isset($context['page_title'])) {
3329
+			$context['page_title'] = '';
3330
+	}
3147 3331
 
3148 3332
 	// Set some specific vars.
3149 3333
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3153,21 +3337,23 @@  discard block
 block discarded – undo
3153 3337
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3154 3338
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3155 3339
 
3156
-	if (!empty($context['meta_keywords']))
3157
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3340
+	if (!empty($context['meta_keywords'])) {
3341
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3342
+	}
3158 3343
 
3159
-	if (!empty($context['canonical_url']))
3160
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3344
+	if (!empty($context['canonical_url'])) {
3345
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3346
+	}
3161 3347
 
3162
-	if (!empty($settings['og_image']))
3163
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3348
+	if (!empty($settings['og_image'])) {
3349
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3350
+	}
3164 3351
 
3165 3352
 	if (!empty($context['meta_description']))
3166 3353
 	{
3167 3354
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3168 3355
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3169
-	}
3170
-	else
3356
+	} else
3171 3357
 	{
3172 3358
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3173 3359
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3192,8 +3378,9 @@  discard block
 block discarded – undo
3192 3378
 	$memory_needed = memoryReturnBytes($needed);
3193 3379
 
3194 3380
 	// should we account for how much is currently being used?
3195
-	if ($in_use)
3196
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3381
+	if ($in_use) {
3382
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3383
+	}
3197 3384
 
3198 3385
 	// if more is needed, request it
3199 3386
 	if ($memory_current < $memory_needed)
@@ -3216,8 +3403,9 @@  discard block
 block discarded – undo
3216 3403
  */
3217 3404
 function memoryReturnBytes($val)
3218 3405
 {
3219
-	if (is_integer($val))
3220
-		return $val;
3406
+	if (is_integer($val)) {
3407
+			return $val;
3408
+	}
3221 3409
 
3222 3410
 	// Separate the number from the designator
3223 3411
 	$val = trim($val);
@@ -3253,10 +3441,11 @@  discard block
 block discarded – undo
3253 3441
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3254 3442
 
3255 3443
 		// Are we debugging the template/html content?
3256
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3257
-			header('Content-Type: application/xhtml+xml');
3258
-		elseif (!isset($_REQUEST['xml']))
3259
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3444
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3445
+					header('Content-Type: application/xhtml+xml');
3446
+		} elseif (!isset($_REQUEST['xml'])) {
3447
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3448
+		}
3260 3449
 	}
3261 3450
 
3262 3451
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3265,8 +3454,9 @@  discard block
 block discarded – undo
3265 3454
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3266 3455
 	{
3267 3456
 		$position = array_search('body', $context['template_layers']);
3268
-		if ($position === false)
3269
-			$position = array_search('main', $context['template_layers']);
3457
+		if ($position === false) {
3458
+					$position = array_search('main', $context['template_layers']);
3459
+		}
3270 3460
 
3271 3461
 		if ($position !== false)
3272 3462
 		{
@@ -3294,23 +3484,25 @@  discard block
 block discarded – undo
3294 3484
 
3295 3485
 			foreach ($securityFiles as $i => $securityFile)
3296 3486
 			{
3297
-				if (!file_exists($boarddir . '/' . $securityFile))
3298
-					unset($securityFiles[$i]);
3487
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3488
+									unset($securityFiles[$i]);
3489
+				}
3299 3490
 			}
3300 3491
 
3301 3492
 			// We are already checking so many files...just few more doesn't make any difference! :P
3302
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3303
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3304
-
3305
-			else
3306
-				$path = $modSettings['attachmentUploadDir'];
3493
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3494
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3495
+			} else {
3496
+							$path = $modSettings['attachmentUploadDir'];
3497
+			}
3307 3498
 
3308 3499
 			secureDirectory($path, true);
3309 3500
 			secureDirectory($cachedir);
3310 3501
 
3311 3502
 			// If agreement is enabled, at least the english version shall exists
3312
-			if ($modSettings['requireAgreement'])
3313
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3503
+			if ($modSettings['requireAgreement']) {
3504
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3505
+			}
3314 3506
 
3315 3507
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3316 3508
 			{
@@ -3325,18 +3517,21 @@  discard block
 block discarded – undo
3325 3517
 					echo '
3326 3518
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3327 3519
 
3328
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3329
-						echo '
3520
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3521
+											echo '
3330 3522
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3523
+					}
3331 3524
 				}
3332 3525
 
3333
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3334
-					echo '
3526
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3527
+									echo '
3335 3528
 				<strong>', $txt['cache_writable'], '</strong><br>';
3529
+				}
3336 3530
 
3337
-				if (!empty($agreement))
3338
-					echo '
3531
+				if (!empty($agreement)) {
3532
+									echo '
3339 3533
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3534
+				}
3340 3535
 
3341 3536
 				echo '
3342 3537
 			</p>
@@ -3351,16 +3546,18 @@  discard block
 block discarded – undo
3351 3546
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3352 3547
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3353 3548
 
3354
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3355
-				echo '
3549
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3550
+							echo '
3356 3551
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3552
+			}
3357 3553
 
3358
-			if (!empty($_SESSION['ban']['expire_time']))
3359
-				echo '
3554
+			if (!empty($_SESSION['ban']['expire_time'])) {
3555
+							echo '
3360 3556
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3361
-			else
3362
-				echo '
3557
+			} else {
3558
+							echo '
3363 3559
 					<div>', $txt['your_ban_expires_never'], '</div>';
3560
+			}
3364 3561
 
3365 3562
 			echo '
3366 3563
 				</div>';
@@ -3376,8 +3573,9 @@  discard block
 block discarded – undo
3376 3573
 	global $forum_copyright, $software_year, $forum_version;
3377 3574
 
3378 3575
 	// Don't display copyright for things like SSI.
3379
-	if (!isset($forum_version) || !isset($software_year))
3380
-		return;
3576
+	if (!isset($forum_version) || !isset($software_year)) {
3577
+			return;
3578
+	}
3381 3579
 
3382 3580
 	// Put in the version...
3383 3581
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3395,9 +3593,10 @@  discard block
 block discarded – undo
3395 3593
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3396 3594
 	$context['load_queries'] = $db_count;
3397 3595
 
3398
-	foreach (array_reverse($context['template_layers']) as $layer)
3399
-		loadSubTemplate($layer . '_below', true);
3400
-}
3596
+	foreach (array_reverse($context['template_layers']) as $layer) {
3597
+			loadSubTemplate($layer . '_below', true);
3598
+	}
3599
+	}
3401 3600
 
3402 3601
 /**
3403 3602
  * Output the Javascript files
@@ -3428,8 +3627,7 @@  discard block
 block discarded – undo
3428 3627
 			{
3429 3628
 				echo '
3430 3629
 		var ', $key, ';';
3431
-			}
3432
-			else
3630
+			} else
3433 3631
 			{
3434 3632
 				echo '
3435 3633
 		var ', $key, ' = ', $value, ';';
@@ -3444,26 +3642,27 @@  discard block
 block discarded – undo
3444 3642
 	foreach ($context['javascript_files'] as $id => $js_file)
3445 3643
 	{
3446 3644
 		// Last minute call! allow theme authors to disable single files.
3447
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3448
-			continue;
3645
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3646
+					continue;
3647
+		}
3449 3648
 
3450 3649
 		// By default all files don't get minimized unless the file explicitly says so!
3451 3650
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3452 3651
 		{
3453
-			if ($do_deferred && !empty($js_file['options']['defer']))
3454
-				$toMinifyDefer[] = $js_file;
3455
-
3456
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3457
-				$toMinify[] = $js_file;
3652
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3653
+							$toMinifyDefer[] = $js_file;
3654
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3655
+							$toMinify[] = $js_file;
3656
+			}
3458 3657
 
3459 3658
 			// Grab a random seed.
3460
-			if (!isset($minSeed))
3461
-				$minSeed = $js_file['options']['seed'];
3462
-		}
3463
-
3464
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3465
-			echo '
3659
+			if (!isset($minSeed)) {
3660
+							$minSeed = $js_file['options']['seed'];
3661
+			}
3662
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3663
+					echo '
3466 3664
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3665
+		}
3467 3666
 	}
3468 3667
 
3469 3668
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3471,14 +3670,14 @@  discard block
 block discarded – undo
3471 3670
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3472 3671
 
3473 3672
 		// Minify process couldn't work, print each individual files.
3474
-		if (!empty($result) && is_array($result))
3475
-			foreach ($result as $minFailedFile)
3673
+		if (!empty($result) && is_array($result)) {
3674
+					foreach ($result as $minFailedFile)
3476 3675
 				echo '
3477 3676
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3478
-
3479
-		else
3480
-			echo '
3677
+		} else {
3678
+					echo '
3481 3679
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3680
+		}
3482 3681
 	}
3483 3682
 
3484 3683
 	// Inline JavaScript - Actually useful some times!
@@ -3489,8 +3688,9 @@  discard block
 block discarded – undo
3489 3688
 			echo '
3490 3689
 <script>';
3491 3690
 
3492
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3493
-				echo $js_code;
3691
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3692
+							echo $js_code;
3693
+			}
3494 3694
 
3495 3695
 			echo '
3496 3696
 </script>';
@@ -3501,8 +3701,9 @@  discard block
 block discarded – undo
3501 3701
 			echo '
3502 3702
 	<script>';
3503 3703
 
3504
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3505
-				echo $js_code;
3704
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3705
+							echo $js_code;
3706
+			}
3506 3707
 
3507 3708
 			echo '
3508 3709
 	</script>';
@@ -3527,8 +3728,9 @@  discard block
 block discarded – undo
3527 3728
 	foreach ($context['css_files'] as $id => $file)
3528 3729
 	{
3529 3730
 		// Last minute call! allow theme authors to disable single files.
3530
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3531
-			continue;
3731
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3732
+					continue;
3733
+		}
3532 3734
 
3533 3735
 		// By default all files don't get minimized unless the file explicitly says so!
3534 3736
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3536,12 +3738,12 @@  discard block
 block discarded – undo
3536 3738
 			$toMinify[] = $file;
3537 3739
 
3538 3740
 			// Grab a random seed.
3539
-			if (!isset($minSeed))
3540
-				$minSeed = $file['options']['seed'];
3741
+			if (!isset($minSeed)) {
3742
+							$minSeed = $file['options']['seed'];
3743
+			}
3744
+		} else {
3745
+					$normal[] = $file['fileUrl'];
3541 3746
 		}
3542
-
3543
-		else
3544
-			$normal[] = $file['fileUrl'];
3545 3747
 	}
3546 3748
 
3547 3749
 	if (!empty($toMinify))
@@ -3549,28 +3751,30 @@  discard block
 block discarded – undo
3549 3751
 		$result = custMinify($toMinify, 'css');
3550 3752
 
3551 3753
 		// Minify process couldn't work, print each individual files.
3552
-		if (!empty($result) && is_array($result))
3553
-			foreach ($result as $minFailedFile)
3754
+		if (!empty($result) && is_array($result)) {
3755
+					foreach ($result as $minFailedFile)
3554 3756
 				echo '
3555 3757
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3556
-
3557
-		else
3558
-			echo '
3758
+		} else {
3759
+					echo '
3559 3760
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3761
+		}
3560 3762
 	}
3561 3763
 
3562 3764
 	// Print the rest after the minified files.
3563
-	if (!empty($normal))
3564
-		foreach ($normal as $nf)
3765
+	if (!empty($normal)) {
3766
+			foreach ($normal as $nf)
3565 3767
 			echo '
3566 3768
 	<link rel="stylesheet" href="', $nf ,'">';
3769
+	}
3567 3770
 
3568 3771
 	if ($db_show_debug === true)
3569 3772
 	{
3570 3773
 		// Try to keep only what's useful.
3571 3774
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3572
-		foreach ($context['css_files'] as $file)
3573
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3775
+		foreach ($context['css_files'] as $file) {
3776
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3777
+		}
3574 3778
 	}
3575 3779
 
3576 3780
 	if (!empty($context['css_header']))
@@ -3578,9 +3782,10 @@  discard block
 block discarded – undo
3578 3782
 		echo '
3579 3783
 	<style>';
3580 3784
 
3581
-		foreach ($context['css_header'] as $css)
3582
-			echo $css .'
3785
+		foreach ($context['css_header'] as $css) {
3786
+					echo $css .'
3583 3787
 	';
3788
+		}
3584 3789
 
3585 3790
 		echo'
3586 3791
 	</style>';
@@ -3604,15 +3809,17 @@  discard block
 block discarded – undo
3604 3809
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3605 3810
 	$data = !empty($data) ? $data : false;
3606 3811
 
3607
-	if (empty($type) || empty($data))
3608
-		return false;
3812
+	if (empty($type) || empty($data)) {
3813
+			return false;
3814
+	}
3609 3815
 
3610 3816
 	// Did we already did this?
3611 3817
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3612 3818
 
3613 3819
 	// Already done?
3614
-	if (!empty($toCache))
3615
-		return true;
3820
+	if (!empty($toCache)) {
3821
+			return true;
3822
+	}
3616 3823
 
3617 3824
 	// No namespaces, sorry!
3618 3825
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3694,8 +3901,9 @@  discard block
 block discarded – undo
3694 3901
 	global $modSettings, $smcFunc;
3695 3902
 
3696 3903
 	// Just make up a nice hash...
3697
-	if ($new)
3698
-		return sha1(md5($filename . time()) . mt_rand());
3904
+	if ($new) {
3905
+			return sha1(md5($filename . time()) . mt_rand());
3906
+	}
3699 3907
 
3700 3908
 	// Just make sure that attachment id is only a int
3701 3909
 	$attachment_id = (int) $attachment_id;
@@ -3712,23 +3920,25 @@  discard block
 block discarded – undo
3712 3920
 				'id_attach' => $attachment_id,
3713 3921
 			));
3714 3922
 
3715
-		if ($smcFunc['db_num_rows']($request) === 0)
3716
-			return false;
3923
+		if ($smcFunc['db_num_rows']($request) === 0) {
3924
+					return false;
3925
+		}
3717 3926
 
3718 3927
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3719 3928
 		$smcFunc['db_free_result']($request);
3720 3929
 	}
3721 3930
 
3722 3931
 	// Still no hash? mmm...
3723
-	if (empty($file_hash))
3724
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3932
+	if (empty($file_hash)) {
3933
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3934
+	}
3725 3935
 
3726 3936
 	// Are we using multiple directories?
3727
-	if (is_array($modSettings['attachmentUploadDir']))
3728
-		$path = $modSettings['attachmentUploadDir'][$dir];
3729
-
3730
-	else
3731
-		$path = $modSettings['attachmentUploadDir'];
3937
+	if (is_array($modSettings['attachmentUploadDir'])) {
3938
+			$path = $modSettings['attachmentUploadDir'][$dir];
3939
+	} else {
3940
+			$path = $modSettings['attachmentUploadDir'];
3941
+	}
3732 3942
 
3733 3943
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3734 3944
 }
@@ -3743,8 +3953,9 @@  discard block
 block discarded – undo
3743 3953
 function ip2range($fullip)
3744 3954
 {
3745 3955
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3746
-	if ($fullip == 'unknown')
3747
-		$fullip = '255.255.255.255';
3956
+	if ($fullip == 'unknown') {
3957
+			$fullip = '255.255.255.255';
3958
+	}
3748 3959
 
3749 3960
 	$ip_parts = explode('-', $fullip);
3750 3961
 	$ip_array = array();
@@ -3768,10 +3979,11 @@  discard block
 block discarded – undo
3768 3979
 		$ip_array['low'] = $ip_parts[0];
3769 3980
 		$ip_array['high'] = $ip_parts[1];
3770 3981
 		return $ip_array;
3771
-	}
3772
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3982
+	} elseif (count($ip_parts) == 2) {
3983
+		// if ip 22.22.*-22.22.*
3773 3984
 	{
3774 3985
 		$valid_low = isValidIP($ip_parts[0]);
3986
+	}
3775 3987
 		$valid_high = isValidIP($ip_parts[1]);
3776 3988
 		$count = 0;
3777 3989
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3786,7 +3998,9 @@  discard block
 block discarded – undo
3786 3998
 				$ip_parts[0] .= $mode . $min;
3787 3999
 				$valid_low = isValidIP($ip_parts[0]);
3788 4000
 				$count++;
3789
-				if ($count > 9) break;
4001
+				if ($count > 9) {
4002
+					break;
4003
+				}
3790 4004
 			}
3791 4005
 		}
3792 4006
 
@@ -3800,7 +4014,9 @@  discard block
 block discarded – undo
3800 4014
 				$ip_parts[1] .= $mode . $max;
3801 4015
 				$valid_high = isValidIP($ip_parts[1]);
3802 4016
 				$count++;
3803
-				if ($count > 9) break;
4017
+				if ($count > 9) {
4018
+					break;
4019
+				}
3804 4020
 			}
3805 4021
 		}
3806 4022
 
@@ -3825,46 +4041,54 @@  discard block
 block discarded – undo
3825 4041
 {
3826 4042
 	global $modSettings;
3827 4043
 
3828
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3829
-		return $host;
4044
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4045
+			return $host;
4046
+	}
3830 4047
 	$t = microtime();
3831 4048
 
3832 4049
 	// Try the Linux host command, perhaps?
3833 4050
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3834 4051
 	{
3835
-		if (!isset($modSettings['host_to_dis']))
3836
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3837
-		else
3838
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4052
+		if (!isset($modSettings['host_to_dis'])) {
4053
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4054
+		} else {
4055
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4056
+		}
3839 4057
 
3840 4058
 		// Did host say it didn't find anything?
3841
-		if (strpos($test, 'not found') !== false)
3842
-			$host = '';
4059
+		if (strpos($test, 'not found') !== false) {
4060
+					$host = '';
4061
+		}
3843 4062
 		// Invalid server option?
3844
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3845
-			updateSettings(array('host_to_dis' => 1));
4063
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4064
+					updateSettings(array('host_to_dis' => 1));
4065
+		}
3846 4066
 		// Maybe it found something, after all?
3847
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3848
-			$host = $match[1];
4067
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4068
+					$host = $match[1];
4069
+		}
3849 4070
 	}
3850 4071
 
3851 4072
 	// This is nslookup; usually only Windows, but possibly some Unix?
3852 4073
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3853 4074
 	{
3854 4075
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3855
-		if (strpos($test, 'Non-existent domain') !== false)
3856
-			$host = '';
3857
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3858
-			$host = $match[1];
4076
+		if (strpos($test, 'Non-existent domain') !== false) {
4077
+					$host = '';
4078
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4079
+					$host = $match[1];
4080
+		}
3859 4081
 	}
3860 4082
 
3861 4083
 	// This is the last try :/.
3862
-	if (!isset($host) || $host === false)
3863
-		$host = @gethostbyaddr($ip);
4084
+	if (!isset($host) || $host === false) {
4085
+			$host = @gethostbyaddr($ip);
4086
+	}
3864 4087
 
3865 4088
 	// It took a long time, so let's cache it!
3866
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3867
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4089
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4090
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4091
+	}
3868 4092
 
3869 4093
 	return $host;
3870 4094
 }
@@ -3900,20 +4124,21 @@  discard block
 block discarded – undo
3900 4124
 			{
3901 4125
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3902 4126
 				$total = 0;
3903
-				for ($i = 0; $i < $max_chars; $i++)
3904
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4127
+				for ($i = 0; $i < $max_chars; $i++) {
4128
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4129
+				}
3905 4130
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3906 4131
 			}
3907 4132
 		}
3908 4133
 		return array_unique($returned_ints);
3909
-	}
3910
-	else
4134
+	} else
3911 4135
 	{
3912 4136
 		// Trim characters before and after and add slashes for database insertion.
3913 4137
 		$returned_words = array();
3914
-		foreach ($words as $word)
3915
-			if (($word = trim($word, '-_\'')) !== '')
4138
+		foreach ($words as $word) {
4139
+					if (($word = trim($word, '-_\'')) !== '')
3916 4140
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4141
+		}
3917 4142
 
3918 4143
 		// Filter out all words that occur more than once.
3919 4144
 		return array_unique($returned_words);
@@ -3935,16 +4160,18 @@  discard block
 block discarded – undo
3935 4160
 	global $settings, $txt;
3936 4161
 
3937 4162
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3938
-	if (function_exists('template_create_button') && !$force_use)
3939
-		return template_create_button($name, $alt, $label = '', $custom = '');
4163
+	if (function_exists('template_create_button') && !$force_use) {
4164
+			return template_create_button($name, $alt, $label = '', $custom = '');
4165
+	}
3940 4166
 
3941
-	if (!$settings['use_image_buttons'])
3942
-		return $txt[$alt];
3943
-	elseif (!empty($settings['use_buttons']))
3944
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3945
-	else
3946
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3947
-}
4167
+	if (!$settings['use_image_buttons']) {
4168
+			return $txt[$alt];
4169
+	} elseif (!empty($settings['use_buttons'])) {
4170
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4171
+	} else {
4172
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4173
+	}
4174
+	}
3948 4175
 
3949 4176
 /**
3950 4177
  * Sets up all of the top menu buttons
@@ -3987,9 +4214,10 @@  discard block
 block discarded – undo
3987 4214
 	var user_menus = new smc_PopupMenu();
3988 4215
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3989 4216
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3990
-		if ($context['allow_pm'])
3991
-			addInlineJavaScript('
4217
+		if ($context['allow_pm']) {
4218
+					addInlineJavaScript('
3992 4219
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4220
+		}
3993 4221
 
3994 4222
 		if (!empty($modSettings['enable_ajax_alerts']))
3995 4223
 		{
@@ -4149,88 +4377,96 @@  discard block
 block discarded – undo
4149 4377
 
4150 4378
 		// Now we put the buttons in the context so the theme can use them.
4151 4379
 		$menu_buttons = array();
4152
-		foreach ($buttons as $act => $button)
4153
-			if (!empty($button['show']))
4380
+		foreach ($buttons as $act => $button) {
4381
+					if (!empty($button['show']))
4154 4382
 			{
4155 4383
 				$button['active_button'] = false;
4384
+		}
4156 4385
 
4157 4386
 				// This button needs some action.
4158
-				if (isset($button['action_hook']))
4159
-					$needs_action_hook = true;
4387
+				if (isset($button['action_hook'])) {
4388
+									$needs_action_hook = true;
4389
+				}
4160 4390
 
4161 4391
 				// Make sure the last button truly is the last button.
4162 4392
 				if (!empty($button['is_last']))
4163 4393
 				{
4164
-					if (isset($last_button))
4165
-						unset($menu_buttons[$last_button]['is_last']);
4394
+					if (isset($last_button)) {
4395
+											unset($menu_buttons[$last_button]['is_last']);
4396
+					}
4166 4397
 					$last_button = $act;
4167 4398
 				}
4168 4399
 
4169 4400
 				// Go through the sub buttons if there are any.
4170
-				if (!empty($button['sub_buttons']))
4171
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4401
+				if (!empty($button['sub_buttons'])) {
4402
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4172 4403
 					{
4173 4404
 						if (empty($subbutton['show']))
4174 4405
 							unset($button['sub_buttons'][$key]);
4406
+				}
4175 4407
 
4176 4408
 						// 2nd level sub buttons next...
4177 4409
 						if (!empty($subbutton['sub_buttons']))
4178 4410
 						{
4179 4411
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4180 4412
 							{
4181
-								if (empty($sub_button2['show']))
4182
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4413
+								if (empty($sub_button2['show'])) {
4414
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4415
+								}
4183 4416
 							}
4184 4417
 						}
4185 4418
 					}
4186 4419
 
4187 4420
 				// Does this button have its own icon?
4188
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4189
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4190
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4191
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4192
-				elseif (isset($button['icon']))
4193
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4194
-				else
4195
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4421
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4422
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4423
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4424
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4425
+				} elseif (isset($button['icon'])) {
4426
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4427
+				} else {
4428
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4429
+				}
4196 4430
 
4197 4431
 				$menu_buttons[$act] = $button;
4198 4432
 			}
4199 4433
 
4200
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4201
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4434
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4435
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4436
+		}
4202 4437
 	}
4203 4438
 
4204 4439
 	$context['menu_buttons'] = $menu_buttons;
4205 4440
 
4206 4441
 	// Logging out requires the session id in the url.
4207
-	if (isset($context['menu_buttons']['logout']))
4208
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4442
+	if (isset($context['menu_buttons']['logout'])) {
4443
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4444
+	}
4209 4445
 
4210 4446
 	// Figure out which action we are doing so we can set the active tab.
4211 4447
 	// Default to home.
4212 4448
 	$current_action = 'home';
4213 4449
 
4214
-	if (isset($context['menu_buttons'][$context['current_action']]))
4215
-		$current_action = $context['current_action'];
4216
-	elseif ($context['current_action'] == 'search2')
4217
-		$current_action = 'search';
4218
-	elseif ($context['current_action'] == 'theme')
4219
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4220
-	elseif ($context['current_action'] == 'register2')
4221
-		$current_action = 'register';
4222
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4223
-		$current_action = 'login';
4224
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4225
-		$current_action = 'moderate';
4450
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4451
+			$current_action = $context['current_action'];
4452
+	} elseif ($context['current_action'] == 'search2') {
4453
+			$current_action = 'search';
4454
+	} elseif ($context['current_action'] == 'theme') {
4455
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4456
+	} elseif ($context['current_action'] == 'register2') {
4457
+			$current_action = 'register';
4458
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4459
+			$current_action = 'login';
4460
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4461
+			$current_action = 'moderate';
4462
+	}
4226 4463
 
4227 4464
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4228 4465
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4229 4466
 	{
4230 4467
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4231 4468
 		$context[$current_action] = true;
4232
-	}
4233
-	elseif ($context['current_action'] == 'pm')
4469
+	} elseif ($context['current_action'] == 'pm')
4234 4470
 	{
4235 4471
 		$current_action = 'self_pm';
4236 4472
 		$context['self_pm'] = true;
@@ -4273,12 +4509,14 @@  discard block
 block discarded – undo
4273 4509
 	}
4274 4510
 
4275 4511
 	// Not all actions are simple.
4276
-	if (!empty($needs_action_hook))
4277
-		call_integration_hook('integrate_current_action', array(&$current_action));
4512
+	if (!empty($needs_action_hook)) {
4513
+			call_integration_hook('integrate_current_action', array(&$current_action));
4514
+	}
4278 4515
 
4279
-	if (isset($context['menu_buttons'][$current_action]))
4280
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4281
-}
4516
+	if (isset($context['menu_buttons'][$current_action])) {
4517
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4518
+	}
4519
+	}
4282 4520
 
4283 4521
 /**
4284 4522
  * Generate a random seed and ensure it's stored in settings.
@@ -4302,16 +4540,19 @@  discard block
 block discarded – undo
4302 4540
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4303 4541
 	global $context, $txt;
4304 4542
 
4305
-	if ($db_show_debug === true)
4306
-		$context['debug']['hooks'][] = $hook;
4543
+	if ($db_show_debug === true) {
4544
+			$context['debug']['hooks'][] = $hook;
4545
+	}
4307 4546
 
4308 4547
 	// Need to have some control.
4309
-	if (!isset($context['instances']))
4310
-		$context['instances'] = array();
4548
+	if (!isset($context['instances'])) {
4549
+			$context['instances'] = array();
4550
+	}
4311 4551
 
4312 4552
 	$results = array();
4313
-	if (empty($modSettings[$hook]))
4314
-		return $results;
4553
+	if (empty($modSettings[$hook])) {
4554
+			return $results;
4555
+	}
4315 4556
 
4316 4557
 	// Define some needed vars.
4317 4558
 	$function = false;
@@ -4321,14 +4562,16 @@  discard block
 block discarded – undo
4321 4562
 	foreach ($functions as $function)
4322 4563
 	{
4323 4564
 		// Hook has been marked as "disabled". Skip it!
4324
-		if (strpos($function, '!') !== false)
4325
-			continue;
4565
+		if (strpos($function, '!') !== false) {
4566
+					continue;
4567
+		}
4326 4568
 
4327 4569
 		$call = call_helper($function, true);
4328 4570
 
4329 4571
 		// Is it valid?
4330
-		if (!empty($call))
4331
-			$results[$function] = call_user_func_array($call, $parameters);
4572
+		if (!empty($call)) {
4573
+					$results[$function] = call_user_func_array($call, $parameters);
4574
+		}
4332 4575
 
4333 4576
 		// Whatever it was suppose to call, it failed :(
4334 4577
 		elseif (!empty($function))
@@ -4344,8 +4587,9 @@  discard block
 block discarded – undo
4344 4587
 			}
4345 4588
 
4346 4589
 			// "Assume" the file resides on $boarddir somewhere...
4347
-			else
4348
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4590
+			else {
4591
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4592
+			}
4349 4593
 		}
4350 4594
 	}
4351 4595
 
@@ -4367,12 +4611,14 @@  discard block
 block discarded – undo
4367 4611
 	global $smcFunc, $modSettings;
4368 4612
 
4369 4613
 	// Any objects?
4370
-	if ($object)
4371
-		$function = $function . '#';
4614
+	if ($object) {
4615
+			$function = $function . '#';
4616
+	}
4372 4617
 
4373 4618
 	// Any files  to load?
4374
-	if (!empty($file) && is_string($file))
4375
-		$function = $file . (!empty($function) ? '|' . $function : '');
4619
+	if (!empty($file) && is_string($file)) {
4620
+			$function = $file . (!empty($function) ? '|' . $function : '');
4621
+	}
4376 4622
 
4377 4623
 	// Get the correct string.
4378 4624
 	$integration_call = $function;
@@ -4394,13 +4640,14 @@  discard block
 block discarded – undo
4394 4640
 		if (!empty($current_functions))
4395 4641
 		{
4396 4642
 			$current_functions = explode(',', $current_functions);
4397
-			if (in_array($integration_call, $current_functions))
4398
-				return;
4643
+			if (in_array($integration_call, $current_functions)) {
4644
+							return;
4645
+			}
4399 4646
 
4400 4647
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4648
+		} else {
4649
+					$permanent_functions = array($integration_call);
4401 4650
 		}
4402
-		else
4403
-			$permanent_functions = array($integration_call);
4404 4651
 
4405 4652
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4406 4653
 	}
@@ -4409,8 +4656,9 @@  discard block
 block discarded – undo
4409 4656
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4410 4657
 
4411 4658
 	// Do nothing, if it's already there.
4412
-	if (in_array($integration_call, $functions))
4413
-		return;
4659
+	if (in_array($integration_call, $functions)) {
4660
+			return;
4661
+	}
4414 4662
 
4415 4663
 	$functions[] = $integration_call;
4416 4664
 	$modSettings[$hook] = implode(',', $functions);
@@ -4433,12 +4681,14 @@  discard block
 block discarded – undo
4433 4681
 	global $smcFunc, $modSettings;
4434 4682
 
4435 4683
 	// Any objects?
4436
-	if ($object)
4437
-		$function = $function . '#';
4684
+	if ($object) {
4685
+			$function = $function . '#';
4686
+	}
4438 4687
 
4439 4688
 	// Any files  to load?
4440
-	if (!empty($file) && is_string($file))
4441
-		$function = $file . '|' . $function;
4689
+	if (!empty($file) && is_string($file)) {
4690
+			$function = $file . '|' . $function;
4691
+	}
4442 4692
 
4443 4693
 	// Get the correct string.
4444 4694
 	$integration_call = $function;
@@ -4459,16 +4709,18 @@  discard block
 block discarded – undo
4459 4709
 	{
4460 4710
 		$current_functions = explode(',', $current_functions);
4461 4711
 
4462
-		if (in_array($integration_call, $current_functions))
4463
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4712
+		if (in_array($integration_call, $current_functions)) {
4713
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4714
+		}
4464 4715
 	}
4465 4716
 
4466 4717
 	// Turn the function list into something usable.
4467 4718
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4468 4719
 
4469 4720
 	// You can only remove it if it's available.
4470
-	if (!in_array($integration_call, $functions))
4471
-		return;
4721
+	if (!in_array($integration_call, $functions)) {
4722
+			return;
4723
+	}
4472 4724
 
4473 4725
 	$functions = array_diff($functions, array($integration_call));
4474 4726
 	$modSettings[$hook] = implode(',', $functions);
@@ -4489,17 +4741,20 @@  discard block
 block discarded – undo
4489 4741
 	global $context, $smcFunc, $txt, $db_show_debug;
4490 4742
 
4491 4743
 	// Really?
4492
-	if (empty($string))
4493
-		return false;
4744
+	if (empty($string)) {
4745
+			return false;
4746
+	}
4494 4747
 
4495 4748
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4496 4749
 	// A closure? should be a callable one.
4497
-	if (is_array($string) || $string instanceof Closure)
4498
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4750
+	if (is_array($string) || $string instanceof Closure) {
4751
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4752
+	}
4499 4753
 
4500 4754
 	// No full objects, sorry! pass a method or a property instead!
4501
-	if (is_object($string))
4502
-		return false;
4755
+	if (is_object($string)) {
4756
+			return false;
4757
+	}
4503 4758
 
4504 4759
 	// Stay vitaminized my friends...
4505 4760
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4508,8 +4763,9 @@  discard block
 block discarded – undo
4508 4763
 	$string = load_file($string);
4509 4764
 
4510 4765
 	// Loaded file failed
4511
-	if (empty($string))
4512
-		return false;
4766
+	if (empty($string)) {
4767
+			return false;
4768
+	}
4513 4769
 
4514 4770
 	// Found a method.
4515 4771
 	if (strpos($string, '::') !== false)
@@ -4530,8 +4786,9 @@  discard block
 block discarded – undo
4530 4786
 				// Add another one to the list.
4531 4787
 				if ($db_show_debug === true)
4532 4788
 				{
4533
-					if (!isset($context['debug']['instances']))
4534
-						$context['debug']['instances'] = array();
4789
+					if (!isset($context['debug']['instances'])) {
4790
+											$context['debug']['instances'] = array();
4791
+					}
4535 4792
 
4536 4793
 					$context['debug']['instances'][$class] = $class;
4537 4794
 				}
@@ -4541,13 +4798,15 @@  discard block
 block discarded – undo
4541 4798
 		}
4542 4799
 
4543 4800
 		// Right then. This is a call to a static method.
4544
-		else
4545
-			$func = array($class, $method);
4801
+		else {
4802
+					$func = array($class, $method);
4803
+		}
4546 4804
 	}
4547 4805
 
4548 4806
 	// Nope! just a plain regular function.
4549
-	else
4550
-		$func = $string;
4807
+	else {
4808
+			$func = $string;
4809
+	}
4551 4810
 
4552 4811
 	// Right, we got what we need, time to do some checks.
4553 4812
 	if (!is_callable($func, false, $callable_name))
@@ -4563,17 +4822,18 @@  discard block
 block discarded – undo
4563 4822
 	else
4564 4823
 	{
4565 4824
 		// What are we gonna do about it?
4566
-		if ($return)
4567
-			return $func;
4825
+		if ($return) {
4826
+					return $func;
4827
+		}
4568 4828
 
4569 4829
 		// If this is a plain function, avoid the heat of calling call_user_func().
4570 4830
 		else
4571 4831
 		{
4572
-			if (is_array($func))
4573
-				call_user_func($func);
4574
-
4575
-			else
4576
-				$func();
4832
+			if (is_array($func)) {
4833
+							call_user_func($func);
4834
+			} else {
4835
+							$func();
4836
+			}
4577 4837
 		}
4578 4838
 	}
4579 4839
 }
@@ -4590,31 +4850,34 @@  discard block
 block discarded – undo
4590 4850
 {
4591 4851
 	global $sourcedir, $txt, $boarddir, $settings;
4592 4852
 
4593
-	if (empty($string))
4594
-		return false;
4853
+	if (empty($string)) {
4854
+			return false;
4855
+	}
4595 4856
 
4596 4857
 	if (strpos($string, '|') !== false)
4597 4858
 	{
4598 4859
 		list ($file, $string) = explode('|', $string);
4599 4860
 
4600 4861
 		// Match the wildcards to their regular vars.
4601
-		if (empty($settings['theme_dir']))
4602
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4603
-
4604
-		else
4605
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4862
+		if (empty($settings['theme_dir'])) {
4863
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4864
+		} else {
4865
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4866
+		}
4606 4867
 
4607 4868
 		// Load the file if it can be loaded.
4608
-		if (file_exists($absPath))
4609
-			require_once($absPath);
4869
+		if (file_exists($absPath)) {
4870
+					require_once($absPath);
4871
+		}
4610 4872
 
4611 4873
 		// No? try a fallback to $sourcedir
4612 4874
 		else
4613 4875
 		{
4614 4876
 			$absPath = $sourcedir .'/'. $file;
4615 4877
 
4616
-			if (file_exists($absPath))
4617
-				require_once($absPath);
4878
+			if (file_exists($absPath)) {
4879
+							require_once($absPath);
4880
+			}
4618 4881
 
4619 4882
 			// Sorry, can't do much for you at this point.
4620 4883
 			else
@@ -4641,8 +4904,9 @@  discard block
 block discarded – undo
4641 4904
 	global $user_info, $smcFunc;
4642 4905
 
4643 4906
 	// Make sure we have something to work with.
4644
-	if (empty($topic))
4645
-		return array();
4907
+	if (empty($topic)) {
4908
+			return array();
4909
+	}
4646 4910
 
4647 4911
 
4648 4912
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4665,8 +4929,9 @@  discard block
 block discarded – undo
4665 4929
 				'topic' => $topic,
4666 4930
 			)
4667 4931
 		);
4668
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4669
-			$temp[] = (int) $row['content_id'];
4932
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4933
+					$temp[] = (int) $row['content_id'];
4934
+		}
4670 4935
 
4671 4936
 		cache_put_data($cache_key, $temp, $ttl);
4672 4937
 	}
@@ -4687,8 +4952,9 @@  discard block
 block discarded – undo
4687 4952
 {
4688 4953
 	global $context;
4689 4954
 
4690
-	if (empty($string))
4691
-		return $string;
4955
+	if (empty($string)) {
4956
+			return $string;
4957
+	}
4692 4958
 
4693 4959
 	// UTF-8 occurences of MS special characters
4694 4960
 	$findchars_utf8 = array(
@@ -4729,10 +4995,11 @@  discard block
 block discarded – undo
4729 4995
 		'--',	// &mdash;
4730 4996
 	);
4731 4997
 
4732
-	if ($context['utf8'])
4733
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4734
-	else
4735
-		$string = str_replace($findchars_iso, $replacechars, $string);
4998
+	if ($context['utf8']) {
4999
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5000
+	} else {
5001
+			$string = str_replace($findchars_iso, $replacechars, $string);
5002
+	}
4736 5003
 
4737 5004
 	return $string;
4738 5005
 }
@@ -4751,49 +5018,59 @@  discard block
 block discarded – undo
4751 5018
 {
4752 5019
 	global $context;
4753 5020
 
4754
-	if (!isset($matches[2]))
4755
-		return '';
5021
+	if (!isset($matches[2])) {
5022
+			return '';
5023
+	}
4756 5024
 
4757 5025
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4758 5026
 
4759 5027
 	// remove left to right / right to left overrides
4760
-	if ($num === 0x202D || $num === 0x202E)
4761
-		return '';
5028
+	if ($num === 0x202D || $num === 0x202E) {
5029
+			return '';
5030
+	}
4762 5031
 
4763 5032
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4764
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4765
-		return '&#' . $num . ';';
5033
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5034
+			return '&#' . $num . ';';
5035
+	}
4766 5036
 
4767 5037
 	if (empty($context['utf8']))
4768 5038
 	{
4769 5039
 		// no control characters
4770
-		if ($num < 0x20)
4771
-			return '';
5040
+		if ($num < 0x20) {
5041
+					return '';
5042
+		}
4772 5043
 		// text is text
4773
-		elseif ($num < 0x80)
4774
-			return chr($num);
5044
+		elseif ($num < 0x80) {
5045
+					return chr($num);
5046
+		}
4775 5047
 		// all others get html-ised
4776
-		else
4777
-			return '&#' . $matches[2] . ';';
4778
-	}
4779
-	else
5048
+		else {
5049
+					return '&#' . $matches[2] . ';';
5050
+		}
5051
+	} else
4780 5052
 	{
4781 5053
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4782 5054
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4783
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4784
-			return '';
5055
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5056
+					return '';
5057
+		}
4785 5058
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4786
-		elseif ($num < 0x80)
4787
-			return chr($num);
5059
+		elseif ($num < 0x80) {
5060
+					return chr($num);
5061
+		}
4788 5062
 		// <0x800 (2048)
4789
-		elseif ($num < 0x800)
4790
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5063
+		elseif ($num < 0x800) {
5064
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5065
+		}
4791 5066
 		// < 0x10000 (65536)
4792
-		elseif ($num < 0x10000)
4793
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5067
+		elseif ($num < 0x10000) {
5068
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5069
+		}
4794 5070
 		// <= 0x10FFFF (1114111)
4795
-		else
4796
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5071
+		else {
5072
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5073
+		}
4797 5074
 	}
4798 5075
 }
4799 5076
 
@@ -4809,28 +5086,34 @@  discard block
 block discarded – undo
4809 5086
  */
4810 5087
 function fixchar__callback($matches)
4811 5088
 {
4812
-	if (!isset($matches[1]))
4813
-		return '';
5089
+	if (!isset($matches[1])) {
5090
+			return '';
5091
+	}
4814 5092
 
4815 5093
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4816 5094
 
4817 5095
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4818 5096
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4819
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4820
-		return '';
5097
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5098
+			return '';
5099
+	}
4821 5100
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4822
-	elseif ($num < 0x80)
4823
-		return chr($num);
5101
+	elseif ($num < 0x80) {
5102
+			return chr($num);
5103
+	}
4824 5104
 	// <0x800 (2048)
4825
-	elseif ($num < 0x800)
4826
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5105
+	elseif ($num < 0x800) {
5106
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5107
+	}
4827 5108
 	// < 0x10000 (65536)
4828
-	elseif ($num < 0x10000)
4829
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5109
+	elseif ($num < 0x10000) {
5110
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5111
+	}
4830 5112
 	// <= 0x10FFFF (1114111)
4831
-	else
4832
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4833
-}
5113
+	else {
5114
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5115
+	}
5116
+	}
4834 5117
 
4835 5118
 /**
4836 5119
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4843,17 +5126,19 @@  discard block
 block discarded – undo
4843 5126
  */
4844 5127
 function entity_fix__callback($matches)
4845 5128
 {
4846
-	if (!isset($matches[2]))
4847
-		return '';
5129
+	if (!isset($matches[2])) {
5130
+			return '';
5131
+	}
4848 5132
 
4849 5133
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4850 5134
 
4851 5135
 	// we don't allow control characters, characters out of range, byte markers, etc
4852
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4853
-		return '';
4854
-	else
4855
-		return '&#' . $num . ';';
4856
-}
5136
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5137
+			return '';
5138
+	} else {
5139
+			return '&#' . $num . ';';
5140
+	}
5141
+	}
4857 5142
 
4858 5143
 /**
4859 5144
  * Return a Gravatar URL based on
@@ -4877,18 +5162,23 @@  discard block
 block discarded – undo
4877 5162
 		$ratings = array('G', 'PG', 'R', 'X');
4878 5163
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4879 5164
 		$url_params = array();
4880
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4881
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4882
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4883
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4884
-		if (!empty($modSettings['avatar_max_width_external']))
4885
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4886
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4887
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5165
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5166
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5167
+		}
5168
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5169
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5170
+		}
5171
+		if (!empty($modSettings['avatar_max_width_external'])) {
5172
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5173
+		}
5174
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5175
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4888 5176
 				$size_string = $modSettings['avatar_max_height_external'];
5177
+		}
4889 5178
 
4890
-		if (!empty($size_string))
4891
-			$url_params[] = 's=' . $size_string;
5179
+		if (!empty($size_string)) {
5180
+					$url_params[] = 's=' . $size_string;
5181
+		}
4892 5182
 	}
4893 5183
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4894 5184
 
@@ -4907,22 +5197,26 @@  discard block
 block discarded – undo
4907 5197
 	static $timezones = null, $lastwhen = null;
4908 5198
 
4909 5199
 	// No point doing this over if we already did it once
4910
-	if (!empty($timezones) && $when == $lastwhen)
4911
-		return $timezones;
4912
-	else
4913
-		$lastwhen = $when;
5200
+	if (!empty($timezones) && $when == $lastwhen) {
5201
+			return $timezones;
5202
+	} else {
5203
+			$lastwhen = $when;
5204
+	}
4914 5205
 
4915 5206
 	// Parseable datetime string?
4916
-	if (is_int($timestamp = strtotime($when)))
4917
-		$when = $timestamp;
5207
+	if (is_int($timestamp = strtotime($when))) {
5208
+			$when = $timestamp;
5209
+	}
4918 5210
 
4919 5211
 	// A Unix timestamp?
4920
-	elseif (is_numeric($when))
4921
-		$when = intval($when);
5212
+	elseif (is_numeric($when)) {
5213
+			$when = intval($when);
5214
+	}
4922 5215
 
4923 5216
 	// Invalid value? Just get current Unix timestamp.
4924
-	else
4925
-		$when = time();
5217
+	else {
5218
+			$when = time();
5219
+	}
4926 5220
 
4927 5221
 	// We'll need this too
4928 5222
 	$later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U');
@@ -4985,8 +5279,9 @@  discard block
 block discarded – undo
4985 5279
 	foreach ($priority_countries as $country)
4986 5280
 	{
4987 5281
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4988
-		if (!empty($country_tzids))
4989
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5282
+		if (!empty($country_tzids)) {
5283
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5284
+		}
4990 5285
 	}
4991 5286
 
4992 5287
 	// Process the preferred timezones first, then the rest.
@@ -4996,8 +5291,9 @@  discard block
 block discarded – undo
4996 5291
 	foreach ($tzids as $tzid)
4997 5292
 	{
4998 5293
 		// We don't want UTC right now
4999
-		if ($tzid == 'UTC')
5000
-			continue;
5294
+		if ($tzid == 'UTC') {
5295
+					continue;
5296
+		}
5001 5297
 
5002 5298
 		// First, get the set of transition rules for this tzid
5003 5299
 		$tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later);
@@ -5008,8 +5304,9 @@  discard block
 block discarded – undo
5008 5304
 			$tz_location = timezone_location_get(timezone_open($tzid));
5009 5305
 
5010 5306
 			// Kazakstan
5011
-			if ($tz_location['country_code'] == 'KZ')
5012
-				$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5307
+			if ($tz_location['country_code'] == 'KZ') {
5308
+							$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5309
+			}
5013 5310
 
5014 5311
 			// Russia likes to experiment with time zones
5015 5312
 			if ($tz_location['country_code'] == 'RU')
@@ -5020,19 +5317,22 @@  discard block
 block discarded – undo
5020 5317
 			}
5021 5318
 
5022 5319
 			// Still no good? We'll just mark it as a UTC offset
5023
-			if (strspn($tzinfo[0]['abbr'], '+-') > 0)
5024
-				$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5320
+			if (strspn($tzinfo[0]['abbr'], '+-') > 0) {
5321
+							$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5322
+			}
5025 5323
 		}
5026 5324
 
5027 5325
 		$tzkey = serialize($tzinfo);
5028 5326
 
5029 5327
 		// Don't overwrite our preferred tzids
5030
-		if (empty($zones[$tzkey]['tzid']))
5031
-			$zones[$tzkey]['tzid'] = $tzid;
5328
+		if (empty($zones[$tzkey]['tzid'])) {
5329
+					$zones[$tzkey]['tzid'] = $tzid;
5330
+		}
5032 5331
 
5033 5332
 		// A time zone from a prioritized country?
5034
-		if (in_array($tzid, $priority_tzids))
5035
-			$priority_zones[$tzkey] = true;
5333
+		if (in_array($tzid, $priority_tzids)) {
5334
+					$priority_zones[$tzkey] = true;
5335
+		}
5036 5336
 
5037 5337
 		// Keep track of the location and offset for this tzid
5038 5338
 		$tzid_parts = explode('/', $tzid);
@@ -5050,15 +5350,17 @@  discard block
 block discarded – undo
5050 5350
 	{
5051 5351
 		$tzinfo = unserialize($tzkey);
5052 5352
 
5053
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5054
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5055
-		else
5056
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5353
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5354
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5355
+		} else {
5356
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5357
+		}
5057 5358
 
5058
-		if (isset($priority_zones[$tzkey]))
5059
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5060
-		else
5061
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5359
+		if (isset($priority_zones[$tzkey])) {
5360
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5361
+		} else {
5362
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5363
+		}
5062 5364
 	}
5063 5365
 
5064 5366
 	$timezones = array_merge(
@@ -5076,8 +5378,9 @@  discard block
 block discarded – undo
5076 5378
  */
5077 5379
 function inet_ptod($ip_address)
5078 5380
 {
5079
-	if (!isValidIP($ip_address))
5080
-		return $ip_address;
5381
+	if (!isValidIP($ip_address)) {
5382
+			return $ip_address;
5383
+	}
5081 5384
 
5082 5385
 	$bin = inet_pton($ip_address);
5083 5386
 	return $bin;
@@ -5089,13 +5392,15 @@  discard block
 block discarded – undo
5089 5392
  */
5090 5393
 function inet_dtop($bin)
5091 5394
 {
5092
-	if(empty($bin))
5093
-		return '';
5395
+	if(empty($bin)) {
5396
+			return '';
5397
+	}
5094 5398
 
5095 5399
 	global $db_type;
5096 5400
 
5097
-	if ($db_type == 'postgresql')
5098
-		return $bin;
5401
+	if ($db_type == 'postgresql') {
5402
+			return $bin;
5403
+	}
5099 5404
 
5100 5405
 	$ip_address = inet_ntop($bin);
5101 5406
 
@@ -5120,26 +5425,32 @@  discard block
 block discarded – undo
5120 5425
  */
5121 5426
 function _safe_serialize($value)
5122 5427
 {
5123
-	if(is_null($value))
5124
-		return 'N;';
5428
+	if(is_null($value)) {
5429
+			return 'N;';
5430
+	}
5125 5431
 
5126
-	if(is_bool($value))
5127
-		return 'b:'. (int) $value .';';
5432
+	if(is_bool($value)) {
5433
+			return 'b:'. (int) $value .';';
5434
+	}
5128 5435
 
5129
-	if(is_int($value))
5130
-		return 'i:'. $value .';';
5436
+	if(is_int($value)) {
5437
+			return 'i:'. $value .';';
5438
+	}
5131 5439
 
5132
-	if(is_float($value))
5133
-		return 'd:'. str_replace(',', '.', $value) .';';
5440
+	if(is_float($value)) {
5441
+			return 'd:'. str_replace(',', '.', $value) .';';
5442
+	}
5134 5443
 
5135
-	if(is_string($value))
5136
-		return 's:'. strlen($value) .':"'. $value .'";';
5444
+	if(is_string($value)) {
5445
+			return 's:'. strlen($value) .':"'. $value .'";';
5446
+	}
5137 5447
 
5138 5448
 	if(is_array($value))
5139 5449
 	{
5140 5450
 		$out = '';
5141
-		foreach($value as $k => $v)
5142
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5451
+		foreach($value as $k => $v) {
5452
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5453
+		}
5143 5454
 
5144 5455
 		return 'a:'. count($value) .':{'. $out .'}';
5145 5456
 	}
@@ -5165,8 +5476,9 @@  discard block
 block discarded – undo
5165 5476
 
5166 5477
 	$out = _safe_serialize($value);
5167 5478
 
5168
-	if (isset($mbIntEnc))
5169
-		mb_internal_encoding($mbIntEnc);
5479
+	if (isset($mbIntEnc)) {
5480
+			mb_internal_encoding($mbIntEnc);
5481
+	}
5170 5482
 
5171 5483
 	return $out;
5172 5484
 }
@@ -5183,8 +5495,9 @@  discard block
 block discarded – undo
5183 5495
 function _safe_unserialize($str)
5184 5496
 {
5185 5497
 	// Input  is not a string.
5186
-	if(empty($str) || !is_string($str))
5187
-		return false;
5498
+	if(empty($str) || !is_string($str)) {
5499
+			return false;
5500
+	}
5188 5501
 
5189 5502
 	$stack = array();
5190 5503
 	$expected = array();
@@ -5200,43 +5513,38 @@  discard block
 block discarded – undo
5200 5513
 	while($state != 1)
5201 5514
 	{
5202 5515
 		$type = isset($str[0]) ? $str[0] : '';
5203
-		if($type == '}')
5204
-			$str = substr($str, 1);
5205
-
5206
-		else if($type == 'N' && $str[1] == ';')
5516
+		if($type == '}') {
5517
+					$str = substr($str, 1);
5518
+		} else if($type == 'N' && $str[1] == ';')
5207 5519
 		{
5208 5520
 			$value = null;
5209 5521
 			$str = substr($str, 2);
5210
-		}
5211
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5522
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5212 5523
 		{
5213 5524
 			$value = $matches[1] == '1' ? true : false;
5214 5525
 			$str = substr($str, 4);
5215
-		}
5216
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5526
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5217 5527
 		{
5218 5528
 			$value = (int)$matches[1];
5219 5529
 			$str = $matches[2];
5220
-		}
5221
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5530
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5222 5531
 		{
5223 5532
 			$value = (float)$matches[1];
5224 5533
 			$str = $matches[3];
5225
-		}
5226
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5534
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5227 5535
 		{
5228 5536
 			$value = substr($matches[2], 0, (int)$matches[1]);
5229 5537
 			$str = substr($matches[2], (int)$matches[1] + 2);
5230
-		}
5231
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5538
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5232 5539
 		{
5233 5540
 			$expectedLength = (int)$matches[1];
5234 5541
 			$str = $matches[2];
5235 5542
 		}
5236 5543
 
5237 5544
 		// Object or unknown/malformed type.
5238
-		else
5239
-			return false;
5545
+		else {
5546
+					return false;
5547
+		}
5240 5548
 
5241 5549
 		switch($state)
5242 5550
 		{
@@ -5264,8 +5572,9 @@  discard block
 block discarded – undo
5264 5572
 				if($type == '}')
5265 5573
 				{
5266 5574
 					// Array size is less than expected.
5267
-					if(count($list) < end($expected))
5268
-						return false;
5575
+					if(count($list) < end($expected)) {
5576
+											return false;
5577
+					}
5269 5578
 
5270 5579
 					unset($list);
5271 5580
 					$list = &$stack[count($stack)-1];
@@ -5274,8 +5583,9 @@  discard block
 block discarded – undo
5274 5583
 					// Go to terminal state if we're at the end of the root array.
5275 5584
 					array_pop($expected);
5276 5585
 
5277
-					if(count($expected) == 0)
5278
-						$state = 1;
5586
+					if(count($expected) == 0) {
5587
+											$state = 1;
5588
+					}
5279 5589
 
5280 5590
 					break;
5281 5591
 				}
@@ -5283,8 +5593,9 @@  discard block
 block discarded – undo
5283 5593
 				if($type == 'i' || $type == 's')
5284 5594
 				{
5285 5595
 					// Array size exceeds expected length.
5286
-					if(count($list) >= end($expected))
5287
-						return false;
5596
+					if(count($list) >= end($expected)) {
5597
+											return false;
5598
+					}
5288 5599
 
5289 5600
 					$key = $value;
5290 5601
 					$state = 3;
@@ -5318,8 +5629,9 @@  discard block
 block discarded – undo
5318 5629
 	}
5319 5630
 
5320 5631
 	// Trailing data in input.
5321
-	if(!empty($str))
5322
-		return false;
5632
+	if(!empty($str)) {
5633
+			return false;
5634
+	}
5323 5635
 
5324 5636
 	return $data;
5325 5637
 }
@@ -5342,8 +5654,9 @@  discard block
 block discarded – undo
5342 5654
 
5343 5655
 	$out = _safe_unserialize($str);
5344 5656
 
5345
-	if (isset($mbIntEnc))
5346
-		mb_internal_encoding($mbIntEnc);
5657
+	if (isset($mbIntEnc)) {
5658
+			mb_internal_encoding($mbIntEnc);
5659
+	}
5347 5660
 
5348 5661
 	return $out;
5349 5662
 }
@@ -5358,12 +5671,14 @@  discard block
 block discarded – undo
5358 5671
 function smf_chmod($file, $value = 0)
5359 5672
 {
5360 5673
 	// No file? no checks!
5361
-	if (empty($file))
5362
-		return false;
5674
+	if (empty($file)) {
5675
+			return false;
5676
+	}
5363 5677
 
5364 5678
 	// Already writable?
5365
-	if (is_writable($file))
5366
-		return true;
5679
+	if (is_writable($file)) {
5680
+			return true;
5681
+	}
5367 5682
 
5368 5683
 	// Do we have a file or a dir?
5369 5684
 	$isDir = is_dir($file);
@@ -5379,10 +5694,9 @@  discard block
 block discarded – undo
5379 5694
 		{
5380 5695
 			$isWritable = true;
5381 5696
 			break;
5697
+		} else {
5698
+					@chmod($file, $val);
5382 5699
 		}
5383
-
5384
-		else
5385
-			@chmod($file, $val);
5386 5700
 	}
5387 5701
 
5388 5702
 	return $isWritable;
@@ -5401,8 +5715,9 @@  discard block
 block discarded – undo
5401 5715
 	global $txt;
5402 5716
 
5403 5717
 	// Come on...
5404
-	if (empty($json) || !is_string($json))
5405
-		return array();
5718
+	if (empty($json) || !is_string($json)) {
5719
+			return array();
5720
+	}
5406 5721
 
5407 5722
 	$returnArray = @json_decode($json, $returnAsArray);
5408 5723
 
@@ -5440,11 +5755,11 @@  discard block
 block discarded – undo
5440 5755
 		$jsonDebug = $jsonDebug[0];
5441 5756
 		loadLanguage('Errors');
5442 5757
 
5443
-		if (!empty($jsonDebug))
5444
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5445
-
5446
-		else
5447
-			log_error($txt['json_'. $jsonError], 'critical');
5758
+		if (!empty($jsonDebug)) {
5759
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5760
+		} else {
5761
+					log_error($txt['json_'. $jsonError], 'critical');
5762
+		}
5448 5763
 
5449 5764
 		// Everyone expects an array.
5450 5765
 		return array();
@@ -5474,8 +5789,9 @@  discard block
 block discarded – undo
5474 5789
 	global $db_show_debug, $modSettings;
5475 5790
 
5476 5791
 	// Defensive programming anyone?
5477
-	if (empty($data))
5478
-		return false;
5792
+	if (empty($data)) {
5793
+			return false;
5794
+	}
5479 5795
 
5480 5796
 	// Don't need extra stuff...
5481 5797
 	$db_show_debug = false;
@@ -5483,11 +5799,11 @@  discard block
 block discarded – undo
5483 5799
 	// Kill anything else.
5484 5800
 	ob_end_clean();
5485 5801
 
5486
-	if (!empty($modSettings['CompressedOutput']))
5487
-		@ob_start('ob_gzhandler');
5488
-
5489
-	else
5490
-		ob_start();
5802
+	if (!empty($modSettings['CompressedOutput'])) {
5803
+			@ob_start('ob_gzhandler');
5804
+	} else {
5805
+			ob_start();
5806
+	}
5491 5807
 
5492 5808
 	// Set the header.
5493 5809
 	header($type);
@@ -5519,8 +5835,9 @@  discard block
 block discarded – undo
5519 5835
 	static $done = false;
5520 5836
 
5521 5837
 	// If we don't need to do anything, don't
5522
-	if (!$update && $done)
5523
-		return;
5838
+	if (!$update && $done) {
5839
+			return;
5840
+	}
5524 5841
 
5525 5842
 	// Should we get a new copy of the official list of TLDs?
5526 5843
 	if ($update)
@@ -5541,10 +5858,11 @@  discard block
 block discarded – undo
5541 5858
 		// Clean $tlds and convert it to an array
5542 5859
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5543 5860
 			$line = trim($line);
5544
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5545
-				return false;
5546
-			else
5547
-				return true;
5861
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5862
+							return false;
5863
+			} else {
5864
+							return true;
5865
+			}
5548 5866
 		});
5549 5867
 
5550 5868
 		// Convert Punycode to Unicode
@@ -5598,8 +5916,9 @@  discard block
 block discarded – undo
5598 5916
 						$idx += $digit * $w;
5599 5917
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5600 5918
 
5601
-						if ($digit < $t)
5602
-							break;
5919
+						if ($digit < $t) {
5920
+													break;
5921
+						}
5603 5922
 
5604 5923
 						$w = (int) ($w * ($base - $t));
5605 5924
 					}
@@ -5608,8 +5927,9 @@  discard block
 block discarded – undo
5608 5927
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5609 5928
 					$delta += intval($delta / ($deco_len + 1));
5610 5929
 
5611
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5612
-						$delta = intval($delta / ($base - $tmin));
5930
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5931
+											$delta = intval($delta / ($base - $tmin));
5932
+					}
5613 5933
 
5614 5934
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5615 5935
 					$is_first = false;
@@ -5618,8 +5938,9 @@  discard block
 block discarded – undo
5618 5938
 
5619 5939
 					if ($deco_len > 0)
5620 5940
 					{
5621
-						for ($i = $deco_len; $i > $idx; $i--)
5622
-							$decoded[$i] = $decoded[($i - 1)];
5941
+						for ($i = $deco_len; $i > $idx; $i--) {
5942
+													$decoded[$i] = $decoded[($i - 1)];
5943
+						}
5623 5944
 					}
5624 5945
 					$decoded[$idx++] = $char;
5625 5946
 				}
@@ -5627,24 +5948,29 @@  discard block
 block discarded – undo
5627 5948
 				foreach ($decoded as $k => $v)
5628 5949
 				{
5629 5950
 					// 7bit are transferred literally
5630
-					if ($v < 128)
5631
-						$output .= chr($v);
5951
+					if ($v < 128) {
5952
+											$output .= chr($v);
5953
+					}
5632 5954
 
5633 5955
 					// 2 bytes
5634
-					elseif ($v < (1 << 11))
5635
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5956
+					elseif ($v < (1 << 11)) {
5957
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5958
+					}
5636 5959
 
5637 5960
 					// 3 bytes
5638
-					elseif ($v < (1 << 16))
5639
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5961
+					elseif ($v < (1 << 16)) {
5962
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5963
+					}
5640 5964
 
5641 5965
 					// 4 bytes
5642
-					elseif ($v < (1 << 21))
5643
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5966
+					elseif ($v < (1 << 21)) {
5967
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5968
+					}
5644 5969
 
5645 5970
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5646
-					else
5647
-						$output .= $safe_char;
5971
+					else {
5972
+											$output .= $safe_char;
5973
+					}
5648 5974
 				}
5649 5975
 
5650 5976
 				$output_parts[] = $output;
@@ -5739,8 +6065,7 @@  discard block
 block discarded – undo
5739 6065
 
5740 6066
 		$strlen = 'mb_strlen';
5741 6067
 		$substr = 'mb_substr';
5742
-	}
5743
-	else
6068
+	} else
5744 6069
 	{
5745 6070
 		$strlen = $smcFunc['strlen'];
5746 6071
 		$substr = $smcFunc['substr'];
@@ -5754,20 +6079,21 @@  discard block
 block discarded – undo
5754 6079
 
5755 6080
 		$first = $substr($string, 0, 1);
5756 6081
 
5757
-		if (empty($index[$first]))
5758
-			$index[$first] = array();
6082
+		if (empty($index[$first])) {
6083
+					$index[$first] = array();
6084
+		}
5759 6085
 
5760 6086
 		if ($strlen($string) > 1)
5761 6087
 		{
5762 6088
 			// Sanity check on recursion
5763
-			if ($depth > 99)
5764
-				$index[$first][$substr($string, 1)] = '';
5765
-
5766
-			else
5767
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6089
+			if ($depth > 99) {
6090
+							$index[$first][$substr($string, 1)] = '';
6091
+			} else {
6092
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6093
+			}
6094
+		} else {
6095
+					$index[$first][''] = '';
5768 6096
 		}
5769
-		else
5770
-			$index[$first][''] = '';
5771 6097
 
5772 6098
 		$depth--;
5773 6099
 		return $index;
@@ -5790,9 +6116,9 @@  discard block
 block discarded – undo
5790 6116
 			$key_regex = preg_quote($key, $delim);
5791 6117
 			$new_key = $key;
5792 6118
 
5793
-			if (empty($value))
5794
-				$sub_regex = '';
5795
-			else
6119
+			if (empty($value)) {
6120
+							$sub_regex = '';
6121
+			} else
5796 6122
 			{
5797 6123
 				$sub_regex = $index_to_regex($value, $delim);
5798 6124
 
@@ -5800,22 +6126,22 @@  discard block
 block discarded – undo
5800 6126
 				{
5801 6127
 					$new_key_array = explode('(?'.'>', $sub_regex);
5802 6128
 					$new_key .= $new_key_array[0];
6129
+				} else {
6130
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5803 6131
 				}
5804
-				else
5805
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5806 6132
 			}
5807 6133
 
5808
-			if ($depth > 1)
5809
-				$regex[$new_key] = $key_regex . $sub_regex;
5810
-			else
6134
+			if ($depth > 1) {
6135
+							$regex[$new_key] = $key_regex . $sub_regex;
6136
+			} else
5811 6137
 			{
5812 6138
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5813 6139
 				{
5814 6140
 					$regex[$new_key] = $key_regex . $sub_regex;
5815 6141
 					unset($index[$key]);
6142
+				} else {
6143
+									break;
5816 6144
 				}
5817
-				else
5818
-					break;
5819 6145
 			}
5820 6146
 		}
5821 6147
 
@@ -5824,10 +6150,11 @@  discard block
 block discarded – undo
5824 6150
 			$l1 = $strlen($k1);
5825 6151
 			$l2 = $strlen($k2);
5826 6152
 
5827
-			if ($l1 == $l2)
5828
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5829
-			else
5830
-				return $l1 > $l2 ? -1 : 1;
6153
+			if ($l1 == $l2) {
6154
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6155
+			} else {
6156
+							return $l1 > $l2 ? -1 : 1;
6157
+			}
5831 6158
 		});
5832 6159
 
5833 6160
 		$depth--;
@@ -5838,15 +6165,18 @@  discard block
 block discarded – undo
5838 6165
 	$index = array();
5839 6166
 	$regexes = array();
5840 6167
 
5841
-	foreach ($strings as $string)
5842
-		$index = $add_string_to_index($string, $index);
6168
+	foreach ($strings as $string) {
6169
+			$index = $add_string_to_index($string, $index);
6170
+	}
5843 6171
 
5844
-	while (!empty($index))
5845
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6172
+	while (!empty($index)) {
6173
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6174
+	}
5846 6175
 
5847 6176
 	// Restore PHP's internal character encoding to whatever it was originally
5848
-	if (!empty($current_encoding))
5849
-		mb_internal_encoding($current_encoding);
6177
+	if (!empty($current_encoding)) {
6178
+			mb_internal_encoding($current_encoding);
6179
+	}
5850 6180
 
5851 6181
 	return $regexes;
5852 6182
 }
Please login to merge, or discard this patch.