Completed
Push — release-2.1 ( 64d581...84b0cc )
by Rick
06:44 queued 10s
created
Sources/PersonalMessage.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
620 620
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
621 621
 					WHERE pmr.id_member = {int:current_member}
622
-						AND pmr.deleted = {int:not_deleted}' . $labelQuery .  $labelQuery2 . '
622
+						AND pmr.deleted = {int:not_deleted}' . $labelQuery . $labelQuery2 . '
623 623
 						AND pmr.id_pm ' . ($descending ? '>' : '<') . ' {int:id_pm}',
624 624
 					array(
625 625
 						'current_member' => $user_info['id'],
@@ -682,12 +682,12 @@  discard block
 block discarded – undo
682 682
 				INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
683 683
 					AND pmr.id_member = {int:current_member}
684 684
 					AND pmr.deleted = {int:deleted_by}
685
-					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ( '
685
+					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ('
686 686
 				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:pm_member})') : '') . '
687 687
 				WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {int:current_member}
688 688
 					AND pm.deleted_by_sender = {int:deleted_by}' : '1=1') . (empty($pmsg) ? '' : '
689 689
 					AND pm.id_pm = {int:pmsg}') . $labelQuery2 . '
690
-				GROUP BY pm.id_pm_head'.($_GET['sort'] != 'pm.id_pm' ? ','.$_GET['sort'] : '').'
690
+				GROUP BY pm.id_pm_head'.($_GET['sort'] != 'pm.id_pm' ? ',' . $_GET['sort'] : '') . '
691 691
 				ORDER BY ' . ($_GET['sort'] == 'pm.id_pm' && $context['folder'] != 'sent' ? 'id_pm' : '{raw:sort}') . ($descending ? ' DESC' : ' ASC') . (empty($_GET['pmsg']) ? '
692 692
 				LIMIT ' . $_GET['start'] . ', ' . $maxPerPage : ''),
693 693
 				array(
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 				INNER JOIN {db_prefix}pm_recipients AS pmr ON (pmr.id_pm = pm.id_pm
712 712
 					AND pmr.id_member = {int:current_member}
713 713
 					AND pmr.deleted = {int:is_deleted}
714
-					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ( '
714
+					' . $labelQuery . ')') . $labelJoin . ($context['sort_by'] == 'name' ? ('
715 715
 				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = {raw:pm_member})') : '') . '
716 716
 			WHERE ' . ($context['folder'] == 'sent' ? 'pm.id_member_from = {raw:current_member}
717 717
 				AND pm.deleted_by_sender = {int:is_deleted}' : '1=1') . (empty($pmsg) ? '' : '
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 					)
849 849
 				);
850 850
 
851
-				while($row2 = $smcFunc['db_fetch_assoc']($request2))
851
+				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
852 852
 				{
853 853
 					$l_id = $row2['id_label'];
854 854
 					if (isset($context['labels'][$l_id]))
@@ -1626,7 +1626,7 @@  discard block
 block discarded – undo
1626 1626
 					)
1627 1627
 				);
1628 1628
 
1629
-				while($row2 = $smcFunc['db_fetch_assoc']($request2))
1629
+				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1630 1630
 				{
1631 1631
 					$l_id = $row2['id_label'];
1632 1632
 					if (isset($context['labels'][$l_id]))
@@ -3723,7 +3723,7 @@  discard block
 block discarded – undo
3723 3723
 	// Editing a specific one?
3724 3724
 	if (isset($_GET['add']))
3725 3725
 	{
3726
-		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']])? (int) $_GET['rid'] : 0;
3726
+		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0;
3727 3727
 		$context['sub_template'] = 'add_rule';
3728 3728
 
3729 3729
 		// Current rule information...
@@ -3764,7 +3764,7 @@  discard block
 block discarded – undo
3764 3764
 	elseif (isset($_GET['save']))
3765 3765
 	{
3766 3766
 		checkSession();
3767
-		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']])? (int) $_GET['rid'] : 0;
3767
+		$context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0;
3768 3768
 
3769 3769
 		// Name is easy!
3770 3770
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
Please login to merge, or discard this patch.
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="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>';
1135
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '" alt="' . $currentAttachment['name'] . '" id="thumb_' . $currentAttachment['id'] . '"></a>';
1136 1136
 						else
1137 1137
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>';
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';
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1307 1307
 				),
1308 1308
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1309
-				'validate' => function (&$tag, &$data, $disabled)
1309
+				'validate' => function(&$tag, &$data, $disabled)
1310 1310
 				{
1311 1311
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1312 1312
 
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
 				'tag' => 'img',
1330 1330
 				'type' => 'unparsed_content',
1331 1331
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1332
-				'validate' => function (&$tag, &$data, $disabled)
1332
+				'validate' => function(&$tag, &$data, $disabled)
1333 1333
 				{
1334 1334
 					global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1335 1335
 
@@ -1352,7 +1352,7 @@  discard block
 block discarded – undo
1352 1352
 				'tag' => 'iurl',
1353 1353
 				'type' => 'unparsed_content',
1354 1354
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1355
-				'validate' => function (&$tag, &$data, $disabled)
1355
+				'validate' => function(&$tag, &$data, $disabled)
1356 1356
 				{
1357 1357
 					$data = strtr($data, array('<br>' => ''));
1358 1358
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
 				'quoted' => 'optional',
1367 1367
 				'before' => '<a href="$1" class="bbc_link">',
1368 1368
 				'after' => '</a>',
1369
-				'validate' => function (&$tag, &$data, $disabled)
1369
+				'validate' => function(&$tag, &$data, $disabled)
1370 1370
 				{
1371 1371
 					if (substr($data, 0, 1) == '#')
1372 1372
 						$data = '#post_' . substr($data, 1);
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
 				'tag' => 'php',
1447 1447
 				'type' => 'unparsed_content',
1448 1448
 				'content' => '<span class="phpcode">$1</span>',
1449
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1449
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1450 1450
 				{
1451 1451
 					if (!isset($disabled['php']))
1452 1452
 					{
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
 				'test' => '[1-7]\]',
1545 1545
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1546 1546
 				'after' => '</span>',
1547
-				'validate' => function (&$tag, &$data, $disabled)
1547
+				'validate' => function(&$tag, &$data, $disabled)
1548 1548
 				{
1549 1549
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1550 1550
 					$data = $sizes[$data] . 'em';
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
 				'tag' => 'time',
1583 1583
 				'type' => 'unparsed_content',
1584 1584
 				'content' => '$1',
1585
-				'validate' => function (&$tag, &$data, $disabled)
1585
+				'validate' => function(&$tag, &$data, $disabled)
1586 1586
 				{
1587 1587
 					if (is_numeric($data))
1588 1588
 						$data = timeformat($data);
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
 				'tag' => 'url',
1611 1611
 				'type' => 'unparsed_content',
1612 1612
 				'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
1613
-				'validate' => function (&$tag, &$data, $disabled)
1613
+				'validate' => function(&$tag, &$data, $disabled)
1614 1614
 				{
1615 1615
 					$data = strtr($data, array('<br>' => ''));
1616 1616
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 				'quoted' => 'optional',
1625 1625
 				'before' => '<a href="$1" class="bbc_link" target="_blank">',
1626 1626
 				'after' => '</a>',
1627
-				'validate' => function (&$tag, &$data, $disabled)
1627
+				'validate' => function(&$tag, &$data, $disabled)
1628 1628
 				{
1629 1629
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1630 1630
 					if (empty($scheme))
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
 		{
1651 1651
 			if (isset($temp_bbc))
1652 1652
 				$bbc_codes = $temp_bbc;
1653
-			usort($codes, function ($a, $b) {
1653
+			usort($codes, function($a, $b) {
1654 1654
 				return strcmp($a['tag'], $b['tag']);
1655 1655
 			});
1656 1656
 			return $codes;
@@ -1890,7 +1890,7 @@  discard block
 block discarded – undo
1890 1890
 										# a run of Unicode domain name characters and a dot
1891 1891
 										[\p{L}\p{M}\p{N}\-.:@]+\.
1892 1892
 										# and then a TLD valid in the DNS or the reserved "local" TLD
1893
-										(?:'. $modSettings['tld_regex'] .'|local)
1893
+										(?:'. $modSettings['tld_regex'] . '|local)
1894 1894
 									)
1895 1895
 									# followed by a non-domain character or end of line
1896 1896
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -1958,7 +1958,7 @@  discard block
 block discarded – undo
1958 1958
 						)?
1959 1959
 						';
1960 1960
 
1961
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
1961
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
1962 1962
 							$url = array_shift($matches);
1963 1963
 
1964 1964
 							$scheme = parse_url($url, PHP_URL_SCHEME);
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2688 2688
 		{
2689 2689
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2690
-			$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">';
2690
+			$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">';
2691 2691
 
2692 2692
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2693 2693
 
@@ -2704,7 +2704,7 @@  discard block
 block discarded – undo
2704 2704
 
2705 2705
 	// Replace away!
2706 2706
 	$message = preg_replace_callback($smileyPregSearch,
2707
-		function ($matches) use ($smileyPregReplacements)
2707
+		function($matches) use ($smileyPregReplacements)
2708 2708
 		{
2709 2709
 			return $smileyPregReplacements[$matches[1]];
2710 2710
 		}, $message);
@@ -2770,13 +2770,13 @@  discard block
 block discarded – undo
2770 2770
 	{
2771 2771
 		if (defined('SID') && SID != '')
2772 2772
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2773
-				function ($m) use ($scripturl)
2773
+				function($m) use ($scripturl)
2774 2774
 				{
2775
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2775
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2776 2776
 				}, $setLocation);
2777 2777
 		else
2778 2778
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2779
-				function ($m) use ($scripturl)
2779
+				function($m) use ($scripturl)
2780 2780
 				{
2781 2781
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2782 2782
 				}, $setLocation);
@@ -3099,7 +3099,7 @@  discard block
 block discarded – undo
3099 3099
 
3100 3100
 	// Add a generic "Are you sure?" confirmation message.
3101 3101
 	addInlineJavaScript('
3102
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3102
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3103 3103
 
3104 3104
 	// Now add the capping code for avatars.
3105 3105
 	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')
@@ -3463,7 +3463,7 @@  discard block
 block discarded – undo
3463 3463
 
3464 3464
 		else
3465 3465
 			echo '
3466
-	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3466
+	<script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>';
3467 3467
 	}
3468 3468
 
3469 3469
 	// Inline JavaScript - Actually useful some times!
@@ -3541,14 +3541,14 @@  discard block
 block discarded – undo
3541 3541
 
3542 3542
 		else
3543 3543
 			echo '
3544
-	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3544
+	<link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">';
3545 3545
 	}
3546 3546
 
3547 3547
 	// Print the rest after the minified files.
3548 3548
 	if (!empty($normal))
3549 3549
 		foreach ($normal as $nf)
3550 3550
 			echo '
3551
-	<link rel="stylesheet" href="', $nf ,'">';
3551
+	<link rel="stylesheet" href="', $nf, '">';
3552 3552
 
3553 3553
 	if ($db_show_debug === true)
3554 3554
 	{
@@ -3564,7 +3564,7 @@  discard block
 block discarded – undo
3564 3564
 	<style>';
3565 3565
 
3566 3566
 		foreach ($context['css_header'] as $css)
3567
-			echo $css .'
3567
+			echo $css . '
3568 3568
 	';
3569 3569
 
3570 3570
 		echo'
@@ -3594,7 +3594,7 @@  discard block
 block discarded – undo
3594 3594
 		return false;
3595 3595
 
3596 3596
 	// Did we already did this?
3597
-	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3597
+	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400);
3598 3598
 
3599 3599
 	// Already done?
3600 3600
 	if (!empty($toCache))
@@ -3602,25 +3602,25 @@  discard block
 block discarded – undo
3602 3602
 
3603 3603
 	// Yep, need a bunch of files.
3604 3604
 	require_once($sourcedir . '/minify/src/Minify.php');
3605
-	require_once($sourcedir . '/minify/src/'. strtoupper($type) .'.php');
3605
+	require_once($sourcedir . '/minify/src/' . strtoupper($type) . '.php');
3606 3606
 	require_once($sourcedir . '/minify/src/Exception.php');
3607 3607
 	require_once($sourcedir . '/minify/src/Converter.php');
3608 3608
 
3609 3609
 	// No namespaces, sorry!
3610
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3610
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3611 3611
 
3612 3612
 	// Temp path.
3613
-	$cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/';
3613
+	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
3614 3614
 
3615 3615
 	// What kind of file are we going to create?
3616
-	$toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type;
3616
+	$toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type;
3617 3617
 
3618 3618
 	// File has to exists, if it isn't try to create it.
3619 3619
 	if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate))
3620 3620
 	{
3621 3621
 		loadLanguage('Errors');
3622 3622
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3623
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3623
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3624 3624
 
3625 3625
 		// The process failed so roll back to print each individual file.
3626 3626
 		return $data;
@@ -3655,14 +3655,14 @@  discard block
 block discarded – undo
3655 3655
 	{
3656 3656
 		loadLanguage('Errors');
3657 3657
 		log_error(sprintf($txt['file_not_created'], $toCreate), 'general');
3658
-		cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null);
3658
+		cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null);
3659 3659
 
3660 3660
 		// The process failed so roll back to print each individual file.
3661 3661
 		return $data;
3662 3662
 	}
3663 3663
 
3664 3664
 	// And create a long lived cache entry.
3665
-	cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400);
3665
+	cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400);
3666 3666
 
3667 3667
 	return true;
3668 3668
 }
@@ -3719,7 +3719,7 @@  discard block
 block discarded – undo
3719 3719
 	else
3720 3720
 		$path = $modSettings['attachmentUploadDir'];
3721 3721
 
3722
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3722
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3723 3723
 }
3724 3724
 
3725 3725
 /**
@@ -3763,10 +3763,10 @@  discard block
 block discarded – undo
3763 3763
 		$valid_low = isValidIP($ip_parts[0]);
3764 3764
 		$valid_high = isValidIP($ip_parts[1]);
3765 3765
 		$count = 0;
3766
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
3766
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
3767 3767
 		$max = ($mode == ':' ? 'ffff' : '255');
3768 3768
 		$min = 0;
3769
-		if(!$valid_low)
3769
+		if (!$valid_low)
3770 3770
 		{
3771 3771
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
3772 3772
 			$valid_low = isValidIP($ip_parts[0]);
@@ -3780,7 +3780,7 @@  discard block
 block discarded – undo
3780 3780
 		}
3781 3781
 
3782 3782
 		$count = 0;
3783
-		if(!$valid_high)
3783
+		if (!$valid_high)
3784 3784
 		{
3785 3785
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
3786 3786
 			$valid_high = isValidIP($ip_parts[1]);
@@ -3793,7 +3793,7 @@  discard block
 block discarded – undo
3793 3793
 			}
3794 3794
 		}
3795 3795
 
3796
-		if($valid_high && $valid_low)
3796
+		if ($valid_high && $valid_low)
3797 3797
 		{
3798 3798
 			$ip_array['low'] = $ip_parts[0];
3799 3799
 			$ip_array['high'] = $ip_parts[1];
@@ -4066,7 +4066,7 @@  discard block
 block discarded – undo
4066 4066
 		addInlineJavaScript('
4067 4067
 	var user_menus = new smc_PopupMenu();
4068 4068
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4069
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4069
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4070 4070
 		if ($context['allow_pm'])
4071 4071
 			addInlineJavaScript('
4072 4072
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4694,7 +4694,7 @@  discard block
 block discarded – undo
4694 4694
 		// No? try a fallback to $sourcedir
4695 4695
 		else
4696 4696
 		{
4697
-			$absPath = $sourcedir .'/'. $file;
4697
+			$absPath = $sourcedir . '/' . $file;
4698 4698
 
4699 4699
 			if (file_exists($absPath))
4700 4700
 				require_once($absPath);
@@ -4775,15 +4775,15 @@  discard block
 block discarded – undo
4775 4775
 
4776 4776
 	// UTF-8 occurences of MS special characters
4777 4777
 	$findchars_utf8 = array(
4778
-		"\xe2\80\x9a",	// single low-9 quotation mark
4779
-		"\xe2\80\x9e",	// double low-9 quotation mark
4780
-		"\xe2\80\xa6",	// horizontal ellipsis
4781
-		"\xe2\x80\x98",	// left single curly quote
4782
-		"\xe2\x80\x99",	// right single curly quote
4783
-		"\xe2\x80\x9c",	// left double curly quote
4784
-		"\xe2\x80\x9d",	// right double curly quote
4785
-		"\xe2\x80\x93",	// en dash
4786
-		"\xe2\x80\x94",	// em dash
4778
+		"\xe2\80\x9a", // single low-9 quotation mark
4779
+		"\xe2\80\x9e", // double low-9 quotation mark
4780
+		"\xe2\80\xa6", // horizontal ellipsis
4781
+		"\xe2\x80\x98", // left single curly quote
4782
+		"\xe2\x80\x99", // right single curly quote
4783
+		"\xe2\x80\x9c", // left double curly quote
4784
+		"\xe2\x80\x9d", // right double curly quote
4785
+		"\xe2\x80\x93", // en dash
4786
+		"\xe2\x80\x94", // em dash
4787 4787
 	);
4788 4788
 
4789 4789
 	// windows 1252 / iso equivalents
@@ -4801,15 +4801,15 @@  discard block
 block discarded – undo
4801 4801
 
4802 4802
 	// safe replacements
4803 4803
 	$replacechars = array(
4804
-		',',	// &sbquo;
4805
-		',,',	// &bdquo;
4806
-		'...',	// &hellip;
4807
-		"'",	// &lsquo;
4808
-		"'",	// &rsquo;
4809
-		'"',	// &ldquo;
4810
-		'"',	// &rdquo;
4811
-		'-',	// &ndash;
4812
-		'--',	// &mdash;
4804
+		',', // &sbquo;
4805
+		',,', // &bdquo;
4806
+		'...', // &hellip;
4807
+		"'", // &lsquo;
4808
+		"'", // &rsquo;
4809
+		'"', // &ldquo;
4810
+		'"', // &rdquo;
4811
+		'-', // &ndash;
4812
+		'--', // &mdash;
4813 4813
 	);
4814 4814
 
4815 4815
 	if ($context['utf8'])
@@ -5095,7 +5095,7 @@  discard block
 block discarded – undo
5095 5095
  */
5096 5096
 function inet_dtop($bin)
5097 5097
 {
5098
-	if(empty($bin))
5098
+	if (empty($bin))
5099 5099
 		return '';
5100 5100
 
5101 5101
 	global $db_type;
@@ -5126,28 +5126,28 @@  discard block
 block discarded – undo
5126 5126
  */
5127 5127
 function _safe_serialize($value)
5128 5128
 {
5129
-	if(is_null($value))
5129
+	if (is_null($value))
5130 5130
 		return 'N;';
5131 5131
 
5132
-	if(is_bool($value))
5133
-		return 'b:'. (int) $value .';';
5132
+	if (is_bool($value))
5133
+		return 'b:' . (int) $value . ';';
5134 5134
 
5135
-	if(is_int($value))
5136
-		return 'i:'. $value .';';
5135
+	if (is_int($value))
5136
+		return 'i:' . $value . ';';
5137 5137
 
5138
-	if(is_float($value))
5139
-		return 'd:'. str_replace(',', '.', $value) .';';
5138
+	if (is_float($value))
5139
+		return 'd:' . str_replace(',', '.', $value) . ';';
5140 5140
 
5141
-	if(is_string($value))
5142
-		return 's:'. strlen($value) .':"'. $value .'";';
5141
+	if (is_string($value))
5142
+		return 's:' . strlen($value) . ':"' . $value . '";';
5143 5143
 
5144
-	if(is_array($value))
5144
+	if (is_array($value))
5145 5145
 	{
5146 5146
 		$out = '';
5147
-		foreach($value as $k => $v)
5147
+		foreach ($value as $k => $v)
5148 5148
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5149 5149
 
5150
-		return 'a:'. count($value) .':{'. $out .'}';
5150
+		return 'a:' . count($value) . ':{' . $out . '}';
5151 5151
 	}
5152 5152
 
5153 5153
 	// safe_serialize cannot serialize resources or objects.
@@ -5189,7 +5189,7 @@  discard block
 block discarded – undo
5189 5189
 function _safe_unserialize($str)
5190 5190
 {
5191 5191
 	// Input  is not a string.
5192
-	if(empty($str) || !is_string($str))
5192
+	if (empty($str) || !is_string($str))
5193 5193
 		return false;
5194 5194
 
5195 5195
 	$stack = array();
@@ -5203,40 +5203,40 @@  discard block
 block discarded – undo
5203 5203
 	 *   3 - in array, expecting value or another array
5204 5204
 	 */
5205 5205
 	$state = 0;
5206
-	while($state != 1)
5206
+	while ($state != 1)
5207 5207
 	{
5208 5208
 		$type = isset($str[0]) ? $str[0] : '';
5209
-		if($type == '}')
5209
+		if ($type == '}')
5210 5210
 			$str = substr($str, 1);
5211 5211
 
5212
-		else if($type == 'N' && $str[1] == ';')
5212
+		else if ($type == 'N' && $str[1] == ';')
5213 5213
 		{
5214 5214
 			$value = null;
5215 5215
 			$str = substr($str, 2);
5216 5216
 		}
5217
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5217
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5218 5218
 		{
5219 5219
 			$value = $matches[1] == '1' ? true : false;
5220 5220
 			$str = substr($str, 4);
5221 5221
 		}
5222
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5222
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5223 5223
 		{
5224
-			$value = (int)$matches[1];
5224
+			$value = (int) $matches[1];
5225 5225
 			$str = $matches[2];
5226 5226
 		}
5227
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5227
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5228 5228
 		{
5229
-			$value = (float)$matches[1];
5229
+			$value = (float) $matches[1];
5230 5230
 			$str = $matches[3];
5231 5231
 		}
5232
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5232
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5233 5233
 		{
5234
-			$value = substr($matches[2], 0, (int)$matches[1]);
5235
-			$str = substr($matches[2], (int)$matches[1] + 2);
5234
+			$value = substr($matches[2], 0, (int) $matches[1]);
5235
+			$str = substr($matches[2], (int) $matches[1] + 2);
5236 5236
 		}
5237
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5237
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5238 5238
 		{
5239
-			$expectedLength = (int)$matches[1];
5239
+			$expectedLength = (int) $matches[1];
5240 5240
 			$str = $matches[2];
5241 5241
 		}
5242 5242
 
@@ -5244,10 +5244,10 @@  discard block
 block discarded – undo
5244 5244
 		else
5245 5245
 			return false;
5246 5246
 
5247
-		switch($state)
5247
+		switch ($state)
5248 5248
 		{
5249 5249
 			case 3: // In array, expecting value or another array.
5250
-				if($type == 'a')
5250
+				if ($type == 'a')
5251 5251
 				{
5252 5252
 					$stack[] = &$list;
5253 5253
 					$list[$key] = array();
@@ -5256,7 +5256,7 @@  discard block
 block discarded – undo
5256 5256
 					$state = 2;
5257 5257
 					break;
5258 5258
 				}
5259
-				if($type != '}')
5259
+				if ($type != '}')
5260 5260
 				{
5261 5261
 					$list[$key] = $value;
5262 5262
 					$state = 2;
@@ -5267,29 +5267,29 @@  discard block
 block discarded – undo
5267 5267
 				return false;
5268 5268
 
5269 5269
 			case 2: // in array, expecting end of array or a key
5270
-				if($type == '}')
5270
+				if ($type == '}')
5271 5271
 				{
5272 5272
 					// Array size is less than expected.
5273
-					if(count($list) < end($expected))
5273
+					if (count($list) < end($expected))
5274 5274
 						return false;
5275 5275
 
5276 5276
 					unset($list);
5277
-					$list = &$stack[count($stack)-1];
5277
+					$list = &$stack[count($stack) - 1];
5278 5278
 					array_pop($stack);
5279 5279
 
5280 5280
 					// Go to terminal state if we're at the end of the root array.
5281 5281
 					array_pop($expected);
5282 5282
 
5283
-					if(count($expected) == 0)
5283
+					if (count($expected) == 0)
5284 5284
 						$state = 1;
5285 5285
 
5286 5286
 					break;
5287 5287
 				}
5288 5288
 
5289
-				if($type == 'i' || $type == 's')
5289
+				if ($type == 'i' || $type == 's')
5290 5290
 				{
5291 5291
 					// Array size exceeds expected length.
5292
-					if(count($list) >= end($expected))
5292
+					if (count($list) >= end($expected))
5293 5293
 						return false;
5294 5294
 
5295 5295
 					$key = $value;
@@ -5302,7 +5302,7 @@  discard block
 block discarded – undo
5302 5302
 
5303 5303
 			// Expecting array or value.
5304 5304
 			case 0:
5305
-				if($type == 'a')
5305
+				if ($type == 'a')
5306 5306
 				{
5307 5307
 					$data = array();
5308 5308
 					$list = &$data;
@@ -5311,7 +5311,7 @@  discard block
 block discarded – undo
5311 5311
 					break;
5312 5312
 				}
5313 5313
 
5314
-				if($type != '}')
5314
+				if ($type != '}')
5315 5315
 				{
5316 5316
 					$data = $value;
5317 5317
 					$state = 1;
@@ -5324,7 +5324,7 @@  discard block
 block discarded – undo
5324 5324
 	}
5325 5325
 
5326 5326
 	// Trailing data in input.
5327
-	if(!empty($str))
5327
+	if (!empty($str))
5328 5328
 		return false;
5329 5329
 
5330 5330
 	return $data;
@@ -5378,7 +5378,7 @@  discard block
 block discarded – undo
5378 5378
 	// Set different modes.
5379 5379
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5380 5380
 
5381
-	foreach($chmodValues as $val)
5381
+	foreach ($chmodValues as $val)
5382 5382
 	{
5383 5383
 		// If it's writable, break out of the loop.
5384 5384
 		if (is_writable($file))
@@ -5416,13 +5416,13 @@  discard block
 block discarded – undo
5416 5416
 	$returnArray = @json_decode($json, $returnAsArray);
5417 5417
 
5418 5418
 	// PHP 5.3 so no json_last_error_msg()
5419
-	switch(json_last_error())
5419
+	switch (json_last_error())
5420 5420
 	{
5421 5421
 		case JSON_ERROR_NONE:
5422 5422
 			$jsonError = false;
5423 5423
 			break;
5424 5424
 		case JSON_ERROR_DEPTH:
5425
-			$jsonError =  'JSON_ERROR_DEPTH';
5425
+			$jsonError = 'JSON_ERROR_DEPTH';
5426 5426
 			break;
5427 5427
 		case JSON_ERROR_STATE_MISMATCH:
5428 5428
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5450,10 +5450,10 @@  discard block
 block discarded – undo
5450 5450
 		loadLanguage('Errors');
5451 5451
 
5452 5452
 		if (!empty($jsonDebug))
5453
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5453
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5454 5454
 
5455 5455
 		else
5456
-			log_error($txt['json_'. $jsonError], 'critical');
5456
+			log_error($txt['json_' . $jsonError], 'critical');
5457 5457
 
5458 5458
 		// Everyone expects an array.
5459 5459
 		return array();
@@ -5557,7 +5557,7 @@  discard block
 block discarded – undo
5557 5557
 		});
5558 5558
 
5559 5559
 		// Convert Punycode to Unicode
5560
-		$tlds = array_map(function ($input) {
5560
+		$tlds = array_map(function($input) {
5561 5561
 			$prefix = 'xn--';
5562 5562
 			$safe_char = 0xFFFC;
5563 5563
 			$base = 36;
@@ -5573,7 +5573,7 @@  discard block
 block discarded – undo
5573 5573
 
5574 5574
 			foreach ($enco_parts as $encoded)
5575 5575
 			{
5576
-				if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0)
5576
+				if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0)
5577 5577
 				{
5578 5578
 					$output_parts[] = $encoded;
5579 5579
 					continue;
@@ -5584,7 +5584,7 @@  discard block
 block discarded – undo
5584 5584
 				$idx = 0;
5585 5585
 				$char = 0x80;
5586 5586
 				$decoded = array();
5587
-				$output='';
5587
+				$output = '';
5588 5588
 				$delim_pos = strrpos($encoded, '-');
5589 5589
 
5590 5590
 				if ($delim_pos > strlen($prefix))
@@ -5600,7 +5600,7 @@  discard block
 block discarded – undo
5600 5600
 
5601 5601
 				for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len)
5602 5602
 				{
5603
-					for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base)
5603
+					for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base)
5604 5604
 					{
5605 5605
 						$cp = ord($encoded{$enco_idx++});
5606 5606
 						$digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base));
@@ -5641,15 +5641,15 @@  discard block
 block discarded – undo
5641 5641
 
5642 5642
 					// 2 bytes
5643 5643
 					elseif ($v < (1 << 11))
5644
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5644
+						$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
5645 5645
 
5646 5646
 					// 3 bytes
5647 5647
 					elseif ($v < (1 << 16))
5648
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5648
+						$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5649 5649
 
5650 5650
 					// 4 bytes
5651 5651
 					elseif ($v < (1 << 21))
5652
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5652
+						$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
5653 5653
 
5654 5654
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5655 5655
 					else
@@ -5756,7 +5756,7 @@  discard block
 block discarded – undo
5756 5756
 	}
5757 5757
 
5758 5758
 	// This recursive function creates the index array from the strings
5759
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5759
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
5760 5760
 	{
5761 5761
 		static $depth = 0;
5762 5762
 		$depth++;
@@ -5783,7 +5783,7 @@  discard block
 block discarded – undo
5783 5783
 	};
5784 5784
 
5785 5785
 	// This recursive function turns the index array into a regular expression
5786
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
5786
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
5787 5787
 	{
5788 5788
 		static $depth = 0;
5789 5789
 		$depth++;
@@ -5806,9 +5806,9 @@  discard block
 block discarded – undo
5806 5806
 				$sub_regex = $index_to_regex($value, $delim);
5807 5807
 
5808 5808
 				if (count(array_keys($value)) == 1)
5809
-					$new_key .= explode('(?'.'>', $sub_regex)[0];
5809
+					$new_key .= explode('(?' . '>', $sub_regex)[0];
5810 5810
 				else
5811
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5811
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
5812 5812
 			}
5813 5813
 
5814 5814
 			if ($depth > 1)
@@ -5848,7 +5848,7 @@  discard block
 block discarded – undo
5848 5848
 		$index = $add_string_to_index($string, $index);
5849 5849
 
5850 5850
 	while (!empty($index))
5851
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
5851
+		$regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
5852 5852
 
5853 5853
 	// Restore PHP's internal character encoding to whatever it was originally
5854 5854
 	if (!empty($current_encoding))
Please login to merge, or discard this patch.
Braces   +1269 added lines, -943 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="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>';
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="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>';
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
 			),
@@ -1314,14 +1378,16 @@  discard block
 block discarded – undo
1314 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1315 1379
 					if ($image_proxy_enabled)
1316 1380
 					{
1317
-						if (empty($scheme))
1318
-							$data = 'http://' . ltrim($data, ':/');
1381
+						if (empty($scheme)) {
1382
+													$data = 'http://' . ltrim($data, ':/');
1383
+						}
1319 1384
 
1320
-						if ($scheme != 'https')
1321
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1385
+						if ($scheme != 'https') {
1386
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1387
+						}
1388
+					} elseif (empty($scheme)) {
1389
+											$data = '//' . ltrim($data, ':/');
1322 1390
 					}
1323
-					elseif (empty($scheme))
1324
-						$data = '//' . ltrim($data, ':/');
1325 1391
 				},
1326 1392
 				'disabled_content' => '($1)',
1327 1393
 			),
@@ -1337,14 +1403,16 @@  discard block
 block discarded – undo
1337 1403
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1338 1404
 					if ($image_proxy_enabled)
1339 1405
 					{
1340
-						if (empty($scheme))
1341
-							$data = 'http://' . ltrim($data, ':/');
1406
+						if (empty($scheme)) {
1407
+													$data = 'http://' . ltrim($data, ':/');
1408
+						}
1342 1409
 
1343
-						if ($scheme != 'https')
1344
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1410
+						if ($scheme != 'https') {
1411
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1412
+						}
1413
+					} elseif (empty($scheme)) {
1414
+											$data = '//' . ltrim($data, ':/');
1345 1415
 					}
1346
-					elseif (empty($scheme))
1347
-						$data = '//' . ltrim($data, ':/');
1348 1416
 				},
1349 1417
 				'disabled_content' => '($1)',
1350 1418
 			),
@@ -1356,8 +1424,9 @@  discard block
 block discarded – undo
1356 1424
 				{
1357 1425
 					$data = strtr($data, array('<br>' => ''));
1358 1426
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1359
-					if (empty($scheme))
1360
-						$data = '//' . ltrim($data, ':/');
1427
+					if (empty($scheme)) {
1428
+											$data = '//' . ltrim($data, ':/');
1429
+					}
1361 1430
 				},
1362 1431
 			),
1363 1432
 			array(
@@ -1368,13 +1437,14 @@  discard block
 block discarded – undo
1368 1437
 				'after' => '</a>',
1369 1438
 				'validate' => function (&$tag, &$data, $disabled)
1370 1439
 				{
1371
-					if (substr($data, 0, 1) == '#')
1372
-						$data = '#post_' . substr($data, 1);
1373
-					else
1440
+					if (substr($data, 0, 1) == '#') {
1441
+											$data = '#post_' . substr($data, 1);
1442
+					} else
1374 1443
 					{
1375 1444
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1376
-						if (empty($scheme))
1377
-							$data = '//' . ltrim($data, ':/');
1445
+						if (empty($scheme)) {
1446
+													$data = '//' . ltrim($data, ':/');
1447
+						}
1378 1448
 					}
1379 1449
 				},
1380 1450
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1452,8 +1522,9 @@  discard block
 block discarded – undo
1452 1522
 					{
1453 1523
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1454 1524
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1455
-						if ($add_begin)
1456
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1525
+						if ($add_begin) {
1526
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1527
+						}
1457 1528
 					}
1458 1529
 				},
1459 1530
 				'block_level' => false,
@@ -1584,10 +1655,11 @@  discard block
 block discarded – undo
1584 1655
 				'content' => '$1',
1585 1656
 				'validate' => function (&$tag, &$data, $disabled)
1586 1657
 				{
1587
-					if (is_numeric($data))
1588
-						$data = timeformat($data);
1589
-					else
1590
-						$tag['content'] = '[time]$1[/time]';
1658
+					if (is_numeric($data)) {
1659
+											$data = timeformat($data);
1660
+					} else {
1661
+											$tag['content'] = '[time]$1[/time]';
1662
+					}
1591 1663
 				},
1592 1664
 			),
1593 1665
 			array(
@@ -1614,8 +1686,9 @@  discard block
 block discarded – undo
1614 1686
 				{
1615 1687
 					$data = strtr($data, array('<br>' => ''));
1616 1688
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1617
-					if (empty($scheme))
1618
-						$data = '//' . ltrim($data, ':/');
1689
+					if (empty($scheme)) {
1690
+											$data = '//' . ltrim($data, ':/');
1691
+					}
1619 1692
 				},
1620 1693
 			),
1621 1694
 			array(
@@ -1627,8 +1700,9 @@  discard block
 block discarded – undo
1627 1700
 				'validate' => function (&$tag, &$data, $disabled)
1628 1701
 				{
1629 1702
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1630
-					if (empty($scheme))
1631
-						$data = '//' . ltrim($data, ':/');
1703
+					if (empty($scheme)) {
1704
+											$data = '//' . ltrim($data, ':/');
1705
+					}
1632 1706
 				},
1633 1707
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1634 1708
 				'disabled_after' => ' ($1)',
@@ -1648,8 +1722,9 @@  discard block
 block discarded – undo
1648 1722
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1649 1723
 		if ($message === false)
1650 1724
 		{
1651
-			if (isset($temp_bbc))
1652
-				$bbc_codes = $temp_bbc;
1725
+			if (isset($temp_bbc)) {
1726
+							$bbc_codes = $temp_bbc;
1727
+			}
1653 1728
 			usort($codes, function ($a, $b) {
1654 1729
 				return strcmp($a['tag'], $b['tag']);
1655 1730
 			});
@@ -1669,8 +1744,9 @@  discard block
 block discarded – undo
1669 1744
 		);
1670 1745
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1671 1746
 		{
1672
-			foreach ($itemcodes as $c => $dummy)
1673
-				$bbc_codes[$c] = array();
1747
+			foreach ($itemcodes as $c => $dummy) {
1748
+							$bbc_codes[$c] = array();
1749
+			}
1674 1750
 		}
1675 1751
 
1676 1752
 		// Shhhh!
@@ -1691,12 +1767,14 @@  discard block
 block discarded – undo
1691 1767
 		foreach ($codes as $code)
1692 1768
 		{
1693 1769
 			// Make it easier to process parameters later
1694
-			if (!empty($code['parameters']))
1695
-				ksort($code['parameters'], SORT_STRING);
1770
+			if (!empty($code['parameters'])) {
1771
+							ksort($code['parameters'], SORT_STRING);
1772
+			}
1696 1773
 
1697 1774
 			// If we are not doing every tag only do ones we are interested in.
1698
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1699
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1775
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1776
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1777
+			}
1700 1778
 		}
1701 1779
 		$codes = null;
1702 1780
 	}
@@ -1707,8 +1785,9 @@  discard block
 block discarded – undo
1707 1785
 		// It's likely this will change if the message is modified.
1708 1786
 		$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']);
1709 1787
 
1710
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1711
-			return $temp;
1788
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1789
+					return $temp;
1790
+		}
1712 1791
 
1713 1792
 		$cache_t = microtime();
1714 1793
 	}
@@ -1740,8 +1819,9 @@  discard block
 block discarded – undo
1740 1819
 		$disabled['flash'] = true;
1741 1820
 
1742 1821
 		// @todo Change maybe?
1743
-		if (!isset($_GET['images']))
1744
-			$disabled['img'] = true;
1822
+		if (!isset($_GET['images'])) {
1823
+					$disabled['img'] = true;
1824
+		}
1745 1825
 
1746 1826
 		// @todo Interface/setting to add more?
1747 1827
 	}
@@ -1767,8 +1847,9 @@  discard block
 block discarded – undo
1767 1847
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1768 1848
 
1769 1849
 		// Failsafe.
1770
-		if ($pos === false || $last_pos > $pos)
1771
-			$pos = strlen($message) + 1;
1850
+		if ($pos === false || $last_pos > $pos) {
1851
+					$pos = strlen($message) + 1;
1852
+		}
1772 1853
 
1773 1854
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1774 1855
 		if ($last_pos < $pos - 1)
@@ -1787,8 +1868,9 @@  discard block
 block discarded – undo
1787 1868
 
1788 1869
 				// <br> should be empty.
1789 1870
 				$empty_tags = array('br', 'hr');
1790
-				foreach ($empty_tags as $tag)
1791
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1871
+				foreach ($empty_tags as $tag) {
1872
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1873
+				}
1792 1874
 
1793 1875
 				// b, u, i, s, pre... basic tags.
1794 1876
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1797,8 +1879,9 @@  discard block
 block discarded – undo
1797 1879
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1798 1880
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1799 1881
 
1800
-					if ($diff > 0)
1801
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1882
+					if ($diff > 0) {
1883
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1884
+					}
1802 1885
 				}
1803 1886
 
1804 1887
 				// Do <img ...> - with security... action= -> action-.
@@ -1811,8 +1894,9 @@  discard block
 block discarded – undo
1811 1894
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1812 1895
 
1813 1896
 						// Remove action= from the URL - no funny business, now.
1814
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1815
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1897
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1898
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1899
+						}
1816 1900
 
1817 1901
 						// Check if the image is larger than allowed.
1818 1902
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1833,9 +1917,9 @@  discard block
 block discarded – undo
1833 1917
 
1834 1918
 							// Set the new image tag.
1835 1919
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1920
+						} else {
1921
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1836 1922
 						}
1837
-						else
1838
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1839 1923
 					}
1840 1924
 
1841 1925
 					$data = strtr($data, $replaces);
@@ -1848,16 +1932,18 @@  discard block
 block discarded – undo
1848 1932
 				$no_autolink_area = false;
1849 1933
 				if (!empty($open_tags))
1850 1934
 				{
1851
-					foreach ($open_tags as $open_tag)
1852
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1935
+					foreach ($open_tags as $open_tag) {
1936
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1853 1937
 							$no_autolink_area = true;
1938
+					}
1854 1939
 				}
1855 1940
 
1856 1941
 				// Don't go backwards.
1857 1942
 				// @todo Don't think is the real solution....
1858 1943
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1859
-				if ($pos < $lastAutoPos)
1860
-					$no_autolink_area = true;
1944
+				if ($pos < $lastAutoPos) {
1945
+									$no_autolink_area = true;
1946
+				}
1861 1947
 				$lastAutoPos = $pos;
1862 1948
 
1863 1949
 				if (!$no_autolink_area)
@@ -1966,17 +2052,19 @@  discard block
 block discarded – undo
1966 2052
 							if ($scheme == 'mailto')
1967 2053
 							{
1968 2054
 								$email_address = str_replace('mailto:', '', $url);
1969
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1970
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1971
-								else
1972
-									return $url;
2055
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2056
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2057
+								} else {
2058
+																	return $url;
2059
+								}
1973 2060
 							}
1974 2061
 
1975 2062
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1976
-							if (empty($scheme))
1977
-								$fullUrl = '//' . ltrim($url, ':/');
1978
-							else
1979
-								$fullUrl = $url;
2063
+							if (empty($scheme)) {
2064
+															$fullUrl = '//' . ltrim($url, ':/');
2065
+							} else {
2066
+															$fullUrl = $url;
2067
+							}
1980 2068
 
1981 2069
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
1982 2070
 						}, $data);
@@ -2025,16 +2113,18 @@  discard block
 block discarded – undo
2025 2113
 		}
2026 2114
 
2027 2115
 		// Are we there yet?  Are we there yet?
2028
-		if ($pos >= strlen($message) - 1)
2029
-			break;
2116
+		if ($pos >= strlen($message) - 1) {
2117
+					break;
2118
+		}
2030 2119
 
2031 2120
 		$tags = strtolower($message[$pos + 1]);
2032 2121
 
2033 2122
 		if ($tags == '/' && !empty($open_tags))
2034 2123
 		{
2035 2124
 			$pos2 = strpos($message, ']', $pos + 1);
2036
-			if ($pos2 == $pos + 2)
2037
-				continue;
2125
+			if ($pos2 == $pos + 2) {
2126
+							continue;
2127
+			}
2038 2128
 
2039 2129
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2040 2130
 
@@ -2044,8 +2134,9 @@  discard block
 block discarded – undo
2044 2134
 			do
2045 2135
 			{
2046 2136
 				$tag = array_pop($open_tags);
2047
-				if (!$tag)
2048
-					break;
2137
+				if (!$tag) {
2138
+									break;
2139
+				}
2049 2140
 
2050 2141
 				if (!empty($tag['block_level']))
2051 2142
 				{
@@ -2059,10 +2150,11 @@  discard block
 block discarded – undo
2059 2150
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2060 2151
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2061 2152
 					{
2062
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2063
-							if ($temp['tag'] == $look_for)
2153
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2154
+													if ($temp['tag'] == $look_for)
2064 2155
 							{
2065 2156
 								$block_level = !empty($temp['block_level']);
2157
+						}
2066 2158
 								break;
2067 2159
 							}
2068 2160
 					}
@@ -2084,15 +2176,15 @@  discard block
 block discarded – undo
2084 2176
 			{
2085 2177
 				$open_tags = $to_close;
2086 2178
 				continue;
2087
-			}
2088
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2179
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2089 2180
 			{
2090 2181
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2091 2182
 				{
2092
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2093
-						if ($temp['tag'] == $look_for)
2183
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2184
+											if ($temp['tag'] == $look_for)
2094 2185
 						{
2095 2186
 							$block_level = !empty($temp['block_level']);
2187
+					}
2096 2188
 							break;
2097 2189
 						}
2098 2190
 				}
@@ -2100,8 +2192,9 @@  discard block
 block discarded – undo
2100 2192
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2101 2193
 				if (!$block_level)
2102 2194
 				{
2103
-					foreach ($to_close as $tag)
2104
-						array_push($open_tags, $tag);
2195
+					foreach ($to_close as $tag) {
2196
+											array_push($open_tags, $tag);
2197
+					}
2105 2198
 					continue;
2106 2199
 				}
2107 2200
 			}
@@ -2113,10 +2206,12 @@  discard block
 block discarded – undo
2113 2206
 				$pos2 = $pos - 1;
2114 2207
 
2115 2208
 				// See the comment at the end of the big loop - just eating whitespace ;).
2116
-				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>')
2117
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2118
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2119
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2209
+				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') {
2210
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2211
+				}
2212
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2213
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2214
+				}
2120 2215
 			}
2121 2216
 
2122 2217
 			if (!empty($to_close))
@@ -2129,8 +2224,9 @@  discard block
 block discarded – undo
2129 2224
 		}
2130 2225
 
2131 2226
 		// No tags for this character, so just keep going (fastest possible course.)
2132
-		if (!isset($bbc_codes[$tags]))
2133
-			continue;
2227
+		if (!isset($bbc_codes[$tags])) {
2228
+					continue;
2229
+		}
2134 2230
 
2135 2231
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2136 2232
 		$tag = null;
@@ -2139,44 +2235,52 @@  discard block
 block discarded – undo
2139 2235
 			$pt_strlen = strlen($possible['tag']);
2140 2236
 
2141 2237
 			// Not a match?
2142
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2143
-				continue;
2238
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2239
+							continue;
2240
+			}
2144 2241
 
2145 2242
 			$next_c = $message[$pos + 1 + $pt_strlen];
2146 2243
 
2147 2244
 			// A test validation?
2148
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2149
-				continue;
2245
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2246
+							continue;
2247
+			}
2150 2248
 			// Do we want parameters?
2151 2249
 			elseif (!empty($possible['parameters']))
2152 2250
 			{
2153
-				if ($next_c != ' ')
2154
-					continue;
2155
-			}
2156
-			elseif (isset($possible['type']))
2251
+				if ($next_c != ' ') {
2252
+									continue;
2253
+				}
2254
+			} elseif (isset($possible['type']))
2157 2255
 			{
2158 2256
 				// Do we need an equal sign?
2159
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2160
-					continue;
2257
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2258
+									continue;
2259
+				}
2161 2260
 				// Maybe we just want a /...
2162
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2163
-					continue;
2261
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2262
+									continue;
2263
+				}
2164 2264
 				// An immediate ]?
2165
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2166
-					continue;
2265
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2266
+									continue;
2267
+				}
2167 2268
 			}
2168 2269
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2169
-			elseif ($next_c != ']')
2170
-				continue;
2270
+			elseif ($next_c != ']') {
2271
+							continue;
2272
+			}
2171 2273
 
2172 2274
 			// Check allowed tree?
2173
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2174
-				continue;
2175
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2176
-				continue;
2275
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2276
+							continue;
2277
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2278
+							continue;
2279
+			}
2177 2280
 			// If this is in the list of disallowed child tags, don't parse it.
2178
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2179
-				continue;
2281
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2282
+							continue;
2283
+			}
2180 2284
 
2181 2285
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2182 2286
 
@@ -2188,8 +2292,9 @@  discard block
 block discarded – undo
2188 2292
 				foreach ($open_tags as $open_quote)
2189 2293
 				{
2190 2294
 					// Every parent quote this quote has flips the styling
2191
-					if ($open_quote['tag'] == 'quote')
2192
-						$quote_alt = !$quote_alt;
2295
+					if ($open_quote['tag'] == 'quote') {
2296
+											$quote_alt = !$quote_alt;
2297
+					}
2193 2298
 				}
2194 2299
 				// Add a class to the quote to style alternating blockquotes
2195 2300
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2200,8 +2305,9 @@  discard block
 block discarded – undo
2200 2305
 			{
2201 2306
 				// Build a regular expression for each parameter for the current tag.
2202 2307
 				$preg = array();
2203
-				foreach ($possible['parameters'] as $p => $info)
2204
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2308
+				foreach ($possible['parameters'] as $p => $info) {
2309
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2310
+				}
2205 2311
 
2206 2312
 				// Extract the string that potentially holds our parameters.
2207 2313
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2221,24 +2327,27 @@  discard block
 block discarded – undo
2221 2327
 
2222 2328
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2223 2329
 
2224
-					if ($match)
2225
-						$blob_counter = count($blobs) + 1;
2330
+					if ($match) {
2331
+											$blob_counter = count($blobs) + 1;
2332
+					}
2226 2333
 				}
2227 2334
 
2228 2335
 				// Didn't match our parameter list, try the next possible.
2229
-				if (!$match)
2230
-					continue;
2336
+				if (!$match) {
2337
+									continue;
2338
+				}
2231 2339
 
2232 2340
 				$params = array();
2233 2341
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2234 2342
 				{
2235 2343
 					$key = strtok(ltrim($matches[$i]), '=');
2236
-					if (isset($possible['parameters'][$key]['value']))
2237
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2238
-					elseif (isset($possible['parameters'][$key]['validate']))
2239
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2240
-					else
2241
-						$params['{' . $key . '}'] = $matches[$i + 1];
2344
+					if (isset($possible['parameters'][$key]['value'])) {
2345
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2346
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2347
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2348
+					} else {
2349
+											$params['{' . $key . '}'] = $matches[$i + 1];
2350
+					}
2242 2351
 
2243 2352
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2244 2353
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2246,23 +2355,26 @@  discard block
 block discarded – undo
2246 2355
 
2247 2356
 				foreach ($possible['parameters'] as $p => $info)
2248 2357
 				{
2249
-					if (!isset($params['{' . $p . '}']))
2250
-						$params['{' . $p . '}'] = '';
2358
+					if (!isset($params['{' . $p . '}'])) {
2359
+											$params['{' . $p . '}'] = '';
2360
+					}
2251 2361
 				}
2252 2362
 
2253 2363
 				$tag = $possible;
2254 2364
 
2255 2365
 				// Put the parameters into the string.
2256
-				if (isset($tag['before']))
2257
-					$tag['before'] = strtr($tag['before'], $params);
2258
-				if (isset($tag['after']))
2259
-					$tag['after'] = strtr($tag['after'], $params);
2260
-				if (isset($tag['content']))
2261
-					$tag['content'] = strtr($tag['content'], $params);
2366
+				if (isset($tag['before'])) {
2367
+									$tag['before'] = strtr($tag['before'], $params);
2368
+				}
2369
+				if (isset($tag['after'])) {
2370
+									$tag['after'] = strtr($tag['after'], $params);
2371
+				}
2372
+				if (isset($tag['content'])) {
2373
+									$tag['content'] = strtr($tag['content'], $params);
2374
+				}
2262 2375
 
2263 2376
 				$pos1 += strlen($given_param_string);
2264
-			}
2265
-			else
2377
+			} else
2266 2378
 			{
2267 2379
 				$tag = $possible;
2268 2380
 				$params = array();
@@ -2273,8 +2385,9 @@  discard block
 block discarded – undo
2273 2385
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2274 2386
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2275 2387
 		{
2276
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2277
-				continue;
2388
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2389
+							continue;
2390
+			}
2278 2391
 
2279 2392
 			$tag = $itemcodes[$message[$pos + 1]];
2280 2393
 
@@ -2295,9 +2408,9 @@  discard block
 block discarded – undo
2295 2408
 			{
2296 2409
 				array_pop($open_tags);
2297 2410
 				$code = '</li>';
2411
+			} else {
2412
+							$code = '';
2298 2413
 			}
2299
-			else
2300
-				$code = '';
2301 2414
 
2302 2415
 			// Now we open a new tag.
2303 2416
 			$open_tags[] = array(
@@ -2344,12 +2457,14 @@  discard block
 block discarded – undo
2344 2457
 		}
2345 2458
 
2346 2459
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2347
-		if ($tag === null)
2348
-			continue;
2460
+		if ($tag === null) {
2461
+					continue;
2462
+		}
2349 2463
 
2350 2464
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2351
-		if (isset($inside['disallow_children']))
2352
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2465
+		if (isset($inside['disallow_children'])) {
2466
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2467
+		}
2353 2468
 
2354 2469
 		// Is this tag disabled?
2355 2470
 		if (isset($disabled[$tag['tag']]))
@@ -2359,14 +2474,13 @@  discard block
 block discarded – undo
2359 2474
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2360 2475
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2361 2476
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2362
-			}
2363
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2477
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2364 2478
 			{
2365 2479
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2366 2480
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2481
+			} else {
2482
+							$tag['content'] = $tag['disabled_content'];
2367 2483
 			}
2368
-			else
2369
-				$tag['content'] = $tag['disabled_content'];
2370 2484
 		}
2371 2485
 
2372 2486
 		// we use this a lot
@@ -2376,8 +2490,9 @@  discard block
 block discarded – undo
2376 2490
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2377 2491
 		{
2378 2492
 			$n = count($open_tags) - 1;
2379
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2380
-				$n--;
2493
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2494
+							$n--;
2495
+			}
2381 2496
 
2382 2497
 			// Close all the non block level tags so this tag isn't surrounded by them.
2383 2498
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2388,10 +2503,12 @@  discard block
 block discarded – undo
2388 2503
 				$pos1 += $ot_strlen + 2;
2389 2504
 
2390 2505
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2391
-				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>')
2392
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2393
-				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2394
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2506
+				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') {
2507
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2508
+				}
2509
+				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2510
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2511
+				}
2395 2512
 
2396 2513
 				array_pop($open_tags);
2397 2514
 			}
@@ -2409,16 +2526,19 @@  discard block
 block discarded – undo
2409 2526
 		elseif ($tag['type'] == 'unparsed_content')
2410 2527
 		{
2411 2528
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2412
-			if ($pos2 === false)
2413
-				continue;
2529
+			if ($pos2 === false) {
2530
+							continue;
2531
+			}
2414 2532
 
2415 2533
 			$data = substr($message, $pos1, $pos2 - $pos1);
2416 2534
 
2417
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2418
-				$data = substr($data, 4);
2535
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2536
+							$data = substr($data, 4);
2537
+			}
2419 2538
 
2420
-			if (isset($tag['validate']))
2421
-				$tag['validate']($tag, $data, $disabled, $params);
2539
+			if (isset($tag['validate'])) {
2540
+							$tag['validate']($tag, $data, $disabled, $params);
2541
+			}
2422 2542
 
2423 2543
 			$code = strtr($tag['content'], array('$1' => $data));
2424 2544
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2434,34 +2554,40 @@  discard block
 block discarded – undo
2434 2554
 			if (isset($tag['quoted']))
2435 2555
 			{
2436 2556
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2437
-				if ($tag['quoted'] != 'optional' && !$quoted)
2438
-					continue;
2557
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2558
+									continue;
2559
+				}
2439 2560
 
2440
-				if ($quoted)
2441
-					$pos1 += 6;
2561
+				if ($quoted) {
2562
+									$pos1 += 6;
2563
+				}
2564
+			} else {
2565
+							$quoted = false;
2442 2566
 			}
2443
-			else
2444
-				$quoted = false;
2445 2567
 
2446 2568
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2447
-			if ($pos2 === false)
2448
-				continue;
2569
+			if ($pos2 === false) {
2570
+							continue;
2571
+			}
2449 2572
 
2450 2573
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2451
-			if ($pos3 === false)
2452
-				continue;
2574
+			if ($pos3 === false) {
2575
+							continue;
2576
+			}
2453 2577
 
2454 2578
 			$data = array(
2455 2579
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2456 2580
 				substr($message, $pos1, $pos2 - $pos1)
2457 2581
 			);
2458 2582
 
2459
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2460
-				$data[0] = substr($data[0], 4);
2583
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2584
+							$data[0] = substr($data[0], 4);
2585
+			}
2461 2586
 
2462 2587
 			// Validation for my parking, please!
2463
-			if (isset($tag['validate']))
2464
-				$tag['validate']($tag, $data, $disabled, $params);
2588
+			if (isset($tag['validate'])) {
2589
+							$tag['validate']($tag, $data, $disabled, $params);
2590
+			}
2465 2591
 
2466 2592
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2467 2593
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2478,23 +2604,27 @@  discard block
 block discarded – undo
2478 2604
 		elseif ($tag['type'] == 'unparsed_commas_content')
2479 2605
 		{
2480 2606
 			$pos2 = strpos($message, ']', $pos1);
2481
-			if ($pos2 === false)
2482
-				continue;
2607
+			if ($pos2 === false) {
2608
+							continue;
2609
+			}
2483 2610
 
2484 2611
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2485
-			if ($pos3 === false)
2486
-				continue;
2612
+			if ($pos3 === false) {
2613
+							continue;
2614
+			}
2487 2615
 
2488 2616
 			// We want $1 to be the content, and the rest to be csv.
2489 2617
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2490 2618
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2491 2619
 
2492
-			if (isset($tag['validate']))
2493
-				$tag['validate']($tag, $data, $disabled, $params);
2620
+			if (isset($tag['validate'])) {
2621
+							$tag['validate']($tag, $data, $disabled, $params);
2622
+			}
2494 2623
 
2495 2624
 			$code = $tag['content'];
2496
-			foreach ($data as $k => $d)
2497
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2625
+			foreach ($data as $k => $d) {
2626
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2627
+			}
2498 2628
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2499 2629
 			$pos += strlen($code) - 1 + 2;
2500 2630
 		}
@@ -2502,24 +2632,28 @@  discard block
 block discarded – undo
2502 2632
 		elseif ($tag['type'] == 'unparsed_commas')
2503 2633
 		{
2504 2634
 			$pos2 = strpos($message, ']', $pos1);
2505
-			if ($pos2 === false)
2506
-				continue;
2635
+			if ($pos2 === false) {
2636
+							continue;
2637
+			}
2507 2638
 
2508 2639
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2509 2640
 
2510
-			if (isset($tag['validate']))
2511
-				$tag['validate']($tag, $data, $disabled, $params);
2641
+			if (isset($tag['validate'])) {
2642
+							$tag['validate']($tag, $data, $disabled, $params);
2643
+			}
2512 2644
 
2513 2645
 			// Fix after, for disabled code mainly.
2514
-			foreach ($data as $k => $d)
2515
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2646
+			foreach ($data as $k => $d) {
2647
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2648
+			}
2516 2649
 
2517 2650
 			$open_tags[] = $tag;
2518 2651
 
2519 2652
 			// Replace them out, $1, $2, $3, $4, etc.
2520 2653
 			$code = $tag['before'];
2521
-			foreach ($data as $k => $d)
2522
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2523 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2524 2658
 			$pos += strlen($code) - 1 + 2;
2525 2659
 		}
@@ -2530,28 +2664,33 @@  discard block
 block discarded – undo
2530 2664
 			if (isset($tag['quoted']))
2531 2665
 			{
2532 2666
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2533
-				if ($tag['quoted'] != 'optional' && !$quoted)
2534
-					continue;
2667
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2668
+									continue;
2669
+				}
2535 2670
 
2536
-				if ($quoted)
2537
-					$pos1 += 6;
2671
+				if ($quoted) {
2672
+									$pos1 += 6;
2673
+				}
2674
+			} else {
2675
+							$quoted = false;
2538 2676
 			}
2539
-			else
2540
-				$quoted = false;
2541 2677
 
2542 2678
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2543
-			if ($pos2 === false)
2544
-				continue;
2679
+			if ($pos2 === false) {
2680
+							continue;
2681
+			}
2545 2682
 
2546 2683
 			$data = substr($message, $pos1, $pos2 - $pos1);
2547 2684
 
2548 2685
 			// Validation for my parking, please!
2549
-			if (isset($tag['validate']))
2550
-				$tag['validate']($tag, $data, $disabled, $params);
2686
+			if (isset($tag['validate'])) {
2687
+							$tag['validate']($tag, $data, $disabled, $params);
2688
+			}
2551 2689
 
2552 2690
 			// For parsed content, we must recurse to avoid security problems.
2553
-			if ($tag['type'] != 'unparsed_equals')
2554
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2691
+			if ($tag['type'] != 'unparsed_equals') {
2692
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2693
+			}
2555 2694
 
2556 2695
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2557 2696
 
@@ -2563,34 +2702,40 @@  discard block
 block discarded – undo
2563 2702
 		}
2564 2703
 
2565 2704
 		// If this is block level, eat any breaks after it.
2566
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2567
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2705
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2706
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2707
+		}
2568 2708
 
2569 2709
 		// Are we trimming outside this tag?
2570
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2571
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2710
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2711
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2712
+		}
2572 2713
 	}
2573 2714
 
2574 2715
 	// Close any remaining tags.
2575
-	while ($tag = array_pop($open_tags))
2576
-		$message .= "\n" . $tag['after'] . "\n";
2716
+	while ($tag = array_pop($open_tags)) {
2717
+			$message .= "\n" . $tag['after'] . "\n";
2718
+	}
2577 2719
 
2578 2720
 	// Parse the smileys within the parts where it can be done safely.
2579 2721
 	if ($smileys === true)
2580 2722
 	{
2581 2723
 		$message_parts = explode("\n", $message);
2582
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2583
-			parsesmileys($message_parts[$i]);
2724
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2725
+					parsesmileys($message_parts[$i]);
2726
+		}
2584 2727
 
2585 2728
 		$message = implode('', $message_parts);
2586 2729
 	}
2587 2730
 
2588 2731
 	// No smileys, just get rid of the markers.
2589
-	else
2590
-		$message = strtr($message, array("\n" => ''));
2732
+	else {
2733
+			$message = strtr($message, array("\n" => ''));
2734
+	}
2591 2735
 
2592
-	if ($message !== '' && $message[0] === ' ')
2593
-		$message = '&nbsp;' . substr($message, 1);
2736
+	if ($message !== '' && $message[0] === ' ') {
2737
+			$message = '&nbsp;' . substr($message, 1);
2738
+	}
2594 2739
 
2595 2740
 	// Cleanup whitespace.
2596 2741
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2599,15 +2744,16 @@  discard block
 block discarded – undo
2599 2744
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2600 2745
 
2601 2746
 	// Cache the output if it took some time...
2602
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2603
-		cache_put_data($cache_key, $message, 240);
2747
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2748
+			cache_put_data($cache_key, $message, 240);
2749
+	}
2604 2750
 
2605 2751
 	// If this was a force parse revert if needed.
2606 2752
 	if (!empty($parse_tags))
2607 2753
 	{
2608
-		if (empty($temp_bbc))
2609
-			$bbc_codes = array();
2610
-		else
2754
+		if (empty($temp_bbc)) {
2755
+					$bbc_codes = array();
2756
+		} else
2611 2757
 		{
2612 2758
 			$bbc_codes = $temp_bbc;
2613 2759
 			unset($temp_bbc);
@@ -2634,8 +2780,9 @@  discard block
 block discarded – undo
2634 2780
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2635 2781
 
2636 2782
 	// No smiley set at all?!
2637
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2638
-		return;
2783
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2784
+			return;
2785
+	}
2639 2786
 
2640 2787
 	// If smileyPregSearch hasn't been set, do it now.
2641 2788
 	if (empty($smileyPregSearch))
@@ -2646,8 +2793,7 @@  discard block
 block discarded – undo
2646 2793
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2647 2794
 			$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');
2648 2795
 			$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'], '', '', '', '');
2649
-		}
2650
-		else
2796
+		} else
2651 2797
 		{
2652 2798
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2653 2799
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2671,9 +2817,9 @@  discard block
 block discarded – undo
2671 2817
 				$smcFunc['db_free_result']($result);
2672 2818
 
2673 2819
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2820
+			} else {
2821
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2674 2822
 			}
2675
-			else
2676
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2677 2823
 		}
2678 2824
 
2679 2825
 		// The non-breaking-space is a complex thing...
@@ -2750,35 +2896,41 @@  discard block
 block discarded – undo
2750 2896
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2751 2897
 
2752 2898
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2753
-	if (!empty($context['flush_mail']))
2754
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2899
+	if (!empty($context['flush_mail'])) {
2900
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2755 2901
 		AddMailQueue(true);
2902
+	}
2756 2903
 
2757 2904
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2758 2905
 
2759
-	if ($add)
2760
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2906
+	if ($add) {
2907
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2908
+	}
2761 2909
 
2762 2910
 	// Put the session ID in.
2763
-	if (defined('SID') && SID != '')
2764
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2911
+	if (defined('SID') && SID != '') {
2912
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2913
+	}
2765 2914
 	// Keep that debug in their for template debugging!
2766
-	elseif (isset($_GET['debug']))
2767
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2915
+	elseif (isset($_GET['debug'])) {
2916
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2917
+	}
2768 2918
 
2769 2919
 	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'])))
2770 2920
 	{
2771
-		if (defined('SID') && SID != '')
2772
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2921
+		if (defined('SID') && SID != '') {
2922
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2773 2923
 				function ($m) use ($scripturl)
2774 2924
 				{
2775 2925
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2926
+		}
2776 2927
 				}, $setLocation);
2777
-		else
2778
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2928
+		else {
2929
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2779 2930
 				function ($m) use ($scripturl)
2780 2931
 				{
2781 2932
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2933
+		}
2782 2934
 				}, $setLocation);
2783 2935
 	}
2784 2936
 
@@ -2789,8 +2941,9 @@  discard block
 block discarded – undo
2789 2941
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2790 2942
 
2791 2943
 	// Debugging.
2792
-	if (isset($db_show_debug) && $db_show_debug === true)
2793
-		$_SESSION['debug_redirect'] = $db_cache;
2944
+	if (isset($db_show_debug) && $db_show_debug === true) {
2945
+			$_SESSION['debug_redirect'] = $db_cache;
2946
+	}
2794 2947
 
2795 2948
 	obExit(false);
2796 2949
 }
@@ -2809,51 +2962,60 @@  discard block
 block discarded – undo
2809 2962
 
2810 2963
 	// Attempt to prevent a recursive loop.
2811 2964
 	++$level;
2812
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2813
-		exit;
2814
-	if ($from_fatal_error)
2815
-		$has_fatal_error = true;
2965
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2966
+			exit;
2967
+	}
2968
+	if ($from_fatal_error) {
2969
+			$has_fatal_error = true;
2970
+	}
2816 2971
 
2817 2972
 	// Clear out the stat cache.
2818 2973
 	trackStats();
2819 2974
 
2820 2975
 	// If we have mail to send, send it.
2821
-	if (!empty($context['flush_mail']))
2822
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2976
+	if (!empty($context['flush_mail'])) {
2977
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2823 2978
 		AddMailQueue(true);
2979
+	}
2824 2980
 
2825 2981
 	$do_header = $header === null ? !$header_done : $header;
2826
-	if ($do_footer === null)
2827
-		$do_footer = $do_header;
2982
+	if ($do_footer === null) {
2983
+			$do_footer = $do_header;
2984
+	}
2828 2985
 
2829 2986
 	// Has the template/header been done yet?
2830 2987
 	if ($do_header)
2831 2988
 	{
2832 2989
 		// Was the page title set last minute? Also update the HTML safe one.
2833
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2834
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2990
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
2991
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2992
+		}
2835 2993
 
2836 2994
 		// Start up the session URL fixer.
2837 2995
 		ob_start('ob_sessrewrite');
2838 2996
 
2839
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2840
-			$buffers = explode(',', $settings['output_buffers']);
2841
-		elseif (!empty($settings['output_buffers']))
2842
-			$buffers = $settings['output_buffers'];
2843
-		else
2844
-			$buffers = array();
2997
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
2998
+					$buffers = explode(',', $settings['output_buffers']);
2999
+		} elseif (!empty($settings['output_buffers'])) {
3000
+					$buffers = $settings['output_buffers'];
3001
+		} else {
3002
+					$buffers = array();
3003
+		}
2845 3004
 
2846
-		if (isset($modSettings['integrate_buffer']))
2847
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3005
+		if (isset($modSettings['integrate_buffer'])) {
3006
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3007
+		}
2848 3008
 
2849
-		if (!empty($buffers))
2850
-			foreach ($buffers as $function)
3009
+		if (!empty($buffers)) {
3010
+					foreach ($buffers as $function)
2851 3011
 			{
2852 3012
 				$call = call_helper($function, true);
3013
+		}
2853 3014
 
2854 3015
 				// Is it valid?
2855
-				if (!empty($call))
2856
-					ob_start($call);
3016
+				if (!empty($call)) {
3017
+									ob_start($call);
3018
+				}
2857 3019
 			}
2858 3020
 
2859 3021
 		// Display the screen in the logical order.
@@ -2865,8 +3027,9 @@  discard block
 block discarded – undo
2865 3027
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2866 3028
 
2867 3029
 		// Anything special to put out?
2868
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2869
-			echo $context['insert_after_template'];
3030
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3031
+					echo $context['insert_after_template'];
3032
+		}
2870 3033
 
2871 3034
 		// Just so we don't get caught in an endless loop of errors from the footer...
2872 3035
 		if (!$footer_done)
@@ -2875,14 +3038,16 @@  discard block
 block discarded – undo
2875 3038
 			template_footer();
2876 3039
 
2877 3040
 			// (since this is just debugging... it's okay that it's after </html>.)
2878
-			if (!isset($_REQUEST['xml']))
2879
-				displayDebug();
3041
+			if (!isset($_REQUEST['xml'])) {
3042
+							displayDebug();
3043
+			}
2880 3044
 		}
2881 3045
 	}
2882 3046
 
2883 3047
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2884
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2885
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3048
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3049
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3050
+	}
2886 3051
 
2887 3052
 	// For session check verification.... don't switch browsers...
2888 3053
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2891,9 +3056,10 @@  discard block
 block discarded – undo
2891 3056
 	call_integration_hook('integrate_exit', array($do_footer));
2892 3057
 
2893 3058
 	// Don't exit if we're coming from index.php; that will pass through normally.
2894
-	if (!$from_index)
2895
-		exit;
2896
-}
3059
+	if (!$from_index) {
3060
+			exit;
3061
+	}
3062
+	}
2897 3063
 
2898 3064
 /**
2899 3065
  * Get the size of a specified image with better error handling.
@@ -2912,8 +3078,9 @@  discard block
 block discarded – undo
2912 3078
 	$url = str_replace(' ', '%20', $url);
2913 3079
 
2914 3080
 	// Can we pull this from the cache... please please?
2915
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2916
-		return $temp;
3081
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3082
+			return $temp;
3083
+	}
2917 3084
 	$t = microtime();
2918 3085
 
2919 3086
 	// Get the host to pester...
@@ -2923,12 +3090,10 @@  discard block
 block discarded – undo
2923 3090
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2924 3091
 	{
2925 3092
 		return false;
2926
-	}
2927
-	elseif (!isset($match[1]))
3093
+	} elseif (!isset($match[1]))
2928 3094
 	{
2929 3095
 		$size = @getimagesize($url);
2930
-	}
2931
-	else
3096
+	} else
2932 3097
 	{
2933 3098
 		// Try to connect to the server... give it half a second.
2934 3099
 		$temp = 0;
@@ -2967,12 +3132,14 @@  discard block
 block discarded – undo
2967 3132
 	}
2968 3133
 
2969 3134
 	// If we didn't get it, we failed.
2970
-	if (!isset($size))
2971
-		$size = false;
3135
+	if (!isset($size)) {
3136
+			$size = false;
3137
+	}
2972 3138
 
2973 3139
 	// If this took a long time, we may never have to do it again, but then again we might...
2974
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
2975
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3140
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3141
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3142
+	}
2976 3143
 
2977 3144
 	// Didn't work.
2978 3145
 	return $size;
@@ -2990,8 +3157,9 @@  discard block
 block discarded – undo
2990 3157
 
2991 3158
 	// Under SSI this function can be called more then once.  That can cause some problems.
2992 3159
 	//   So only run the function once unless we are forced to run it again.
2993
-	if ($loaded && !$forceload)
2994
-		return;
3160
+	if ($loaded && !$forceload) {
3161
+			return;
3162
+	}
2995 3163
 
2996 3164
 	$loaded = true;
2997 3165
 
@@ -3003,14 +3171,16 @@  discard block
 block discarded – undo
3003 3171
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3004 3172
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3005 3173
 	{
3006
-		if (trim($context['news_lines'][$i]) == '')
3007
-			continue;
3174
+		if (trim($context['news_lines'][$i]) == '') {
3175
+					continue;
3176
+		}
3008 3177
 
3009 3178
 		// Clean it up for presentation ;).
3010 3179
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3011 3180
 	}
3012
-	if (!empty($context['news_lines']))
3013
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3181
+	if (!empty($context['news_lines'])) {
3182
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3183
+	}
3014 3184
 
3015 3185
 	if (!$user_info['is_guest'])
3016 3186
 	{
@@ -3019,40 +3189,48 @@  discard block
 block discarded – undo
3019 3189
 		$context['user']['alerts'] = &$user_info['alerts'];
3020 3190
 
3021 3191
 		// Personal message popup...
3022
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3023
-			$context['user']['popup_messages'] = true;
3024
-		else
3025
-			$context['user']['popup_messages'] = false;
3192
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3193
+					$context['user']['popup_messages'] = true;
3194
+		} else {
3195
+					$context['user']['popup_messages'] = false;
3196
+		}
3026 3197
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3027 3198
 
3028
-		if (allowedTo('moderate_forum'))
3029
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3199
+		if (allowedTo('moderate_forum')) {
3200
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3201
+		}
3030 3202
 
3031 3203
 		$context['user']['avatar'] = array();
3032 3204
 
3033 3205
 		// Check for gravatar first since we might be forcing them...
3034 3206
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3035 3207
 		{
3036
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3037
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3038
-			else
3039
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3208
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3209
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3210
+			} else {
3211
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3212
+			}
3040 3213
 		}
3041 3214
 		// Uploaded?
3042
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3043
-			$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';
3215
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3216
+					$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';
3217
+		}
3044 3218
 		// Full URL?
3045
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3046
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3219
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3220
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3221
+		}
3047 3222
 		// Otherwise we assume it's server stored.
3048
-		elseif ($user_info['avatar']['url'] != '')
3049
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3223
+		elseif ($user_info['avatar']['url'] != '') {
3224
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3225
+		}
3050 3226
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3051
-		else
3052
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3227
+		else {
3228
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3229
+		}
3053 3230
 
3054
-		if (!empty($context['user']['avatar']))
3055
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3231
+		if (!empty($context['user']['avatar'])) {
3232
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3233
+		}
3056 3234
 
3057 3235
 		// Figure out how long they've been logged in.
3058 3236
 		$context['user']['total_time_logged_in'] = array(
@@ -3060,8 +3238,7 @@  discard block
 block discarded – undo
3060 3238
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3061 3239
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3062 3240
 		);
3063
-	}
3064
-	else
3241
+	} else
3065 3242
 	{
3066 3243
 		$context['user']['messages'] = 0;
3067 3244
 		$context['user']['unread_messages'] = 0;
@@ -3069,12 +3246,14 @@  discard block
 block discarded – undo
3069 3246
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3070 3247
 		$context['user']['popup_messages'] = false;
3071 3248
 
3072
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3073
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3249
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3250
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3251
+		}
3074 3252
 
3075 3253
 		// If we've upgraded recently, go easy on the passwords.
3076
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3077
-			$context['disable_login_hashing'] = true;
3254
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3255
+					$context['disable_login_hashing'] = true;
3256
+		}
3078 3257
 	}
3079 3258
 
3080 3259
 	// Setup the main menu items.
@@ -3087,8 +3266,8 @@  discard block
 block discarded – undo
3087 3266
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3088 3267
 
3089 3268
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3090
-	if ($context['show_pm_popup'])
3091
-		addInlineJavaScript('
3269
+	if ($context['show_pm_popup']) {
3270
+			addInlineJavaScript('
3092 3271
 		jQuery(document).ready(function($) {
3093 3272
 			new smc_Popup({
3094 3273
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3096,15 +3275,17 @@  discard block
 block discarded – undo
3096 3275
 				icon_class: \'generic_icons mail_new\'
3097 3276
 			});
3098 3277
 		});');
3278
+	}
3099 3279
 
3100 3280
 	// Add a generic "Are you sure?" confirmation message.
3101 3281
 	addInlineJavaScript('
3102 3282
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3103 3283
 
3104 3284
 	// Now add the capping code for avatars.
3105
-	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')
3106
-		addInlineCss('
3285
+	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') {
3286
+			addInlineCss('
3107 3287
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3288
+	}
3108 3289
 
3109 3290
 	// This looks weird, but it's because BoardIndex.php references the variable.
3110 3291
 	$context['common_stats']['latest_member'] = array(
@@ -3121,11 +3302,13 @@  discard block
 block discarded – undo
3121 3302
 	);
3122 3303
 	$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']);
3123 3304
 
3124
-	if (empty($settings['theme_version']))
3125
-		addJavaScriptVar('smf_scripturl', $scripturl);
3305
+	if (empty($settings['theme_version'])) {
3306
+			addJavaScriptVar('smf_scripturl', $scripturl);
3307
+	}
3126 3308
 
3127
-	if (!isset($context['page_title']))
3128
-		$context['page_title'] = '';
3309
+	if (!isset($context['page_title'])) {
3310
+			$context['page_title'] = '';
3311
+	}
3129 3312
 
3130 3313
 	// Set some specific vars.
3131 3314
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3135,21 +3318,23 @@  discard block
 block discarded – undo
3135 3318
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3136 3319
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3137 3320
 
3138
-	if (!empty($context['meta_keywords']))
3139
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3321
+	if (!empty($context['meta_keywords'])) {
3322
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3323
+	}
3140 3324
 
3141
-	if (!empty($context['canonical_url']))
3142
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3325
+	if (!empty($context['canonical_url'])) {
3326
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3327
+	}
3143 3328
 
3144
-	if (!empty($settings['og_image']))
3145
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3329
+	if (!empty($settings['og_image'])) {
3330
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3331
+	}
3146 3332
 
3147 3333
 	if (!empty($context['meta_description']))
3148 3334
 	{
3149 3335
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3150 3336
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3151
-	}
3152
-	else
3337
+	} else
3153 3338
 	{
3154 3339
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3155 3340
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3175,8 +3360,9 @@  discard block
 block discarded – undo
3175 3360
 	$memory_needed = memoryReturnBytes($needed);
3176 3361
 
3177 3362
 	// should we account for how much is currently being used?
3178
-	if ($in_use)
3179
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3363
+	if ($in_use) {
3364
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3365
+	}
3180 3366
 
3181 3367
 	// if more is needed, request it
3182 3368
 	if ($memory_current < $memory_needed)
@@ -3199,8 +3385,9 @@  discard block
 block discarded – undo
3199 3385
  */
3200 3386
 function memoryReturnBytes($val)
3201 3387
 {
3202
-	if (is_integer($val))
3203
-		return $val;
3388
+	if (is_integer($val)) {
3389
+			return $val;
3390
+	}
3204 3391
 
3205 3392
 	// Separate the number from the designator
3206 3393
 	$val = trim($val);
@@ -3236,10 +3423,11 @@  discard block
 block discarded – undo
3236 3423
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3237 3424
 
3238 3425
 		// Are we debugging the template/html content?
3239
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3240
-			header('Content-Type: application/xhtml+xml');
3241
-		elseif (!isset($_REQUEST['xml']))
3242
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3426
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3427
+					header('Content-Type: application/xhtml+xml');
3428
+		} elseif (!isset($_REQUEST['xml'])) {
3429
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3430
+		}
3243 3431
 	}
3244 3432
 
3245 3433
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3248,8 +3436,9 @@  discard block
 block discarded – undo
3248 3436
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3249 3437
 	{
3250 3438
 		$position = array_search('body', $context['template_layers']);
3251
-		if ($position === false)
3252
-			$position = array_search('main', $context['template_layers']);
3439
+		if ($position === false) {
3440
+					$position = array_search('main', $context['template_layers']);
3441
+		}
3253 3442
 
3254 3443
 		if ($position !== false)
3255 3444
 		{
@@ -3277,15 +3466,15 @@  discard block
 block discarded – undo
3277 3466
 
3278 3467
 			foreach ($securityFiles as $i => $securityFile)
3279 3468
 			{
3280
-				if (!file_exists($boarddir . '/' . $securityFile))
3281
-					unset($securityFiles[$i]);
3469
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3470
+									unset($securityFiles[$i]);
3471
+				}
3282 3472
 			}
3283 3473
 
3284 3474
 			// We are already checking so many files...just few more doesn't make any difference! :P
3285
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3286
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3287
-
3288
-			else
3475
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3476
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3477
+			} else
3289 3478
 			{
3290 3479
 				$path = $modSettings['attachmentUploadDir'];
3291 3480
 				$id_folder_thumb = 1;
@@ -3294,8 +3483,9 @@  discard block
 block discarded – undo
3294 3483
 			secureDirectory($cachedir);
3295 3484
 
3296 3485
 			// If agreement is enabled, at least the english version shall exists
3297
-			if ($modSettings['requireAgreement'])
3298
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3486
+			if ($modSettings['requireAgreement']) {
3487
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3488
+			}
3299 3489
 
3300 3490
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3301 3491
 			{
@@ -3310,18 +3500,21 @@  discard block
 block discarded – undo
3310 3500
 					echo '
3311 3501
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3312 3502
 
3313
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3314
-						echo '
3503
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3504
+											echo '
3315 3505
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3506
+					}
3316 3507
 				}
3317 3508
 
3318
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3319
-					echo '
3509
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3510
+									echo '
3320 3511
 				<strong>', $txt['cache_writable'], '</strong><br>';
3512
+				}
3321 3513
 
3322
-				if (!empty($agreement))
3323
-					echo '
3514
+				if (!empty($agreement)) {
3515
+									echo '
3324 3516
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3517
+				}
3325 3518
 
3326 3519
 				echo '
3327 3520
 			</p>
@@ -3336,16 +3529,18 @@  discard block
 block discarded – undo
3336 3529
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3337 3530
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3338 3531
 
3339
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3340
-				echo '
3532
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3533
+							echo '
3341 3534
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3535
+			}
3342 3536
 
3343
-			if (!empty($_SESSION['ban']['expire_time']))
3344
-				echo '
3537
+			if (!empty($_SESSION['ban']['expire_time'])) {
3538
+							echo '
3345 3539
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3346
-			else
3347
-				echo '
3540
+			} else {
3541
+							echo '
3348 3542
 					<div>', $txt['your_ban_expires_never'], '</div>';
3543
+			}
3349 3544
 
3350 3545
 			echo '
3351 3546
 				</div>';
@@ -3361,8 +3556,9 @@  discard block
 block discarded – undo
3361 3556
 	global $forum_copyright, $software_year, $forum_version;
3362 3557
 
3363 3558
 	// Don't display copyright for things like SSI.
3364
-	if (!isset($forum_version) || !isset($software_year))
3365
-		return;
3559
+	if (!isset($forum_version) || !isset($software_year)) {
3560
+			return;
3561
+	}
3366 3562
 
3367 3563
 	// Put in the version...
3368 3564
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3380,9 +3576,10 @@  discard block
 block discarded – undo
3380 3576
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3381 3577
 	$context['load_queries'] = $db_count;
3382 3578
 
3383
-	foreach (array_reverse($context['template_layers']) as $layer)
3384
-		loadSubTemplate($layer . '_below', true);
3385
-}
3579
+	foreach (array_reverse($context['template_layers']) as $layer) {
3580
+			loadSubTemplate($layer . '_below', true);
3581
+	}
3582
+	}
3386 3583
 
3387 3584
 /**
3388 3585
  * Output the Javascript files
@@ -3413,8 +3610,7 @@  discard block
 block discarded – undo
3413 3610
 			{
3414 3611
 				echo '
3415 3612
 		var ', $key, ';';
3416
-			}
3417
-			else
3613
+			} else
3418 3614
 			{
3419 3615
 				echo '
3420 3616
 		var ', $key, ' = ', $value, ';';
@@ -3429,26 +3625,27 @@  discard block
 block discarded – undo
3429 3625
 	foreach ($context['javascript_files'] as $id => $js_file)
3430 3626
 	{
3431 3627
 		// Last minute call! allow theme authors to disable single files.
3432
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3433
-			continue;
3628
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3629
+					continue;
3630
+		}
3434 3631
 
3435 3632
 		// By default all files don't get minimized unless the file explicitly says so!
3436 3633
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3437 3634
 		{
3438
-			if ($do_deferred && !empty($js_file['options']['defer']))
3439
-				$toMinifyDefer[] = $js_file;
3440
-
3441
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3442
-				$toMinify[] = $js_file;
3635
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3636
+							$toMinifyDefer[] = $js_file;
3637
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3638
+							$toMinify[] = $js_file;
3639
+			}
3443 3640
 
3444 3641
 			// Grab a random seed.
3445
-			if (!isset($minSeed))
3446
-				$minSeed = $js_file['options']['seed'];
3447
-		}
3448
-
3449
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3450
-			echo '
3642
+			if (!isset($minSeed)) {
3643
+							$minSeed = $js_file['options']['seed'];
3644
+			}
3645
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3646
+					echo '
3451 3647
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3648
+		}
3452 3649
 	}
3453 3650
 
3454 3651
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3456,14 +3653,14 @@  discard block
 block discarded – undo
3456 3653
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3457 3654
 
3458 3655
 		// Minify process couldn't work, print each individual files.
3459
-		if (!empty($result) && is_array($result))
3460
-			foreach ($result as $minFailedFile)
3656
+		if (!empty($result) && is_array($result)) {
3657
+					foreach ($result as $minFailedFile)
3461 3658
 				echo '
3462 3659
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3463
-
3464
-		else
3465
-			echo '
3660
+		} else {
3661
+					echo '
3466 3662
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3663
+		}
3467 3664
 	}
3468 3665
 
3469 3666
 	// Inline JavaScript - Actually useful some times!
@@ -3474,8 +3671,9 @@  discard block
 block discarded – undo
3474 3671
 			echo '
3475 3672
 <script>';
3476 3673
 
3477
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3478
-				echo $js_code;
3674
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3675
+							echo $js_code;
3676
+			}
3479 3677
 
3480 3678
 			echo '
3481 3679
 </script>';
@@ -3486,8 +3684,9 @@  discard block
 block discarded – undo
3486 3684
 			echo '
3487 3685
 	<script>';
3488 3686
 
3489
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3490
-				echo $js_code;
3687
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3688
+							echo $js_code;
3689
+			}
3491 3690
 
3492 3691
 			echo '
3493 3692
 	</script>';
@@ -3512,8 +3711,9 @@  discard block
 block discarded – undo
3512 3711
 	foreach ($context['css_files'] as $id => $file)
3513 3712
 	{
3514 3713
 		// Last minute call! allow theme authors to disable single files.
3515
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3516
-			continue;
3714
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3715
+					continue;
3716
+		}
3517 3717
 
3518 3718
 		// By default all files don't get minimized unless the file explicitly says so!
3519 3719
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3521,12 +3721,12 @@  discard block
 block discarded – undo
3521 3721
 			$toMinify[] = $file;
3522 3722
 
3523 3723
 			// Grab a random seed.
3524
-			if (!isset($minSeed))
3525
-				$minSeed = $file['options']['seed'];
3724
+			if (!isset($minSeed)) {
3725
+							$minSeed = $file['options']['seed'];
3726
+			}
3727
+		} else {
3728
+					$normal[] = $file['fileUrl'];
3526 3729
 		}
3527
-
3528
-		else
3529
-			$normal[] = $file['fileUrl'];
3530 3730
 	}
3531 3731
 
3532 3732
 	if (!empty($toMinify))
@@ -3534,28 +3734,30 @@  discard block
 block discarded – undo
3534 3734
 		$result = custMinify($toMinify, 'css');
3535 3735
 
3536 3736
 		// Minify process couldn't work, print each individual files.
3537
-		if (!empty($result) && is_array($result))
3538
-			foreach ($result as $minFailedFile)
3737
+		if (!empty($result) && is_array($result)) {
3738
+					foreach ($result as $minFailedFile)
3539 3739
 				echo '
3540 3740
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3541
-
3542
-		else
3543
-			echo '
3741
+		} else {
3742
+					echo '
3544 3743
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3744
+		}
3545 3745
 	}
3546 3746
 
3547 3747
 	// Print the rest after the minified files.
3548
-	if (!empty($normal))
3549
-		foreach ($normal as $nf)
3748
+	if (!empty($normal)) {
3749
+			foreach ($normal as $nf)
3550 3750
 			echo '
3551 3751
 	<link rel="stylesheet" href="', $nf ,'">';
3752
+	}
3552 3753
 
3553 3754
 	if ($db_show_debug === true)
3554 3755
 	{
3555 3756
 		// Try to keep only what's useful.
3556 3757
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3557
-		foreach ($context['css_files'] as $file)
3558
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3758
+		foreach ($context['css_files'] as $file) {
3759
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3760
+		}
3559 3761
 	}
3560 3762
 
3561 3763
 	if (!empty($context['css_header']))
@@ -3563,9 +3765,10 @@  discard block
 block discarded – undo
3563 3765
 		echo '
3564 3766
 	<style>';
3565 3767
 
3566
-		foreach ($context['css_header'] as $css)
3567
-			echo $css .'
3768
+		foreach ($context['css_header'] as $css) {
3769
+					echo $css .'
3568 3770
 	';
3771
+		}
3569 3772
 
3570 3773
 		echo'
3571 3774
 	</style>';
@@ -3590,15 +3793,17 @@  discard block
 block discarded – undo
3590 3793
 	$data = !empty($data) ? $data : false;
3591 3794
 	$minFailed = array();
3592 3795
 
3593
-	if (empty($type) || empty($data))
3594
-		return false;
3796
+	if (empty($type) || empty($data)) {
3797
+			return false;
3798
+	}
3595 3799
 
3596 3800
 	// Did we already did this?
3597 3801
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3598 3802
 
3599 3803
 	// Already done?
3600
-	if (!empty($toCache))
3601
-		return true;
3804
+	if (!empty($toCache)) {
3805
+			return true;
3806
+	}
3602 3807
 
3603 3808
 	// Yep, need a bunch of files.
3604 3809
 	require_once($sourcedir . '/minify/src/Minify.php');
@@ -3686,8 +3891,9 @@  discard block
 block discarded – undo
3686 3891
 	global $modSettings, $smcFunc;
3687 3892
 
3688 3893
 	// Just make up a nice hash...
3689
-	if ($new)
3690
-		return sha1(md5($filename . time()) . mt_rand());
3894
+	if ($new) {
3895
+			return sha1(md5($filename . time()) . mt_rand());
3896
+	}
3691 3897
 
3692 3898
 	// Grab the file hash if it wasn't added.
3693 3899
 	// Left this for legacy.
@@ -3701,23 +3907,25 @@  discard block
 block discarded – undo
3701 3907
 				'id_attach' => $attachment_id,
3702 3908
 			));
3703 3909
 
3704
-		if ($smcFunc['db_num_rows']($request) === 0)
3705
-			return false;
3910
+		if ($smcFunc['db_num_rows']($request) === 0) {
3911
+					return false;
3912
+		}
3706 3913
 
3707 3914
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3708 3915
 		$smcFunc['db_free_result']($request);
3709 3916
 	}
3710 3917
 
3711 3918
 	// Still no hash? mmm...
3712
-	if (empty($file_hash))
3713
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3919
+	if (empty($file_hash)) {
3920
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3921
+	}
3714 3922
 
3715 3923
 	// Are we using multiple directories?
3716
-	if (!empty($modSettings['currentAttachmentUploadDir']))
3717
-		$path = $modSettings['attachmentUploadDir'][$dir];
3718
-
3719
-	else
3720
-		$path = $modSettings['attachmentUploadDir'];
3924
+	if (!empty($modSettings['currentAttachmentUploadDir'])) {
3925
+			$path = $modSettings['attachmentUploadDir'][$dir];
3926
+	} else {
3927
+			$path = $modSettings['attachmentUploadDir'];
3928
+	}
3721 3929
 
3722 3930
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3723 3931
 }
@@ -3732,8 +3940,9 @@  discard block
 block discarded – undo
3732 3940
 function ip2range($fullip)
3733 3941
 {
3734 3942
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3735
-	if ($fullip == 'unknown')
3736
-		$fullip = '255.255.255.255';
3943
+	if ($fullip == 'unknown') {
3944
+			$fullip = '255.255.255.255';
3945
+	}
3737 3946
 
3738 3947
 	$ip_parts = explode('-', $fullip);
3739 3948
 	$ip_array = array();
@@ -3757,10 +3966,11 @@  discard block
 block discarded – undo
3757 3966
 		$ip_array['low'] = $ip_parts[0];
3758 3967
 		$ip_array['high'] = $ip_parts[1];
3759 3968
 		return $ip_array;
3760
-	}
3761
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3969
+	} elseif (count($ip_parts) == 2) {
3970
+		// if ip 22.22.*-22.22.*
3762 3971
 	{
3763 3972
 		$valid_low = isValidIP($ip_parts[0]);
3973
+	}
3764 3974
 		$valid_high = isValidIP($ip_parts[1]);
3765 3975
 		$count = 0;
3766 3976
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3775,7 +3985,9 @@  discard block
 block discarded – undo
3775 3985
 				$ip_parts[0] .= $mode . $min;
3776 3986
 				$valid_low = isValidIP($ip_parts[0]);
3777 3987
 				$count++;
3778
-				if ($count > 9) break;
3988
+				if ($count > 9) {
3989
+					break;
3990
+				}
3779 3991
 			}
3780 3992
 		}
3781 3993
 
@@ -3789,7 +4001,9 @@  discard block
 block discarded – undo
3789 4001
 				$ip_parts[1] .= $mode . $max;
3790 4002
 				$valid_high = isValidIP($ip_parts[1]);
3791 4003
 				$count++;
3792
-				if ($count > 9) break;
4004
+				if ($count > 9) {
4005
+					break;
4006
+				}
3793 4007
 			}
3794 4008
 		}
3795 4009
 
@@ -3814,46 +4028,54 @@  discard block
 block discarded – undo
3814 4028
 {
3815 4029
 	global $modSettings;
3816 4030
 
3817
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3818
-		return $host;
4031
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4032
+			return $host;
4033
+	}
3819 4034
 	$t = microtime();
3820 4035
 
3821 4036
 	// Try the Linux host command, perhaps?
3822 4037
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3823 4038
 	{
3824
-		if (!isset($modSettings['host_to_dis']))
3825
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3826
-		else
3827
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4039
+		if (!isset($modSettings['host_to_dis'])) {
4040
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4041
+		} else {
4042
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4043
+		}
3828 4044
 
3829 4045
 		// Did host say it didn't find anything?
3830
-		if (strpos($test, 'not found') !== false)
3831
-			$host = '';
4046
+		if (strpos($test, 'not found') !== false) {
4047
+					$host = '';
4048
+		}
3832 4049
 		// Invalid server option?
3833
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3834
-			updateSettings(array('host_to_dis' => 1));
4050
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4051
+					updateSettings(array('host_to_dis' => 1));
4052
+		}
3835 4053
 		// Maybe it found something, after all?
3836
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3837
-			$host = $match[1];
4054
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4055
+					$host = $match[1];
4056
+		}
3838 4057
 	}
3839 4058
 
3840 4059
 	// This is nslookup; usually only Windows, but possibly some Unix?
3841 4060
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3842 4061
 	{
3843 4062
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3844
-		if (strpos($test, 'Non-existent domain') !== false)
3845
-			$host = '';
3846
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3847
-			$host = $match[1];
4063
+		if (strpos($test, 'Non-existent domain') !== false) {
4064
+					$host = '';
4065
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4066
+					$host = $match[1];
4067
+		}
3848 4068
 	}
3849 4069
 
3850 4070
 	// This is the last try :/.
3851
-	if (!isset($host) || $host === false)
3852
-		$host = @gethostbyaddr($ip);
4071
+	if (!isset($host) || $host === false) {
4072
+			$host = @gethostbyaddr($ip);
4073
+	}
3853 4074
 
3854 4075
 	// It took a long time, so let's cache it!
3855
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3856
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4076
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4077
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4078
+	}
3857 4079
 
3858 4080
 	return $host;
3859 4081
 }
@@ -3889,20 +4111,21 @@  discard block
 block discarded – undo
3889 4111
 			{
3890 4112
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3891 4113
 				$total = 0;
3892
-				for ($i = 0; $i < $max_chars; $i++)
3893
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4114
+				for ($i = 0; $i < $max_chars; $i++) {
4115
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4116
+				}
3894 4117
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3895 4118
 			}
3896 4119
 		}
3897 4120
 		return array_unique($returned_ints);
3898
-	}
3899
-	else
4121
+	} else
3900 4122
 	{
3901 4123
 		// Trim characters before and after and add slashes for database insertion.
3902 4124
 		$returned_words = array();
3903
-		foreach ($words as $word)
3904
-			if (($word = trim($word, '-_\'')) !== '')
4125
+		foreach ($words as $word) {
4126
+					if (($word = trim($word, '-_\'')) !== '')
3905 4127
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4128
+		}
3906 4129
 
3907 4130
 		// Filter out all words that occur more than once.
3908 4131
 		return array_unique($returned_words);
@@ -3924,16 +4147,18 @@  discard block
 block discarded – undo
3924 4147
 	global $settings, $txt;
3925 4148
 
3926 4149
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3927
-	if (function_exists('template_create_button') && !$force_use)
3928
-		return template_create_button($name, $alt, $label = '', $custom = '');
4150
+	if (function_exists('template_create_button') && !$force_use) {
4151
+			return template_create_button($name, $alt, $label = '', $custom = '');
4152
+	}
3929 4153
 
3930
-	if (!$settings['use_image_buttons'])
3931
-		return $txt[$alt];
3932
-	elseif (!empty($settings['use_buttons']))
3933
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3934
-	else
3935
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3936
-}
4154
+	if (!$settings['use_image_buttons']) {
4155
+			return $txt[$alt];
4156
+	} elseif (!empty($settings['use_buttons'])) {
4157
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4158
+	} else {
4159
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4160
+	}
4161
+	}
3937 4162
 
3938 4163
 /**
3939 4164
  * Empty out the cache in use as best it can
@@ -3957,16 +4182,19 @@  discard block
 block discarded – undo
3957 4182
 			if (function_exists('memcache_flush') || function_exists('memcached_flush') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '')
3958 4183
 			{
3959 4184
 				// Not connected yet?
3960
-				if (empty($memcached))
3961
-					get_memcached_server();
3962
-				if (!$memcached)
3963
-					return;
4185
+				if (empty($memcached)) {
4186
+									get_memcached_server();
4187
+				}
4188
+				if (!$memcached) {
4189
+									return;
4190
+				}
3964 4191
 
3965 4192
 				// clear it out
3966
-				if (function_exists('memcache_flush'))
3967
-					memcache_flush($memcached);
3968
-				else
3969
-					memcached_flush($memcached);
4193
+				if (function_exists('memcache_flush')) {
4194
+									memcache_flush($memcached);
4195
+				} else {
4196
+									memcached_flush($memcached);
4197
+				}
3970 4198
 			}
3971 4199
 			break;
3972 4200
 		case 'apc':
@@ -3977,14 +4205,15 @@  discard block
 block discarded – undo
3977 4205
 				{
3978 4206
 					apc_clear_cache('user');
3979 4207
 					apc_clear_cache('system');
4208
+				} elseif ($type === 'user') {
4209
+									apc_clear_cache('user');
3980 4210
 				}
3981
-				elseif ($type === 'user')
3982
-					apc_clear_cache('user');
3983 4211
 			}
3984 4212
 			break;
3985 4213
 		case 'zend':
3986
-			if (function_exists('zend_shm_cache_clear'))
3987
-				zend_shm_cache_clear('SMF');
4214
+			if (function_exists('zend_shm_cache_clear')) {
4215
+							zend_shm_cache_clear('SMF');
4216
+			}
3988 4217
 			break;
3989 4218
 		case 'xcache':
3990 4219
 			if (function_exists('xcache_clear_cache'))
@@ -3995,23 +4224,27 @@  discard block
 block discarded – undo
3995 4224
 					xcache_clear_cache(XC_TYPE_VAR, 0);
3996 4225
 					xcache_clear_cache(XC_TYPE_PHP, 0);
3997 4226
 				}
3998
-				if ($type === 'user')
3999
-					xcache_clear_cache(XC_TYPE_VAR, 0);
4000
-				if ($type === 'data')
4001
-					xcache_clear_cache(XC_TYPE_PHP, 0);
4227
+				if ($type === 'user') {
4228
+									xcache_clear_cache(XC_TYPE_VAR, 0);
4229
+				}
4230
+				if ($type === 'data') {
4231
+									xcache_clear_cache(XC_TYPE_PHP, 0);
4232
+				}
4002 4233
 			}
4003 4234
 			break;
4004 4235
 		default:
4005 4236
 			// No directory = no game.
4006
-			if (!is_dir($cachedir))
4007
-				return;
4237
+			if (!is_dir($cachedir)) {
4238
+							return;
4239
+			}
4008 4240
 
4009 4241
 			// Remove the files in SMF's own disk cache, if any
4010 4242
 			$dh = opendir($cachedir);
4011 4243
 			while ($file = readdir($dh))
4012 4244
 			{
4013
-				if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
4014
-					@unlink($cachedir . '/' . $file);
4245
+				if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) {
4246
+									@unlink($cachedir . '/' . $file);
4247
+				}
4015 4248
 			}
4016 4249
 			closedir($dh);
4017 4250
 			break;
@@ -4019,8 +4252,9 @@  discard block
 block discarded – undo
4019 4252
 
4020 4253
 	// Invalidate cache, to be sure!
4021 4254
 	// ... as long as index.php can be modified, anyway.
4022
-	if (empty($type))
4023
-		@touch($cachedir . '/' . 'index.php');
4255
+	if (empty($type)) {
4256
+			@touch($cachedir . '/' . 'index.php');
4257
+	}
4024 4258
 
4025 4259
 	call_integration_hook('integrate_clean_cache');
4026 4260
 	clearstatcache();
@@ -4067,9 +4301,10 @@  discard block
 block discarded – undo
4067 4301
 	var user_menus = new smc_PopupMenu();
4068 4302
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4069 4303
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4070
-		if ($context['allow_pm'])
4071
-			addInlineJavaScript('
4304
+		if ($context['allow_pm']) {
4305
+					addInlineJavaScript('
4072 4306
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4307
+		}
4073 4308
 
4074 4309
 		if (!empty($modSettings['enable_ajax_alerts']))
4075 4310
 		{
@@ -4229,88 +4464,96 @@  discard block
 block discarded – undo
4229 4464
 
4230 4465
 		// Now we put the buttons in the context so the theme can use them.
4231 4466
 		$menu_buttons = array();
4232
-		foreach ($buttons as $act => $button)
4233
-			if (!empty($button['show']))
4467
+		foreach ($buttons as $act => $button) {
4468
+					if (!empty($button['show']))
4234 4469
 			{
4235 4470
 				$button['active_button'] = false;
4471
+		}
4236 4472
 
4237 4473
 				// This button needs some action.
4238
-				if (isset($button['action_hook']))
4239
-					$needs_action_hook = true;
4474
+				if (isset($button['action_hook'])) {
4475
+									$needs_action_hook = true;
4476
+				}
4240 4477
 
4241 4478
 				// Make sure the last button truly is the last button.
4242 4479
 				if (!empty($button['is_last']))
4243 4480
 				{
4244
-					if (isset($last_button))
4245
-						unset($menu_buttons[$last_button]['is_last']);
4481
+					if (isset($last_button)) {
4482
+											unset($menu_buttons[$last_button]['is_last']);
4483
+					}
4246 4484
 					$last_button = $act;
4247 4485
 				}
4248 4486
 
4249 4487
 				// Go through the sub buttons if there are any.
4250
-				if (!empty($button['sub_buttons']))
4251
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4488
+				if (!empty($button['sub_buttons'])) {
4489
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4252 4490
 					{
4253 4491
 						if (empty($subbutton['show']))
4254 4492
 							unset($button['sub_buttons'][$key]);
4493
+				}
4255 4494
 
4256 4495
 						// 2nd level sub buttons next...
4257 4496
 						if (!empty($subbutton['sub_buttons']))
4258 4497
 						{
4259 4498
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4260 4499
 							{
4261
-								if (empty($sub_button2['show']))
4262
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4500
+								if (empty($sub_button2['show'])) {
4501
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4502
+								}
4263 4503
 							}
4264 4504
 						}
4265 4505
 					}
4266 4506
 
4267 4507
 				// Does this button have its own icon?
4268
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4269
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4270
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4271
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4272
-				elseif (isset($button['icon']))
4273
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4274
-				else
4275
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4508
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4509
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4510
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4511
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4512
+				} elseif (isset($button['icon'])) {
4513
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4514
+				} else {
4515
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4516
+				}
4276 4517
 
4277 4518
 				$menu_buttons[$act] = $button;
4278 4519
 			}
4279 4520
 
4280
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4281
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4521
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4522
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4523
+		}
4282 4524
 	}
4283 4525
 
4284 4526
 	$context['menu_buttons'] = $menu_buttons;
4285 4527
 
4286 4528
 	// Logging out requires the session id in the url.
4287
-	if (isset($context['menu_buttons']['logout']))
4288
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4529
+	if (isset($context['menu_buttons']['logout'])) {
4530
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4531
+	}
4289 4532
 
4290 4533
 	// Figure out which action we are doing so we can set the active tab.
4291 4534
 	// Default to home.
4292 4535
 	$current_action = 'home';
4293 4536
 
4294
-	if (isset($context['menu_buttons'][$context['current_action']]))
4295
-		$current_action = $context['current_action'];
4296
-	elseif ($context['current_action'] == 'search2')
4297
-		$current_action = 'search';
4298
-	elseif ($context['current_action'] == 'theme')
4299
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4300
-	elseif ($context['current_action'] == 'register2')
4301
-		$current_action = 'register';
4302
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4303
-		$current_action = 'login';
4304
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4305
-		$current_action = 'moderate';
4537
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4538
+			$current_action = $context['current_action'];
4539
+	} elseif ($context['current_action'] == 'search2') {
4540
+			$current_action = 'search';
4541
+	} elseif ($context['current_action'] == 'theme') {
4542
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4543
+	} elseif ($context['current_action'] == 'register2') {
4544
+			$current_action = 'register';
4545
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4546
+			$current_action = 'login';
4547
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4548
+			$current_action = 'moderate';
4549
+	}
4306 4550
 
4307 4551
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4308 4552
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4309 4553
 	{
4310 4554
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4311 4555
 		$context[$current_action] = true;
4312
-	}
4313
-	elseif ($context['current_action'] == 'pm')
4556
+	} elseif ($context['current_action'] == 'pm')
4314 4557
 	{
4315 4558
 		$current_action = 'self_pm';
4316 4559
 		$context['self_pm'] = true;
@@ -4353,12 +4596,14 @@  discard block
 block discarded – undo
4353 4596
 	}
4354 4597
 
4355 4598
 	// Not all actions are simple.
4356
-	if (!empty($needs_action_hook))
4357
-		call_integration_hook('integrate_current_action', array(&$current_action));
4599
+	if (!empty($needs_action_hook)) {
4600
+			call_integration_hook('integrate_current_action', array(&$current_action));
4601
+	}
4358 4602
 
4359
-	if (isset($context['menu_buttons'][$current_action]))
4360
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4361
-}
4603
+	if (isset($context['menu_buttons'][$current_action])) {
4604
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4605
+	}
4606
+	}
4362 4607
 
4363 4608
 /**
4364 4609
  * Generate a random seed and ensure it's stored in settings.
@@ -4382,16 +4627,19 @@  discard block
 block discarded – undo
4382 4627
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4383 4628
 	global $context, $txt;
4384 4629
 
4385
-	if ($db_show_debug === true)
4386
-		$context['debug']['hooks'][] = $hook;
4630
+	if ($db_show_debug === true) {
4631
+			$context['debug']['hooks'][] = $hook;
4632
+	}
4387 4633
 
4388 4634
 	// Need to have some control.
4389
-	if (!isset($context['instances']))
4390
-		$context['instances'] = array();
4635
+	if (!isset($context['instances'])) {
4636
+			$context['instances'] = array();
4637
+	}
4391 4638
 
4392 4639
 	$results = array();
4393
-	if (empty($modSettings[$hook]))
4394
-		return $results;
4640
+	if (empty($modSettings[$hook])) {
4641
+			return $results;
4642
+	}
4395 4643
 
4396 4644
 	// Define some needed vars.
4397 4645
 	$function = false;
@@ -4401,14 +4649,16 @@  discard block
 block discarded – undo
4401 4649
 	foreach ($functions as $function)
4402 4650
 	{
4403 4651
 		// Hook has been marked as "disabled". Skip it!
4404
-		if (strpos($function, '!') !== false)
4405
-			continue;
4652
+		if (strpos($function, '!') !== false) {
4653
+					continue;
4654
+		}
4406 4655
 
4407 4656
 		$call = call_helper($function, true);
4408 4657
 
4409 4658
 		// Is it valid?
4410
-		if (!empty($call))
4411
-			$results[$function] = call_user_func_array($call, $parameters);
4659
+		if (!empty($call)) {
4660
+					$results[$function] = call_user_func_array($call, $parameters);
4661
+		}
4412 4662
 
4413 4663
 		// Whatever it was suppose to call, it failed :(
4414 4664
 		elseif (!empty($function))
@@ -4424,8 +4674,9 @@  discard block
 block discarded – undo
4424 4674
 			}
4425 4675
 
4426 4676
 			// "Assume" the file resides on $boarddir somewhere...
4427
-			else
4428
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4677
+			else {
4678
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4679
+			}
4429 4680
 		}
4430 4681
 	}
4431 4682
 
@@ -4447,12 +4698,14 @@  discard block
 block discarded – undo
4447 4698
 	global $smcFunc, $modSettings;
4448 4699
 
4449 4700
 	// Any objects?
4450
-	if ($object)
4451
-		$function = $function . '#';
4701
+	if ($object) {
4702
+			$function = $function . '#';
4703
+	}
4452 4704
 
4453 4705
 	// Any files  to load?
4454
-	if (!empty($file) && is_string($file))
4455
-		$function = $file . (!empty($function) ? '|' . $function : '');
4706
+	if (!empty($file) && is_string($file)) {
4707
+			$function = $file . (!empty($function) ? '|' . $function : '');
4708
+	}
4456 4709
 
4457 4710
 	// Get the correct string.
4458 4711
 	$integration_call = $function;
@@ -4474,13 +4727,14 @@  discard block
 block discarded – undo
4474 4727
 		if (!empty($current_functions))
4475 4728
 		{
4476 4729
 			$current_functions = explode(',', $current_functions);
4477
-			if (in_array($integration_call, $current_functions))
4478
-				return;
4730
+			if (in_array($integration_call, $current_functions)) {
4731
+							return;
4732
+			}
4479 4733
 
4480 4734
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4735
+		} else {
4736
+					$permanent_functions = array($integration_call);
4481 4737
 		}
4482
-		else
4483
-			$permanent_functions = array($integration_call);
4484 4738
 
4485 4739
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4486 4740
 	}
@@ -4489,8 +4743,9 @@  discard block
 block discarded – undo
4489 4743
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4490 4744
 
4491 4745
 	// Do nothing, if it's already there.
4492
-	if (in_array($integration_call, $functions))
4493
-		return;
4746
+	if (in_array($integration_call, $functions)) {
4747
+			return;
4748
+	}
4494 4749
 
4495 4750
 	$functions[] = $integration_call;
4496 4751
 	$modSettings[$hook] = implode(',', $functions);
@@ -4513,12 +4768,14 @@  discard block
 block discarded – undo
4513 4768
 	global $smcFunc, $modSettings;
4514 4769
 
4515 4770
 	// Any objects?
4516
-	if ($object)
4517
-		$function = $function . '#';
4771
+	if ($object) {
4772
+			$function = $function . '#';
4773
+	}
4518 4774
 
4519 4775
 	// Any files  to load?
4520
-	if (!empty($file) && is_string($file))
4521
-		$function = $file . '|' . $function;
4776
+	if (!empty($file) && is_string($file)) {
4777
+			$function = $file . '|' . $function;
4778
+	}
4522 4779
 
4523 4780
 	// Get the correct string.
4524 4781
 	$integration_call = $function;
@@ -4539,16 +4796,18 @@  discard block
 block discarded – undo
4539 4796
 	{
4540 4797
 		$current_functions = explode(',', $current_functions);
4541 4798
 
4542
-		if (in_array($integration_call, $current_functions))
4543
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4799
+		if (in_array($integration_call, $current_functions)) {
4800
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4801
+		}
4544 4802
 	}
4545 4803
 
4546 4804
 	// Turn the function list into something usable.
4547 4805
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4548 4806
 
4549 4807
 	// You can only remove it if it's available.
4550
-	if (!in_array($integration_call, $functions))
4551
-		return;
4808
+	if (!in_array($integration_call, $functions)) {
4809
+			return;
4810
+	}
4552 4811
 
4553 4812
 	$functions = array_diff($functions, array($integration_call));
4554 4813
 	$modSettings[$hook] = implode(',', $functions);
@@ -4569,17 +4828,20 @@  discard block
 block discarded – undo
4569 4828
 	global $context, $smcFunc, $txt, $db_show_debug;
4570 4829
 
4571 4830
 	// Really?
4572
-	if (empty($string))
4573
-		return false;
4831
+	if (empty($string)) {
4832
+			return false;
4833
+	}
4574 4834
 
4575 4835
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4576 4836
 	// A closure? should be a callable one.
4577
-	if (is_array($string) || $string instanceof Closure)
4578
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4837
+	if (is_array($string) || $string instanceof Closure) {
4838
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4839
+	}
4579 4840
 
4580 4841
 	// No full objects, sorry! pass a method or a property instead!
4581
-	if (is_object($string))
4582
-		return false;
4842
+	if (is_object($string)) {
4843
+			return false;
4844
+	}
4583 4845
 
4584 4846
 	// Stay vitaminized my friends...
4585 4847
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4591,8 +4853,9 @@  discard block
 block discarded – undo
4591 4853
 	$string = load_file($string);
4592 4854
 
4593 4855
 	// Loaded file failed
4594
-	if (empty($string))
4595
-		return false;
4856
+	if (empty($string)) {
4857
+			return false;
4858
+	}
4596 4859
 
4597 4860
 	// Found a method.
4598 4861
 	if (strpos($string, '::') !== false)
@@ -4613,8 +4876,9 @@  discard block
 block discarded – undo
4613 4876
 				// Add another one to the list.
4614 4877
 				if ($db_show_debug === true)
4615 4878
 				{
4616
-					if (!isset($context['debug']['instances']))
4617
-						$context['debug']['instances'] = array();
4879
+					if (!isset($context['debug']['instances'])) {
4880
+											$context['debug']['instances'] = array();
4881
+					}
4618 4882
 
4619 4883
 					$context['debug']['instances'][$class] = $class;
4620 4884
 				}
@@ -4624,13 +4888,15 @@  discard block
 block discarded – undo
4624 4888
 		}
4625 4889
 
4626 4890
 		// Right then. This is a call to a static method.
4627
-		else
4628
-			$func = array($class, $method);
4891
+		else {
4892
+					$func = array($class, $method);
4893
+		}
4629 4894
 	}
4630 4895
 
4631 4896
 	// Nope! just a plain regular function.
4632
-	else
4633
-		$func = $string;
4897
+	else {
4898
+			$func = $string;
4899
+	}
4634 4900
 
4635 4901
 	// Right, we got what we need, time to do some checks.
4636 4902
 	if (!is_callable($func, false, $callable_name))
@@ -4646,17 +4912,18 @@  discard block
 block discarded – undo
4646 4912
 	else
4647 4913
 	{
4648 4914
 		// What are we gonna do about it?
4649
-		if ($return)
4650
-			return $func;
4915
+		if ($return) {
4916
+					return $func;
4917
+		}
4651 4918
 
4652 4919
 		// If this is a plain function, avoid the heat of calling call_user_func().
4653 4920
 		else
4654 4921
 		{
4655
-			if (is_array($func))
4656
-				call_user_func($func);
4657
-
4658
-			else
4659
-				$func();
4922
+			if (is_array($func)) {
4923
+							call_user_func($func);
4924
+			} else {
4925
+							$func();
4926
+			}
4660 4927
 		}
4661 4928
 	}
4662 4929
 }
@@ -4673,31 +4940,34 @@  discard block
 block discarded – undo
4673 4940
 {
4674 4941
 	global $sourcedir, $txt, $boarddir, $settings;
4675 4942
 
4676
-	if (empty($string))
4677
-		return false;
4943
+	if (empty($string)) {
4944
+			return false;
4945
+	}
4678 4946
 
4679 4947
 	if (strpos($string, '|') !== false)
4680 4948
 	{
4681 4949
 		list ($file, $string) = explode('|', $string);
4682 4950
 
4683 4951
 		// Match the wildcards to their regular vars.
4684
-		if (empty($settings['theme_dir']))
4685
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4686
-
4687
-		else
4688
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4952
+		if (empty($settings['theme_dir'])) {
4953
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4954
+		} else {
4955
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4956
+		}
4689 4957
 
4690 4958
 		// Load the file if it can be loaded.
4691
-		if (file_exists($absPath))
4692
-			require_once($absPath);
4959
+		if (file_exists($absPath)) {
4960
+					require_once($absPath);
4961
+		}
4693 4962
 
4694 4963
 		// No? try a fallback to $sourcedir
4695 4964
 		else
4696 4965
 		{
4697 4966
 			$absPath = $sourcedir .'/'. $file;
4698 4967
 
4699
-			if (file_exists($absPath))
4700
-				require_once($absPath);
4968
+			if (file_exists($absPath)) {
4969
+							require_once($absPath);
4970
+			}
4701 4971
 
4702 4972
 			// Sorry, can't do much for you at this point.
4703 4973
 			else
@@ -4724,8 +4994,9 @@  discard block
 block discarded – undo
4724 4994
 	global $user_info, $smcFunc;
4725 4995
 
4726 4996
 	// Make sure we have something to work with.
4727
-	if (empty($topic))
4728
-		return array();
4997
+	if (empty($topic)) {
4998
+			return array();
4999
+	}
4729 5000
 
4730 5001
 
4731 5002
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4748,8 +5019,9 @@  discard block
 block discarded – undo
4748 5019
 				'topic' => $topic,
4749 5020
 			)
4750 5021
 		);
4751
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4752
-			$temp[] = (int) $row['content_id'];
5022
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5023
+					$temp[] = (int) $row['content_id'];
5024
+		}
4753 5025
 
4754 5026
 		cache_put_data($cache_key, $temp, $ttl);
4755 5027
 	}
@@ -4770,8 +5042,9 @@  discard block
 block discarded – undo
4770 5042
 {
4771 5043
 	global $context;
4772 5044
 
4773
-	if (empty($string))
4774
-		return $string;
5045
+	if (empty($string)) {
5046
+			return $string;
5047
+	}
4775 5048
 
4776 5049
 	// UTF-8 occurences of MS special characters
4777 5050
 	$findchars_utf8 = array(
@@ -4812,10 +5085,11 @@  discard block
 block discarded – undo
4812 5085
 		'--',	// &mdash;
4813 5086
 	);
4814 5087
 
4815
-	if ($context['utf8'])
4816
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4817
-	else
4818
-		$string = str_replace($findchars_iso, $replacechars, $string);
5088
+	if ($context['utf8']) {
5089
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5090
+	} else {
5091
+			$string = str_replace($findchars_iso, $replacechars, $string);
5092
+	}
4819 5093
 
4820 5094
 	return $string;
4821 5095
 }
@@ -4834,49 +5108,59 @@  discard block
 block discarded – undo
4834 5108
 {
4835 5109
 	global $context;
4836 5110
 
4837
-	if (!isset($matches[2]))
4838
-		return '';
5111
+	if (!isset($matches[2])) {
5112
+			return '';
5113
+	}
4839 5114
 
4840 5115
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4841 5116
 
4842 5117
 	// remove left to right / right to left overrides
4843
-	if ($num === 0x202D || $num === 0x202E)
4844
-		return '';
5118
+	if ($num === 0x202D || $num === 0x202E) {
5119
+			return '';
5120
+	}
4845 5121
 
4846 5122
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4847
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4848
-		return '&#' . $num . ';';
5123
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5124
+			return '&#' . $num . ';';
5125
+	}
4849 5126
 
4850 5127
 	if (empty($context['utf8']))
4851 5128
 	{
4852 5129
 		// no control characters
4853
-		if ($num < 0x20)
4854
-			return '';
5130
+		if ($num < 0x20) {
5131
+					return '';
5132
+		}
4855 5133
 		// text is text
4856
-		elseif ($num < 0x80)
4857
-			return chr($num);
5134
+		elseif ($num < 0x80) {
5135
+					return chr($num);
5136
+		}
4858 5137
 		// all others get html-ised
4859
-		else
4860
-			return '&#' . $matches[2] . ';';
4861
-	}
4862
-	else
5138
+		else {
5139
+					return '&#' . $matches[2] . ';';
5140
+		}
5141
+	} else
4863 5142
 	{
4864 5143
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4865 5144
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4866
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4867
-			return '';
5145
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5146
+					return '';
5147
+		}
4868 5148
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4869
-		elseif ($num < 0x80)
4870
-			return chr($num);
5149
+		elseif ($num < 0x80) {
5150
+					return chr($num);
5151
+		}
4871 5152
 		// <0x800 (2048)
4872
-		elseif ($num < 0x800)
4873
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5153
+		elseif ($num < 0x800) {
5154
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5155
+		}
4874 5156
 		// < 0x10000 (65536)
4875
-		elseif ($num < 0x10000)
4876
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5157
+		elseif ($num < 0x10000) {
5158
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5159
+		}
4877 5160
 		// <= 0x10FFFF (1114111)
4878
-		else
4879
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5161
+		else {
5162
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5163
+		}
4880 5164
 	}
4881 5165
 }
4882 5166
 
@@ -4892,28 +5176,34 @@  discard block
 block discarded – undo
4892 5176
  */
4893 5177
 function fixchar__callback($matches)
4894 5178
 {
4895
-	if (!isset($matches[1]))
4896
-		return '';
5179
+	if (!isset($matches[1])) {
5180
+			return '';
5181
+	}
4897 5182
 
4898 5183
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4899 5184
 
4900 5185
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4901 5186
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4902
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4903
-		return '';
5187
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5188
+			return '';
5189
+	}
4904 5190
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4905
-	elseif ($num < 0x80)
4906
-		return chr($num);
5191
+	elseif ($num < 0x80) {
5192
+			return chr($num);
5193
+	}
4907 5194
 	// <0x800 (2048)
4908
-	elseif ($num < 0x800)
4909
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5195
+	elseif ($num < 0x800) {
5196
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5197
+	}
4910 5198
 	// < 0x10000 (65536)
4911
-	elseif ($num < 0x10000)
4912
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5199
+	elseif ($num < 0x10000) {
5200
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5201
+	}
4913 5202
 	// <= 0x10FFFF (1114111)
4914
-	else
4915
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4916
-}
5203
+	else {
5204
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5205
+	}
5206
+	}
4917 5207
 
4918 5208
 /**
4919 5209
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4926,17 +5216,19 @@  discard block
 block discarded – undo
4926 5216
  */
4927 5217
 function entity_fix__callback($matches)
4928 5218
 {
4929
-	if (!isset($matches[2]))
4930
-		return '';
5219
+	if (!isset($matches[2])) {
5220
+			return '';
5221
+	}
4931 5222
 
4932 5223
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4933 5224
 
4934 5225
 	// we don't allow control characters, characters out of range, byte markers, etc
4935
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4936
-		return '';
4937
-	else
4938
-		return '&#' . $num . ';';
4939
-}
5226
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5227
+			return '';
5228
+	} else {
5229
+			return '&#' . $num . ';';
5230
+	}
5231
+	}
4940 5232
 
4941 5233
 /**
4942 5234
  * Return a Gravatar URL based on
@@ -4960,18 +5252,23 @@  discard block
 block discarded – undo
4960 5252
 		$ratings = array('G', 'PG', 'R', 'X');
4961 5253
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4962 5254
 		$url_params = array();
4963
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4964
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4965
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4966
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4967
-		if (!empty($modSettings['avatar_max_width_external']))
4968
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4969
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4970
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5255
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5256
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5257
+		}
5258
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5259
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5260
+		}
5261
+		if (!empty($modSettings['avatar_max_width_external'])) {
5262
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5263
+		}
5264
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5265
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4971 5266
 				$size_string = $modSettings['avatar_max_height_external'];
5267
+		}
4972 5268
 
4973
-		if (!empty($size_string))
4974
-			$url_params[] = 's=' . $size_string;
5269
+		if (!empty($size_string)) {
5270
+					$url_params[] = 's=' . $size_string;
5271
+		}
4975 5272
 	}
4976 5273
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4977 5274
 
@@ -5082,8 +5379,9 @@  discard block
 block discarded – undo
5082 5379
  */
5083 5380
 function inet_ptod($ip_address)
5084 5381
 {
5085
-	if (!isValidIP($ip_address))
5086
-		return $ip_address;
5382
+	if (!isValidIP($ip_address)) {
5383
+			return $ip_address;
5384
+	}
5087 5385
 
5088 5386
 	$bin = inet_pton($ip_address);
5089 5387
 	return $bin;
@@ -5095,13 +5393,15 @@  discard block
 block discarded – undo
5095 5393
  */
5096 5394
 function inet_dtop($bin)
5097 5395
 {
5098
-	if(empty($bin))
5099
-		return '';
5396
+	if(empty($bin)) {
5397
+			return '';
5398
+	}
5100 5399
 
5101 5400
 	global $db_type;
5102 5401
 
5103
-	if ($db_type == 'postgresql')
5104
-		return $bin;
5402
+	if ($db_type == 'postgresql') {
5403
+			return $bin;
5404
+	}
5105 5405
 
5106 5406
 	$ip_address = inet_ntop($bin);
5107 5407
 
@@ -5126,26 +5426,32 @@  discard block
 block discarded – undo
5126 5426
  */
5127 5427
 function _safe_serialize($value)
5128 5428
 {
5129
-	if(is_null($value))
5130
-		return 'N;';
5429
+	if(is_null($value)) {
5430
+			return 'N;';
5431
+	}
5131 5432
 
5132
-	if(is_bool($value))
5133
-		return 'b:'. (int) $value .';';
5433
+	if(is_bool($value)) {
5434
+			return 'b:'. (int) $value .';';
5435
+	}
5134 5436
 
5135
-	if(is_int($value))
5136
-		return 'i:'. $value .';';
5437
+	if(is_int($value)) {
5438
+			return 'i:'. $value .';';
5439
+	}
5137 5440
 
5138
-	if(is_float($value))
5139
-		return 'd:'. str_replace(',', '.', $value) .';';
5441
+	if(is_float($value)) {
5442
+			return 'd:'. str_replace(',', '.', $value) .';';
5443
+	}
5140 5444
 
5141
-	if(is_string($value))
5142
-		return 's:'. strlen($value) .':"'. $value .'";';
5445
+	if(is_string($value)) {
5446
+			return 's:'. strlen($value) .':"'. $value .'";';
5447
+	}
5143 5448
 
5144 5449
 	if(is_array($value))
5145 5450
 	{
5146 5451
 		$out = '';
5147
-		foreach($value as $k => $v)
5148
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5452
+		foreach($value as $k => $v) {
5453
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5454
+		}
5149 5455
 
5150 5456
 		return 'a:'. count($value) .':{'. $out .'}';
5151 5457
 	}
@@ -5171,8 +5477,9 @@  discard block
 block discarded – undo
5171 5477
 
5172 5478
 	$out = _safe_serialize($value);
5173 5479
 
5174
-	if (isset($mbIntEnc))
5175
-		mb_internal_encoding($mbIntEnc);
5480
+	if (isset($mbIntEnc)) {
5481
+			mb_internal_encoding($mbIntEnc);
5482
+	}
5176 5483
 
5177 5484
 	return $out;
5178 5485
 }
@@ -5189,8 +5496,9 @@  discard block
 block discarded – undo
5189 5496
 function _safe_unserialize($str)
5190 5497
 {
5191 5498
 	// Input  is not a string.
5192
-	if(empty($str) || !is_string($str))
5193
-		return false;
5499
+	if(empty($str) || !is_string($str)) {
5500
+			return false;
5501
+	}
5194 5502
 
5195 5503
 	$stack = array();
5196 5504
 	$expected = array();
@@ -5206,43 +5514,38 @@  discard block
 block discarded – undo
5206 5514
 	while($state != 1)
5207 5515
 	{
5208 5516
 		$type = isset($str[0]) ? $str[0] : '';
5209
-		if($type == '}')
5210
-			$str = substr($str, 1);
5211
-
5212
-		else if($type == 'N' && $str[1] == ';')
5517
+		if($type == '}') {
5518
+					$str = substr($str, 1);
5519
+		} else if($type == 'N' && $str[1] == ';')
5213 5520
 		{
5214 5521
 			$value = null;
5215 5522
 			$str = substr($str, 2);
5216
-		}
5217
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5523
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5218 5524
 		{
5219 5525
 			$value = $matches[1] == '1' ? true : false;
5220 5526
 			$str = substr($str, 4);
5221
-		}
5222
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5527
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5223 5528
 		{
5224 5529
 			$value = (int)$matches[1];
5225 5530
 			$str = $matches[2];
5226
-		}
5227
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5531
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5228 5532
 		{
5229 5533
 			$value = (float)$matches[1];
5230 5534
 			$str = $matches[3];
5231
-		}
5232
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5535
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5233 5536
 		{
5234 5537
 			$value = substr($matches[2], 0, (int)$matches[1]);
5235 5538
 			$str = substr($matches[2], (int)$matches[1] + 2);
5236
-		}
5237
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5539
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5238 5540
 		{
5239 5541
 			$expectedLength = (int)$matches[1];
5240 5542
 			$str = $matches[2];
5241 5543
 		}
5242 5544
 
5243 5545
 		// Object or unknown/malformed type.
5244
-		else
5245
-			return false;
5546
+		else {
5547
+					return false;
5548
+		}
5246 5549
 
5247 5550
 		switch($state)
5248 5551
 		{
@@ -5270,8 +5573,9 @@  discard block
 block discarded – undo
5270 5573
 				if($type == '}')
5271 5574
 				{
5272 5575
 					// Array size is less than expected.
5273
-					if(count($list) < end($expected))
5274
-						return false;
5576
+					if(count($list) < end($expected)) {
5577
+											return false;
5578
+					}
5275 5579
 
5276 5580
 					unset($list);
5277 5581
 					$list = &$stack[count($stack)-1];
@@ -5280,8 +5584,9 @@  discard block
 block discarded – undo
5280 5584
 					// Go to terminal state if we're at the end of the root array.
5281 5585
 					array_pop($expected);
5282 5586
 
5283
-					if(count($expected) == 0)
5284
-						$state = 1;
5587
+					if(count($expected) == 0) {
5588
+											$state = 1;
5589
+					}
5285 5590
 
5286 5591
 					break;
5287 5592
 				}
@@ -5289,8 +5594,9 @@  discard block
 block discarded – undo
5289 5594
 				if($type == 'i' || $type == 's')
5290 5595
 				{
5291 5596
 					// Array size exceeds expected length.
5292
-					if(count($list) >= end($expected))
5293
-						return false;
5597
+					if(count($list) >= end($expected)) {
5598
+											return false;
5599
+					}
5294 5600
 
5295 5601
 					$key = $value;
5296 5602
 					$state = 3;
@@ -5324,8 +5630,9 @@  discard block
 block discarded – undo
5324 5630
 	}
5325 5631
 
5326 5632
 	// Trailing data in input.
5327
-	if(!empty($str))
5328
-		return false;
5633
+	if(!empty($str)) {
5634
+			return false;
5635
+	}
5329 5636
 
5330 5637
 	return $data;
5331 5638
 }
@@ -5348,8 +5655,9 @@  discard block
 block discarded – undo
5348 5655
 
5349 5656
 	$out = _safe_unserialize($str);
5350 5657
 
5351
-	if (isset($mbIntEnc))
5352
-		mb_internal_encoding($mbIntEnc);
5658
+	if (isset($mbIntEnc)) {
5659
+			mb_internal_encoding($mbIntEnc);
5660
+	}
5353 5661
 
5354 5662
 	return $out;
5355 5663
 }
@@ -5364,12 +5672,14 @@  discard block
 block discarded – undo
5364 5672
 function smf_chmod($file, $value = 0)
5365 5673
 {
5366 5674
 	// No file? no checks!
5367
-	if (empty($file))
5368
-		return false;
5675
+	if (empty($file)) {
5676
+			return false;
5677
+	}
5369 5678
 
5370 5679
 	// Already writable?
5371
-	if (is_writable($file))
5372
-		return true;
5680
+	if (is_writable($file)) {
5681
+			return true;
5682
+	}
5373 5683
 
5374 5684
 	// Do we have a file or a dir?
5375 5685
 	$isDir = is_dir($file);
@@ -5385,10 +5695,9 @@  discard block
 block discarded – undo
5385 5695
 		{
5386 5696
 			$isWritable = true;
5387 5697
 			break;
5698
+		} else {
5699
+					@chmod($file, $val);
5388 5700
 		}
5389
-
5390
-		else
5391
-			@chmod($file, $val);
5392 5701
 	}
5393 5702
 
5394 5703
 	return $isWritable;
@@ -5407,8 +5716,9 @@  discard block
 block discarded – undo
5407 5716
 	global $txt;
5408 5717
 
5409 5718
 	// Come on...
5410
-	if (empty($json) || !is_string($json))
5411
-		return array();
5719
+	if (empty($json) || !is_string($json)) {
5720
+			return array();
5721
+	}
5412 5722
 
5413 5723
 	$returnArray = array();
5414 5724
 	$jsonError = false;
@@ -5449,11 +5759,11 @@  discard block
 block discarded – undo
5449 5759
 		$jsonDebug = $jsonDebug[0];
5450 5760
 		loadLanguage('Errors');
5451 5761
 
5452
-		if (!empty($jsonDebug))
5453
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5454
-
5455
-		else
5456
-			log_error($txt['json_'. $jsonError], 'critical');
5762
+		if (!empty($jsonDebug)) {
5763
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5764
+		} else {
5765
+					log_error($txt['json_'. $jsonError], 'critical');
5766
+		}
5457 5767
 
5458 5768
 		// Everyone expects an array.
5459 5769
 		return array();
@@ -5483,8 +5793,9 @@  discard block
 block discarded – undo
5483 5793
 	global $db_show_debug, $modSettings;
5484 5794
 
5485 5795
 	// Defensive programming anyone?
5486
-	if (empty($data))
5487
-		return false;
5796
+	if (empty($data)) {
5797
+			return false;
5798
+	}
5488 5799
 
5489 5800
 	// Don't need extra stuff...
5490 5801
 	$db_show_debug = false;
@@ -5492,11 +5803,11 @@  discard block
 block discarded – undo
5492 5803
 	// Kill anything else.
5493 5804
 	ob_end_clean();
5494 5805
 
5495
-	if (!empty($modSettings['CompressedOutput']))
5496
-		@ob_start('ob_gzhandler');
5497
-
5498
-	else
5499
-		ob_start();
5806
+	if (!empty($modSettings['CompressedOutput'])) {
5807
+			@ob_start('ob_gzhandler');
5808
+	} else {
5809
+			ob_start();
5810
+	}
5500 5811
 
5501 5812
 	// Set the header.
5502 5813
 	header($type);
@@ -5528,8 +5839,9 @@  discard block
 block discarded – undo
5528 5839
 	static $done = false;
5529 5840
 
5530 5841
 	// If we don't need to do anything, don't
5531
-	if (!$update && $done)
5532
-		return;
5842
+	if (!$update && $done) {
5843
+			return;
5844
+	}
5533 5845
 
5534 5846
 	// Should we get a new copy of the official list of TLDs?
5535 5847
 	if ($update)
@@ -5550,10 +5862,11 @@  discard block
 block discarded – undo
5550 5862
 		// Clean $tlds and convert it to an array
5551 5863
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5552 5864
 			$line = trim($line);
5553
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5554
-				return false;
5555
-			else
5556
-				return true;
5865
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5866
+							return false;
5867
+			} else {
5868
+							return true;
5869
+			}
5557 5870
 		});
5558 5871
 
5559 5872
 		// Convert Punycode to Unicode
@@ -5607,8 +5920,9 @@  discard block
 block discarded – undo
5607 5920
 						$idx += $digit * $w;
5608 5921
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5609 5922
 
5610
-						if ($digit < $t)
5611
-							break;
5923
+						if ($digit < $t) {
5924
+													break;
5925
+						}
5612 5926
 
5613 5927
 						$w = (int) ($w * ($base - $t));
5614 5928
 					}
@@ -5617,8 +5931,9 @@  discard block
 block discarded – undo
5617 5931
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5618 5932
 					$delta += intval($delta / ($deco_len + 1));
5619 5933
 
5620
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5621
-						$delta = intval($delta / ($base - $tmin));
5934
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5935
+											$delta = intval($delta / ($base - $tmin));
5936
+					}
5622 5937
 
5623 5938
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5624 5939
 					$is_first = false;
@@ -5627,8 +5942,9 @@  discard block
 block discarded – undo
5627 5942
 
5628 5943
 					if ($deco_len > 0)
5629 5944
 					{
5630
-						for ($i = $deco_len; $i > $idx; $i--)
5631
-							$decoded[$i] = $decoded[($i - 1)];
5945
+						for ($i = $deco_len; $i > $idx; $i--) {
5946
+													$decoded[$i] = $decoded[($i - 1)];
5947
+						}
5632 5948
 					}
5633 5949
 					$decoded[$idx++] = $char;
5634 5950
 				}
@@ -5636,24 +5952,29 @@  discard block
 block discarded – undo
5636 5952
 				foreach ($decoded as $k => $v)
5637 5953
 				{
5638 5954
 					// 7bit are transferred literally
5639
-					if ($v < 128)
5640
-						$output .= chr($v);
5955
+					if ($v < 128) {
5956
+											$output .= chr($v);
5957
+					}
5641 5958
 
5642 5959
 					// 2 bytes
5643
-					elseif ($v < (1 << 11))
5644
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5960
+					elseif ($v < (1 << 11)) {
5961
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5962
+					}
5645 5963
 
5646 5964
 					// 3 bytes
5647
-					elseif ($v < (1 << 16))
5648
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5965
+					elseif ($v < (1 << 16)) {
5966
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5967
+					}
5649 5968
 
5650 5969
 					// 4 bytes
5651
-					elseif ($v < (1 << 21))
5652
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5970
+					elseif ($v < (1 << 21)) {
5971
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5972
+					}
5653 5973
 
5654 5974
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5655
-					else
5656
-						$output .= $safe_char;
5975
+					else {
5976
+											$output .= $safe_char;
5977
+					}
5657 5978
 				}
5658 5979
 
5659 5980
 				$output_parts[] = $output;
@@ -5748,8 +6069,7 @@  discard block
 block discarded – undo
5748 6069
 
5749 6070
 		$strlen = 'mb_strlen';
5750 6071
 		$substr = 'mb_substr';
5751
-	}
5752
-	else
6072
+	} else
5753 6073
 	{
5754 6074
 		$strlen = $smcFunc['strlen'];
5755 6075
 		$substr = $smcFunc['substr'];
@@ -5763,20 +6083,21 @@  discard block
 block discarded – undo
5763 6083
 
5764 6084
 		$first = $substr($string, 0, 1);
5765 6085
 
5766
-		if (empty($index[$first]))
5767
-			$index[$first] = array();
6086
+		if (empty($index[$first])) {
6087
+					$index[$first] = array();
6088
+		}
5768 6089
 
5769 6090
 		if ($strlen($string) > 1)
5770 6091
 		{
5771 6092
 			// Sanity check on recursion
5772
-			if ($depth > 99)
5773
-				$index[$first][$substr($string, 1)] = '';
5774
-
5775
-			else
5776
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6093
+			if ($depth > 99) {
6094
+							$index[$first][$substr($string, 1)] = '';
6095
+			} else {
6096
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6097
+			}
6098
+		} else {
6099
+					$index[$first][''] = '';
5777 6100
 		}
5778
-		else
5779
-			$index[$first][''] = '';
5780 6101
 
5781 6102
 		$depth--;
5782 6103
 		return $index;
@@ -5799,29 +6120,30 @@  discard block
 block discarded – undo
5799 6120
 			$key_regex = preg_quote($key, $delim);
5800 6121
 			$new_key = $key;
5801 6122
 
5802
-			if (empty($value))
5803
-				$sub_regex = '';
5804
-			else
6123
+			if (empty($value)) {
6124
+							$sub_regex = '';
6125
+			} else
5805 6126
 			{
5806 6127
 				$sub_regex = $index_to_regex($value, $delim);
5807 6128
 
5808
-				if (count(array_keys($value)) == 1)
5809
-					$new_key .= explode('(?'.'>', $sub_regex)[0];
5810
-				else
5811
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6129
+				if (count(array_keys($value)) == 1) {
6130
+									$new_key .= explode('(?'.'>', $sub_regex)[0];
6131
+				} else {
6132
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6133
+				}
5812 6134
 			}
5813 6135
 
5814
-			if ($depth > 1)
5815
-				$regex[$new_key] = $key_regex . $sub_regex;
5816
-			else
6136
+			if ($depth > 1) {
6137
+							$regex[$new_key] = $key_regex . $sub_regex;
6138
+			} else
5817 6139
 			{
5818 6140
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5819 6141
 				{
5820 6142
 					$regex[$new_key] = $key_regex . $sub_regex;
5821 6143
 					unset($index[$key]);
6144
+				} else {
6145
+									break;
5822 6146
 				}
5823
-				else
5824
-					break;
5825 6147
 			}
5826 6148
 		}
5827 6149
 
@@ -5830,10 +6152,11 @@  discard block
 block discarded – undo
5830 6152
 			$l1 = $strlen($k1);
5831 6153
 			$l2 = $strlen($k2);
5832 6154
 
5833
-			if ($l1 == $l2)
5834
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5835
-			else
5836
-				return $l1 > $l2 ? -1 : 1;
6155
+			if ($l1 == $l2) {
6156
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6157
+			} else {
6158
+							return $l1 > $l2 ? -1 : 1;
6159
+			}
5837 6160
 		});
5838 6161
 
5839 6162
 		$depth--;
@@ -5844,15 +6167,18 @@  discard block
 block discarded – undo
5844 6167
 	$index = array();
5845 6168
 	$regexes = array();
5846 6169
 
5847
-	foreach ($strings as $string)
5848
-		$index = $add_string_to_index($string, $index);
6170
+	foreach ($strings as $string) {
6171
+			$index = $add_string_to_index($string, $index);
6172
+	}
5849 6173
 
5850
-	while (!empty($index))
5851
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6174
+	while (!empty($index)) {
6175
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6176
+	}
5852 6177
 
5853 6178
 	// Restore PHP's internal character encoding to whatever it was originally
5854
-	if (!empty($current_encoding))
5855
-		mb_internal_encoding($current_encoding);
6179
+	if (!empty($current_encoding)) {
6180
+			mb_internal_encoding($current_encoding);
6181
+	}
5856 6182
 
5857 6183
 	return $regexes;
5858 6184
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +860 added lines, -648 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
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// Try to load it from the cache first; it'll never get cached if the setting is off.
37 39
 	if (($modSettings = cache_get_data('modSettings', 90)) == null)
@@ -43,27 +45,35 @@  discard block
 block discarded – undo
43 45
 			)
44 46
 		);
45 47
 		$modSettings = array();
46
-		if (!$request)
47
-			display_db_error();
48
-		while ($row = $smcFunc['db_fetch_row']($request))
49
-			$modSettings[$row[0]] = $row[1];
48
+		if (!$request) {
49
+					display_db_error();
50
+		}
51
+		while ($row = $smcFunc['db_fetch_row']($request)) {
52
+					$modSettings[$row[0]] = $row[1];
53
+		}
50 54
 		$smcFunc['db_free_result']($request);
51 55
 
52 56
 		// Do a few things to protect against missing settings or settings with invalid values...
53
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
54
-			$modSettings['defaultMaxTopics'] = 20;
55
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
56
-			$modSettings['defaultMaxMessages'] = 15;
57
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
58
-			$modSettings['defaultMaxMembers'] = 30;
59
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
60
-			$modSettings['defaultMaxListItems'] = 15;
57
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
58
+					$modSettings['defaultMaxTopics'] = 20;
59
+		}
60
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
61
+					$modSettings['defaultMaxMessages'] = 15;
62
+		}
63
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
64
+					$modSettings['defaultMaxMembers'] = 30;
65
+		}
66
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
67
+					$modSettings['defaultMaxListItems'] = 15;
68
+		}
61 69
 
62
-		if (!is_array($modSettings['attachmentUploadDir']))
63
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
70
+		if (!is_array($modSettings['attachmentUploadDir'])) {
71
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
72
+		}
64 73
 
65
-		if (!empty($cache_enable))
66
-			cache_put_data('modSettings', $modSettings, 90);
74
+		if (!empty($cache_enable)) {
75
+					cache_put_data('modSettings', $modSettings, 90);
76
+		}
67 77
 	}
68 78
 
69 79
 	$modSettings['cache_enable'] = $cache_enable;
@@ -83,8 +93,9 @@  discard block
 block discarded – undo
83 93
 		};
84 94
 	$fix_utf8mb4 = function ($string) use ($utf8)
85 95
 	{
86
-		if (!$utf8)
87
-			return $string;
96
+		if (!$utf8) {
97
+					return $string;
98
+		}
88 99
 
89 100
 		$i = 0;
90 101
 		$len = strlen($string);
@@ -96,18 +107,15 @@  discard block
 block discarded – undo
96 107
 			{
97 108
 				$new_string .= $string[$i];
98 109
 				$i++;
99
-			}
100
-			elseif ($ord < 224)
110
+			} elseif ($ord < 224)
101 111
 			{
102 112
 				$new_string .= $string[$i] . $string[$i+1];
103 113
 				$i += 2;
104
-			}
105
-			elseif ($ord < 240)
114
+			} elseif ($ord < 240)
106 115
 			{
107 116
 				$new_string .= $string[$i] . $string[$i+1] . $string[$i+2];
108 117
 				$i += 3;
109
-			}
110
-			elseif ($ord < 248)
118
+			} elseif ($ord < 248)
111 119
 			{
112 120
 				// Magic happens.
113 121
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -151,8 +159,7 @@  discard block
 block discarded – undo
151 159
 			{
152 160
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
153 161
 				return is_int($result) ? $result + $offset : false;
154
-			}
155
-			else
162
+			} else
156 163
 			{
157 164
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
158 165
 				$needle_size = count($needle_arr);
@@ -161,8 +168,9 @@  discard block
 block discarded – undo
161 168
 				while ((int) $result === $result)
162 169
 				{
163 170
 					$offset += $result;
164
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
165
-						return $offset;
171
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
172
+											return $offset;
173
+					}
166 174
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
167 175
 				}
168 176
 				return false;
@@ -200,8 +208,9 @@  discard block
 block discarded – undo
200 208
 			$string = $ent_check($string);
201 209
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~'.  ($utf8 ? 'u' : ''), $string, $matches);
202 210
 			$string = $matches[0];
203
-			while (strlen($string) > $length)
204
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
211
+			while (strlen($string) > $length) {
212
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~'.  ($utf8 ? 'u' : ''), '', $string);
213
+			}
205 214
 			return $string;
206 215
 		},
207 216
 		'ucfirst' => $utf8 ? function ($string) use (&$smcFunc)
@@ -211,15 +220,17 @@  discard block
 block discarded – undo
211 220
 		'ucwords' => $utf8 ? function ($string) use (&$smcFunc)
212 221
 		{
213 222
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
214
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
215
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
223
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
224
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
225
+			}
216 226
 			return implode('', $words);
217 227
 		} : 'ucwords',
218 228
 	);
219 229
 
220 230
 	// Setting the timezone is a requirement for some functions.
221
-	if (isset($modSettings['default_timezone']))
222
-		date_default_timezone_set($modSettings['default_timezone']);
231
+	if (isset($modSettings['default_timezone'])) {
232
+			date_default_timezone_set($modSettings['default_timezone']);
233
+	}
223 234
 
224 235
 	// Check the load averages?
225 236
 	if (!empty($modSettings['loadavg_enable']))
@@ -227,22 +238,26 @@  discard block
 block discarded – undo
227 238
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
228 239
 		{
229 240
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
230
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
231
-				$modSettings['load_average'] = (float) $matches[1];
232
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
233
-				$modSettings['load_average'] = (float) $matches[1];
234
-			else
235
-				unset($modSettings['load_average']);
241
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
242
+							$modSettings['load_average'] = (float) $matches[1];
243
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
244
+							$modSettings['load_average'] = (float) $matches[1];
245
+			} else {
246
+							unset($modSettings['load_average']);
247
+			}
236 248
 
237
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
238
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
249
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
250
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
251
+			}
239 252
 		}
240 253
 
241
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
242
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
254
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
255
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
256
+		}
243 257
 
244
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
245
-			display_loadavg_error();
258
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
259
+					display_loadavg_error();
260
+		}
246 261
 	}
247 262
 
248 263
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -263,8 +278,9 @@  discard block
 block discarded – undo
263 278
 	if (defined('SMF_INTEGRATION_SETTINGS'))
264 279
 	{
265 280
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
266
-		foreach ($integration_settings as $hook => $function)
267
-			add_integration_function($hook, $function, '', false);
281
+		foreach ($integration_settings as $hook => $function) {
282
+					add_integration_function($hook, $function, '', false);
283
+		}
268 284
 	}
269 285
 
270 286
 	// Any files to pre include?
@@ -274,8 +290,9 @@  discard block
 block discarded – undo
274 290
 		foreach ($pre_includes as $include)
275 291
 		{
276 292
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
277
-			if (file_exists($include))
278
-				require_once($include);
293
+			if (file_exists($include)) {
294
+							require_once($include);
295
+			}
279 296
 		}
280 297
 	}
281 298
 
@@ -379,27 +396,28 @@  discard block
 block discarded – undo
379 396
 				break;
380 397
 			}
381 398
 		}
399
+	} else {
400
+			$id_member = 0;
382 401
 	}
383
-	else
384
-		$id_member = 0;
385 402
 
386 403
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
387 404
 	{
388 405
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
389 406
 
390
-		if (empty($cookie_data))
391
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
407
+		if (empty($cookie_data)) {
408
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
409
+		}
392 410
 
393 411
 		list ($id_member, $password) = $cookie_data;
394 412
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
395
-	}
396
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
413
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
397 414
 	{
398 415
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
399 416
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
400 417
 
401
-		if (empty($cookie_data))
402
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
418
+		if (empty($cookie_data)) {
419
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
420
+		}
403 421
 
404 422
 		list ($id_member, $password, $login_span) = $cookie_data;
405 423
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -424,30 +442,34 @@  discard block
 block discarded – undo
424 442
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
425 443
 			$smcFunc['db_free_result']($request);
426 444
 
427
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
428
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
445
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
446
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
447
+			}
429 448
 
430
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
431
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
449
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
450
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
451
+			}
432 452
 		}
433 453
 
434 454
 		// Did we find 'im?  If not, junk it.
435 455
 		if (!empty($user_settings))
436 456
 		{
437 457
 			// As much as the password should be right, we can assume the integration set things up.
438
-			if (!empty($already_verified) && $already_verified === true)
439
-				$check = true;
458
+			if (!empty($already_verified) && $already_verified === true) {
459
+							$check = true;
460
+			}
440 461
 			// SHA-512 hash should be 128 characters long.
441
-			elseif (strlen($password) == 128)
442
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
443
-			else
444
-				$check = false;
462
+			elseif (strlen($password) == 128) {
463
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
+			} else {
465
+							$check = false;
466
+			}
445 467
 
446 468
 			// Wrong password or not activated - either way, you're going nowhere.
447 469
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
470
+		} else {
471
+					$id_member = 0;
448 472
 		}
449
-		else
450
-			$id_member = 0;
451 473
 
452 474
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
453 475
 		if (!$id_member)
@@ -469,13 +491,15 @@  discard block
 block discarded – undo
469 491
 				{
470 492
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
471 493
 
472
-					if (is_null($tfa_data))
473
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
494
+					if (is_null($tfa_data)) {
495
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
496
+					}
474 497
 
475 498
 					list ($tfamember, $tfasecret) = $tfa_data;
476 499
 
477
-					if ((int) $tfamember != $id_member)
478
-						$tfasecret = null;
500
+					if ((int) $tfamember != $id_member) {
501
+											$tfasecret = null;
502
+					}
479 503
 				}
480 504
 
481 505
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -495,10 +519,12 @@  discard block
 block discarded – undo
495 519
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
496 520
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
497 521
 		{
498
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
522
+			if ($modSettings['tfa_mode'] == 2) {
523
+				//only do this if we are just forcing SOME membergroups
499 524
 			{
500 525
 				//Build an array of ALL user membergroups.
501 526
 				$full_groups = array($user_settings['id_group']);
527
+			}
502 528
 				if (!empty($user_settings['additional_groups']))
503 529
 				{
504 530
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -518,15 +544,17 @@  discard block
 block discarded – undo
518 544
 				);
519 545
 				$row = $smcFunc['db_fetch_assoc']($request);
520 546
 				$smcFunc['db_free_result']($request);
547
+			} else {
548
+							$row['total'] = 1;
521 549
 			}
522
-			else
523
-				$row['total'] = 1; //simplifies logics in the next "if"
550
+			//simplifies logics in the next "if"
524 551
 
525 552
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
526 553
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
527 554
 
528
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
529
-				redirectexit('action=profile;area=tfasetup;forced');
555
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
556
+							redirectexit('action=profile;area=tfasetup;forced');
557
+			}
530 558
 		}
531 559
 	}
532 560
 
@@ -563,33 +591,37 @@  discard block
 block discarded – undo
563 591
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
564 592
 				$user_settings['last_login'] = time();
565 593
 
566
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
567
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
594
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
595
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
596
+				}
568 597
 
569
-				if (!empty($modSettings['cache_enable']))
570
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
598
+				if (!empty($modSettings['cache_enable'])) {
599
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
600
+				}
571 601
 			}
602
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
603
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
572 604
 		}
573
-		elseif (empty($_SESSION['id_msg_last_visit']))
574
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
575 605
 
576 606
 		$username = $user_settings['member_name'];
577 607
 
578
-		if (empty($user_settings['additional_groups']))
579
-			$user_info = array(
608
+		if (empty($user_settings['additional_groups'])) {
609
+					$user_info = array(
580 610
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
581 611
 			);
582
-		else
583
-			$user_info = array(
612
+		} else {
613
+					$user_info = array(
584 614
 				'groups' => array_merge(
585 615
 					array($user_settings['id_group'], $user_settings['id_post_group']),
586 616
 					explode(',', $user_settings['additional_groups'])
587 617
 				)
588 618
 			);
619
+		}
589 620
 
590 621
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
591
-		foreach ($user_info['groups'] as $k => $v)
592
-			$user_info['groups'][$k] = (int) $v;
622
+		foreach ($user_info['groups'] as $k => $v) {
623
+					$user_info['groups'][$k] = (int) $v;
624
+		}
593 625
 
594 626
 		// This is a logged in user, so definitely not a spider.
595 627
 		$user_info['possibly_robot'] = false;
@@ -603,8 +635,7 @@  discard block
 block discarded – undo
603 635
 			$time_system = new DateTime('now', $tz_system);
604 636
 			$time_user = new DateTime('now', $tz_user);
605 637
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
606
-		}
607
-		else
638
+		} else
608 639
 		{
609 640
 			// !!! Compatibility.
610 641
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 :$user_settings['time_offset'];
@@ -618,16 +649,18 @@  discard block
 block discarded – undo
618 649
 		$user_info = array('groups' => array(-1));
619 650
 		$user_settings = array();
620 651
 
621
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
622
-			$_COOKIE[$cookiename] = '';
652
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
653
+					$_COOKIE[$cookiename] = '';
654
+		}
623 655
 
624 656
 		// Expire the 2FA cookie
625 657
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
626 658
 		{
627 659
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
628 660
 
629
-			if (is_null($tfa_data))
630
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
661
+			if (is_null($tfa_data)) {
662
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
663
+			}
631 664
 
632 665
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
633 666
 
@@ -639,19 +672,20 @@  discard block
 block discarded – undo
639 672
 		}
640 673
 
641 674
 		// Create a login token if it doesn't exist yet.
642
-		if (!isset($_SESSION['token']['post-login']))
643
-			createToken('login');
644
-		else
645
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
675
+		if (!isset($_SESSION['token']['post-login'])) {
676
+					createToken('login');
677
+		} else {
678
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
679
+		}
646 680
 
647 681
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
648 682
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
649 683
 		{
650 684
 			require_once($sourcedir . '/ManageSearchEngines.php');
651 685
 			$user_info['possibly_robot'] = SpiderCheck();
686
+		} elseif (!empty($modSettings['spider_mode'])) {
687
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
652 688
 		}
653
-		elseif (!empty($modSettings['spider_mode']))
654
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
655 689
 		// If we haven't turned on proper spider hunts then have a guess!
656 690
 		else
657 691
 		{
@@ -699,8 +733,9 @@  discard block
 block discarded – undo
699 733
 	$user_info['groups'] = array_unique($user_info['groups']);
700 734
 
701 735
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
702
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
703
-		unset($user_info['ignoreboards'][$tmp]);
736
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
737
+			unset($user_info['ignoreboards'][$tmp]);
738
+	}
704 739
 
705 740
 	// Allow the user to change their language.
706 741
 	if (!empty($modSettings['userLanguage']))
@@ -713,31 +748,36 @@  discard block
 block discarded – undo
713 748
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
714 749
 
715 750
 			// Make it permanent for members.
716
-			if (!empty($user_info['id']))
717
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
718
-			else
719
-				$_SESSION['language'] = $user_info['language'];
751
+			if (!empty($user_info['id'])) {
752
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
753
+			} else {
754
+							$_SESSION['language'] = $user_info['language'];
755
+			}
756
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
757
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
720 758
 		}
721
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
722
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
723 759
 	}
724 760
 
725 761
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
726
-	if ($user_info['is_admin'])
727
-		$user_info['query_see_board'] = '1=1';
762
+	if ($user_info['is_admin']) {
763
+			$user_info['query_see_board'] = '1=1';
764
+	}
728 765
 	// Otherwise just the groups in $user_info['groups'].
729
-	else
730
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
766
+	else {
767
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
768
+	}
731 769
 
732 770
 	// Build the list of boards they WANT to see.
733 771
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
734 772
 
735 773
 	// If they aren't ignoring any boards then they want to see all the boards they can see
736
-	if (empty($user_info['ignoreboards']))
737
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
774
+	if (empty($user_info['ignoreboards'])) {
775
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
776
+	}
738 777
 	// Ok I guess they don't want to see all the boards
739
-	else
740
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
778
+	else {
779
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
780
+	}
741 781
 
742 782
 	call_integration_hook('integrate_user_info');
743 783
 }
@@ -795,9 +835,9 @@  discard block
 block discarded – undo
795 835
 		}
796 836
 
797 837
 		// Remember redirection is the key to avoiding fallout from your bosses.
798
-		if (!empty($topic))
799
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
800
-		else
838
+		if (!empty($topic)) {
839
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
840
+		} else
801 841
 		{
802 842
 			loadPermissions();
803 843
 			loadTheme();
@@ -815,10 +855,11 @@  discard block
 block discarded – undo
815 855
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
816 856
 	{
817 857
 		// @todo SLOW?
818
-		if (!empty($topic))
819
-			$temp = cache_get_data('topic_board-' . $topic, 120);
820
-		else
821
-			$temp = cache_get_data('board-' . $board, 120);
858
+		if (!empty($topic)) {
859
+					$temp = cache_get_data('topic_board-' . $topic, 120);
860
+		} else {
861
+					$temp = cache_get_data('board-' . $board, 120);
862
+		}
822 863
 
823 864
 		if (!empty($temp))
824 865
 		{
@@ -856,8 +897,9 @@  discard block
 block discarded – undo
856 897
 			$row = $smcFunc['db_fetch_assoc']($request);
857 898
 
858 899
 			// Set the current board.
859
-			if (!empty($row['id_board']))
860
-				$board = $row['id_board'];
900
+			if (!empty($row['id_board'])) {
901
+							$board = $row['id_board'];
902
+			}
861 903
 
862 904
 			// Basic operating information. (globals... :/)
863 905
 			$board_info = array(
@@ -893,21 +935,23 @@  discard block
 block discarded – undo
893 935
 
894 936
 			do
895 937
 			{
896
-				if (!empty($row['id_moderator']))
897
-					$board_info['moderators'][$row['id_moderator']] = array(
938
+				if (!empty($row['id_moderator'])) {
939
+									$board_info['moderators'][$row['id_moderator']] = array(
898 940
 						'id' => $row['id_moderator'],
899 941
 						'name' => $row['real_name'],
900 942
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
901 943
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
902 944
 					);
945
+				}
903 946
 
904
-				if (!empty($row['id_moderator_group']))
905
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
947
+				if (!empty($row['id_moderator_group'])) {
948
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
906 949
 						'id' => $row['id_moderator_group'],
907 950
 						'name' => $row['group_name'],
908 951
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
909 952
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
910 953
 					);
954
+				}
911 955
 			}
912 956
 			while ($row = $smcFunc['db_fetch_assoc']($request));
913 957
 
@@ -939,12 +983,12 @@  discard block
 block discarded – undo
939 983
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
940 984
 			{
941 985
 				// @todo SLOW?
942
-				if (!empty($topic))
943
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
986
+				if (!empty($topic)) {
987
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
988
+				}
944 989
 				cache_put_data('board-' . $board, $board_info, 120);
945 990
 			}
946
-		}
947
-		else
991
+		} else
948 992
 		{
949 993
 			// Otherwise the topic is invalid, there are no moderators, etc.
950 994
 			$board_info = array(
@@ -958,8 +1002,9 @@  discard block
 block discarded – undo
958 1002
 		$smcFunc['db_free_result']($request);
959 1003
 	}
960 1004
 
961
-	if (!empty($topic))
962
-		$_GET['board'] = (int) $board;
1005
+	if (!empty($topic)) {
1006
+			$_GET['board'] = (int) $board;
1007
+	}
963 1008
 
964 1009
 	if (!empty($board))
965 1010
 	{
@@ -969,10 +1014,12 @@  discard block
 block discarded – undo
969 1014
 		// Now check if the user is a moderator.
970 1015
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
971 1016
 
972
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
973
-			$board_info['error'] = 'access';
974
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
975
-			$board_info['error'] = 'access';
1017
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1018
+					$board_info['error'] = 'access';
1019
+		}
1020
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1021
+					$board_info['error'] = 'access';
1022
+		}
976 1023
 
977 1024
 		// Build up the linktree.
978 1025
 		$context['linktree'] = array_merge(
@@ -995,8 +1042,9 @@  discard block
 block discarded – undo
995 1042
 	$context['current_board'] = $board;
996 1043
 
997 1044
 	// No posting in redirection boards!
998
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
999
-		$board_info['error'] == 'post_in_redirect';
1045
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1046
+			$board_info['error'] == 'post_in_redirect';
1047
+	}
1000 1048
 
1001 1049
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1002 1050
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1022,24 +1070,23 @@  discard block
 block discarded – undo
1022 1070
 			ob_end_clean();
1023 1071
 			header('HTTP/1.1 403 Forbidden');
1024 1072
 			die;
1025
-		}
1026
-		elseif ($board_info['error'] == 'post_in_redirect')
1073
+		} elseif ($board_info['error'] == 'post_in_redirect')
1027 1074
 		{
1028 1075
 			// Slightly different error message here...
1029 1076
 			fatal_lang_error('cannot_post_redirect', false);
1030
-		}
1031
-		elseif ($user_info['is_guest'])
1077
+		} elseif ($user_info['is_guest'])
1032 1078
 		{
1033 1079
 			loadLanguage('Errors');
1034 1080
 			is_not_guest($txt['topic_gone']);
1081
+		} else {
1082
+					fatal_lang_error('topic_gone', false);
1035 1083
 		}
1036
-		else
1037
-			fatal_lang_error('topic_gone', false);
1038 1084
 	}
1039 1085
 
1040
-	if ($user_info['is_mod'])
1041
-		$user_info['groups'][] = 3;
1042
-}
1086
+	if ($user_info['is_mod']) {
1087
+			$user_info['groups'][] = 3;
1088
+	}
1089
+	}
1043 1090
 
1044 1091
 /**
1045 1092
  * Load this user's permissions.
@@ -1060,8 +1107,9 @@  discard block
 block discarded – undo
1060 1107
 		asort($cache_groups);
1061 1108
 		$cache_groups = implode(',', $cache_groups);
1062 1109
 		// If it's a spider then cache it different.
1063
-		if ($user_info['possibly_robot'])
1064
-			$cache_groups .= '-spider';
1110
+		if ($user_info['possibly_robot']) {
1111
+					$cache_groups .= '-spider';
1112
+		}
1065 1113
 
1066 1114
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1067 1115
 		{
@@ -1069,9 +1117,9 @@  discard block
 block discarded – undo
1069 1117
 			banPermissions();
1070 1118
 
1071 1119
 			return;
1120
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1121
+					list ($user_info['permissions'], $removals) = $temp;
1072 1122
 		}
1073
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1074
-			list ($user_info['permissions'], $removals) = $temp;
1075 1123
 	}
1076 1124
 
1077 1125
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1093,23 +1141,26 @@  discard block
 block discarded – undo
1093 1141
 		$removals = array();
1094 1142
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1095 1143
 		{
1096
-			if (empty($row['add_deny']))
1097
-				$removals[] = $row['permission'];
1098
-			else
1099
-				$user_info['permissions'][] = $row['permission'];
1144
+			if (empty($row['add_deny'])) {
1145
+							$removals[] = $row['permission'];
1146
+			} else {
1147
+							$user_info['permissions'][] = $row['permission'];
1148
+			}
1100 1149
 		}
1101 1150
 		$smcFunc['db_free_result']($request);
1102 1151
 
1103
-		if (isset($cache_groups))
1104
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1152
+		if (isset($cache_groups)) {
1153
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1154
+		}
1105 1155
 	}
1106 1156
 
1107 1157
 	// Get the board permissions.
1108 1158
 	if (!empty($board))
1109 1159
 	{
1110 1160
 		// Make sure the board (if any) has been loaded by loadBoard().
1111
-		if (!isset($board_info['profile']))
1112
-			fatal_lang_error('no_board');
1161
+		if (!isset($board_info['profile'])) {
1162
+					fatal_lang_error('no_board');
1163
+		}
1113 1164
 
1114 1165
 		$request = $smcFunc['db_query']('', '
1115 1166
 			SELECT permission, add_deny
@@ -1125,20 +1176,23 @@  discard block
 block discarded – undo
1125 1176
 		);
1126 1177
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1127 1178
 		{
1128
-			if (empty($row['add_deny']))
1129
-				$removals[] = $row['permission'];
1130
-			else
1131
-				$user_info['permissions'][] = $row['permission'];
1179
+			if (empty($row['add_deny'])) {
1180
+							$removals[] = $row['permission'];
1181
+			} else {
1182
+							$user_info['permissions'][] = $row['permission'];
1183
+			}
1132 1184
 		}
1133 1185
 		$smcFunc['db_free_result']($request);
1134 1186
 	}
1135 1187
 
1136 1188
 	// Remove all the permissions they shouldn't have ;).
1137
-	if (!empty($modSettings['permission_enable_deny']))
1138
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1189
+	if (!empty($modSettings['permission_enable_deny'])) {
1190
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1191
+	}
1139 1192
 
1140
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1141
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1193
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1194
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1195
+	}
1142 1196
 
1143 1197
 	// Banned?  Watch, don't touch..
1144 1198
 	banPermissions();
@@ -1150,17 +1204,18 @@  discard block
 block discarded – undo
1150 1204
 		{
1151 1205
 			require_once($sourcedir . '/Subs-Auth.php');
1152 1206
 			rebuildModCache();
1207
+		} else {
1208
+					$user_info['mod_cache'] = $_SESSION['mc'];
1153 1209
 		}
1154
-		else
1155
-			$user_info['mod_cache'] = $_SESSION['mc'];
1156 1210
 
1157 1211
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1158 1212
 		// For example this drastically simplifies certain changes to the profile area.
1159 1213
 		$user_info['permissions'][] = 'is_not_guest';
1160 1214
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1161 1215
 		$user_info['permissions'][] = 'profile_view_own';
1162
-		if (in_array('profile_view', $user_info['permissions']))
1163
-			$user_info['permissions'][] = 'profile_view_any';
1216
+		if (in_array('profile_view', $user_info['permissions'])) {
1217
+					$user_info['permissions'][] = 'profile_view_any';
1218
+		}
1164 1219
 	}
1165 1220
 }
1166 1221
 
@@ -1178,8 +1233,9 @@  discard block
 block discarded – undo
1178 1233
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1179 1234
 
1180 1235
 	// Can't just look for no users :P.
1181
-	if (empty($users))
1182
-		return array();
1236
+	if (empty($users)) {
1237
+			return array();
1238
+	}
1183 1239
 
1184 1240
 	// Pass the set value
1185 1241
 	$context['loadMemberContext_set'] = $set;
@@ -1194,8 +1250,9 @@  discard block
 block discarded – undo
1194 1250
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1195 1251
 		{
1196 1252
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1197
-			if ($data == null)
1198
-				continue;
1253
+			if ($data == null) {
1254
+							continue;
1255
+			}
1199 1256
 
1200 1257
 			$loaded_ids[] = $data['id_member'];
1201 1258
 			$user_profile[$data['id_member']] = $data;
@@ -1259,13 +1316,16 @@  discard block
 block discarded – undo
1259 1316
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1260 1317
 		{
1261 1318
 			// Take care of proxying avatar if required, do this here for maximum reach
1262
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1263
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1319
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1320
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1321
+			}
1264 1322
 
1265
-			if ( isset($row['member_ip']) )
1266
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1267
-			if ( isset($row['member_ip2']) )
1268
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1323
+			if ( isset($row['member_ip']) ) {
1324
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1325
+			}
1326
+			if ( isset($row['member_ip2']) ) {
1327
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1328
+			}
1269 1329
 			$new_loaded_ids[] = $row['id_member'];
1270 1330
 			$loaded_ids[] = $row['id_member'];
1271 1331
 			$row['options'] = array();
@@ -1284,8 +1344,9 @@  discard block
 block discarded – undo
1284 1344
 				'loaded_ids' => $new_loaded_ids,
1285 1345
 			)
1286 1346
 		);
1287
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1288
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1347
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1348
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1349
+		}
1289 1350
 		$smcFunc['db_free_result']($request);
1290 1351
 	}
1291 1352
 
@@ -1296,10 +1357,11 @@  discard block
 block discarded – undo
1296 1357
 	{
1297 1358
 		foreach ($loaded_ids as $a_member)
1298 1359
 		{
1299
-			if (!empty($user_profile[$a_member]['additional_groups']))
1300
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1301
-			else
1302
-				$groups = array($user_profile[$a_member]['id_group']);
1360
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1361
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1362
+			} else {
1363
+							$groups = array($user_profile[$a_member]['id_group']);
1364
+			}
1303 1365
 
1304 1366
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1305 1367
 
@@ -1312,8 +1374,9 @@  discard block
 block discarded – undo
1312 1374
 
1313 1375
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1314 1376
 	{
1315
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1316
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1377
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1378
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1379
+		}
1317 1380
 	}
1318 1381
 
1319 1382
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1339,14 +1402,17 @@  discard block
 block discarded – undo
1339 1402
 		foreach ($temp_mods as $id)
1340 1403
 		{
1341 1404
 			// By popular demand, don't show admins or global moderators as moderators.
1342
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1343
-				$user_profile[$id]['member_group'] = $row['member_group'];
1405
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1406
+							$user_profile[$id]['member_group'] = $row['member_group'];
1407
+			}
1344 1408
 
1345 1409
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1346
-			if (!empty($row['icons']))
1347
-				$user_profile[$id]['icons'] = $row['icons'];
1348
-			if (!empty($row['member_group_color']))
1349
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1410
+			if (!empty($row['icons'])) {
1411
+							$user_profile[$id]['icons'] = $row['icons'];
1412
+			}
1413
+			if (!empty($row['member_group_color'])) {
1414
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1415
+			}
1350 1416
 		}
1351 1417
 	}
1352 1418
 
@@ -1368,12 +1434,14 @@  discard block
 block discarded – undo
1368 1434
 	static $loadedLanguages = array();
1369 1435
 
1370 1436
 	// If this person's data is already loaded, skip it.
1371
-	if (isset($dataLoaded[$user]))
1372
-		return true;
1437
+	if (isset($dataLoaded[$user])) {
1438
+			return true;
1439
+	}
1373 1440
 
1374 1441
 	// We can't load guests or members not loaded by loadMemberData()!
1375
-	if ($user == 0)
1376
-		return false;
1442
+	if ($user == 0) {
1443
+			return false;
1444
+	}
1377 1445
 	if (!isset($user_profile[$user]))
1378 1446
 	{
1379 1447
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1399,12 +1467,16 @@  discard block
 block discarded – undo
1399 1467
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1400 1468
 
1401 1469
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1402
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1470
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1471
+		//icon is set and exists
1403 1472
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1404
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1473
+	} elseif (isset($profile['icons'][1])) {
1474
+		//icon is set and doesn't exist, fallback to default
1405 1475
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1406
-	else //not set, bye bye
1476
+	} else {
1477
+		//not set, bye bye
1407 1478
 		$group_icon_url = '';
1479
+	}
1408 1480
 
1409 1481
 	// These minimal values are always loaded
1410 1482
 	$memberContext[$user] = array(
@@ -1423,8 +1495,9 @@  discard block
 block discarded – undo
1423 1495
 	if ($context['loadMemberContext_set'] != 'minimal')
1424 1496
 	{
1425 1497
 		// Go the extra mile and load the user's native language name.
1426
-		if (empty($loadedLanguages))
1427
-			$loadedLanguages = getLanguages();
1498
+		if (empty($loadedLanguages)) {
1499
+					$loadedLanguages = getLanguages();
1500
+		}
1428 1501
 
1429 1502
 		$memberContext[$user] += array(
1430 1503
 			'username_color' => '<span '. (!empty($profile['member_group_color']) ? 'style="color:'. $profile['member_group_color'] .';"' : '') .'>'. $profile['member_name'] .'</span>',
@@ -1478,31 +1551,33 @@  discard block
 block discarded – undo
1478 1551
 	{
1479 1552
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1480 1553
 		{
1481
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1482
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1483
-			else
1484
-				$image = get_gravatar_url($profile['email_address']);
1485
-		}
1486
-		else
1554
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1555
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1556
+			} else {
1557
+							$image = get_gravatar_url($profile['email_address']);
1558
+			}
1559
+		} else
1487 1560
 		{
1488 1561
 			// So it's stored in the member table?
1489 1562
 			if (!empty($profile['avatar']))
1490 1563
 			{
1491 1564
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1565
+			} elseif (!empty($profile['filename'])) {
1566
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1492 1567
 			}
1493
-			elseif (!empty($profile['filename']))
1494
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1495 1568
 			// Right... no avatar...use the default one
1496
-			else
1497
-				$image = $modSettings['avatar_url'] . '/default.png';
1569
+			else {
1570
+							$image = $modSettings['avatar_url'] . '/default.png';
1571
+			}
1498 1572
 		}
1499
-		if (!empty($image))
1500
-			$memberContext[$user]['avatar'] = array(
1573
+		if (!empty($image)) {
1574
+					$memberContext[$user]['avatar'] = array(
1501 1575
 				'name' => $profile['avatar'],
1502 1576
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_'. $profile['member_name'].'">',
1503 1577
 				'href' => $image,
1504 1578
 				'url' => $image,
1505 1579
 			);
1580
+		}
1506 1581
 	}
1507 1582
 
1508 1583
 	// Are we also loading the members custom fields into context?
@@ -1510,35 +1585,41 @@  discard block
 block discarded – undo
1510 1585
 	{
1511 1586
 		$memberContext[$user]['custom_fields'] = array();
1512 1587
 
1513
-		if (!isset($context['display_fields']))
1514
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1588
+		if (!isset($context['display_fields'])) {
1589
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1590
+		}
1515 1591
 
1516 1592
 		foreach ($context['display_fields'] as $custom)
1517 1593
 		{
1518
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1519
-				continue;
1594
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1595
+							continue;
1596
+			}
1520 1597
 
1521 1598
 			$value = $profile['options'][$custom['col_name']];
1522 1599
 
1523 1600
 			// Don't show the "disabled" option for the "gender" field.
1524
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1525
-				continue;
1601
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1602
+							continue;
1603
+			}
1526 1604
 
1527 1605
 			// BBC?
1528
-			if ($custom['bbc'])
1529
-				$value = parse_bbc($value);
1606
+			if ($custom['bbc']) {
1607
+							$value = parse_bbc($value);
1608
+			}
1530 1609
 			// ... or checkbox?
1531
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1532
-				$value = $value ? $txt['yes'] : $txt['no'];
1610
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1611
+							$value = $value ? $txt['yes'] : $txt['no'];
1612
+			}
1533 1613
 
1534 1614
 			// Enclosing the user input within some other text?
1535
-			if (!empty($custom['enclose']))
1536
-				$value = strtr($custom['enclose'], array(
1615
+			if (!empty($custom['enclose'])) {
1616
+							$value = strtr($custom['enclose'], array(
1537 1617
 					'{SCRIPTURL}' => $scripturl,
1538 1618
 					'{IMAGES_URL}' => $settings['images_url'],
1539 1619
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1540 1620
 					'{INPUT}' => $value,
1541 1621
 				));
1622
+			}
1542 1623
 
1543 1624
 			$memberContext[$user]['custom_fields'][] = array(
1544 1625
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1565,8 +1646,9 @@  discard block
 block discarded – undo
1565 1646
 	global $smcFunc, $txt, $scripturl, $settings;
1566 1647
 
1567 1648
 	// Do not waste my time...
1568
-	if (empty($users) || empty($params))
1569
-		return false;
1649
+	if (empty($users) || empty($params)) {
1650
+			return false;
1651
+	}
1570 1652
 
1571 1653
 	// Make sure it's an array.
1572 1654
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1590,31 +1672,36 @@  discard block
 block discarded – undo
1590 1672
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1591 1673
 	{
1592 1674
 		// BBC?
1593
-		if (!empty($row['bbc']))
1594
-			$row['value'] = parse_bbc($row['value']);
1675
+		if (!empty($row['bbc'])) {
1676
+					$row['value'] = parse_bbc($row['value']);
1677
+		}
1595 1678
 
1596 1679
 		// ... or checkbox?
1597
-		elseif (isset($row['type']) && $row['type'] == 'check')
1598
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1680
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1681
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1682
+		}
1599 1683
 
1600 1684
 		// Enclosing the user input within some other text?
1601
-		if (!empty($row['enclose']))
1602
-			$row['value'] = strtr($row['enclose'], array(
1685
+		if (!empty($row['enclose'])) {
1686
+					$row['value'] = strtr($row['enclose'], array(
1603 1687
 				'{SCRIPTURL}' => $scripturl,
1604 1688
 				'{IMAGES_URL}' => $settings['images_url'],
1605 1689
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1606 1690
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1607 1691
 			));
1692
+		}
1608 1693
 
1609 1694
 		// Send a simple array if there is just 1 param
1610
-		if (count($params) == 1)
1611
-			$return[$row['id_member']] = $row;
1695
+		if (count($params) == 1) {
1696
+					$return[$row['id_member']] = $row;
1697
+		}
1612 1698
 
1613 1699
 		// More than 1? knock yourself out...
1614 1700
 		else
1615 1701
 		{
1616
-			if (!isset($return[$row['id_member']]))
1617
-				$return[$row['id_member']] = array();
1702
+			if (!isset($return[$row['id_member']])) {
1703
+							$return[$row['id_member']] = array();
1704
+			}
1618 1705
 
1619 1706
 			$return[$row['id_member']][$row['variable']] = $row;
1620 1707
 		}
@@ -1648,8 +1735,9 @@  discard block
 block discarded – undo
1648 1735
 	global $context;
1649 1736
 
1650 1737
 	// Don't know any browser!
1651
-	if (empty($context['browser']))
1652
-		detectBrowser();
1738
+	if (empty($context['browser'])) {
1739
+			detectBrowser();
1740
+	}
1653 1741
 
1654 1742
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1655 1743
 }
@@ -1667,8 +1755,9 @@  discard block
 block discarded – undo
1667 1755
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1668 1756
 
1669 1757
 	// The theme was specified by parameter.
1670
-	if (!empty($id_theme))
1671
-		$id_theme = (int) $id_theme;
1758
+	if (!empty($id_theme)) {
1759
+			$id_theme = (int) $id_theme;
1760
+	}
1672 1761
 	// The theme was specified by REQUEST.
1673 1762
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1674 1763
 	{
@@ -1676,51 +1765,58 @@  discard block
 block discarded – undo
1676 1765
 		$_SESSION['id_theme'] = $id_theme;
1677 1766
 	}
1678 1767
 	// The theme was specified by REQUEST... previously.
1679
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1680
-		$id_theme = (int) $_SESSION['id_theme'];
1768
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1769
+			$id_theme = (int) $_SESSION['id_theme'];
1770
+	}
1681 1771
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1682
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1683
-		$id_theme = $user_info['theme'];
1772
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1773
+			$id_theme = $user_info['theme'];
1774
+	}
1684 1775
 	// The theme was specified by the board.
1685
-	elseif (!empty($board_info['theme']))
1686
-		$id_theme = $board_info['theme'];
1776
+	elseif (!empty($board_info['theme'])) {
1777
+			$id_theme = $board_info['theme'];
1778
+	}
1687 1779
 	// The theme is the forum's default.
1688
-	else
1689
-		$id_theme = $modSettings['theme_guests'];
1780
+	else {
1781
+			$id_theme = $modSettings['theme_guests'];
1782
+	}
1690 1783
 
1691 1784
 	// Verify the id_theme... no foul play.
1692 1785
 	// Always allow the board specific theme, if they are overriding.
1693
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1694
-		$id_theme = $board_info['theme'];
1786
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1787
+			$id_theme = $board_info['theme'];
1788
+	}
1695 1789
 	// If they have specified a particular theme to use with SSI allow it to be used.
1696
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1697
-		$id_theme = (int) $id_theme;
1698
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1790
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1791
+			$id_theme = (int) $id_theme;
1792
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1699 1793
 	{
1700 1794
 		$themes = explode(',', $modSettings['enableThemes']);
1701
-		if (!in_array($id_theme, $themes))
1702
-			$id_theme = $modSettings['theme_guests'];
1703
-		else
1795
+		if (!in_array($id_theme, $themes)) {
1796
+					$id_theme = $modSettings['theme_guests'];
1797
+		} else {
1798
+					$id_theme = (int) $id_theme;
1799
+		}
1800
+	} else {
1704 1801
 			$id_theme = (int) $id_theme;
1705 1802
 	}
1706
-	else
1707
-		$id_theme = (int) $id_theme;
1708 1803
 
1709 1804
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1710 1805
 
1711 1806
 	// Disable image proxy if we don't have SSL enabled
1712
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1713
-		$image_proxy_enabled = false;
1807
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1808
+			$image_proxy_enabled = false;
1809
+	}
1714 1810
 
1715 1811
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1716 1812
 	{
1717 1813
 		$themeData = $temp;
1718 1814
 		$flag = true;
1815
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1816
+			$themeData = $temp + array($member => array());
1817
+	} else {
1818
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1719 1819
 	}
1720
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1721
-		$themeData = $temp + array($member => array());
1722
-	else
1723
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1724 1820
 
1725 1821
 	if (empty($flag))
1726 1822
 	{
@@ -1739,31 +1835,37 @@  discard block
 block discarded – undo
1739 1835
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1740 1836
 		{
1741 1837
 			// There are just things we shouldn't be able to change as members.
1742
-			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1743
-				continue;
1838
+			if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1839
+							continue;
1840
+			}
1744 1841
 
1745 1842
 			// If this is the theme_dir of the default theme, store it.
1746
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1747
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1843
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1844
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1845
+			}
1748 1846
 
1749 1847
 			// If this isn't set yet, is a theme option, or is not the default theme..
1750
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1751
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1848
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1849
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1850
+			}
1752 1851
 		}
1753 1852
 		$smcFunc['db_free_result']($result);
1754 1853
 
1755
-		if (!empty($themeData[-1]))
1756
-			foreach ($themeData[-1] as $k => $v)
1854
+		if (!empty($themeData[-1])) {
1855
+					foreach ($themeData[-1] as $k => $v)
1757 1856
 			{
1758 1857
 				if (!isset($themeData[$member][$k]))
1759 1858
 					$themeData[$member][$k] = $v;
1859
+		}
1760 1860
 			}
1761 1861
 
1762
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1763
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1862
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1863
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1864
+		}
1764 1865
 		// Only if we didn't already load that part of the cache...
1765
-		elseif (!isset($temp))
1766
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1866
+		elseif (!isset($temp)) {
1867
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1868
+		}
1767 1869
 	}
1768 1870
 
1769 1871
 	$settings = $themeData[0];
@@ -1780,20 +1882,24 @@  discard block
 block discarded – undo
1780 1882
 	$settings['template_dirs'][] = $settings['theme_dir'];
1781 1883
 
1782 1884
 	// Based on theme (if there is one).
1783
-	if (!empty($settings['base_theme_dir']))
1784
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1885
+	if (!empty($settings['base_theme_dir'])) {
1886
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1887
+	}
1785 1888
 
1786 1889
 	// Lastly the default theme.
1787
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1788
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1890
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1891
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1892
+	}
1789 1893
 
1790
-	if (!$initialize)
1791
-		return;
1894
+	if (!$initialize) {
1895
+			return;
1896
+	}
1792 1897
 
1793 1898
 	// Check to see if we're forcing SSL
1794 1899
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1795
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1796
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1900
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1901
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1902
+	}
1797 1903
 
1798 1904
 	// Check to see if they're accessing it from the wrong place.
1799 1905
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1801,8 +1907,9 @@  discard block
 block discarded – undo
1801 1907
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1802 1908
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1803 1909
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1804
-		if ($temp != '/')
1805
-			$detected_url .= $temp;
1910
+		if ($temp != '/') {
1911
+					$detected_url .= $temp;
1912
+		}
1806 1913
 	}
1807 1914
 	if (isset($detected_url) && $detected_url != $boardurl)
1808 1915
 	{
@@ -1814,8 +1921,9 @@  discard block
 block discarded – undo
1814 1921
 			foreach ($aliases as $alias)
1815 1922
 			{
1816 1923
 				// Rip off all the boring parts, spaces, etc.
1817
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1818
-					$do_fix = true;
1924
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1925
+									$do_fix = true;
1926
+				}
1819 1927
 			}
1820 1928
 		}
1821 1929
 
@@ -1823,20 +1931,22 @@  discard block
 block discarded – undo
1823 1931
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1824 1932
 		{
1825 1933
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1826
-			if (empty($_GET))
1827
-				redirectexit('wwwRedirect');
1828
-			else
1934
+			if (empty($_GET)) {
1935
+							redirectexit('wwwRedirect');
1936
+			} else
1829 1937
 			{
1830 1938
 				list ($k, $v) = each($_GET);
1831 1939
 
1832
-				if ($k != 'wwwRedirect')
1833
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1940
+				if ($k != 'wwwRedirect') {
1941
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1942
+				}
1834 1943
 			}
1835 1944
 		}
1836 1945
 
1837 1946
 		// #3 is just a check for SSL...
1838
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1839
-			$do_fix = true;
1947
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1948
+					$do_fix = true;
1949
+		}
1840 1950
 
1841 1951
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1842 1952
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1870,8 +1980,9 @@  discard block
 block discarded – undo
1870 1980
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1871 1981
 				}
1872 1982
 			}
1873
-			foreach ($context['linktree'] as $k => $dummy)
1874
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1983
+			foreach ($context['linktree'] as $k => $dummy) {
1984
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1985
+			}
1875 1986
 		}
1876 1987
 	}
1877 1988
 	// Set up the contextual user array.
@@ -1890,16 +2001,16 @@  discard block
 block discarded – undo
1890 2001
 			'email' => $user_info['email'],
1891 2002
 			'ignoreusers' => $user_info['ignoreusers'],
1892 2003
 		);
1893
-		if (!$context['user']['is_guest'])
1894
-			$context['user']['name'] = $user_info['name'];
1895
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1896
-			$context['user']['name'] = $txt['guest_title'];
2004
+		if (!$context['user']['is_guest']) {
2005
+					$context['user']['name'] = $user_info['name'];
2006
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2007
+					$context['user']['name'] = $txt['guest_title'];
2008
+		}
1897 2009
 
1898 2010
 		// Determine the current smiley set.
1899 2011
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1900 2012
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1901
-	}
1902
-	else
2013
+	} else
1903 2014
 	{
1904 2015
 		$context['user'] = array(
1905 2016
 			'id' => -1,
@@ -1915,18 +2026,24 @@  discard block
 block discarded – undo
1915 2026
 	}
1916 2027
 
1917 2028
 	// Some basic information...
1918
-	if (!isset($context['html_headers']))
1919
-		$context['html_headers'] = '';
1920
-	if (!isset($context['javascript_files']))
1921
-		$context['javascript_files'] = array();
1922
-	if (!isset($context['css_files']))
1923
-		$context['css_files'] = array();
1924
-	if (!isset($context['css_header']))
1925
-		$context['css_header'] = array();
1926
-	if (!isset($context['javascript_inline']))
1927
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1928
-	if (!isset($context['javascript_vars']))
1929
-		$context['javascript_vars'] = array();
2029
+	if (!isset($context['html_headers'])) {
2030
+			$context['html_headers'] = '';
2031
+	}
2032
+	if (!isset($context['javascript_files'])) {
2033
+			$context['javascript_files'] = array();
2034
+	}
2035
+	if (!isset($context['css_files'])) {
2036
+			$context['css_files'] = array();
2037
+	}
2038
+	if (!isset($context['css_header'])) {
2039
+			$context['css_header'] = array();
2040
+	}
2041
+	if (!isset($context['javascript_inline'])) {
2042
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2043
+	}
2044
+	if (!isset($context['javascript_vars'])) {
2045
+			$context['javascript_vars'] = array();
2046
+	}
1930 2047
 
1931 2048
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1932 2049
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1938,8 +2055,9 @@  discard block
 block discarded – undo
1938 2055
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1939 2056
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1940 2057
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1941
-	if (isset($modSettings['load_average']))
1942
-		$context['load_average'] = $modSettings['load_average'];
2058
+	if (isset($modSettings['load_average'])) {
2059
+			$context['load_average'] = $modSettings['load_average'];
2060
+	}
1943 2061
 
1944 2062
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1945 2063
 	detectBrowser();
@@ -1953,8 +2071,9 @@  discard block
 block discarded – undo
1953 2071
 	// This allows sticking some HTML on the page output - useful for controls.
1954 2072
 	$context['insert_after_template'] = '';
1955 2073
 
1956
-	if (!isset($txt))
1957
-		$txt = array();
2074
+	if (!isset($txt)) {
2075
+			$txt = array();
2076
+	}
1958 2077
 
1959 2078
 	$simpleActions = array(
1960 2079
 		'findmember',
@@ -2000,9 +2119,10 @@  discard block
 block discarded – undo
2000 2119
 
2001 2120
 	// See if theres any extra param to check.
2002 2121
 	$requiresXML = false;
2003
-	foreach ($extraParams as $key => $extra)
2004
-		if (isset($_REQUEST[$extra]))
2122
+	foreach ($extraParams as $key => $extra) {
2123
+			if (isset($_REQUEST[$extra]))
2005 2124
 			$requiresXML = true;
2125
+	}
2006 2126
 
2007 2127
 	// Output is fully XML, so no need for the index template.
2008 2128
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2017,37 +2137,39 @@  discard block
 block discarded – undo
2017 2137
 	{
2018 2138
 		loadLanguage('index+Modifications');
2019 2139
 		$context['template_layers'] = array();
2020
-	}
2021
-
2022
-	else
2140
+	} else
2023 2141
 	{
2024 2142
 		// Custom templates to load, or just default?
2025
-		if (isset($settings['theme_templates']))
2026
-			$templates = explode(',', $settings['theme_templates']);
2027
-		else
2028
-			$templates = array('index');
2143
+		if (isset($settings['theme_templates'])) {
2144
+					$templates = explode(',', $settings['theme_templates']);
2145
+		} else {
2146
+					$templates = array('index');
2147
+		}
2029 2148
 
2030 2149
 		// Load each template...
2031
-		foreach ($templates as $template)
2032
-			loadTemplate($template);
2150
+		foreach ($templates as $template) {
2151
+					loadTemplate($template);
2152
+		}
2033 2153
 
2034 2154
 		// ...and attempt to load their associated language files.
2035 2155
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2036 2156
 		loadLanguage($required_files, '', false);
2037 2157
 
2038 2158
 		// Custom template layers?
2039
-		if (isset($settings['theme_layers']))
2040
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2041
-		else
2042
-			$context['template_layers'] = array('html', 'body');
2159
+		if (isset($settings['theme_layers'])) {
2160
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2161
+		} else {
2162
+					$context['template_layers'] = array('html', 'body');
2163
+		}
2043 2164
 	}
2044 2165
 
2045 2166
 	// Initialize the theme.
2046 2167
 	loadSubTemplate('init', 'ignore');
2047 2168
 
2048 2169
 	// Allow overriding the board wide time/number formats.
2049
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2050
-		$user_info['time_format'] = $txt['time_format'];
2170
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2171
+			$user_info['time_format'] = $txt['time_format'];
2172
+	}
2051 2173
 
2052 2174
 	// Set the character set from the template.
2053 2175
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2055,12 +2177,14 @@  discard block
 block discarded – undo
2055 2177
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2056 2178
 
2057 2179
 	// Guests may still need a name.
2058
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2059
-		$context['user']['name'] = $txt['guest_title'];
2180
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2181
+			$context['user']['name'] = $txt['guest_title'];
2182
+	}
2060 2183
 
2061 2184
 	// Any theme-related strings that need to be loaded?
2062
-	if (!empty($settings['require_theme_strings']))
2063
-		loadLanguage('ThemeStrings', '', false);
2185
+	if (!empty($settings['require_theme_strings'])) {
2186
+			loadLanguage('ThemeStrings', '', false);
2187
+	}
2064 2188
 
2065 2189
 	// Make a special URL for the language.
2066 2190
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2071,8 +2195,9 @@  discard block
 block discarded – undo
2071 2195
 	// Here is my luvly Responsive CSS
2072 2196
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2073 2197
 
2074
-	if ($context['right_to_left'])
2075
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2198
+	if ($context['right_to_left']) {
2199
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2200
+	}
2076 2201
 
2077 2202
 	// We allow theme variants, because we're cool.
2078 2203
 	$context['theme_variant'] = '';
@@ -2080,14 +2205,17 @@  discard block
 block discarded – undo
2080 2205
 	if (!empty($settings['theme_variants']))
2081 2206
 	{
2082 2207
 		// Overriding - for previews and that ilk.
2083
-		if (!empty($_REQUEST['variant']))
2084
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2208
+		if (!empty($_REQUEST['variant'])) {
2209
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2210
+		}
2085 2211
 		// User selection?
2086
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2087
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2212
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2213
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2214
+		}
2088 2215
 		// If not a user variant, select the default.
2089
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2090
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2216
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2217
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2218
+		}
2091 2219
 
2092 2220
 		// Do this to keep things easier in the templates.
2093 2221
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2096,20 +2224,23 @@  discard block
 block discarded – undo
2096 2224
 		if (!empty($context['theme_variant']))
2097 2225
 		{
2098 2226
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2099
-			if ($context['right_to_left'])
2100
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2227
+			if ($context['right_to_left']) {
2228
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2229
+			}
2101 2230
 		}
2102 2231
 	}
2103 2232
 
2104 2233
 	// Let's be compatible with old themes!
2105
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2106
-		$context['template_layers'] = array('main');
2234
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2235
+			$context['template_layers'] = array('main');
2236
+	}
2107 2237
 
2108 2238
 	$context['tabindex'] = 1;
2109 2239
 
2110 2240
 	// Compatibility.
2111
-	if (!isset($settings['theme_version']))
2112
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2241
+	if (!isset($settings['theme_version'])) {
2242
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2243
+	}
2113 2244
 
2114 2245
 	// Default JS variables for use in every theme
2115 2246
 	$context['javascript_vars'] = array(
@@ -2128,18 +2259,18 @@  discard block
 block discarded – undo
2128 2259
 	);
2129 2260
 
2130 2261
 	// Add the JQuery library to the list of files to load.
2131
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2132
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2133
-
2134
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2135
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2136
-
2137
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2138
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2262
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2263
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2264
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2265
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2266
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2267
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2268
+	}
2139 2269
 
2140 2270
 	// Auto loading? template_javascript() will take care of the local half of this.
2141
-	else
2142
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2271
+	else {
2272
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2273
+	}
2143 2274
 
2144 2275
 	// Queue our JQuery plugins!
2145 2276
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2162,12 +2293,12 @@  discard block
 block discarded – undo
2162 2293
 			require_once($sourcedir . '/ScheduledTasks.php');
2163 2294
 
2164 2295
 			// What to do, what to do?!
2165
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2166
-				AutoTask();
2167
-			else
2168
-				ReduceMailQueue();
2169
-		}
2170
-		else
2296
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2297
+							AutoTask();
2298
+			} else {
2299
+							ReduceMailQueue();
2300
+			}
2301
+		} else
2171 2302
 		{
2172 2303
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2173 2304
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2218,8 +2349,9 @@  discard block
 block discarded – undo
2218 2349
 		foreach ($theme_includes as $include)
2219 2350
 		{
2220 2351
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2221
-			if (file_exists($include))
2222
-				require_once($include);
2352
+			if (file_exists($include)) {
2353
+							require_once($include);
2354
+			}
2223 2355
 		}
2224 2356
 	}
2225 2357
 
@@ -2249,16 +2381,19 @@  discard block
 block discarded – undo
2249 2381
 	// Do any style sheets first, cause we're easy with those.
2250 2382
 	if (!empty($style_sheets))
2251 2383
 	{
2252
-		if (!is_array($style_sheets))
2253
-			$style_sheets = array($style_sheets);
2384
+		if (!is_array($style_sheets)) {
2385
+					$style_sheets = array($style_sheets);
2386
+		}
2254 2387
 
2255
-		foreach ($style_sheets as $sheet)
2256
-			loadCSSFile($sheet . '.css', array(), $sheet);
2388
+		foreach ($style_sheets as $sheet) {
2389
+					loadCSSFile($sheet . '.css', array(), $sheet);
2390
+		}
2257 2391
 	}
2258 2392
 
2259 2393
 	// No template to load?
2260
-	if ($template_name === false)
2261
-		return true;
2394
+	if ($template_name === false) {
2395
+			return true;
2396
+	}
2262 2397
 
2263 2398
 	$loaded = false;
2264 2399
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2273,12 +2408,14 @@  discard block
 block discarded – undo
2273 2408
 
2274 2409
 	if ($loaded)
2275 2410
 	{
2276
-		if ($db_show_debug === true)
2277
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2411
+		if ($db_show_debug === true) {
2412
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2413
+		}
2278 2414
 
2279 2415
 		// If they have specified an initialization function for this template, go ahead and call it now.
2280
-		if (function_exists('template_' . $template_name . '_init'))
2281
-			call_user_func('template_' . $template_name . '_init');
2416
+		if (function_exists('template_' . $template_name . '_init')) {
2417
+					call_user_func('template_' . $template_name . '_init');
2418
+		}
2282 2419
 	}
2283 2420
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2284 2421
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2298,13 +2435,14 @@  discard block
 block discarded – undo
2298 2435
 		loadTemplate($template_name);
2299 2436
 	}
2300 2437
 	// Cause an error otherwise.
2301
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2302
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2303
-	elseif ($fatal)
2304
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2305
-	else
2306
-		return false;
2307
-}
2438
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2439
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2440
+	} elseif ($fatal) {
2441
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2442
+	} else {
2443
+			return false;
2444
+	}
2445
+	}
2308 2446
 
2309 2447
 
2310 2448
 /**
@@ -2323,17 +2461,19 @@  discard block
 block discarded – undo
2323 2461
 {
2324 2462
 	global $context, $txt, $db_show_debug;
2325 2463
 
2326
-	if ($db_show_debug === true)
2327
-		$context['debug']['sub_templates'][] = $sub_template_name;
2464
+	if ($db_show_debug === true) {
2465
+			$context['debug']['sub_templates'][] = $sub_template_name;
2466
+	}
2328 2467
 
2329 2468
 	// Figure out what the template function is named.
2330 2469
 	$theme_function = 'template_' . $sub_template_name;
2331
-	if (function_exists($theme_function))
2332
-		$theme_function();
2333
-	elseif ($fatal === false)
2334
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2335
-	elseif ($fatal !== 'ignore')
2336
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2470
+	if (function_exists($theme_function)) {
2471
+			$theme_function();
2472
+	} elseif ($fatal === false) {
2473
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2474
+	} elseif ($fatal !== 'ignore') {
2475
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2476
+	}
2337 2477
 
2338 2478
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2339 2479
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2370,8 +2510,9 @@  discard block
 block discarded – undo
2370 2510
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2371 2511
 
2372 2512
 	// If this is an external file, automatically set this to false.
2373
-	if (!empty($params['external']))
2374
-		$params['minimize'] = false;
2513
+	if (!empty($params['external'])) {
2514
+			$params['minimize'] = false;
2515
+	}
2375 2516
 
2376 2517
 	// Account for shorthand like admin.css?alp21 filenames
2377 2518
 	$has_seed = strpos($fileName, '.css?');
@@ -2388,13 +2529,10 @@  discard block
 block discarded – undo
2388 2529
 			{
2389 2530
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2390 2531
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2532
+			} else {
2533
+							$fileUrl = false;
2391 2534
 			}
2392
-
2393
-			else
2394
-				$fileUrl = false;
2395
-		}
2396
-
2397
-		else
2535
+		} else
2398 2536
 		{
2399 2537
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2400 2538
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2409,12 +2547,14 @@  discard block
 block discarded – undo
2409 2547
 	}
2410 2548
 
2411 2549
 	// Add it to the array for use in the template
2412
-	if (!empty($fileName))
2413
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2550
+	if (!empty($fileName)) {
2551
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2552
+	}
2414 2553
 
2415
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2416
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2417
-}
2554
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2555
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2556
+	}
2557
+	}
2418 2558
 
2419 2559
 /**
2420 2560
  * Add a block of inline css code to be executed later
@@ -2431,8 +2571,9 @@  discard block
 block discarded – undo
2431 2571
 	global $context;
2432 2572
 
2433 2573
 	// Gotta add something...
2434
-	if (empty($css))
2435
-		return false;
2574
+	if (empty($css)) {
2575
+			return false;
2576
+	}
2436 2577
 
2437 2578
 	$context['css_header'][] = $css;
2438 2579
 }
@@ -2467,8 +2608,9 @@  discard block
 block discarded – undo
2467 2608
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2468 2609
 
2469 2610
 	// If this is an external file, automatically set this to false.
2470
-	if (!empty($params['external']))
2471
-		$params['minimize'] = false;
2611
+	if (!empty($params['external'])) {
2612
+			$params['minimize'] = false;
2613
+	}
2472 2614
 
2473 2615
 	// Account for shorthand like admin.js?alp21 filenames
2474 2616
 	$has_seed = strpos($fileName, '.js?');
@@ -2485,16 +2627,12 @@  discard block
 block discarded – undo
2485 2627
 			{
2486 2628
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2487 2629
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2488
-			}
2489
-
2490
-			else
2630
+			} else
2491 2631
 			{
2492 2632
 				$fileUrl = false;
2493 2633
 				$filePath = false;
2494 2634
 			}
2495
-		}
2496
-
2497
-		else
2635
+		} else
2498 2636
 		{
2499 2637
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2500 2638
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2509,9 +2647,10 @@  discard block
 block discarded – undo
2509 2647
 	}
2510 2648
 
2511 2649
 	// Add it to the array for use in the template
2512
-	if (!empty($fileName))
2513
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2514
-}
2650
+	if (!empty($fileName)) {
2651
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2652
+	}
2653
+	}
2515 2654
 
2516 2655
 /**
2517 2656
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2525,9 +2664,10 @@  discard block
 block discarded – undo
2525 2664
 {
2526 2665
 	global $context;
2527 2666
 
2528
-	if (!empty($key) && (!empty($value) || $value === '0'))
2529
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2530
-}
2667
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2668
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2669
+	}
2670
+	}
2531 2671
 
2532 2672
 /**
2533 2673
  * Add a block of inline Javascript code to be executed later
@@ -2544,8 +2684,9 @@  discard block
 block discarded – undo
2544 2684
 {
2545 2685
 	global $context;
2546 2686
 
2547
-	if (empty($javascript))
2548
-		return false;
2687
+	if (empty($javascript)) {
2688
+			return false;
2689
+	}
2549 2690
 
2550 2691
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2551 2692
 }
@@ -2566,15 +2707,18 @@  discard block
 block discarded – undo
2566 2707
 	static $already_loaded = array();
2567 2708
 
2568 2709
 	// Default to the user's language.
2569
-	if ($lang == '')
2570
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2710
+	if ($lang == '') {
2711
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2712
+	}
2571 2713
 
2572 2714
 	// Do we want the English version of language file as fallback?
2573
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2574
-		loadLanguage($template_name, 'english', false);
2715
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2716
+			loadLanguage($template_name, 'english', false);
2717
+	}
2575 2718
 
2576
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2577
-		return $lang;
2719
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2720
+			return $lang;
2721
+	}
2578 2722
 
2579 2723
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2580 2724
 	if (empty($settings['default_theme_dir']))
@@ -2585,8 +2729,9 @@  discard block
 block discarded – undo
2585 2729
 
2586 2730
 	// What theme are we in?
2587 2731
 	$theme_name = basename($settings['theme_url']);
2588
-	if (empty($theme_name))
2589
-		$theme_name = 'unknown';
2732
+	if (empty($theme_name)) {
2733
+			$theme_name = 'unknown';
2734
+	}
2590 2735
 
2591 2736
 	// For each file open it up and write it out!
2592 2737
 	foreach (explode('+', $template_name) as $template)
@@ -2665,8 +2810,9 @@  discard block
 block discarded – undo
2665 2810
 	}
2666 2811
 
2667 2812
 	// Keep track of what we're up to soldier.
2668
-	if ($db_show_debug === true)
2669
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2813
+	if ($db_show_debug === true) {
2814
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2815
+	}
2670 2816
 
2671 2817
 	// Remember what we have loaded, and in which language.
2672 2818
 	$already_loaded[$template_name] = $lang;
@@ -2712,8 +2858,9 @@  discard block
 block discarded – undo
2712 2858
 				)
2713 2859
 			);
2714 2860
 			// In the EXTREMELY unlikely event this happens, give an error message.
2715
-			if ($smcFunc['db_num_rows']($result) == 0)
2716
-				fatal_lang_error('parent_not_found', 'critical');
2861
+			if ($smcFunc['db_num_rows']($result) == 0) {
2862
+							fatal_lang_error('parent_not_found', 'critical');
2863
+			}
2717 2864
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2718 2865
 			{
2719 2866
 				if (!isset($boards[$row['id_board']]))
@@ -2730,8 +2877,8 @@  discard block
 block discarded – undo
2730 2877
 					);
2731 2878
 				}
2732 2879
 				// If a moderator exists for this board, add that moderator for all children too.
2733
-				if (!empty($row['id_moderator']))
2734
-					foreach ($boards as $id => $dummy)
2880
+				if (!empty($row['id_moderator'])) {
2881
+									foreach ($boards as $id => $dummy)
2735 2882
 					{
2736 2883
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2737 2884
 							'id' => $row['id_moderator'],
@@ -2739,11 +2886,12 @@  discard block
 block discarded – undo
2739 2886
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2740 2887
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2741 2888
 						);
2889
+				}
2742 2890
 					}
2743 2891
 
2744 2892
 				// If a moderator group exists for this board, add that moderator group for all children too
2745
-				if (!empty($row['id_moderator_group']))
2746
-					foreach ($boards as $id => $dummy)
2893
+				if (!empty($row['id_moderator_group'])) {
2894
+									foreach ($boards as $id => $dummy)
2747 2895
 					{
2748 2896
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2749 2897
 							'id' => $row['id_moderator_group'],
@@ -2751,6 +2899,7 @@  discard block
 block discarded – undo
2751 2899
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2752 2900
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2753 2901
 						);
2902
+				}
2754 2903
 					}
2755 2904
 			}
2756 2905
 			$smcFunc['db_free_result']($result);
@@ -2778,23 +2927,27 @@  discard block
 block discarded – undo
2778 2927
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2779 2928
 	{
2780 2929
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2781
-		if (empty($smcFunc['ucwords']))
2782
-			reloadSettings();
2930
+		if (empty($smcFunc['ucwords'])) {
2931
+					reloadSettings();
2932
+		}
2783 2933
 
2784 2934
 		// If we don't have our theme information yet, let's get it.
2785
-		if (empty($settings['default_theme_dir']))
2786
-			loadTheme(0, false);
2935
+		if (empty($settings['default_theme_dir'])) {
2936
+					loadTheme(0, false);
2937
+		}
2787 2938
 
2788 2939
 		// Default language directories to try.
2789 2940
 		$language_directories = array(
2790 2941
 			$settings['default_theme_dir'] . '/languages',
2791 2942
 		);
2792
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2793
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2943
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2944
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2945
+		}
2794 2946
 
2795 2947
 		// We possibly have a base theme directory.
2796
-		if (!empty($settings['base_theme_dir']))
2797
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2948
+		if (!empty($settings['base_theme_dir'])) {
2949
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2950
+		}
2798 2951
 
2799 2952
 		// Remove any duplicates.
2800 2953
 		$language_directories = array_unique($language_directories);
@@ -2808,20 +2961,21 @@  discard block
 block discarded – undo
2808 2961
 		foreach ($language_directories as $language_dir)
2809 2962
 		{
2810 2963
 			// Can't look in here... doesn't exist!
2811
-			if (!file_exists($language_dir))
2812
-				continue;
2964
+			if (!file_exists($language_dir)) {
2965
+							continue;
2966
+			}
2813 2967
 
2814 2968
 			$dir = dir($language_dir);
2815 2969
 			while ($entry = $dir->read())
2816 2970
 			{
2817 2971
 				// Look for the index language file....
2818
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2819
-					continue;
2820
-
2821
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2822
-					$langName = $langList[$matches[1]];
2972
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2973
+									continue;
2974
+				}
2823 2975
 
2824
-				else
2976
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2977
+									$langName = $langList[$matches[1]];
2978
+				} else
2825 2979
 				{
2826 2980
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2827 2981
 
@@ -2864,20 +3018,23 @@  discard block
 block discarded – undo
2864 3018
 		}
2865 3019
 
2866 3020
 		// Do we need to store the lang list?
2867
-		if (empty($langList))
2868
-			updateSettings(array('langList' => json_encode($catchLang)));
3021
+		if (empty($langList)) {
3022
+					updateSettings(array('langList' => json_encode($catchLang)));
3023
+		}
2869 3024
 
2870 3025
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2871 3026
 		if ($favor_utf8)
2872 3027
 		{
2873
-			foreach ($context['languages'] as $lang)
2874
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3028
+			foreach ($context['languages'] as $lang) {
3029
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2875 3030
 					unset($context['languages'][$lang['filename']]);
3031
+			}
2876 3032
 		}
2877 3033
 
2878 3034
 		// Let's cash in on this deal.
2879
-		if (!empty($modSettings['cache_enable']))
2880
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3035
+		if (!empty($modSettings['cache_enable'])) {
3036
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3037
+		}
2881 3038
 	}
2882 3039
 
2883 3040
 	return $context['languages'];
@@ -2900,8 +3057,9 @@  discard block
 block discarded – undo
2900 3057
 	global $modSettings, $options, $txt;
2901 3058
 	static $censor_vulgar = null, $censor_proper;
2902 3059
 
2903
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2904
-		return $text;
3060
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3061
+			return $text;
3062
+	}
2905 3063
 
2906 3064
 	// If they haven't yet been loaded, load them.
2907 3065
 	if ($censor_vulgar == null)
@@ -2929,9 +3087,9 @@  discard block
 block discarded – undo
2929 3087
 	{
2930 3088
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2931 3089
 		$text = $func($censor_vulgar, $censor_proper, $text);
3090
+	} else {
3091
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2932 3092
 	}
2933
-	else
2934
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2935 3093
 
2936 3094
 	return $text;
2937 3095
 }
@@ -2957,38 +3115,42 @@  discard block
 block discarded – undo
2957 3115
 	@ini_set('track_errors', '1');
2958 3116
 
2959 3117
 	// Don't include the file more than once, if $once is true.
2960
-	if ($once && in_array($filename, $templates))
2961
-		return;
3118
+	if ($once && in_array($filename, $templates)) {
3119
+			return;
3120
+	}
2962 3121
 	// Add this file to the include list, whether $once is true or not.
2963
-	else
2964
-		$templates[] = $filename;
3122
+	else {
3123
+			$templates[] = $filename;
3124
+	}
2965 3125
 
2966 3126
 	// Are we going to use eval?
2967 3127
 	if (empty($modSettings['disableTemplateEval']))
2968 3128
 	{
2969 3129
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2970 3130
 		$settings['current_include_filename'] = $filename;
2971
-	}
2972
-	else
3131
+	} else
2973 3132
 	{
2974 3133
 		$file_found = file_exists($filename);
2975 3134
 
2976
-		if ($once && $file_found)
2977
-			require_once($filename);
2978
-		elseif ($file_found)
2979
-			require($filename);
3135
+		if ($once && $file_found) {
3136
+					require_once($filename);
3137
+		} elseif ($file_found) {
3138
+					require($filename);
3139
+		}
2980 3140
 	}
2981 3141
 
2982 3142
 	if ($file_found !== true)
2983 3143
 	{
2984 3144
 		ob_end_clean();
2985
-		if (!empty($modSettings['enableCompressedOutput']))
2986
-			@ob_start('ob_gzhandler');
2987
-		else
2988
-			ob_start();
3145
+		if (!empty($modSettings['enableCompressedOutput'])) {
3146
+					@ob_start('ob_gzhandler');
3147
+		} else {
3148
+					ob_start();
3149
+		}
2989 3150
 
2990
-		if (isset($_GET['debug']))
2991
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3151
+		if (isset($_GET['debug'])) {
3152
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3153
+		}
2992 3154
 
2993 3155
 		// Don't cache error pages!!
2994 3156
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3007,12 +3169,13 @@  discard block
 block discarded – undo
3007 3169
 		echo '<!DOCTYPE html>
3008 3170
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3009 3171
 	<head>';
3010
-		if (isset($context['character_set']))
3011
-			echo '
3172
+		if (isset($context['character_set'])) {
3173
+					echo '
3012 3174
 		<meta charset="', $context['character_set'], '">';
3175
+		}
3013 3176
 
3014
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3015
-			echo '
3177
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3178
+					echo '
3016 3179
 		<title>', $mtitle, '</title>
3017 3180
 	</head>
3018 3181
 	<body>
@@ -3020,8 +3183,8 @@  discard block
 block discarded – undo
3020 3183
 		', $mmessage, '
3021 3184
 	</body>
3022 3185
 </html>';
3023
-		elseif (!allowedTo('admin_forum'))
3024
-			echo '
3186
+		} elseif (!allowedTo('admin_forum')) {
3187
+					echo '
3025 3188
 		<title>', $txt['template_parse_error'], '</title>
3026 3189
 	</head>
3027 3190
 	<body>
@@ -3029,15 +3192,17 @@  discard block
 block discarded – undo
3029 3192
 		', $txt['template_parse_error_message'], '
3030 3193
 	</body>
3031 3194
 </html>';
3032
-		else
3195
+		} else
3033 3196
 		{
3034 3197
 			require_once($sourcedir . '/Subs-Package.php');
3035 3198
 
3036 3199
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3037
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3038
-				$error = $php_errormsg;
3039
-			if (empty($error))
3040
-				$error = $txt['template_parse_errmsg'];
3200
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3201
+							$error = $php_errormsg;
3202
+			}
3203
+			if (empty($error)) {
3204
+							$error = $txt['template_parse_errmsg'];
3205
+			}
3041 3206
 
3042 3207
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3043 3208
 
@@ -3048,11 +3213,12 @@  discard block
 block discarded – undo
3048 3213
 		<h3>', $txt['template_parse_error'], '</h3>
3049 3214
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3050 3215
 
3051
-			if (!empty($error))
3052
-				echo '
3216
+			if (!empty($error)) {
3217
+							echo '
3053 3218
 		<hr>
3054 3219
 
3055 3220
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3221
+			}
3056 3222
 
3057 3223
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3058 3224
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3062,10 +3228,11 @@  discard block
 block discarded – undo
3062 3228
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3063 3229
 
3064 3230
 				// Fix the PHP code stuff...
3065
-				if (!isBrowser('gecko'))
3066
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3067
-				else
3068
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3231
+				if (!isBrowser('gecko')) {
3232
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3233
+				} else {
3234
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3235
+				}
3069 3236
 
3070 3237
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3071 3238
 				$j = -1;
@@ -3073,8 +3240,9 @@  discard block
 block discarded – undo
3073 3240
 				{
3074 3241
 					$j++;
3075 3242
 
3076
-					if (substr_count($line, '<br>') == 0)
3077
-						continue;
3243
+					if (substr_count($line, '<br>') == 0) {
3244
+											continue;
3245
+					}
3078 3246
 
3079 3247
 					$n = substr_count($line, '<br>');
3080 3248
 					for ($i = 0; $i < $n; $i++)
@@ -3093,38 +3261,42 @@  discard block
 block discarded – undo
3093 3261
 				// Figure out what the color coding was before...
3094 3262
 				$line = max($match[1] - 9, 1);
3095 3263
 				$last_line = '';
3096
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3097
-					if (strpos($data2[$line2], '<') !== false)
3264
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3265
+									if (strpos($data2[$line2], '<') !== false)
3098 3266
 					{
3099 3267
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3100 3268
 							$last_line = $color_match[1];
3269
+				}
3101 3270
 						break;
3102 3271
 					}
3103 3272
 
3104 3273
 				// Show the relevant lines...
3105 3274
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3106 3275
 				{
3107
-					if ($line == $match[1])
3108
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3276
+					if ($line == $match[1]) {
3277
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3278
+					}
3109 3279
 
3110 3280
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3111
-					if (isset($data2[$line]) && $data2[$line] != '')
3112
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3281
+					if (isset($data2[$line]) && $data2[$line] != '') {
3282
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3283
+					}
3113 3284
 
3114 3285
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3115 3286
 					{
3116 3287
 						$last_line = $color_match[1];
3117 3288
 						echo '</', substr($last_line, 1, 4), '>';
3289
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3290
+											$last_line = '';
3291
+					} elseif ($last_line != '' && $data2[$line] != '') {
3292
+											echo '</', substr($last_line, 1, 4), '>';
3118 3293
 					}
3119
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3120
-						$last_line = '';
3121
-					elseif ($last_line != '' && $data2[$line] != '')
3122
-						echo '</', substr($last_line, 1, 4), '>';
3123 3294
 
3124
-					if ($line == $match[1])
3125
-						echo '</pre></div><pre style="margin: 0;">';
3126
-					else
3127
-						echo "\n";
3295
+					if ($line == $match[1]) {
3296
+											echo '</pre></div><pre style="margin: 0;">';
3297
+					} else {
3298
+											echo "\n";
3299
+					}
3128 3300
 				}
3129 3301
 
3130 3302
 				echo '</pre></div>';
@@ -3148,8 +3320,9 @@  discard block
 block discarded – undo
3148 3320
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3149 3321
 
3150 3322
 	// Figure out what type of database we are using.
3151
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3152
-		$db_type = 'mysql';
3323
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3324
+			$db_type = 'mysql';
3325
+	}
3153 3326
 
3154 3327
 	// Load the file for the database.
3155 3328
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3157,8 +3330,9 @@  discard block
 block discarded – undo
3157 3330
 	$db_options = array();
3158 3331
 
3159 3332
 	// Add in the port if needed
3160
-	if (!empty($db_port))
3161
-		$db_options['port'] = $db_port;
3333
+	if (!empty($db_port)) {
3334
+			$db_options['port'] = $db_port;
3335
+	}
3162 3336
 
3163 3337
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3164 3338
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3177,13 +3351,15 @@  discard block
 block discarded – undo
3177 3351
 	}
3178 3352
 
3179 3353
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3180
-	if (!$db_connection)
3181
-		display_db_error();
3354
+	if (!$db_connection) {
3355
+			display_db_error();
3356
+	}
3182 3357
 
3183 3358
 	// If in SSI mode fix up the prefix.
3184
-	if (SMF == 'SSI')
3185
-		db_fix_prefix($db_prefix, $db_name);
3186
-}
3359
+	if (SMF == 'SSI') {
3360
+			db_fix_prefix($db_prefix, $db_name);
3361
+	}
3362
+	}
3187 3363
 
3188 3364
 /**
3189 3365
  * Try to retrieve a cache entry. On failure, call the appropriate function.
@@ -3201,8 +3377,9 @@  discard block
 block discarded – undo
3201 3377
 
3202 3378
 	// @todo Why are we doing this if caching is disabled?
3203 3379
 
3204
-	if (function_exists('call_integration_hook'))
3205
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3380
+	if (function_exists('call_integration_hook')) {
3381
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3382
+	}
3206 3383
 
3207 3384
 	/* Refresh the cache if either:
3208 3385
 		1. Caching is disabled.
@@ -3216,16 +3393,19 @@  discard block
 block discarded – undo
3216 3393
 		require_once($sourcedir . '/' . $file);
3217 3394
 		$cache_block = call_user_func_array($function, $params);
3218 3395
 
3219
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3220
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3396
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3397
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3398
+		}
3221 3399
 	}
3222 3400
 
3223 3401
 	// Some cached data may need a freshening up after retrieval.
3224
-	if (!empty($cache_block['post_retri_eval']))
3225
-		eval($cache_block['post_retri_eval']);
3402
+	if (!empty($cache_block['post_retri_eval'])) {
3403
+			eval($cache_block['post_retri_eval']);
3404
+	}
3226 3405
 
3227
-	if (function_exists('call_integration_hook'))
3228
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3406
+	if (function_exists('call_integration_hook')) {
3407
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3408
+	}
3229 3409
 
3230 3410
 	return $cache_block['data'];
3231 3411
 }
@@ -3253,8 +3433,9 @@  discard block
 block discarded – undo
3253 3433
 	global $cache_hits, $cache_count, $db_show_debug, $cachedir;
3254 3434
 	global $cache_accelerator, $cache_enable, $cache_memcached;
3255 3435
 
3256
-	if (empty($cache_enable))
3257
-		return;
3436
+	if (empty($cache_enable)) {
3437
+			return;
3438
+	}
3258 3439
 
3259 3440
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3260 3441
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3273,10 +3454,12 @@  discard block
 block discarded – undo
3273 3454
 			if ((function_exists('memcached_set') || function_exists('memcache_set')) && isset($cache_memcached) && trim($cache_memcached) != '')
3274 3455
 			{
3275 3456
 				// Not connected yet?
3276
-				if (empty($memcached))
3277
-					get_memcached_server();
3278
-				if (!$memcached)
3279
-					return;
3457
+				if (empty($memcached)) {
3458
+									get_memcached_server();
3459
+				}
3460
+				if (!$memcached) {
3461
+									return;
3462
+				}
3280 3463
 
3281 3464
 				memcache_set($memcached, $key, $value, 0, $ttl);
3282 3465
 			}
@@ -3286,10 +3469,11 @@  discard block
 block discarded – undo
3286 3469
 			if (function_exists('apc_store'))
3287 3470
 			{
3288 3471
 				// An extended key is needed to counteract a bug in APC.
3289
-				if ($value === null)
3290
-					apc_delete($key . 'smf');
3291
-				else
3292
-					apc_store($key . 'smf', $value, $ttl);
3472
+				if ($value === null) {
3473
+									apc_delete($key . 'smf');
3474
+				} else {
3475
+									apc_store($key . 'smf', $value, $ttl);
3476
+				}
3293 3477
 			}
3294 3478
 			break;
3295 3479
 		case 'apcu':
@@ -3297,57 +3481,65 @@  discard block
 block discarded – undo
3297 3481
 			if (function_exists('apcu_store'))
3298 3482
 			{
3299 3483
 				// Not sure if this bug exists in APCu or not?
3300
-				if ($value === null)
3301
-					apcu_delete($key . 'smf');
3302
-				else
3303
-					apcu_store($key . 'smf', $value, $ttl);
3484
+				if ($value === null) {
3485
+									apcu_delete($key . 'smf');
3486
+				} else {
3487
+									apcu_store($key . 'smf', $value, $ttl);
3488
+				}
3304 3489
 			}
3305 3490
 			break;
3306 3491
 		case 'zend':
3307 3492
 			// Zend Platform/ZPS/etc.
3308
-			if (function_exists('zend_shm_cache_store'))
3309
-				zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3310
-			elseif (function_exists('output_cache_put'))
3311
-				output_cache_put($key, $value);
3493
+			if (function_exists('zend_shm_cache_store')) {
3494
+							zend_shm_cache_store('SMF::' . $key, $value, $ttl);
3495
+			} elseif (function_exists('output_cache_put')) {
3496
+							output_cache_put($key, $value);
3497
+			}
3312 3498
 			break;
3313 3499
 		case 'xcache':
3314 3500
 			if (function_exists('xcache_set') && ini_get('xcache.var_size') > 0)
3315 3501
 			{
3316
-				if ($value === null)
3317
-					xcache_unset($key);
3318
-				else
3319
-					xcache_set($key, $value, $ttl);
3502
+				if ($value === null) {
3503
+									xcache_unset($key);
3504
+				} else {
3505
+									xcache_set($key, $value, $ttl);
3506
+				}
3320 3507
 			}
3321 3508
 			break;
3322 3509
 		default:
3323 3510
 			// Otherwise custom cache?
3324
-			if ($value === null)
3325
-				@unlink($cachedir . '/data_' . $key . '.php');
3326
-			else
3511
+			if ($value === null) {
3512
+							@unlink($cachedir . '/data_' . $key . '.php');
3513
+			} else
3327 3514
 			{
3328 3515
 				$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
3329 3516
 
3330 3517
 				// Write out the cache file, check that the cache write was successful; all the data must be written
3331 3518
 				// If it fails due to low diskspace, or other, remove the cache file
3332
-				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data))
3333
-					@unlink($cachedir . '/data_' . $key . '.php');
3519
+				if (file_put_contents($cachedir . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data)) {
3520
+									@unlink($cachedir . '/data_' . $key . '.php');
3521
+				}
3334 3522
 			}
3335 3523
 			break;
3336 3524
 	}
3337 3525
 
3338
-	if (function_exists('call_integration_hook'))
3339
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3526
+	if (function_exists('call_integration_hook')) {
3527
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3528
+	}
3340 3529
 
3341
-	if (isset($db_show_debug) && $db_show_debug === true)
3342
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3530
+	if (isset($db_show_debug) && $db_show_debug === true) {
3531
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3532
+	}
3343 3533
 
3344 3534
 	// Invalidate the opcode cache
3345
-	if (function_exists('opcache_invalidate'))
3346
-   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3535
+	if (function_exists('opcache_invalidate')) {
3536
+	   		opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3537
+	}
3347 3538
 
3348
-	if (function_exists('apc_delete_file'))
3349
-   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3350
-}
3539
+	if (function_exists('apc_delete_file')) {
3540
+	   		@apc_delete_file($cachedir . '/data_' . $key . '.php');
3541
+	}
3542
+	}
3351 3543
 
3352 3544
 /**
3353 3545
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3364,8 +3556,9 @@  discard block
 block discarded – undo
3364 3556
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug, $cachedir;
3365 3557
 	global $cache_accelerator, $cache_enable, $cache_memcached;
3366 3558
 
3367
-	if (empty($cache_enable))
3368
-		return;
3559
+	if (empty($cache_enable)) {
3560
+			return;
3561
+	}
3369 3562
 
3370 3563
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3371 3564
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3384,37 +3577,42 @@  discard block
 block discarded – undo
3384 3577
 			if ((function_exists('memcache_get') || function_exists('memcached_get')) && isset($cache_memcached) && trim($cache_memcached) != '')
3385 3578
 			{
3386 3579
 				// Not connected yet?
3387
-				if (empty($memcached))
3388
-					get_memcached_server();
3580
+				if (empty($memcached)) {
3581
+									get_memcached_server();
3582
+				}
3389 3583
 				if (!$memcached)
3390 3584
 				{
3391 3585
 					$cache_misses_count = isset($cache_misses) ? $cache_misses + 1 : 1;
3392 3586
 					$value = null;
3587
+				} else {
3588
+									$value = (function_exists('memcache_get')) ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
3393 3589
 				}
3394
-				else
3395
-					$value = (function_exists('memcache_get')) ? memcache_get($memcached, $key) : memcached_get($memcached, $key);
3396 3590
 			}
3397 3591
 			break;
3398 3592
 		case 'apc':
3399 3593
 			// This is the free APC from PECL.
3400
-			if (function_exists('apc_fetch'))
3401
-				$value = apc_fetch($key . 'smf');
3594
+			if (function_exists('apc_fetch')) {
3595
+							$value = apc_fetch($key . 'smf');
3596
+			}
3402 3597
 			break;
3403 3598
 		case 'apcu':
3404 3599
 			// APC User Cache. A continuation of the now-unsupported APC but without opcode cache
3405
-			if (function_exists('apcu_fetch'))
3406
-				$value = apcu_fetch($key . 'smf');
3600
+			if (function_exists('apcu_fetch')) {
3601
+							$value = apcu_fetch($key . 'smf');
3602
+			}
3407 3603
 			break;
3408 3604
 		case 'zend':
3409 3605
 			// Zend's pricey stuff.
3410
-			if (function_exists('zend_shm_cache_fetch'))
3411
-				$value = zend_shm_cache_fetch('SMF::' . $key);
3412
-			elseif (function_exists('output_cache_get'))
3413
-				$value = output_cache_get($key, $ttl);
3606
+			if (function_exists('zend_shm_cache_fetch')) {
3607
+							$value = zend_shm_cache_fetch('SMF::' . $key);
3608
+			} elseif (function_exists('output_cache_get')) {
3609
+							$value = output_cache_get($key, $ttl);
3610
+			}
3414 3611
 			break;
3415 3612
 		case 'xcache':
3416
-			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0)
3417
-				$value = xcache_get($key);
3613
+			if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) {
3614
+							$value = xcache_get($key);
3615
+			}
3418 3616
 			break;
3419 3617
 		default:
3420 3618
 			// Otherwise it's SMF data!
@@ -3422,8 +3620,9 @@  discard block
 block discarded – undo
3422 3620
 			{
3423 3621
 				// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
3424 3622
 				// causing newer files to take effect a while later.
3425
-				if (function_exists('opcache_invalidate'))
3426
-					opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3623
+				if (function_exists('opcache_invalidate')) {
3624
+									opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
3625
+				}
3427 3626
 
3428 3627
 				// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
3429 3628
 				@include($cachedir . '/data_' . $key . '.php');
@@ -3443,16 +3642,18 @@  discard block
 block discarded – undo
3443 3642
 
3444 3643
 		if (empty($value))
3445 3644
 		{
3446
-			if (!isset($cache_misses))
3447
-				$cache_misses = array();
3645
+			if (!isset($cache_misses)) {
3646
+							$cache_misses = array();
3647
+			}
3448 3648
 
3449 3649
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3450 3650
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3451 3651
 		}
3452 3652
 	}
3453 3653
 
3454
-	if (function_exists('call_integration_hook') && isset($value))
3455
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3654
+	if (function_exists('call_integration_hook') && isset($value)) {
3655
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3656
+	}
3456 3657
 
3457 3658
 	return empty($value) ? null : smf_json_decode($value, true);
3458 3659
 }
@@ -3476,9 +3677,9 @@  discard block
 block discarded – undo
3476 3677
 	$port = 0;
3477 3678
 
3478 3679
 	// Normal host names do not contain slashes, while e.g. unix sockets do. Assume alternative transport pipe with port 0.
3479
-	if(strpos($server,'/') !== false)
3480
-		$host = $server;
3481
-	else
3680
+	if(strpos($server,'/') !== false) {
3681
+			$host = $server;
3682
+	} else
3482 3683
 	{
3483 3684
 		$server = explode(':', $server);
3484 3685
 		$host = $server[0];
@@ -3493,22 +3694,26 @@  discard block
 block discarded – undo
3493 3694
 	// Don't wait too long: yes, we want the server, but we might be able to run the query faster!
3494 3695
 	if (empty($db_persist))
3495 3696
 	{
3496
-		if ($cache === 'memcached')
3497
-			$memcached = memcached_connect($host, $port);
3498
-		if ($cache === 'memcache')
3499
-			$memcached = memcache_connect($host, $port);
3500
-	}
3501
-	else
3697
+		if ($cache === 'memcached') {
3698
+					$memcached = memcached_connect($host, $port);
3699
+		}
3700
+		if ($cache === 'memcache') {
3701
+					$memcached = memcache_connect($host, $port);
3702
+		}
3703
+	} else
3502 3704
 	{
3503
-		if ($cache === 'memcached')
3504
-			$memcached = memcached_pconnect($host, $port);
3505
-		if ($cache === 'memcache')
3506
-			$memcached = memcache_pconnect($host, $port);
3705
+		if ($cache === 'memcached') {
3706
+					$memcached = memcached_pconnect($host, $port);
3707
+		}
3708
+		if ($cache === 'memcache') {
3709
+					$memcached = memcache_pconnect($host, $port);
3710
+		}
3507 3711
 	}
3508 3712
 
3509
-	if (!$memcached && $level > 0)
3510
-		get_memcached_server($level - 1);
3511
-}
3713
+	if (!$memcached && $level > 0) {
3714
+			get_memcached_server($level - 1);
3715
+	}
3716
+	}
3512 3717
 
3513 3718
 /**
3514 3719
  * Helper function to set an array of data for an user's avatar.
@@ -3526,8 +3731,9 @@  discard block
 block discarded – undo
3526 3731
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3527 3732
 
3528 3733
 	// Come on!
3529
-	if (empty($data))
3530
-		return array();
3734
+	if (empty($data)) {
3735
+			return array();
3736
+	}
3531 3737
 
3532 3738
 	// Set a nice default var.
3533 3739
 	$image = '';
@@ -3535,11 +3741,11 @@  discard block
 block discarded – undo
3535 3741
 	// Gravatar has been set as mandatory!
3536 3742
 	if (!empty($modSettings['gravatarOverride']))
3537 3743
 	{
3538
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3539
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3540
-
3541
-		else if (!empty($data['email']))
3542
-			$image = get_gravatar_url($data['email']);
3744
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3745
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3746
+		} else if (!empty($data['email'])) {
3747
+					$image = get_gravatar_url($data['email']);
3748
+		}
3543 3749
 	}
3544 3750
 
3545 3751
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3551,54 +3757,60 @@  discard block
 block discarded – undo
3551 3757
 			// Gravatar.
3552 3758
 			if (stristr($data['avatar'], 'gravatar://'))
3553 3759
 			{
3554
-				if ($data['avatar'] == 'gravatar://')
3555
-					$image = get_gravatar_url($data['email']);
3556
-
3557
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3558
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3760
+				if ($data['avatar'] == 'gravatar://') {
3761
+									$image = get_gravatar_url($data['email']);
3762
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3763
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3764
+				}
3559 3765
 			}
3560 3766
 
3561 3767
 			// External url.
3562 3768
 			else
3563 3769
 			{
3564 3770
 				// Using ssl?
3565
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3566
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3771
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3772
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3773
+				}
3567 3774
 
3568 3775
 				// Just a plain external url.
3569
-				else
3570
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3776
+				else {
3777
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3778
+				}
3571 3779
 			}
3572 3780
 		}
3573 3781
 
3574 3782
 		// Perhaps this user has an attachment as avatar...
3575
-		else if (!empty($data['filename']))
3576
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3783
+		else if (!empty($data['filename'])) {
3784
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3785
+		}
3577 3786
 
3578 3787
 		// Right... no avatar... use our default image.
3579
-		else
3580
-			$image = $modSettings['avatar_url'] . '/default.png';
3788
+		else {
3789
+					$image = $modSettings['avatar_url'] . '/default.png';
3790
+		}
3581 3791
 	}
3582 3792
 
3583 3793
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3584 3794
 
3585 3795
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3586
-	if (!empty($image))
3587
-		return array(
3796
+	if (!empty($image)) {
3797
+			return array(
3588 3798
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3589 3799
 			'image' => '<img class="avatar" src="' . $image . '" />',
3590 3800
 			'href' => $image,
3591 3801
 			'url' => $image,
3592 3802
 		);
3803
+	}
3593 3804
 
3594 3805
 	// Fallback to make life easier for everyone...
3595
-	else
3596
-		return array(
3806
+	else {
3807
+			return array(
3597 3808
 			'name' => '',
3598 3809
 			'image' => '',
3599 3810
 			'href' => '',
3600 3811
 			'url' => '',
3601 3812
 		);
3602
-}
3813
+	}
3814
+	}
3603 3815
 
3604 3816
 ?>
3605 3817
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageSmileys.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 					'class' => 'centercol',
394 394
 				),
395 395
 				'data' => array(
396
-					'function' => function ($rowData)
396
+					'function' => function($rowData)
397 397
 					{
398 398
 						return $rowData['selected'] ? '<span class="generic_icons valid"></span>' : '';
399 399
 					},
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 					'class' => 'centercol',
454 454
 				),
455 455
 				'data' => array(
456
-					'function' => function ($rowData)
456
+					'function' => function($rowData)
457 457
 					{
458 458
 						return $rowData['selected'] ? '' : sprintf('<input type="checkbox" name="smiley_set[%1$d]" class="input_check">', $rowData['id']);
459 459
 					},
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 						'value' => $txt['smileys_location'],
998 998
 					),
999 999
 					'data' => array(
1000
-						'function' => function ($rowData) use ($txt)
1000
+						'function' => function($rowData) use ($txt)
1001 1001
 						{
1002 1002
 							if (empty($rowData['hidden']))
1003 1003
 								return $txt['smileys_location_form'];
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 						'value' => $txt['smileys_description'],
1018 1018
 					),
1019 1019
 					'data' => array(
1020
-						'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc)
1020
+						'function' => function($rowData) use ($context, $txt, $modSettings, $smcFunc)
1021 1021
 						{
1022 1022
 							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']))
1023 1023
 								return $smcFunc['htmlspecialchars']($rowData['description']);
@@ -1557,7 +1557,7 @@  discard block
 block discarded – undo
1557 1557
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
1558 1558
 			);
1559 1559
 
1560
-			$file =  $packagesdir . '/temp/' . $base_path . $action['filename'];
1560
+			$file = $packagesdir . '/temp/' . $base_path . $action['filename'];
1561 1561
 			if (isset($action['filename']) && (!file_exists($file) || !is_writable(dirname($action['destination']))))
1562 1562
 			{
1563 1563
 				$context['has_failure'] = true;
@@ -1601,7 +1601,7 @@  discard block
 block discarded – undo
1601 1601
 		{
1602 1602
 			updateSettings(array(
1603 1603
 				'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . basename($action['action']),
1604
-				'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' .  (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''),
1604
+				'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''),
1605 1605
 			));
1606 1606
 		}
1607 1607
 
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
 			'{db_prefix}log_packages',
1614 1614
 			array(
1615 1615
 				'filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string',
1616
-				'id_member_installed' => 'int', 'member_installed' => 'string','time_installed' => 'int',
1616
+				'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int',
1617 1617
 				'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string',
1618 1618
 				'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string',
1619 1619
 			),
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
 		'columns' => array(
1863 1863
 			'icon' => array(
1864 1864
 				'data' => array(
1865
-					'function' => function ($rowData) use ($settings, $smcFunc)
1865
+					'function' => function($rowData) use ($settings, $smcFunc)
1866 1866
 					{
1867 1867
 						$images_url = $settings[file_exists(sprintf('%1$s/images/post/%2$s.png', $settings['theme_dir'], $rowData['filename'])) ? 'actual_images_url' : 'default_images_url'];
1868 1868
 						return sprintf('<img src="%1$s/post/%2$s.png" alt="%3$s">', $images_url, $rowData['filename'], $smcFunc['htmlspecialchars']($rowData['title']));
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
 					'value' => $txt['icons_board'],
1897 1897
 				),
1898 1898
 				'data' => array(
1899
-					'function' => function ($rowData) use ($txt)
1899
+					'function' => function($rowData) use ($txt)
1900 1900
 					{
1901 1901
 						return empty($rowData['board_name']) ? $txt['icons_edit_icons_all_boards'] : $rowData['board_name'];
1902 1902
 					},
Please login to merge, or discard this patch.
Sources/tasks/UpdateTldRegex.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@
 block discarded – undo
18 18
  */
19 19
 class Update_TLD_Regex extends SMF_BackgroundTask
20 20
 {
21
-    /**
22
-     * This executes the task. It just calls set_tld_regex() in Subs.php
23
-     * @return bool Always returns true
24
-     */
21
+	/**
22
+	 * This executes the task. It just calls set_tld_regex() in Subs.php
23
+	 * @return bool Always returns true
24
+	 */
25 25
 	public function execute()
26 26
  	{
27 27
 		global $sourcedir;
Please login to merge, or discard this patch.
Sources/ManageErrors.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -42,42 +42,42 @@  discard block
 block discarded – undo
42 42
 
43 43
 	// You can filter by any of the following columns:
44 44
 	$filters = array(
45
-		'id_member' => array (
45
+		'id_member' => array(
46 46
 			'txt' => $txt['username'],
47 47
 			'operator' => '=',
48 48
 			'datatype' => 'int',
49 49
 		),
50
-		'ip' => array (
50
+		'ip' => array(
51 51
 			'txt' => $txt['ip_address'],
52 52
 			'operator' => '=',
53 53
 			'datatype' => 'inet',
54 54
 		),
55
-		'session' => array (
55
+		'session' => array(
56 56
 			'txt' => $txt['session'],
57 57
 			'operator' => 'LIKE',
58 58
 			'datatype' => 'string',
59 59
 		),
60
-		'url' => array (
60
+		'url' => array(
61 61
 			'txt' => $txt['error_url'],
62 62
 			'operator' => 'LIKE',
63 63
 			'datatype' => 'string',
64 64
 		),
65
-		'message' => array (
65
+		'message' => array(
66 66
 			'txt' => $txt['error_message'],
67 67
 			'operator' => 'LIKE',
68 68
 			'datatype' => 'string',
69 69
 		),
70
-		'error_type' => array (
70
+		'error_type' => array(
71 71
 			'txt' => $txt['error_type'],
72 72
 			'operator' => 'LIKE',
73 73
 			'datatype' => 'string',
74 74
 		),
75
-		'file' => array (
75
+		'file' => array(
76 76
 			'txt' => $txt['file'],
77 77
 			'operator' => 'LIKE',
78 78
 			'datatype' => 'string',
79 79
 		),
80
-		'line' => array (
80
+		'line' => array(
81 81
 			'txt' => $txt['line'],
82 82
 			'operator' => '=',
83 83
 			'datatype' => 'int',
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	$result = $smcFunc['db_query']('', '
104 104
 		SELECT COUNT(*)
105 105
 		FROM {db_prefix}log_errors' . (isset($filter) ? '
106
-		WHERE ' . $filter['variable'] . ' '.$filters[$_GET['filter']]['operator'].' {'.$filters[$_GET['filter']]['datatype'].':filter}' : ''),
106
+		WHERE ' . $filter['variable'] . ' ' . $filters[$_GET['filter']]['operator'] . ' {' . $filters[$_GET['filter']]['datatype'] . ':filter}' : ''),
107 107
 		array(
108 108
 			'filter' => isset($filter) ? $filter['value']['sql'] : '',
109 109
 		)
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	$request = $smcFunc['db_query']('', '
147 147
 		SELECT id_error, id_member, ip, url, log_time, message, session, error_type, file, line
148 148
 		FROM {db_prefix}log_errors' . (isset($filter) ? '
149
-		WHERE ' . $filter['variable'] . ' '.$filters[$_GET['filter']]['operator'].' {'.$filters[$_GET['filter']]['datatype'].':filter}' : '') . '
149
+		WHERE ' . $filter['variable'] . ' ' . $filters[$_GET['filter']]['operator'] . ' {' . $filters[$_GET['filter']]['datatype'] . ':filter}' : '') . '
150 150
 		ORDER BY id_error ' . ($context['sort_direction'] == 'down' ? 'DESC' : '') . '
151 151
 		LIMIT {int:start}, {int:max}',
152 152
 		array(
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	$context['errors'] = array();
159 159
 	$members = array();
160 160
 
161
-	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
161
+	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
162 162
 	{
163 163
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
164 164
 		if ($search_message == $filter['value']['sql'])
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 			'id' => $row['id_error'],
185 185
 			'error_type' => array(
186 186
 				'type' => $row['error_type'],
187
-				'name' => isset($txt['errortype_'.$row['error_type']]) ? $txt['errortype_'.$row['error_type']] : $row['error_type'],
187
+				'name' => isset($txt['errortype_' . $row['error_type']]) ? $txt['errortype_' . $row['error_type']] : $row['error_type'],
188 188
 			),
189 189
 			'file' => array(),
190 190
 		);
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 	// We don't want to slice off too many so lets make sure we stop at the last one
413 413
 	$max = min($max, max(array_keys($file_data)));
414 414
 
415
-	$file_data = array_slice($file_data, $min-1, $max - $min);
415
+	$file_data = array_slice($file_data, $min - 1, $max - $min);
416 416
 
417 417
 	$context['file_data'] = array(
418 418
 		'contents' => $file_data,
Please login to merge, or discard this patch.
Themes/default/Admin.template.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 							<div id="live_news" class="floatleft">
34 34
 								<div class="cat_bar">
35 35
 									<h3 class="catbg">
36
-										<a href="', $scripturl, '?action=helpadmin;help=live_news" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'],'"></span></a> ', $txt['live'], '
36
+										<a href="', $scripturl, '?action=helpadmin;help=live_news" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a> ', $txt['live'], '
37 37
 									</h3>
38 38
 								</div>
39 39
 								<div class="windowbg nopadding">
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 								<tbody>
506 506
 									<tr class="windowbg">
507 507
 										<td class="half_table">
508
-											<a href="#" id="Tasks-link">', $txt['dvc_tasks'] ,'</a>
508
+											<a href="#" id="Tasks-link">', $txt['dvc_tasks'], '</a>
509 509
 										</td>
510 510
 										<td class="quarter_table">
511 511
 											<em id="yourTasks">??</em>
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 				echo '
769 769
 							<div class="cat_bar">
770 770
 								<h3 class="', !empty($config_var['class']) ? $config_var['class'] : 'catbg', '"', !empty($config_var['force_div_id']) ? ' id="' . $config_var['force_div_id'] . '"' : '', '>
771
-									', ($config_var['help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=' . $config_var['help'] . '" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="'. $txt['help'].'"></span></a>' : ''), '
771
+									', ($config_var['help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=' . $config_var['help'] . '" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="' . $txt['help'] . '"></span></a>' : ''), '
772 772
 									', $config_var['label'], '
773 773
 								</h3>
774 774
 							</div>';
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 				// Show the [?] button.
831 831
 				if ($config_var['help'])
832 832
 					echo '
833
-							<a id="setting_', $config_var['name'], '_help" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help" title="', $txt['help'],'"></span></a> ';
833
+							<a id="setting_', $config_var['name'], '_help" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help" title="', $txt['help'], '"></span></a> ';
834 834
 
835 835
 				echo '
836 836
 										<a id="setting_', $config_var['name'], '"></a> <span', ($config_var['disabled'] ? ' style="color: #777777;"' : ($config_var['invalid'] ? ' class="error"' : '')), '><label for="', $config_var['name'], '">', $config_var['label'], '</label>', $subtext, ($config_var['type'] == 'password' ? '<br><em>' . $txt['admin_confirm_password'] . '</em>' : ''), '</span>
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 					$max = isset($config_var['max']) ? ' max="' . $config_var['max'] . '"' : '';
935 935
 
936 936
 					echo '
937
-											<input type="', $type ,'"', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '" value="', $config_var['value'], '"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' class="input_text"', $min . $max . $step, '>';
937
+											<input type="', $type, '"', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '" value="', $config_var['value'], '"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' class="input_text"', $min . $max . $step, '>';
938 938
 				}
939 939
 
940 940
 				echo isset($config_var['postinput']) ? '
@@ -1126,13 +1126,13 @@  discard block
 block discarded – undo
1126 1126
 
1127 1127
 	foreach ($context['cust_profile_fields_placement'] as $order => $name)
1128 1128
 		echo '
1129
-												<option value="', $order ,'"', $context['field']['placement'] == $order ? ' selected' : '', '>', $txt['custom_profile_placement_'. $name], '</option>';
1129
+												<option value="', $order, '"', $context['field']['placement'] == $order ? ' selected' : '', '>', $txt['custom_profile_placement_' . $name], '</option>';
1130 1130
 
1131 1131
 	echo '
1132 1132
 											</select>
1133 1133
 										</dd>
1134 1134
 										<dt>
1135
-											<a id="field_show_enclosed" href="', $scripturl, '?action=helpadmin;help=field_show_enclosed" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'],'"></span></a>
1135
+											<a id="field_show_enclosed" href="', $scripturl, '?action=helpadmin;help=field_show_enclosed" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a>
1136 1136
 											<strong><label for="enclose">', $txt['custom_edit_enclose'], ':</label></strong><br>
1137 1137
 											<span class="smalltext">', $txt['custom_edit_enclose_desc'], '</span>
1138 1138
 										</dt>
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 											<input type="checkbox" name="bbc" id="bbc_dd"', $context['field']['bbc'] ? ' checked' : '', ' class="input_check">
1178 1178
 										</dd>
1179 1179
 										<dt id="options_dt">
1180
-											<a href="', $scripturl, '?action=helpadmin;help=customoptions" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'],'"></span></a>
1180
+											<a href="', $scripturl, '?action=helpadmin;help=customoptions" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a>
1181 1181
 											<strong><label for="options_dd">', $txt['custom_edit_options'], ':</label></strong><br>
1182 1182
 											<span class="smalltext">', $txt['custom_edit_options_desc'], '</span>
1183 1183
 										</dt>
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
 									<legend>', $txt['custom_edit_advanced'], '</legend>
1207 1207
 									<dl class="settings">
1208 1208
 										<dt id="mask_dt">
1209
-											<a id="custom_mask" href="', $scripturl, '?action=helpadmin;help=custom_mask" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'],'"></span></a>
1209
+											<a id="custom_mask" href="', $scripturl, '?action=helpadmin;help=custom_mask" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a>
1210 1210
 											<strong><label for="mask">', $txt['custom_edit_mask'], ':</label></strong><br>
1211 1211
 											<span class="smalltext">', $txt['custom_edit_mask_desc'], '</span>
1212 1212
 										</dt>
@@ -1322,7 +1322,7 @@  discard block
 block discarded – undo
1322 1322
 			{
1323 1323
 				echo '
1324 1324
 							<li>
1325
-								<a href="', $result['url'], '"><strong>', $result['name'], '</strong></a> [', isset($txt['admin_search_section_' . $result['type']]) ? $txt['admin_search_section_' . $result['type']] : $result['type'] , ']';
1325
+								<a href="', $result['url'], '"><strong>', $result['name'], '</strong></a> [', isset($txt['admin_search_section_' . $result['type']]) ? $txt['admin_search_section_' . $result['type']] : $result['type'], ']';
1326 1326
 
1327 1327
 				if ($result['help'])
1328 1328
 					echo '
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
 					<div id="admincenter">
1403 1403
 						<div id="section_header" class="cat_bar">
1404 1404
 							<h3 class="catbg">',
1405
-								$context['error_search'] ? $txt['errors_list'] : $txt['errors_fixing'] , '
1405
+								$context['error_search'] ? $txt['errors_list'] : $txt['errors_fixing'], '
1406 1406
 							</h3>
1407 1407
 						</div>
1408 1408
 						<div class="windowbg">';
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
 			{
1556 1556
 				echo '
1557 1557
 								<tr class="windowbg">
1558
-									<td class="equal_table">', $key,  '</td>
1558
+									<td class="equal_table">', $key, '</td>
1559 1559
 									<td colspan="2">', $setting, '</td>
1560 1560
 								</tr>';
1561 1561
 			}
Please login to merge, or discard this patch.